@feitio/react 0.0.0-stage → 0.2.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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -2
  3. package/dist/Anchor.d.ts +19 -0
  4. package/dist/AppShell.d.ts +24 -0
  5. package/dist/BackToTop.d.ts +8 -0
  6. package/dist/Block.d.ts +7 -0
  7. package/dist/Breadcrumbs.d.ts +12 -0
  8. package/dist/Button.d.ts +16 -0
  9. package/dist/Checkbox.d.ts +11 -0
  10. package/dist/CodeBlock.d.ts +10 -0
  11. package/dist/Details.d.ts +9 -0
  12. package/dist/Dialog.d.ts +21 -0
  13. package/dist/Divider.d.ts +7 -0
  14. package/dist/DoDont.d.ts +14 -0
  15. package/dist/Drawer.d.ts +13 -0
  16. package/dist/EmptyState.d.ts +11 -0
  17. package/dist/ErrorMessage.d.ts +8 -0
  18. package/dist/ErrorSummary.d.ts +11 -0
  19. package/dist/Example.d.ts +14 -0
  20. package/dist/FeitioProvider.d.ts +8 -0
  21. package/dist/Field.d.ts +15 -0
  22. package/dist/Fieldset.d.ts +8 -0
  23. package/dist/FilterField.d.ts +19 -0
  24. package/dist/Footer.d.ts +14 -0
  25. package/dist/Grid.d.ts +10 -0
  26. package/dist/Header.d.ts +22 -0
  27. package/dist/Heading.d.ts +8 -0
  28. package/dist/Hint.d.ts +7 -0
  29. package/dist/Icon.d.ts +9 -0
  30. package/dist/Inline.d.ts +9 -0
  31. package/dist/Kbd.d.ts +5 -0
  32. package/dist/Label.d.ts +8 -0
  33. package/dist/Link.d.ts +11 -0
  34. package/dist/LinkCard.d.ts +9 -0
  35. package/dist/Menu.d.ts +25 -0
  36. package/dist/Nav.d.ts +17 -0
  37. package/dist/Notice.d.ts +19 -0
  38. package/dist/Pagination.d.ts +20 -0
  39. package/dist/Radios.d.ts +13 -0
  40. package/dist/ScrollFade.d.ts +3 -0
  41. package/dist/Search.d.ts +17 -0
  42. package/dist/SegmentedControl.d.ts +9 -0
  43. package/dist/Select.d.ts +16 -0
  44. package/dist/SkipLink.d.ts +6 -0
  45. package/dist/Stack.d.ts +9 -0
  46. package/dist/StatusOverlay.d.ts +12 -0
  47. package/dist/SummaryList.d.ts +13 -0
  48. package/dist/Swatch.d.ts +5 -0
  49. package/dist/Switch.d.ts +12 -0
  50. package/dist/Table.d.ts +18 -0
  51. package/dist/Tag.d.ts +9 -0
  52. package/dist/TaskList.d.ts +13 -0
  53. package/dist/Text.d.ts +5 -0
  54. package/dist/TextInput.d.ts +10 -0
  55. package/dist/Textarea.d.ts +8 -0
  56. package/dist/TimeInput.d.ts +14 -0
  57. package/dist/VisuallyHidden.d.ts +5 -0
  58. package/dist/actions/notices.d.ts +16 -0
  59. package/dist/actions/status.d.ts +5 -0
  60. package/dist/actions/use-element-behavior.d.ts +6 -0
  61. package/dist/actions/use-page-behavior.d.ts +6 -0
  62. package/dist/actions/use-sprite.d.ts +2 -0
  63. package/dist/actions/wire.d.ts +10 -0
  64. package/dist/calculations/pagination.d.ts +10 -0
  65. package/dist/calculations/svg-parts.d.ts +9 -0
  66. package/dist/calculations/text.d.ts +4 -0
  67. package/dist/data/sprite.d.ts +4 -0
  68. package/dist/index.d.ts +58 -0
  69. package/dist/index.js +2482 -0
  70. package/package.json +56 -4
  71. package/src/Anchor.tsx +47 -0
  72. package/src/AppShell.tsx +95 -0
  73. package/src/BackToTop.tsx +26 -0
  74. package/src/Block.tsx +11 -0
  75. package/src/Breadcrumbs.tsx +40 -0
  76. package/src/Button.tsx +40 -0
  77. package/src/Checkbox.tsx +34 -0
  78. package/src/CodeBlock.tsx +38 -0
  79. package/src/Details.tsx +22 -0
  80. package/src/Dialog.tsx +70 -0
  81. package/src/Divider.tsx +17 -0
  82. package/src/DoDont.tsx +46 -0
  83. package/src/Drawer.tsx +52 -0
  84. package/src/EmptyState.tsx +37 -0
  85. package/src/ErrorMessage.tsx +18 -0
  86. package/src/ErrorSummary.tsx +27 -0
  87. package/src/Example.tsx +45 -0
  88. package/src/FeitioProvider.tsx +13 -0
  89. package/src/Field.tsx +45 -0
  90. package/src/Fieldset.tsx +18 -0
  91. package/src/FilterField.tsx +61 -0
  92. package/src/Footer.tsx +37 -0
  93. package/src/Grid.tsx +19 -0
  94. package/src/Header.tsx +60 -0
  95. package/src/Heading.tsx +13 -0
  96. package/src/Hint.tsx +15 -0
  97. package/src/Icon.tsx +19 -0
  98. package/src/Inline.tsx +17 -0
  99. package/src/Kbd.tsx +6 -0
  100. package/src/Label.tsx +16 -0
  101. package/src/Link.tsx +33 -0
  102. package/src/LinkCard.tsx +22 -0
  103. package/src/Menu.tsx +73 -0
  104. package/src/Nav.tsx +36 -0
  105. package/src/Notice.tsx +73 -0
  106. package/src/Pagination.tsx +98 -0
  107. package/src/Radios.tsx +43 -0
  108. package/src/ScrollFade.tsx +10 -0
  109. package/src/Search.tsx +66 -0
  110. package/src/SegmentedControl.tsx +36 -0
  111. package/src/Select.tsx +50 -0
  112. package/src/SkipLink.tsx +16 -0
  113. package/src/Stack.tsx +17 -0
  114. package/src/StatusOverlay.tsx +46 -0
  115. package/src/SummaryList.tsx +27 -0
  116. package/src/Swatch.tsx +11 -0
  117. package/src/Switch.tsx +41 -0
  118. package/src/Table.tsx +74 -0
  119. package/src/Tag.tsx +21 -0
  120. package/src/TaskList.tsx +34 -0
  121. package/src/Text.tsx +6 -0
  122. package/src/TextInput.tsx +29 -0
  123. package/src/Textarea.tsx +25 -0
  124. package/src/TimeInput.tsx +59 -0
  125. package/src/VisuallyHidden.tsx +6 -0
  126. package/src/actions/notices.ts +30 -0
  127. package/src/actions/status.ts +13 -0
  128. package/src/actions/use-element-behavior.ts +23 -0
  129. package/src/actions/use-page-behavior.ts +17 -0
  130. package/src/actions/use-sprite.ts +8 -0
  131. package/src/actions/wire.ts +30 -0
  132. package/src/calculations/pagination.ts +15 -0
  133. package/src/calculations/svg-parts.ts +22 -0
  134. package/src/calculations/text.ts +9 -0
  135. package/src/data/sprite.ts +7 -0
  136. package/src/index.ts +59 -0
  137. package/src/text-modules.d.ts +5 -0
