@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.
- package/CHANGELOG.md +317 -0
- package/NOTICE +29 -0
- package/README.md +596 -5
- package/dist/DiyaProvider.d.ts +79 -0
- package/dist/DiyaProvider.js +77 -0
- package/dist/Icon.d.ts +10 -0
- package/dist/Icon.js +27 -0
- package/dist/accordion/Accordion.d.ts +34 -0
- package/dist/accordion/Accordion.js +15 -0
- package/dist/alert/Alert.d.ts +49 -0
- package/dist/alert/Alert.js +11 -0
- package/dist/alert/messages.d.ts +9 -0
- package/dist/alert/messages.js +2 -0
- package/dist/api.json +7277 -0
- package/dist/api.schema.json +214 -0
- package/dist/application-patterns/Chatbot.d.ts +114 -0
- package/dist/application-patterns/Chatbot.js +110 -0
- package/dist/application-patterns/SideNavigation.d.ts +74 -0
- package/dist/application-patterns/SideNavigation.js +31 -0
- package/dist/application-patterns/chatbot-messages.d.ts +20 -0
- package/dist/application-patterns/chatbot-messages.js +2 -0
- package/dist/application-patterns/side-navigation-messages.d.ts +5 -0
- package/dist/application-patterns/side-navigation-messages.js +2 -0
- package/dist/avatar/Avatar.d.ts +32 -0
- package/dist/avatar/Avatar.js +19 -0
- package/dist/avatar/messages.d.ts +7 -0
- package/dist/avatar/messages.js +2 -0
- package/dist/badge/Badge.d.ts +42 -0
- package/dist/badge/Badge.js +16 -0
- package/dist/badge/badge-utils.d.ts +6 -0
- package/dist/badge/badge-utils.js +24 -0
- package/dist/badge/messages.d.ts +4 -0
- package/dist/badge/messages.js +2 -0
- package/dist/breadcrumbs/Breadcrumbs.d.ts +34 -0
- package/dist/breadcrumbs/Breadcrumbs.js +19 -0
- package/dist/breadcrumbs/messages.d.ts +5 -0
- package/dist/breadcrumbs/messages.js +2 -0
- package/dist/button/Button.d.ts +46 -0
- package/dist/button/Button.js +44 -0
- package/dist/calendar/Calendar.d.ts +55 -0
- package/dist/calendar/Calendar.js +61 -0
- package/dist/calendar/messages.d.ts +8 -0
- package/dist/calendar/messages.js +2 -0
- package/dist/calendar/month.d.ts +61 -0
- package/dist/calendar/month.js +134 -0
- package/dist/card/Card.d.ts +46 -0
- package/dist/card/Card.js +8 -0
- package/dist/choice/Choice.d.ts +72 -0
- package/dist/choice/Choice.js +68 -0
- package/dist/choice/messages.d.ts +4 -0
- package/dist/choice/messages.js +2 -0
- package/dist/code-block/CodeBlock.d.ts +20 -0
- package/dist/code-block/CodeBlock.js +49 -0
- package/dist/code-block/messages.d.ts +8 -0
- package/dist/code-block/messages.js +2 -0
- package/dist/combobox/Combobox.d.ts +60 -0
- package/dist/combobox/Combobox.js +160 -0
- package/dist/combobox/messages.d.ts +9 -0
- package/dist/combobox/messages.js +2 -0
- package/dist/combobox/useAnchoredPopover.d.ts +5 -0
- package/dist/combobox/useAnchoredPopover.js +100 -0
- package/dist/data-viz/DataViz.d.ts +140 -0
- package/dist/data-viz/DataViz.js +469 -0
- package/dist/data-viz/index.d.ts +2 -0
- package/dist/data-viz/index.js +1 -0
- package/dist/data-viz/messages.d.ts +11 -0
- package/dist/data-viz/messages.js +2 -0
- package/dist/date-picker/DatePicker.d.ts +57 -0
- package/dist/date-picker/DatePicker.js +146 -0
- package/dist/date-picker/messages.d.ts +13 -0
- package/dist/date-picker/messages.js +2 -0
- package/dist/dialog/Dialog.d.ts +84 -0
- package/dist/dialog/Dialog.js +107 -0
- package/dist/dialog/messages.d.ts +9 -0
- package/dist/dialog/messages.js +2 -0
- package/dist/fonts/DIYASans-Italic.woff2 +0 -0
- package/dist/fonts/DIYASans.woff2 +0 -0
- package/dist/fonts/OFL.txt +94 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +46 -0
- package/dist/internal/brand.d.ts +33 -0
- package/dist/internal/brand.js +57 -0
- package/dist/internal/cx.d.ts +2 -0
- package/dist/internal/cx.js +4 -0
- package/dist/internal/link.d.ts +14 -0
- package/dist/internal/link.js +7 -0
- package/dist/internal/slot.d.ts +15 -0
- package/dist/internal/slot.js +67 -0
- package/dist/layout/Inline.d.ts +4 -0
- package/dist/layout/Inline.js +7 -0
- package/dist/layout/Stack.d.ts +4 -0
- package/dist/layout/Stack.js +7 -0
- package/dist/layout/layout.d.ts +32 -0
- package/dist/layout/layout.js +12 -0
- package/dist/link/TextLink.d.ts +23 -0
- package/dist/link/TextLink.js +17 -0
- package/dist/list/List.d.ts +48 -0
- package/dist/list/List.js +17 -0
- package/dist/list/messages.d.ts +4 -0
- package/dist/list/messages.js +2 -0
- package/dist/menu/Menu.d.ts +49 -0
- package/dist/menu/Menu.js +54 -0
- package/dist/messages-defaults.d.ts +201 -0
- package/dist/messages-defaults.js +61 -0
- package/dist/messages.d.ts +12 -0
- package/dist/messages.js +1 -0
- package/dist/metric/Metric.d.ts +42 -0
- package/dist/metric/Metric.js +11 -0
- package/dist/metric/messages.d.ts +9 -0
- package/dist/metric/messages.js +2 -0
- package/dist/overlay/FloatingSurface.d.ts +29 -0
- package/dist/overlay/FloatingSurface.js +254 -0
- package/dist/page-header/PageHeader.d.ts +38 -0
- package/dist/page-header/PageHeader.js +10 -0
- package/dist/pagination/Pagination.d.ts +44 -0
- package/dist/pagination/Pagination.js +26 -0
- package/dist/pagination/messages.d.ts +11 -0
- package/dist/pagination/messages.js +2 -0
- package/dist/popover/Popover.d.ts +23 -0
- package/dist/popover/Popover.js +8 -0
- package/dist/progress/Progress.d.ts +33 -0
- package/dist/progress/Progress.js +14 -0
- package/dist/progress/messages.d.ts +4 -0
- package/dist/progress/messages.js +2 -0
- package/dist/prose/Prose.d.ts +14 -0
- package/dist/prose/Prose.js +7 -0
- package/dist/rating/Rating.d.ts +32 -0
- package/dist/rating/Rating.js +27 -0
- package/dist/rating/messages.d.ts +6 -0
- package/dist/rating/messages.js +2 -0
- package/dist/search/Search.d.ts +11 -0
- package/dist/search/Search.js +9 -0
- package/dist/select/Select.d.ts +65 -0
- package/dist/select/Select.js +19 -0
- package/dist/select/messages.d.ts +4 -0
- package/dist/select/messages.js +2 -0
- package/dist/site-header/SiteHeader.d.ts +88 -0
- package/dist/site-header/SiteHeader.js +211 -0
- package/dist/site-header/messages.d.ts +8 -0
- package/dist/site-header/messages.js +2 -0
- package/dist/slider/Slider.d.ts +54 -0
- package/dist/slider/Slider.js +89 -0
- package/dist/slider/messages.d.ts +5 -0
- package/dist/slider/messages.js +2 -0
- package/dist/styles.css +3379 -0
- package/dist/switch/Switch.d.ts +47 -0
- package/dist/switch/Switch.js +18 -0
- package/dist/table/Table.d.ts +99 -0
- package/dist/table/Table.js +158 -0
- package/dist/table/messages.d.ts +23 -0
- package/dist/table/messages.js +2 -0
- package/dist/tabs/Tabs.d.ts +49 -0
- package/dist/tabs/Tabs.js +26 -0
- package/dist/tag/Tag.d.ts +37 -0
- package/dist/tag/Tag.js +20 -0
- package/dist/tag/messages.d.ts +4 -0
- package/dist/tag/messages.js +2 -0
- package/dist/text-area/TextArea.d.ts +47 -0
- package/dist/text-area/TextArea.js +19 -0
- package/dist/text-input/TextInput.d.ts +53 -0
- package/dist/text-input/TextInput.js +35 -0
- package/dist/text-input/messages.d.ts +4 -0
- package/dist/text-input/messages.js +3 -0
- package/dist/text-input/native-field.d.ts +15 -0
- package/dist/text-input/native-field.js +56 -0
- package/dist/toast/Toast.d.ts +24 -0
- package/dist/toast/Toast.js +79 -0
- package/dist/toast/messages.d.ts +4 -0
- package/dist/toast/messages.js +2 -0
- package/dist/tooltip/Tooltip.d.ts +22 -0
- package/dist/tooltip/Tooltip.js +92 -0
- package/dist/workflow/ContentState.d.ts +44 -0
- package/dist/workflow/ContentState.js +11 -0
- package/dist/workflow/Drawer.d.ts +48 -0
- package/dist/workflow/Drawer.js +51 -0
- package/dist/workflow/FileUpload.d.ts +67 -0
- package/dist/workflow/FileUpload.js +47 -0
- package/dist/workflow/Form.d.ts +52 -0
- package/dist/workflow/Form.js +16 -0
- package/dist/workflow/Wizard.d.ts +76 -0
- package/dist/workflow/Wizard.js +31 -0
- package/dist/workflow/drawer-messages.d.ts +4 -0
- package/dist/workflow/drawer-messages.js +2 -0
- package/dist/workflow/file-upload-messages.d.ts +11 -0
- package/dist/workflow/file-upload-messages.js +2 -0
- package/dist/workflow/form-messages.d.ts +5 -0
- package/dist/workflow/form-messages.js +2 -0
- package/dist/workflow/wizard-messages.d.ts +9 -0
- package/dist/workflow/wizard-messages.js +2 -0
- package/package.json +82 -7
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, forwardRef, useContext, useMemo, useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { LinkComponentContext } from './internal/link.js';
|
|
5
|
+
import { cx } from './internal/cx.js';
|
|
6
|
+
import { resolveBrand } from './internal/brand.js';
|
|
7
|
+
/** DIYA Sans ships with the stylesheet; a metric-matched Arial covers the moment before it loads. */
|
|
8
|
+
export const DEFAULT_FONT_FAMILY = '"DIYA Sans", "DIYA Sans Fallback", Arial, sans-serif';
|
|
9
|
+
const DEFAULT_BRAND = resolveBrand(undefined);
|
|
10
|
+
const PortalContext = createContext(null);
|
|
11
|
+
const AppearanceContext = createContext({ theme: 'light', glass: false, fontFamily: DEFAULT_FONT_FAMILY, brand: DEFAULT_BRAND.light });
|
|
12
|
+
export function useDiyaPortal() { return useContext(PortalContext); }
|
|
13
|
+
/** The nearest provider's resolved theme, Glass, font and brand accent. */
|
|
14
|
+
export function useDiyaAppearance() { return useContext(AppearanceContext); }
|
|
15
|
+
const MessagesContext = createContext({ overrides: {} });
|
|
16
|
+
/** A nested provider adds to its parent's strings; a key set to undefined keeps the inherited one. */
|
|
17
|
+
function mergeMessages(parent, own) {
|
|
18
|
+
if (!own)
|
|
19
|
+
return parent;
|
|
20
|
+
const out = { ...parent };
|
|
21
|
+
for (const [component, strings] of Object.entries(own)) {
|
|
22
|
+
if (!strings)
|
|
23
|
+
continue;
|
|
24
|
+
const kept = Object.fromEntries(Object.entries(strings).filter(([, value]) => value !== undefined));
|
|
25
|
+
out[component] = { ...(out[component] ?? {}), ...kept };
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
/** A component's built-in strings, with any provider overrides applied. */
|
|
30
|
+
export function useDiyaMessages(component, defaults) {
|
|
31
|
+
const override = useContext(MessagesContext).overrides[component];
|
|
32
|
+
// Cast through object: a bundle without translatable components has an empty map.
|
|
33
|
+
return useMemo(() => (override ? { ...defaults, ...override } : defaults), [defaults, override]);
|
|
34
|
+
}
|
|
35
|
+
/** BCP 47 locale for dates and numbers. */
|
|
36
|
+
export function useDiyaLocale() { return useContext(MessagesContext).locale ?? 'en-US'; }
|
|
37
|
+
// theme="system" is pure CSS (prefers-color-scheme); this only tells JavaScript which one won.
|
|
38
|
+
const DARK_QUERY = '(prefers-color-scheme: dark)';
|
|
39
|
+
const media = () => (typeof window !== 'undefined' && typeof window.matchMedia === 'function' ? window.matchMedia(DARK_QUERY) : undefined);
|
|
40
|
+
function subscribeToScheme(onChange) {
|
|
41
|
+
const query = media();
|
|
42
|
+
query?.addEventListener?.('change', onChange);
|
|
43
|
+
return () => query?.removeEventListener?.('change', onChange);
|
|
44
|
+
}
|
|
45
|
+
const ignoreScheme = () => () => { };
|
|
46
|
+
const prefersDark = () => media()?.matches ?? false;
|
|
47
|
+
const serverPrefersDark = () => false;
|
|
48
|
+
/** Scoped appearance; no document mutation, cookies, network calls or global CSS. */
|
|
49
|
+
export const DiyaProvider = forwardRef(function DiyaProvider({ children, theme = 'system', surface = true, glass = false, brandColor, fontFamily = DEFAULT_FONT_FAMILY, messages, locale, linkComponent, className, style, ...rest }, ref) {
|
|
50
|
+
const [portal, setPortal] = useState(null);
|
|
51
|
+
const parent = useContext(MessagesContext);
|
|
52
|
+
const parentLink = useContext(LinkComponentContext);
|
|
53
|
+
const text = useMemo(() => ({ overrides: mergeMessages(parent.overrides, messages), locale: locale ?? parent.locale }), [parent, messages, locale]);
|
|
54
|
+
const dark = useSyncExternalStore(theme === 'system' ? subscribeToScheme : ignoreScheme, prefersDark, serverPrefersDark);
|
|
55
|
+
const resolved = theme === 'system' ? (dark ? 'dark' : 'light') : theme;
|
|
56
|
+
const brandKey = typeof brandColor === 'object' ? `${brandColor.light}|${brandColor.dark}` : brandColor;
|
|
57
|
+
const brand = useMemo(() => (brandColor === undefined ? DEFAULT_BRAND : resolveBrand(brandColor)), [brandKey]);
|
|
58
|
+
const appearance = useMemo(() => ({ theme: resolved, glass, fontFamily, brand: brand[resolved] }), [resolved, glass, fontFamily, brand]);
|
|
59
|
+
const tokens = {
|
|
60
|
+
'--diya-font': fontFamily,
|
|
61
|
+
...accentVariables(brand),
|
|
62
|
+
...style,
|
|
63
|
+
};
|
|
64
|
+
return _jsx("div", { ...rest, ref: ref, className: cx('diya-root', className), "data-theme": theme, "data-glass": String(glass), "data-surface": String(surface), style: tokens, children: _jsx(AppearanceContext.Provider, { value: appearance, children: _jsx(MessagesContext.Provider, { value: text, children: _jsxs(PortalContext.Provider, { value: portal, children: [_jsx(LinkComponentContext.Provider, { value: linkComponent ?? parentLink, children: children }), _jsx("div", { className: "diya-portal-root", ref: setPortal })] }) }) }) });
|
|
65
|
+
});
|
|
66
|
+
/** Both themes' accent tokens as private variables; styles.css picks the pair for the theme in effect. */
|
|
67
|
+
function accentVariables(brand) {
|
|
68
|
+
const out = {};
|
|
69
|
+
for (const theme of ['light', 'dark']) {
|
|
70
|
+
const { accent, accentText, accentSoft, accentInk } = brand[theme];
|
|
71
|
+
out[`--diya-internal-accent-${theme}`] = accent;
|
|
72
|
+
out[`--diya-internal-accent-text-${theme}`] = accentText;
|
|
73
|
+
out[`--diya-internal-accent-soft-${theme}`] = accentSoft;
|
|
74
|
+
out[`--diya-internal-accent-ink-${theme}`] = accentInk;
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
package/dist/Icon.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
/** A decorative line icon from a small built-in set; hidden from screen readers. */
|
|
3
|
+
export declare function Icon({ name, size, style, }: {
|
|
4
|
+
/** Icon name, such as 'search', 'close' or 'download'; unknown names draw 'grid'. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Width and height in pixels. Defaults to 18. */
|
|
7
|
+
size?: number;
|
|
8
|
+
/** Inline styles on the svg. */
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/Icon.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** A decorative line icon from a small built-in set; hidden from screen readers. */
|
|
3
|
+
export function Icon({ name, size = 18, style, }) {
|
|
4
|
+
const paths = {
|
|
5
|
+
paperclip: _jsx("path", { d: "m21 11-8 8a6 6 0 0 1-8-8l9-9a4 4 0 0 1 6 6l-9 9a2 2 0 0 1-3-3l8-8" }),
|
|
6
|
+
'chevron-down': _jsx("path", { d: "m6 9 6 6 6-6" }),
|
|
7
|
+
download: _jsx("path", { d: "M12 3v12m-4-4 4 4 4-4M4 16v5h16v-5" }),
|
|
8
|
+
search: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "10.5", cy: "10.5", r: "6.5" }), _jsx("path", { d: "m16 16 4 4" })] })),
|
|
9
|
+
grid: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "3", width: "7", height: "7", rx: "1.5" }), _jsx("rect", { x: "14", y: "3", width: "7", height: "7", rx: "1.5" }), _jsx("rect", { x: "3", y: "14", width: "7", height: "7", rx: "1.5" }), _jsx("rect", { x: "14", y: "14", width: "7", height: "7", rx: "1.5" })] })),
|
|
10
|
+
layers: (_jsx(_Fragment, { children: _jsx("path", { d: "m12 3 9 5-9 5-9-5 9-5Zm-9 9 9 5 9-5M3 16l9 5 9-5" }) })),
|
|
11
|
+
bookmark: _jsx("path", { d: "M6 4h12v17l-6-4-6 4V4Z" }),
|
|
12
|
+
arrow: _jsx("path", { d: "M4 12h16m-6-6 6 6-6 6" }),
|
|
13
|
+
close: _jsx("path", { d: "m6 6 12 12M6 18 18 6" }),
|
|
14
|
+
sun: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1 1m12 12 1 1M5 19l1-1M18 6l1-1" })] })),
|
|
15
|
+
moon: _jsx("path", { d: "M20 14A8 8 0 0 1 10 4a8 8 0 1 0 10 10Z" }),
|
|
16
|
+
system: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "4", width: "18", height: "12", rx: "2" }), _jsx("path", { d: "M8 21h8m-4-5v5" })] })),
|
|
17
|
+
filter: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M4 7h16M4 17h16" }), _jsx("circle", { cx: "9", cy: "7", r: "2" }), _jsx("circle", { cx: "15", cy: "17", r: "2" })] })),
|
|
18
|
+
plus: _jsx("path", { d: "M12 5v14M5 12h14" }),
|
|
19
|
+
check: _jsx("path", { d: "m5 12 4 4L19 6" }),
|
|
20
|
+
copy: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "8", y: "8", width: "12", height: "12", rx: "2.5" }), _jsx("path", { d: "M16 8V6.5A2.5 2.5 0 0 0 13.5 4h-7A2.5 2.5 0 0 0 4 6.5v7A2.5 2.5 0 0 0 6.5 16H8" })] })),
|
|
21
|
+
compass: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "9" }), _jsx("path", { d: "m16 8-3 5-5 3 3-5 5-3Z" })] })),
|
|
22
|
+
code: _jsx("path", { d: "m8 6-6 6 6 6m8-12 6 6-6 6m-5-14-2 16" }),
|
|
23
|
+
type: _jsx("path", { d: "M4 5h16M12 5v15M8 20h8" }),
|
|
24
|
+
book: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M12 6c-3-2-6-2-9-1v15c3-1 6-1 9 1 3-2 6-2 9-1V5c-3-1-6-1-9 1Z" }), _jsx("path", { d: "M12 6v15" })] })),
|
|
25
|
+
};
|
|
26
|
+
return (_jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", style: style, children: paths[name] ?? paths.grid }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export type AccordionItem = {
|
|
3
|
+
/** Unique key for the section. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Visible heading text on the button that opens and closes the section. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Content shown while the section is open. */
|
|
8
|
+
content: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export type AccordionProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
11
|
+
/** The sections, in order; all start closed. */
|
|
12
|
+
items: AccordionItem[];
|
|
13
|
+
/** Lets several sections stay open at once; by default opening one closes the others. */
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
/** Draws lines between sections. Defaults to true. */
|
|
16
|
+
divided?: boolean;
|
|
17
|
+
/** Disables every section's button. */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** Heading level of each section's button, h1 to h6. Defaults to 3. */
|
|
20
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
21
|
+
};
|
|
22
|
+
/** Stacked sections that open and close under their headings. */
|
|
23
|
+
export declare const Accordion: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
24
|
+
/** The sections, in order; all start closed. */
|
|
25
|
+
items: AccordionItem[];
|
|
26
|
+
/** Lets several sections stay open at once; by default opening one closes the others. */
|
|
27
|
+
multiple?: boolean;
|
|
28
|
+
/** Draws lines between sections. Defaults to true. */
|
|
29
|
+
divided?: boolean;
|
|
30
|
+
/** Disables every section's button. */
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** Heading level of each section's button, h1 to h6. Defaults to 3. */
|
|
33
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
34
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useId, useState } from 'react';
|
|
4
|
+
import { cx } from '../internal/cx.js';
|
|
5
|
+
/** Stacked sections that open and close under their headings. */
|
|
6
|
+
export const Accordion = forwardRef(function Accordion({ items, multiple = false, divided = true, disabled = false, headingLevel = 3, className, ...props }, ref) {
|
|
7
|
+
const id = useId();
|
|
8
|
+
const [expanded, setExpanded] = useState([]);
|
|
9
|
+
const visible = multiple ? expanded : expanded.slice(-1);
|
|
10
|
+
const Heading = `h${headingLevel}`;
|
|
11
|
+
return _jsx("div", { ...props, ref: ref, className: cx('diya-accordion', className), "data-divided": divided, children: items.map((item, index) => {
|
|
12
|
+
const open = visible.includes(item.id);
|
|
13
|
+
return _jsxs("section", { className: "diya-accordion-item", children: [_jsx(Heading, { className: "diya-accordion-heading", children: _jsxs("button", { type: "button", disabled: disabled, id: `${id}-trigger-${index}`, "aria-expanded": open, "aria-controls": `${id}-panel-${index}`, onClick: () => setExpanded(open ? visible.filter((key) => key !== item.id) : multiple ? [...visible, item.id] : [item.id]), children: [item.label, _jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: _jsx("path", { d: open ? 'M5 12l5-5 5 5' : 'M5 8l5 5 5-5' }) })] }) }), _jsx("div", { role: "region", id: `${id}-panel-${index}`, "aria-labelledby": `${id}-trigger-${index}`, hidden: !open, className: "diya-accordion-content", children: item.content })] }, item.id);
|
|
14
|
+
}) });
|
|
15
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import type { Tone } from '../badge/Badge.js';
|
|
3
|
+
import { alertMessages } from './messages.js';
|
|
4
|
+
declare module '../messages.js' {
|
|
5
|
+
interface DiyaMessages {
|
|
6
|
+
alert: typeof alertMessages;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Alerts carry a status, so every tone except neutral. */
|
|
10
|
+
export type AlertTone = Exclude<Tone, 'neutral'>;
|
|
11
|
+
export type AlertProps = Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'children'> & {
|
|
12
|
+
/** 'card' is a contained box; 'banner' is a full-width strip with its content in one row. Defaults to 'card'. */
|
|
13
|
+
layout?: 'card' | 'banner';
|
|
14
|
+
/** 'info' for information, 'success' done, 'warning' needs care, 'error' failed, 'brand' the provider's brand color; sets the icon and color and is announced before the message. Defaults to 'info'. */
|
|
15
|
+
tone?: AlertTone;
|
|
16
|
+
/** Visible bold first line. */
|
|
17
|
+
title?: string;
|
|
18
|
+
/** Visible message. */
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
/** One visible button after the message; `label` is its text. */
|
|
21
|
+
action?: {
|
|
22
|
+
label: string;
|
|
23
|
+
onClick: () => void;
|
|
24
|
+
};
|
|
25
|
+
/** When given, shows a close button that calls it. */
|
|
26
|
+
onDismiss?: () => void;
|
|
27
|
+
/** Announces immediately as `role="alert"`, interrupting a screen reader; otherwise it is a polite status. Use for errors that need action. */
|
|
28
|
+
urgent?: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** An inline message that reports a status, with an optional action and close button. */
|
|
31
|
+
export declare const Alert: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "children" | "title"> & {
|
|
32
|
+
/** 'card' is a contained box; 'banner' is a full-width strip with its content in one row. Defaults to 'card'. */
|
|
33
|
+
layout?: "card" | "banner";
|
|
34
|
+
/** 'info' for information, 'success' done, 'warning' needs care, 'error' failed, 'brand' the provider's brand color; sets the icon and color and is announced before the message. Defaults to 'info'. */
|
|
35
|
+
tone?: AlertTone;
|
|
36
|
+
/** Visible bold first line. */
|
|
37
|
+
title?: string;
|
|
38
|
+
/** Visible message. */
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
/** One visible button after the message; `label` is its text. */
|
|
41
|
+
action?: {
|
|
42
|
+
label: string;
|
|
43
|
+
onClick: () => void;
|
|
44
|
+
};
|
|
45
|
+
/** When given, shows a close button that calls it. */
|
|
46
|
+
onDismiss?: () => void;
|
|
47
|
+
/** Announces immediately as `role="alert"`, interrupting a screen reader; otherwise it is a polite status. Use for errors that need action. */
|
|
48
|
+
urgent?: boolean;
|
|
49
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { useDiyaMessages } from '../DiyaProvider.js';
|
|
5
|
+
import { cx } from '../internal/cx.js';
|
|
6
|
+
import { alertMessages } from './messages.js';
|
|
7
|
+
/** An inline message that reports a status, with an optional action and close button. */
|
|
8
|
+
export const Alert = forwardRef(function Alert({ layout = 'card', tone = 'info', title, children, action, onDismiss, urgent = false, className, ...props }, ref) {
|
|
9
|
+
const t = useDiyaMessages('alert', alertMessages);
|
|
10
|
+
return _jsxs("div", { ...props, ref: ref, className: cx('diya-alert', className), "data-tone": tone, "data-layout": layout, children: [_jsx("svg", { className: "diya-alert-icon", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: tone === 'warning' ? _jsxs(_Fragment, { children: [_jsx("path", { d: "m12 3 10 18H2Z" }), _jsx("path", { d: "M12 9v5m0 3v.1" })] }) : _jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "9" }), tone === 'success' ? _jsx("path", { d: "m8 12 3 3 5-6" }) : tone === 'error' ? _jsx("path", { d: "m9 9 6 6m0-6-6 6" }) : _jsx("path", { d: "M12 11v6m0-10v.1" })] }) }), _jsxs("div", { className: "diya-alert-copy", children: [_jsxs("div", { role: urgent ? 'alert' : 'status', "aria-atomic": "true", children: [_jsxs("span", { className: "diya-alert-sr", children: [t[tone], ": "] }), title && _jsx("p", { className: "diya-alert-title", children: title }), _jsx("div", { className: "diya-alert-description", children: children })] }), action && _jsx("button", { type: "button", className: "diya-alert-action", onClick: action.onClick, children: action.label })] }), onDismiss && _jsx("button", { type: "button", className: "diya-alert-dismiss", "aria-label": t.dismiss, onClick: onDismiss, children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", "aria-hidden": "true", children: _jsx("path", { d: "m6 6 12 12M18 6 6 18" }) }) })] });
|
|
11
|
+
});
|