@graftwork/ui 1.1.1 → 1.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/components/accordion.d.ts +21 -0
  3. package/dist/components/accordion.js +17 -0
  4. package/dist/components/alert-dialog.d.ts +10 -0
  5. package/dist/components/alert-dialog.js +32 -0
  6. package/dist/components/alert.d.ts +11 -0
  7. package/dist/components/alert.js +13 -0
  8. package/dist/components/avatar.d.ts +26 -0
  9. package/dist/components/avatar.js +33 -0
  10. package/dist/components/badge.d.ts +10 -0
  11. package/dist/components/badge.js +27 -0
  12. package/dist/components/breadcrumb.d.ts +15 -0
  13. package/dist/components/breadcrumb.js +11 -0
  14. package/dist/components/button.js +3 -3
  15. package/dist/components/card.js +1 -1
  16. package/dist/components/checkbox.d.ts +22 -0
  17. package/dist/components/checkbox.js +29 -0
  18. package/dist/components/collapsible.d.ts +15 -0
  19. package/dist/components/collapsible.js +13 -0
  20. package/dist/components/combobox.d.ts +19 -0
  21. package/dist/components/combobox.js +14 -0
  22. package/dist/components/dialog.d.ts +36 -0
  23. package/dist/components/dialog.js +67 -0
  24. package/dist/components/dropdown-menu.d.ts +27 -0
  25. package/dist/components/dropdown-menu.js +49 -0
  26. package/dist/components/empty.d.ts +12 -0
  27. package/dist/components/empty.js +6 -0
  28. package/dist/components/field.js +3 -1
  29. package/dist/components/input-group.d.ts +16 -0
  30. package/dist/components/input-group.js +14 -0
  31. package/dist/components/kbd.d.ts +4 -0
  32. package/dist/components/kbd.js +6 -0
  33. package/dist/components/label.d.ts +4 -0
  34. package/dist/components/label.js +7 -0
  35. package/dist/components/pagination.d.ts +19 -0
  36. package/dist/components/pagination.js +32 -0
  37. package/dist/components/popover.d.ts +13 -0
  38. package/dist/components/popover.js +28 -0
  39. package/dist/components/progress.d.ts +9 -0
  40. package/dist/components/progress.js +8 -0
  41. package/dist/components/radio-group.d.ts +18 -0
  42. package/dist/components/radio-group.js +12 -0
  43. package/dist/components/select.js +2 -2
  44. package/dist/components/separator.d.ts +5 -0
  45. package/dist/components/separator.js +6 -0
  46. package/dist/components/sheet.d.ts +20 -0
  47. package/dist/components/sheet.js +38 -0
  48. package/dist/components/skeleton.d.ts +2 -0
  49. package/dist/components/skeleton.js +14 -0
  50. package/dist/components/slider.d.ts +12 -0
  51. package/dist/components/slider.js +8 -0
  52. package/dist/components/spinner.d.ts +14 -0
  53. package/dist/components/spinner.js +15 -0
  54. package/dist/components/switch.d.ts +8 -0
  55. package/dist/components/switch.js +8 -0
  56. package/dist/components/table.js +1 -1
  57. package/dist/components/tabs.d.ts +17 -0
  58. package/dist/components/tabs.js +18 -0
  59. package/dist/components/textarea.d.ts +16 -0
  60. package/dist/components/textarea.js +8 -0
  61. package/dist/components/toast.d.ts +24 -0
  62. package/dist/components/toast.js +28 -0
  63. package/dist/components/toggle.d.ts +14 -0
  64. package/dist/components/toggle.js +37 -0
  65. package/dist/components/tooltip.d.ts +6 -0
  66. package/dist/components/tooltip.js +24 -0
  67. package/dist/index.d.ts +30 -0
  68. package/dist/index.js +30 -0
  69. package/dist/lib/utils.d.ts +1 -1
  70. package/dist/lib/utils.js +6 -1
  71. package/dist/styles.css +11 -1
  72. package/package.json +3 -3