@@ -0,0 +1,6 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ /** SkipLink: the first thing the keyboard reaches; jumps straight to the content. */
3
+ export declare function SkipLink({ href, children, }: {
4
+ href?: string;
5
+ children?: ReactNode;
6
+ }): ReactElement;
@@ -0,0 +1,9 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ export interface StackProps {
3
+ gap?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
4
+ align?: 'start' | 'center';
5
+ as?: 'div' | 'section' | 'ul' | 'ol';
6
+ children?: ReactNode;
7
+ }
8
+ /** Stack: pieces one below the other, one step of the scale apart. */
9
+ export declare function Stack({ gap, align, as: Tag, children }: StackProps): ReactElement;
@@ -0,0 +1,12 @@
1
+ import type { ReactElement, ReactNode, Ref } from 'react';
2
+ export interface StatusOverlayProps {
3
+ /** What it shows over the content: loading, done or failed; nothing without it. */
4
+ state?: 'loading' | 'ok' | 'error';
5
+ /** The words for the state, which screen readers hear. */
6
+ label?: string;
7
+ as?: 'div' | 'form' | 'section';
8
+ ref?: Ref<HTMLElement | null>;
9
+ children?: ReactNode;
10
+ }
11
+ /** StatusOverlay: feedback drawn over a part of the page while it loads, and when it is done or failed. */
12
+ export declare function StatusOverlay({ state, label, as: Tag, ref, children, }: StatusOverlayProps): ReactElement;
@@ -0,0 +1,13 @@
1
+ import type { ReactElement } from 'react';
2
+ export interface SummaryListProps {
3
+ rows: {
4
+ key: string;
5
+ value: string;
6
+ change?: {
7
+ href: string;
8
+ label: string;
9
+ };
10
+ }[];
11
+ }
12
+ /** SummaryList: pairs of a name and its value, each one with a link to change it. */
13
+ export declare function SummaryList({ rows }: SummaryListProps): ReactElement;
@@ -0,0 +1,5 @@
1
+ import type { ReactElement } from 'react';
2
+ /** Swatch: a color role, painted. role is like "accent" or "ok". */
3
+ export declare function Swatch({ role }: {
4
+ role: string;
5
+ }): ReactElement;
@@ -0,0 +1,12 @@
1
+ import type { ReactElement } from 'react';
2
+ export interface SwitchProps {
3
+ label: string;
4
+ on?: boolean;
5
+ disabled?: boolean;
6
+ onLabel?: string;
7
+ offLabel?: string;
8
+ name?: string;
9
+ onChange?: (on: boolean) => void;
10
+ }
11
+ /** Switch: a setting that takes effect at once, its state said in words. */
12
+ export declare function Switch({ label, on, disabled, onLabel, offLabel, name, onChange, }: SwitchProps): ReactElement;
@@ -0,0 +1,18 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ export interface TableColumn {
3
+ label: string;
4
+ align?: 'end';
5
+ /** The column's name is only heard (like the actions column). */
6
+ hidden?: boolean;
7
+ }
8
+ export interface TableProps {
9
+ id: string;
10
+ caption?: string;
11
+ columns: TableColumn[];
12
+ /** Each row: one cell per column (text, or a Tag, a link, a button). */
13
+ rows: ReactNode[][];
14
+ /** The first column is the row's title on a phone card. */
15
+ compact?: boolean;
16
+ }
17
+ /** Table: rows to compare; on a phone, each row becomes a card. */
18
+ export declare function Table({ id, caption, columns, rows, compact }: TableProps): ReactElement;
package/dist/Tag.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ export interface TagProps {
3
+ status?: 'ok' | 'warn' | 'error';
4
+ size?: 'small';
5
+ sprite?: string;
6
+ children?: ReactNode;
7
+ }
8
+ /** Tag: a short word about a state, with its icon, never color alone. */
9
+ export declare function Tag({ status, size, sprite, children }: TagProps): ReactElement;
@@ -0,0 +1,13 @@
1
+ import type { ReactElement } from 'react';
2
+ export interface TaskListProps {
3
+ items: {
4
+ name: string;
5
+ href: string;
6
+ detail?: string;
7
+ status?: 'ok' | 'warn' | 'error';
8
+ word: string;
9
+ }[];
10
+ sprite?: string;
11
+ }
12
+ /** TaskList: the steps of a long job, each with its state in a Tag. */
13
+ export declare function TaskList({ items, sprite }: TaskListProps): ReactElement;
package/dist/Text.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ /** Text: a paragraph, at the measure that reads well. */
3
+ export declare function Text({ children }: {
4
+ children?: ReactNode;
5
+ }): ReactElement;
@@ -0,0 +1,10 @@
1
+ import type { InputHTMLAttributes, ReactElement } from 'react';
2
+ export interface TextInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'width'> {
3
+ id: string;
4
+ invalid?: boolean;
5
+ describedBy?: string;
6
+ /** The width it is meant for, in characters: 2, 4, 10, 20 or 40. Without it, the whole line. */
7
+ width?: 2 | 4 | 10 | 20 | 40;
8
+ }
9
+ /** TextInput: one line of text, as wide as what it is meant to hold. */
10
+ export declare function TextInput({ invalid, describedBy, width, className, ...rest }: TextInputProps): ReactElement;
@@ -0,0 +1,8 @@
1
+ import type { ReactElement, TextareaHTMLAttributes } from 'react';
2
+ export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
3
+ id: string;
4
+ invalid?: boolean;
5
+ describedBy?: string;
6
+ }
7
+ /** Textarea: longer text, over several lines. */
8
+ export declare function Textarea({ invalid, describedBy, className, ...rest }: TextareaProps): ReactElement;
@@ -0,0 +1,14 @@
1
+ import type { ReactElement } from 'react';
2
+ export interface TimeInputProps {
3
+ hour?: string;
4
+ minute?: string;
5
+ cycle?: '12' | '24';
6
+ period?: 'AM' | 'PM';
7
+ hourLabel?: string;
8
+ minuteLabel?: string;
9
+ periodLabel?: string;
10
+ invalid?: boolean;
11
+ disabled?: boolean;
12
+ }
13
+ /** TimeInput: an hour and its minutes in two short fields; in a 12-hour cycle, AM or PM. */
14
+ export declare function TimeInput({ hour, minute, cycle, period, hourLabel, minuteLabel, periodLabel, invalid, disabled, }: TimeInputProps): ReactElement;
@@ -0,0 +1,5 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ /** VisuallyHidden: words only screen readers hear. */
3
+ export declare function VisuallyHidden({ children }: {
4
+ children?: ReactNode;
5
+ }): ReactElement;
@@ -0,0 +1,16 @@
1
+ /** What the page's Notice controller does. */
2
+ export interface NoticeApi {
3
+ show: (notice: HTMLElement) => void;
4
+ close: (notice: HTMLElement) => void;
5
+ wire: (root: ParentNode) => void;
6
+ }
7
+ /**
8
+ * The page's Notice controller, the same one the Astro Notice creates (window.feitioNotice); made
9
+ * here first, it wires the notices already on the page, as the Astro script would.
10
+ */
11
+ export declare function noticeApi(window: Window): NoticeApi;
12
+ /** Show and close a Notice from code: show(element) brings a hidden notice in, close(element) takes it out. */
13
+ export declare function useNotices(): {
14
+ show: (notice: HTMLElement) => void;
15
+ close: (notice: HTMLElement) => void;
16
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shows a StatusOverlay's feedback from code, on its element: "loading", "ok" or "error", with the
3
+ * words for it; null clears it. In React, the state and label props usually do this.
4
+ */
5
+ export declare function status(host: HTMLElement, state: 'loading' | 'ok' | 'error' | null, label?: string): void;
@@ -0,0 +1,6 @@
1
+ import { type RefObject } from 'react';
2
+ /**
3
+ * Wires a behavior on one element when it mounts, only once per element (React's strict mode runs
4
+ * effects twice in development; listeners must not double).
5
+ */
6
+ export declare function useElementBehavior<T extends Element>(ref: RefObject<T | null>, name: string, wire: (element: T) => void): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Wires a delegated behavior once for the whole page (it listens on the document, so components that
3
+ * mount later are covered too). The flag on window is shared with the Astro components, so a page
4
+ * that mixes both never wires it twice.
5
+ */
6
+ export declare function usePageBehavior(flag: string, wire: (window: Window) => void): void;
@@ -0,0 +1,2 @@
1
+ /** The sprite an icon uses: its own, else the FeitioProvider's, else the default path. */
2
+ export declare function useSprite(own?: string): string;
@@ -0,0 +1,10 @@
1
+ /** The form controls of the page: Switch words, SegmentedControl choice, AM/PM, FilterField. */
2
+ export declare function wireForms(window: Window): void;
3
+ /** The Dialogs of the page: openers, the typed confirmation, the reset on close. */
4
+ export declare function wireDialogs(window: Window): void;
5
+ /** One Menu: its button, its list, the arrows. */
6
+ export declare function wireMenu(element: HTMLElement): void;
7
+ /** One Notice: its close button and, when timed, its clock. */
8
+ export declare function wireNotice(element: HTMLElement): void;
9
+ /** The ScrollFade or BackToTop next to this element (each one is wired once). */
10
+ export declare function wireScroll(element: HTMLElement): void;
@@ -0,0 +1,10 @@
1
+ /** One entry of a Pagination: a page number, or a gap (…) between pages that are not next to each other. */
2
+ export type PageEntry = {
3
+ kind: 'page';
4
+ page: number;
5
+ } | {
6
+ kind: 'gap';
7
+ after: number;
8
+ };
9
+ /** The pages a Pagination shows: the first, the last, and the ones around the current, with gaps between. */
10
+ export declare function paginationEntries(current: number, total: number): PageEntry[];
@@ -0,0 +1,9 @@
1
+ /** An SVG file split for React: its root attributes, named as React wants them, and its inner markup. */
2
+ export interface SvgParts {
3
+ attributes: Record<string, string>;
4
+ inner: string;
5
+ }
6
+ /** stroke-width becomes strokeWidth; aria-*, data-* and names without a dash stay as they are. */
7
+ export declare function reactAttributeName(name: string): string;
8
+ /** Splits an SVG file's text into its root's attributes and what is inside it. */
9
+ export declare function svgParts(svg: string): SvgParts;
@@ -0,0 +1,4 @@
1
+ /** Joins class names, leaving out the empty ones. */
2
+ export declare function classNames(...names: (string | false | null | undefined)[]): string;
3
+ /** The years a Footer shows: the year it started, or "since–now" when that was before this year. */
4
+ export declare function yearsText(since: number, year: number): string;
@@ -0,0 +1,4 @@
1
+ /** Where the icon sprite is served when nobody says otherwise: the same default as the Astro Icon. */
2
+ export declare const DEFAULT_SPRITE = "/feitio/icons/sprite.svg";
3
+ /** The sprite for every icon under a FeitioProvider. */
4
+ export declare const SpriteContext: import("react").Context<string | undefined>;
@@ -0,0 +1,58 @@
1
+ /** Feitio for React: the same HTML as the Astro components, with the behaviors wired by hooks. */
2
+ export * from './Anchor.js';
3
+ export * from './AppShell.js';
4
+ export { useNotices } from './actions/notices.js';
5
+ export { status } from './actions/status.js';
6
+ export * from './BackToTop.js';
7
+ export * from './Block.js';
8
+ export * from './Breadcrumbs.js';
9
+ export * from './Button.js';
10
+ export * from './Checkbox.js';
11
+ export * from './CodeBlock.js';
12
+ export * from './Details.js';
13
+ export * from './Dialog.js';
14
+ export * from './Divider.js';
15
+ export * from './DoDont.js';
16
+ export * from './Drawer.js';
17
+ export * from './EmptyState.js';
18
+ export * from './ErrorMessage.js';
19
+ export * from './ErrorSummary.js';
20
+ export * from './Example.js';
21
+ export * from './FeitioProvider.js';
22
+ export * from './Field.js';
23
+ export * from './Fieldset.js';
24
+ export * from './FilterField.js';
25
+ export * from './Footer.js';
26
+ export * from './Grid.js';
27
+ export * from './Header.js';
28
+ export * from './Heading.js';
29
+ export * from './Hint.js';
30
+ export * from './Icon.js';
31
+ export * from './Inline.js';
32
+ export * from './Kbd.js';
33
+ export * from './Label.js';
34
+ export * from './Link.js';
35
+ export * from './LinkCard.js';
36
+ export * from './Menu.js';
37
+ export * from './Nav.js';
38
+ export * from './Notice.js';
39
+ export * from './Pagination.js';
40
+ export * from './Radios.js';
41
+ export * from './ScrollFade.js';
42
+ export * from './Search.js';
43
+ export * from './SegmentedControl.js';
44
+ export * from './Select.js';
45
+ export * from './SkipLink.js';
46
+ export * from './Stack.js';
47
+ export * from './StatusOverlay.js';
48
+ export * from './SummaryList.js';
49
+ export * from './Swatch.js';
50
+ export * from './Switch.js';
51
+ export * from './Table.js';
52
+ export * from './Tag.js';
53
+ export * from './TaskList.js';
54
+ export * from './Text.js';
55
+ export * from './Textarea.js';
56
+ export * from './TextInput.js';
57
+ export * from './TimeInput.js';
58
+ export * from './VisuallyHidden.js';