@idyeah/diya 0.0.0 → 1.0.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 (190) hide show
  1. package/CHANGELOG.md +317 -0
  2. package/NOTICE +29 -0
  3. package/README.md +596 -5
  4. package/dist/DiyaProvider.d.ts +79 -0
  5. package/dist/DiyaProvider.js +77 -0
  6. package/dist/Icon.d.ts +10 -0
  7. package/dist/Icon.js +27 -0
  8. package/dist/accordion/Accordion.d.ts +34 -0
  9. package/dist/accordion/Accordion.js +15 -0
  10. package/dist/alert/Alert.d.ts +49 -0
  11. package/dist/alert/Alert.js +11 -0
  12. package/dist/alert/messages.d.ts +9 -0
  13. package/dist/alert/messages.js +2 -0
  14. package/dist/api.json +7277 -0
  15. package/dist/api.schema.json +214 -0
  16. package/dist/application-patterns/Chatbot.d.ts +114 -0
  17. package/dist/application-patterns/Chatbot.js +110 -0
  18. package/dist/application-patterns/SideNavigation.d.ts +74 -0
  19. package/dist/application-patterns/SideNavigation.js +31 -0
  20. package/dist/application-patterns/chatbot-messages.d.ts +20 -0
  21. package/dist/application-patterns/chatbot-messages.js +2 -0
  22. package/dist/application-patterns/side-navigation-messages.d.ts +5 -0
  23. package/dist/application-patterns/side-navigation-messages.js +2 -0
  24. package/dist/avatar/Avatar.d.ts +32 -0
  25. package/dist/avatar/Avatar.js +19 -0
  26. package/dist/avatar/messages.d.ts +7 -0
  27. package/dist/avatar/messages.js +2 -0
  28. package/dist/badge/Badge.d.ts +42 -0
  29. package/dist/badge/Badge.js +16 -0
  30. package/dist/badge/badge-utils.d.ts +6 -0
  31. package/dist/badge/badge-utils.js +24 -0
  32. package/dist/badge/messages.d.ts +4 -0
  33. package/dist/badge/messages.js +2 -0
  34. package/dist/breadcrumbs/Breadcrumbs.d.ts +34 -0
  35. package/dist/breadcrumbs/Breadcrumbs.js +19 -0
  36. package/dist/breadcrumbs/messages.d.ts +5 -0
  37. package/dist/breadcrumbs/messages.js +2 -0
  38. package/dist/button/Button.d.ts +46 -0
  39. package/dist/button/Button.js +44 -0
  40. package/dist/calendar/Calendar.d.ts +55 -0
  41. package/dist/calendar/Calendar.js +61 -0
  42. package/dist/calendar/messages.d.ts +8 -0
  43. package/dist/calendar/messages.js +2 -0
  44. package/dist/calendar/month.d.ts +61 -0
  45. package/dist/calendar/month.js +134 -0
  46. package/dist/card/Card.d.ts +46 -0
  47. package/dist/card/Card.js +8 -0
  48. package/dist/choice/Choice.d.ts +72 -0
  49. package/dist/choice/Choice.js +68 -0
  50. package/dist/choice/messages.d.ts +4 -0
  51. package/dist/choice/messages.js +2 -0
  52. package/dist/code-block/CodeBlock.d.ts +20 -0
  53. package/dist/code-block/CodeBlock.js +49 -0
  54. package/dist/code-block/messages.d.ts +8 -0
  55. package/dist/code-block/messages.js +2 -0
  56. package/dist/combobox/Combobox.d.ts +60 -0
  57. package/dist/combobox/Combobox.js +160 -0
  58. package/dist/combobox/messages.d.ts +9 -0
  59. package/dist/combobox/messages.js +2 -0
  60. package/dist/combobox/useAnchoredPopover.d.ts +5 -0
  61. package/dist/combobox/useAnchoredPopover.js +100 -0
  62. package/dist/data-viz/DataViz.d.ts +140 -0
  63. package/dist/data-viz/DataViz.js +469 -0
  64. package/dist/data-viz/index.d.ts +2 -0
  65. package/dist/data-viz/index.js +1 -0
  66. package/dist/data-viz/messages.d.ts +11 -0
  67. package/dist/data-viz/messages.js +2 -0
  68. package/dist/date-picker/DatePicker.d.ts +57 -0
  69. package/dist/date-picker/DatePicker.js +146 -0
  70. package/dist/date-picker/messages.d.ts +13 -0
  71. package/dist/date-picker/messages.js +2 -0
  72. package/dist/dialog/Dialog.d.ts +84 -0
  73. package/dist/dialog/Dialog.js +107 -0
  74. package/dist/dialog/messages.d.ts +9 -0
  75. package/dist/dialog/messages.js +2 -0
  76. package/dist/fonts/DIYASans-Italic.woff2 +0 -0
  77. package/dist/fonts/DIYASans.woff2 +0 -0
  78. package/dist/fonts/OFL.txt +94 -0
  79. package/dist/index.d.ts +50 -0
  80. package/dist/index.js +46 -0
  81. package/dist/internal/brand.d.ts +33 -0
  82. package/dist/internal/brand.js +57 -0
  83. package/dist/internal/cx.d.ts +2 -0
  84. package/dist/internal/cx.js +4 -0
  85. package/dist/internal/link.d.ts +14 -0
  86. package/dist/internal/link.js +7 -0
  87. package/dist/internal/slot.d.ts +15 -0
  88. package/dist/internal/slot.js +67 -0
  89. package/dist/layout/Inline.d.ts +4 -0
  90. package/dist/layout/Inline.js +7 -0
  91. package/dist/layout/Stack.d.ts +4 -0
  92. package/dist/layout/Stack.js +7 -0
  93. package/dist/layout/layout.d.ts +32 -0
  94. package/dist/layout/layout.js +12 -0
  95. package/dist/link/TextLink.d.ts +23 -0
  96. package/dist/link/TextLink.js +17 -0
  97. package/dist/list/List.d.ts +48 -0
  98. package/dist/list/List.js +17 -0
  99. package/dist/list/messages.d.ts +4 -0
  100. package/dist/list/messages.js +2 -0
  101. package/dist/menu/Menu.d.ts +49 -0
  102. package/dist/menu/Menu.js +54 -0
  103. package/dist/messages-defaults.d.ts +201 -0
  104. package/dist/messages-defaults.js +61 -0
  105. package/dist/messages.d.ts +12 -0
  106. package/dist/messages.js +1 -0
  107. package/dist/metric/Metric.d.ts +42 -0
  108. package/dist/metric/Metric.js +11 -0
  109. package/dist/metric/messages.d.ts +9 -0
  110. package/dist/metric/messages.js +2 -0
  111. package/dist/overlay/FloatingSurface.d.ts +29 -0
  112. package/dist/overlay/FloatingSurface.js +254 -0
  113. package/dist/page-header/PageHeader.d.ts +38 -0
  114. package/dist/page-header/PageHeader.js +10 -0
  115. package/dist/pagination/Pagination.d.ts +44 -0
  116. package/dist/pagination/Pagination.js +26 -0
  117. package/dist/pagination/messages.d.ts +11 -0
  118. package/dist/pagination/messages.js +2 -0
  119. package/dist/popover/Popover.d.ts +23 -0
  120. package/dist/popover/Popover.js +8 -0
  121. package/dist/progress/Progress.d.ts +33 -0
  122. package/dist/progress/Progress.js +14 -0
  123. package/dist/progress/messages.d.ts +4 -0
  124. package/dist/progress/messages.js +2 -0
  125. package/dist/prose/Prose.d.ts +14 -0
  126. package/dist/prose/Prose.js +7 -0
  127. package/dist/rating/Rating.d.ts +32 -0
  128. package/dist/rating/Rating.js +27 -0
  129. package/dist/rating/messages.d.ts +6 -0
  130. package/dist/rating/messages.js +2 -0
  131. package/dist/search/Search.d.ts +11 -0
  132. package/dist/search/Search.js +9 -0
  133. package/dist/select/Select.d.ts +65 -0
  134. package/dist/select/Select.js +19 -0
  135. package/dist/select/messages.d.ts +4 -0
  136. package/dist/select/messages.js +2 -0
  137. package/dist/site-header/SiteHeader.d.ts +88 -0
  138. package/dist/site-header/SiteHeader.js +211 -0
  139. package/dist/site-header/messages.d.ts +8 -0
  140. package/dist/site-header/messages.js +2 -0
  141. package/dist/slider/Slider.d.ts +54 -0
  142. package/dist/slider/Slider.js +89 -0
  143. package/dist/slider/messages.d.ts +5 -0
  144. package/dist/slider/messages.js +2 -0
  145. package/dist/styles.css +3379 -0
  146. package/dist/switch/Switch.d.ts +47 -0
  147. package/dist/switch/Switch.js +18 -0
  148. package/dist/table/Table.d.ts +99 -0
  149. package/dist/table/Table.js +158 -0
  150. package/dist/table/messages.d.ts +23 -0
  151. package/dist/table/messages.js +2 -0
  152. package/dist/tabs/Tabs.d.ts +49 -0
  153. package/dist/tabs/Tabs.js +26 -0
  154. package/dist/tag/Tag.d.ts +37 -0
  155. package/dist/tag/Tag.js +20 -0
  156. package/dist/tag/messages.d.ts +4 -0
  157. package/dist/tag/messages.js +2 -0
  158. package/dist/text-area/TextArea.d.ts +47 -0
  159. package/dist/text-area/TextArea.js +19 -0
  160. package/dist/text-input/TextInput.d.ts +53 -0
  161. package/dist/text-input/TextInput.js +35 -0
  162. package/dist/text-input/messages.d.ts +4 -0
  163. package/dist/text-input/messages.js +3 -0
  164. package/dist/text-input/native-field.d.ts +15 -0
  165. package/dist/text-input/native-field.js +56 -0
  166. package/dist/toast/Toast.d.ts +24 -0
  167. package/dist/toast/Toast.js +79 -0
  168. package/dist/toast/messages.d.ts +4 -0
  169. package/dist/toast/messages.js +2 -0
  170. package/dist/tooltip/Tooltip.d.ts +22 -0
  171. package/dist/tooltip/Tooltip.js +92 -0
  172. package/dist/workflow/ContentState.d.ts +44 -0
  173. package/dist/workflow/ContentState.js +11 -0
  174. package/dist/workflow/Drawer.d.ts +48 -0
  175. package/dist/workflow/Drawer.js +51 -0
  176. package/dist/workflow/FileUpload.d.ts +67 -0
  177. package/dist/workflow/FileUpload.js +47 -0
  178. package/dist/workflow/Form.d.ts +52 -0
  179. package/dist/workflow/Form.js +16 -0
  180. package/dist/workflow/Wizard.d.ts +76 -0
  181. package/dist/workflow/Wizard.js +31 -0
  182. package/dist/workflow/drawer-messages.d.ts +4 -0
  183. package/dist/workflow/drawer-messages.js +2 -0
  184. package/dist/workflow/file-upload-messages.d.ts +11 -0
  185. package/dist/workflow/file-upload-messages.js +2 -0
  186. package/dist/workflow/form-messages.d.ts +5 -0
  187. package/dist/workflow/form-messages.js +2 -0
  188. package/dist/workflow/wizard-messages.d.ts +9 -0
  189. package/dist/workflow/wizard-messages.js +2 -0
  190. package/package.json +82 -7