@@ -0,0 +1,24 @@
1
+ import type * as React from "react";
2
+ import { UNSTABLE_ToastQueue as ToastQueue } from "react-aria-components";
3
+ export type ToastVariant = "info" | "success" | "warning" | "error";
4
+ export type ToastContent = {
5
+ title: string;
6
+ description?: string;
7
+ /** Sets the icon. Defaults to info. */
8
+ variant?: ToastVariant;
9
+ };
10
+ /** The app-wide queue <Toaster /> shows. */
11
+ export declare const toastQueue: ToastQueue<ToastContent>;
12
+ /**
13
+ * Shows a toast. Returns its key, for toastQueue.close(key).
14
+ * timeout is in milliseconds; errors default to staying until dismissed.
15
+ */
16
+ export declare function toast(content: ToastContent, options?: {
17
+ timeout?: number;
18
+ }): string;
19
+ export type ToasterProps = {
20
+ /** Names the landmark. Defaults to "Notifications". */
21
+ "aria-label"?: string;
22
+ className?: string;
23
+ };
24
+ export declare function Toaster({ "aria-label": label, className }: ToasterProps): React.JSX.Element;
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { CircleAlertIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, XIcon } from "lucide-react";
4
+ import { Button as ButtonPrimitive, Text, UNSTABLE_Toast as ToastPrimitive, UNSTABLE_ToastContent as ToastContentPrimitive, UNSTABLE_ToastQueue as ToastQueue, UNSTABLE_ToastRegion as ToastRegion, } from "react-aria-components";
5
+ import { cn } from "../lib/utils.js";
6
+ /** The app-wide queue <Toaster /> shows. */
7
+ export const toastQueue = new ToastQueue({ maxVisibleToasts: 3 });
8
+ /**
9
+ * Shows a toast. Returns its key, for toastQueue.close(key).
10
+ * timeout is in milliseconds; errors default to staying until dismissed.
11
+ */
12
+ export function toast(content, options = {}) {
13
+ const timeout = options.timeout ?? (content.variant === "error" ? undefined : 8000);
14
+ return toastQueue.add(content, { timeout });
15
+ }
16
+ const icons = {
17
+ info: { icon: InfoIcon, className: "text-text-info" },
18
+ success: { icon: CircleCheckIcon, className: "text-text-success" },
19
+ warning: { icon: TriangleAlertIcon, className: "text-text-warning" },
20
+ error: { icon: CircleAlertIcon, className: "text-text-error" },
21
+ };
22
+ export function Toaster({ "aria-label": label = "Notifications", className }) {
23
+ return (_jsx(ToastRegion, { queue: toastQueue, "aria-label": label, "data-slot": "toaster", className: cn("fixed end-4 bottom-4 z-50 flex w-[min(24rem,calc(100vw-2rem))] flex-col-reverse gap-2 outline-none", "data-focus-visible:focus-ring-drawn rounded-lg", className), children: ({ toast: item }) => {
24
+ const variant = item.content.variant ?? "info";
25
+ const { icon: Icon, className: iconClass } = icons[variant];
26
+ return (_jsxs(ToastPrimitive, { toast: item, "data-slot": "toast", "data-variant": variant, className: cn("flex items-start gap-3 rounded-md border border-border-default bg-surface-overlay p-4 text-body text-text-default shadow-lg outline-none", "data-focus-visible:focus-ring-drawn"), children: [_jsx(Icon, { "aria-hidden": true, className: cn("mt-0.5 size-5 shrink-0", iconClass) }), _jsxs(ToastContentPrimitive, { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsx(Text, { slot: "title", className: "font-semibold", children: item.content.title }), item.content.description ? (_jsx(Text, { slot: "description", className: "text-text-secondary", children: item.content.description })) : null] }), _jsx(ButtonPrimitive, { slot: "close", "aria-label": "Dismiss", className: "focus-ring hit-area -m-1 flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md text-icon-default hover:bg-action-ghost-bg-hover", children: _jsx(XIcon, { "aria-hidden": true, className: "size-4" }) })] }));
27
+ } }));
28
+ }
@@ -0,0 +1,14 @@
1
+ import { type ToggleButtonProps as TogglePrimitiveProps } from "react-aria-components";
2
+ export declare const toggleVariants: (props?: ({
3
+ variant?: "secondary" | "ghost" | null | undefined;
4
+ size?: "sm" | "md" | "lg" | null | undefined;
5
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
+ export type ToggleVariant = "ghost" | "secondary";
7
+ export type ToggleProps = Omit<TogglePrimitiveProps, "className" | "style"> & {
8
+ /** Visual style. Defaults to ghost. */
9
+ variant?: ToggleVariant;
10
+ /** Visual size. Every size keeps a hit area of at least 44 × 44px. Defaults to md. */
11
+ size?: "sm" | "md" | "lg";
12
+ className?: string;
13
+ };
14
+ export declare function Toggle({ className, variant, size, children, ...props }: ToggleProps): import("react").JSX.Element;
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { cva } from "class-variance-authority";
4
+ import { composeRenderProps, ToggleButton as TogglePrimitive, } from "react-aria-components";
5
+ import { cn } from "../lib/utils.js";
6
+ /*
7
+ * Adapted from shadcn/ui (aria-nova). Copyright (c) 2023 shadcn. MIT licence.
8
+ *
9
+ * Figma contract: Toggle { variant: ghost | secondary; size: sm | md | lg; isSelected; isDisabled }
10
+ *
11
+ * A button that stays pressed, like Bold in a text editor. Give icon-only
12
+ * toggles an aria-label.
13
+ */
14
+ export const toggleVariants = cva([
15
+ "focus-ring hit-area inline-flex shrink-0 cursor-pointer items-center justify-center gap-2",
16
+ "rounded-md border border-transparent font-medium whitespace-nowrap text-text-default select-none",
17
+ "transition-colors duration-(--gw-motion-duration-fast)",
18
+ "hover:bg-action-ghost-bg-hover data-selected:bg-action-secondary-bg-hover data-selected:border-border-input",
19
+ "disabled:cursor-not-allowed disabled:opacity-50 data-disabled:cursor-not-allowed data-disabled:opacity-50",
20
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
21
+ ], {
22
+ variants: {
23
+ variant: {
24
+ ghost: "bg-transparent",
25
+ secondary: "border-border-input bg-action-secondary-bg",
26
+ },
27
+ size: {
28
+ sm: "h-8 min-w-8 px-2 text-xs [&_svg]:size-4",
29
+ md: "h-10 min-w-10 px-3 text-body [&_svg]:size-4",
30
+ lg: "h-11 min-w-11 px-4 text-md [&_svg]:size-5",
31
+ },
32
+ },
33
+ defaultVariants: { variant: "ghost", size: "md" },
34
+ });
35
+ export function Toggle({ className, variant = "ghost", size = "md", children, ...props }) {
36
+ return (_jsx(TogglePrimitive, { "data-slot": "toggle", "data-variant": variant, "data-size": size, className: cn(toggleVariants({ variant, size }), className), ...props, children: composeRenderProps(children, (c) => c) }));
37
+ }
@@ -0,0 +1,6 @@
1
+ import { type TooltipProps as TooltipPrimitiveProps, type TooltipTriggerComponentProps } from "react-aria-components";
2
+ export declare function Tooltip({ delay, closeDelay, ...props }: TooltipTriggerComponentProps): import("react").JSX.Element;
3
+ export type TooltipContentProps = Omit<TooltipPrimitiveProps, "className" | "style"> & {
4
+ className?: string;
5
+ };
6
+ export declare function TooltipContent({ className, offset, ...props }: TooltipContentProps): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Tooltip as TooltipPrimitive, TooltipTrigger, } from "react-aria-components";
4
+ import { cn } from "../lib/utils.js";
5
+ /*
6
+ * Adapted from shadcn/ui (aria-nova). Copyright (c) 2023 shadcn. MIT licence.
7
+ *
8
+ * Figma contract: Tooltip, TooltipContent { placement }
9
+ *
10
+ * <Tooltip>
11
+ * <Button aria-label="Archive" variant="ghost"><ArchiveIcon aria-hidden /></Button>
12
+ * <TooltipContent>Archive</TooltipContent>
13
+ * </Tooltip>
14
+ *
15
+ * Shows on hover and on keyboard focus, and Escape hides it (WCAG 1.4.13).
16
+ * Tooltips are a hint, not the only place to find information: never put
17
+ * anything essential or interactive in one, and touch users won't see it.
18
+ */
19
+ export function Tooltip({ delay = 600, closeDelay = 200, ...props }) {
20
+ return _jsx(TooltipTrigger, { delay: delay, closeDelay: closeDelay, ...props });
21
+ }
22
+ export function TooltipContent({ className, offset = 6, ...props }) {
23
+ return (_jsx(TooltipPrimitive, { "data-slot": "tooltip", offset: offset, className: cn("max-w-xs rounded-sm bg-text-default px-2 py-1 text-sm text-surface-default", "transition-opacity duration-(--gw-motion-duration-fade) data-entering:opacity-0 data-exiting:opacity-0", className), ...props }));
24
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,38 @@
1
+ export { Accordion, AccordionContent, type AccordionContentProps, AccordionItem, type AccordionItemProps, type AccordionProps, AccordionTrigger, type AccordionTriggerProps, } from "./components/accordion.js";
2
+ export { Alert, type AlertProps, type AlertVariant } from "./components/alert.js";
3
+ export { AlertDialog, AlertDialogContent, type AlertDialogContentProps, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "./components/alert-dialog.js";
4
+ export { Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps } from "./components/avatar.js";
5
+ export { Badge, type BadgeProps, type BadgeVariant, badgeVariants } from "./components/badge.js";
6
+ export { Breadcrumb, BreadcrumbItem, type BreadcrumbItemProps, type BreadcrumbProps } from "./components/breadcrumb.js";
1
7
  export { BarChart, type BarChartProps, type BarChartSeries, type BarChartView } from "./components/bar-chart.js";
2
8
  export { Button, type ButtonProps, type ButtonSize, type ButtonVariant, buttonVariants } from "./components/button.js";
3
9
  export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type CardTitleProps, } from "./components/card.js";
10
+ export { Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps } from "./components/checkbox.js";
11
+ export { Collapsible, CollapsibleContent, type CollapsibleContentProps, type CollapsibleProps, CollapsibleTrigger, type CollapsibleTriggerProps, } from "./components/collapsible.js";
12
+ export { Combobox, ComboboxItem, type ComboboxItemProps, type ComboboxProps } from "./components/combobox.js";
13
+ export { Dialog, DialogBody, DialogContent, type DialogContentProps, DialogDescription, DialogFooter, DialogHeader, DialogTitle, type DialogTitleProps, } from "./components/dialog.js";
14
+ export { DropdownMenu, DropdownMenuContent, type DropdownMenuContentProps, DropdownMenuItem, type DropdownMenuItemProps, DropdownMenuSection, type DropdownMenuSectionProps, DropdownMenuSeparator, DropdownMenuSub, } from "./components/dropdown-menu.js";
15
+ export { Empty, type EmptyProps } from "./components/empty.js";
4
16
  export { Input, type InputProps } from "./components/input.js";
17
+ export { InputGroup, type InputGroupProps } from "./components/input-group.js";
18
+ export { Kbd, type KbdProps } from "./components/kbd.js";
19
+ export { Label, type LabelProps } from "./components/label.js";
20
+ export { Pagination, type PaginationProps } from "./components/pagination.js";
21
+ export { Popover, PopoverContent, type PopoverContentProps, PopoverTitle } from "./components/popover.js";
22
+ export { Progress, type ProgressProps } from "./components/progress.js";
23
+ export { Radio, RadioGroup, type RadioGroupProps, type RadioProps } from "./components/radio-group.js";
5
24
  export { Select, SelectItem, type SelectItemProps, type SelectProps } from "./components/select.js";
25
+ export { Separator, type SeparatorProps } from "./components/separator.js";
26
+ export { Sheet, SheetBody, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, type SheetSide, SheetTitle, } from "./components/sheet.js";
27
+ export { Skeleton } from "./components/skeleton.js";
28
+ export { Slider, type SliderProps } from "./components/slider.js";
29
+ export { Spinner, type SpinnerProps } from "./components/spinner.js";
30
+ export { Switch, type SwitchProps } from "./components/switch.js";
6
31
  export { Table, TableBody, TableCell, TableColumn, type TableDensity, TableHeader, type TableProps, TableRow, } from "./components/table.js";
32
+ export { Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Tabs, type TabsProps, } from "./components/tabs.js";
7
33
  export { applyTheme, THEME_STORAGE_KEY, type ThemeChoice, ThemeToggle, type ThemeToggleProps, themeScript, } from "./components/theme-toggle.js";
34
+ export { Textarea, type TextareaProps } from "./components/textarea.js";
35
+ export { type ToastContent, Toaster, type ToasterProps, type ToastVariant, toast, toastQueue } from "./components/toast.js";
36
+ export { Toggle, type ToggleProps, type ToggleVariant, toggleVariants } from "./components/toggle.js";
37
+ export { Tooltip, TooltipContent, type TooltipContentProps } from "./components/tooltip.js";
8
38
  export { cn } from "./lib/utils.js";
package/dist/index.js CHANGED
@@ -1,8 +1,38 @@
1
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "./components/accordion.js";
2
+ export { Alert } from "./components/alert.js";
3
+ export { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "./components/alert-dialog.js";
4
+ export { Avatar, AvatarGroup } from "./components/avatar.js";
5
+ export { Badge, badgeVariants } from "./components/badge.js";
6
+ export { Breadcrumb, BreadcrumbItem } from "./components/breadcrumb.js";
1
7
  export { BarChart } from "./components/bar-chart.js";
2
8
  export { Button, buttonVariants } from "./components/button.js";
3
9
  export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "./components/card.js";
10
+ export { Checkbox, CheckboxGroup } from "./components/checkbox.js";
11
+ export { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "./components/collapsible.js";
12
+ export { Combobox, ComboboxItem } from "./components/combobox.js";
13
+ export { Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "./components/dialog.js";
14
+ export { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSection, DropdownMenuSeparator, DropdownMenuSub, } from "./components/dropdown-menu.js";
15
+ export { Empty } from "./components/empty.js";
4
16
  export { Input } from "./components/input.js";
17
+ export { InputGroup } from "./components/input-group.js";
18
+ export { Kbd } from "./components/kbd.js";
19
+ export { Label } from "./components/label.js";
20
+ export { Pagination } from "./components/pagination.js";
21
+ export { Popover, PopoverContent, PopoverTitle } from "./components/popover.js";
22
+ export { Progress } from "./components/progress.js";
23
+ export { Radio, RadioGroup } from "./components/radio-group.js";
5
24
  export { Select, SelectItem } from "./components/select.js";
25
+ export { Separator } from "./components/separator.js";
26
+ export { Sheet, SheetBody, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, } from "./components/sheet.js";
27
+ export { Skeleton } from "./components/skeleton.js";
28
+ export { Slider } from "./components/slider.js";
29
+ export { Spinner } from "./components/spinner.js";
30
+ export { Switch } from "./components/switch.js";
6
31
  export { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow, } from "./components/table.js";
32
+ export { Tab, TabList, TabPanel, Tabs, } from "./components/tabs.js";
7
33
  export { applyTheme, THEME_STORAGE_KEY, ThemeToggle, themeScript, } from "./components/theme-toggle.js";
34
+ export { Textarea } from "./components/textarea.js";
35
+ export { Toaster, toast, toastQueue } from "./components/toast.js";
36
+ export { Toggle, toggleVariants } from "./components/toggle.js";
37
+ export { Tooltip, TooltipContent } from "./components/tooltip.js";
8
38
  export { cn } from "./lib/utils.js";
@@ -1 +1 @@
1
- export { cn } from "cn";
1
+ export declare const cn: import("cn/config").CnFunction;
package/dist/lib/utils.js CHANGED
@@ -1 +1,6 @@
1
- export { cn } from "cn";
1
+ import { createCn } from "cn/config";
2
+ // Font sizes from @graftwork/tokens that aren't t-shirt sizes. Without this,
3
+ // cn reads `text-body` as a text colour and drops it next to `text-text-default`.
4
+ export const cn = createCn({
5
+ extend: { classGroups: { "font-size": [{ text: ["body"] }] } },
6
+ });
package/dist/styles.css CHANGED
@@ -5,7 +5,7 @@
5
5
  * @import "@graftwork/ui/styles.css";
6
6
  * @source "../node_modules/@graftwork/ui/dist";
7
7
  */
8
- @import "@fontsource-variable/noto-sans";
8
+ @import "@fontsource-variable/geist";
9
9
  @import "@graftwork/tokens/css";
10
10
  @import "@graftwork/tokens/tailwind.css";
11
11
 
@@ -25,6 +25,15 @@
25
25
  }
26
26
  }
27
27
 
28
+ /*
29
+ * The same ring, drawn unconditionally. For a part that shows focus on behalf of
30
+ * its focused parent, e.g. group-data-focus-visible/selection:focus-ring-drawn.
31
+ */
32
+ @utility focus-ring-drawn {
33
+ outline: var(--gw-focus-ring-width) solid var(--gw-color-focus-ring);
34
+ outline-offset: var(--gw-focus-ring-offset);
35
+ }
36
+
28
37
  /* WCAG 2.5.5: extends the hit area to at least 44 × 44px without changing the look. */
29
38
  @utility hit-area {
30
39
  position: relative;
@@ -85,6 +94,7 @@
85
94
 
86
95
  body {
87
96
  min-width: 20rem;
97
+ font-size: var(--gw-font-size-body);
88
98
  }
89
99
 
90
100
  /* Every focusable element gets a visible ring unless a component draws its own. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graftwork/ui",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "Graftwork React components, built on shadcn/ui with React Aria",
5
5
  "license": "MIT",
6
6
  "homepage": "https://graftwork-studio.github.io/design-system/",
@@ -40,8 +40,8 @@
40
40
  }
41
41
  },
42
42
  "dependencies": {
43
- "@fontsource-variable/noto-sans": "5.3.0",
44
- "@graftwork/tokens": "^1.1.1",
43
+ "@fontsource-variable/geist": "5.3.0",
44
+ "@graftwork/tokens": "^1.3.0",
45
45
  "class-variance-authority": "0.7.1",
46
46
  "cn": "0.5.2",
47
47
  "lucide-react": "1.74.0",