@mszczygiel-projects/ui-core-react 0.0.0-stage → 1.0.0-alpha.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 (111) hide show
  1. package/README.md +48 -2
  2. package/dist/accordion/Accordion.d.ts +29 -0
  3. package/dist/accordion/Accordion.js +40 -0
  4. package/dist/accordion-item/AccordionItem.d.ts +25 -0
  5. package/dist/accordion-item/AccordionItem.js +100 -0
  6. package/dist/badge/Badge.d.ts +20 -0
  7. package/dist/badge/Badge.js +22 -0
  8. package/dist/breadcrumbs/Breadcrumbs.d.ts +21 -0
  9. package/dist/breadcrumbs/Breadcrumbs.js +43 -0
  10. package/dist/button/Button.d.ts +19 -0
  11. package/dist/button/Button.js +24 -0
  12. package/dist/calendar/Calendar.d.ts +34 -0
  13. package/dist/calendar/Calendar.js +182 -0
  14. package/dist/checkbox-field/CheckboxField.d.ts +25 -0
  15. package/dist/checkbox-field/CheckboxField.js +38 -0
  16. package/dist/chip/Chip.d.ts +33 -0
  17. package/dist/chip/Chip.js +71 -0
  18. package/dist/combobox/Combobox.d.ts +49 -0
  19. package/dist/combobox/Combobox.js +380 -0
  20. package/dist/date-field/DateField.d.ts +29 -0
  21. package/dist/date-field/DateField.js +194 -0
  22. package/dist/date-time-field/DateTimeField.d.ts +18 -0
  23. package/dist/date-time-field/DateTimeField.js +217 -0
  24. package/dist/dialog/Dialog.d.ts +36 -0
  25. package/dist/dialog/Dialog.js +93 -0
  26. package/dist/drawer/Drawer.d.ts +33 -0
  27. package/dist/drawer/Drawer.js +58 -0
  28. package/dist/file-input-field/FileInputField.d.ts +36 -0
  29. package/dist/file-input-field/FileInputField.js +207 -0
  30. package/dist/icon-button/IconButton.d.ts +15 -0
  31. package/dist/icon-button/IconButton.js +23 -0
  32. package/dist/index.d.ts +37 -0
  33. package/dist/index.js +37 -0
  34. package/dist/internal/action.d.ts +6 -0
  35. package/dist/internal/action.js +32 -0
  36. package/dist/internal/choice.d.ts +33 -0
  37. package/dist/internal/choice.js +30 -0
  38. package/dist/internal/class-names.d.ts +2 -0
  39. package/dist/internal/class-names.js +4 -0
  40. package/dist/internal/field.d.ts +53 -0
  41. package/dist/internal/field.js +63 -0
  42. package/dist/internal/listbox.d.ts +73 -0
  43. package/dist/internal/listbox.js +119 -0
  44. package/dist/internal/overlay.d.ts +60 -0
  45. package/dist/internal/overlay.js +260 -0
  46. package/dist/internal/renders-content.d.ts +3 -0
  47. package/dist/internal/renders-content.js +4 -0
  48. package/dist/internal/scroll-lock.d.ts +7 -0
  49. package/dist/internal/scroll-lock.js +30 -0
  50. package/dist/internal/set-ref.d.ts +6 -0
  51. package/dist/internal/set-ref.js +21 -0
  52. package/dist/internal/tabs-context.d.ts +14 -0
  53. package/dist/internal/tabs-context.js +3 -0
  54. package/dist/internal/use-browser.d.ts +10 -0
  55. package/dist/internal/use-browser.js +27 -0
  56. package/dist/internal/use-date-mask.d.ts +4 -0
  57. package/dist/internal/use-date-mask.js +62 -0
  58. package/dist/internal/use-form-state.d.ts +7 -0
  59. package/dist/internal/use-form-state.js +40 -0
  60. package/dist/internal/use-overlay.d.ts +22 -0
  61. package/dist/internal/use-overlay.js +64 -0
  62. package/dist/internal/use-parsed-field.d.ts +34 -0
  63. package/dist/internal/use-parsed-field.js +111 -0
  64. package/dist/internal/use-popup.d.ts +37 -0
  65. package/dist/internal/use-popup.js +175 -0
  66. package/dist/internal/use-ui-core-config.d.ts +6 -0
  67. package/dist/internal/use-ui-core-config.js +9 -0
  68. package/dist/link-button/LinkButton.d.ts +33 -0
  69. package/dist/link-button/LinkButton.js +40 -0
  70. package/dist/listbox/Listbox.d.ts +29 -0
  71. package/dist/listbox/Listbox.js +107 -0
  72. package/dist/loader/Loader.d.ts +14 -0
  73. package/dist/loader/Loader.js +21 -0
  74. package/dist/menu/Menu.d.ts +44 -0
  75. package/dist/menu/Menu.js +235 -0
  76. package/dist/notification/Notification.d.ts +20 -0
  77. package/dist/notification/Notification.js +56 -0
  78. package/dist/number-field/NumberField.d.ts +14 -0
  79. package/dist/number-field/NumberField.js +132 -0
  80. package/dist/pagination/Pagination.d.ts +34 -0
  81. package/dist/pagination/Pagination.js +144 -0
  82. package/dist/password-field/PasswordField.d.ts +37 -0
  83. package/dist/password-field/PasswordField.js +71 -0
  84. package/dist/popover/Popover.d.ts +36 -0
  85. package/dist/popover/Popover.js +129 -0
  86. package/dist/radio-field/RadioField.d.ts +14 -0
  87. package/dist/radio-field/RadioField.js +27 -0
  88. package/dist/radio-group/RadioGroup.d.ts +42 -0
  89. package/dist/radio-group/RadioGroup.js +44 -0
  90. package/dist/search-field/SearchField.d.ts +33 -0
  91. package/dist/search-field/SearchField.js +84 -0
  92. package/dist/select-field/SelectField.d.ts +39 -0
  93. package/dist/select-field/SelectField.js +236 -0
  94. package/dist/split-button/SplitButton.d.ts +33 -0
  95. package/dist/split-button/SplitButton.js +70 -0
  96. package/dist/styles.css +4724 -0
  97. package/dist/switch-field/SwitchField.d.ts +26 -0
  98. package/dist/switch-field/SwitchField.js +25 -0
  99. package/dist/tab/Tab.d.ts +15 -0
  100. package/dist/tab/Tab.js +46 -0
  101. package/dist/tabs/Tabs.d.ts +24 -0
  102. package/dist/tabs/Tabs.js +88 -0
  103. package/dist/text-field/TextField.d.ts +33 -0
  104. package/dist/text-field/TextField.js +25 -0
  105. package/dist/textarea-field/TextareaField.d.ts +28 -0
  106. package/dist/textarea-field/TextareaField.js +95 -0
  107. package/dist/time-field/TimeField.d.ts +13 -0
  108. package/dist/time-field/TimeField.js +50 -0
  109. package/dist/tooltip/Tooltip.d.ts +29 -0
  110. package/dist/tooltip/Tooltip.js +203 -0
  111. package/package.json +93 -3
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @mszczygiel-projects/ui-core-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The React components of UI Core Library, safe for server rendering. Import the components from the root and their styles once:
4
+
5
+ ```ts
6
+ import { Button } from '@mszczygiel-projects/ui-core-react';
7
+ import '@mszczygiel-projects/ui-core-react/styles.css';
8
+ ```
9
+
10
+ | Component | Export |
11
+ | -------------- | ---------------- |
12
+ | Accordion | `Accordion` |
13
+ | AccordionItem | `AccordionItem` |
14
+ | Badge | `Badge` |
15
+ | Breadcrumbs | `Breadcrumbs` |
16
+ | Button | `Button` |
17
+ | Calendar | `Calendar` |
18
+ | CheckboxField | `CheckboxField` |
19
+ | Chip | `Chip` |
20
+ | Combobox | `Combobox` |
21
+ | DateField | `DateField` |
22
+ | DateTimeField | `DateTimeField` |
23
+ | Dialog | `Dialog` |
24
+ | Drawer | `Drawer` |
25
+ | FileInputField | `FileInputField` |
26
+ | IconButton | `IconButton` |
27
+ | LinkButton | `LinkButton` |
28
+ | Listbox | `Listbox` |
29
+ | Loader | `Loader` |
30
+ | Menu | `Menu` |
31
+ | Notification | `Notification` |
32
+ | NumberField | `NumberField` |
33
+ | Pagination | `Pagination` |
34
+ | PasswordField | `PasswordField` |
35
+ | Popover | `Popover` |
36
+ | RadioField | `RadioField` |
37
+ | RadioGroup | `RadioGroup` |
38
+ | SearchField | `SearchField` |
39
+ | SelectField | `SelectField` |
40
+ | SplitButton | `SplitButton` |
41
+ | SwitchField | `SwitchField` |
42
+ | Tab | `Tab` |
43
+ | Tabs | `Tabs` |
44
+ | TextField | `TextField` |
45
+ | TextareaField | `TextareaField` |
46
+ | TimeField | `TimeField` |
47
+ | Tooltip | `Tooltip` |
48
+
49
+ The components read the tokens of `@mszczygiel-projects/ui-core-foundations`, which a page loads once. `react` and `react-dom` 19 are peer dependencies. The documentation site documents [the components](https://mszczygiel-projects.github.io/ui-core-library/?path=/docs/components-status--docs), one page each. [Getting started](https://mszczygiel-projects.github.io/ui-core-library/?path=/docs/guides-getting-started--docs) renders the first one, and [Configuration](https://mszczygiel-projects.github.io/ui-core-library/?path=/docs/guides-configuration--docs) translates the texts they render.
@@ -0,0 +1,29 @@
1
+ import type { AccordionProps as SharedAccordionProps } from '@mszczygiel-projects/ui-core-shared/accordion';
2
+ import { type ComponentPropsWithRef, type ReactNode } from 'react';
3
+ /** What a section of an Accordion lets its group do. */
4
+ export interface AccordionSectionHandle {
5
+ /** Closes the section because another one opened, with the event that opened it. */
6
+ readonly close: (originalEvent: Event) => void;
7
+ }
8
+ /** What a group gives its sections. */
9
+ export interface AccordionContextValue {
10
+ /** Keeps a section until it unmounts; returns the function that lets it go. */
11
+ readonly register: (id: string, section: AccordionSectionHandle) => () => void;
12
+ /** A section opened, so a group that keeps one open closes the others. */
13
+ readonly opened: (id: string, originalEvent: Event) => void;
14
+ }
15
+ /** The group of the sections inside it, or null outside a group. */
16
+ export declare const AccordionContext: import("react").Context<AccordionContextValue | null>;
17
+ /** The props of Accordion. Other attributes of a `div` and ref go to its root element. */
18
+ export interface AccordionProps extends SharedAccordionProps, Omit<ComponentPropsWithRef<'div'>, keyof SharedAccordionProps> {
19
+ /** The sections, AccordionItem elements. */
20
+ children?: ReactNode;
21
+ }
22
+ /**
23
+ * A stack of sections whose headings show and hide their content.
24
+ *
25
+ * Its children are AccordionItem elements. Without `multiple`, a section that the user opens
26
+ * closes the others, and each closed section reports it through `onOpenChange` with the reason
27
+ * `group`. A line separates the sections.
28
+ */
29
+ export declare function Accordion({ multiple, className, children, ...rest }: AccordionProps): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useEffect, useLayoutEffect, useMemo, useRef, } from 'react';
4
+ import { classNames } from "../internal/class-names.js";
5
+ const useBrowserLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
6
+ /** The group of the sections inside it, or null outside a group. */
7
+ export const AccordionContext = createContext(null);
8
+ /**
9
+ * A stack of sections whose headings show and hide their content.
10
+ *
11
+ * Its children are AccordionItem elements. Without `multiple`, a section that the user opens
12
+ * closes the others, and each closed section reports it through `onOpenChange` with the reason
13
+ * `group`. A line separates the sections.
14
+ */
15
+ export function Accordion({ multiple = false, className, children, ...rest }) {
16
+ const sections = useRef(new Map());
17
+ const multipleRef = useRef(multiple);
18
+ useBrowserLayoutEffect(() => {
19
+ multipleRef.current = multiple;
20
+ });
21
+ const context = useMemo(() => ({
22
+ register: (id, section) => {
23
+ sections.current.set(id, section);
24
+ return () => {
25
+ sections.current.delete(id);
26
+ };
27
+ },
28
+ opened: (id, originalEvent) => {
29
+ if (multipleRef.current) {
30
+ return;
31
+ }
32
+ for (const [other, section] of sections.current) {
33
+ if (other !== id) {
34
+ section.close(originalEvent);
35
+ }
36
+ }
37
+ },
38
+ }), []);
39
+ return (_jsx("div", { className: classNames('ui-accordion', 'ui-accordion__base', className), ...rest, children: _jsx(AccordionContext, { value: context, children: children }) }));
40
+ }
@@ -0,0 +1,25 @@
1
+ import { type AccordionItemOpenChangeDetails as SharedOpenChangeDetails, type AccordionItemProps as SharedAccordionItemProps } from '@mszczygiel-projects/ui-core-shared/accordion-item';
2
+ import { type ComponentPropsWithRef, type ReactNode } from 'react';
3
+ export type { AccordionHeadingLevel, AccordionItemOpenChangeReason, } from '@mszczygiel-projects/ui-core-shared/accordion-item';
4
+ /** The event that asked the section to open or close, before React wraps it. */
5
+ export type AccordionItemOpenChangeDetails = SharedOpenChangeDetails<Event>;
6
+ /** The props of AccordionItem. Other attributes of a `div` and ref go to its root element. */
7
+ export interface AccordionItemProps extends SharedAccordionItemProps, Omit<ComponentPropsWithRef<'div'>, keyof SharedAccordionItemProps | 'children'> {
8
+ /** The initial state of an uncontrolled section. */
9
+ defaultOpen?: boolean;
10
+ /** The content of the section, in the page whether it is open or closed. */
11
+ children?: ReactNode;
12
+ /** Called on each request to open or close, with the new state and what asked for it. */
13
+ onOpenChange?: (open: boolean, details: AccordionItemOpenChangeDetails) => void;
14
+ }
15
+ /**
16
+ * One section of an Accordion: a heading that shows and hides its content.
17
+ *
18
+ * The heading is an HTML heading of `headingLevel` that holds a button, which carries
19
+ * `aria-expanded` and controls the panel, a region named by the heading. A controlled section
20
+ * follows `open`, and `onOpenChange` reports each request. The content of a closed section stays
21
+ * in the page as `hidden="until-found"`, so find in page and a link to a text fragment open it.
22
+ * Arrow Down and Arrow Up move the focus between the headings of the Accordion, Home and End to
23
+ * the first and last.
24
+ */
25
+ export declare function AccordionItem({ label, open, defaultOpen, disabled, headingLevel, onOpenChange, className, children, ...rest }: AccordionItemProps): import("react").JSX.Element;
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { iconChevronDown } from '@mszczygiel-projects/ui-core-icons';
4
+ import { accordionHeadingLevel, } from '@mszczygiel-projects/ui-core-shared/accordion-item';
5
+ import { nextAccordionHeading } from '@mszczygiel-projects/ui-core-shared/accordion-navigation';
6
+ import { use, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
7
+ import { AccordionContext } from "../accordion/Accordion.js";
8
+ import { classNames } from "../internal/class-names.js";
9
+ const useBrowserLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
10
+ const TRIGGERS = ':scope > .ui-accordion-item > .ui-accordion-item__heading > .ui-accordion-item__trigger';
11
+ /**
12
+ * One section of an Accordion: a heading that shows and hides its content.
13
+ *
14
+ * The heading is an HTML heading of `headingLevel` that holds a button, which carries
15
+ * `aria-expanded` and controls the panel, a region named by the heading. A controlled section
16
+ * follows `open`, and `onOpenChange` reports each request. The content of a closed section stays
17
+ * in the page as `hidden="until-found"`, so find in page and a link to a text fragment open it.
18
+ * Arrow Down and Arrow Up move the focus between the headings of the Accordion, Home and End to
19
+ * the first and last.
20
+ */
21
+ export function AccordionItem({ label, open, defaultOpen = false, disabled = false, headingLevel = 3, onOpenChange, className, children, ...rest }) {
22
+ const group = use(AccordionContext);
23
+ const id = useId();
24
+ const triggerId = `${id}-trigger`;
25
+ const panelId = `${id}-panel`;
26
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
27
+ // The browser shows the content of a match before the page answers, so a controlled section that
28
+ // keeps `open` false still shows it, until it closes or `open` changes.
29
+ const [found, setFound] = useState(false);
30
+ const [followedOpen, setFollowedOpen] = useState(open);
31
+ if (open !== followedOpen) {
32
+ setFollowedOpen(open);
33
+ setFound(false);
34
+ }
35
+ const isOpen = found || (open ?? uncontrolledOpen);
36
+ const panelRef = useRef(null);
37
+ const openingRef = useRef(null);
38
+ const Heading = `h${String(accordionHeadingLevel(headingLevel))}`;
39
+ const request = (next, reason, originalEvent) => {
40
+ if (next === isOpen) {
41
+ return;
42
+ }
43
+ setUncontrolledOpen(next);
44
+ setFound(next && reason === 'find');
45
+ openingRef.current = next ? originalEvent : null;
46
+ onOpenChange?.(next, { reason, originalEvent });
47
+ };
48
+ const requestRef = useRef(request);
49
+ useBrowserLayoutEffect(() => {
50
+ requestRef.current = request;
51
+ });
52
+ // The others close once the section has opened, so that a controlled parent that keeps it closed
53
+ // keeps them open, as a canceled request does in the web component. The request waits for a
54
+ // parent that opens the section later, after an asynchronous answer.
55
+ useBrowserLayoutEffect(() => {
56
+ const opening = openingRef.current;
57
+ if (isOpen && opening !== null) {
58
+ openingRef.current = null;
59
+ group?.opened(id, opening);
60
+ }
61
+ });
62
+ useEffect(() => {
63
+ return group?.register(id, {
64
+ close: (originalEvent) => {
65
+ requestRef.current(false, 'group', originalEvent);
66
+ },
67
+ });
68
+ }, [group, id]);
69
+ // React renders `hidden` as a boolean, so the panel takes `until-found` once it is in the page.
70
+ // A browser without it hides the panel plainly, and find in page skips the content.
71
+ useBrowserLayoutEffect(() => {
72
+ const panel = panelRef.current;
73
+ if (panel === null || isOpen) {
74
+ return;
75
+ }
76
+ panel.setAttribute('hidden', 'until-found');
77
+ const onBeforeMatch = (event) => {
78
+ requestRef.current(true, 'find', event);
79
+ };
80
+ panel.addEventListener('beforematch', onBeforeMatch);
81
+ return () => {
82
+ panel.removeEventListener('beforematch', onBeforeMatch);
83
+ };
84
+ }, [isOpen]);
85
+ const onKeyDown = (event) => {
86
+ const root = event.currentTarget.closest('.ui-accordion-item')?.parentElement;
87
+ if (group === null || root === null || root === undefined) {
88
+ return;
89
+ }
90
+ const triggers = Array.from(root.querySelectorAll(TRIGGERS));
91
+ const next = nextAccordionHeading(event.key, triggers.indexOf(event.currentTarget), triggers.map((trigger) => !trigger.disabled));
92
+ if (next !== undefined) {
93
+ event.preventDefault();
94
+ triggers[next]?.focus();
95
+ }
96
+ };
97
+ return (_jsxs("div", { className: classNames('ui-accordion-item', 'ui-accordion-item__base', className, isOpen && 'ui-accordion-item--open', disabled && 'ui-accordion-item--disabled'), ...rest, children: [_jsx(Heading, { className: "ui-accordion-item__heading", children: _jsxs("button", { type: "button", id: triggerId, className: "ui-accordion-item__trigger", "aria-expanded": isOpen, "aria-controls": panelId, disabled: disabled, onClick: (event) => {
98
+ request(!isOpen, 'trigger', event.nativeEvent);
99
+ }, onKeyDown: onKeyDown, children: [_jsx("span", { className: "ui-accordion-item__label", children: label }), _jsx("span", { className: "ui-accordion-item__icon", "aria-hidden": "true", dangerouslySetInnerHTML: { __html: iconChevronDown } })] }) }), _jsx("div", { ref: panelRef, id: panelId, className: "ui-accordion-item__panel", role: "region", "aria-labelledby": triggerId, hidden: !isOpen, children: _jsx("div", { className: "ui-accordion-item__body", children: children }) })] }));
100
+ }
@@ -0,0 +1,20 @@
1
+ import { type BadgeProps as SharedBadgeProps, type BadgeShape, type BadgeSize, type BadgeTone, type BadgeVariant } from '@mszczygiel-projects/ui-core-shared/badge';
2
+ import type { ComponentPropsWithRef, ReactNode } from 'react';
3
+ export type { BadgeShape, BadgeSize, BadgeTone, BadgeVariant };
4
+ /** The props of Badge. Other attributes of a `span` go to its root element. */
5
+ export interface BadgeProps extends SharedBadgeProps, Omit<ComponentPropsWithRef<'span'>, keyof SharedBadgeProps> {
6
+ /**
7
+ * Decorative content before the text, such as an icon or a status dot, which the author styles.
8
+ * An icon takes the icon size of the badge.
9
+ */
10
+ leading?: ReactNode;
11
+ /** Decorative content after the text, like `leading`. */
12
+ trailing?: ReactNode;
13
+ }
14
+ /**
15
+ * Marks a status, a category or a count with a short label and any content before or after it.
16
+ *
17
+ * The badge is not interactive. Its text names it; a badge without text becomes an image named by
18
+ * `label`, or by an `aria-label` of the author.
19
+ */
20
+ export declare function Badge({ tone, variant, size, shape, label, leading, trailing, className, children, 'aria-label': ariaLabel, ...rest }: BadgeProps): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { badge, } from '@mszczygiel-projects/ui-core-shared/badge';
3
+ import { oneOf } from '@mszczygiel-projects/ui-core-shared/one-of';
4
+ import { classNames } from "../internal/class-names.js";
5
+ import { rendersContent } from "../internal/renders-content.js";
6
+ const { options } = badge;
7
+ /**
8
+ * Marks a status, a category or a count with a short label and any content before or after it.
9
+ *
10
+ * The badge is not interactive. Its text names it; a badge without text becomes an image named by
11
+ * `label`, or by an `aria-label` of the author.
12
+ */
13
+ export function Badge({ tone = 'neutral', variant = 'solid', size = 'medium', shape = 'rounded', label, leading, trailing, className, children, 'aria-label': ariaLabel, ...rest }) {
14
+ const hasLeading = rendersContent(leading);
15
+ const hasTrailing = rendersContent(trailing);
16
+ const iconOnly = (hasLeading || hasTrailing) && !rendersContent(children);
17
+ const name = ariaLabel ?? label;
18
+ const named = iconOnly && name !== undefined && name !== '';
19
+ return (_jsxs("span", { ...rest, className: classNames('ui-badge', 'ui-badge__base', `ui-badge--${oneOf(tone, options.tone.options, options.tone.default)}`, `ui-badge--${oneOf(variant, options.variant.options, options.variant.default)}`, `ui-badge--${oneOf(size, options.size.options, options.size.default)}`, `ui-badge--${oneOf(shape, options.shape.options, options.shape.default)}`, iconOnly && 'ui-badge--icon-only', className),
20
+ // An explicit role of the author, such as status, stays; the image role is the fallback.
21
+ role: rest.role ?? (named ? 'img' : undefined), "aria-label": named ? name : iconOnly ? undefined : ariaLabel, children: [hasLeading && (_jsx("span", { className: "ui-badge__leading", "aria-hidden": "true", children: leading })), !iconOnly && _jsx("span", { className: "ui-badge__label", children: children }), hasTrailing && (_jsx("span", { className: "ui-badge__trailing", "aria-hidden": "true", children: trailing }))] }));
22
+ }
@@ -0,0 +1,21 @@
1
+ import { type BreadcrumbsItem, type BreadcrumbsNavigateDetails, type BreadcrumbsProps as SharedBreadcrumbsProps, type BreadcrumbsSeparator, type BreadcrumbsSize } from '@mszczygiel-projects/ui-core-shared/breadcrumbs';
2
+ import type { ComponentPropsWithRef, ReactNode } from 'react';
3
+ export type { BreadcrumbsItem, BreadcrumbsSeparator, BreadcrumbsSize };
4
+ /** The props of Breadcrumbs. Other attributes of a `nav`, the ref among them, go to its root. */
5
+ export interface BreadcrumbsProps extends SharedBreadcrumbsProps<ReactNode>, Omit<ComponentPropsWithRef<'nav'>, keyof SharedBreadcrumbsProps> {
6
+ /**
7
+ * Called when a user presses the link of an item. Call `preventDefault()` on the original
8
+ * event to keep the browser from following the link, as a page with client-side routing does.
9
+ */
10
+ onNavigate?: (details: BreadcrumbsNavigateDetails<MouseEvent, ReactNode>) => void;
11
+ }
12
+ /**
13
+ * A trail of links from the top of a site down to the current page.
14
+ *
15
+ * A navigation landmark holds an ordered list of the items. The last item is the current page:
16
+ * text with `aria-current="page"`, never a link. An item with `href` is a link, and one without
17
+ * is text. In a container narrower than `breakpoint/sm` the items before the last two hide behind
18
+ * an ellipsis; they stay in the accessibility tree. The separators are decorative and follow the
19
+ * direction of the text. An `aria-label` names the navigation instead of the label.
20
+ */
21
+ export declare function Breadcrumbs({ items, label, size, separator, onNavigate, className, 'aria-label': ariaLabel, ...rest }: BreadcrumbsProps): import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { iconChevronRight } from '@mszczygiel-projects/ui-core-icons';
4
+ import { breadcrumbs, } from '@mszczygiel-projects/ui-core-shared/breadcrumbs';
5
+ import { oneOf } from '@mszczygiel-projects/ui-core-shared/one-of';
6
+ import { classNames } from "../internal/class-names.js";
7
+ import { useUiCoreConfig } from "../internal/use-ui-core-config.js";
8
+ const { options } = breadcrumbs;
9
+ /**
10
+ * A trail of links from the top of a site down to the current page.
11
+ *
12
+ * A navigation landmark holds an ordered list of the items. The last item is the current page:
13
+ * text with `aria-current="page"`, never a link. An item with `href` is a link, and one without
14
+ * is text. In a container narrower than `breakpoint/sm` the items before the last two hide behind
15
+ * an ellipsis; they stay in the accessibility tree. The separators are decorative and follow the
16
+ * direction of the text. An `aria-label` names the navigation instead of the label.
17
+ */
18
+ export function Breadcrumbs({ items = [], label, size = 'medium', separator = 'chevron', onNavigate, className, 'aria-label': ariaLabel, ...rest }) {
19
+ const { labels } = useUiCoreConfig();
20
+ const sizeClass = oneOf(size, options.size.options, options.size.default);
21
+ const separatorClass = oneOf(separator, options.separator.options, options.separator.default);
22
+ // The items before the last two hide in a narrow container, so a trail of two never does.
23
+ const hidden = Math.max(items.length - 2, 0);
24
+ const mark = (_jsx("span", { className: "ui-breadcrumbs__separator", "aria-hidden": "true", dangerouslySetInnerHTML: separatorClass === 'chevron' ? { __html: iconChevronRight } : undefined }));
25
+ return (_jsx("nav", { className: classNames('ui-breadcrumbs', 'ui-breadcrumbs__base', `ui-breadcrumbs--${sizeClass}`, `ui-breadcrumbs--${separatorClass}`, className), "aria-label": ariaLabel ?? label ?? labels.breadcrumbs.label, ...rest, children: _jsxs("ol", { className: "ui-breadcrumbs__list", children: [hidden > 0 && (_jsxs("li", { className: "ui-breadcrumbs__item ui-breadcrumbs__item--ellipsis", "aria-hidden": "true", children: [_jsx("span", { className: "ui-breadcrumbs__ellipsis" }), mark] })), items.map((item, index) => {
26
+ const last = index === items.length - 1;
27
+ const hasIcon = item.icon !== undefined && item.icon !== null && item.icon !== false;
28
+ const content = (_jsxs(_Fragment, { children: [hasIcon && (_jsx("span", { className: "ui-breadcrumbs__item-icon", "aria-hidden": "true", children: item.icon })), _jsx("span", { className: classNames('ui-breadcrumbs__item-label', hasIcon && item.iconOnly === true && 'ui-breadcrumbs__item-label--hidden'), children: item.label })] }));
29
+ let node;
30
+ if (last) {
31
+ node = (_jsx("span", { className: "ui-breadcrumbs__current", "aria-current": "page", children: content }));
32
+ }
33
+ else if (typeof item.href !== 'string' || item.href === '') {
34
+ node = _jsx("span", { className: "ui-breadcrumbs__text", children: content });
35
+ }
36
+ else {
37
+ node = (_jsx("a", { className: "ui-breadcrumbs__link", href: item.href, onClick: (event) => {
38
+ onNavigate?.({ item, index, originalEvent: event.nativeEvent });
39
+ }, children: content }));
40
+ }
41
+ return (_jsxs("li", { className: classNames('ui-breadcrumbs__item', index < hidden && 'ui-breadcrumbs__item--collapsible'), children: [node, !last && mark] }, index));
42
+ })] }) }));
43
+ }
@@ -0,0 +1,19 @@
1
+ import { type ButtonProps as SharedButtonProps, type ButtonShape, type ButtonSize, type ButtonType, type ButtonVariant } from '@mszczygiel-projects/ui-core-shared/button';
2
+ import { type ComponentPropsWithRef, type ReactNode } from 'react';
3
+ export type { ButtonShape, ButtonSize, ButtonType, ButtonVariant };
4
+ /** The props of Button. Remaining attributes and ref reach its native button. */
5
+ export interface ButtonProps extends SharedButtonProps, Omit<ComponentPropsWithRef<'button'>, keyof SharedButtonProps> {
6
+ /** The visible action name. Supply text or non-interactive content. */
7
+ children?: ReactNode;
8
+ /** A decorative icon before the action name, in reading order. */
9
+ leadingIcon?: ReactNode;
10
+ /** A decorative icon after the action name, in reading order. */
11
+ trailingIcon?: ReactNode;
12
+ }
13
+ /**
14
+ * Triggers an action, with optional icons and a loading state.
15
+ *
16
+ * It uses native click and form behaviour. Loading retains the native button and its accessible
17
+ * name, adding a description from the configuration while blocking activation.
18
+ */
19
+ export declare function Button({ variant, size, shape, disabled, loading, type, name, value, label, loadingLabel, children, leadingIcon, trailingIcon, className, ref, 'aria-describedby': describedBy, ...rest }: ButtonProps): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { button, } from '@mszczygiel-projects/ui-core-shared/button';
4
+ import { oneOf } from '@mszczygiel-projects/ui-core-shared/one-of';
5
+ import { useId } from 'react';
6
+ import { useActionRef } from "../internal/action.js";
7
+ import { classNames } from "../internal/class-names.js";
8
+ import { rendersContent } from "../internal/renders-content.js";
9
+ import { useUiCoreConfig } from "../internal/use-ui-core-config.js";
10
+ import { Loader } from "../loader/Loader.js";
11
+ const { options } = button;
12
+ /**
13
+ * Triggers an action, with optional icons and a loading state.
14
+ *
15
+ * It uses native click and form behaviour. Loading retains the native button and its accessible
16
+ * name, adding a description from the configuration while blocking activation.
17
+ */
18
+ export function Button({ variant = 'primary', size = 'medium', shape = 'square', disabled = false, loading = false, type = 'button', name, value, label, loadingLabel, children, leadingIcon, trailingIcon, className, ref, 'aria-describedby': describedBy, ...rest }) {
19
+ const { labels } = useUiCoreConfig();
20
+ const descriptionId = useId();
21
+ const buttonRef = useActionRef(ref);
22
+ const buttonSize = oneOf(size, options.size.options, options.size.default);
23
+ return (_jsxs("button", { ref: buttonRef, type: oneOf(type, options.type.options, options.type.default), name: name, value: value, disabled: disabled, "aria-label": label, "aria-busy": loading || undefined, "aria-disabled": loading || undefined, className: classNames('ui-button', 'ui-button__base', 'ui-action', `ui-action--${oneOf(variant, options.variant.options, options.variant.default)}`, `ui-action--${buttonSize}`, `ui-action--${oneOf(shape, options.shape.options, options.shape.default)}`, loading && 'ui-action--loading', className), ...rest, "aria-describedby": [describedBy, loading ? descriptionId : undefined].filter(Boolean).join(' ') || undefined, children: [_jsxs("span", { className: "ui-button__wrapper", children: [_jsxs("span", { className: "ui-button__content", children: [rendersContent(leadingIcon) && (_jsx("span", { className: "ui-button__leading-icon", "aria-hidden": "true", children: leadingIcon })), _jsx("span", { className: "ui-button__label", children: children }), rendersContent(trailingIcon) && (_jsx("span", { className: "ui-button__trailing-icon", "aria-hidden": "true", children: trailingIcon }))] }), loading && (_jsx("span", { className: "ui-button__loader", "aria-hidden": "true", children: _jsx(Loader, { size: buttonSize === 'large' ? 'medium' : 'small' }) }))] }), loading && (_jsx("span", { id: descriptionId, hidden: true, children: loadingLabel ?? labels.button.loading }))] }));
24
+ }
@@ -0,0 +1,34 @@
1
+ import type { CalendarChangeDetails as SharedDetails, CalendarProps as SharedCalendarProps } from '@mszczygiel-projects/ui-core-shared/calendar';
2
+ import { type ComponentPropsWithRef } from 'react';
3
+ /** What accompanies a new value or month: the native event that caused it. */
4
+ export type CalendarChangeDetails = SharedDetails<Event>;
5
+ /** The props of Calendar. Other attributes of a `div`, the ref among them, go to its root. */
6
+ export interface CalendarProps extends SharedCalendarProps, Omit<ComponentPropsWithRef<'div'>, keyof SharedCalendarProps | 'defaultValue' | 'onChange'> {
7
+ /**
8
+ * The first value of an uncontrolled calendar.
9
+ * @default ''
10
+ */
11
+ defaultValue?: string;
12
+ /** The first month of an uncontrolled calendar, `YYYY-MM`. */
13
+ defaultMonth?: string;
14
+ /** Called with the new value when a user picks a date, or the last day of a range. */
15
+ onValueChange?: (value: string, details: CalendarChangeDetails) => void;
16
+ /** Called with the new month, `YYYY-MM`, when a user moves the day grid to it. */
17
+ onMonthChange?: (month: string, details: CalendarChangeDetails) => void;
18
+ }
19
+ /**
20
+ * A month of days, with a grid of months and of years behind its heading, to pick a date or a range.
21
+ *
22
+ * The days form a WAI-ARIA grid labelled by the heading, with one cell in the order of the Tab
23
+ * key. The arrow keys move by a day and a week in the direction of the text, Home and End to the
24
+ * edges of the week, and Page Up and Page Down by a month, or a year with Shift. Enter, Space or a
25
+ * press picks a day. The heading button opens a grid of the months of the year and then a page of
26
+ * 24 years, and Escape goes back one grid. With `range` a user picks the first and then the last
27
+ * day, and the value is the ISO interval `start/end`. A disabled day stays in the order of the
28
+ * keys but cannot be picked, and a month or year that `min` and `max` rule out entirely is
29
+ * disabled too. The value is controlled with `value` or uncontrolled with `defaultValue`, and the
30
+ * month with `month` or `defaultMonth`. Without `today`, a server and the first render in the
31
+ * browser mark no day as today and, without a value or month, show no grid; the browser's clock
32
+ * applies right after hydration.
33
+ */
34
+ export declare function Calendar({ value, defaultValue, range, month, defaultMonth, min, max, disabledDates, locale, firstDayOfWeek, today, previousMonthLabel, nextMonthLabel, previousYearLabel, nextYearLabel, previousYearsLabel, nextYearsLabel, getChooseMonthLabel, getChooseYearLabel, onValueChange, onMonthChange, className, ...rest }: CalendarProps): import("react").JSX.Element;
@@ -0,0 +1,182 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { iconChevronLeft, iconChevronRight } from '@mszczygiel-projects/ui-core-icons';
4
+ import { calendarModel, firstDayOfWeek as localeWeekStart, focusInMonth, initialFocus, isIsoWeekday, monthOf, nextFocusedDate, parseIsoMonth, pickCell, stepDate, zoomIn, zoomOut, } from '@mszczygiel-projects/ui-core-shared/calendar-grid';
5
+ import { parseIsoDate } from '@mszczygiel-projects/ui-core-shared/date';
6
+ import { resolveLocale } from '@mszczygiel-projects/ui-core-shared/locale';
7
+ import { useId, useLayoutEffect, useRef, useState, } from 'react';
8
+ import { IconButton } from "../icon-button/IconButton.js";
9
+ import { classNames } from "../internal/class-names.js";
10
+ import { useBrowserLanguage, useBrowserToday } from "../internal/use-browser.js";
11
+ import { useUiCoreConfig } from "../internal/use-ui-core-config.js";
12
+ /**
13
+ * A month of days, with a grid of months and of years behind its heading, to pick a date or a range.
14
+ *
15
+ * The days form a WAI-ARIA grid labelled by the heading, with one cell in the order of the Tab
16
+ * key. The arrow keys move by a day and a week in the direction of the text, Home and End to the
17
+ * edges of the week, and Page Up and Page Down by a month, or a year with Shift. Enter, Space or a
18
+ * press picks a day. The heading button opens a grid of the months of the year and then a page of
19
+ * 24 years, and Escape goes back one grid. With `range` a user picks the first and then the last
20
+ * day, and the value is the ISO interval `start/end`. A disabled day stays in the order of the
21
+ * keys but cannot be picked, and a month or year that `min` and `max` rule out entirely is
22
+ * disabled too. The value is controlled with `value` or uncontrolled with `defaultValue`, and the
23
+ * month with `month` or `defaultMonth`. Without `today`, a server and the first render in the
24
+ * browser mark no day as today and, without a value or month, show no grid; the browser's clock
25
+ * applies right after hydration.
26
+ */
27
+ export function Calendar({ value, defaultValue = '', range = false, month, defaultMonth, min, max, disabledDates, locale, firstDayOfWeek, today, previousMonthLabel, nextMonthLabel, previousYearLabel, nextYearLabel, previousYearsLabel, nextYearsLabel, getChooseMonthLabel, getChooseYearLabel, onValueChange, onMonthChange, className, ...rest }) {
28
+ const config = useUiCoreConfig();
29
+ const labels = config.labels.calendar;
30
+ const browserLanguage = useBrowserLanguage();
31
+ const browserToday = useBrowserToday();
32
+ const headingId = useId();
33
+ const gridRef = useRef(null);
34
+ const focusCellRef = useRef(false);
35
+ const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
36
+ const [uncontrolledMonth, setUncontrolledMonth] = useState(defaultMonth);
37
+ const [stored, setStored] = useState();
38
+ // The value the calendar last saw, and the one it last reported, so that only a value that the
39
+ // parent sets, and not the echo of a pick, shows its month again.
40
+ const [seenValue, setSeenValue] = useState(value);
41
+ const [reported, setReported] = useState();
42
+ let base = stored;
43
+ let ownMonth = uncontrolledMonth;
44
+ if (value !== seenValue) {
45
+ setSeenValue(value);
46
+ if (value !== reported) {
47
+ // A value that the parent sets shows its month, and ends a range a user had started.
48
+ base = undefined;
49
+ ownMonth = undefined;
50
+ setStored(undefined);
51
+ setUncontrolledMonth(undefined);
52
+ }
53
+ }
54
+ const currentValue = value ?? uncontrolledValue;
55
+ const currentMonth = month ?? ownMonth;
56
+ const shownMonth = currentMonth !== undefined && parseIsoMonth(currentMonth) !== null ? currentMonth : undefined;
57
+ const todayDate = today !== undefined && parseIsoDate(today) !== null ? today : browserToday;
58
+ const displayLocale = resolveLocale(locale, config.locale, browserLanguage);
59
+ const weekStart = isIsoWeekday(firstDayOfWeek) ? firstDayOfWeek : localeWeekStart(displayLocale);
60
+ const initial = initialFocus(currentValue, range, shownMonth, todayDate);
61
+ // The month the day grid shows, with which a move compares its own.
62
+ const daysMonth = shownMonth ?? (initial === undefined ? undefined : monthOf(initial));
63
+ const state = base === undefined
64
+ ? initial === undefined
65
+ ? undefined
66
+ : { view: 'days', focused: initial }
67
+ : shownMonth !== undefined && base.view === 'days'
68
+ ? { ...base, focused: focusInMonth(base.focused, shownMonth) }
69
+ : base;
70
+ useLayoutEffect(() => {
71
+ if (focusCellRef.current) {
72
+ focusCellRef.current = false;
73
+ gridRef.current?.querySelector('[tabindex="0"]')?.focus();
74
+ }
75
+ });
76
+ /** Moves to a state, and reports a new month once the day grid shows it. */
77
+ function moveTo(next, event) {
78
+ setStored(next);
79
+ if (next.view !== 'days') {
80
+ return;
81
+ }
82
+ const nextMonth = monthOf(next.focused);
83
+ if (nextMonth !== daysMonth) {
84
+ setUncontrolledMonth(nextMonth);
85
+ onMonthChange?.(nextMonth, { originalEvent: event });
86
+ }
87
+ }
88
+ function pick(from, cell, event) {
89
+ const result = pickCell(from, cell, range);
90
+ if (result === undefined) {
91
+ return;
92
+ }
93
+ focusCellRef.current = result.state.view !== from.view || cell.date !== from.focused;
94
+ if (result.value !== undefined) {
95
+ setReported(result.value);
96
+ setUncontrolledValue(result.value);
97
+ onValueChange?.(result.value, { originalEvent: event });
98
+ }
99
+ moveTo(result.state, event);
100
+ }
101
+ function handleKey(from, cells, event) {
102
+ const target = event.target;
103
+ if (!(target instanceof HTMLElement) || target.dataset['date'] === undefined) {
104
+ return;
105
+ }
106
+ if (event.key === 'Enter' || event.key === ' ') {
107
+ event.preventDefault();
108
+ const cell = cells.find((candidate) => candidate.focusable);
109
+ if (cell !== undefined) {
110
+ pick(from, cell, event.nativeEvent);
111
+ }
112
+ return;
113
+ }
114
+ if (event.key === 'Escape') {
115
+ const view = zoomIn(from.view);
116
+ if (view !== undefined) {
117
+ // Escape goes back one grid before it closes anything around the calendar.
118
+ event.preventDefault();
119
+ event.stopPropagation();
120
+ focusCellRef.current = true;
121
+ moveTo({ ...from, view }, event.nativeEvent);
122
+ }
123
+ return;
124
+ }
125
+ const focused = nextFocusedDate(event.key, from.focused, {
126
+ view: from.view,
127
+ direction: getComputedStyle(target).direction === 'rtl' ? 'rtl' : 'ltr',
128
+ firstDayOfWeek: weekStart,
129
+ shiftKey: event.shiftKey,
130
+ });
131
+ if (focused === undefined) {
132
+ return;
133
+ }
134
+ event.preventDefault();
135
+ focusCellRef.current = true;
136
+ moveTo({ ...from, focused }, event.nativeEvent);
137
+ }
138
+ function stepLabel(label) {
139
+ const own = {
140
+ previousMonth: previousMonthLabel,
141
+ nextMonth: nextMonthLabel,
142
+ previousYear: previousYearLabel,
143
+ nextYear: nextYearLabel,
144
+ previousYears: previousYearsLabel,
145
+ nextYears: nextYearsLabel,
146
+ };
147
+ return own[label] ?? labels[label];
148
+ }
149
+ if (state === undefined) {
150
+ return _jsx("div", { className: classNames('ui-calendar', className), ...rest });
151
+ }
152
+ const model = calendarModel(state, {
153
+ value: currentValue,
154
+ range,
155
+ anchor: state.anchor,
156
+ constraints: { min, max, disabledDates },
157
+ locale: displayLocale,
158
+ firstDayOfWeek: weekStart,
159
+ today: todayDate,
160
+ });
161
+ const cells = model.rows.flat();
162
+ const headingText = (_jsx("span", { id: headingId, className: "ui-calendar__heading-text", "aria-live": "polite", children: model.heading }));
163
+ const renderStep = (step, button) => (_jsx(IconButton, { className: `ui-calendar__${step}`, variant: "ghost", size: "small", label: stepLabel(button.label), disabled: button.disabled, icon: _jsx("span", { className: "ui-calendar__chevron", dangerouslySetInnerHTML: {
164
+ __html: step === 'previous' ? iconChevronLeft : iconChevronRight,
165
+ } }), onClick: (event) => {
166
+ const target = stepDate(state.view, state.focused, step === 'previous' ? -1 : 1);
167
+ if (target !== null) {
168
+ moveTo({ ...state, focused: target }, event.nativeEvent);
169
+ }
170
+ } }));
171
+ const { zoom } = model;
172
+ return (_jsxs("div", { className: classNames('ui-calendar', className), ...rest, children: [_jsxs("div", { className: "ui-calendar__header", children: [renderStep('previous', model.previous), zoom === null ? (_jsx("span", { className: "ui-calendar__heading", children: headingText })) : (_jsx("button", { type: "button", className: "ui-calendar__heading ui-calendar__heading--zoom", "aria-label": zoom.label === 'chooseMonth'
173
+ ? (getChooseMonthLabel ?? labels.chooseMonth)(zoom.text)
174
+ : (getChooseYearLabel ?? labels.chooseYear)(zoom.text), onClick: () => {
175
+ focusCellRef.current = true;
176
+ setStored({ ...state, view: zoomOut(state.view) });
177
+ }, children: headingText })), renderStep('next', model.next)] }), _jsxs("table", { ref: gridRef, className: `ui-calendar__grid ui-calendar__grid--${model.view}`, role: "grid", "aria-labelledby": headingId, onKeyDown: (event) => {
178
+ handleKey(state, cells, event);
179
+ }, children: [model.weekdays.length > 0 && (_jsx("thead", { children: _jsx("tr", { children: model.weekdays.map((weekday) => (_jsx("th", { className: "ui-calendar__weekday", scope: "col", abbr: weekday.long, children: weekday.short }, weekday.long))) }) })), _jsx("tbody", { children: model.rows.map((row) => (_jsx("tr", { children: row.map((cell, index) => cell.date === '' ? (_jsx("td", { className: "ui-calendar__cell ui-calendar__cell--empty", role: "gridcell" }, `empty-${String(index)}`)) : (_jsx("td", { className: classNames('ui-calendar__cell', `ui-calendar__cell--${cell.selection}`, cell.current && 'ui-calendar__cell--current', cell.disabled && 'ui-calendar__cell--disabled', cell.outside && 'ui-calendar__cell--outside'), role: "gridcell", tabIndex: cell.focusable ? 0 : -1, "aria-label": cell.name, "aria-selected": cell.selection !== 'none', "aria-disabled": cell.disabled ? true : undefined, "aria-current": cell.current ? (state.view === 'days' ? 'date' : true) : undefined, "data-date": cell.date, onClick: (event) => {
180
+ pick(state, cell, event.nativeEvent);
181
+ }, children: _jsx("span", { className: "ui-calendar__cell-label", "aria-hidden": "true", children: cell.label }) }, cell.date))) }, row.map((cell) => cell.date).join()))) })] })] }));
182
+ }