@sustaina/shared-ui 1.70.8 β 1.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -251
- package/README.md.local-bak +273 -0
- package/dist/index.js +71 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,273 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sustaina/shared-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared UI component library for Sustaina micro-frontend modules.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Install UI package and required dependencies
|
|
10
|
-
|
|
11
|
-
Make sure you've installed [TailwindCSS](https://tailwindcss.com/docs/installation) and [shadcn/ui](https://ui.shadcn.com/docs/installation/manual) before installing our library. **Donβt skip this.**
|
|
12
|
-
|
|
13
|
-
### 1. Place shadcn/ui styles
|
|
14
|
-
|
|
15
|
-
```css
|
|
16
|
-
@import "tailwindcss";
|
|
17
|
-
@import "tw-animate-css";
|
|
18
|
-
@custom-variant dark (&:is(.dark *));
|
|
19
|
-
|
|
20
|
-
:root {
|
|
21
|
-
--background: oklch(1 0 0);
|
|
22
|
-
--foreground: oklch(0.145 0 0);
|
|
23
|
-
--card: oklch(1 0 0);
|
|
24
|
-
--card-foreground: oklch(0.145 0 0);
|
|
25
|
-
--popover: oklch(1 0 0);
|
|
26
|
-
--popover-foreground: oklch(0.145 0 0);
|
|
27
|
-
--primary: oklch(0.205 0 0);
|
|
28
|
-
--primary-foreground: oklch(0.985 0 0);
|
|
29
|
-
--secondary: oklch(0.97 0 0);
|
|
30
|
-
--secondary-foreground: oklch(0.205 0 0);
|
|
31
|
-
--muted: oklch(0.97 0 0);
|
|
32
|
-
--muted-foreground: oklch(0.556 0 0);
|
|
33
|
-
--accent: oklch(0.97 0 0);
|
|
34
|
-
--accent-foreground: oklch(0.205 0 0);
|
|
35
|
-
--destructive: oklch(0.577 0.245 27.325);
|
|
36
|
-
--destructive-foreground: oklch(0.577 0.245 27.325);
|
|
37
|
-
--border: oklch(0.922 0 0);
|
|
38
|
-
--input: oklch(0.922 0 0);
|
|
39
|
-
--ring: oklch(0.708 0 0);
|
|
40
|
-
--chart-1: oklch(0.646 0.222 41.116);
|
|
41
|
-
--chart-2: oklch(0.6 0.118 184.704);
|
|
42
|
-
--chart-3: oklch(0.398 0.07 227.392);
|
|
43
|
-
--chart-4: oklch(0.828 0.189 84.429);
|
|
44
|
-
--chart-5: oklch(0.769 0.188 70.08);
|
|
45
|
-
--radius: 0.625rem;
|
|
46
|
-
--sidebar: oklch(0.985 0 0);
|
|
47
|
-
--sidebar-foreground: oklch(0.145 0 0);
|
|
48
|
-
--sidebar-primary: oklch(0.205 0 0);
|
|
49
|
-
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
50
|
-
--sidebar-accent: oklch(0.97 0 0);
|
|
51
|
-
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
52
|
-
--sidebar-border: oklch(0.922 0 0);
|
|
53
|
-
--sidebar-ring: oklch(0.708 0 0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.dark {
|
|
57
|
-
--background: oklch(0.145 0 0);
|
|
58
|
-
--foreground: oklch(0.985 0 0);
|
|
59
|
-
--card: oklch(0.145 0 0);
|
|
60
|
-
--card-foreground: oklch(0.985 0 0);
|
|
61
|
-
--popover: oklch(0.145 0 0);
|
|
62
|
-
--popover-foreground: oklch(0.985 0 0);
|
|
63
|
-
--primary: oklch(0.985 0 0);
|
|
64
|
-
--primary-foreground: oklch(0.205 0 0);
|
|
65
|
-
--secondary: oklch(0.269 0 0);
|
|
66
|
-
--secondary-foreground: oklch(0.985 0 0);
|
|
67
|
-
--muted: oklch(0.269 0 0);
|
|
68
|
-
--muted-foreground: oklch(0.708 0 0);
|
|
69
|
-
--accent: oklch(0.269 0 0);
|
|
70
|
-
--accent-foreground: oklch(0.985 0 0);
|
|
71
|
-
--destructive: oklch(0.396 0.141 25.723);
|
|
72
|
-
--destructive-foreground: oklch(0.637 0.237 25.331);
|
|
73
|
-
--border: oklch(0.269 0 0);
|
|
74
|
-
--input: oklch(0.269 0 0);
|
|
75
|
-
--ring: oklch(0.439 0 0);
|
|
76
|
-
--chart-1: oklch(0.488 0.243 264.376);
|
|
77
|
-
--chart-2: oklch(0.696 0.17 162.48);
|
|
78
|
-
--chart-3: oklch(0.769 0.188 70.08);
|
|
79
|
-
--chart-4: oklch(0.627 0.265 303.9);
|
|
80
|
-
--chart-5: oklch(0.645 0.246 16.439);
|
|
81
|
-
--sidebar: oklch(0.205 0 0);
|
|
82
|
-
--sidebar-foreground: oklch(0.985 0 0);
|
|
83
|
-
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
84
|
-
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
85
|
-
--sidebar-accent: oklch(0.269 0 0);
|
|
86
|
-
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
87
|
-
--sidebar-border: oklch(0.269 0 0);
|
|
88
|
-
--sidebar-ring: oklch(0.439 0 0);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@theme inline {
|
|
92
|
-
--color-background: var(--background);
|
|
93
|
-
--color-foreground: var(--foreground);
|
|
94
|
-
--color-card: var(--card);
|
|
95
|
-
--color-card-foreground: var(--card-foreground);
|
|
96
|
-
--color-popover: var(--popover);
|
|
97
|
-
--color-popover-foreground: var(--popover-foreground);
|
|
98
|
-
--color-primary: var(--primary);
|
|
99
|
-
--color-primary-foreground: var(--primary-foreground);
|
|
100
|
-
--color-secondary: var(--secondary);
|
|
101
|
-
--color-secondary-foreground: var(--secondary-foreground);
|
|
102
|
-
--color-muted: var(--muted);
|
|
103
|
-
--color-muted-foreground: var(--muted-foreground);
|
|
104
|
-
--color-accent: var(--accent);
|
|
105
|
-
--color-accent-foreground: var(--accent-foreground);
|
|
106
|
-
--color-destructive: var(--destructive);
|
|
107
|
-
--color-destructive-foreground: var(--destructive-foreground);
|
|
108
|
-
--color-border: var(--border);
|
|
109
|
-
--color-input: var(--input);
|
|
110
|
-
--color-ring: var(--ring);
|
|
111
|
-
--color-chart-1: var(--chart-1);
|
|
112
|
-
--color-chart-2: var(--chart-2);
|
|
113
|
-
--color-chart-3: var(--chart-3);
|
|
114
|
-
--color-chart-4: var(--chart-4);
|
|
115
|
-
--color-chart-5: var(--chart-5);
|
|
116
|
-
--radius-sm: calc(var(--radius) - 4px);
|
|
117
|
-
--radius-md: calc(var(--radius) - 2px);
|
|
118
|
-
--radius-lg: var(--radius);
|
|
119
|
-
--radius-xl: calc(var(--radius) + 4px);
|
|
120
|
-
--color-sidebar: var(--sidebar);
|
|
121
|
-
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
122
|
-
--color-sidebar-primary: var(--sidebar-primary);
|
|
123
|
-
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
124
|
-
--color-sidebar-accent: var(--sidebar-accent);
|
|
125
|
-
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
126
|
-
--color-sidebar-border: var(--sidebar-border);
|
|
127
|
-
--color-sidebar-ring: var(--sidebar-ring);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
@layer base {
|
|
131
|
-
* {
|
|
132
|
-
@apply border-border outline-ring/50;
|
|
133
|
-
}
|
|
134
|
-
body {
|
|
135
|
-
@apply bg-background text-foreground;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. Install library
|
|
5
|
+
## Installation
|
|
141
6
|
|
|
142
7
|
```bash
|
|
143
8
|
npm install @sustaina/shared-ui
|
|
144
9
|
```
|
|
145
10
|
|
|
146
|
-
|
|
11
|
+
## Setup
|
|
147
12
|
|
|
148
|
-
|
|
13
|
+
Import the stylesheet in your app entry point:
|
|
149
14
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
npm install react react-dom react-hook-form
|
|
15
|
+
```ts
|
|
16
|
+
import "@sustaina/shared-ui/dist/index.css";
|
|
154
17
|
```
|
|
155
18
|
|
|
156
|
-
|
|
19
|
+
## Usage
|
|
157
20
|
|
|
158
|
-
```
|
|
159
|
-
{
|
|
160
|
-
"peerDependencies": {
|
|
161
|
-
"react": "^18.0.0 || ^19.0.0",
|
|
162
|
-
"react-dom": "^18.0.0 || ^19.0.0",
|
|
163
|
-
"react-hook-form": "^7.61.1"
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
> β οΈ If your project doesn't match the version ranges above, you may get runtime or type errors.
|
|
21
|
+
```tsx
|
|
22
|
+
import { Button, Dialog, DataTable, DatePicker } from "@sustaina/shared-ui";
|
|
169
23
|
|
|
170
|
-
|
|
24
|
+
// Button
|
|
25
|
+
<Button variant="default" onClick={() => console.log("clicked")}>
|
|
26
|
+
Submit
|
|
27
|
+
</Button>
|
|
171
28
|
|
|
172
|
-
|
|
29
|
+
// Dialog
|
|
30
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
31
|
+
<DialogContent>
|
|
32
|
+
<p>Hello from shared dialog</p>
|
|
33
|
+
</DialogContent>
|
|
34
|
+
</Dialog>
|
|
173
35
|
|
|
174
|
-
|
|
36
|
+
// DatePicker
|
|
37
|
+
<DatePicker value={date} onChange={setDate} />
|
|
175
38
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
@import "@sustaina/shared-ui/styles.css"; /* this include styles/theme.css already */
|
|
179
|
-
@source "../../node_modules/@sustaina/shared-ui/dist"; /* depend your root CSS file locate. */
|
|
180
|
-
... omit code
|
|
39
|
+
// DataTable
|
|
40
|
+
<DataTable columns={columns} data={rows} />
|
|
181
41
|
```
|
|
182
42
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
43
|
+
## Available Components
|
|
44
|
+
|
|
45
|
+
| Component | Description |
|
|
46
|
+
| ------------------------------- | ---------------------------- |
|
|
47
|
+
| `Button` | Base button with variants |
|
|
48
|
+
| `Dialog` / `DialogAlert` | Modal dialogs |
|
|
49
|
+
| `DataTable` | Sortable, filterable table |
|
|
50
|
+
| `DatePicker` / `DateTimePicker` | Date & time selection |
|
|
51
|
+
| `Combobox` | Searchable select |
|
|
52
|
+
| `Form` | Form wrapper with validation |
|
|
53
|
+
| `Checkbox` | Checkbox input |
|
|
54
|
+
| `DropdownMenu` | Dropdown menu |
|
|
55
|
+
| `Accordion` | Collapsible sections |
|
|
56
|
+
| `Carousel` | Image/content carousel |
|
|
57
|
+
| `ActionMenu` | Context action menu |
|
|
58
|
+
| `AdvanceSearch` | Advanced search panel |
|
|
59
|
+
| `AuditFooter` | Audit trail footer |
|
|
60
|
+
| `CropperModal` | Image cropper modal |
|
|
61
|
+
|
|
62
|
+
## Hooks & Utils
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { useDebounce, formatDate } from "@sustaina/shared-ui";
|
|
195
66
|
```
|
|
196
67
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# Developer Notes
|
|
200
|
-
|
|
201
|
-
## Git Flow
|
|
202
|
-
|
|
203
|
-
### How to developed
|
|
204
|
-
|
|
205
|
-
We follow a **`feature/xxx` β `dev` β `prod`** workflow:
|
|
206
|
-
|
|
207
|
-
- Developed on `feature/xxx` or `bugfix/xxx` or any what you want. Then **merge request** to `dev`
|
|
208
|
-
- Only `prod` branch triggers **npm package publishing**.
|
|
209
|
-
- To publish a new version:
|
|
210
|
-
- Create a **merge request from `dev` to `prod`**, or
|
|
211
|
-
- Contact your lead developer or maintainer to perform the merge.
|
|
212
|
-
|
|
213
|
-
### Versioning & Commits
|
|
214
|
-
|
|
215
|
-
We use **semantic versioning**:
|
|
216
|
-
|
|
217
|
-
- `patch` β bug fixes (`fix: description`)
|
|
218
|
-
- `minor` β new features (`feat: description`)
|
|
219
|
-
- All other commit types (e.g., `docs`, `chore`, `refactor`) **do not trigger a version change**.
|
|
220
|
-
|
|
221
|
-
**<em>no major change for now just use `patch` and `minor`</em>**
|
|
222
|
-
|
|
223
|
-
## CSS and Custom Styling
|
|
224
|
-
|
|
225
|
-
- **Prefer Tailwind classes inline** whenever possible.
|
|
226
|
-
- If additional CSS is needed, include it in your components.
|
|
227
|
-
- **Important:** After running `npm run build`, always check `dist/index.css` to ensure your custom styles are included in the final build.
|
|
228
|
-
|
|
229
|
-
- **Use `styles/theme.css` for global customizations**:
|
|
230
|
-
- Store custom shorthand colors, CSS variables, or utility classes here.
|
|
231
|
-
- <span style="color:red; font-weight:bold; text-decoration:underline; font-style:italic;">These styles will be available to consumers when they import the library `Go check step 3`.</span>
|
|
232
|
-
- Example:
|
|
233
|
-
```css
|
|
234
|
-
@theme {
|
|
235
|
-
--color-sus-primary-1: #000;
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
- **Reference:** [Tailwind Theme Variable Namespaces](https://tailwindcss.com/docs/theme#theme-variable-namespaces)
|
|
239
|
-
|
|
240
|
-
## Including External Files in the Build
|
|
68
|
+
## Peer Dependencies
|
|
241
69
|
|
|
242
|
-
-
|
|
243
|
-
|
|
244
|
-
- Example entry:
|
|
245
|
-
```js
|
|
246
|
-
const filesToCopy = [
|
|
247
|
-
{
|
|
248
|
-
from: "./src/styles/theme.css",
|
|
249
|
-
to: "./dist/index.css",
|
|
250
|
-
mode: "prepend" // "replace" | "append" | "prepend"
|
|
251
|
-
}
|
|
252
|
-
];
|
|
253
|
-
```
|
|
70
|
+
- React `^18`
|
|
71
|
+
- Tailwind CSS `^3`
|
|
254
72
|
|
|
255
|
-
|
|
256
|
-
- `"replace"` β overwrite the destination file completely.
|
|
257
|
-
- `"append"` β add content at the end of the destination file.
|
|
258
|
-
- `"prepend"` β add content at the beginning of the destination file.
|
|
259
|
-
- This script handles copying files into the `dist` folder during the build process.
|
|
260
|
-
- After copying files, you can export them for consumers.
|
|
261
|
-
- Add `exports` your file in `package.json`
|
|
262
|
-
```json
|
|
263
|
-
"exports": {
|
|
264
|
-
".": {
|
|
265
|
-
"require": "./dist/index.js",
|
|
266
|
-
"import": "./dist/index.mjs",
|
|
267
|
-
"types": "./dist/index.d.ts"
|
|
268
|
-
},
|
|
269
|
-
"./styles.css": "./dist/index.css",
|
|
270
|
-
"./helpers": "./dist/helpers.js"
|
|
271
|
-
}
|
|
272
|
-
```
|
|
273
|
-
- **Note:** This will happen automatically when you run `npm run build`.
|
|
73
|
+
## test
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# Sustaina - Shared UI
|
|
2
|
+
|
|
3
|
+
# π¦ Installation
|
|
4
|
+
|
|
5
|
+
To use `@sustaina/shared-ui` in your project, follow these steps carefully.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Install UI package and required dependencies
|
|
10
|
+
|
|
11
|
+
Make sure you've installed [TailwindCSS](https://tailwindcss.com/docs/installation) and [shadcn/ui](https://ui.shadcn.com/docs/installation/manual) before installing our library. **Donβt skip this.**
|
|
12
|
+
|
|
13
|
+
### 1. Place shadcn/ui styles
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
@import "tailwindcss";
|
|
17
|
+
@import "tw-animate-css";
|
|
18
|
+
@custom-variant dark (&:is(.dark *));
|
|
19
|
+
|
|
20
|
+
:root {
|
|
21
|
+
--background: oklch(1 0 0);
|
|
22
|
+
--foreground: oklch(0.145 0 0);
|
|
23
|
+
--card: oklch(1 0 0);
|
|
24
|
+
--card-foreground: oklch(0.145 0 0);
|
|
25
|
+
--popover: oklch(1 0 0);
|
|
26
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
27
|
+
--primary: oklch(0.205 0 0);
|
|
28
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
29
|
+
--secondary: oklch(0.97 0 0);
|
|
30
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
31
|
+
--muted: oklch(0.97 0 0);
|
|
32
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
33
|
+
--accent: oklch(0.97 0 0);
|
|
34
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
35
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
36
|
+
--destructive-foreground: oklch(0.577 0.245 27.325);
|
|
37
|
+
--border: oklch(0.922 0 0);
|
|
38
|
+
--input: oklch(0.922 0 0);
|
|
39
|
+
--ring: oklch(0.708 0 0);
|
|
40
|
+
--chart-1: oklch(0.646 0.222 41.116);
|
|
41
|
+
--chart-2: oklch(0.6 0.118 184.704);
|
|
42
|
+
--chart-3: oklch(0.398 0.07 227.392);
|
|
43
|
+
--chart-4: oklch(0.828 0.189 84.429);
|
|
44
|
+
--chart-5: oklch(0.769 0.188 70.08);
|
|
45
|
+
--radius: 0.625rem;
|
|
46
|
+
--sidebar: oklch(0.985 0 0);
|
|
47
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
48
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
49
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
50
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
51
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
52
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
53
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.dark {
|
|
57
|
+
--background: oklch(0.145 0 0);
|
|
58
|
+
--foreground: oklch(0.985 0 0);
|
|
59
|
+
--card: oklch(0.145 0 0);
|
|
60
|
+
--card-foreground: oklch(0.985 0 0);
|
|
61
|
+
--popover: oklch(0.145 0 0);
|
|
62
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
63
|
+
--primary: oklch(0.985 0 0);
|
|
64
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
65
|
+
--secondary: oklch(0.269 0 0);
|
|
66
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
67
|
+
--muted: oklch(0.269 0 0);
|
|
68
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
69
|
+
--accent: oklch(0.269 0 0);
|
|
70
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
71
|
+
--destructive: oklch(0.396 0.141 25.723);
|
|
72
|
+
--destructive-foreground: oklch(0.637 0.237 25.331);
|
|
73
|
+
--border: oklch(0.269 0 0);
|
|
74
|
+
--input: oklch(0.269 0 0);
|
|
75
|
+
--ring: oklch(0.439 0 0);
|
|
76
|
+
--chart-1: oklch(0.488 0.243 264.376);
|
|
77
|
+
--chart-2: oklch(0.696 0.17 162.48);
|
|
78
|
+
--chart-3: oklch(0.769 0.188 70.08);
|
|
79
|
+
--chart-4: oklch(0.627 0.265 303.9);
|
|
80
|
+
--chart-5: oklch(0.645 0.246 16.439);
|
|
81
|
+
--sidebar: oklch(0.205 0 0);
|
|
82
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
83
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
84
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
85
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
86
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
87
|
+
--sidebar-border: oklch(0.269 0 0);
|
|
88
|
+
--sidebar-ring: oklch(0.439 0 0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@theme inline {
|
|
92
|
+
--color-background: var(--background);
|
|
93
|
+
--color-foreground: var(--foreground);
|
|
94
|
+
--color-card: var(--card);
|
|
95
|
+
--color-card-foreground: var(--card-foreground);
|
|
96
|
+
--color-popover: var(--popover);
|
|
97
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
98
|
+
--color-primary: var(--primary);
|
|
99
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
100
|
+
--color-secondary: var(--secondary);
|
|
101
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
102
|
+
--color-muted: var(--muted);
|
|
103
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
104
|
+
--color-accent: var(--accent);
|
|
105
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
106
|
+
--color-destructive: var(--destructive);
|
|
107
|
+
--color-destructive-foreground: var(--destructive-foreground);
|
|
108
|
+
--color-border: var(--border);
|
|
109
|
+
--color-input: var(--input);
|
|
110
|
+
--color-ring: var(--ring);
|
|
111
|
+
--color-chart-1: var(--chart-1);
|
|
112
|
+
--color-chart-2: var(--chart-2);
|
|
113
|
+
--color-chart-3: var(--chart-3);
|
|
114
|
+
--color-chart-4: var(--chart-4);
|
|
115
|
+
--color-chart-5: var(--chart-5);
|
|
116
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
117
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
118
|
+
--radius-lg: var(--radius);
|
|
119
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
120
|
+
--color-sidebar: var(--sidebar);
|
|
121
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
122
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
123
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
124
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
125
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
126
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
127
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@layer base {
|
|
131
|
+
* {
|
|
132
|
+
@apply border-border outline-ring/50;
|
|
133
|
+
}
|
|
134
|
+
body {
|
|
135
|
+
@apply bg-background text-foreground;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 2. Install library
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm install @sustaina/shared-ui
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
### Peer Dependencies
|
|
149
|
+
|
|
150
|
+
You must manually install these peer dependencies in your host project:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm install react react-dom react-hook-form
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Supported versions:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"peerDependencies": {
|
|
161
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
162
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
163
|
+
"react-hook-form": "^7.61.1"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
> β οΈ If your project doesn't match the version ranges above, you may get runtime or type errors.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 3. Add `@sustaina/shared-ui` to your CSS
|
|
173
|
+
|
|
174
|
+
To make styling work with our components, add this to your `index.css` or root CSS file:
|
|
175
|
+
|
|
176
|
+
```css
|
|
177
|
+
... omit code
|
|
178
|
+
@import "@sustaina/shared-ui/styles.css"; /* this include styles/theme.css already */
|
|
179
|
+
@source "../../node_modules/@sustaina/shared-ui/dist"; /* depend your root CSS file locate. */
|
|
180
|
+
... omit code
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
# Usage
|
|
186
|
+
|
|
187
|
+
Import `@sustaina/shared-ui` components within your React component files:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { Button } from "@sustaina/shared-ui";
|
|
191
|
+
|
|
192
|
+
export default function MyComponent() {
|
|
193
|
+
return <Button color="primary">Click me!</Button>;
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
# Developer Notes
|
|
200
|
+
|
|
201
|
+
## Git Flow
|
|
202
|
+
|
|
203
|
+
### How to developed
|
|
204
|
+
|
|
205
|
+
We follow a **`feature/xxx` β `dev` β `prod`** workflow:
|
|
206
|
+
|
|
207
|
+
- Developed on `feature/xxx` or `bugfix/xxx` or any what you want. Then **merge request** to `dev`
|
|
208
|
+
- Only `prod` branch triggers **npm package publishing**.
|
|
209
|
+
- To publish a new version:
|
|
210
|
+
- Create a **merge request from `dev` to `prod`**, or
|
|
211
|
+
- Contact your lead developer or maintainer to perform the merge.
|
|
212
|
+
|
|
213
|
+
### Versioning & Commits
|
|
214
|
+
|
|
215
|
+
We use **semantic versioning**:
|
|
216
|
+
|
|
217
|
+
- `patch` β bug fixes (`fix: description`)
|
|
218
|
+
- `minor` β new features (`feat: description`)
|
|
219
|
+
- All other commit types (e.g., `docs`, `chore`, `refactor`) **do not trigger a version change**.
|
|
220
|
+
|
|
221
|
+
**<em>no major change for now just use `patch` and `minor`</em>**
|
|
222
|
+
|
|
223
|
+
## CSS and Custom Styling
|
|
224
|
+
|
|
225
|
+
- **Prefer Tailwind classes inline** whenever possible.
|
|
226
|
+
- If additional CSS is needed, include it in your components.
|
|
227
|
+
- **Important:** After running `npm run build`, always check `dist/index.css` to ensure your custom styles are included in the final build.
|
|
228
|
+
|
|
229
|
+
- **Use `styles/theme.css` for global customizations**:
|
|
230
|
+
- Store custom shorthand colors, CSS variables, or utility classes here.
|
|
231
|
+
- <span style="color:red; font-weight:bold; text-decoration:underline; font-style:italic;">These styles will be available to consumers when they import the library `Go check step 3`.</span>
|
|
232
|
+
- Example:
|
|
233
|
+
```css
|
|
234
|
+
@theme {
|
|
235
|
+
--color-sus-primary-1: #000;
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
- **Reference:** [Tailwind Theme Variable Namespaces](https://tailwindcss.com/docs/theme#theme-variable-namespaces)
|
|
239
|
+
|
|
240
|
+
## Including External Files in the Build
|
|
241
|
+
|
|
242
|
+
- **Add your files to `copy-files-to-dist.js`**:
|
|
243
|
+
- This script handles copying files into the `dist` folder during the build process.
|
|
244
|
+
- Example entry:
|
|
245
|
+
```js
|
|
246
|
+
const filesToCopy = [
|
|
247
|
+
{
|
|
248
|
+
from: "./src/styles/theme.css",
|
|
249
|
+
to: "./dist/index.css",
|
|
250
|
+
mode: "prepend" // "replace" | "append" | "prepend"
|
|
251
|
+
}
|
|
252
|
+
];
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
- **How `mode` works:**
|
|
256
|
+
- `"replace"` β overwrite the destination file completely.
|
|
257
|
+
- `"append"` β add content at the end of the destination file.
|
|
258
|
+
- `"prepend"` β add content at the beginning of the destination file.
|
|
259
|
+
- This script handles copying files into the `dist` folder during the build process.
|
|
260
|
+
- After copying files, you can export them for consumers.
|
|
261
|
+
- Add `exports` your file in `package.json`
|
|
262
|
+
```json
|
|
263
|
+
"exports": {
|
|
264
|
+
".": {
|
|
265
|
+
"require": "./dist/index.js",
|
|
266
|
+
"import": "./dist/index.mjs",
|
|
267
|
+
"types": "./dist/index.d.ts"
|
|
268
|
+
},
|
|
269
|
+
"./styles.css": "./dist/index.css",
|
|
270
|
+
"./helpers": "./dist/helpers.js"
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
- **Note:** This will happen automatically when you run `npm run build`.
|