@@ -0,0 +1,146 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useId, useMemo, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { display, iso, monthOf, outsideLimits, useMonthGrid } from '../calendar/month.js';
6
+ import { adjacentTabStop, useAnchoredPopover } from '../combobox/useAnchoredPopover.js';
7
+ import { useDiyaLocale, useDiyaMessages } from '../DiyaProvider.js';
8
+ import { cx } from '../internal/cx.js';
9
+ import { useFormReset, useMergedRef } from '../text-input/native-field.js';
10
+ import { datePickerMessages } from './messages.js';
11
+ /** A labeled date field that opens a calendar popup; picks one ISO date, or a start and end date with `range`. */
12
+ export const DatePicker = forwardRef(function DatePicker(props, ref) {
13
+ const { label, disabled = false, error, hideLabel = false, helperText, size = 'medium', min, max, isDateUnavailable, name, className, style, onClick: onTriggerClick, onKeyDown: onTriggerKeyDown, 'aria-describedby': describedBy, range: _range, value: _value, defaultValue: _defaultValue, onValueChange: _onValueChange, ...rest } = props;
14
+ const t = useDiyaMessages('datePicker', datePickerMessages);
15
+ const locale = useDiyaLocale();
16
+ const range = props.range === true;
17
+ const controlled = props.value !== undefined;
18
+ const initial = () => props.range ? props.defaultValue ?? { start: '', end: '' } : { start: props.defaultValue ?? '', end: '' };
19
+ const [uncontrolled, setUncontrolled] = useState(initial);
20
+ // Internally a value is always a range; a single date is { start: date, end: '' }.
21
+ const value = !controlled ? uncontrolled : props.range ? props.value ?? { start: '', end: '' } : { start: props.value ?? '', end: '' };
22
+ const onChange = (next) => {
23
+ if (!controlled)
24
+ setUncontrolled(next);
25
+ if (props.range)
26
+ props.onValueChange?.(next);
27
+ else
28
+ props.onValueChange?.(next.start);
29
+ };
30
+ const outside = (day) => outsideLimits(day, min, max) || !!isDateUnavailable?.(day);
31
+ const monthFor = (day) => monthOf(day, min, max);
32
+ const id = useId();
33
+ const [open, setOpen] = useState(false);
34
+ const [month, setMonth] = useState(() => monthFor(value.start));
35
+ const [choosingEnd, setChoosingEnd] = useState(false);
36
+ const field = useRef(null);
37
+ const trigger = useRef(null);
38
+ const triggerRef = useMergedRef(ref, trigger);
39
+ const calendar = useRef(null);
40
+ const isOpen = open && !disabled;
41
+ const popupContent = useMemo(() => ({ month, range, size }), [month, range, size]);
42
+ const portal = useAnchoredPopover(isOpen, trigger, calendar, 300, popupContent);
43
+ useFormReset(trigger, () => { if (!controlled)
44
+ setUncontrolled(initial()); });
45
+ const monthGrid = useMonthGrid({ locale, month, onMonthChange: setMonth, value, range, choosingEnd, min, max, isDateUnavailable, active: isOpen, strings: t, onChoose: choose });
46
+ function close() { setOpen(false); setChoosingEnd(false); }
47
+ function escape(event) {
48
+ if (event.key !== 'Escape' || !isOpen)
49
+ return;
50
+ event.preventDefault();
51
+ event.stopPropagation();
52
+ close();
53
+ trigger.current?.focus();
54
+ }
55
+ useEffect(() => { if (disabled)
56
+ close(); }, [disabled]);
57
+ useEffect(() => {
58
+ if (!isOpen)
59
+ return;
60
+ const outside = (event) => {
61
+ if (!field.current?.contains(event.target) && !calendar.current?.contains(event.target))
62
+ close();
63
+ };
64
+ const resize = () => {
65
+ if (calendar.current?.contains(document.activeElement))
66
+ trigger.current?.focus();
67
+ close();
68
+ };
69
+ const scroll = (event) => { if (!calendar.current?.contains(event.target))
70
+ resize(); };
71
+ document.addEventListener('pointerdown', outside);
72
+ window.addEventListener('resize', resize);
73
+ window.addEventListener('scroll', scroll, true);
74
+ return () => {
75
+ document.removeEventListener('pointerdown', outside);
76
+ window.removeEventListener('resize', resize);
77
+ window.removeEventListener('scroll', scroll, true);
78
+ };
79
+ }, [isOpen]);
80
+ const today = iso(new Date());
81
+ function choose(day) {
82
+ if (disabled || outside(day))
83
+ return;
84
+ if (range && (!choosingEnd || !value.start)) {
85
+ onChange({ start: day, end: '' });
86
+ setChoosingEnd(true);
87
+ }
88
+ else {
89
+ onChange(range ? { start: day < value.start ? day : value.start, end: day < value.start ? value.start : day } : { start: day, end: '' });
90
+ close();
91
+ trigger.current?.focus();
92
+ }
93
+ }
94
+ // Tab moves through the calendar's controls: the month buttons, one day, then Today and Clear.
95
+ const tabStops = () => Array.from(calendar.current?.querySelectorAll('button:not(:disabled)') ?? []).filter((button) => button.tabIndex >= 0);
96
+ return _jsxs("div", { ref: field, className: cx('diya-date-field', className), style: style, "data-size": size, "data-invalid": !!error, onBlur: (event) => {
97
+ const next = event.relatedTarget;
98
+ if (!field.current?.contains(next) && !calendar.current?.contains(next))
99
+ close();
100
+ }, children: [_jsx("label", { id: `${id}-label`, className: hideLabel ? 'diya-sr-only' : '', children: label }), name && (range ? [value.start, value.end] : [value.start]).map((entry, index) => _jsx("input", { type: "hidden", name: name, value: entry, disabled: disabled }, index)), _jsxs("button", { ...rest, ref: triggerRef, type: "button", className: "diya-date-trigger", disabled: disabled, "aria-labelledby": `${id}-label ${id}-value`, "aria-expanded": isOpen, "aria-controls": isOpen ? `${id}-calendar` : undefined, "aria-describedby": [describedBy, error || helperText ? `${id}-help` : undefined].filter(Boolean).join(' ') || undefined, "aria-invalid": !!error, onClick: (event) => {
101
+ onTriggerClick?.(event);
102
+ if (event.defaultPrevented)
103
+ return;
104
+ if (isOpen)
105
+ close();
106
+ else if (!disabled) {
107
+ setMonth(monthFor(value.start));
108
+ monthGrid.resetCursor();
109
+ setChoosingEnd(range && !!value.start && !value.end);
110
+ setOpen(true);
111
+ }
112
+ }, onKeyDown: (event) => {
113
+ onTriggerKeyDown?.(event);
114
+ if (event.defaultPrevented)
115
+ return;
116
+ escape(event);
117
+ if (isOpen && event.key === 'Tab' && !event.shiftKey) {
118
+ const firstControl = tabStops()[0];
119
+ if (firstControl) {
120
+ event.preventDefault();
121
+ firstControl.focus();
122
+ }
123
+ }
124
+ }, children: [_jsxs("span", { id: `${id}-value`, children: [value.start ? `${display(value.start, locale)}${range ? ` – ${value.end ? display(value.end, locale) : t.endDate}` : ''}` : range ? t.chooseRange : t.chooseDate, " "] }), _jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: [_jsx("rect", { x: "3", y: "5", width: "18", height: "16", rx: "3" }), _jsx("path", { d: "M7 3v4m10-4v4M3 10h18" })] })] }), (error || helperText) && _jsxs("p", { id: `${id}-help`, className: "diya-field-help", children: [error && _jsx("span", { "aria-hidden": "true", children: "!" }), error || helperText] }), isOpen && portal && createPortal(_jsxs("div", { ref: calendar, id: `${id}-calendar`, className: "diya-calendar", role: "group", "aria-label": t.chooseDate, onKeyDown: (event) => {
125
+ escape(event);
126
+ if (event.key !== 'Tab')
127
+ return;
128
+ const controls = tabStops();
129
+ if (event.shiftKey && event.target === controls[0]) {
130
+ event.preventDefault();
131
+ trigger.current?.focus();
132
+ }
133
+ else if (!event.shiftKey && event.target === controls[controls.length - 1]) {
134
+ const destination = trigger.current && adjacentTabStop(trigger.current, calendar.current, false);
135
+ close();
136
+ if (destination) {
137
+ destination.focus();
138
+ if (destination.ownerDocument.activeElement === destination)
139
+ event.preventDefault();
140
+ }
141
+ }
142
+ }, style: { position: 'fixed', inset: 'auto', margin: 0 }, children: [monthGrid.render(), _jsxs("div", { className: "diya-calendar-footer", children: [_jsx("button", { type: "button", disabled: outside(today), onClick: () => { setMonth(monthFor(today)); choose(today); }, children: t.today }), _jsx("button", { type: "button", onClick: () => { if (!disabled) {
143
+ onChange({ start: '', end: '' });
144
+ setChoosingEnd(false);
145
+ } }, children: t.clear })] })] }), portal)] });
146
+ });
@@ -0,0 +1,13 @@
1
+ /** datePicker: English defaults, overridable through DiyaProvider `messages`. */
2
+ export declare const datePickerMessages: {
3
+ chooseDate: string;
4
+ chooseRange: string;
5
+ chooseStart: string;
6
+ chooseEnd: string;
7
+ endDate: string;
8
+ previousMonth: string;
9
+ nextMonth: string;
10
+ today: string;
11
+ clear: string;
12
+ unavailableDay: (date: string) => string;
13
+ };
@@ -0,0 +1,2 @@
1
+ /** datePicker: English defaults, overridable through DiyaProvider `messages`. */
2
+ export const datePickerMessages = { chooseDate: 'Choose date', chooseRange: 'Choose date range', chooseStart: 'Choose start date', chooseEnd: 'Choose end date', endDate: 'End date', previousMonth: 'Previous month', nextMonth: 'Next month', today: 'Today', clear: 'Clear', unavailableDay: (date) => `${date}, unavailable` };
@@ -0,0 +1,84 @@
1
+ import { type DialogHTMLAttributes, type ReactElement, type ReactNode } from 'react';
2
+ import { dialogMessages } from './messages.js';
3
+ declare module '../messages.js' {
4
+ interface DiyaMessages {
5
+ dialog: typeof dialogMessages;
6
+ }
7
+ }
8
+ export type DialogProps = Omit<DialogHTMLAttributes<HTMLDialogElement>, 'title' | 'children' | 'open'> & {
9
+ /** Your own element that opens the dialog, such as `<Button>Edit project</Button>`; DIYA wires its click and `aria-haspopup`, and focus returns to it on close. */
10
+ trigger?: ReactElement;
11
+ /** Visible dialog heading; it is also the dialog's accessible name. */
12
+ title: string;
13
+ /** The title's heading level, 1 to 6; it looks the same at every level. Defaults to 3. */
14
+ headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
15
+ /** Supporting text under the title, also read as the dialog's description. */
16
+ description?: string;
17
+ /** Dialog width; defaults to 'medium'. */
18
+ size?: 'small' | 'medium' | 'large';
19
+ /** Dialog body. */
20
+ children?: ReactNode;
21
+ /** Replaces the default dismiss and confirm buttons. */
22
+ footer?: ReactNode;
23
+ /** Whether the dialog is open; leave it out to let `trigger` manage it. */
24
+ open?: boolean;
25
+ /** Called with the next open state whenever the dialog opens or closes. */
26
+ onOpenChange?: (open: boolean) => void;
27
+ /** Shows the confirm button. May be async; the dialog closes when it settles, unless it returns false. A thrown Error's message shows in the dialog. */
28
+ onConfirm?: () => void | boolean | Promise<void | boolean>;
29
+ /** Called when the person dismisses the dialog (dismiss or close button, Escape or a backdrop click). */
30
+ onDismiss?: () => void;
31
+ /** Confirm button text; defaults to "Save changes". */
32
+ confirmLabel?: string;
33
+ /** 'destructive' marks the confirm button as an action that deletes or can't be undone; defaults to 'solid'. */
34
+ confirmVariant?: 'solid' | 'destructive';
35
+ /** Dismiss button text; defaults to "Cancel" with `onConfirm`, otherwise "Close". */
36
+ dismissLabel?: string;
37
+ /** Disables the confirm button; defaults to false. */
38
+ confirmDisabled?: boolean;
39
+ /** Shows a spinner on the confirm button and blocks confirming; defaults to false. */
40
+ loading?: boolean;
41
+ /** Draws a line above the buttons; defaults to false. */
42
+ divided?: boolean;
43
+ /** Shows the close icon button in the corner; defaults to true. */
44
+ showClose?: boolean;
45
+ };
46
+ /** A modal dialog opened by your `trigger`, or controlled through `open`; focus returns on close. The ref, `className`, `style` and other attributes go to the native `dialog` element. */
47
+ export declare const Dialog: import("react").ForwardRefExoticComponent<Omit<DialogHTMLAttributes<HTMLDialogElement>, "children" | "open" | "title"> & {
48
+ /** Your own element that opens the dialog, such as `<Button>Edit project</Button>`; DIYA wires its click and `aria-haspopup`, and focus returns to it on close. */
49
+ trigger?: ReactElement;
50
+ /** Visible dialog heading; it is also the dialog's accessible name. */
51
+ title: string;
52
+ /** The title's heading level, 1 to 6; it looks the same at every level. Defaults to 3. */
53
+ headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
54
+ /** Supporting text under the title, also read as the dialog's description. */
55
+ description?: string;
56
+ /** Dialog width; defaults to 'medium'. */
57
+ size?: "small" | "medium" | "large";
58
+ /** Dialog body. */
59
+ children?: ReactNode;
60
+ /** Replaces the default dismiss and confirm buttons. */
61
+ footer?: ReactNode;
62
+ /** Whether the dialog is open; leave it out to let `trigger` manage it. */
63
+ open?: boolean;
64
+ /** Called with the next open state whenever the dialog opens or closes. */
65
+ onOpenChange?: (open: boolean) => void;
66
+ /** Shows the confirm button. May be async; the dialog closes when it settles, unless it returns false. A thrown Error's message shows in the dialog. */
67
+ onConfirm?: () => void | boolean | Promise<void | boolean>;
68
+ /** Called when the person dismisses the dialog (dismiss or close button, Escape or a backdrop click). */
69
+ onDismiss?: () => void;
70
+ /** Confirm button text; defaults to "Save changes". */
71
+ confirmLabel?: string;
72
+ /** 'destructive' marks the confirm button as an action that deletes or can't be undone; defaults to 'solid'. */
73
+ confirmVariant?: "solid" | "destructive";
74
+ /** Dismiss button text; defaults to "Cancel" with `onConfirm`, otherwise "Close". */
75
+ dismissLabel?: string;
76
+ /** Disables the confirm button; defaults to false. */
77
+ confirmDisabled?: boolean;
78
+ /** Shows a spinner on the confirm button and blocks confirming; defaults to false. */
79
+ loading?: boolean;
80
+ /** Draws a line above the buttons; defaults to false. */
81
+ divided?: boolean;
82
+ /** Shows the close icon button in the corner; defaults to true. */
83
+ showClose?: boolean;
84
+ } & import("react").RefAttributes<HTMLDialogElement>>;
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useId, useMemo, useRef, useState } from 'react';
4
+ import { Button } from '../button/Button.js';
5
+ import { useDiyaMessages } from '../DiyaProvider.js';
6
+ import { cx } from '../internal/cx.js';
7
+ import { composeRefs, renderSlot } from '../internal/slot.js';
8
+ import { dialogMessages } from './messages.js';
9
+ /** A modal dialog opened by your `trigger`, or controlled through `open`; focus returns on close. The ref, `className`, `style` and other attributes go to the native `dialog` element. */
10
+ export const Dialog = forwardRef(function Dialog({ trigger: triggerElement, title, headingLevel = 3, description, size = 'medium', children, footer, open: controlledOpen, onOpenChange, onConfirm, onDismiss, confirmLabel, confirmVariant = 'solid', dismissLabel, confirmDisabled = false, loading = false, divided = false, showClose = true, className, onCancel, onClose, onClick, ...props }, ref) {
11
+ const t = useDiyaMessages('dialog', dialogMessages);
12
+ const [localOpen, setLocalOpen] = useState(false);
13
+ const [pending, setPending] = useState(false);
14
+ const [error, setError] = useState('');
15
+ const open = controlledOpen ?? localOpen;
16
+ const busy = loading || pending;
17
+ const dialog = useRef(null);
18
+ const setDialog = useMemo(() => composeRefs(dialog, ref), [ref]);
19
+ const trigger = useRef(null);
20
+ const Heading = `h${headingLevel}`;
21
+ const previousFocus = useRef(null);
22
+ const operation = useRef(0);
23
+ const id = useId();
24
+ function change(next) {
25
+ if (controlledOpen === undefined)
26
+ setLocalOpen(next);
27
+ onOpenChange?.(next);
28
+ }
29
+ function dismiss() {
30
+ operation.current += 1;
31
+ setPending(false);
32
+ change(false);
33
+ onDismiss?.();
34
+ }
35
+ useEffect(() => () => {
36
+ operation.current += 1;
37
+ }, []);
38
+ useEffect(() => {
39
+ const node = dialog.current;
40
+ if (!node)
41
+ return;
42
+ if (open && !node.open) {
43
+ previousFocus.current =
44
+ document.activeElement instanceof HTMLElement ? document.activeElement : null;
45
+ setError('');
46
+ if (typeof node.showModal === 'function')
47
+ node.showModal();
48
+ else
49
+ node.setAttribute('open', '');
50
+ }
51
+ else if (!open && node.open) {
52
+ operation.current += 1;
53
+ setPending(false);
54
+ if (typeof node.close === 'function')
55
+ node.close();
56
+ else
57
+ node.removeAttribute('open');
58
+ (trigger.current ?? previousFocus.current)?.focus();
59
+ }
60
+ }, [open]);
61
+ async function confirm() {
62
+ if (busy || confirmDisabled || !onConfirm)
63
+ return;
64
+ const request = ++operation.current;
65
+ setPending(true);
66
+ setError('');
67
+ try {
68
+ if ((await onConfirm()) !== false && request === operation.current)
69
+ change(false);
70
+ }
71
+ catch (failure) {
72
+ if (request === operation.current)
73
+ setError(failure instanceof Error ? failure.message : t.error);
74
+ }
75
+ finally {
76
+ if (request === operation.current)
77
+ setPending(false);
78
+ }
79
+ }
80
+ const content = (_jsxs("div", { className: "diya-dialog-layout", children: [_jsxs("div", { className: "diya-dialog-heading", children: [_jsxs("div", { children: [_jsx(Heading, { id: id + '-title', className: "diya-dialog-title", children: title }), description && (_jsx("p", { id: id + '-description', className: "diya-dialog-description", children: description }))] }), showClose && (_jsx("button", { type: "button", className: "diya-dialog-close", "aria-label": t.close, onClick: dismiss, children: _jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: _jsx("path", { d: "m5 5 10 10M15 5 5 15" }) }) }))] }), children && _jsx("div", { className: "diya-dialog-content", children: children }), error && (_jsx("p", { className: "diya-workflow-error", role: "alert", children: error })), _jsx("div", { className: "diya-dialog-actions", "data-divider": divided || undefined, children: footer ?? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "quiet", onClick: dismiss, children: dismissLabel ?? (onConfirm ? t.dismiss : t.closeAction) }), onConfirm && (_jsx(Button, { variant: confirmVariant, loading: busy, disabled: confirmDisabled, onClick: confirm, children: confirmLabel ?? t.confirm }))] })) })] }));
81
+ return (_jsxs(_Fragment, { children: [triggerElement && renderSlot(triggerElement, { 'aria-haspopup': 'dialog', onClick: () => change(true) }, trigger), _jsx("dialog", { ...props, ref: setDialog, className: cx('diya-dialog', className), "data-size": size, "aria-labelledby": id + '-title', "aria-describedby": description ? id + '-description' : undefined, onCancel: (event) => {
82
+ onCancel?.(event);
83
+ if (event.defaultPrevented)
84
+ return;
85
+ event.preventDefault();
86
+ dismiss();
87
+ }, onClose: (event) => {
88
+ onClose?.(event);
89
+ if (event.currentTarget.open)
90
+ return;
91
+ operation.current += 1;
92
+ setPending(false);
93
+ if (open)
94
+ change(false);
95
+ (trigger.current ?? previousFocus.current)?.focus();
96
+ }, onClick: (event) => {
97
+ onClick?.(event);
98
+ if (event.target !== event.currentTarget)
99
+ return;
100
+ const box = event.currentTarget.getBoundingClientRect();
101
+ if (event.clientX < box.left ||
102
+ event.clientX > box.right ||
103
+ event.clientY < box.top ||
104
+ event.clientY > box.bottom)
105
+ dismiss();
106
+ }, children: content })] }));
107
+ });
@@ -0,0 +1,9 @@
1
+ /** dialog: English defaults, overridable through DiyaProvider `messages`. */
2
+ export declare const dialogMessages: {
3
+ open: string;
4
+ confirm: string;
5
+ dismiss: string;
6
+ closeAction: string;
7
+ close: string;
8
+ error: string;
9
+ };
@@ -0,0 +1,2 @@
1
+ /** dialog: English defaults, overridable through DiyaProvider `messages`. */
2
+ export const dialogMessages = { open: 'Open dialog', confirm: 'Save changes', dismiss: 'Cancel', closeAction: 'Close', close: 'Close dialog', error: 'Could not complete the action. Try again.' };
Binary file
Binary file
@@ -0,0 +1,94 @@
1
+ Copyright 2022 The Mona Sans Project Authors (https://github.com/github/mona-sans), with Reserved Font Name "Mona"
2
+ Copyright 2026 IDYeah Studio (https://diya13.ai), for the modifications in DIYA Sans.
3
+
4
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
5
+ This license is copied below, and is also available with a FAQ at:
6
+ https://openfontlicense.org
7
+
8
+
9
+ -----------------------------------------------------------
10
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11
+ -----------------------------------------------------------
12
+
13
+ PREAMBLE
14
+ The goals of the Open Font License (OFL) are to stimulate worldwide
15
+ development of collaborative font projects, to support the font creation
16
+ efforts of academic and linguistic communities, and to provide a free and
17
+ open framework in which fonts may be shared and improved in partnership
18
+ with others.
19
+
20
+ The OFL allows the licensed fonts to be used, studied, modified and
21
+ redistributed freely as long as they are not sold by themselves. The
22
+ fonts, including any derivative works, can be bundled, embedded,
23
+ redistributed and/or sold with any software provided that any reserved
24
+ names are not used by derivative works. The fonts and derivatives,
25
+ however, cannot be released under any other type of license. The
26
+ requirement for fonts to remain under this license does not apply
27
+ to any document created using the fonts or their derivatives.
28
+
29
+ DEFINITIONS
30
+ "Font Software" refers to the set of files released by the Copyright
31
+ Holder(s) under this license and clearly marked as such. This may
32
+ include source files, build scripts and documentation.
33
+
34
+ "Reserved Font Name" refers to any names specified as such after the
35
+ copyright statement(s).
36
+
37
+ "Original Version" refers to the collection of Font Software components as
38
+ distributed by the Copyright Holder(s).
39
+
40
+ "Modified Version" refers to any derivative made by adding to, deleting,
41
+ or substituting -- in part or in whole -- any of the components of the
42
+ Original Version, by changing formats or by porting the Font Software to a
43
+ new environment.
44
+
45
+ "Author" refers to any designer, engineer, programmer, technical
46
+ writer or other person who contributed to the Font Software.
47
+
48
+ PERMISSION & CONDITIONS
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
51
+ redistribute, and sell modified and unmodified copies of the Font
52
+ Software, subject to the following conditions:
53
+
54
+ 1) Neither the Font Software nor any of its individual components,
55
+ in Original or Modified Versions, may be sold by itself.
56
+
57
+ 2) Original or Modified Versions of the Font Software may be bundled,
58
+ redistributed and/or sold with any software, provided that each copy
59
+ contains the above copyright notice and this license. These can be
60
+ included either as stand-alone text files, human-readable headers or
61
+ in the appropriate machine-readable metadata fields within text or
62
+ binary files as long as those fields can be easily viewed by the user.
63
+
64
+ 3) No Modified Version of the Font Software may use the Reserved Font
65
+ Name(s) unless explicit written permission is granted by the corresponding
66
+ Copyright Holder. This restriction only applies to the primary font name as
67
+ presented to the users.
68
+
69
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70
+ Software shall not be used to promote, endorse or advertise any
71
+ Modified Version, except to acknowledge the contribution(s) of the
72
+ Copyright Holder(s) and the Author(s) or with their explicit written
73
+ permission.
74
+
75
+ 5) The Font Software, modified or unmodified, in part or in whole,
76
+ must be distributed entirely under this license, and must not be
77
+ distributed under any other license. The requirement for fonts to
78
+ remain under this license does not apply to any document created
79
+ using the Font Software.
80
+
81
+ TERMINATION
82
+ This license becomes null and void if any of the above conditions are
83
+ not met.
84
+
85
+ DISCLAIMER
86
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,50 @@
1
+ export { Button, type ButtonProps } from './button/Button.js';
2
+ export { PageHeader, type PageHeaderProps } from './page-header/PageHeader.js';
3
+ export { DiyaProvider, useDiyaAppearance, type DiyaProviderProps, type DiyaAppearance } from './DiyaProvider.js';
4
+ export type { DiyaBrandTokens } from './internal/brand.js';
5
+ export { Stack, type StackProps } from './layout/Stack.js';
6
+ export { Inline, type InlineProps } from './layout/Inline.js';
7
+ export type { LayoutProps, DiyaSpace, DiyaAlign, DiyaJustify, DiyaLayoutElement } from './layout/layout.js';
8
+ export type { DiyaMessages, DiyaMessagesInput } from './messages.js';
9
+ export { defaultMessages } from './messages-defaults.js';
10
+ export { Breadcrumbs, type BreadcrumbsProps, type BreadcrumbItem } from './breadcrumbs/Breadcrumbs.js';
11
+ export { Tabs, type TabsProps, type TabItem } from './tabs/Tabs.js';
12
+ export { Tag, type TagProps } from './tag/Tag.js';
13
+ export { Badge, type BadgeProps, type Tone } from './badge/Badge.js';
14
+ export { TextInput, type TextInputProps } from './text-input/TextInput.js';
15
+ export { TextArea, type TextAreaProps } from './text-area/TextArea.js';
16
+ export { Select, type SelectProps, type SelectOption } from './select/Select.js';
17
+ export { DatePicker, type DatePickerProps, type DatePickerSingleProps, type DatePickerRangeProps, type DateRange } from './date-picker/DatePicker.js';
18
+ export { Calendar, type CalendarProps, type CalendarSingleProps, type CalendarRangeProps } from './calendar/Calendar.js';
19
+ export { Combobox, type ComboboxProps, type ComboboxSingleProps, type ComboboxMultipleProps, type ComboboxOption } from './combobox/Combobox.js';
20
+ export { Choice, type ChoiceProps, type ChoiceSingleProps, type ChoiceMultipleProps, type ChoiceOption } from './choice/Choice.js';
21
+ export { Switch, type SwitchProps } from './switch/Switch.js';
22
+ export { Slider, type SliderProps, type SliderSingleProps, type SliderRangeProps } from './slider/Slider.js';
23
+ export { Search, type SearchProps } from './search/Search.js';
24
+ export { TextLink, type TextLinkProps } from './link/TextLink.js';
25
+ export { Pagination, type PaginationProps } from './pagination/Pagination.js';
26
+ export { Menu, type MenuProps, type MenuItem } from './menu/Menu.js';
27
+ export { Metric, type MetricProps, type MetricChange } from './metric/Metric.js';
28
+ export { Avatar, type AvatarProps } from './avatar/Avatar.js';
29
+ export { Rating, type RatingProps } from './rating/Rating.js';
30
+ export { List, type ListProps, type ListItem } from './list/List.js';
31
+ export { Accordion, type AccordionProps, type AccordionItem } from './accordion/Accordion.js';
32
+ export { Prose, type ProseProps } from './prose/Prose.js';
33
+ export { CodeBlock, type CodeBlockProps } from './code-block/CodeBlock.js';
34
+ export { Alert, type AlertProps, type AlertTone } from './alert/Alert.js';
35
+ export { Toast, type ToastProps } from './toast/Toast.js';
36
+ export { Progress, type ProgressProps } from './progress/Progress.js';
37
+ export { Tooltip, type TooltipProps } from './tooltip/Tooltip.js';
38
+ export { Popover, type PopoverProps } from './popover/Popover.js';
39
+ export { SiteHeader, type SiteHeaderProps, type SiteHeaderItem, } from './site-header/SiteHeader.js';
40
+ export { Card, type CardProps } from './card/Card.js';
41
+ export { Dialog, type DialogProps } from './dialog/Dialog.js';
42
+ export { Table, type TableProps, type TableColumn, type TableFilter, type TableBulkAction } from './table/Table.js';
43
+ export { FileUpload, type FileUploadProps, type FileRejection } from './workflow/FileUpload.js';
44
+ export { Form, type FormProps } from './workflow/Form.js';
45
+ export { Wizard, type WizardProps, type WizardStep } from './workflow/Wizard.js';
46
+ export { Drawer, type DrawerProps } from './workflow/Drawer.js';
47
+ export { ContentState, type ContentStateProps } from './workflow/ContentState.js';
48
+ export { Chatbot, type ChatbotProps, type ChatMessage } from './application-patterns/Chatbot.js';
49
+ export { SideNavigation, type SideNavigationProps, type SideNavigationGroup, type SideNavigationItem, } from './application-patterns/SideNavigation.js';
50
+ export type { DiyaLinkComponent, DiyaLinkProps } from './internal/link.js';
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ export { Button } from './button/Button.js';
2
+ export { PageHeader } from './page-header/PageHeader.js';
3
+ export { DiyaProvider, useDiyaAppearance } from './DiyaProvider.js';
4
+ export { Stack } from './layout/Stack.js';
5
+ export { Inline } from './layout/Inline.js';
6
+ export { defaultMessages } from './messages-defaults.js';
7
+ export { Breadcrumbs } from './breadcrumbs/Breadcrumbs.js';
8
+ export { Tabs } from './tabs/Tabs.js';
9
+ export { Tag } from './tag/Tag.js';
10
+ export { Badge } from './badge/Badge.js';
11
+ export { TextInput } from './text-input/TextInput.js';
12
+ export { TextArea } from './text-area/TextArea.js';
13
+ export { Select } from './select/Select.js';
14
+ export { DatePicker } from './date-picker/DatePicker.js';
15
+ export { Calendar } from './calendar/Calendar.js';
16
+ export { Combobox } from './combobox/Combobox.js';
17
+ export { Choice } from './choice/Choice.js';
18
+ export { Switch } from './switch/Switch.js';
19
+ export { Slider } from './slider/Slider.js';
20
+ export { Search } from './search/Search.js';
21
+ export { TextLink } from './link/TextLink.js';
22
+ export { Pagination } from './pagination/Pagination.js';
23
+ export { Menu } from './menu/Menu.js';
24
+ export { Metric } from './metric/Metric.js';
25
+ export { Avatar } from './avatar/Avatar.js';
26
+ export { Rating } from './rating/Rating.js';
27
+ export { List } from './list/List.js';
28
+ export { Accordion } from './accordion/Accordion.js';
29
+ export { Prose } from './prose/Prose.js';
30
+ export { CodeBlock } from './code-block/CodeBlock.js';
31
+ export { Alert } from './alert/Alert.js';
32
+ export { Toast } from './toast/Toast.js';
33
+ export { Progress } from './progress/Progress.js';
34
+ export { Tooltip } from './tooltip/Tooltip.js';
35
+ export { Popover } from './popover/Popover.js';
36
+ export { SiteHeader, } from './site-header/SiteHeader.js';
37
+ export { Card } from './card/Card.js';
38
+ export { Dialog } from './dialog/Dialog.js';
39
+ export { Table } from './table/Table.js';
40
+ export { FileUpload } from './workflow/FileUpload.js';
41
+ export { Form } from './workflow/Form.js';
42
+ export { Wizard } from './workflow/Wizard.js';
43
+ export { Drawer } from './workflow/Drawer.js';
44
+ export { ContentState } from './workflow/ContentState.js';
45
+ export { Chatbot } from './application-patterns/Chatbot.js';
46
+ export { SideNavigation, } from './application-patterns/SideNavigation.js';
@@ -0,0 +1,33 @@
1
+ /** DIYA's own accent when the provider sets no `brandColor`: a true neutral ink in Light, its pale twin in Dark. */
2
+ export declare const DIYA_DEFAULT_BRAND: {
3
+ readonly light: "#262626";
4
+ readonly dark: "#e8e8e8";
5
+ };
6
+ export type BrandTheme = 'light' | 'dark';
7
+ /** The accent tokens for one theme, as hex. */
8
+ export type DiyaBrandTokens = {
9
+ /** Fills: the solid Button, a selected pill Tab, an on Switch, chart series 1. */
10
+ accent: string;
11
+ /** Text and icons on the accent fill. */
12
+ accentText: string;
13
+ /** A quiet translucent tint, such as behind a brand-tone Tag. */
14
+ accentSoft: string;
15
+ /** Accent-colored text that reads on the page, the soft tint and raised surfaces. */
16
+ accentInk: string;
17
+ };
18
+ export declare const BRAND_GROUNDS: Record<BrandTheme, {
19
+ surface: string;
20
+ raised: string;
21
+ text: string;
22
+ }>;
23
+ /** `#rgb` or `#rrggbb`, with or without the hash, as lowercase `#rrggbb`; anything else is undefined. */
24
+ export declare function normalizeHex(value: string): string | undefined;
25
+ /** WCAG 2 contrast ratio between two opaque hex colors. */
26
+ export declare function contrast(a: string, b: string): number;
27
+ /** The four accent tokens for one theme, from a hex brand color; contrast is checked against DIYA's default grounds. */
28
+ export declare function brandTokens(color: string, theme: BrandTheme): DiyaBrandTokens;
29
+ /** A provider's `brandColor`, one color or one per theme, as the accent tokens for both themes. */
30
+ export declare function resolveBrand(brandColor: string | {
31
+ light: string;
32
+ dark: string;
33
+ } | undefined): Record<BrandTheme, DiyaBrandTokens>;