@bwui/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +36 -2
- package/dist/alert.d.ts +8 -0
- package/dist/alert.js +11 -0
- package/dist/badge.d.ts +6 -0
- package/dist/badge.js +5 -0
- package/dist/button.d.ts +16 -0
- package/dist/button.js +12 -0
- package/dist/card.d.ts +9 -0
- package/dist/card.js +20 -0
- package/dist/chrome.d.ts +59 -0
- package/dist/chrome.js +75 -0
- package/dist/cn.d.ts +6 -0
- package/dist/cn.js +8 -0
- package/dist/combobox.d.ts +20 -0
- package/dist/combobox.js +70 -0
- package/dist/command.d.ts +16 -0
- package/dist/command.js +74 -0
- package/dist/data-table.d.ts +17 -0
- package/dist/data-table.js +17 -0
- package/dist/date-picker.d.ts +30 -0
- package/dist/date-picker.js +146 -0
- package/dist/form.d.ts +31 -0
- package/dist/form.js +55 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +17 -0
- package/dist/kbd.d.ts +2 -0
- package/dist/kbd.js +5 -0
- package/dist/layout.d.ts +10 -0
- package/dist/layout.js +23 -0
- package/dist/modal.d.ts +11 -0
- package/dist/modal.js +18 -0
- package/dist/pages.d.ts +42 -0
- package/dist/pages.js +84 -0
- package/dist/toast.d.ts +18 -0
- package/dist/toast.js +24 -0
- package/package.json +43 -3
- package/src/alert.tsx +36 -0
- package/src/badge.tsx +24 -0
- package/src/button.tsx +66 -0
- package/src/card.tsx +34 -0
- package/src/chrome.tsx +263 -0
- package/src/cn.ts +8 -0
- package/src/combobox.tsx +162 -0
- package/src/command.tsx +145 -0
- package/src/data-table.tsx +114 -0
- package/src/date-picker.tsx +357 -0
- package/src/form.tsx +201 -0
- package/src/index.ts +90 -0
- package/src/kbd.tsx +9 -0
- package/src/layout.tsx +44 -0
- package/src/modal.tsx +70 -0
- package/src/pages.tsx +361 -0
- package/src/toast.tsx +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nigel Copley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@bwui/react`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed React adapter for Brickwork. Components emit the same `bw-*` classes as
|
|
4
|
+
the HTML gallery and `django-brickwork`. Peer CSS is `@bwui/css`; this package
|
|
5
|
+
does not bundle the stylesheet.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bwui/react @bwui/css
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import "@bwui/css";
|
|
13
|
+
import { Homepage, Landing, ContactForm, Button, Field, Input } from "@bwui/react";
|
|
14
|
+
|
|
15
|
+
export function App() {
|
|
16
|
+
return <Homepage brand="Acme" />;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Four jobs
|
|
21
|
+
|
|
22
|
+
| Job | Export |
|
|
23
|
+
|---|---|
|
|
24
|
+
| Homepage | `<Homepage>` |
|
|
25
|
+
| Landing | `<Landing>` |
|
|
26
|
+
| Forms | `<Form>`, `<Field>`, `<Input>`, `<Checkbox>`, `<Combobox>`, `<DatePicker>`, `<DateRangePicker>`, `<TimeInput>`, `<ContactForm>` |
|
|
27
|
+
| Components | `<Button>`, `<Card>`, `<Modal>`, `<DataTable>`, `<CommandPalette>`, … |
|
|
28
|
+
|
|
29
|
+
Copy Pro gallery HTML from brickworkui.com. `@bwui/gallery` is not an npm
|
|
30
|
+
dependency.
|
|
31
|
+
|
|
32
|
+
## Stack mates
|
|
33
|
+
|
|
34
|
+
- HTML: `@bwui/css` + `@bwui/js`
|
|
35
|
+
- Vue: `@bwui/vue`
|
|
36
|
+
- Django: `django-brickwork` on PyPI
|
|
37
|
+
- Tailwind-first: `@bwui/tokens` + `@bwui/tailwind`
|
package/dist/alert.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type AlertVariant = 'default' | 'success' | 'warning' | 'danger' | 'info';
|
|
3
|
+
export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
variant?: AlertVariant;
|
|
5
|
+
}
|
|
6
|
+
export declare function Alert({ className, variant, ...props }: AlertProps): React.JSX.Element;
|
|
7
|
+
export declare function AlertTitle({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
8
|
+
export declare function AlertBody({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
package/dist/alert.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
export function Alert({ className, variant = 'default', ...props }) {
|
|
4
|
+
return (_jsx("div", { role: "alert", className: cn('bw-alert', variant !== 'default' && `bw-alert--${variant}`, className), ...props }));
|
|
5
|
+
}
|
|
6
|
+
export function AlertTitle({ className, ...props }) {
|
|
7
|
+
return _jsx("div", { className: cn('bw-alert__title', className), ...props });
|
|
8
|
+
}
|
|
9
|
+
export function AlertBody({ className, ...props }) {
|
|
10
|
+
return _jsx("div", { className: cn('bw-alert__body', className), ...props });
|
|
11
|
+
}
|
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type BadgeVariant = 'default' | 'secondary' | 'outline' | 'success' | 'warning' | 'danger' | 'info';
|
|
3
|
+
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
variant?: BadgeVariant;
|
|
5
|
+
}
|
|
6
|
+
export declare function Badge({ className, variant, ...props }: BadgeProps): React.JSX.Element;
|
package/dist/badge.js
ADDED
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger' | 'solid';
|
|
3
|
+
export type ButtonSize = 'sm' | 'md' | 'lg';
|
|
4
|
+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
variant?: ButtonVariant;
|
|
6
|
+
size?: ButtonSize;
|
|
7
|
+
}
|
|
8
|
+
export declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
9
|
+
export type ButtonLinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
10
|
+
variant?: ButtonVariant;
|
|
11
|
+
size?: ButtonSize;
|
|
12
|
+
};
|
|
13
|
+
export declare const ButtonLink: React.ForwardRefExoticComponent<React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
14
|
+
variant?: ButtonVariant;
|
|
15
|
+
size?: ButtonSize;
|
|
16
|
+
} & React.RefAttributes<HTMLAnchorElement>>;
|
package/dist/button.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cn } from './cn';
|
|
4
|
+
function buttonClasses(variant, size, className) {
|
|
5
|
+
return cn('bw-btn', `bw-btn--${variant}`, size !== 'md' && `bw-btn--${size}`, className);
|
|
6
|
+
}
|
|
7
|
+
export const Button = React.forwardRef(function Button({ className, variant = 'primary', size = 'md', type = 'button', ...props }, ref) {
|
|
8
|
+
return (_jsx("button", { ref: ref, type: type, className: buttonClasses(variant, size, className), ...props }));
|
|
9
|
+
});
|
|
10
|
+
export const ButtonLink = React.forwardRef(function ButtonLink({ className, variant = 'primary', size = 'md', ...props }, ref) {
|
|
11
|
+
return (_jsx("a", { ref: ref, className: buttonClasses(variant, size, className), ...props }));
|
|
12
|
+
});
|
package/dist/card.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export declare function Card({ className, ...props }: DivProps): React.JSX.Element;
|
|
4
|
+
export declare function CardHeader({ className, ...props }: DivProps): React.JSX.Element;
|
|
5
|
+
export declare function CardTitle({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>): React.JSX.Element;
|
|
6
|
+
export declare function CardDescription({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>): React.JSX.Element;
|
|
7
|
+
export declare function CardBody({ className, ...props }: DivProps): React.JSX.Element;
|
|
8
|
+
export declare function CardFooter({ className, ...props }: DivProps): React.JSX.Element;
|
|
9
|
+
export {};
|
package/dist/card.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
export function Card({ className, ...props }) {
|
|
4
|
+
return _jsx("div", { className: cn('bw-card', className), ...props });
|
|
5
|
+
}
|
|
6
|
+
export function CardHeader({ className, ...props }) {
|
|
7
|
+
return _jsx("div", { className: cn('bw-card__header', className), ...props });
|
|
8
|
+
}
|
|
9
|
+
export function CardTitle({ className, ...props }) {
|
|
10
|
+
return _jsx("h3", { className: cn('bw-card__title', className), ...props });
|
|
11
|
+
}
|
|
12
|
+
export function CardDescription({ className, ...props }) {
|
|
13
|
+
return _jsx("p", { className: cn('bw-card__description', className), ...props });
|
|
14
|
+
}
|
|
15
|
+
export function CardBody({ className, ...props }) {
|
|
16
|
+
return _jsx("div", { className: cn('bw-card__body', className), ...props });
|
|
17
|
+
}
|
|
18
|
+
export function CardFooter({ className, ...props }) {
|
|
19
|
+
return _jsx("div", { className: cn('bw-card__footer', className), ...props });
|
|
20
|
+
}
|
package/dist/chrome.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function Tabs({ value, onValueChange, className, children, }: {
|
|
3
|
+
value: string;
|
|
4
|
+
onValueChange: (value: string) => void;
|
|
5
|
+
className?: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}): React.JSX.Element;
|
|
8
|
+
export declare function TabList({ className, children, }: {
|
|
9
|
+
className?: string;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}): React.JSX.Element;
|
|
12
|
+
export declare function Tab({ value, className, children, }: {
|
|
13
|
+
value: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}): React.JSX.Element;
|
|
17
|
+
export declare function TabPanel({ value, className, children, }: {
|
|
18
|
+
value: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}): React.JSX.Element | null;
|
|
22
|
+
export declare function ThemeToggle({ className }: {
|
|
23
|
+
className?: string;
|
|
24
|
+
}): React.JSX.Element;
|
|
25
|
+
export declare function EmptyState({ title, children, className, }: {
|
|
26
|
+
title: string;
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
className?: string;
|
|
29
|
+
}): React.JSX.Element;
|
|
30
|
+
export declare function Spinner({ className }: {
|
|
31
|
+
className?: string;
|
|
32
|
+
}): React.JSX.Element;
|
|
33
|
+
export declare function Progress({ value, className, }: {
|
|
34
|
+
value: number;
|
|
35
|
+
className?: string;
|
|
36
|
+
}): React.JSX.Element;
|
|
37
|
+
export declare function Skeleton({ className }: {
|
|
38
|
+
className?: string;
|
|
39
|
+
}): React.JSX.Element;
|
|
40
|
+
export declare function Avatar({ initials, src, alt, className, }: {
|
|
41
|
+
initials?: string;
|
|
42
|
+
src?: string;
|
|
43
|
+
alt?: string;
|
|
44
|
+
className?: string;
|
|
45
|
+
}): React.JSX.Element;
|
|
46
|
+
export declare function Chip({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>): React.JSX.Element;
|
|
47
|
+
export declare function Breadcrumbs({ items, className, }: {
|
|
48
|
+
items: Array<{
|
|
49
|
+
href?: string;
|
|
50
|
+
label: string;
|
|
51
|
+
}>;
|
|
52
|
+
className?: string;
|
|
53
|
+
}): React.JSX.Element;
|
|
54
|
+
export declare function Pagination({ page, pageCount, onPageChange, className, }: {
|
|
55
|
+
page: number;
|
|
56
|
+
pageCount: number;
|
|
57
|
+
onPageChange: (page: number) => void;
|
|
58
|
+
className?: string;
|
|
59
|
+
}): React.JSX.Element;
|
package/dist/chrome.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
const TabsContext = React.createContext(null);
|
|
6
|
+
function useTabs() {
|
|
7
|
+
const ctx = React.useContext(TabsContext);
|
|
8
|
+
if (!ctx)
|
|
9
|
+
throw new Error('Tabs parts must be used within <Tabs>');
|
|
10
|
+
return ctx;
|
|
11
|
+
}
|
|
12
|
+
export function Tabs({ value, onValueChange, className, children, }) {
|
|
13
|
+
return (_jsx(TabsContext.Provider, { value: { value, onValueChange }, children: _jsx("div", { className: cn('bw-tabs', className), "data-bw-tabs": "", children: children }) }));
|
|
14
|
+
}
|
|
15
|
+
export function TabList({ className, children, }) {
|
|
16
|
+
return (_jsx("div", { className: cn('bw-tabs__list', className), role: "tablist", children: children }));
|
|
17
|
+
}
|
|
18
|
+
export function Tab({ value, className, children, }) {
|
|
19
|
+
const tabs = useTabs();
|
|
20
|
+
const selected = tabs.value === value;
|
|
21
|
+
return (_jsx("button", { type: "button", role: "tab", className: cn('bw-tabs__tab', selected && 'bw-tabs__tab--active', className), "aria-selected": selected, ...(selected ? { 'data-bw-active': '' } : {}), onClick: () => tabs.onValueChange(value), children: children }));
|
|
22
|
+
}
|
|
23
|
+
export function TabPanel({ value, className, children, }) {
|
|
24
|
+
const tabs = useTabs();
|
|
25
|
+
if (tabs.value !== value)
|
|
26
|
+
return null;
|
|
27
|
+
return (_jsx("div", { className: cn('bw-tabs__panel', className), role: "tabpanel", children: children }));
|
|
28
|
+
}
|
|
29
|
+
export function ThemeToggle({ className }) {
|
|
30
|
+
const [theme, setTheme] = React.useState('light');
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
const stored = (typeof document !== 'undefined' &&
|
|
33
|
+
document.body.getAttribute('data-theme')) ||
|
|
34
|
+
'light';
|
|
35
|
+
setTheme(stored === 'dark' ? 'dark' : 'light');
|
|
36
|
+
}, []);
|
|
37
|
+
function toggle() {
|
|
38
|
+
const next = theme === 'dark' ? 'light' : 'dark';
|
|
39
|
+
setTheme(next);
|
|
40
|
+
document.body.setAttribute('data-theme', next);
|
|
41
|
+
document.documentElement.setAttribute('data-theme', next);
|
|
42
|
+
try {
|
|
43
|
+
localStorage.setItem('bw-theme', next);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* ignore quota / private mode */
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return (_jsx("button", { type: "button", className: cn('bw-btn', 'bw-btn--ghost', className), "data-bw-theme-toggle": "", "aria-pressed": theme === 'dark', onClick: toggle, children: theme === 'dark' ? 'Light' : 'Dark' }));
|
|
50
|
+
}
|
|
51
|
+
export function EmptyState({ title, children, className, }) {
|
|
52
|
+
return (_jsxs("div", { className: cn('bw-empty', className), children: [_jsx("h2", { className: "bw-empty__title", children: title }), children ? _jsx("div", { className: "bw-empty__body", children: children }) : null] }));
|
|
53
|
+
}
|
|
54
|
+
export function Spinner({ className }) {
|
|
55
|
+
return (_jsx("span", { className: cn('bw-spinner', className), role: "status", "aria-label": "Loading" }));
|
|
56
|
+
}
|
|
57
|
+
export function Progress({ value, className, }) {
|
|
58
|
+
const clamped = Math.max(0, Math.min(100, value));
|
|
59
|
+
return (_jsx("div", { className: cn('bw-progress', className), role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": clamped, children: _jsx("div", { className: "bw-progress__bar", style: { inlineSize: `${clamped}%` } }) }));
|
|
60
|
+
}
|
|
61
|
+
export function Skeleton({ className }) {
|
|
62
|
+
return _jsx("div", { className: cn('bw-skeleton', className), "aria-hidden": "true" });
|
|
63
|
+
}
|
|
64
|
+
export function Avatar({ initials, src, alt = '', className, }) {
|
|
65
|
+
return (_jsx("span", { className: cn('bw-avatar', className), children: src ? _jsx("img", { src: src, alt: alt }) : initials }));
|
|
66
|
+
}
|
|
67
|
+
export function Chip({ className, ...props }) {
|
|
68
|
+
return _jsx("span", { className: cn('bw-chip', className), ...props });
|
|
69
|
+
}
|
|
70
|
+
export function Breadcrumbs({ items, className, }) {
|
|
71
|
+
return (_jsx("nav", { className: cn('bw-breadcrumbs', className), "aria-label": "Breadcrumb", children: _jsx("ol", { children: items.map((item, i) => (_jsx("li", { children: item.href && i < items.length - 1 ? (_jsx("a", { href: item.href, children: item.label })) : (_jsx("span", { "aria-current": i === items.length - 1 ? 'page' : undefined, children: item.label })) }, item.label))) }) }));
|
|
72
|
+
}
|
|
73
|
+
export function Pagination({ page, pageCount, onPageChange, className, }) {
|
|
74
|
+
return (_jsxs("nav", { className: cn('bw-pagination', className), "aria-label": "Pagination", children: [_jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--sm", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: "Previous" }), _jsxs("span", { className: "bw-pagination__status", children: [page, " of ", pageCount] }), _jsx("button", { type: "button", className: "bw-btn bw-btn--ghost bw-btn--sm", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: "Next" })] }));
|
|
75
|
+
}
|
package/dist/cn.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal class-name joiner. The React adapter deliberately avoids a runtime
|
|
3
|
+
* styling dependency (clsx/tailwind-merge) because all styling lives in the
|
|
4
|
+
* Brickwork CSS layer — components only ever toggle bw-* classes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cn(...parts: Array<string | false | null | undefined>): string;
|
package/dist/cn.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal class-name joiner. The React adapter deliberately avoids a runtime
|
|
3
|
+
* styling dependency (clsx/tailwind-merge) because all styling lives in the
|
|
4
|
+
* Brickwork CSS layer — components only ever toggle bw-* classes.
|
|
5
|
+
*/
|
|
6
|
+
export function cn(...parts) {
|
|
7
|
+
return parts.filter(Boolean).join(' ');
|
|
8
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ComboboxOption = {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ComboboxProps = {
|
|
8
|
+
id?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
options: ComboboxOption[];
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onValueChange?: (value: string) => void;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
required?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
emptyLabel?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function Combobox({ id, name, options, value, defaultValue, onValueChange, placeholder, disabled, required, className, emptyLabel, }: ComboboxProps): React.JSX.Element;
|
package/dist/combobox.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
export function Combobox({ id, name, options, value, defaultValue = '', onValueChange, placeholder = 'Search', disabled, required, className, emptyLabel = 'No matches', }) {
|
|
6
|
+
const listboxId = React.useId();
|
|
7
|
+
const [open, setOpen] = React.useState(false);
|
|
8
|
+
const [query, setQuery] = React.useState('');
|
|
9
|
+
const [active, setActive] = React.useState(0);
|
|
10
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
|
|
11
|
+
const rootRef = React.useRef(null);
|
|
12
|
+
const selected = value ?? uncontrolled;
|
|
13
|
+
const selectedOption = options.find((o) => o.value === selected);
|
|
14
|
+
const filtered = React.useMemo(() => {
|
|
15
|
+
const q = query.trim().toLowerCase();
|
|
16
|
+
if (!q)
|
|
17
|
+
return options;
|
|
18
|
+
return options.filter((o) => o.label.toLowerCase().includes(q));
|
|
19
|
+
}, [options, query]);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (open)
|
|
22
|
+
return;
|
|
23
|
+
setQuery(selectedOption?.label ?? '');
|
|
24
|
+
}, [open, selectedOption]);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
function onPointer(e) {
|
|
27
|
+
if (!rootRef.current?.contains(e.target))
|
|
28
|
+
setOpen(false);
|
|
29
|
+
}
|
|
30
|
+
document.addEventListener('pointerdown', onPointer);
|
|
31
|
+
return () => document.removeEventListener('pointerdown', onPointer);
|
|
32
|
+
}, []);
|
|
33
|
+
function commit(next) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
setUncontrolled(next);
|
|
36
|
+
onValueChange?.(next);
|
|
37
|
+
const label = options.find((o) => o.value === next)?.label ?? next;
|
|
38
|
+
setQuery(label);
|
|
39
|
+
setOpen(false);
|
|
40
|
+
}
|
|
41
|
+
return (_jsxs("div", { ref: rootRef, className: cn('bw-combobox', className), "data-bw-combobox": "", ...(open ? { 'data-bw-open': '' } : {}), children: [_jsxs("select", { className: "bw-input bw-combobox__floor", id: id, name: name, value: selected, required: required, disabled: disabled, tabIndex: -1, "aria-hidden": "true", hidden: true, onChange: (e) => commit(e.target.value), children: [_jsx("option", { value: "", children: "Choose" }), options.map((opt) => (_jsx("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value)))] }), _jsxs("div", { className: "bw-combobox__field", children: [_jsx("input", { className: "bw-input bw-combobox__input", role: "combobox", "aria-expanded": open, "aria-controls": listboxId, "aria-autocomplete": "list", autoComplete: "off", disabled: disabled, placeholder: placeholder, value: open ? query : (selectedOption?.label ?? query), onChange: (e) => {
|
|
42
|
+
setQuery(e.target.value);
|
|
43
|
+
setOpen(true);
|
|
44
|
+
setActive(0);
|
|
45
|
+
}, onFocus: () => setOpen(true), onKeyDown: (e) => {
|
|
46
|
+
if (e.key === 'ArrowDown') {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
setOpen(true);
|
|
49
|
+
setActive((i) => Math.min(i + 1, Math.max(filtered.length - 1, 0)));
|
|
50
|
+
}
|
|
51
|
+
else if (e.key === 'ArrowUp') {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
setActive((i) => Math.max(i - 1, 0));
|
|
54
|
+
}
|
|
55
|
+
else if (e.key === 'Enter') {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
const opt = filtered[active];
|
|
58
|
+
if (opt && !opt.disabled)
|
|
59
|
+
commit(opt.value);
|
|
60
|
+
}
|
|
61
|
+
else if (e.key === 'Escape') {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
setOpen(false);
|
|
64
|
+
}
|
|
65
|
+
} }), _jsxs("ul", { className: "bw-combobox__listbox", role: "listbox", id: listboxId, children: [filtered.map((opt, idx) => (_jsx("li", { className: "bw-combobox__option", role: "option", "data-bw-value": opt.value, "aria-selected": opt.value === selected, "aria-disabled": opt.disabled || undefined, ...(idx === active ? { 'data-bw-active': '' } : {}), onMouseMove: () => setActive(idx), onMouseDown: (e) => {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
if (!opt.disabled)
|
|
68
|
+
commit(opt.value);
|
|
69
|
+
}, children: opt.label }, opt.value))), _jsx("li", { className: "bw-combobox__empty", hidden: filtered.length > 0, children: emptyLabel })] })] })] }));
|
|
70
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type CommandItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
group?: string;
|
|
6
|
+
href?: string;
|
|
7
|
+
onSelect?: () => void;
|
|
8
|
+
};
|
|
9
|
+
export type CommandPaletteProps = {
|
|
10
|
+
open: boolean;
|
|
11
|
+
onOpenChange: (open: boolean) => void;
|
|
12
|
+
items: CommandItem[];
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function CommandPalette({ open, onOpenChange, items, placeholder, className, }: CommandPaletteProps): React.JSX.Element;
|
package/dist/command.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
export function CommandPalette({ open, onOpenChange, items, placeholder = 'Type a command or search...', className, }) {
|
|
6
|
+
const [query, setQuery] = React.useState('');
|
|
7
|
+
const [active, setActive] = React.useState(0);
|
|
8
|
+
const inputRef = React.useRef(null);
|
|
9
|
+
const filtered = React.useMemo(() => {
|
|
10
|
+
const q = query.trim().toLowerCase();
|
|
11
|
+
if (!q)
|
|
12
|
+
return items;
|
|
13
|
+
return items.filter((i) => i.label.toLowerCase().includes(q));
|
|
14
|
+
}, [items, query]);
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
if (open) {
|
|
17
|
+
setQuery('');
|
|
18
|
+
setActive(0);
|
|
19
|
+
queueMicrotask(() => inputRef.current?.focus());
|
|
20
|
+
}
|
|
21
|
+
}, [open]);
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
const onKey = (e) => {
|
|
24
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
onOpenChange(!open);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
document.addEventListener('keydown', onKey);
|
|
30
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
31
|
+
}, [open, onOpenChange]);
|
|
32
|
+
function run(item) {
|
|
33
|
+
onOpenChange(false);
|
|
34
|
+
item.onSelect?.();
|
|
35
|
+
if (item.href)
|
|
36
|
+
window.location.href = item.href;
|
|
37
|
+
}
|
|
38
|
+
const groups = React.useMemo(() => {
|
|
39
|
+
const map = new Map();
|
|
40
|
+
for (const item of filtered) {
|
|
41
|
+
const g = item.group || 'Commands';
|
|
42
|
+
if (!map.has(g))
|
|
43
|
+
map.set(g, []);
|
|
44
|
+
map.get(g).push(item);
|
|
45
|
+
}
|
|
46
|
+
return map;
|
|
47
|
+
}, [filtered]);
|
|
48
|
+
return (_jsxs("div", { className: cn('bw-cmdk', className), ...(open ? { 'data-bw-open': '' } : {}), role: "dialog", "aria-modal": "true", "aria-label": "Command palette", "aria-hidden": !open, children: [_jsx("div", { className: "bw-cmdk__scrim", onClick: () => onOpenChange(false) }), _jsxs("div", { className: "bw-cmdk__panel", children: [_jsxs("div", { className: "bw-cmdk__search", children: [_jsx("input", { ref: inputRef, className: "bw-cmdk__input", type: "search", placeholder: placeholder, "aria-label": "Command search", value: query, onChange: (e) => {
|
|
49
|
+
setQuery(e.target.value);
|
|
50
|
+
setActive(0);
|
|
51
|
+
}, onKeyDown: (e) => {
|
|
52
|
+
if (e.key === 'ArrowDown') {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
setActive((i) => Math.min(i + 1, filtered.length - 1));
|
|
55
|
+
}
|
|
56
|
+
else if (e.key === 'ArrowUp') {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
setActive((i) => Math.max(i - 1, 0));
|
|
59
|
+
}
|
|
60
|
+
else if (e.key === 'Enter') {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
const item = filtered[active];
|
|
63
|
+
if (item)
|
|
64
|
+
run(item);
|
|
65
|
+
}
|
|
66
|
+
else if (e.key === 'Escape') {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
onOpenChange(false);
|
|
69
|
+
}
|
|
70
|
+
} }), _jsx("kbd", { className: "bw-kbd", children: "Esc" })] }), _jsx("ul", { className: "bw-cmdk__list", role: "listbox", children: filtered.length === 0 ? (_jsx("li", { className: "bw-cmdk__empty", children: "No results" })) : (Array.from(groups.entries()).map(([group, groupItems]) => (_jsxs(React.Fragment, { children: [_jsx("li", { className: "bw-cmdk__group-label", children: group }), groupItems.map((item) => {
|
|
71
|
+
const idx = filtered.indexOf(item);
|
|
72
|
+
return (_jsx("li", { className: "bw-cmdk__item", role: "option", ...(idx === active ? { 'data-bw-active': '' } : {}), onMouseMove: () => setActive(idx), onClick: () => run(item), children: _jsx("span", { children: item.label }) }, item.id));
|
|
73
|
+
})] }, group)))) })] })] }));
|
|
74
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type DataTableColumn<T> = {
|
|
3
|
+
id: string;
|
|
4
|
+
header: React.ReactNode;
|
|
5
|
+
cell: (row: T) => React.ReactNode;
|
|
6
|
+
align?: 'start' | 'center' | 'end';
|
|
7
|
+
sortable?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type DataTableProps<T> = {
|
|
10
|
+
columns: DataTableColumn<T>[];
|
|
11
|
+
rows: T[];
|
|
12
|
+
getRowId: (row: T) => string;
|
|
13
|
+
selectedIds?: string[];
|
|
14
|
+
onSelectionChange?: (ids: string[]) => void;
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function DataTable<T>({ columns, rows, getRowId, selectedIds, onSelectionChange, className, }: DataTableProps<T>): React.JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from './cn';
|
|
4
|
+
export function DataTable({ columns, rows, getRowId, selectedIds = [], onSelectionChange, className, }) {
|
|
5
|
+
const allSelected = rows.length > 0 && rows.every((r) => selectedIds.includes(getRowId(r)));
|
|
6
|
+
return (_jsx("div", { className: cn('bw-data-table-wrap bw-data-table-wrap--sticky', className), tabIndex: 0, children: _jsxs("table", { className: "bw-data-table", children: [_jsx("thead", { children: _jsxs("tr", { className: "bw-data-table__row", children: [onSelectionChange ? (_jsx("th", { className: "bw-data-table__th bw-data-table__th--select", children: _jsx("input", { type: "checkbox", "aria-label": "Select all", checked: allSelected, onChange: (e) => {
|
|
7
|
+
onSelectionChange(e.target.checked ? rows.map(getRowId) : []);
|
|
8
|
+
} }) })) : null, columns.map((col) => (_jsx("th", { className: cn('bw-data-table__th', col.align === 'end' && 'bw-data-table__th--end', col.align === 'center' && 'bw-data-table__th--center'), children: col.sortable ? (_jsxs("button", { type: "button", className: "bw-data-table__sort", children: [col.header, " ", _jsx("span", { className: "bw-data-table__sort-idle", children: "v" })] })) : (col.header) }, col.id)))] }) }), _jsx("tbody", { children: rows.map((row) => {
|
|
9
|
+
const id = getRowId(row);
|
|
10
|
+
const selected = selectedIds.includes(id);
|
|
11
|
+
return (_jsxs("tr", { className: cn('bw-data-table__row', selected && 'bw-data-table__row--selected'), children: [onSelectionChange ? (_jsx("td", { className: "bw-data-table__td bw-data-table__td--select", children: _jsx("input", { type: "checkbox", "aria-label": `Select ${id}`, checked: selected, onChange: (e) => {
|
|
12
|
+
onSelectionChange(e.target.checked
|
|
13
|
+
? [...selectedIds, id]
|
|
14
|
+
: selectedIds.filter((x) => x !== id));
|
|
15
|
+
} }) })) : null, columns.map((col) => (_jsx("td", { className: cn('bw-data-table__td', col.align === 'end' && 'bw-data-table__td--end', col.align === 'center' && 'bw-data-table__td--center'), children: col.cell(row) }, col.id)))] }, id));
|
|
16
|
+
}) })] }) }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type DatePickerProps = {
|
|
3
|
+
id?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
value?: string;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onValueChange?: (value: string) => void;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function DatePicker({ id, name, value, defaultValue, onValueChange, placeholder, disabled, required, className, }: DatePickerProps): React.JSX.Element;
|
|
14
|
+
export type DateRangePickerProps = {
|
|
15
|
+
startId?: string;
|
|
16
|
+
endId?: string;
|
|
17
|
+
startName?: string;
|
|
18
|
+
endName?: string;
|
|
19
|
+
startValue?: string;
|
|
20
|
+
endValue?: string;
|
|
21
|
+
defaultStartValue?: string;
|
|
22
|
+
defaultEndValue?: string;
|
|
23
|
+
onValueChange?: (range: {
|
|
24
|
+
start: string;
|
|
25
|
+
end: string;
|
|
26
|
+
}) => void;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
className?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function DateRangePicker({ startId, endId, startName, endName, startValue, endValue, defaultStartValue, defaultEndValue, onValueChange, disabled, className, }: DateRangePickerProps): React.JSX.Element;
|