@weichenlin/swell-ui 0.2.0 → 0.3.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 +105 -35
- package/dist/index.d.ts +106 -6
- package/dist/index.js +463 -138
- package/dist/theme.css +185 -77
- package/package.json +1 -2
- package/dist/themes/warm.css +0 -63
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Hand-built React 19 components styled with Tailwind CSS v4: Badge, Button, Card, Checkbox,
|
|
4
4
|
CheckboxGroup, Dialog, Drawer, Input (plus Search, Password and Copy), Meter, Select, Sidebar,
|
|
5
|
-
Switch, Tabs, TabNav, ThemeSwitcher, Toast and Tooltip.
|
|
5
|
+
Switch, Table, Tabs, TabNav, ThemeSwitcher, Toast and Tooltip.
|
|
6
6
|
|
|
7
7
|
The package ships ESM, type declarations and two CSS files. Your app compiles the CSS with its own
|
|
8
8
|
Tailwind v4, so the design tokens become your utilities too (`bg-primary`, `text-fg`, ...).
|
|
@@ -38,6 +38,28 @@ export function App() {
|
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
### Table
|
|
42
|
+
|
|
43
|
+
Pass the current rows, column definitions, and a stable row ID. Add `search`, `sorting`, `pagination`,
|
|
44
|
+
or `selection` to show controlled UI. The caller handles filtering, sorting, and fetching or slicing
|
|
45
|
+
rows. The pagination `rowCount` is the total after filtering, before paging.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { Table } from '@weichenlin/swell-ui'
|
|
49
|
+
|
|
50
|
+
;<Table
|
|
51
|
+
title="Deployments"
|
|
52
|
+
data={deployments}
|
|
53
|
+
getRowId={(row) => row.id}
|
|
54
|
+
columns={[
|
|
55
|
+
{ id: 'service', header: 'Service', rowHeader: true, cell: (row) => row.service },
|
|
56
|
+
{ id: 'duration', header: 'Duration', numeric: true, cell: (row) => row.duration },
|
|
57
|
+
]}
|
|
58
|
+
emptyState="No deployments yet"
|
|
59
|
+
noResults="No matching deployments"
|
|
60
|
+
/>
|
|
61
|
+
```
|
|
62
|
+
|
|
41
63
|
### Change the brand
|
|
42
64
|
|
|
43
65
|
The default look is neutral gray with a near-black primary. A rebrand is two tokens, set once,
|
|
@@ -79,49 +101,80 @@ contrast, override just that one:
|
|
|
79
101
|
Set tokens in `@theme` (or a plain `:root` rule) rather than on an inner element: the derived
|
|
80
102
|
tokens are resolved on the root.
|
|
81
103
|
|
|
104
|
+
### Change the palette
|
|
105
|
+
|
|
106
|
+
Colors come in two layers. A handful of **base colors** carry literal values; every other color
|
|
107
|
+
token is computed from them at runtime (`var()` and `color-mix()`), so overriding a base color
|
|
108
|
+
carries through to borders, muted text, fields, tints and so on:
|
|
109
|
+
|
|
110
|
+
```css
|
|
111
|
+
@theme {
|
|
112
|
+
--color-bg: light-dark(#f5f4ed, #141413);
|
|
113
|
+
--color-surface: light-dark(#faf9f5, #30302e);
|
|
114
|
+
--color-fg: light-dark(#141413, #faf9f5);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The mix percentages are tuned so the default palette, and a warm one like the example above, pass WCAG contrast (text >=4.5:1,
|
|
119
|
+
field borders >=3:1). A palette far from these (a mid-tone page, low-contrast text) can fall
|
|
120
|
+
short, so check contrast after changing `bg`, `surface` or `fg`. Any computed token can still be
|
|
121
|
+
overridden on its own.
|
|
122
|
+
|
|
123
|
+
Override at the root (`@theme` or `:root`): computed tokens are resolved there, so a base color
|
|
124
|
+
set on an inner element does not reach them.
|
|
125
|
+
|
|
82
126
|
### Tokens
|
|
83
127
|
|
|
84
|
-
Every
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
| `--color-bg`
|
|
92
|
-
| `--color-surface
|
|
93
|
-
| `--color-
|
|
94
|
-
| `--color-
|
|
95
|
-
| `--color-
|
|
96
|
-
| `--color-
|
|
97
|
-
| `--color-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
| `--color-
|
|
104
|
-
| `--color-
|
|
105
|
-
| `--color-
|
|
106
|
-
| `--color-
|
|
107
|
-
| `--color-
|
|
108
|
-
| `--color-
|
|
109
|
-
| `--color-
|
|
110
|
-
| `--color-
|
|
111
|
-
| `--
|
|
112
|
-
| `--
|
|
113
|
-
|
|
114
|
-
|
|
128
|
+
Every pair is written `light-dark(<light>, <dark>)`; override it the same way, once. All color
|
|
129
|
+
tokens are also Tailwind utilities (`bg-surface`, `text-fg-muted`, `border-input-border`, ...).
|
|
130
|
+
|
|
131
|
+
**Base colors**
|
|
132
|
+
|
|
133
|
+
| Token | Used for |
|
|
134
|
+
| --------------------------------------- | ------------------------------------------------------ |
|
|
135
|
+
| `--color-bg` | Page background |
|
|
136
|
+
| `--color-surface` | Cards, panels and text fields |
|
|
137
|
+
| `--color-surface-raised` | Popovers and dialogs |
|
|
138
|
+
| `--color-fg` | Text |
|
|
139
|
+
| `--color-primary`, `--color-primary-fg` | Brand fill and the text on it. Default: `fg` (neutral) |
|
|
140
|
+
| `--color-focus` | Keyboard focus outline (blue) |
|
|
141
|
+
| `--color-{danger,success,warning,info}` | Status tones: solid fill, icon, and danger text |
|
|
142
|
+
|
|
143
|
+
**Computed** (from the base colors; override only to fine-tune)
|
|
144
|
+
|
|
145
|
+
| Token | Used for | Computed from |
|
|
146
|
+
| ------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
147
|
+
| `--color-accent` | Secondary brand color; unused by components | `primary` |
|
|
148
|
+
| `--color-surface-muted` | Hover fills, secondary button | fg into bg |
|
|
149
|
+
| `--color-fg-strong`, `-fg-muted`, `-fg-subtle` | Text from strong to quiet (`fg-subtle` >=4.5:1 on every surface) | fg into bg |
|
|
150
|
+
| `--color-border`, `-border-strong`, `-ring`, `-ring-deep` | Dividers, hairlines, 1px button and tab-list rings | fg into bg |
|
|
151
|
+
| `--color-inverse`, `-inverse-fg` | `dark` button, tooltips | fg into bg; the page on dark |
|
|
152
|
+
| `--color-input-bg`, `-input-bg-hover` | Text field fill (read-only fields use `bg`) | `surface` |
|
|
153
|
+
| `--color-input-border`, `-input-border-hover` | Field border; also the off track of Switch and box of Checkbox | fg into bg; `fg-strong` |
|
|
154
|
+
| `--color-input-placeholder` | Placeholder text | fg into bg |
|
|
155
|
+
| `--color-input-focus`, `-input-halo` | Focused field border and its 3px ring | `primary`; input-focus at 14% |
|
|
156
|
+
| `--color-input-halo-invalid`, `-invalid-focus` | Same ring for invalid fields | danger at 12% / 22% |
|
|
157
|
+
| `--color-control-checked`, `-control-checked-fg` | Checked Switch/Checkbox fill and the check on it | `primary` / `primary-fg` |
|
|
158
|
+
| `--color-switch-handle`, `-switch-handle-checked` | Switch thumb, off / on | off: `surface-raised` / dark `fg`; on: white or black by track lightness |
|
|
159
|
+
| `--color-popover-bg`, `-popover-border`, `-popover-highlight` | Select picker and dialogs; highlight is the active row | `surface-raised`, fg into it |
|
|
160
|
+
| `--color-dialog-backdrop` | Dimmed page behind Dialog and Drawer | fg at 40%; black at 60% on dark |
|
|
161
|
+
| `--color-neutral` | Neutral status tone | fg into bg |
|
|
162
|
+
| `--color-{tone}-fg` | Text on a solid status fill | `surface` / `bg` |
|
|
163
|
+
| `--color-{tone}-subtle-bg`, `-border` | Tinted badge and its hairline | tone into bg |
|
|
164
|
+
| `--color-{tone}-subtle-fg` | Text on the tinted badge (>=5:1) | tone pushed toward fg |
|
|
165
|
+
|
|
166
|
+
Shadows (`--shadow-input`, `-input-lift`, `-switch-thumb`, `-popover`, `-dialog`, `-whisper`) and
|
|
167
|
+
the input highlight are black or white at low opacity: they shade, so they have no palette color.
|
|
168
|
+
`--container-page` is `max-w-page` (1200px).
|
|
169
|
+
|
|
170
|
+
### Serif headings
|
|
115
171
|
|
|
116
172
|
```css
|
|
117
173
|
@import 'tailwindcss';
|
|
118
174
|
@import '@weichenlin/swell-ui/styles.css';
|
|
119
|
-
@import '@weichenlin/swell-ui/themes/warm.css'; /* parchment surfaces, brown primary */
|
|
120
175
|
@import '@weichenlin/swell-ui/typography.css'; /* h1-h3 in the serif stack, weight 500 */
|
|
121
176
|
```
|
|
122
177
|
|
|
123
|
-
Both are independent; your own `@theme` overrides go after them.
|
|
124
|
-
|
|
125
178
|
### Fonts
|
|
126
179
|
|
|
127
180
|
swell-ui sets no font names: text uses Tailwind's `--font-sans` (the system UI stack), and
|
|
@@ -266,6 +319,23 @@ links do) closes it.
|
|
|
266
319
|
</TabNav>
|
|
267
320
|
```
|
|
268
321
|
|
|
322
|
+
`Button` takes `asChild` too, for a navigation that should look like a button. It keeps the
|
|
323
|
+
button's look, icons and ripple, and stays a real link (open in a new tab, copy the URL):
|
|
324
|
+
|
|
325
|
+
```tsx
|
|
326
|
+
<Button asChild intent="secondary" iconLeft={<Plus />}>
|
|
327
|
+
<Link to="/apps/new">New app</Link>
|
|
328
|
+
</Button>
|
|
329
|
+
|
|
330
|
+
<Button asChild icon={<Settings />} aria-label="Settings">
|
|
331
|
+
<Link to="/settings" />
|
|
332
|
+
</Button>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
`disabled` (with or without `disabledReason`) works as on the button: the link stays focusable with
|
|
336
|
+
`aria-disabled`, and clicks are stopped before your Link sees them, so it never navigates. `loading`
|
|
337
|
+
and `type` are button-only.
|
|
338
|
+
|
|
269
339
|
## Develop
|
|
270
340
|
|
|
271
341
|
Node 26.11.1 (`.node-version`, via fnm) and pnpm 12.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { ClassValue } from "clsx";
|
|
2
2
|
import { VariantProps } from "class-variance-authority";
|
|
3
|
-
import { ComponentProps, MouseEvent, ReactElement, ReactNode } from "react";
|
|
3
|
+
import { ComponentProps, MouseEvent, MouseEventHandler, ReactElement, ReactNode } from "react";
|
|
4
|
+
//#region src/components/alert/alert.d.ts
|
|
5
|
+
type AlertTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
6
|
+
type AlertProps = Omit<ComponentProps<'div'>, 'title'> & {
|
|
7
|
+
tone?: AlertTone;
|
|
8
|
+
title?: ReactNode;
|
|
9
|
+
/** An action such as a retry button or a link to settings. */
|
|
10
|
+
action?: ReactNode;
|
|
11
|
+
/** Shows the dismiss button. The caller controls whether the Alert stays mounted. */
|
|
12
|
+
onDismiss?: MouseEventHandler<HTMLButtonElement>;
|
|
13
|
+
/** Accessible name of the dismiss button. */
|
|
14
|
+
dismissLabel?: string;
|
|
15
|
+
};
|
|
16
|
+
/** A persistent message shown next to the content it describes. Use a live region for updates that need announcing. */
|
|
17
|
+
export declare function Alert({ tone, title, action, onDismiss, dismissLabel, className, children, ...props }: AlertProps): import("react").JSX.Element;
|
|
18
|
+
//#endregion
|
|
4
19
|
//#region src/components/badge/badge.d.ts
|
|
5
20
|
type BadgeTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
6
21
|
type BadgeVariant = 'subtle' | 'outline' | 'solid';
|
|
@@ -63,14 +78,28 @@ type BaseProps = Omit<ComponentProps<'button'>, 'children'> & Omit<VariantProps<
|
|
|
63
78
|
/** Material-style press ripple; on by default. */
|
|
64
79
|
ripple?: boolean;
|
|
65
80
|
};
|
|
81
|
+
/** With `asChild` the host is your element (a router Link): loading and `type` are button-only. */
|
|
82
|
+
type AsChildProps = {
|
|
83
|
+
/**
|
|
84
|
+
* Render the only child (e.g. a router Link) instead of a `<button>`, with the button's props,
|
|
85
|
+
* classes, ref and content merged into it.
|
|
86
|
+
*/
|
|
87
|
+
asChild: true;
|
|
88
|
+
children: ReactElement;
|
|
89
|
+
loading?: never;
|
|
90
|
+
loadingText?: never;
|
|
91
|
+
type?: never;
|
|
92
|
+
};
|
|
66
93
|
type TextButtonProps = BaseProps & {
|
|
67
94
|
icon?: never;
|
|
68
95
|
iconLeft?: ReactNode;
|
|
69
96
|
iconRight?: ReactNode;
|
|
70
|
-
children?: ReactNode;
|
|
71
97
|
tooltip?: never;
|
|
72
98
|
tooltipSide?: never;
|
|
73
|
-
}
|
|
99
|
+
} & ({
|
|
100
|
+
asChild?: false;
|
|
101
|
+
children?: ReactNode;
|
|
102
|
+
} | AsChildProps);
|
|
74
103
|
type IconOnlyButtonProps = Omit<BaseProps, 'aria-label' | 'fullWidth'> & {
|
|
75
104
|
/** Renders a square icon-only button. */
|
|
76
105
|
icon: NonNullable<ReactNode>;
|
|
@@ -80,10 +109,12 @@ type IconOnlyButtonProps = Omit<BaseProps, 'aria-label' | 'fullWidth'> & {
|
|
|
80
109
|
tooltip?: boolean;
|
|
81
110
|
tooltipSide?: TooltipProps['side'];
|
|
82
111
|
fullWidth?: never;
|
|
83
|
-
children?: never;
|
|
84
112
|
iconLeft?: never;
|
|
85
113
|
iconRight?: never;
|
|
86
|
-
}
|
|
114
|
+
} & ({
|
|
115
|
+
asChild?: false;
|
|
116
|
+
children?: never;
|
|
117
|
+
} | AsChildProps);
|
|
87
118
|
type ButtonProps = TextButtonProps | IconOnlyButtonProps;
|
|
88
119
|
export declare function Button(props: ButtonProps): import("react").JSX.Element;
|
|
89
120
|
//#endregion
|
|
@@ -460,6 +491,75 @@ type SwitchProps = NativeSwitchProps & ChoiceLabelProps & {
|
|
|
460
491
|
};
|
|
461
492
|
export declare function Switch({ label, description, error, size, loading, labelPosition, className, inputClassName, disabled, onChange, 'aria-describedby': describedBy, 'aria-invalid': ariaInvalid, ...props }: SwitchProps): import("react").JSX.Element;
|
|
462
493
|
//#endregion
|
|
494
|
+
//#region src/components/table/table.d.ts
|
|
495
|
+
type TableColumn<T> = {
|
|
496
|
+
id: string;
|
|
497
|
+
header: ReactNode;
|
|
498
|
+
cell: (row: T) => ReactNode;
|
|
499
|
+
sortable?: boolean;
|
|
500
|
+
align?: 'start' | 'center' | 'end';
|
|
501
|
+
numeric?: boolean;
|
|
502
|
+
rowHeader?: boolean;
|
|
503
|
+
className?: string;
|
|
504
|
+
headerClassName?: string;
|
|
505
|
+
};
|
|
506
|
+
type TableSort = {
|
|
507
|
+
id: string;
|
|
508
|
+
direction: 'asc' | 'desc';
|
|
509
|
+
};
|
|
510
|
+
declare const labels: {
|
|
511
|
+
search: string;
|
|
512
|
+
clearSelection: string;
|
|
513
|
+
selectPage: string;
|
|
514
|
+
selectRow: (id: string) => string;
|
|
515
|
+
selectionCount: (count: number) => string;
|
|
516
|
+
scrollRegion: string;
|
|
517
|
+
pagination: string;
|
|
518
|
+
previousPage: string;
|
|
519
|
+
nextPage: string;
|
|
520
|
+
page: (page: number, count: number) => string;
|
|
521
|
+
range: (first: number, last: number, total: number) => string;
|
|
522
|
+
emptyState: string;
|
|
523
|
+
noResults: string;
|
|
524
|
+
};
|
|
525
|
+
type TableProps<T> = Omit<ComponentProps<'table'>, 'title' | 'children' | 'className'> & {
|
|
526
|
+
/** Rows to render on the current page, in display order. */
|
|
527
|
+
data: readonly T[];
|
|
528
|
+
columns: readonly TableColumn<T>[];
|
|
529
|
+
getRowId: (row: T) => string;
|
|
530
|
+
title?: ReactNode;
|
|
531
|
+
emptyState?: ReactNode;
|
|
532
|
+
noResults?: ReactNode;
|
|
533
|
+
/** Indicates filtering when the caller applies filters outside the search field. */
|
|
534
|
+
filtered?: boolean;
|
|
535
|
+
/** Controlled UI. The caller supplies the resulting data. */
|
|
536
|
+
search?: {
|
|
537
|
+
value: string;
|
|
538
|
+
onChange: (value: string) => void;
|
|
539
|
+
};
|
|
540
|
+
sorting?: {
|
|
541
|
+
value: TableSort | null;
|
|
542
|
+
onChange: (value: TableSort | null) => void;
|
|
543
|
+
};
|
|
544
|
+
pagination?: {
|
|
545
|
+
/** Zero-based page index. */
|
|
546
|
+
pageIndex: number;
|
|
547
|
+
pageSize: number;
|
|
548
|
+
rowCount: number;
|
|
549
|
+
onPageChange: (pageIndex: number) => void;
|
|
550
|
+
};
|
|
551
|
+
selection?: {
|
|
552
|
+
ids: ReadonlySet<string>;
|
|
553
|
+
onChange: (ids: Set<string>) => void;
|
|
554
|
+
canSelectRow?: (row: T) => boolean;
|
|
555
|
+
};
|
|
556
|
+
/** Root element classes. Use `tableClassName` for column layout or minimum width. */
|
|
557
|
+
className?: string;
|
|
558
|
+
tableClassName?: string;
|
|
559
|
+
labels?: Partial<typeof labels>;
|
|
560
|
+
};
|
|
561
|
+
export declare function Table<T>({ data, columns, getRowId, title, emptyState, noResults, filtered, search, sorting, pagination, selection, className, tableClassName, labels: labelOverrides, ...props }: TableProps<T>): import("react").JSX.Element;
|
|
562
|
+
//#endregion
|
|
463
563
|
//#region src/components/tabs/shared.d.ts
|
|
464
564
|
type TabsVariant = 'line' | 'segmented';
|
|
465
565
|
type TabsSize = 'sm' | 'md';
|
|
@@ -656,4 +756,4 @@ export declare function Toaster(props: ToasterProps): import("react").ReactPorta
|
|
|
656
756
|
//#region src/lib/cn.d.ts
|
|
657
757
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
658
758
|
//#endregion
|
|
659
|
-
export type { BadgeProps, BadgeTone, ButtonProps, CardHeaderProps, CardProps, CheckboxGroupProps, CheckboxProps, CopyInputProps, DialogCloseReason, DialogHeaderProps, DialogProps, DialogSize, DrawerCloseProps, DrawerCloseReason, DrawerHeaderProps, DrawerProps, DrawerSide, DrawerSize, InputProps, MeterProps, MeterSegment, MeterTone, PasswordInputProps, SearchInputProps, SelectGroup, SelectOption, SelectProps, SidebarGroupProps, SidebarItemProps, SidebarProps, SidebarTriggerProps, SwitchProps, SwitchSize, TabListProps, TabNavLinkProps, TabNavProps, TabPanelProps, TabProps, TabsActivationMode, TabsProps, TabsSize, TabsVariant, Theme, ThemeSwitcherProps, ToastActionButton, ToastOptions, ToastPatch, ToastPosition, ToastPromiseOptions, ToastType, ToasterProps, TooltipProps, UseThemeOptions };
|
|
759
|
+
export type { AlertProps, AlertTone, BadgeProps, BadgeTone, ButtonProps, CardHeaderProps, CardProps, CheckboxGroupProps, CheckboxProps, CopyInputProps, DialogCloseReason, DialogHeaderProps, DialogProps, DialogSize, DrawerCloseProps, DrawerCloseReason, DrawerHeaderProps, DrawerProps, DrawerSide, DrawerSize, InputProps, MeterProps, MeterSegment, MeterTone, PasswordInputProps, SearchInputProps, SelectGroup, SelectOption, SelectProps, SidebarGroupProps, SidebarItemProps, SidebarProps, SidebarTriggerProps, SwitchProps, SwitchSize, TabListProps, TabNavLinkProps, TabNavProps, TabPanelProps, TabProps, TableColumn, TableProps, TableSort, TabsActivationMode, TabsProps, TabsSize, TabsVariant, Theme, ThemeSwitcherProps, ToastActionButton, ToastOptions, ToastPatch, ToastPosition, ToastPromiseOptions, ToastType, ToasterProps, TooltipProps, UseThemeOptions };
|