@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.
- package/LICENSE +21 -0
- package/README.md +35 -2
- package/dist/Anchor.d.ts +19 -0
- package/dist/AppShell.d.ts +24 -0
- package/dist/BackToTop.d.ts +8 -0
- package/dist/Block.d.ts +7 -0
- package/dist/Breadcrumbs.d.ts +12 -0
- package/dist/Button.d.ts +16 -0
- package/dist/Checkbox.d.ts +11 -0
- package/dist/CodeBlock.d.ts +10 -0
- package/dist/Details.d.ts +9 -0
- package/dist/Dialog.d.ts +21 -0
- package/dist/Divider.d.ts +7 -0
- package/dist/DoDont.d.ts +14 -0
- package/dist/Drawer.d.ts +13 -0
- package/dist/EmptyState.d.ts +11 -0
- package/dist/ErrorMessage.d.ts +8 -0
- package/dist/ErrorSummary.d.ts +11 -0
- package/dist/Example.d.ts +14 -0
- package/dist/FeitioProvider.d.ts +8 -0
- package/dist/Field.d.ts +15 -0
- package/dist/Fieldset.d.ts +8 -0
- package/dist/FilterField.d.ts +19 -0
- package/dist/Footer.d.ts +14 -0
- package/dist/Grid.d.ts +10 -0
- package/dist/Header.d.ts +22 -0
- package/dist/Heading.d.ts +8 -0
- package/dist/Hint.d.ts +7 -0
- package/dist/Icon.d.ts +9 -0
- package/dist/Inline.d.ts +9 -0
- package/dist/Kbd.d.ts +5 -0
- package/dist/Label.d.ts +8 -0
- package/dist/Link.d.ts +11 -0
- package/dist/LinkCard.d.ts +9 -0
- package/dist/Menu.d.ts +25 -0
- package/dist/Nav.d.ts +17 -0
- package/dist/Notice.d.ts +19 -0
- package/dist/Pagination.d.ts +20 -0
- package/dist/Radios.d.ts +13 -0
- package/dist/ScrollFade.d.ts +3 -0
- package/dist/Search.d.ts +17 -0
- package/dist/SegmentedControl.d.ts +9 -0
- package/dist/Select.d.ts +16 -0
- package/dist/SkipLink.d.ts +6 -0
- package/dist/Stack.d.ts +9 -0
- package/dist/StatusOverlay.d.ts +12 -0
- package/dist/SummaryList.d.ts +13 -0
- package/dist/Swatch.d.ts +5 -0
- package/dist/Switch.d.ts +12 -0
- package/dist/Table.d.ts +18 -0
- package/dist/Tag.d.ts +9 -0
- package/dist/TaskList.d.ts +13 -0
- package/dist/Text.d.ts +5 -0
- package/dist/TextInput.d.ts +10 -0
- package/dist/Textarea.d.ts +8 -0
- package/dist/TimeInput.d.ts +14 -0
- package/dist/VisuallyHidden.d.ts +5 -0
- package/dist/actions/notices.d.ts +16 -0
- package/dist/actions/status.d.ts +5 -0
- package/dist/actions/use-element-behavior.d.ts +6 -0
- package/dist/actions/use-page-behavior.d.ts +6 -0
- package/dist/actions/use-sprite.d.ts +2 -0
- package/dist/actions/wire.d.ts +10 -0
- package/dist/calculations/pagination.d.ts +10 -0
- package/dist/calculations/svg-parts.d.ts +9 -0
- package/dist/calculations/text.d.ts +4 -0
- package/dist/data/sprite.d.ts +4 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +2482 -0
- package/package.json +56 -4
- package/src/Anchor.tsx +47 -0
- package/src/AppShell.tsx +95 -0
- package/src/BackToTop.tsx +26 -0
- package/src/Block.tsx +11 -0
- package/src/Breadcrumbs.tsx +40 -0
- package/src/Button.tsx +40 -0
- package/src/Checkbox.tsx +34 -0
- package/src/CodeBlock.tsx +38 -0
- package/src/Details.tsx +22 -0
- package/src/Dialog.tsx +70 -0
- package/src/Divider.tsx +17 -0
- package/src/DoDont.tsx +46 -0
- package/src/Drawer.tsx +52 -0
- package/src/EmptyState.tsx +37 -0
- package/src/ErrorMessage.tsx +18 -0
- package/src/ErrorSummary.tsx +27 -0
- package/src/Example.tsx +45 -0
- package/src/FeitioProvider.tsx +13 -0
- package/src/Field.tsx +45 -0
- package/src/Fieldset.tsx +18 -0
- package/src/FilterField.tsx +61 -0
- package/src/Footer.tsx +37 -0
- package/src/Grid.tsx +19 -0
- package/src/Header.tsx +60 -0
- package/src/Heading.tsx +13 -0
- package/src/Hint.tsx +15 -0
- package/src/Icon.tsx +19 -0
- package/src/Inline.tsx +17 -0
- package/src/Kbd.tsx +6 -0
- package/src/Label.tsx +16 -0
- package/src/Link.tsx +33 -0
- package/src/LinkCard.tsx +22 -0
- package/src/Menu.tsx +73 -0
- package/src/Nav.tsx +36 -0
- package/src/Notice.tsx +73 -0
- package/src/Pagination.tsx +98 -0
- package/src/Radios.tsx +43 -0
- package/src/ScrollFade.tsx +10 -0
- package/src/Search.tsx +66 -0
- package/src/SegmentedControl.tsx +36 -0
- package/src/Select.tsx +50 -0
- package/src/SkipLink.tsx +16 -0
- package/src/Stack.tsx +17 -0
- package/src/StatusOverlay.tsx +46 -0
- package/src/SummaryList.tsx +27 -0
- package/src/Swatch.tsx +11 -0
- package/src/Switch.tsx +41 -0
- package/src/Table.tsx +74 -0
- package/src/Tag.tsx +21 -0
- package/src/TaskList.tsx +34 -0
- package/src/Text.tsx +6 -0
- package/src/TextInput.tsx +29 -0
- package/src/Textarea.tsx +25 -0
- package/src/TimeInput.tsx +59 -0
- package/src/VisuallyHidden.tsx +6 -0
- package/src/actions/notices.ts +30 -0
- package/src/actions/status.ts +13 -0
- package/src/actions/use-element-behavior.ts +23 -0
- package/src/actions/use-page-behavior.ts +17 -0
- package/src/actions/use-sprite.ts +8 -0
- package/src/actions/wire.ts +30 -0
- package/src/calculations/pagination.ts +15 -0
- package/src/calculations/svg-parts.ts +22 -0
- package/src/calculations/text.ts +9 -0
- package/src/data/sprite.ts +7 -0
- package/src/index.ts +59 -0
- package/src/text-modules.d.ts +5 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { paginationEntries } from './calculations/pagination.ts';
|
|
3
|
+
import { Icon } from './Icon.tsx';
|
|
4
|
+
|
|
5
|
+
export interface PaginationProps {
|
|
6
|
+
label: string;
|
|
7
|
+
current: number;
|
|
8
|
+
total: number;
|
|
9
|
+
href: (page: number) => string;
|
|
10
|
+
count?: string;
|
|
11
|
+
perPage?: { label: string; options: number[]; current: number; href: (n: number) => string };
|
|
12
|
+
previousLabel?: string;
|
|
13
|
+
nextLabel?: string;
|
|
14
|
+
pageLabel?: (page: number) => string;
|
|
15
|
+
sprite?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function defaultPageLabel(page: number): string {
|
|
19
|
+
return `Página ${page}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Pagination: the pages of a long list, the first and last always in reach. */
|
|
23
|
+
export function Pagination({
|
|
24
|
+
label,
|
|
25
|
+
current,
|
|
26
|
+
total,
|
|
27
|
+
href,
|
|
28
|
+
count,
|
|
29
|
+
perPage,
|
|
30
|
+
previousLabel = 'Anterior',
|
|
31
|
+
nextLabel = 'Próxima',
|
|
32
|
+
pageLabel = defaultPageLabel,
|
|
33
|
+
sprite,
|
|
34
|
+
}: PaginationProps): ReactElement {
|
|
35
|
+
return (
|
|
36
|
+
<nav className="feitio-pagination" aria-label={label}>
|
|
37
|
+
<ul>
|
|
38
|
+
{current > 1 && (
|
|
39
|
+
<li>
|
|
40
|
+
<a className="step prev" href={href(current - 1)} rel="prev">
|
|
41
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
42
|
+
{previousLabel}
|
|
43
|
+
</a>
|
|
44
|
+
</li>
|
|
45
|
+
)}
|
|
46
|
+
{paginationEntries(current, total).map((entry) =>
|
|
47
|
+
entry.kind === 'gap' ? (
|
|
48
|
+
<li key={`gap-${entry.after}`}>
|
|
49
|
+
<span className="gap" aria-hidden="true">
|
|
50
|
+
…
|
|
51
|
+
</span>
|
|
52
|
+
</li>
|
|
53
|
+
) : (
|
|
54
|
+
<li key={entry.page}>
|
|
55
|
+
{entry.page === current ? (
|
|
56
|
+
<span aria-current="page">{entry.page}</span>
|
|
57
|
+
) : (
|
|
58
|
+
<a href={href(entry.page)} aria-label={pageLabel(entry.page)}>
|
|
59
|
+
{entry.page}
|
|
60
|
+
</a>
|
|
61
|
+
)}
|
|
62
|
+
</li>
|
|
63
|
+
),
|
|
64
|
+
)}
|
|
65
|
+
{current < total && (
|
|
66
|
+
<li>
|
|
67
|
+
<a className="step" href={href(current + 1)} rel="next">
|
|
68
|
+
{nextLabel}
|
|
69
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
70
|
+
</a>
|
|
71
|
+
</li>
|
|
72
|
+
)}
|
|
73
|
+
</ul>
|
|
74
|
+
{(count || perPage) && (
|
|
75
|
+
<div className="meta">
|
|
76
|
+
{count && <p className="count">{count}</p>}
|
|
77
|
+
{perPage && (
|
|
78
|
+
// biome-ignore lint/a11y/useSemanticElements: a group of links, not a form.
|
|
79
|
+
<div className="per-page" role="group" aria-label={perPage.label}>
|
|
80
|
+
<span>{perPage.label}</span>
|
|
81
|
+
{perPage.options.map((n) =>
|
|
82
|
+
n === perPage.current ? (
|
|
83
|
+
<span key={n} aria-current="true">
|
|
84
|
+
{n}
|
|
85
|
+
</span>
|
|
86
|
+
) : (
|
|
87
|
+
<a key={n} href={perPage.href(n)}>
|
|
88
|
+
{n}
|
|
89
|
+
</a>
|
|
90
|
+
),
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
96
|
+
</nav>
|
|
97
|
+
);
|
|
98
|
+
}
|
package/src/Radios.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface RadiosProps {
|
|
4
|
+
legend: string;
|
|
5
|
+
name: string;
|
|
6
|
+
options: string[];
|
|
7
|
+
value?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/** "inline" puts short options side by side. */
|
|
10
|
+
layout?: 'stack' | 'inline';
|
|
11
|
+
onChange?: (value: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Radios: one answer out of a few, all of them in sight. */
|
|
15
|
+
export function Radios({
|
|
16
|
+
legend,
|
|
17
|
+
name,
|
|
18
|
+
options,
|
|
19
|
+
value,
|
|
20
|
+
disabled,
|
|
21
|
+
layout = 'stack',
|
|
22
|
+
onChange,
|
|
23
|
+
}: RadiosProps): ReactElement {
|
|
24
|
+
return (
|
|
25
|
+
<fieldset className="feitio-fieldset" disabled={disabled}>
|
|
26
|
+
<legend className="feitio-label">{legend}</legend>
|
|
27
|
+
<div className="feitio-choices" data-layout={layout === 'inline' ? 'inline' : undefined}>
|
|
28
|
+
{options.map((o) => (
|
|
29
|
+
<label className="feitio-choice" key={o}>
|
|
30
|
+
<input
|
|
31
|
+
type="radio"
|
|
32
|
+
name={name}
|
|
33
|
+
value={o}
|
|
34
|
+
defaultChecked={o === value}
|
|
35
|
+
onChange={onChange && (() => onChange(o))}
|
|
36
|
+
/>
|
|
37
|
+
{o}
|
|
38
|
+
</label>
|
|
39
|
+
))}
|
|
40
|
+
</div>
|
|
41
|
+
</fieldset>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactElement, useRef } from 'react';
|
|
2
|
+
import { useElementBehavior } from './actions/use-element-behavior.ts';
|
|
3
|
+
import { wireScroll } from './actions/wire.ts';
|
|
4
|
+
|
|
5
|
+
/** ScrollFade: a soft edge at the bottom of a box that scrolls, while there is more below. */
|
|
6
|
+
export function ScrollFade(): ReactElement {
|
|
7
|
+
const ref = useRef<HTMLSpanElement>(null);
|
|
8
|
+
useElementBehavior(ref, 'scroll', wireScroll);
|
|
9
|
+
return <span className="feitio-scroll-fade" aria-hidden="true" ref={ref} />;
|
|
10
|
+
}
|
package/src/Search.tsx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface SearchProps {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
closeLabel?: string;
|
|
9
|
+
keys?: { open: string; choose: string; close: string };
|
|
10
|
+
sprite?: string;
|
|
11
|
+
/** The results, as list items. */
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Search: the site's search in a Dialog, its results in a list, moved through with the keyboard. */
|
|
16
|
+
export function Search({
|
|
17
|
+
id,
|
|
18
|
+
title,
|
|
19
|
+
placeholder,
|
|
20
|
+
closeLabel = 'Fechar',
|
|
21
|
+
keys,
|
|
22
|
+
sprite,
|
|
23
|
+
children,
|
|
24
|
+
}: SearchProps): ReactElement {
|
|
25
|
+
return (
|
|
26
|
+
<dialog className="feitio-dialog search-dialog" id={id} aria-labelledby={`${id}-t`}>
|
|
27
|
+
<form method="dialog">
|
|
28
|
+
<h2 id={`${id}-t`} className="feitio-visually-hidden">
|
|
29
|
+
{title}
|
|
30
|
+
</h2>
|
|
31
|
+
<div className="search-head">
|
|
32
|
+
<Icon name="search" sprite={sprite} />
|
|
33
|
+
<label className="feitio-visually-hidden" htmlFor={`${id}-field`}>
|
|
34
|
+
{title}
|
|
35
|
+
</label>
|
|
36
|
+
<input
|
|
37
|
+
className="search-field"
|
|
38
|
+
id={`${id}-field`}
|
|
39
|
+
type="search"
|
|
40
|
+
autoComplete="off"
|
|
41
|
+
placeholder={placeholder}
|
|
42
|
+
/>
|
|
43
|
+
<button type="submit" className="feitio-button close" data-size="small" value="close">
|
|
44
|
+
<Icon name="close" sprite={sprite} />
|
|
45
|
+
{closeLabel}
|
|
46
|
+
</button>
|
|
47
|
+
</div>
|
|
48
|
+
<ul className="results">{children}</ul>
|
|
49
|
+
{keys && (
|
|
50
|
+
<p className="foot">
|
|
51
|
+
<span>
|
|
52
|
+
<kbd className="feitio-kbd">↵</kbd> {keys.open}
|
|
53
|
+
</span>
|
|
54
|
+
<span>
|
|
55
|
+
<kbd className="feitio-kbd">↑</kbd>
|
|
56
|
+
<kbd className="feitio-kbd">↓</kbd> {keys.choose}
|
|
57
|
+
</span>
|
|
58
|
+
<span>
|
|
59
|
+
<kbd className="feitio-kbd">Esc</kbd> {keys.close}
|
|
60
|
+
</span>
|
|
61
|
+
</p>
|
|
62
|
+
)}
|
|
63
|
+
</form>
|
|
64
|
+
</dialog>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { usePageBehavior } from './actions/use-page-behavior.ts';
|
|
3
|
+
import { wireForms } from './actions/wire.ts';
|
|
4
|
+
|
|
5
|
+
export interface SegmentedControlProps {
|
|
6
|
+
label: string;
|
|
7
|
+
options: string[];
|
|
8
|
+
value?: string;
|
|
9
|
+
onChange?: (value: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** SegmentedControl: a few options side by side, one of them on. */
|
|
13
|
+
export function SegmentedControl({
|
|
14
|
+
label,
|
|
15
|
+
options,
|
|
16
|
+
value,
|
|
17
|
+
onChange,
|
|
18
|
+
}: SegmentedControlProps): ReactElement {
|
|
19
|
+
usePageBehavior('feitioForms', wireForms);
|
|
20
|
+
const current = value ?? options[0];
|
|
21
|
+
return (
|
|
22
|
+
// biome-ignore lint/a11y/useSemanticElements: a group of toggle buttons, not a form.
|
|
23
|
+
<div className="feitio-segmented" role="group" aria-label={label}>
|
|
24
|
+
{options.map((o) => (
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
key={o}
|
|
28
|
+
aria-pressed={o === current ? 'true' : 'false'}
|
|
29
|
+
onClick={onChange && (() => onChange(o))}
|
|
30
|
+
>
|
|
31
|
+
{o}
|
|
32
|
+
</button>
|
|
33
|
+
))}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
package/src/Select.tsx
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface SelectProps {
|
|
5
|
+
id: string;
|
|
6
|
+
options: string[];
|
|
7
|
+
value?: string;
|
|
8
|
+
/** A first, empty option, like "Choose…". */
|
|
9
|
+
empty?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
invalid?: boolean;
|
|
12
|
+
describedBy?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
sprite?: string;
|
|
15
|
+
onChange?: (value: string) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Select: one option out of a long list, closed until opened. */
|
|
19
|
+
export function Select({
|
|
20
|
+
id,
|
|
21
|
+
options,
|
|
22
|
+
value,
|
|
23
|
+
empty,
|
|
24
|
+
disabled,
|
|
25
|
+
invalid,
|
|
26
|
+
describedBy,
|
|
27
|
+
name,
|
|
28
|
+
sprite,
|
|
29
|
+
onChange,
|
|
30
|
+
}: SelectProps): ReactElement {
|
|
31
|
+
return (
|
|
32
|
+
<span className="feitio-select">
|
|
33
|
+
<select
|
|
34
|
+
id={id}
|
|
35
|
+
name={name}
|
|
36
|
+
disabled={disabled}
|
|
37
|
+
aria-invalid={invalid ? 'true' : undefined}
|
|
38
|
+
aria-describedby={describedBy}
|
|
39
|
+
defaultValue={value}
|
|
40
|
+
onChange={onChange && ((event) => onChange(event.target.value))}
|
|
41
|
+
>
|
|
42
|
+
{empty && <option value="">{empty}</option>}
|
|
43
|
+
{options.map((o) => (
|
|
44
|
+
<option key={o}>{o}</option>
|
|
45
|
+
))}
|
|
46
|
+
</select>
|
|
47
|
+
<Icon name="chevron-down" sprite={sprite} />
|
|
48
|
+
</span>
|
|
49
|
+
);
|
|
50
|
+
}
|
package/src/SkipLink.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/** SkipLink: the first thing the keyboard reaches; jumps straight to the content. */
|
|
4
|
+
export function SkipLink({
|
|
5
|
+
href = '#content',
|
|
6
|
+
children,
|
|
7
|
+
}: {
|
|
8
|
+
href?: string;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}): ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<a className="feitio-skip-link" href={href}>
|
|
13
|
+
{children}
|
|
14
|
+
</a>
|
|
15
|
+
);
|
|
16
|
+
}
|
package/src/Stack.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface StackProps {
|
|
4
|
+
gap?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
5
|
+
align?: 'start' | 'center';
|
|
6
|
+
as?: 'div' | 'section' | 'ul' | 'ol';
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Stack: pieces one below the other, one step of the scale apart. */
|
|
11
|
+
export function Stack({ gap = 4, align, as: Tag = 'div', children }: StackProps): ReactElement {
|
|
12
|
+
return (
|
|
13
|
+
<Tag className="feitio-stack" data-gap={gap} data-align={align}>
|
|
14
|
+
{children}
|
|
15
|
+
</Tag>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode, Ref } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface StatusOverlayProps {
|
|
4
|
+
/** What it shows over the content: loading, done or failed; nothing without it. */
|
|
5
|
+
state?: 'loading' | 'ok' | 'error';
|
|
6
|
+
/** The words for the state, which screen readers hear. */
|
|
7
|
+
label?: string;
|
|
8
|
+
as?: 'div' | 'form' | 'section';
|
|
9
|
+
ref?: Ref<HTMLElement | null>;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** StatusOverlay: feedback drawn over a part of the page while it loads, and when it is done or failed. */
|
|
14
|
+
export function StatusOverlay({
|
|
15
|
+
state,
|
|
16
|
+
label = '',
|
|
17
|
+
as: Tag = 'div',
|
|
18
|
+
ref,
|
|
19
|
+
children,
|
|
20
|
+
}: StatusOverlayProps): ReactElement {
|
|
21
|
+
return (
|
|
22
|
+
<Tag className="feitio-status-host" data-state={state} ref={ref as Ref<never>}>
|
|
23
|
+
{children}
|
|
24
|
+
<div className="feitio-status" role="status">
|
|
25
|
+
<svg viewBox="0 0 48 48" aria-hidden="true">
|
|
26
|
+
<g className="loading">
|
|
27
|
+
<path pathLength={1} d="M24 7 C34 6.5 41.5 14 41 24 C40.6 33 33 41 24 41.2" />
|
|
28
|
+
<path
|
|
29
|
+
pathLength={1}
|
|
30
|
+
d="M25.5 41 C14.5 41.6 6.8 33.5 7.2 23.6 C7.6 14 14.6 7.4 23 6.4"
|
|
31
|
+
/>
|
|
32
|
+
</g>
|
|
33
|
+
<g className="ok">
|
|
34
|
+
<path pathLength={1} d="M13 25 L21 33.5" />
|
|
35
|
+
<path pathLength={1} d="M19.5 34 L36 14.5" />
|
|
36
|
+
</g>
|
|
37
|
+
<g className="error">
|
|
38
|
+
<path pathLength={1} d="M15 15 L33.5 33" />
|
|
39
|
+
<path pathLength={1} d="M33 14.5 L15.5 33.5" />
|
|
40
|
+
</g>
|
|
41
|
+
</svg>
|
|
42
|
+
<span className="label">{label}</span>
|
|
43
|
+
</div>
|
|
44
|
+
</Tag>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface SummaryListProps {
|
|
4
|
+
rows: { key: string; value: string; change?: { href: string; label: string } }[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** SummaryList: pairs of a name and its value, each one with a link to change it. */
|
|
8
|
+
export function SummaryList({ rows }: SummaryListProps): ReactElement {
|
|
9
|
+
return (
|
|
10
|
+
<dl className="feitio-summary-list">
|
|
11
|
+
{rows.map((r) => (
|
|
12
|
+
<div key={r.key}>
|
|
13
|
+
<dt>{r.key}</dt>
|
|
14
|
+
<dd>{r.value}</dd>
|
|
15
|
+
{r.change && (
|
|
16
|
+
<dd className="change">
|
|
17
|
+
<a className="feitio-link" href={r.change.href}>
|
|
18
|
+
{r.change.label}
|
|
19
|
+
<span className="feitio-visually-hidden"> {r.key}</span>
|
|
20
|
+
</a>
|
|
21
|
+
</dd>
|
|
22
|
+
)}
|
|
23
|
+
</div>
|
|
24
|
+
))}
|
|
25
|
+
</dl>
|
|
26
|
+
);
|
|
27
|
+
}
|
package/src/Swatch.tsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
/** Swatch: a color role, painted. role is like "accent" or "ok". */
|
|
4
|
+
export function Swatch({ role }: { role: string }): ReactElement {
|
|
5
|
+
return (
|
|
6
|
+
<span
|
|
7
|
+
className="feitio-swatch"
|
|
8
|
+
style={{ '--swatch': `var(--feitio-color-${role})` } as CSSProperties}
|
|
9
|
+
/>
|
|
10
|
+
);
|
|
11
|
+
}
|
package/src/Switch.tsx
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { usePageBehavior } from './actions/use-page-behavior.ts';
|
|
3
|
+
import { wireForms } from './actions/wire.ts';
|
|
4
|
+
|
|
5
|
+
export interface SwitchProps {
|
|
6
|
+
label: string;
|
|
7
|
+
on?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
onLabel?: string;
|
|
10
|
+
offLabel?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
onChange?: (on: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Switch: a setting that takes effect at once, its state said in words. */
|
|
16
|
+
export function Switch({
|
|
17
|
+
label,
|
|
18
|
+
on = false,
|
|
19
|
+
disabled,
|
|
20
|
+
onLabel = 'Ligado',
|
|
21
|
+
offLabel = 'Desligado',
|
|
22
|
+
name,
|
|
23
|
+
onChange,
|
|
24
|
+
}: SwitchProps): ReactElement {
|
|
25
|
+
usePageBehavior('feitioForms', wireForms);
|
|
26
|
+
return (
|
|
27
|
+
<label className="feitio-switch" data-on={onLabel} data-off={offLabel}>
|
|
28
|
+
<input
|
|
29
|
+
type="checkbox"
|
|
30
|
+
// biome-ignore lint/a11y/useAriaPropsForRole: a checkbox says whether it is checked by itself.
|
|
31
|
+
role="switch"
|
|
32
|
+
name={name}
|
|
33
|
+
defaultChecked={on}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
onChange={onChange && ((event) => onChange(event.target.checked))}
|
|
36
|
+
/>
|
|
37
|
+
{label}
|
|
38
|
+
<span className="state">{on ? onLabel : offLabel}</span>
|
|
39
|
+
</label>
|
|
40
|
+
);
|
|
41
|
+
}
|
package/src/Table.tsx
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TableColumn {
|
|
4
|
+
label: string;
|
|
5
|
+
align?: 'end';
|
|
6
|
+
/** The column's name is only heard (like the actions column). */
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface TableProps {
|
|
11
|
+
id: string;
|
|
12
|
+
caption?: string;
|
|
13
|
+
columns: TableColumn[];
|
|
14
|
+
/** Each row: one cell per column (text, or a Tag, a link, a button). */
|
|
15
|
+
rows: ReactNode[][];
|
|
16
|
+
/** The first column is the row's title on a phone card. */
|
|
17
|
+
compact?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Table: rows to compare; on a phone, each row becomes a card. */
|
|
21
|
+
export function Table({ id, caption, columns, rows, compact }: TableProps): ReactElement {
|
|
22
|
+
const cap = `${id}-cap`;
|
|
23
|
+
return (
|
|
24
|
+
<div data-density={compact ? 'compact' : undefined} style={{ inlineSize: '100%' }}>
|
|
25
|
+
{/* biome-ignore lint/a11y/useSemanticElements: the same HTML as the Astro Table. */}
|
|
26
|
+
<div
|
|
27
|
+
className="feitio-table-scroll"
|
|
28
|
+
// biome-ignore lint/a11y/noNoninteractiveTabindex: a table that scrolls sideways must be reachable by keyboard.
|
|
29
|
+
tabIndex={0}
|
|
30
|
+
role="region"
|
|
31
|
+
aria-labelledby={caption ? cap : undefined}
|
|
32
|
+
aria-label={caption ? undefined : columns[0]?.label}
|
|
33
|
+
>
|
|
34
|
+
<table className="feitio-table">
|
|
35
|
+
{caption && <caption id={cap}>{caption}</caption>}
|
|
36
|
+
<thead>
|
|
37
|
+
<tr>
|
|
38
|
+
{columns.map((c) => (
|
|
39
|
+
<th scope="col" data-align={c.align} key={c.label}>
|
|
40
|
+
{c.hidden ? <span className="feitio-visually-hidden">{c.label}</span> : c.label}
|
|
41
|
+
</th>
|
|
42
|
+
))}
|
|
43
|
+
</tr>
|
|
44
|
+
</thead>
|
|
45
|
+
<tbody>
|
|
46
|
+
{rows.map((r, n) => (
|
|
47
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: rows have no id of their own.
|
|
48
|
+
<tr key={n}>
|
|
49
|
+
{r.map((cell, i) =>
|
|
50
|
+
i === 0 ? (
|
|
51
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: one cell per column, in order.
|
|
52
|
+
<td className="title" key={i}>
|
|
53
|
+
{cell}
|
|
54
|
+
</td>
|
|
55
|
+
) : columns[i]?.hidden ? (
|
|
56
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: one cell per column, in order.
|
|
57
|
+
<td className="actions" key={i}>
|
|
58
|
+
{cell}
|
|
59
|
+
</td>
|
|
60
|
+
) : (
|
|
61
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: one cell per column, in order.
|
|
62
|
+
<td data-align={columns[i]?.align} data-label={columns[i]?.label} key={i}>
|
|
63
|
+
{cell}
|
|
64
|
+
</td>
|
|
65
|
+
),
|
|
66
|
+
)}
|
|
67
|
+
</tr>
|
|
68
|
+
))}
|
|
69
|
+
</tbody>
|
|
70
|
+
</table>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
package/src/Tag.tsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
const icons = { ok: 'check', warn: 'warn', error: 'close', info: 'info' } as const;
|
|
5
|
+
|
|
6
|
+
export interface TagProps {
|
|
7
|
+
status?: 'ok' | 'warn' | 'error';
|
|
8
|
+
size?: 'small';
|
|
9
|
+
sprite?: string;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Tag: a short word about a state, with its icon, never color alone. */
|
|
14
|
+
export function Tag({ status, size, sprite, children }: TagProps): ReactElement {
|
|
15
|
+
return (
|
|
16
|
+
<span className="feitio-tag" data-status={status} data-size={size}>
|
|
17
|
+
{size !== 'small' && <Icon name={icons[status ?? 'info']} sprite={sprite} />}
|
|
18
|
+
{children}
|
|
19
|
+
</span>
|
|
20
|
+
);
|
|
21
|
+
}
|
package/src/TaskList.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { Tag } from './Tag.tsx';
|
|
3
|
+
|
|
4
|
+
export interface TaskListProps {
|
|
5
|
+
items: {
|
|
6
|
+
name: string;
|
|
7
|
+
href: string;
|
|
8
|
+
detail?: string;
|
|
9
|
+
status?: 'ok' | 'warn' | 'error';
|
|
10
|
+
word: string;
|
|
11
|
+
}[];
|
|
12
|
+
sprite?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** TaskList: the steps of a long job, each with its state in a Tag. */
|
|
16
|
+
export function TaskList({ items, sprite }: TaskListProps): ReactElement {
|
|
17
|
+
return (
|
|
18
|
+
<ul className="feitio-task-list">
|
|
19
|
+
{items.map((i) => (
|
|
20
|
+
<li key={i.href}>
|
|
21
|
+
<span className="name">
|
|
22
|
+
<a className="feitio-link" href={i.href}>
|
|
23
|
+
{i.name}
|
|
24
|
+
</a>
|
|
25
|
+
{i.detail && <small>{i.detail}</small>}
|
|
26
|
+
</span>
|
|
27
|
+
<Tag status={i.status} sprite={sprite}>
|
|
28
|
+
{i.word}
|
|
29
|
+
</Tag>
|
|
30
|
+
</li>
|
|
31
|
+
))}
|
|
32
|
+
</ul>
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/Text.tsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, ReactElement } from 'react';
|
|
2
|
+
import { classNames } from './calculations/text.ts';
|
|
3
|
+
|
|
4
|
+
export interface TextInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'width'> {
|
|
5
|
+
id: string;
|
|
6
|
+
invalid?: boolean;
|
|
7
|
+
describedBy?: string;
|
|
8
|
+
/** The width it is meant for, in characters: 2, 4, 10, 20 or 40. Without it, the whole line. */
|
|
9
|
+
width?: 2 | 4 | 10 | 20 | 40;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** TextInput: one line of text, as wide as what it is meant to hold. */
|
|
13
|
+
export function TextInput({
|
|
14
|
+
invalid,
|
|
15
|
+
describedBy,
|
|
16
|
+
width,
|
|
17
|
+
className,
|
|
18
|
+
...rest
|
|
19
|
+
}: TextInputProps): ReactElement {
|
|
20
|
+
return (
|
|
21
|
+
<input
|
|
22
|
+
{...rest}
|
|
23
|
+
className={classNames('feitio-input', className)}
|
|
24
|
+
aria-invalid={invalid ? 'true' : undefined}
|
|
25
|
+
aria-describedby={describedBy}
|
|
26
|
+
data-width={width}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
package/src/Textarea.tsx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReactElement, TextareaHTMLAttributes } from 'react';
|
|
2
|
+
import { classNames } from './calculations/text.ts';
|
|
3
|
+
|
|
4
|
+
export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
5
|
+
id: string;
|
|
6
|
+
invalid?: boolean;
|
|
7
|
+
describedBy?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Textarea: longer text, over several lines. */
|
|
11
|
+
export function Textarea({
|
|
12
|
+
invalid,
|
|
13
|
+
describedBy,
|
|
14
|
+
className,
|
|
15
|
+
...rest
|
|
16
|
+
}: TextareaProps): ReactElement {
|
|
17
|
+
return (
|
|
18
|
+
<textarea
|
|
19
|
+
{...rest}
|
|
20
|
+
className={classNames('feitio-textarea', className)}
|
|
21
|
+
aria-invalid={invalid ? 'true' : undefined}
|
|
22
|
+
aria-describedby={describedBy}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|