@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.
Files changed (178) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Alert.d.ts +11 -0
  4. package/dist/Alert.d.ts.map +1 -0
  5. package/dist/Alert.js +7 -0
  6. package/dist/Alert.js.map +1 -0
  7. package/dist/Avatar.d.ts +12 -0
  8. package/dist/Avatar.d.ts.map +1 -0
  9. package/dist/Avatar.js +14 -0
  10. package/dist/Avatar.js.map +1 -0
  11. package/dist/Badge.d.ts +9 -0
  12. package/dist/Badge.d.ts.map +1 -0
  13. package/dist/Badge.js +7 -0
  14. package/dist/Badge.js.map +1 -0
  15. package/dist/Breadcrumb.d.ts +13 -0
  16. package/dist/Breadcrumb.d.ts.map +1 -0
  17. package/dist/Breadcrumb.js +10 -0
  18. package/dist/Breadcrumb.js.map +1 -0
  19. package/dist/Button.d.ts +10 -0
  20. package/dist/Button.d.ts.map +1 -0
  21. package/dist/Button.js +11 -0
  22. package/dist/Button.js.map +1 -0
  23. package/dist/Card.d.ts +9 -0
  24. package/dist/Card.d.ts.map +1 -0
  25. package/dist/Card.js +7 -0
  26. package/dist/Card.js.map +1 -0
  27. package/dist/Checkbox.d.ts +11 -0
  28. package/dist/Checkbox.d.ts.map +1 -0
  29. package/dist/Checkbox.js +28 -0
  30. package/dist/Checkbox.js.map +1 -0
  31. package/dist/DatePicker.d.ts +10 -0
  32. package/dist/DatePicker.d.ts.map +1 -0
  33. package/dist/DatePicker.js +10 -0
  34. package/dist/DatePicker.js.map +1 -0
  35. package/dist/Dialog.d.ts +18 -0
  36. package/dist/Dialog.d.ts.map +1 -0
  37. package/dist/Dialog.js +15 -0
  38. package/dist/Dialog.js.map +1 -0
  39. package/dist/Drawer.d.ts +14 -0
  40. package/dist/Drawer.d.ts.map +1 -0
  41. package/dist/Drawer.js +11 -0
  42. package/dist/Drawer.js.map +1 -0
  43. package/dist/FileUpload.d.ts +15 -0
  44. package/dist/FileUpload.d.ts.map +1 -0
  45. package/dist/FileUpload.js +42 -0
  46. package/dist/FileUpload.js.map +1 -0
  47. package/dist/Input.d.ts +11 -0
  48. package/dist/Input.d.ts.map +1 -0
  49. package/dist/Input.js +12 -0
  50. package/dist/Input.js.map +1 -0
  51. package/dist/List.d.ts +13 -0
  52. package/dist/List.d.ts.map +1 -0
  53. package/dist/List.js +10 -0
  54. package/dist/List.js.map +1 -0
  55. package/dist/Menu.d.ts +14 -0
  56. package/dist/Menu.d.ts.map +1 -0
  57. package/dist/Menu.js +90 -0
  58. package/dist/Menu.js.map +1 -0
  59. package/dist/Modal.d.ts +13 -0
  60. package/dist/Modal.d.ts.map +1 -0
  61. package/dist/Modal.js +11 -0
  62. package/dist/Modal.js.map +1 -0
  63. package/dist/Nav.d.ts +14 -0
  64. package/dist/Nav.d.ts.map +1 -0
  65. package/dist/Nav.js +10 -0
  66. package/dist/Nav.js.map +1 -0
  67. package/dist/Pagination.d.ts +13 -0
  68. package/dist/Pagination.d.ts.map +1 -0
  69. package/dist/Pagination.js +12 -0
  70. package/dist/Pagination.js.map +1 -0
  71. package/dist/Progress.d.ts +12 -0
  72. package/dist/Progress.d.ts.map +1 -0
  73. package/dist/Progress.js +11 -0
  74. package/dist/Progress.js.map +1 -0
  75. package/dist/Radio.d.ts +21 -0
  76. package/dist/Radio.d.ts.map +1 -0
  77. package/dist/Radio.js +17 -0
  78. package/dist/Radio.js.map +1 -0
  79. package/dist/SegmentedControl.d.ts +23 -0
  80. package/dist/SegmentedControl.d.ts.map +1 -0
  81. package/dist/SegmentedControl.js +16 -0
  82. package/dist/SegmentedControl.js.map +1 -0
  83. package/dist/Select.d.ts +16 -0
  84. package/dist/Select.d.ts.map +1 -0
  85. package/dist/Select.js +10 -0
  86. package/dist/Select.js.map +1 -0
  87. package/dist/Sheet.d.ts +12 -0
  88. package/dist/Sheet.d.ts.map +1 -0
  89. package/dist/Sheet.js +11 -0
  90. package/dist/Sheet.js.map +1 -0
  91. package/dist/Skeleton.d.ts +9 -0
  92. package/dist/Skeleton.d.ts.map +1 -0
  93. package/dist/Skeleton.js +7 -0
  94. package/dist/Skeleton.js.map +1 -0
  95. package/dist/Slider.d.ts +10 -0
  96. package/dist/Slider.d.ts.map +1 -0
  97. package/dist/Slider.js +9 -0
  98. package/dist/Slider.js.map +1 -0
  99. package/dist/TabBar.d.ts +17 -0
  100. package/dist/TabBar.d.ts.map +1 -0
  101. package/dist/TabBar.js +7 -0
  102. package/dist/TabBar.js.map +1 -0
  103. package/dist/Table.d.ts +16 -0
  104. package/dist/Table.d.ts.map +1 -0
  105. package/dist/Table.js +7 -0
  106. package/dist/Table.js.map +1 -0
  107. package/dist/Tabs.d.ts +20 -0
  108. package/dist/Tabs.d.ts.map +1 -0
  109. package/dist/Tabs.js +49 -0
  110. package/dist/Tabs.js.map +1 -0
  111. package/dist/Textarea.d.ts +11 -0
  112. package/dist/Textarea.d.ts.map +1 -0
  113. package/dist/Textarea.js +12 -0
  114. package/dist/Textarea.js.map +1 -0
  115. package/dist/Toast.d.ts +12 -0
  116. package/dist/Toast.d.ts.map +1 -0
  117. package/dist/Toast.js +45 -0
  118. package/dist/Toast.js.map +1 -0
  119. package/dist/Toggle.d.ts +9 -0
  120. package/dist/Toggle.d.ts.map +1 -0
  121. package/dist/Toggle.js +16 -0
  122. package/dist/Toggle.js.map +1 -0
  123. package/dist/Tooltip.d.ts +11 -0
  124. package/dist/Tooltip.d.ts.map +1 -0
  125. package/dist/Tooltip.js +36 -0
  126. package/dist/Tooltip.js.map +1 -0
  127. package/dist/cn.d.ts +2 -0
  128. package/dist/cn.d.ts.map +1 -0
  129. package/dist/cn.js +7 -0
  130. package/dist/cn.js.map +1 -0
  131. package/dist/index.d.ts +35 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +40 -0
  134. package/dist/index.js.map +1 -0
  135. package/dist/useFocusTrap.d.ts +11 -0
  136. package/dist/useFocusTrap.d.ts.map +1 -0
  137. package/dist/useFocusTrap.js +67 -0
  138. package/dist/useFocusTrap.js.map +1 -0
  139. package/dist/useModalDialog.d.ts +20 -0
  140. package/dist/useModalDialog.d.ts.map +1 -0
  141. package/dist/useModalDialog.js +81 -0
  142. package/dist/useModalDialog.js.map +1 -0
  143. package/package.json +42 -4
  144. package/src/Alert.tsx +40 -0
  145. package/src/Avatar.tsx +47 -0
  146. package/src/Badge.tsx +20 -0
  147. package/src/Breadcrumb.tsx +52 -0
  148. package/src/Button.tsx +38 -0
  149. package/src/Card.tsx +20 -0
  150. package/src/Checkbox.tsx +65 -0
  151. package/src/DatePicker.tsx +46 -0
  152. package/src/Dialog.tsx +81 -0
  153. package/src/Drawer.tsx +57 -0
  154. package/src/FileUpload.tsx +116 -0
  155. package/src/Input.tsx +46 -0
  156. package/src/List.tsx +35 -0
  157. package/src/Menu.tsx +141 -0
  158. package/src/Modal.tsx +40 -0
  159. package/src/Nav.tsx +40 -0
  160. package/src/Pagination.tsx +78 -0
  161. package/src/Progress.tsx +43 -0
  162. package/src/Radio.tsx +71 -0
  163. package/src/SegmentedControl.tsx +72 -0
  164. package/src/Select.tsx +64 -0
  165. package/src/Sheet.tsx +40 -0
  166. package/src/Skeleton.tsx +21 -0
  167. package/src/Slider.tsx +34 -0
  168. package/src/TabBar.tsx +46 -0
  169. package/src/Table.tsx +60 -0
  170. package/src/Tabs.tsx +114 -0
  171. package/src/Textarea.tsx +54 -0
  172. package/src/Toast.tsx +97 -0
  173. package/src/Toggle.tsx +42 -0
  174. package/src/Tooltip.tsx +70 -0
  175. package/src/cn.ts +6 -0
  176. package/src/index.ts +44 -0
  177. package/src/useFocusTrap.ts +71 -0
  178. package/src/useModalDialog.ts +83 -0
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@crystal-neuo/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
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
+ }
@@ -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
+ }