@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,27 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface ErrorSummaryProps {
|
|
5
|
+
title: string;
|
|
6
|
+
errors: { text: string; href: string }[];
|
|
7
|
+
sprite?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** ErrorSummary: every error of a form at the top, each one a link to its field. */
|
|
11
|
+
export function ErrorSummary({ title, errors, sprite }: ErrorSummaryProps): ReactElement {
|
|
12
|
+
return (
|
|
13
|
+
<div className="feitio-error-summary" role="alert" tabIndex={-1}>
|
|
14
|
+
<h3>
|
|
15
|
+
<Icon name="close" sprite={sprite} />
|
|
16
|
+
{title}
|
|
17
|
+
</h3>
|
|
18
|
+
<ul>
|
|
19
|
+
{errors.map((e) => (
|
|
20
|
+
<li key={e.href}>
|
|
21
|
+
<a href={e.href}>{e.text}</a>
|
|
22
|
+
</li>
|
|
23
|
+
))}
|
|
24
|
+
</ul>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
package/src/Example.tsx
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { CodeBlock } from './CodeBlock.tsx';
|
|
3
|
+
import { Icon } from './Icon.tsx';
|
|
4
|
+
|
|
5
|
+
export interface ExampleProps {
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
code: string;
|
|
10
|
+
showLabel?: string;
|
|
11
|
+
copyLabel?: string;
|
|
12
|
+
copiedLabel?: string;
|
|
13
|
+
sprite?: string;
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Example: a live piece of interface, what it is for, and its code behind a Details. */
|
|
18
|
+
export function Example({
|
|
19
|
+
id,
|
|
20
|
+
title,
|
|
21
|
+
description,
|
|
22
|
+
code,
|
|
23
|
+
showLabel = 'Mostrar código',
|
|
24
|
+
copyLabel,
|
|
25
|
+
copiedLabel,
|
|
26
|
+
sprite,
|
|
27
|
+
children,
|
|
28
|
+
}: ExampleProps): ReactElement {
|
|
29
|
+
return (
|
|
30
|
+
<div className="feitio-example">
|
|
31
|
+
<div className="live">{children}</div>
|
|
32
|
+
<div className="about">
|
|
33
|
+
<h3 id={id}>{title}</h3>
|
|
34
|
+
<p>{description}</p>
|
|
35
|
+
<details>
|
|
36
|
+
<summary>
|
|
37
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
38
|
+
{showLabel}
|
|
39
|
+
</summary>
|
|
40
|
+
<CodeBlock code={code} copyLabel={copyLabel} copiedLabel={copiedLabel} />
|
|
41
|
+
</details>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { SpriteContext } from './data/sprite.ts';
|
|
3
|
+
|
|
4
|
+
export interface FeitioProviderProps {
|
|
5
|
+
/** Where the icon sprite is served, for every icon inside. */
|
|
6
|
+
sprite?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Settings for every Feitio component inside it; today, where the icon sprite lives. */
|
|
11
|
+
export function FeitioProvider({ sprite, children }: FeitioProviderProps): ReactElement {
|
|
12
|
+
return <SpriteContext value={sprite}>{children}</SpriteContext>;
|
|
13
|
+
}
|
package/src/Field.tsx
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface FieldProps {
|
|
5
|
+
label: string;
|
|
6
|
+
/** The id of the control inside; the hint and the error take ids from it. */
|
|
7
|
+
for: string;
|
|
8
|
+
hint?: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
sprite?: string;
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Field: a label, an optional hint, the control and its error, in that order. The hint is
|
|
16
|
+
* "{for}-hint" and the error "{for}-error", for the control's aria-describedby.
|
|
17
|
+
*/
|
|
18
|
+
export function Field({
|
|
19
|
+
label,
|
|
20
|
+
for: target,
|
|
21
|
+
hint,
|
|
22
|
+
error,
|
|
23
|
+
sprite,
|
|
24
|
+
children,
|
|
25
|
+
}: FieldProps): ReactElement {
|
|
26
|
+
return (
|
|
27
|
+
<div className="feitio-field">
|
|
28
|
+
<label className="feitio-label" htmlFor={target}>
|
|
29
|
+
{label}
|
|
30
|
+
</label>
|
|
31
|
+
{hint && (
|
|
32
|
+
<span className="feitio-hint" id={`${target}-hint`}>
|
|
33
|
+
{hint}
|
|
34
|
+
</span>
|
|
35
|
+
)}
|
|
36
|
+
{children}
|
|
37
|
+
{error && (
|
|
38
|
+
<span className="feitio-error-message" id={`${target}-error`}>
|
|
39
|
+
<Icon name="close" sprite={sprite} />
|
|
40
|
+
{error}
|
|
41
|
+
</span>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
package/src/Fieldset.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface FieldsetProps {
|
|
4
|
+
legend: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Fieldset: controls that answer one question together, under its legend. */
|
|
10
|
+
export function Fieldset({ legend, hint, children }: FieldsetProps): ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<fieldset className="feitio-fieldset">
|
|
13
|
+
<legend className="feitio-label">{legend}</legend>
|
|
14
|
+
{hint && <span className="feitio-hint">{hint}</span>}
|
|
15
|
+
{children}
|
|
16
|
+
</fieldset>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 FilterFieldProps {
|
|
6
|
+
id: string;
|
|
7
|
+
/** The id of the list it filters; each item carries data-search. */
|
|
8
|
+
list: string;
|
|
9
|
+
label: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
/** Milliseconds to wait for the typing to stop before filtering. */
|
|
12
|
+
debounce?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The search runs elsewhere: the field sends a feitio-filter event with the query and a done() to
|
|
15
|
+
* call when the results are in, and shows it is busy meanwhile.
|
|
16
|
+
*/
|
|
17
|
+
async?: boolean;
|
|
18
|
+
/** What the count says while an asynchronous search runs. */
|
|
19
|
+
busyLabel?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** FilterField: narrows a list as you type, and says how many are left. */
|
|
23
|
+
export function FilterField({
|
|
24
|
+
id,
|
|
25
|
+
list,
|
|
26
|
+
label,
|
|
27
|
+
placeholder,
|
|
28
|
+
debounce,
|
|
29
|
+
async: isAsync,
|
|
30
|
+
busyLabel = 'Buscando…',
|
|
31
|
+
}: FilterFieldProps): ReactElement {
|
|
32
|
+
usePageBehavior('feitioForms', wireForms);
|
|
33
|
+
return (
|
|
34
|
+
<div className="feitio-filter">
|
|
35
|
+
<label className="feitio-visually-hidden" htmlFor={id}>
|
|
36
|
+
{label}
|
|
37
|
+
</label>
|
|
38
|
+
<span className="box">
|
|
39
|
+
<input
|
|
40
|
+
className="feitio-input"
|
|
41
|
+
id={id}
|
|
42
|
+
type="search"
|
|
43
|
+
autoComplete="off"
|
|
44
|
+
placeholder={placeholder}
|
|
45
|
+
data-filter={list}
|
|
46
|
+
data-debounce={debounce}
|
|
47
|
+
data-async={isAsync ? '' : undefined}
|
|
48
|
+
data-busy-label={isAsync ? busyLabel : undefined}
|
|
49
|
+
/>
|
|
50
|
+
<span className="wait" aria-hidden="true" />
|
|
51
|
+
<svg className="busy" viewBox="0 0 24 24" aria-hidden="true">
|
|
52
|
+
<path
|
|
53
|
+
pathLength={1}
|
|
54
|
+
d="M12 3.4C16.9 3.2 20.7 7.1 20.6 12C20.5 16.7 16.7 20.6 12 20.6C7.2 20.6 3.4 16.8 3.4 12.1C3.4 7.6 6.9 3.9 11.4 3.5"
|
|
55
|
+
/>
|
|
56
|
+
</svg>
|
|
57
|
+
</span>
|
|
58
|
+
<span className="count" data-count={list} aria-live="polite" />
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
package/src/Footer.tsx
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { yearsText } from './calculations/text.ts';
|
|
3
|
+
|
|
4
|
+
export interface FooterProps {
|
|
5
|
+
name: string;
|
|
6
|
+
since: number;
|
|
7
|
+
links: { text: string; href: string }[];
|
|
8
|
+
/** A short note, as HTML (it may hold a link). */
|
|
9
|
+
note?: string;
|
|
10
|
+
logo?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Footer: who made it, since when, and the links that go at the end of every page. */
|
|
14
|
+
export function Footer({ name, since, links, note, logo }: FooterProps): ReactElement {
|
|
15
|
+
return (
|
|
16
|
+
<footer className="feitio-footer">
|
|
17
|
+
<div className="inner">
|
|
18
|
+
<span className="who">
|
|
19
|
+
{logo}
|
|
20
|
+
<strong>{name}</strong>
|
|
21
|
+
<span>
|
|
22
|
+
© <span data-since={since}>{yearsText(since, new Date().getFullYear())}</span>
|
|
23
|
+
</span>
|
|
24
|
+
</span>
|
|
25
|
+
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: the note is the page author's own HTML. */}
|
|
26
|
+
{note && <span dangerouslySetInnerHTML={{ __html: note }} />}
|
|
27
|
+
<ul>
|
|
28
|
+
{links.map((l) => (
|
|
29
|
+
<li key={l.href}>
|
|
30
|
+
<a href={l.href}>{l.text}</a>
|
|
31
|
+
</li>
|
|
32
|
+
))}
|
|
33
|
+
</ul>
|
|
34
|
+
</div>
|
|
35
|
+
</footer>
|
|
36
|
+
);
|
|
37
|
+
}
|
package/src/Grid.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface GridProps {
|
|
4
|
+
gap?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
5
|
+
/** The narrowest a column may get, like "9rem". */
|
|
6
|
+
min?: string;
|
|
7
|
+
as?: 'div' | 'ul';
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Grid: columns that fit the width; below their narrowest, they wrap. */
|
|
12
|
+
export function Grid({ gap = 4, min, as: Tag = 'div', children }: GridProps): ReactElement {
|
|
13
|
+
const style = min ? ({ '--feitio-grid-min': min } as CSSProperties) : undefined;
|
|
14
|
+
return (
|
|
15
|
+
<Tag className="feitio-grid" data-gap={gap} style={style}>
|
|
16
|
+
{children}
|
|
17
|
+
</Tag>
|
|
18
|
+
);
|
|
19
|
+
}
|
package/src/Header.tsx
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface HeaderProps {
|
|
5
|
+
brand: string;
|
|
6
|
+
brandHref: string;
|
|
7
|
+
areas: { text: string; href: string; current?: boolean }[];
|
|
8
|
+
label?: string;
|
|
9
|
+
/** The Menu button's words and the id of the Drawer it opens; without it, no Menu. */
|
|
10
|
+
menu?: { label: string; target: string };
|
|
11
|
+
sprite?: string;
|
|
12
|
+
logo?: ReactNode;
|
|
13
|
+
/** Tools on the right, like search or the language. */
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Header: the brand, the areas of the site and its tools; on a narrow screen, a Menu for a Drawer. */
|
|
18
|
+
export function Header({
|
|
19
|
+
brand,
|
|
20
|
+
brandHref,
|
|
21
|
+
areas,
|
|
22
|
+
label,
|
|
23
|
+
menu,
|
|
24
|
+
sprite,
|
|
25
|
+
logo,
|
|
26
|
+
children,
|
|
27
|
+
}: HeaderProps): ReactElement {
|
|
28
|
+
return (
|
|
29
|
+
<div className="feitio-header-wrap">
|
|
30
|
+
<header className="feitio-header">
|
|
31
|
+
<a className="brand" href={brandHref}>
|
|
32
|
+
{logo}
|
|
33
|
+
{brand}
|
|
34
|
+
</a>
|
|
35
|
+
<nav className="areas" aria-label={label}>
|
|
36
|
+
{areas.map((a) => (
|
|
37
|
+
<a key={a.href} href={a.href} aria-current={a.current ? 'true' : undefined}>
|
|
38
|
+
{a.text}
|
|
39
|
+
</a>
|
|
40
|
+
))}
|
|
41
|
+
</nav>
|
|
42
|
+
<div className="tools">
|
|
43
|
+
{children}
|
|
44
|
+
{menu && (
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
className="feitio-button menu"
|
|
48
|
+
data-size="small"
|
|
49
|
+
popoverTarget={menu.target}
|
|
50
|
+
aria-controls={menu.target}
|
|
51
|
+
>
|
|
52
|
+
{menu.label}
|
|
53
|
+
<Icon name="menu" sprite={sprite} />
|
|
54
|
+
</button>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
</header>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
package/src/Heading.tsx
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface HeadingProps {
|
|
4
|
+
level?: 1 | 2 | 3 | 4;
|
|
5
|
+
id?: string;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Heading: a title at one of the four levels of the scale. */
|
|
10
|
+
export function Heading({ level = 2, id, children }: HeadingProps): ReactElement {
|
|
11
|
+
const Tag = `h${level}` as 'h1' | 'h2' | 'h3' | 'h4';
|
|
12
|
+
return <Tag id={id}>{children}</Tag>;
|
|
13
|
+
}
|
package/src/Hint.tsx
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface HintProps {
|
|
4
|
+
id?: string;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Hint: a short help under a label; the control points to it with aria-describedby. */
|
|
9
|
+
export function Hint({ id, children }: HintProps): ReactElement {
|
|
10
|
+
return (
|
|
11
|
+
<span className="feitio-hint" id={id}>
|
|
12
|
+
{children}
|
|
13
|
+
</span>
|
|
14
|
+
);
|
|
15
|
+
}
|
package/src/Icon.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { useSprite } from './actions/use-sprite.ts';
|
|
3
|
+
|
|
4
|
+
export interface IconProps {
|
|
5
|
+
/** The icon's name in the sprite, like "check" or "search". */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Where the sprite is served; without it, the FeitioProvider's, else /feitio/icons/sprite.svg. */
|
|
8
|
+
sprite?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** A hand-drawn icon from the sprite. Decorative: the words beside it say what it means. */
|
|
12
|
+
export function Icon({ name, sprite }: IconProps): ReactElement {
|
|
13
|
+
const href = useSprite(sprite);
|
|
14
|
+
return (
|
|
15
|
+
<svg className="feitio-icon" aria-hidden="true">
|
|
16
|
+
<use href={`${href}#feitio-${name}`} />
|
|
17
|
+
</svg>
|
|
18
|
+
);
|
|
19
|
+
}
|
package/src/Inline.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface InlineProps {
|
|
4
|
+
gap?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
5
|
+
justify?: 'between' | 'end';
|
|
6
|
+
as?: 'div' | 'ul';
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Inline: pieces side by side, wrapping when they do not fit, one step of the scale apart. */
|
|
11
|
+
export function Inline({ gap = 3, justify, as: Tag = 'div', children }: InlineProps): ReactElement {
|
|
12
|
+
return (
|
|
13
|
+
<Tag className="feitio-inline" data-gap={gap} data-justify={justify}>
|
|
14
|
+
{children}
|
|
15
|
+
</Tag>
|
|
16
|
+
);
|
|
17
|
+
}
|
package/src/Kbd.tsx
ADDED
package/src/Label.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface LabelProps {
|
|
4
|
+
/** The control's id. */
|
|
5
|
+
htmlFor: string;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Label: a control's name, tied to it by htmlFor (the control's id). */
|
|
10
|
+
export function Label({ htmlFor, children }: LabelProps): ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<label className="feitio-label" htmlFor={htmlFor}>
|
|
13
|
+
{children}
|
|
14
|
+
</label>
|
|
15
|
+
);
|
|
16
|
+
}
|
package/src/Link.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface LinkProps {
|
|
5
|
+
href: string;
|
|
6
|
+
newTab?: boolean;
|
|
7
|
+
/** What screen readers hear after the text when it opens in a new tab. */
|
|
8
|
+
newTabLabel?: string;
|
|
9
|
+
sprite?: string;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Link: goes somewhere; opening in a new tab, it says so, to the eye and to the ear. */
|
|
14
|
+
export function Link({
|
|
15
|
+
href,
|
|
16
|
+
newTab = false,
|
|
17
|
+
newTabLabel = '(abre em nova aba)',
|
|
18
|
+
sprite,
|
|
19
|
+
children,
|
|
20
|
+
}: LinkProps): ReactElement {
|
|
21
|
+
return (
|
|
22
|
+
<a
|
|
23
|
+
className="feitio-link"
|
|
24
|
+
href={href}
|
|
25
|
+
target={newTab ? '_blank' : undefined}
|
|
26
|
+
rel={newTab ? 'noopener' : undefined}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
{newTab && <Icon name="new-tab" sprite={sprite} />}
|
|
30
|
+
{newTab && <span className="feitio-visually-hidden"> {newTabLabel}</span>}
|
|
31
|
+
</a>
|
|
32
|
+
);
|
|
33
|
+
}
|
package/src/LinkCard.tsx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface LinkCardProps {
|
|
5
|
+
href: string;
|
|
6
|
+
title: string;
|
|
7
|
+
sprite?: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** LinkCard: a whole card that is one link, its title and a line about where it goes. */
|
|
12
|
+
export function LinkCard({ href, title, sprite, children }: LinkCardProps): ReactElement {
|
|
13
|
+
return (
|
|
14
|
+
<a className="feitio-link-card" href={href}>
|
|
15
|
+
<strong>
|
|
16
|
+
{title}
|
|
17
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
18
|
+
</strong>
|
|
19
|
+
<span>{children}</span>
|
|
20
|
+
</a>
|
|
21
|
+
);
|
|
22
|
+
}
|
package/src/Menu.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ReactElement, useRef } from 'react';
|
|
2
|
+
import { useElementBehavior } from './actions/use-element-behavior.ts';
|
|
3
|
+
import { wireMenu } from './actions/wire.ts';
|
|
4
|
+
import { Icon } from './Icon.tsx';
|
|
5
|
+
|
|
6
|
+
export interface MenuItem {
|
|
7
|
+
text: string;
|
|
8
|
+
href?: string;
|
|
9
|
+
current?: boolean;
|
|
10
|
+
lang?: string;
|
|
11
|
+
hreflang?: string;
|
|
12
|
+
/** For an item without href: what it does. */
|
|
13
|
+
onSelect?: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MenuProps {
|
|
17
|
+
/** What the button says: the current choice, or what the menu is for. */
|
|
18
|
+
label: string;
|
|
19
|
+
/**
|
|
20
|
+
* Words screen readers hear after the label, when it is short ("PT" + ", idioma: Português"). They
|
|
21
|
+
* come after the visible text, never instead of it, so a voice command can still say "PT".
|
|
22
|
+
*/
|
|
23
|
+
hint?: string;
|
|
24
|
+
items: MenuItem[];
|
|
25
|
+
id: string;
|
|
26
|
+
size?: 'small';
|
|
27
|
+
sprite?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Menu: a button that opens a short list of links or actions, moved through with the arrows. */
|
|
31
|
+
export function Menu({ label, hint, items, id, size, sprite }: MenuProps): ReactElement {
|
|
32
|
+
const ref = useRef<HTMLSpanElement>(null);
|
|
33
|
+
useElementBehavior(ref, 'menu', wireMenu);
|
|
34
|
+
return (
|
|
35
|
+
<span className="feitio-menu" ref={ref}>
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
className="feitio-button"
|
|
39
|
+
data-size={size}
|
|
40
|
+
popoverTarget={`${id}-list`}
|
|
41
|
+
aria-haspopup="true"
|
|
42
|
+
aria-expanded="false"
|
|
43
|
+
>
|
|
44
|
+
{label}
|
|
45
|
+
{hint && <span className="feitio-visually-hidden">{hint}</span>}
|
|
46
|
+
<Icon name="chevron-down" sprite={sprite} />
|
|
47
|
+
</button>
|
|
48
|
+
<ul className="feitio-menu-list" id={`${id}-list`} popover="">
|
|
49
|
+
{items.map((item) =>
|
|
50
|
+
item.href ? (
|
|
51
|
+
<li key={item.text}>
|
|
52
|
+
<a
|
|
53
|
+
href={item.href}
|
|
54
|
+
lang={item.lang}
|
|
55
|
+
hrefLang={item.hreflang}
|
|
56
|
+
aria-current={item.current ? 'true' : undefined}
|
|
57
|
+
>
|
|
58
|
+
{item.current && <Icon name="check" sprite={sprite} />}
|
|
59
|
+
<span>{item.text}</span>
|
|
60
|
+
</a>
|
|
61
|
+
</li>
|
|
62
|
+
) : (
|
|
63
|
+
<li key={item.text}>
|
|
64
|
+
<button type="button" onClick={item.onSelect}>
|
|
65
|
+
{item.text}
|
|
66
|
+
</button>
|
|
67
|
+
</li>
|
|
68
|
+
),
|
|
69
|
+
)}
|
|
70
|
+
</ul>
|
|
71
|
+
</span>
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/Nav.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface NavGroup {
|
|
5
|
+
title?: string;
|
|
6
|
+
items: { text: string; href: string; current?: boolean; icon?: string }[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface NavProps {
|
|
10
|
+
groups: NavGroup[];
|
|
11
|
+
label?: string;
|
|
12
|
+
sprite?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Nav: the side navigation of a product, in groups, the current page marked. */
|
|
16
|
+
export function Nav({ groups, label, sprite }: NavProps): ReactElement {
|
|
17
|
+
return (
|
|
18
|
+
<nav className="feitio-nav" aria-label={label}>
|
|
19
|
+
{groups.map((g, n) => (
|
|
20
|
+
<div className="group" key={g.title ?? n}>
|
|
21
|
+
{g.title && <p className="group-title">{g.title}</p>}
|
|
22
|
+
<ul>
|
|
23
|
+
{g.items.map((i) => (
|
|
24
|
+
<li key={i.href}>
|
|
25
|
+
<a href={i.href} aria-current={i.current ? 'page' : undefined}>
|
|
26
|
+
{i.icon && <Icon name={i.icon} sprite={sprite} />}
|
|
27
|
+
{i.text}
|
|
28
|
+
</a>
|
|
29
|
+
</li>
|
|
30
|
+
))}
|
|
31
|
+
</ul>
|
|
32
|
+
</div>
|
|
33
|
+
))}
|
|
34
|
+
</nav>
|
|
35
|
+
);
|
|
36
|
+
}
|
package/src/Notice.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, type Ref, useImperativeHandle, useRef } from 'react';
|
|
2
|
+
import { useElementBehavior } from './actions/use-element-behavior.ts';
|
|
3
|
+
import { wireNotice } from './actions/wire.ts';
|
|
4
|
+
import { Icon } from './Icon.tsx';
|
|
5
|
+
|
|
6
|
+
const icons = { ok: 'check', warn: 'warn', error: 'close', info: 'info' } as const;
|
|
7
|
+
const ring =
|
|
8
|
+
'M12 3.2C17.2 3 21 7 20.8 12.2C20.6 17.2 16.8 20.9 11.8 20.8C6.9 20.7 3.1 16.8 3.2 11.8C3.3 7 6.9 3.4 12.6 3.5';
|
|
9
|
+
|
|
10
|
+
export interface NoticeProps {
|
|
11
|
+
status?: 'ok' | 'warn' | 'error';
|
|
12
|
+
title: string;
|
|
13
|
+
close?: boolean;
|
|
14
|
+
/** Milliseconds until it closes by itself (never for a warning or an error). */
|
|
15
|
+
timeout?: number;
|
|
16
|
+
id?: string;
|
|
17
|
+
hidden?: boolean;
|
|
18
|
+
/** "status" after an action, "alert" for an error after an action. */
|
|
19
|
+
role?: 'status' | 'alert';
|
|
20
|
+
closeLabel?: string;
|
|
21
|
+
sprite?: string;
|
|
22
|
+
/** The element, for useNotices().show() and close(). */
|
|
23
|
+
ref?: Ref<HTMLDivElement | null>;
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Notice: a message about the page or about what just happened; it may close, or close by itself. */
|
|
28
|
+
export function Notice({
|
|
29
|
+
status,
|
|
30
|
+
title,
|
|
31
|
+
close = false,
|
|
32
|
+
timeout,
|
|
33
|
+
id,
|
|
34
|
+
hidden,
|
|
35
|
+
role,
|
|
36
|
+
closeLabel = 'Fechar o aviso',
|
|
37
|
+
sprite,
|
|
38
|
+
ref,
|
|
39
|
+
children,
|
|
40
|
+
}: NoticeProps): ReactElement {
|
|
41
|
+
const own = useRef<HTMLDivElement>(null);
|
|
42
|
+
useImperativeHandle(ref, () => own.current as HTMLDivElement, []);
|
|
43
|
+
useElementBehavior(own, 'notice', wireNotice);
|
|
44
|
+
const hasTools = close || Boolean(timeout);
|
|
45
|
+
const text = children !== undefined && children !== null && children !== false;
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
className="feitio-notice"
|
|
49
|
+
data-status={status}
|
|
50
|
+
id={id}
|
|
51
|
+
role={role}
|
|
52
|
+
data-timeout={timeout}
|
|
53
|
+
hidden={hidden}
|
|
54
|
+
ref={own}
|
|
55
|
+
>
|
|
56
|
+
<Icon name={icons[status ?? 'info']} sprite={sprite} />
|
|
57
|
+
<strong>{title}</strong>
|
|
58
|
+
{text && <p>{children}</p>}
|
|
59
|
+
{hasTools && (
|
|
60
|
+
<span className="tools">
|
|
61
|
+
<button type="button" className="close" aria-label={closeLabel}>
|
|
62
|
+
{Boolean(timeout) && (
|
|
63
|
+
<svg className="ring" viewBox="0 0 24 24" aria-hidden="true">
|
|
64
|
+
<path pathLength={100} d={ring} />
|
|
65
|
+
</svg>
|
|
66
|
+
)}
|
|
67
|
+
<Icon name="close" sprite={sprite} />
|
|
68
|
+
</button>
|
|
69
|
+
</span>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|