Skip to content

Commit f8b2eaf

Browse files
authored
Ci (#1)
ci update
1 parent 4db1325 commit f8b2eaf

File tree

8 files changed

+244
-9
lines changed

8 files changed

+244
-9
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.changeset/twelve-suns-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zemd/react-slottable": major
3+
---
4+
5+
new license

.github /workflows/node.js.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
pull_request:
8+
branches: ["main"]
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: "20.x"
18+
cache: "npm"
19+
- run: npm ci
20+
- run: npm run lint
21+
22+
build:
23+
runs-on: ubuntu-latest
24+
25+
strategy:
26+
matrix:
27+
node-version: [18.x, 20.x]
28+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
29+
30+
steps:
31+
- uses: actions/checkout@v3
32+
- name: Use Node.js ${{ matrix.node-version }}
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version: ${{ matrix.node-version }}
36+
cache: "npm"
37+
- run: npm ci
38+
- run: npm run build --if-present
39+
- run: npm test

.github /workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v3
17+
18+
- name: Setup Node.js 20.x
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: 20.x
22+
23+
- name: Setup bun
24+
uses: oven-sh/setup-bun@v1
25+
26+
- name: Install Dependencies
27+
run: bun install
28+
29+
- name: Create Release Pull Request or Publish to npm
30+
id: changesets
31+
uses: changesets/action@v1
32+
with:
33+
publish: bun run release
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 140 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,148 @@
11
# @zemd/react-slottable
22

3-
To install dependencies:
3+
[![npm](https://img.shields.io/npm/v/@zemd/react-slottable?color=000&label=npm)](https://npmjs.com/package/@zemd/react-slottable)
44

5-
```bash
6-
bun install
5+
The package provides a way to create your components in a customizable, easy-to-use, and maintainable way. Zero dependencies.
6+
7+
With it, you can build your own complex component libraries, composing different components without losing control over their internals, providing a great developer experience to your team.
8+
9+
Sounds interesting? Just look at the example of such a `Button` built with the library:
10+
11+
```typescript
12+
import {
13+
type TSlottablePropsFactory,
14+
slottable,
15+
useSlot,
16+
clsx
17+
} from "@zemd/react-slottable";
18+
19+
type TButtonProps = TSlottablePropsFactory<
20+
{
21+
fullWidth?: boolean;
22+
disabled?: boolean;
23+
size?: "sm" | "md" | "xl";
24+
variant?: "solid" | "outlined";
25+
color?: "primary" | "secondary";
26+
},
27+
"startDecorator" | "endDecorator" // this is how cool you can define your slots
28+
// in case you want control the type of slots explicitly, you can use an object:
29+
// { startDecorator: typeof MyCustomComponent, endDecorator: React.ElementType }
30+
>;
31+
32+
export const Button = slottable<"button", TButtonProps>(
33+
// params for the component are the same as you would expect from `forwardRef`
34+
function Button(inProps, ref) {
35+
const {
36+
component = "button", // each Slottable component is overridable by default using `component` prop, if you don't need - just Omit it
37+
className, // TSlottablePropsFactory provides `className` prop by default
38+
children, // TSlottablePropsFactory provides `children` prop by default
39+
startDecorator, // TSlottablePropsFactory provides ability to provide kind of `children` element for your slot
40+
endDecorator, // same as ^
41+
slots = {}, // slots are not receiving default value by default
42+
slotProps = {}, // as well as slotProps
43+
disabled, // here we just handle all props that we defined in `TButtonProps`
44+
fullWidth,
45+
size = "md",
46+
variant = "solid",
47+
color = "primary",
48+
...rest
49+
} = inProps;
50+
51+
const props = Object.assign({}, rest, { slots, slotProps }); // building a map with all important props for root slot and slot information
52+
53+
const [SlotRoot, rootProps] = useSlot("root", {
54+
ref, // ref is mandatory for the `root` slot
55+
component,
56+
className: clsx(
57+
"button-default-className", // use Tailwind, jss, or any other styling solution you want
58+
`button__size_${size}`,
59+
`button__color_${color}`,
60+
`button__variant_${variant}`,
61+
"text-blue-400 text-xl text-green-500",
62+
{
63+
"button__width_full": fullWidth
64+
},
65+
className // don't forget that your users would like to customize this prop
66+
),
67+
props,
68+
extraProps: {
69+
// optional `extraProps` field, which can include everything you want to send specifically to the slot component
70+
},
71+
// classNameMergeFn: twMerge, // if you need to normalize classNames you can pass a function reference
72+
});
73+
74+
const [SlotStartDecorator, startDecoratorProps] = useSlot(
75+
"startDecorator",
76+
{
77+
component: slots["startDecorator"] ?? ("div" as ElementType),
78+
className: "start-decorator-className",
79+
props,
80+
}
81+
);
82+
83+
const [SlotEndDecorator, endDecoratorProps] = useSlot("endDecorator", {
84+
component: slots["endDecorator"] ?? ("div" as ElementType),
85+
className: "end-decorator-className",
86+
props,
87+
});
88+
89+
// Wow! How easy to maintain it looks!!! Such declarative!
90+
return (
91+
<SlotRoot {...rootProps}>
92+
{startDecorator ? (
93+
<SlotStartDecorator {...startDecoratorProps}>
94+
{startDecorator}
95+
</SlotStartDecorator>
96+
) : null}
97+
{children}
98+
{endDecorator ? (
99+
<SlotEndDecorator {...endDecoratorProps}>
100+
{endDecorator}
101+
</SlotEndDecorator>
102+
) : null}
103+
</SlotRoot>
104+
);
105+
}
106+
);
7107
```
8108

9-
To run:
109+
Now your users can use this `Button`:
10110

11-
```bash
12-
bun run index.ts
111+
```typescript
112+
import { Button } from "./MyButton";
113+
114+
export function HomePage() {
115+
const buttonRef = useRef(null);
116+
return (
117+
<div>
118+
<Button
119+
// ref={buttonRef} // just in case if you need
120+
startDecorator={<MySvgIcon />}
121+
endDecorator={<span>no icon. just label.</span>}
122+
slots={{
123+
endDecorator: MyCustomLabelComponent
124+
}}
125+
slotProps={{
126+
startDecorator: {
127+
prop1: "value"
128+
}
129+
}}
130+
className: "my-custom-button-className"
131+
>
132+
Click me!
133+
</Button>
134+
</div>
135+
);
136+
}
13137
```
14138

15-
This project was created using `bun init` in bun v1.0.29. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
139+
The package exposes three essential parts: `slottable`, the `useSlot` hook, and the `TSlottablePropsFactory` typescript type. Combining them together, you get a backbone for your fantastic components.
140+
141+
## License
142+
143+
All the code in the repository released under the Apache 2.0 license
144+
145+
## Donate
146+
147+
[![](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/red_rabbit)
148+
[![](https://img.shields.io/static/v1?label=UNITED24&message=support%20Ukraine&color=blue)](https://u24.gov.ua/)

bun.lockb

11.4 KB
Binary file not shown.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zemd/react-slottable",
33
"type": "module",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"license": "Apache-2.0",
66
"description": "Foundation for component libraries with highly customizable approach",
77
"main": "dist/index.cjs",
@@ -39,10 +39,13 @@
3939
],
4040
"scripts": {
4141
"build": "tsup",
42-
"test": "vitest --run"
42+
"test": "vitest --run",
43+
"release": "changesets"
4344
},
4445
"devDependencies": {
4546
"@changesets/cli": "^2.27.1",
47+
"@testing-library/jest-dom": "^6.4.2",
48+
"@testing-library/react": "^14.2.1",
4649
"@types/bun": "latest",
4750
"@types/react": "^18.2.58",
4851
"@zemd/tsconfig": "^1.2.0",

0 commit comments

Comments
 (0)