@paul-portfolio/react 0.1.17 → 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/README.md +166 -0
- package/dist/Divider.d.ts +10 -0
- package/dist/Divider.js +9 -0
- package/dist/IconButton.d.ts +12 -0
- package/dist/IconButton.js +10 -0
- package/dist/InfoTip.d.ts +13 -0
- package/dist/InfoTip.js +9 -0
- package/dist/Spinner.d.ts +12 -0
- package/dist/Spinner.js +9 -0
- package/dist/Switch.d.ts +13 -0
- package/dist/Switch.js +11 -0
- package/dist/Textarea.d.ts +11 -0
- package/dist/Textarea.js +13 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# @paul-portfolio/react
|
|
2
|
+
|
|
3
|
+
React components for the Paul Design System. Thin, accessible components styled
|
|
4
|
+
by [`@paul-portfolio/css`](https://www.npmjs.com/package/@paul-portfolio/css) —
|
|
5
|
+
the components render semantic markup with class names, and the CSS package
|
|
6
|
+
supplies the looks via design tokens.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @paul-portfolio/react @paul-portfolio/css @paul-portfolio/tokens
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`@paul-portfolio/css` and `@paul-portfolio/tokens` are peer dependencies, along
|
|
15
|
+
with `react` and `react-dom` (>=18).
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
Import the token variables and the component styles once, near the root of your
|
|
20
|
+
app:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import "@paul-portfolio/tokens/tokens.css";
|
|
24
|
+
import "@paul-portfolio/css/components.css";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then use the components:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { Button } from "@paul-portfolio/react";
|
|
31
|
+
|
|
32
|
+
export function Example() {
|
|
33
|
+
return <Button variant="primary">Save</Button>;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Components
|
|
38
|
+
|
|
39
|
+
### Button
|
|
40
|
+
|
|
41
|
+
Variants (`primary`, `secondary`, `outline`, `ghost`, `danger`), sizes (`xs`,
|
|
42
|
+
`sm`, `md`, `lg`), `loading`, and an `href` form that renders an `<a>`.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<Button variant="outline" size="sm" onClick={save}>Save</Button>
|
|
46
|
+
<Button href="/docs" variant="ghost">Docs</Button>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### IconButton
|
|
50
|
+
|
|
51
|
+
A square, icon-only button. Requires `aria-label` since there's no visible text.
|
|
52
|
+
Sizes `sm` and `md`.
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
<IconButton aria-label="Close" onClick={close}>✕</IconButton>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Input / Textarea
|
|
59
|
+
|
|
60
|
+
Labelled fields with `error` and `helper` text. `Input` takes a `size`
|
|
61
|
+
(`sm`/`md`); `Textarea` resizes vertically.
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
<Input label="Email" type="email" error={emailError} />
|
|
65
|
+
<Textarea label="Bio" helper="Max 200 characters" />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Switch
|
|
69
|
+
|
|
70
|
+
An on/off toggle. Controlled via `checked` + `onCheckedChange`. Give it an
|
|
71
|
+
`aria-label`.
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
<Switch checked={on} onCheckedChange={setOn} aria-label="Notifications" />
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Chip
|
|
78
|
+
|
|
79
|
+
A compact tag, optionally removable and colorable.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<Chip label="Design" onRemove={() => remove("design")} />
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Modal
|
|
86
|
+
|
|
87
|
+
An accessible dialog with focus trap, Escape-to-close, and a backdrop. Controlled
|
|
88
|
+
via `open` + `onClose`.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
<Modal open={open} onClose={close} aria-label="Settings">
|
|
92
|
+
<h2>Settings</h2>
|
|
93
|
+
</Modal>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Tooltip / InfoTip
|
|
97
|
+
|
|
98
|
+
`Tooltip` wraps any element and shows text on hover. `InfoTip` is the common
|
|
99
|
+
"small i that explains a label" shortcut, built on `Tooltip`.
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
<Tooltip content="Copied to clipboard"><IconButton aria-label="Copy">⧉</IconButton></Tooltip>
|
|
103
|
+
<InfoTip content="We never share your email." />
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Card
|
|
107
|
+
|
|
108
|
+
A surface with optional `Card.Header`, `Card.Body`, and `Card.Footer`.
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<Card>
|
|
112
|
+
<Card.Header>Plan</Card.Header>
|
|
113
|
+
<Card.Body>Pro — $12/mo</Card.Body>
|
|
114
|
+
</Card>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Badge / Avatar / Skeleton / Spinner
|
|
118
|
+
|
|
119
|
+
- **Badge** — a small status label.
|
|
120
|
+
- **Avatar** — a rounded user image with initials fallback.
|
|
121
|
+
- **Skeleton** — a shimmer placeholder for content that's still loading.
|
|
122
|
+
- **Spinner** — an indeterminate loading spinner (`sm`/`md`/`lg`), announced as a
|
|
123
|
+
status region.
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
<Badge>New</Badge>
|
|
127
|
+
<Avatar name="Ada Lovelace" src={url} />
|
|
128
|
+
<Skeleton width="12rem" />
|
|
129
|
+
<Spinner label="Loading results" />
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Divider
|
|
133
|
+
|
|
134
|
+
A thin separator rule, `horizontal` (default) or `vertical`.
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
<Divider />
|
|
138
|
+
<Divider orientation="vertical" />
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### VisuallyHidden
|
|
142
|
+
|
|
143
|
+
Renders content that's available to screen readers but hidden visually.
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
<VisuallyHidden>Loading</VisuallyHidden>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### cx
|
|
150
|
+
|
|
151
|
+
A tiny classname joiner used internally, exported for convenience.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
cx("card", isActive && "card--active"); // "card card--active"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Accessibility
|
|
158
|
+
|
|
159
|
+
Every component ships with an axe test in the package's suite. Components that
|
|
160
|
+
have no visible text (IconButton, Switch, Spinner) require or default an
|
|
161
|
+
accessible name, and interactive components expose the right roles and ARIA
|
|
162
|
+
state.
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT © Paul Sumido
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
type DividerProps = HTMLAttributes<HTMLHRElement> & {
|
|
3
|
+
orientation?: 'horizontal' | 'vertical';
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* A thin rule that separates content. Renders an <hr> (implicit
|
|
7
|
+
* role="separator"); pass orientation="vertical" for use inside a flex row.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Divider({ orientation, className, ...props }: DividerProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
package/dist/Divider.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from './cx';
|
|
3
|
+
/**
|
|
4
|
+
* A thin rule that separates content. Renders an <hr> (implicit
|
|
5
|
+
* role="separator"); pass orientation="vertical" for use inside a flex row.
|
|
6
|
+
*/
|
|
7
|
+
export function Divider({ orientation = 'horizontal', className, ...props }) {
|
|
8
|
+
return (_jsx("hr", { className: cx('divider', orientation === 'vertical' && 'divider--vertical', className), "aria-orientation": orientation, ...props }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A square, icon-only button. Always needs an aria-label because there's no
|
|
4
|
+
* visible text to name it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const IconButton: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
7
|
+
/** Required: describes the action for screen readers, since the button
|
|
8
|
+
* holds only an icon. */
|
|
9
|
+
'aria-label': string;
|
|
10
|
+
size?: 'sm' | 'md';
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { cx } from './cx';
|
|
4
|
+
/**
|
|
5
|
+
* A square, icon-only button. Always needs an aria-label because there's no
|
|
6
|
+
* visible text to name it.
|
|
7
|
+
*/
|
|
8
|
+
export const IconButton = forwardRef(function IconButton({ size, className, children, type, ...props }, ref) {
|
|
9
|
+
return (_jsx("button", { ref: ref, type: type ?? 'button', className: cx('icon-btn', size && size !== 'md' && `icon-btn--${size}`, className), ...props, children: children }));
|
|
10
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type InfoTipProps = {
|
|
2
|
+
/** The explanatory text shown in the tooltip. */
|
|
3
|
+
content: string;
|
|
4
|
+
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
5
|
+
/** Accessible name for the trigger. Defaults to "More information". */
|
|
6
|
+
label?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A small "i" glyph that reveals a tooltip on hover or focus. A convenience
|
|
10
|
+
* wrapper over Tooltip for the very common "explain this label" case.
|
|
11
|
+
*/
|
|
12
|
+
export declare function InfoTip({ content, side, label }: InfoTipProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
package/dist/InfoTip.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip } from './Tooltip';
|
|
3
|
+
/**
|
|
4
|
+
* A small "i" glyph that reveals a tooltip on hover or focus. A convenience
|
|
5
|
+
* wrapper over Tooltip for the very common "explain this label" case.
|
|
6
|
+
*/
|
|
7
|
+
export function InfoTip({ content, side = 'top', label = 'More information' }) {
|
|
8
|
+
return (_jsx(Tooltip, { content: content, side: side, children: _jsx("span", { className: "info-tip", role: "img", "aria-label": label, tabIndex: 0, children: "i" }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
type SpinnerProps = HTMLAttributes<HTMLSpanElement> & {
|
|
3
|
+
size?: 'sm' | 'md' | 'lg';
|
|
4
|
+
/** Accessible name announced to screen readers. Defaults to "Loading". */
|
|
5
|
+
label?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* An indeterminate loading spinner. Renders as a live status region so
|
|
9
|
+
* assistive tech announces that something is loading.
|
|
10
|
+
*/
|
|
11
|
+
export declare function Spinner({ size, label, className, ...props }: SpinnerProps): import("react").JSX.Element;
|
|
12
|
+
export {};
|
package/dist/Spinner.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from './cx';
|
|
3
|
+
/**
|
|
4
|
+
* An indeterminate loading spinner. Renders as a live status region so
|
|
5
|
+
* assistive tech announces that something is loading.
|
|
6
|
+
*/
|
|
7
|
+
export function Spinner({ size, label = 'Loading', className, ...props }) {
|
|
8
|
+
return (_jsx("span", { role: "status", "aria-label": label, className: cx('spinner', size && size !== 'md' && `spinner--${size}`, className), ...props }));
|
|
9
|
+
}
|
package/dist/Switch.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* An on/off toggle. Controlled via `checked` + `onCheckedChange`. Exposes
|
|
4
|
+
* role="switch" with aria-checked so assistive tech reads its state. Give it
|
|
5
|
+
* an aria-label (or aria-labelledby) since it has no text of its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange"> & {
|
|
8
|
+
/** Whether the switch is on. Controlled. */
|
|
9
|
+
checked: boolean;
|
|
10
|
+
/** Called with the next value when toggled. */
|
|
11
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
package/dist/Switch.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { cx } from './cx';
|
|
4
|
+
/**
|
|
5
|
+
* An on/off toggle. Controlled via `checked` + `onCheckedChange`. Exposes
|
|
6
|
+
* role="switch" with aria-checked so assistive tech reads its state. Give it
|
|
7
|
+
* an aria-label (or aria-labelledby) since it has no text of its own.
|
|
8
|
+
*/
|
|
9
|
+
export const Switch = forwardRef(function Switch({ checked, onCheckedChange, disabled, className, ...props }, ref) {
|
|
10
|
+
return (_jsx("button", { ref: ref, type: "button", role: "switch", "aria-checked": checked, disabled: disabled, onClick: () => onCheckedChange?.(!checked), className: cx('switch', checked && 'switch--on', className), ...props, children: _jsx("span", { className: "switch__thumb" }) }));
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TextareaHTMLAttributes } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Multi-line text field. Mirrors Input's label/error/helper API so the two
|
|
4
|
+
* feel the same in a form.
|
|
5
|
+
*/
|
|
6
|
+
export declare const Textarea: import("react").ForwardRefExoticComponent<TextareaHTMLAttributes<HTMLTextAreaElement> & {
|
|
7
|
+
label?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
helper?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
} & import("react").RefAttributes<HTMLTextAreaElement>>;
|
package/dist/Textarea.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId } from 'react';
|
|
3
|
+
import { cx } from './cx';
|
|
4
|
+
/**
|
|
5
|
+
* Multi-line text field. Mirrors Input's label/error/helper API so the two
|
|
6
|
+
* feel the same in a form.
|
|
7
|
+
*/
|
|
8
|
+
export const Textarea = forwardRef(function Textarea({ label, error, helper, disabled, className, ...props }, ref) {
|
|
9
|
+
const id = useId();
|
|
10
|
+
const helperId = `${id}-helper`;
|
|
11
|
+
const helperText = error || helper;
|
|
12
|
+
return (_jsxs("div", { className: "input__wrapper", children: [label && (_jsx("label", { className: "input__label", htmlFor: id, children: label })), _jsx("textarea", { ref: ref, id: id, className: cx('textarea', error && 'textarea--error', className), disabled: disabled, "aria-invalid": error ? true : undefined, "aria-describedby": helperText ? helperId : undefined, ...props }), helperText && (_jsx("span", { id: helperId, className: cx('input__helper', error && 'input__helper--error'), children: helperText }))] }));
|
|
13
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export { Button } from './Button';
|
|
2
|
+
export { IconButton } from './IconButton';
|
|
2
3
|
export { Card } from './Card';
|
|
3
4
|
export { Chip } from './Chip';
|
|
4
5
|
export { Input } from './Input';
|
|
6
|
+
export { Textarea } from './Textarea';
|
|
7
|
+
export { Switch } from './Switch';
|
|
5
8
|
export { Modal } from './Modal';
|
|
6
9
|
export { Tooltip } from './Tooltip';
|
|
10
|
+
export { InfoTip } from './InfoTip';
|
|
7
11
|
export { Avatar } from './Avatar';
|
|
8
12
|
export { Badge } from './Badge';
|
|
9
13
|
export { Skeleton } from './Skeleton';
|
|
14
|
+
export { Spinner } from './Spinner';
|
|
15
|
+
export { Divider } from './Divider';
|
|
10
16
|
export { VisuallyHidden } from './VisuallyHidden';
|
|
11
17
|
export { cx } from './cx';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export { Button } from './Button';
|
|
2
|
+
export { IconButton } from './IconButton';
|
|
2
3
|
export { Card } from './Card';
|
|
3
4
|
export { Chip } from './Chip';
|
|
4
5
|
export { Input } from './Input';
|
|
6
|
+
export { Textarea } from './Textarea';
|
|
7
|
+
export { Switch } from './Switch';
|
|
5
8
|
export { Modal } from './Modal';
|
|
6
9
|
export { Tooltip } from './Tooltip';
|
|
10
|
+
export { InfoTip } from './InfoTip';
|
|
7
11
|
export { Avatar } from './Avatar';
|
|
8
12
|
export { Badge } from './Badge';
|
|
9
13
|
export { Skeleton } from './Skeleton';
|
|
14
|
+
export { Spinner } from './Spinner';
|
|
15
|
+
export { Divider } from './Divider';
|
|
10
16
|
export { VisuallyHidden } from './VisuallyHidden';
|
|
11
17
|
export { cx } from './cx';
|