@crystal-neuo/react 0.0.0-stage → 4.0.1
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 +6 -2
- package/dist/Alert.d.ts +11 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Alert.js +7 -0
- package/dist/Alert.js.map +1 -0
- package/dist/Avatar.d.ts +12 -0
- package/dist/Avatar.d.ts.map +1 -0
- package/dist/Avatar.js +14 -0
- package/dist/Avatar.js.map +1 -0
- package/dist/Badge.d.ts +9 -0
- package/dist/Badge.d.ts.map +1 -0
- package/dist/Badge.js +7 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Breadcrumb.d.ts +13 -0
- package/dist/Breadcrumb.d.ts.map +1 -0
- package/dist/Breadcrumb.js +10 -0
- package/dist/Breadcrumb.js.map +1 -0
- package/dist/Button.d.ts +10 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +11 -0
- package/dist/Button.js.map +1 -0
- package/dist/Card.d.ts +9 -0
- package/dist/Card.d.ts.map +1 -0
- package/dist/Card.js +7 -0
- package/dist/Card.js.map +1 -0
- package/dist/Checkbox.d.ts +11 -0
- package/dist/Checkbox.d.ts.map +1 -0
- package/dist/Checkbox.js +28 -0
- package/dist/Checkbox.js.map +1 -0
- package/dist/DatePicker.d.ts +10 -0
- package/dist/DatePicker.d.ts.map +1 -0
- package/dist/DatePicker.js +10 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/Dialog.d.ts +18 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +15 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Drawer.d.ts +14 -0
- package/dist/Drawer.d.ts.map +1 -0
- package/dist/Drawer.js +11 -0
- package/dist/Drawer.js.map +1 -0
- package/dist/FileUpload.d.ts +15 -0
- package/dist/FileUpload.d.ts.map +1 -0
- package/dist/FileUpload.js +42 -0
- package/dist/FileUpload.js.map +1 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.d.ts.map +1 -0
- package/dist/Input.js +12 -0
- package/dist/Input.js.map +1 -0
- package/dist/List.d.ts +13 -0
- package/dist/List.d.ts.map +1 -0
- package/dist/List.js +10 -0
- package/dist/List.js.map +1 -0
- package/dist/Menu.d.ts +14 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +90 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Modal.d.ts +13 -0
- package/dist/Modal.d.ts.map +1 -0
- package/dist/Modal.js +11 -0
- package/dist/Modal.js.map +1 -0
- package/dist/Nav.d.ts +14 -0
- package/dist/Nav.d.ts.map +1 -0
- package/dist/Nav.js +10 -0
- package/dist/Nav.js.map +1 -0
- package/dist/Pagination.d.ts +13 -0
- package/dist/Pagination.d.ts.map +1 -0
- package/dist/Pagination.js +12 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/Progress.d.ts +12 -0
- package/dist/Progress.d.ts.map +1 -0
- package/dist/Progress.js +11 -0
- package/dist/Progress.js.map +1 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.d.ts.map +1 -0
- package/dist/Radio.js +17 -0
- package/dist/Radio.js.map +1 -0
- package/dist/SegmentedControl.d.ts +23 -0
- package/dist/SegmentedControl.d.ts.map +1 -0
- package/dist/SegmentedControl.js +16 -0
- package/dist/SegmentedControl.js.map +1 -0
- package/dist/Select.d.ts +16 -0
- package/dist/Select.d.ts.map +1 -0
- package/dist/Select.js +10 -0
- package/dist/Select.js.map +1 -0
- package/dist/Sheet.d.ts +12 -0
- package/dist/Sheet.d.ts.map +1 -0
- package/dist/Sheet.js +11 -0
- package/dist/Sheet.js.map +1 -0
- package/dist/Skeleton.d.ts +9 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +7 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Slider.d.ts +10 -0
- package/dist/Slider.d.ts.map +1 -0
- package/dist/Slider.js +9 -0
- package/dist/Slider.js.map +1 -0
- package/dist/TabBar.d.ts +17 -0
- package/dist/TabBar.d.ts.map +1 -0
- package/dist/TabBar.js +7 -0
- package/dist/TabBar.js.map +1 -0
- package/dist/Table.d.ts +16 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +7 -0
- package/dist/Table.js.map +1 -0
- package/dist/Tabs.d.ts +20 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +49 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Textarea.d.ts +11 -0
- package/dist/Textarea.d.ts.map +1 -0
- package/dist/Textarea.js +12 -0
- package/dist/Textarea.js.map +1 -0
- package/dist/Toast.d.ts +12 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +45 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Toggle.d.ts +9 -0
- package/dist/Toggle.d.ts.map +1 -0
- package/dist/Toggle.js +16 -0
- package/dist/Toggle.js.map +1 -0
- package/dist/Tooltip.d.ts +11 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +36 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/cn.d.ts +2 -0
- package/dist/cn.d.ts.map +1 -0
- package/dist/cn.js +7 -0
- package/dist/cn.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/useFocusTrap.d.ts +11 -0
- package/dist/useFocusTrap.d.ts.map +1 -0
- package/dist/useFocusTrap.js +67 -0
- package/dist/useFocusTrap.js.map +1 -0
- package/dist/useModalDialog.d.ts +20 -0
- package/dist/useModalDialog.d.ts.map +1 -0
- package/dist/useModalDialog.js +81 -0
- package/dist/useModalDialog.js.map +1 -0
- package/package.json +42 -4
- package/src/Alert.tsx +40 -0
- package/src/Avatar.tsx +47 -0
- package/src/Badge.tsx +20 -0
- package/src/Breadcrumb.tsx +52 -0
- package/src/Button.tsx +38 -0
- package/src/Card.tsx +20 -0
- package/src/Checkbox.tsx +65 -0
- package/src/DatePicker.tsx +46 -0
- package/src/Dialog.tsx +81 -0
- package/src/Drawer.tsx +57 -0
- package/src/FileUpload.tsx +116 -0
- package/src/Input.tsx +46 -0
- package/src/List.tsx +35 -0
- package/src/Menu.tsx +141 -0
- package/src/Modal.tsx +40 -0
- package/src/Nav.tsx +40 -0
- package/src/Pagination.tsx +78 -0
- package/src/Progress.tsx +43 -0
- package/src/Radio.tsx +71 -0
- package/src/SegmentedControl.tsx +72 -0
- package/src/Select.tsx +64 -0
- package/src/Sheet.tsx +40 -0
- package/src/Skeleton.tsx +21 -0
- package/src/Slider.tsx +34 -0
- package/src/TabBar.tsx +46 -0
- package/src/Table.tsx +60 -0
- package/src/Tabs.tsx +114 -0
- package/src/Textarea.tsx +54 -0
- package/src/Toast.tsx +97 -0
- package/src/Toggle.tsx +42 -0
- package/src/Tooltip.tsx +70 -0
- package/src/cn.ts +6 -0
- package/src/index.ts +44 -0
- package/src/useFocusTrap.ts +71 -0
- package/src/useModalDialog.ts +83 -0
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystal-neuo/react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "Crystal Neuo React components (shadcn/ui pattern). Prop types derived from @crystal-neuo/contract.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/AnoRebel/crystal-neuo.git",
|
|
9
|
+
"directory": "packages/react"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://crystal-neuo.anorebel.net",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"source": "./src/index.ts",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.build.json",
|
|
26
|
+
"typecheck": "tsc --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=18",
|
|
30
|
+
"react-dom": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@crystal-neuo/contract": "4.0.1",
|
|
34
|
+
"@crystal-neuo/css": "4.0.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/react": "^19.3.0",
|
|
38
|
+
"@types/react-dom": "^19.3.0",
|
|
39
|
+
"react": "^19.3.1",
|
|
40
|
+
"react-dom": "^19.3.1",
|
|
41
|
+
"typescript": "^6.0.3"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false
|
|
44
|
+
}
|
package/src/Alert.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { AlertVariant, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface AlertProps extends React.ComponentProps<"div"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
variant?: AlertVariant;
|
|
8
|
+
title?: string;
|
|
9
|
+
/** When true, renders role="alert" for assertive announcement of dynamic inserts. */
|
|
10
|
+
live?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Alert({
|
|
14
|
+
material,
|
|
15
|
+
className,
|
|
16
|
+
variant = "info",
|
|
17
|
+
title,
|
|
18
|
+
live,
|
|
19
|
+
children,
|
|
20
|
+
...props
|
|
21
|
+
}: AlertProps) {
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
data-slot="alert"
|
|
25
|
+
data-material={material}
|
|
26
|
+
role={live ? "alert" : "note"}
|
|
27
|
+
className={cn("cn-alert", `cn-alert--${variant}`, className)}
|
|
28
|
+
{...props}
|
|
29
|
+
>
|
|
30
|
+
<svg className="cn-alert__icon" viewBox="0 0 20 20" aria-hidden="true">
|
|
31
|
+
<circle cx="10" cy="10" r="8" fill="none" stroke="currentColor" strokeWidth="1.5" />
|
|
32
|
+
<path d="M10 6v5M10 14h.01" stroke="currentColor" strokeWidth="1.5" fill="none" />
|
|
33
|
+
</svg>
|
|
34
|
+
<div>
|
|
35
|
+
{title ? <strong>{title}</strong> : null}
|
|
36
|
+
<div>{children}</div>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
package/src/Avatar.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { AvatarVariant, AvatarSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface AvatarProps extends Omit<React.ComponentProps<"span">, "children"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
variant?: AvatarVariant;
|
|
8
|
+
size?: AvatarSize;
|
|
9
|
+
src?: string;
|
|
10
|
+
/** Accessible name. Required for image avatars; used as initials source for fallback. */
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function initials(name: string): string {
|
|
15
|
+
return name
|
|
16
|
+
.split(/\s+/)
|
|
17
|
+
.slice(0, 2)
|
|
18
|
+
.map((p) => p.charAt(0).toUpperCase())
|
|
19
|
+
.join("");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Avatar({
|
|
23
|
+
material,
|
|
24
|
+
className,
|
|
25
|
+
variant = "circle",
|
|
26
|
+
size = "md",
|
|
27
|
+
src,
|
|
28
|
+
name,
|
|
29
|
+
...props
|
|
30
|
+
}: AvatarProps) {
|
|
31
|
+
return (
|
|
32
|
+
<span
|
|
33
|
+
data-slot="avatar"
|
|
34
|
+
data-material={material}
|
|
35
|
+
className={cn("cn-avatar", `cn-avatar--${variant}`, `cn-avatar--size-${size}`, className)}
|
|
36
|
+
{...props}
|
|
37
|
+
>
|
|
38
|
+
{src ? (
|
|
39
|
+
<img src={src} alt={name} />
|
|
40
|
+
) : (
|
|
41
|
+
<span role="img" aria-label={name}>
|
|
42
|
+
{initials(name)}
|
|
43
|
+
</span>
|
|
44
|
+
)}
|
|
45
|
+
</span>
|
|
46
|
+
);
|
|
47
|
+
}
|
package/src/Badge.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { BadgeVariant, BadgeSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface BadgeProps extends React.ComponentProps<"span"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
variant?: BadgeVariant;
|
|
8
|
+
size?: BadgeSize;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function Badge({ material, className, variant = "neutral", size = "md", ...props }: BadgeProps) {
|
|
12
|
+
return (
|
|
13
|
+
<span
|
|
14
|
+
data-slot="badge"
|
|
15
|
+
data-material={material}
|
|
16
|
+
className={cn("cn-badge", `cn-badge--${variant}`, `cn-badge--size-${size}`, className)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { BreadcrumbSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface Crumb {
|
|
6
|
+
label: string;
|
|
7
|
+
href?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface BreadcrumbProps extends Omit<React.ComponentProps<"nav">, "children"> {
|
|
11
|
+
material?: Material;
|
|
12
|
+
size?: BreadcrumbSize;
|
|
13
|
+
items: Crumb[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function Breadcrumb({ material, className, size = "md", items, ...props }: BreadcrumbProps) {
|
|
17
|
+
return (
|
|
18
|
+
<nav
|
|
19
|
+
data-slot="breadcrumb"
|
|
20
|
+
data-material={material}
|
|
21
|
+
aria-label="Breadcrumb"
|
|
22
|
+
className={cn("cn-breadcrumb", `cn-breadcrumb--size-${size}`, className)}
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
<ol className="cn-breadcrumb__list">
|
|
26
|
+
{items.map((c, i) => {
|
|
27
|
+
const last = i === items.length - 1;
|
|
28
|
+
return (
|
|
29
|
+
<li key={i} className="cn-breadcrumb__item">
|
|
30
|
+
{last ? (
|
|
31
|
+
<span className="cn-breadcrumb__current" aria-current="page">
|
|
32
|
+
{c.label}
|
|
33
|
+
</span>
|
|
34
|
+
) : !c.href ? (
|
|
35
|
+
<span className="cn-breadcrumb__text">{c.label}</span>
|
|
36
|
+
) : (
|
|
37
|
+
<a className="cn-breadcrumb__link" href={c.href}>
|
|
38
|
+
{c.label}
|
|
39
|
+
</a>
|
|
40
|
+
)}
|
|
41
|
+
{!last ? (
|
|
42
|
+
<span className="cn-breadcrumb__sep" aria-hidden="true">
|
|
43
|
+
/
|
|
44
|
+
</span>
|
|
45
|
+
) : null}
|
|
46
|
+
</li>
|
|
47
|
+
);
|
|
48
|
+
})}
|
|
49
|
+
</ol>
|
|
50
|
+
</nav>
|
|
51
|
+
);
|
|
52
|
+
}
|
package/src/Button.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ButtonVariant, ButtonSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface ButtonProps extends React.ComponentProps<"button"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
variant?: ButtonVariant;
|
|
8
|
+
size?: ButtonSize;
|
|
9
|
+
loading?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Button({
|
|
13
|
+
material,
|
|
14
|
+
className,
|
|
15
|
+
variant = "primary",
|
|
16
|
+
size = "md",
|
|
17
|
+
loading = false,
|
|
18
|
+
disabled,
|
|
19
|
+
type = "button",
|
|
20
|
+
children,
|
|
21
|
+
...props
|
|
22
|
+
}: ButtonProps) {
|
|
23
|
+
return (
|
|
24
|
+
<button
|
|
25
|
+
data-slot="button"
|
|
26
|
+
data-material={material}
|
|
27
|
+
className={cn("cn-button", `cn-button--${variant}`, `cn-button--size-${size}`, className)}
|
|
28
|
+
// Never submit a surrounding form unless asked; matches the Vue adapter.
|
|
29
|
+
type={type}
|
|
30
|
+
// Loading always blocks activation, so a double submit is impossible.
|
|
31
|
+
disabled={disabled || loading}
|
|
32
|
+
aria-busy={loading || undefined}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</button>
|
|
37
|
+
);
|
|
38
|
+
}
|
package/src/Card.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { CardVariant, CardSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface CardProps extends React.ComponentProps<"section"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
variant?: CardVariant;
|
|
8
|
+
size?: CardSize;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function Card({ material, className, variant = "glass", size = "md", ...props }: CardProps) {
|
|
12
|
+
return (
|
|
13
|
+
<section
|
|
14
|
+
data-slot="card"
|
|
15
|
+
data-material={material}
|
|
16
|
+
className={cn("cn-card", `cn-card--${variant}`, `cn-card--size-${size}`, className)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
package/src/Checkbox.tsx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { CheckboxSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface CheckboxProps extends Omit<React.ComponentProps<"input">, "size" | "type"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
size?: CheckboxSize;
|
|
8
|
+
label: string;
|
|
9
|
+
error?: boolean;
|
|
10
|
+
indeterminate?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Checkbox({
|
|
14
|
+
material,
|
|
15
|
+
className,
|
|
16
|
+
size = "md",
|
|
17
|
+
label,
|
|
18
|
+
error,
|
|
19
|
+
indeterminate = false,
|
|
20
|
+
id,
|
|
21
|
+
ref: forwardedRef,
|
|
22
|
+
onChange,
|
|
23
|
+
...props
|
|
24
|
+
}: CheckboxProps) {
|
|
25
|
+
const autoId = React.useId();
|
|
26
|
+
const cbId = id ?? autoId;
|
|
27
|
+
const inputRef = React.useRef<HTMLInputElement | null>(null);
|
|
28
|
+
// Keep the consumer's ref working alongside ours.
|
|
29
|
+
const setRef = React.useCallback(
|
|
30
|
+
(node: HTMLInputElement | null) => {
|
|
31
|
+
inputRef.current = node;
|
|
32
|
+
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
33
|
+
else if (forwardedRef) forwardedRef.current = node;
|
|
34
|
+
},
|
|
35
|
+
[forwardedRef],
|
|
36
|
+
);
|
|
37
|
+
// `indeterminate` is a DOM property, not an attribute; sync it every render.
|
|
38
|
+
React.useLayoutEffect(() => {
|
|
39
|
+
if (inputRef.current) inputRef.current.indeterminate = indeterminate;
|
|
40
|
+
});
|
|
41
|
+
return (
|
|
42
|
+
<label
|
|
43
|
+
className={cn("cn-choice", `cn-choice--size-${size}`, error && "cn-choice--error", className)}
|
|
44
|
+
htmlFor={cbId}
|
|
45
|
+
data-slot="checkbox"
|
|
46
|
+
data-material={material}
|
|
47
|
+
>
|
|
48
|
+
<input
|
|
49
|
+
ref={setRef}
|
|
50
|
+
id={cbId}
|
|
51
|
+
type="checkbox"
|
|
52
|
+
className="cn-choice__input"
|
|
53
|
+
aria-invalid={error ? true : undefined}
|
|
54
|
+
onChange={(e) => {
|
|
55
|
+
onChange?.(e);
|
|
56
|
+
// A click clears the DOM flag; the prop stays the source of truth
|
|
57
|
+
// until the owner changes it.
|
|
58
|
+
e.currentTarget.indeterminate = indeterminate;
|
|
59
|
+
}}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
<span className="cn-choice__label">{label}</span>
|
|
63
|
+
</label>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DatePickerSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface DatePickerProps extends Omit<React.ComponentProps<"input">, "size" | "type"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
size?: DatePickerSize;
|
|
8
|
+
label?: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function DatePicker({
|
|
13
|
+
material,
|
|
14
|
+
className,
|
|
15
|
+
size = "md",
|
|
16
|
+
label,
|
|
17
|
+
error,
|
|
18
|
+
id,
|
|
19
|
+
...props
|
|
20
|
+
}: DatePickerProps) {
|
|
21
|
+
const autoId = React.useId();
|
|
22
|
+
const dpId = id ?? autoId;
|
|
23
|
+
const msgId = `${dpId}-msg`;
|
|
24
|
+
return (
|
|
25
|
+
<div className={cn("cn-field", className)} data-slot="date-field" data-material={material}>
|
|
26
|
+
{label ? (
|
|
27
|
+
<label className="cn-field__label" htmlFor={dpId}>
|
|
28
|
+
{label}
|
|
29
|
+
</label>
|
|
30
|
+
) : null}
|
|
31
|
+
<input
|
|
32
|
+
id={dpId}
|
|
33
|
+
type="date"
|
|
34
|
+
className={cn("cn-input", `cn-input--size-${size}`, error && "cn-input--error")}
|
|
35
|
+
aria-invalid={error ? true : undefined}
|
|
36
|
+
aria-describedby={error ? msgId : undefined}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
{error ? (
|
|
40
|
+
<span className="cn-field__message" id={msgId}>
|
|
41
|
+
{error}
|
|
42
|
+
</span>
|
|
43
|
+
) : null}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
package/src/Dialog.tsx
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DialogVariant, DialogSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
import { closeOnScrim, useModalDialog } from "./useModalDialog.ts";
|
|
5
|
+
|
|
6
|
+
export interface DialogProps {
|
|
7
|
+
material?: Material;
|
|
8
|
+
open: boolean;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
title: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
variant?: DialogVariant;
|
|
13
|
+
size?: DialogSize;
|
|
14
|
+
confirmLabel?: string;
|
|
15
|
+
cancelLabel?: string;
|
|
16
|
+
onConfirm?: () => void;
|
|
17
|
+
className?: string;
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Dialog({
|
|
22
|
+
material,
|
|
23
|
+
open,
|
|
24
|
+
onClose,
|
|
25
|
+
title,
|
|
26
|
+
description,
|
|
27
|
+
variant = "default",
|
|
28
|
+
size = "sm",
|
|
29
|
+
confirmLabel = "Confirm",
|
|
30
|
+
cancelLabel = "Cancel",
|
|
31
|
+
onConfirm,
|
|
32
|
+
className,
|
|
33
|
+
children,
|
|
34
|
+
}: DialogProps) {
|
|
35
|
+
const ref = React.useRef<HTMLDialogElement>(null);
|
|
36
|
+
const titleId = React.useId();
|
|
37
|
+
const descId = React.useId();
|
|
38
|
+
useModalDialog(ref, open, onClose);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<dialog
|
|
42
|
+
ref={ref}
|
|
43
|
+
className="cn-scrim"
|
|
44
|
+
data-slot="dialog-scrim"
|
|
45
|
+
data-material={material}
|
|
46
|
+
role="alertdialog"
|
|
47
|
+
aria-labelledby={titleId}
|
|
48
|
+
aria-describedby={description ? descId : undefined}
|
|
49
|
+
onMouseDown={closeOnScrim(onClose)}
|
|
50
|
+
>
|
|
51
|
+
{open ? (
|
|
52
|
+
<div className={cn("cn-dialog", `cn-dialog--size-${size}`, className)}>
|
|
53
|
+
<h2 id={titleId} className="cn-dialog__title">
|
|
54
|
+
{title}
|
|
55
|
+
</h2>
|
|
56
|
+
{description ? <p id={descId}>{description}</p> : null}
|
|
57
|
+
{children}
|
|
58
|
+
<div className="cn-dialog__actions">
|
|
59
|
+
<button type="button" className="cn-button cn-button--ghost cn-button--size-md" onClick={onClose}>
|
|
60
|
+
{cancelLabel}
|
|
61
|
+
</button>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
className={cn(
|
|
65
|
+
"cn-button",
|
|
66
|
+
variant === "destructive" ? "cn-button--danger" : "cn-button--primary",
|
|
67
|
+
"cn-button--size-md",
|
|
68
|
+
)}
|
|
69
|
+
onClick={() => {
|
|
70
|
+
onConfirm?.();
|
|
71
|
+
onClose();
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{confirmLabel}
|
|
75
|
+
</button>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
) : null}
|
|
79
|
+
</dialog>
|
|
80
|
+
);
|
|
81
|
+
}
|
package/src/Drawer.tsx
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DrawerSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
import { closeOnScrim, useModalDialog } from "./useModalDialog.ts";
|
|
5
|
+
|
|
6
|
+
export interface DrawerProps {
|
|
7
|
+
material?: Material;
|
|
8
|
+
open: boolean;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
title: string;
|
|
11
|
+
placement?: "start" | "end";
|
|
12
|
+
size?: DrawerSize;
|
|
13
|
+
className?: string;
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Drawer({
|
|
18
|
+
material,
|
|
19
|
+
open,
|
|
20
|
+
onClose,
|
|
21
|
+
title,
|
|
22
|
+
placement = "start",
|
|
23
|
+
size = "md",
|
|
24
|
+
className,
|
|
25
|
+
children,
|
|
26
|
+
}: DrawerProps) {
|
|
27
|
+
const ref = React.useRef<HTMLDialogElement>(null);
|
|
28
|
+
const titleId = React.useId();
|
|
29
|
+
useModalDialog(ref, open, onClose);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<dialog
|
|
33
|
+
ref={ref}
|
|
34
|
+
className="cn-scrim cn-scrim--drawer"
|
|
35
|
+
data-slot="drawer-scrim"
|
|
36
|
+
data-material={material}
|
|
37
|
+
aria-labelledby={titleId}
|
|
38
|
+
onMouseDown={closeOnScrim(onClose)}
|
|
39
|
+
>
|
|
40
|
+
{open ? (
|
|
41
|
+
<div
|
|
42
|
+
className={cn(
|
|
43
|
+
"cn-drawer",
|
|
44
|
+
`cn-drawer--size-${size}`,
|
|
45
|
+
placement === "end" && "cn-drawer--end",
|
|
46
|
+
className,
|
|
47
|
+
)}
|
|
48
|
+
>
|
|
49
|
+
<h2 id={titleId} className="cn-drawer__title">
|
|
50
|
+
{title}
|
|
51
|
+
</h2>
|
|
52
|
+
{children}
|
|
53
|
+
</div>
|
|
54
|
+
) : null}
|
|
55
|
+
</dialog>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { acceptedFiles, type FileUploadSize, type Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface FileUploadProps extends Omit<React.ComponentProps<"input">, "size" | "type"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
size?: FileUploadSize;
|
|
8
|
+
label: string;
|
|
9
|
+
hint?: string;
|
|
10
|
+
/** Error message; switches to the error variant. */
|
|
11
|
+
error?: string;
|
|
12
|
+
/** Announced while files are dragged over the zone. */
|
|
13
|
+
dropLabel?: string;
|
|
14
|
+
onFiles?: (files: File[]) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function FileUpload({
|
|
18
|
+
material,
|
|
19
|
+
className,
|
|
20
|
+
size = "md",
|
|
21
|
+
label,
|
|
22
|
+
hint,
|
|
23
|
+
error,
|
|
24
|
+
dropLabel = "Drop to upload",
|
|
25
|
+
onFiles,
|
|
26
|
+
onChange,
|
|
27
|
+
disabled,
|
|
28
|
+
accept,
|
|
29
|
+
multiple,
|
|
30
|
+
id,
|
|
31
|
+
...props
|
|
32
|
+
}: FileUploadProps) {
|
|
33
|
+
const autoId = React.useId();
|
|
34
|
+
const fileId = id ?? autoId;
|
|
35
|
+
const hintId = `${fileId}-hint`;
|
|
36
|
+
const msgId = `${fileId}-msg`;
|
|
37
|
+
const [dragover, setDragover] = React.useState(false);
|
|
38
|
+
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
39
|
+
const describedBy = [hint ? hintId : null, error ? msgId : null].filter(Boolean).join(" ") || undefined;
|
|
40
|
+
|
|
41
|
+
function onDrop(e: React.DragEvent) {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
setDragover(false);
|
|
44
|
+
if (disabled) return;
|
|
45
|
+
const files = acceptedFiles(e.dataTransfer.files, accept, multiple);
|
|
46
|
+
if (!files.length) return;
|
|
47
|
+
// The native input stays the source of truth, so a form post carries the drop.
|
|
48
|
+
const input = inputRef.current;
|
|
49
|
+
if (input) {
|
|
50
|
+
const transfer = new DataTransfer();
|
|
51
|
+
files.forEach((f) => transfer.items.add(f));
|
|
52
|
+
input.files = transfer.files;
|
|
53
|
+
}
|
|
54
|
+
onFiles?.(files);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className={cn(
|
|
60
|
+
"cn-fileupload",
|
|
61
|
+
`cn-fileupload--size-${size}`,
|
|
62
|
+
error && "cn-fileupload--error",
|
|
63
|
+
className,
|
|
64
|
+
)}
|
|
65
|
+
data-slot="file-upload"
|
|
66
|
+
data-material={material}
|
|
67
|
+
>
|
|
68
|
+
<button
|
|
69
|
+
type="button"
|
|
70
|
+
className="cn-fileupload__zone"
|
|
71
|
+
data-dragover={dragover || undefined}
|
|
72
|
+
disabled={disabled}
|
|
73
|
+
aria-describedby={describedBy}
|
|
74
|
+
onClick={() => inputRef.current?.click()}
|
|
75
|
+
onDragOver={(e) => {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
if (!disabled) setDragover(true);
|
|
78
|
+
}}
|
|
79
|
+
onDragLeave={() => setDragover(false)}
|
|
80
|
+
onDrop={onDrop}
|
|
81
|
+
>
|
|
82
|
+
<span>{label}</span>
|
|
83
|
+
{hint ? (
|
|
84
|
+
<span className="cn-field__hint" id={hintId}>
|
|
85
|
+
{hint}
|
|
86
|
+
</span>
|
|
87
|
+
) : null}
|
|
88
|
+
</button>
|
|
89
|
+
<input
|
|
90
|
+
ref={inputRef}
|
|
91
|
+
id={fileId}
|
|
92
|
+
type="file"
|
|
93
|
+
className="cn-fileupload__input"
|
|
94
|
+
// Operated through the zone button; keep it out of the Tab order and tree.
|
|
95
|
+
tabIndex={-1}
|
|
96
|
+
aria-hidden="true"
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
accept={accept}
|
|
99
|
+
multiple={multiple}
|
|
100
|
+
{...props}
|
|
101
|
+
onChange={(e) => {
|
|
102
|
+
onChange?.(e);
|
|
103
|
+
if (e.target.files?.length) onFiles?.(Array.from(e.target.files));
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
<span className="cn-visually-hidden" aria-live="polite">
|
|
107
|
+
{dragover ? dropLabel : ""}
|
|
108
|
+
</span>
|
|
109
|
+
{error ? (
|
|
110
|
+
<span className="cn-field__message" id={msgId}>
|
|
111
|
+
{error}
|
|
112
|
+
</span>
|
|
113
|
+
) : null}
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
package/src/Input.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { InputSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
import { cn } from "./cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface InputProps extends Omit<React.ComponentProps<"input">, "size"> {
|
|
6
|
+
material?: Material;
|
|
7
|
+
size?: InputSize;
|
|
8
|
+
label?: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Input({ material, className, size = "md", label, error, hint, id, ...props }: InputProps) {
|
|
14
|
+
const autoId = React.useId();
|
|
15
|
+
const inputId = id ?? autoId;
|
|
16
|
+
const msgId = `${inputId}-msg`;
|
|
17
|
+
const hintId = `${inputId}-hint`;
|
|
18
|
+
const describedBy = [error ? msgId : null, hint ? hintId : null].filter(Boolean).join(" ") || undefined;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className={cn("cn-field", className)} data-slot="input-field" data-material={material}>
|
|
22
|
+
{label ? (
|
|
23
|
+
<label className="cn-field__label" htmlFor={inputId}>
|
|
24
|
+
{label}
|
|
25
|
+
</label>
|
|
26
|
+
) : null}
|
|
27
|
+
<input
|
|
28
|
+
id={inputId}
|
|
29
|
+
className={cn("cn-input", `cn-input--size-${size}`, error && "cn-input--error")}
|
|
30
|
+
aria-invalid={error ? true : undefined}
|
|
31
|
+
aria-describedby={describedBy}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
{hint && !error ? (
|
|
35
|
+
<span className="cn-field__hint" id={hintId}>
|
|
36
|
+
{hint}
|
|
37
|
+
</span>
|
|
38
|
+
) : null}
|
|
39
|
+
{error ? (
|
|
40
|
+
<span className="cn-field__message" id={msgId}>
|
|
41
|
+
{error}
|
|
42
|
+
</span>
|
|
43
|
+
) : null}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|