@feitio/react 0.0.0-stage → 0.1.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
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feitio/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Feitio's components for React: the same HTML as the Astro components, with the behaviors wired by hooks.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"feitio",
|
|
7
|
+
"design-system",
|
|
8
|
+
"accessibility",
|
|
9
|
+
"a11y",
|
|
10
|
+
"handmade",
|
|
11
|
+
"react",
|
|
12
|
+
"react-components",
|
|
13
|
+
"components",
|
|
14
|
+
"ui"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://made-by-maid.github.io/feitio/en/dev/react/",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Made-by-MAID/feitio/issues"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Made-by-MAID/feitio.git",
|
|
26
|
+
"directory": "packages/react"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"src",
|
|
31
|
+
"!src/**/*.spec.ts"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "rm -rf dist && NODE_ENV=production bun build src/index.ts --outdir dist --format esm --external react --external react/jsx-runtime && tsc -p tsconfig.build.json && bun scripts/fix-declarations.ts"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": ">=19"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@feitio/core": "0.1.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@feitio/vanilla": "0.1.0",
|
|
50
|
+
"@types/react": "19.3.0",
|
|
51
|
+
"@types/react-dom": "19.3.0",
|
|
52
|
+
"react": "19.3.1",
|
|
53
|
+
"react-dom": "19.3.1"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/Anchor.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface AnchorItem {
|
|
5
|
+
id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
current?: boolean;
|
|
8
|
+
children?: { id: string; text: string; current?: boolean }[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AnchorProps {
|
|
12
|
+
title?: string;
|
|
13
|
+
items: AnchorItem[];
|
|
14
|
+
label?: string;
|
|
15
|
+
sprite?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Anchor: the page index, following the scroll; the current part in ink, with the hand-drawn arrow. */
|
|
19
|
+
export function Anchor({ title, items, label, sprite }: AnchorProps): ReactElement {
|
|
20
|
+
return (
|
|
21
|
+
<nav className="feitio-anchor" aria-label={label ?? title}>
|
|
22
|
+
{title && <p className="title">{title}</p>}
|
|
23
|
+
<ul>
|
|
24
|
+
{items.map((t) => (
|
|
25
|
+
<li key={t.id}>
|
|
26
|
+
<a href={`#${t.id}`} aria-current={t.current ? 'location' : undefined}>
|
|
27
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
28
|
+
{t.text}
|
|
29
|
+
</a>
|
|
30
|
+
{t.children && (
|
|
31
|
+
<ul>
|
|
32
|
+
{t.children.map((c) => (
|
|
33
|
+
<li key={c.id}>
|
|
34
|
+
<a href={`#${c.id}`} aria-current={c.current ? 'location' : undefined}>
|
|
35
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
36
|
+
{c.text}
|
|
37
|
+
</a>
|
|
38
|
+
</li>
|
|
39
|
+
))}
|
|
40
|
+
</ul>
|
|
41
|
+
)}
|
|
42
|
+
</li>
|
|
43
|
+
))}
|
|
44
|
+
</ul>
|
|
45
|
+
</nav>
|
|
46
|
+
);
|
|
47
|
+
}
|
package/src/AppShell.tsx
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, useRef } from 'react';
|
|
2
|
+
import { useElementBehavior } from './actions/use-element-behavior.ts';
|
|
3
|
+
import { wireScroll } from './actions/wire.ts';
|
|
4
|
+
import { Icon } from './Icon.tsx';
|
|
5
|
+
import { Nav, type NavGroup } from './Nav.tsx';
|
|
6
|
+
|
|
7
|
+
export interface AppShellProps {
|
|
8
|
+
id: string;
|
|
9
|
+
brand: string;
|
|
10
|
+
nav: NavGroup[];
|
|
11
|
+
user?: string;
|
|
12
|
+
signOut?: { text: string; href: string };
|
|
13
|
+
menuLabel?: string;
|
|
14
|
+
closeLabel?: string;
|
|
15
|
+
topLabel?: string;
|
|
16
|
+
sprite?: string;
|
|
17
|
+
/** The main area's content. */
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* AppShell: a product's layout of regions: the header (it leaves when scrolling down on mobile and
|
|
23
|
+
* comes back up), the navigation in a Drawer from the right, the main area with its ScrollFade and
|
|
24
|
+
* BackToTop.
|
|
25
|
+
*/
|
|
26
|
+
export function AppShell({
|
|
27
|
+
id,
|
|
28
|
+
brand,
|
|
29
|
+
nav,
|
|
30
|
+
user,
|
|
31
|
+
signOut,
|
|
32
|
+
menuLabel = 'Menu',
|
|
33
|
+
closeLabel = 'Fechar',
|
|
34
|
+
topLabel = 'Topo',
|
|
35
|
+
sprite,
|
|
36
|
+
children,
|
|
37
|
+
}: AppShellProps): ReactElement {
|
|
38
|
+
const fade = useRef<HTMLSpanElement>(null);
|
|
39
|
+
useElementBehavior(fade, 'scroll', wireScroll);
|
|
40
|
+
return (
|
|
41
|
+
<div className="feitio-app">
|
|
42
|
+
<header className="feitio-app-header" data-hide-on-scroll="">
|
|
43
|
+
<a className="brand" href={`#${id}-content`}>
|
|
44
|
+
{brand}
|
|
45
|
+
</a>
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
className="feitio-button menu"
|
|
49
|
+
data-size="small"
|
|
50
|
+
popoverTarget={id}
|
|
51
|
+
aria-controls={id}
|
|
52
|
+
>
|
|
53
|
+
{menuLabel}
|
|
54
|
+
<Icon name="menu" sprite={sprite} />
|
|
55
|
+
</button>
|
|
56
|
+
</header>
|
|
57
|
+
<nav className="feitio-drawer feitio-app-nav" id={id} popover="" aria-label={menuLabel}>
|
|
58
|
+
<div className="drawer-header">
|
|
59
|
+
<h2>{menuLabel}</h2>
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
className="feitio-button close"
|
|
63
|
+
data-size="small"
|
|
64
|
+
popoverTarget={id}
|
|
65
|
+
popoverTargetAction="hide"
|
|
66
|
+
>
|
|
67
|
+
<Icon name="close" sprite={sprite} />
|
|
68
|
+
{closeLabel}
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
<div className="drawer-body">
|
|
72
|
+
<Nav groups={nav} sprite={sprite} />
|
|
73
|
+
</div>
|
|
74
|
+
{(user || signOut) && (
|
|
75
|
+
<div className="drawer-footer nav-footer">
|
|
76
|
+
{user && <span className="who">{user}</span>}
|
|
77
|
+
{signOut && (
|
|
78
|
+
<a className="feitio-link" href={signOut.href}>
|
|
79
|
+
{signOut.text}
|
|
80
|
+
</a>
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
)}
|
|
84
|
+
</nav>
|
|
85
|
+
<div className="feitio-app-main" id={`${id}-content`} tabIndex={-1}>
|
|
86
|
+
{children}
|
|
87
|
+
<span className="feitio-scroll-fade" aria-hidden="true" ref={fade} />
|
|
88
|
+
<a className="feitio-button feitio-back-to-top" data-size="small" href={`#${id}-content`}>
|
|
89
|
+
<Icon name="chevron-down" sprite={sprite} />
|
|
90
|
+
{topLabel}
|
|
91
|
+
</a>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactElement, useRef } from 'react';
|
|
2
|
+
import { useElementBehavior } from './actions/use-element-behavior.ts';
|
|
3
|
+
import { wireScroll } from './actions/wire.ts';
|
|
4
|
+
import { Icon } from './Icon.tsx';
|
|
5
|
+
|
|
6
|
+
export interface BackToTopProps {
|
|
7
|
+
href?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
sprite?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** BackToTop: shows after half a screen of scrolling and takes the reader (and the focus) back up. */
|
|
13
|
+
export function BackToTop({
|
|
14
|
+
href = '#content',
|
|
15
|
+
label = 'Topo',
|
|
16
|
+
sprite,
|
|
17
|
+
}: BackToTopProps): ReactElement {
|
|
18
|
+
const ref = useRef<HTMLAnchorElement>(null);
|
|
19
|
+
useElementBehavior(ref, 'scroll', wireScroll);
|
|
20
|
+
return (
|
|
21
|
+
<a ref={ref} className="feitio-button feitio-back-to-top" data-size="small" href={href}>
|
|
22
|
+
<Icon name="chevron-down" sprite={sprite} />
|
|
23
|
+
{label}
|
|
24
|
+
</a>
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/Block.tsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface BlockProps {
|
|
4
|
+
as?: 'div' | 'section' | 'article';
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Block: a surface that groups related content, with the inner padding of the scale. */
|
|
9
|
+
export function Block({ as: Tag = 'div', children }: BlockProps): ReactElement {
|
|
10
|
+
return <Tag className="feitio-block">{children}</Tag>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface BreadcrumbsProps {
|
|
5
|
+
items: { text: string; href: string }[];
|
|
6
|
+
current: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
sprite?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Breadcrumbs: where the page sits, from the top down to here. */
|
|
12
|
+
export function Breadcrumbs({
|
|
13
|
+
items,
|
|
14
|
+
current,
|
|
15
|
+
label = 'Você está em',
|
|
16
|
+
sprite,
|
|
17
|
+
}: BreadcrumbsProps): ReactElement {
|
|
18
|
+
return (
|
|
19
|
+
<nav className="feitio-breadcrumbs" aria-label={label}>
|
|
20
|
+
<ol>
|
|
21
|
+
{items.map((i, n) => (
|
|
22
|
+
<li key={i.href}>
|
|
23
|
+
{n > 0 && (
|
|
24
|
+
<span className="sep" aria-hidden="true">
|
|
25
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
26
|
+
</span>
|
|
27
|
+
)}
|
|
28
|
+
<a href={i.href}>{i.text}</a>
|
|
29
|
+
</li>
|
|
30
|
+
))}
|
|
31
|
+
<li>
|
|
32
|
+
<span className="sep" aria-hidden="true">
|
|
33
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
34
|
+
</span>
|
|
35
|
+
<span aria-current="page">{current}</span>
|
|
36
|
+
</li>
|
|
37
|
+
</ol>
|
|
38
|
+
</nav>
|
|
39
|
+
);
|
|
40
|
+
}
|
package/src/Button.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactElement } from 'react';
|
|
2
|
+
import { classNames } from './calculations/text.ts';
|
|
3
|
+
|
|
4
|
+
interface Common {
|
|
5
|
+
/** primary is the screen's main action (orange, at most one); danger destroys something. */
|
|
6
|
+
variant?: 'primary' | 'danger';
|
|
7
|
+
size?: 'small' | 'large';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ButtonProps = Common &
|
|
11
|
+
(
|
|
12
|
+
| (Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & {
|
|
13
|
+
type?: 'button' | 'submit' | 'reset';
|
|
14
|
+
href?: undefined;
|
|
15
|
+
})
|
|
16
|
+
| (AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
17
|
+
/** Makes it a link that looks like a button. */
|
|
18
|
+
href: string;
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/** Button: an action. With href, a link that looks like one. */
|
|
23
|
+
export function Button(props: ButtonProps): ReactElement {
|
|
24
|
+
const { variant, size, className, children } = props;
|
|
25
|
+
const classes = classNames('feitio-button', className);
|
|
26
|
+
if (props.href !== undefined) {
|
|
27
|
+
const { variant: _v, size: _s, className: _c, children: _ch, ...rest } = props;
|
|
28
|
+
return (
|
|
29
|
+
<a {...rest} className={classes} data-variant={variant} data-size={size}>
|
|
30
|
+
{children}
|
|
31
|
+
</a>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const { variant: _v, size: _s, className: _c, children: _ch, type = 'button', ...rest } = props;
|
|
35
|
+
return (
|
|
36
|
+
<button {...rest} className={classes} type={type} data-variant={variant} data-size={size}>
|
|
37
|
+
{children}
|
|
38
|
+
</button>
|
|
39
|
+
);
|
|
40
|
+
}
|
package/src/Checkbox.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChangeEvent, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface CheckboxProps {
|
|
4
|
+
label: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
onChange?: (checked: boolean, event: ChangeEvent<HTMLInputElement>) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Checkbox: one choice that is on or off, its words beside it. */
|
|
13
|
+
export function Checkbox({
|
|
14
|
+
label,
|
|
15
|
+
name,
|
|
16
|
+
value,
|
|
17
|
+
checked,
|
|
18
|
+
disabled,
|
|
19
|
+
onChange,
|
|
20
|
+
}: CheckboxProps): ReactElement {
|
|
21
|
+
return (
|
|
22
|
+
<label className="feitio-choice">
|
|
23
|
+
<input
|
|
24
|
+
type="checkbox"
|
|
25
|
+
name={name}
|
|
26
|
+
value={value}
|
|
27
|
+
defaultChecked={checked}
|
|
28
|
+
disabled={disabled}
|
|
29
|
+
onChange={onChange && ((event) => onChange(event.target.checked, event))}
|
|
30
|
+
/>
|
|
31
|
+
{label}
|
|
32
|
+
</label>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface CodeBlockProps {
|
|
4
|
+
code: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
syntax?: 'html' | 'jsx' | 'shell';
|
|
7
|
+
copyLabel?: string;
|
|
8
|
+
copiedLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** CodeBlock: code to read and copy, with its language named on the bar. */
|
|
12
|
+
export function CodeBlock({
|
|
13
|
+
code,
|
|
14
|
+
label = 'HTML',
|
|
15
|
+
syntax = 'html',
|
|
16
|
+
copyLabel = 'Copiar',
|
|
17
|
+
copiedLabel = 'Copiado',
|
|
18
|
+
}: CodeBlockProps): ReactElement {
|
|
19
|
+
return (
|
|
20
|
+
<div className="feitio-code" data-lang={syntax}>
|
|
21
|
+
<div className="bar">
|
|
22
|
+
<span>{label}</span>
|
|
23
|
+
<button
|
|
24
|
+
type="button"
|
|
25
|
+
className="feitio-button copy"
|
|
26
|
+
data-size="small"
|
|
27
|
+
data-done-label={copiedLabel}
|
|
28
|
+
>
|
|
29
|
+
{copyLabel}
|
|
30
|
+
</button>
|
|
31
|
+
</div>
|
|
32
|
+
{/* biome-ignore lint/a11y/noNoninteractiveTabindex: a code block scrolls sideways, so the keyboard must reach it. */}
|
|
33
|
+
<pre tabIndex={0}>
|
|
34
|
+
<code>{code}</code>
|
|
35
|
+
</pre>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
package/src/Details.tsx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface DetailsProps {
|
|
5
|
+
summary: string;
|
|
6
|
+
open?: boolean;
|
|
7
|
+
sprite?: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Details: more about something, closed until the reader asks for it. */
|
|
12
|
+
export function Details({ summary, open, sprite, children }: DetailsProps): ReactElement {
|
|
13
|
+
return (
|
|
14
|
+
<details className="feitio-details" open={open}>
|
|
15
|
+
<summary>
|
|
16
|
+
<Icon name="chevron-right" sprite={sprite} />
|
|
17
|
+
{summary}
|
|
18
|
+
</summary>
|
|
19
|
+
<div className="content">{children}</div>
|
|
20
|
+
</details>
|
|
21
|
+
);
|
|
22
|
+
}
|
package/src/Dialog.tsx
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { usePageBehavior } from './actions/use-page-behavior.ts';
|
|
3
|
+
import { wireDialogs } from './actions/wire.ts';
|
|
4
|
+
|
|
5
|
+
export interface DialogProps {
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
action: string;
|
|
9
|
+
cancel?: string;
|
|
10
|
+
danger?: boolean;
|
|
11
|
+
/** For what deletes a lot at once: the word to type, and the field's label. */
|
|
12
|
+
confirmWord?: { word: string; label: string };
|
|
13
|
+
/** Called when it closes, with "yes" or "cancel". */
|
|
14
|
+
onClose?: (answer: string) => void;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Dialog: a question that stops everything until it is answered. A button with
|
|
20
|
+
* data-open-dialog="its id" opens it.
|
|
21
|
+
*/
|
|
22
|
+
export function Dialog({
|
|
23
|
+
id,
|
|
24
|
+
title,
|
|
25
|
+
action,
|
|
26
|
+
cancel = 'Cancelar',
|
|
27
|
+
danger = false,
|
|
28
|
+
confirmWord,
|
|
29
|
+
onClose,
|
|
30
|
+
children,
|
|
31
|
+
}: DialogProps): ReactElement {
|
|
32
|
+
usePageBehavior('feitioDialogs', wireDialogs);
|
|
33
|
+
return (
|
|
34
|
+
<dialog
|
|
35
|
+
className="feitio-dialog"
|
|
36
|
+
id={id}
|
|
37
|
+
aria-labelledby={`${id}-t`}
|
|
38
|
+
aria-describedby={`${id}-d`}
|
|
39
|
+
onClose={onClose && ((event) => onClose(event.currentTarget.returnValue))}
|
|
40
|
+
>
|
|
41
|
+
<form method="dialog" data-type-to-confirm={confirmWord?.word}>
|
|
42
|
+
<h2 id={`${id}-t`}>{title}</h2>
|
|
43
|
+
<div id={`${id}-d`}>{children}</div>
|
|
44
|
+
{confirmWord && (
|
|
45
|
+
<div className="feitio-field">
|
|
46
|
+
<label className="feitio-label" htmlFor={`${id}-word`}>
|
|
47
|
+
{confirmWord.label}
|
|
48
|
+
</label>
|
|
49
|
+
<input className="feitio-input" id={`${id}-word`} autoComplete="off" />
|
|
50
|
+
</div>
|
|
51
|
+
)}
|
|
52
|
+
<div className="actions">
|
|
53
|
+
<button
|
|
54
|
+
type="submit"
|
|
55
|
+
className="feitio-button"
|
|
56
|
+
data-variant={danger ? 'danger' : 'primary'}
|
|
57
|
+
value="yes"
|
|
58
|
+
disabled={Boolean(confirmWord)}
|
|
59
|
+
>
|
|
60
|
+
{action}
|
|
61
|
+
</button>
|
|
62
|
+
{/* biome-ignore lint/a11y/noAutofocus: a Dialog puts the focus on its safe answer. */}
|
|
63
|
+
<button type="submit" className="feitio-button" value="cancel" autoFocus={!confirmWord}>
|
|
64
|
+
{cancel}
|
|
65
|
+
</button>
|
|
66
|
+
</div>
|
|
67
|
+
</form>
|
|
68
|
+
</dialog>
|
|
69
|
+
);
|
|
70
|
+
}
|
package/src/Divider.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface DividerProps {
|
|
4
|
+
tone?: 'ink';
|
|
5
|
+
orientation?: 'horizontal' | 'vertical';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Divider: a hand-drawn line between two parts. */
|
|
9
|
+
export function Divider({ tone, orientation = 'horizontal' }: DividerProps): ReactElement {
|
|
10
|
+
return (
|
|
11
|
+
<hr
|
|
12
|
+
className="feitio-divider"
|
|
13
|
+
data-tone={tone}
|
|
14
|
+
aria-orientation={orientation === 'vertical' ? 'vertical' : undefined}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
package/src/DoDont.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface DoDontProps {
|
|
5
|
+
doWhy: string;
|
|
6
|
+
dontWhy: string;
|
|
7
|
+
doLabel?: string;
|
|
8
|
+
dontLabel?: string;
|
|
9
|
+
sprite?: string;
|
|
10
|
+
/** The right way. */
|
|
11
|
+
do?: ReactNode;
|
|
12
|
+
/** The wrong way. */
|
|
13
|
+
dont?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** DoDont: the right way and the wrong way side by side, each with why. */
|
|
17
|
+
export function DoDont({
|
|
18
|
+
doWhy,
|
|
19
|
+
dontWhy,
|
|
20
|
+
doLabel = 'Faça assim',
|
|
21
|
+
dontLabel = 'Não faça',
|
|
22
|
+
sprite,
|
|
23
|
+
do: right,
|
|
24
|
+
dont: wrong,
|
|
25
|
+
}: DoDontProps): ReactElement {
|
|
26
|
+
return (
|
|
27
|
+
<div className="pair feitio-dodont">
|
|
28
|
+
<div className="do">
|
|
29
|
+
<p className="verdict">
|
|
30
|
+
<Icon name="check" sprite={sprite} />
|
|
31
|
+
{doLabel}
|
|
32
|
+
</p>
|
|
33
|
+
<div className="demo">{right}</div>
|
|
34
|
+
<p className="why">{doWhy}</p>
|
|
35
|
+
</div>
|
|
36
|
+
<div className="dont">
|
|
37
|
+
<p className="verdict">
|
|
38
|
+
<Icon name="close" sprite={sprite} />
|
|
39
|
+
{dontLabel}
|
|
40
|
+
</p>
|
|
41
|
+
<div className="demo">{wrong}</div>
|
|
42
|
+
<p className="why">{dontWhy}</p>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
package/src/Drawer.tsx
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface DrawerProps {
|
|
5
|
+
id: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
side?: 'end' | 'start' | 'top' | 'bottom';
|
|
8
|
+
label?: string;
|
|
9
|
+
closeLabel?: string;
|
|
10
|
+
sprite?: string;
|
|
11
|
+
footer?: ReactNode;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Drawer: a panel that slides in from a side, over the page; a button with popoverTarget opens it. */
|
|
16
|
+
export function Drawer({
|
|
17
|
+
id,
|
|
18
|
+
title,
|
|
19
|
+
side = 'end',
|
|
20
|
+
label,
|
|
21
|
+
closeLabel = 'Fechar',
|
|
22
|
+
sprite,
|
|
23
|
+
footer,
|
|
24
|
+
children,
|
|
25
|
+
}: DrawerProps): ReactElement {
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
className="feitio-drawer"
|
|
29
|
+
id={id}
|
|
30
|
+
popover=""
|
|
31
|
+
data-side={side === 'end' ? undefined : side}
|
|
32
|
+
role="dialog"
|
|
33
|
+
aria-label={label ?? title}
|
|
34
|
+
>
|
|
35
|
+
<div className="drawer-header">
|
|
36
|
+
{title && <h2>{title}</h2>}
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
className="feitio-button close"
|
|
40
|
+
data-size="small"
|
|
41
|
+
popoverTarget={id}
|
|
42
|
+
popoverTargetAction="hide"
|
|
43
|
+
>
|
|
44
|
+
<Icon name="close" sprite={sprite} />
|
|
45
|
+
{closeLabel}
|
|
46
|
+
</button>
|
|
47
|
+
</div>
|
|
48
|
+
<div className="drawer-body">{children}</div>
|
|
49
|
+
{footer !== undefined && footer !== null && <div className="drawer-footer">{footer}</div>}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import basket from '@feitio/core/illustrations/empty-basket.svg' with { type: 'text' };
|
|
2
|
+
import torn from '@feitio/core/illustrations/torn-paper.svg' with { type: 'text' };
|
|
3
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
4
|
+
import { svgParts } from './calculations/svg-parts.ts';
|
|
5
|
+
|
|
6
|
+
const art = { basket: svgParts(basket), torn: svgParts(torn) };
|
|
7
|
+
|
|
8
|
+
export interface EmptyStateProps {
|
|
9
|
+
title: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
/** "basket" for nothing yet, "torn" for an error. */
|
|
12
|
+
illustration?: 'basket' | 'torn' | 'none';
|
|
13
|
+
size?: 'compact';
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** EmptyState: what shows where there is nothing yet, or where something went wrong, and what to do. */
|
|
18
|
+
export function EmptyState({
|
|
19
|
+
title,
|
|
20
|
+
text,
|
|
21
|
+
illustration = 'basket',
|
|
22
|
+
size,
|
|
23
|
+
children,
|
|
24
|
+
}: EmptyStateProps): ReactElement {
|
|
25
|
+
const drawing = illustration === 'none' ? undefined : art[illustration];
|
|
26
|
+
return (
|
|
27
|
+
<div className="feitio-empty" data-size={size}>
|
|
28
|
+
{drawing && (
|
|
29
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: the illustration is Feitio's own file.
|
|
30
|
+
<svg {...drawing.attributes} dangerouslySetInnerHTML={{ __html: drawing.inner }} />
|
|
31
|
+
)}
|
|
32
|
+
<h3>{title}</h3>
|
|
33
|
+
{text && <p>{text}</p>}
|
|
34
|
+
{children}
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface ErrorMessageProps {
|
|
5
|
+
id?: string;
|
|
6
|
+
sprite?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** ErrorMessage: what is wrong with a field and how to fix it, right above it. */
|
|
11
|
+
export function ErrorMessage({ id, sprite, children }: ErrorMessageProps): ReactElement {
|
|
12
|
+
return (
|
|
13
|
+
<span className="feitio-error-message" id={id}>
|
|
14
|
+
<Icon name="close" sprite={sprite} />
|
|
15
|
+
{children}
|
|
16
|
+
</span>
|
|
17
|
+
);
|
|
18
|
+
}
|