@polyfen/polykit-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 +166 -2
- package/dist/components/avatar.d.ts +19 -0
- package/dist/components/avatar.js +27 -0
- package/dist/components/button.d.ts +45 -0
- package/dist/components/button.js +44 -0
- package/dist/components/choice.d.ts +53 -0
- package/dist/components/choice.js +73 -0
- package/dist/components/dialog.d.ts +65 -0
- package/dist/components/dialog.js +178 -0
- package/dist/components/display.d.ts +61 -0
- package/dist/components/display.js +63 -0
- package/dist/components/field.d.ts +44 -0
- package/dist/components/field.js +62 -0
- package/dist/components/icon.d.ts +29 -0
- package/dist/components/icon.js +17 -0
- package/dist/components/link.d.ts +10 -0
- package/dist/components/link.js +9 -0
- package/dist/components/menu.d.ts +35 -0
- package/dist/components/menu.js +60 -0
- package/dist/components/navigation.d.ts +42 -0
- package/dist/components/navigation.js +47 -0
- package/dist/components/page.d.ts +97 -0
- package/dist/components/page.js +120 -0
- package/dist/components/popover.d.ts +10 -0
- package/dist/components/popover.js +16 -0
- package/dist/components/shell.d.ts +153 -0
- package/dist/components/shell.js +359 -0
- package/dist/components/table.d.ts +41 -0
- package/dist/components/table.js +35 -0
- package/dist/components/theme.d.ts +10 -0
- package/dist/components/theme.js +41 -0
- package/dist/components/toast.d.ts +27 -0
- package/dist/components/toast.js +93 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +20 -0
- package/dist/lib/boot-script.d.ts +9 -0
- package/dist/lib/boot-script.js +26 -0
- package/dist/lib/compose-refs.d.ts +3 -0
- package/dist/lib/compose-refs.js +11 -0
- package/dist/lib/cx.d.ts +4 -0
- package/dist/lib/cx.js +4 -0
- package/dist/lib/dom.d.ts +10 -0
- package/dist/lib/dom.js +29 -0
- package/dist/lib/use-controllable.d.ts +5 -0
- package/dist/lib/use-controllable.js +19 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Polyfen Group LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,167 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @polyfen/polykit-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Polykit for React. The components render the [Polykit CSS](../css/README.md) classes, take their behavior from [Radix Primitives](https://www.radix-ui.com/primitives) (or the browser, where the CSS is built on a native element), and use [shadcn/ui](https://ui.shadcn.com)'s names and props, so code written against shadcn moves over with few changes.
|
|
4
|
+
|
|
5
|
+
Status: **0.x, first stage of v2** ([ADR 0035](../../docs/adr/0035-react-package.md)). The API may still change between minor versions.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @polyfen/polykit-react @polyfen/polykit-css @polyfen/polykit-tokens react react-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Load the CSS once, tokens first:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import '@polyfen/polykit-tokens/tokens.css';
|
|
17
|
+
import '@polyfen/polykit-css/polykit.css';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Icons come from the [icons package](../icons/README.md)'s sprite: inline it in the page once (recommended), or copy `sprite.svg` to your assets and tell the components where it is:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { IconProvider } from '@polyfen/polykit-react';
|
|
24
|
+
|
|
25
|
+
<IconProvider spriteUrl="/assets/sprite.svg">{app}</IconProvider>;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Components that hold state or use hooks are marked `"use client"`, so they work in the Next.js App Router.
|
|
29
|
+
|
|
30
|
+
## Use
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import {
|
|
34
|
+
Button,
|
|
35
|
+
Dialog,
|
|
36
|
+
DialogContent,
|
|
37
|
+
DialogHeader,
|
|
38
|
+
DialogTitle,
|
|
39
|
+
DialogTrigger,
|
|
40
|
+
Field,
|
|
41
|
+
Input,
|
|
42
|
+
Toaster,
|
|
43
|
+
toast,
|
|
44
|
+
} from '@polyfen/polykit-react';
|
|
45
|
+
|
|
46
|
+
<Dialog>
|
|
47
|
+
<DialogTrigger asChild>
|
|
48
|
+
<Button>Rename…</Button>
|
|
49
|
+
</DialogTrigger>
|
|
50
|
+
<DialogContent>
|
|
51
|
+
<DialogHeader>
|
|
52
|
+
<DialogTitle>Rename Atlas</DialogTitle>
|
|
53
|
+
</DialogHeader>
|
|
54
|
+
<Field label="Name" hint="Shown in the sidebar.">
|
|
55
|
+
<Input defaultValue="Atlas" />
|
|
56
|
+
</Field>
|
|
57
|
+
</DialogContent>
|
|
58
|
+
</Dialog>;
|
|
59
|
+
|
|
60
|
+
<Button variant="primary" onClick={() => toast('Saved')}>
|
|
61
|
+
Save
|
|
62
|
+
</Button>;
|
|
63
|
+
<Toaster />;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Components
|
|
67
|
+
|
|
68
|
+
| Polykit React | CSS | Behavior | shadcn/ui equivalent |
|
|
69
|
+
| -------------------------------------------------------------------------------- | ----------------------------------------------------------- | ---------------------------------- | ------------------------------------------- |
|
|
70
|
+
| `Button`, `buttonClassName()` | `.pk-button` | native | Button |
|
|
71
|
+
| `IconButton` | `.pk-icon-button` | native | Button `size="icon"` |
|
|
72
|
+
| `Link` | `.pk-link` | native | Button `variant="link"` |
|
|
73
|
+
| `Icon`, `IconProvider` | `.pk-icon` | sprite `<use>` | (lucide-react) |
|
|
74
|
+
| `Badge`, `StatusPill` | `.pk-badge`, `.pk-status` | — | Badge |
|
|
75
|
+
| `Card` | `.pk-card` | — | Card (the surface only) |
|
|
76
|
+
| `Banner`, `BannerText`, `BannerActions` | `.pk-banner` | — | Alert |
|
|
77
|
+
| `Callout`, `Empty`, `Progress`, `Separator` | `.pk-callout`, `.pk-empty`, `.pk-progress`, `.pk-separator` | — | —, Empty, Progress, Separator |
|
|
78
|
+
| `Avatar`, `AvatarImage`, `AvatarFallback` | `.pk-avatar`, `.pk-monogram` | — | Avatar |
|
|
79
|
+
| `Field`, `Label`, `Input`, `Textarea`, `NativeSelect`, `FormGrid`, `FormActions` | `.pk-field`, `.pk-input` … | native | Field, Label, Input, Textarea, NativeSelect |
|
|
80
|
+
| `Checkbox`, `RadioGroup`, `RadioGroupItem`, `Choice` | `.pk-checkbox`, `.pk-radio`, `.pk-choice` | native inputs | Checkbox, RadioGroup |
|
|
81
|
+
| `Switch` | `.pk-switch` | Radix Switch | Switch |
|
|
82
|
+
| `CheckRound` | `.pk-check-round` | Radix Toggle | Checkbox (round) |
|
|
83
|
+
| `Chip` | `.pk-chip` | Radix Toggle | Toggle |
|
|
84
|
+
| `SegmentedControl`, `SegmentedControlItem` | `.pk-segmented` | Radix ToggleGroup (single) | ToggleGroup `type="single"` |
|
|
85
|
+
| `Tabs`, `TabsList`, `TabsTrigger`, `TabsContent`, `TabsCount` | `.pk-tabs` | Radix Tabs | Tabs |
|
|
86
|
+
| `NavTabs`, `NavTab` | `.pk-tabs` (links) | native | NavigationMenu |
|
|
87
|
+
| `DropdownMenu*` | `.pk-menu` | Radix DropdownMenu | DropdownMenu |
|
|
88
|
+
| `ContextMenu*` | `.pk-menu` | Radix ContextMenu | ContextMenu |
|
|
89
|
+
| `Popover*` | `.pk-popover` | Radix Popover | Popover |
|
|
90
|
+
| `Dialog*`, `AlertDialog*` | `.pk-dialog` | native `<dialog>` | Dialog, AlertDialog |
|
|
91
|
+
| `Toaster`, `toast()` | `.pk-toast` | own (one at a time, as `toast.js`) | Sonner |
|
|
92
|
+
| `Table*` | `.pk-table` | native | Table |
|
|
93
|
+
|
|
94
|
+
### App shell and page parts
|
|
95
|
+
|
|
96
|
+
| Polykit React | CSS | shadcn/ui equivalent |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `AppShell`, `ShellMain`, `useAppShell()` | `.pk-shell`, `.pk-scrim` | SidebarProvider |
|
|
99
|
+
| `Sidebar`, `SidebarBrand`, `Wordmark`, `SidebarNav`, `SidebarGroup`, `SidebarItem`, `SidebarSubItem`, `SidebarFoot`, `SidebarCollapse`, `SidebarThemeToggle` | `.pk-sidebar` | Sidebar |
|
|
100
|
+
| `Topbar`, `TopbarStart`, `TopbarMid`, `TopbarEnd`, `TopbarContext`, `TopbarMenuButton`, `Search` | `.pk-topbar`, `.pk-search` | — |
|
|
101
|
+
| `Content`, `Page` | `.pk-content`, `.pk-page` | SidebarInset |
|
|
102
|
+
| `SidePanel`, `SidePanelHeader`, `SidePanelBody`, `SidePanelFooter` | `.pk-panel` | Sheet |
|
|
103
|
+
| `PageHeader`, `PageHeaderTitle`, `PageHeaderActions`, `PageHeaderDescription` | `.pk-page-header` | — |
|
|
104
|
+
| `Group`, `Count`, `Row`, `Meta`, `MetaItem` | `.pk-group`, `.pk-row`, `.pk-meta` | — |
|
|
105
|
+
| `Pagination`, `pageRange()` | `.pk-pagination` | Pagination |
|
|
106
|
+
| `useTheme()`, `polykitBootScript` | `boot.js`, `theme.js` | (next-themes) |
|
|
107
|
+
|
|
108
|
+
The shell keeps its state on `<html>` (`data-sidebar="rail"`, `data-sidebar-open`, `data-panel-open`), as the CSS expects ([ADR 0036](../../docs/adr/0036-react-app-shell.md)). Put the boot script in `<head>` so a saved theme and rail apply before the first paint:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// Next.js app/layout.tsx
|
|
112
|
+
import { polykitBootScript } from '@polyfen/polykit-react';
|
|
113
|
+
|
|
114
|
+
<html lang="en" suppressHydrationWarning>
|
|
115
|
+
<head>
|
|
116
|
+
<script dangerouslySetInnerHTML={{ __html: polykitBootScript }} />
|
|
117
|
+
</head>
|
|
118
|
+
<body>{children}</body>
|
|
119
|
+
</html>;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
<AppShell>
|
|
124
|
+
<Sidebar>
|
|
125
|
+
<SidebarBrand>
|
|
126
|
+
<Wordmark href="/">Lumen</Wordmark>
|
|
127
|
+
</SidebarBrand>
|
|
128
|
+
<SidebarNav aria-label="Projects">
|
|
129
|
+
<SidebarGroup label="Projects">
|
|
130
|
+
<SidebarItem asChild icon="grid" current>
|
|
131
|
+
<NextLink href="/">All projects</NextLink>
|
|
132
|
+
</SidebarItem>
|
|
133
|
+
</SidebarGroup>
|
|
134
|
+
</SidebarNav>
|
|
135
|
+
<SidebarFoot>
|
|
136
|
+
<SidebarThemeToggle />
|
|
137
|
+
<SidebarCollapse />
|
|
138
|
+
</SidebarFoot>
|
|
139
|
+
</Sidebar>
|
|
140
|
+
<ShellMain>
|
|
141
|
+
<Topbar>
|
|
142
|
+
<TopbarStart>
|
|
143
|
+
<TopbarMenuButton />
|
|
144
|
+
<TopbarContext>Week 47</TopbarContext>
|
|
145
|
+
</TopbarStart>
|
|
146
|
+
</Topbar>
|
|
147
|
+
<Content>
|
|
148
|
+
<Page>{children}</Page>
|
|
149
|
+
</Content>
|
|
150
|
+
</ShellMain>
|
|
151
|
+
</AppShell>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Where Polykit differs from shadcn
|
|
155
|
+
|
|
156
|
+
- **Button variants.** shadcn's `default` is a filled button; in Polykit that is `primary`, and `default` is the bordered button. `outline` and `secondary` map to Polykit's `default`, `destructive` to `danger`. Sizes are `default` (shadcn's `sm` maps to it), `md` and `lg`.
|
|
157
|
+
- **Dialog** is the native `<dialog>`, as in the CSS: the browser supplies the backdrop, the focus trap and Escape. `DialogHeader` holds the close button; `DialogBody` and `DialogFooter` follow. Focus goes to the first field (an alert dialog starts on Cancel) and returns to the trigger.
|
|
158
|
+
- **Checkbox and radios** are the browser's inputs, so forms submit them as usual; `onCheckedChange` and `onValueChange` work as in shadcn.
|
|
159
|
+
- **Select** is `NativeSelect` only. For a custom listbox, use shadcn's Select through the [token bridge](../tokens/README.md).
|
|
160
|
+
|
|
161
|
+
### Not here yet
|
|
162
|
+
|
|
163
|
+
Anything else falls back to shadcn/ui, themed by `@polyfen/polykit-tokens/shadcn.css` ([fallback policy](../../docs/FALLBACK.md)): Tooltip, Select, Combobox, Command, Accordion and the rest. The board, calendar and chat come in a later stage.
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
[MIT](LICENSE), Copyright (c) 2026 The Polyfen Group LLC.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ImgHTMLAttributes } from 'react';
|
|
2
|
+
import type { CategoryColor } from './display.js';
|
|
3
|
+
export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
/** `sm` 24, default 32, `lg` 40, `xl` 56. */
|
|
5
|
+
size?: 'sm' | 'default' | 'lg' | 'xl';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A person's picture, round (`.pk-avatar`). Put an `AvatarFallback` (the initial) and an
|
|
9
|
+
* `AvatarImage` inside; the image covers the fallback and steps aside if it cannot load.
|
|
10
|
+
*/
|
|
11
|
+
export declare const Avatar: import("react").ForwardRefExoticComponent<AvatarProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
12
|
+
/** The picture. With the person's name beside the avatar, give it `alt=""`. */
|
|
13
|
+
export declare const AvatarImage: import("react").ForwardRefExoticComponent<ImgHTMLAttributes<HTMLImageElement> & import("react").RefAttributes<HTMLImageElement>>;
|
|
14
|
+
export interface AvatarFallbackProps extends HTMLAttributes<HTMLSpanElement> {
|
|
15
|
+
/** A categorical hue for the monogram. Without one it is an outline. */
|
|
16
|
+
color?: CategoryColor;
|
|
17
|
+
}
|
|
18
|
+
/** The initial underneath the picture (`.pk-monogram`). It is decoration: name the person. */
|
|
19
|
+
export declare const AvatarFallback: import("react").ForwardRefExoticComponent<AvatarFallbackProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useState, } from 'react';
|
|
4
|
+
import { cx } from '../lib/cx.js';
|
|
5
|
+
/**
|
|
6
|
+
* A person's picture, round (`.pk-avatar`). Put an `AvatarFallback` (the initial) and an
|
|
7
|
+
* `AvatarImage` inside; the image covers the fallback and steps aside if it cannot load.
|
|
8
|
+
*/
|
|
9
|
+
export const Avatar = forwardRef(function Avatar({ size = 'default', className, ...props }, ref) {
|
|
10
|
+
return (_jsx("span", { ref: ref, className: cx('pk-avatar', size !== 'default' && `pk-avatar--${size}`, className), ...props }));
|
|
11
|
+
});
|
|
12
|
+
/** The picture. With the person's name beside the avatar, give it `alt=""`. */
|
|
13
|
+
export const AvatarImage = forwardRef(function AvatarImage({ onError, alt = '', ...props }, ref) {
|
|
14
|
+
const [failed, setFailed] = useState(false);
|
|
15
|
+
if (failed)
|
|
16
|
+
return null;
|
|
17
|
+
return (_jsx("img", { ref: ref, alt: alt, onError: (event) => {
|
|
18
|
+
setFailed(true);
|
|
19
|
+
onError?.(event);
|
|
20
|
+
}, ...props }));
|
|
21
|
+
});
|
|
22
|
+
/** The initial underneath the picture (`.pk-monogram`). It is decoration: name the person. */
|
|
23
|
+
export const AvatarFallback = forwardRef(function AvatarFallback({ color, className, style, ...props }, ref) {
|
|
24
|
+
return (_jsx("span", { ref: ref, "aria-hidden": "true", className: cx('pk-monogram', className), style: color
|
|
25
|
+
? { '--pk-monogram-color': `var(--pk-color-cat-${color})`, ...style }
|
|
26
|
+
: style, ...props }));
|
|
27
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Polykit's variants, plus shadcn's names where one maps cleanly. Note that shadcn's `default`
|
|
4
|
+
* is a filled button, which is Polykit's `primary`; Polykit's `default` is the bordered button.
|
|
5
|
+
*/
|
|
6
|
+
export type ButtonVariant = 'default' | 'primary' | 'ghost' | 'danger' | 'accent' | 'accent-tint' | 'accent-secondary' | 'accent-secondary-tint' | 'frame'
|
|
7
|
+
/** shadcn: the bordered button (Polykit's `default`). */
|
|
8
|
+
| 'outline'
|
|
9
|
+
/** shadcn: the bordered button (Polykit's `default`). */
|
|
10
|
+
| 'secondary'
|
|
11
|
+
/** shadcn: Polykit's `danger`. */
|
|
12
|
+
| 'destructive';
|
|
13
|
+
/** `default` is the compact 32px button; `md` and `lg` are taller. shadcn's `sm` is the default. */
|
|
14
|
+
export type ButtonSize = 'default' | 'sm' | 'md' | 'lg';
|
|
15
|
+
/** The class names of a Polykit button, for an element that is not a `Button` (a router link). */
|
|
16
|
+
export declare function buttonClassName({ variant, size, pill, className, }?: {
|
|
17
|
+
variant?: ButtonVariant;
|
|
18
|
+
size?: ButtonSize;
|
|
19
|
+
pill?: boolean;
|
|
20
|
+
className?: string;
|
|
21
|
+
}): string;
|
|
22
|
+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
23
|
+
variant?: ButtonVariant;
|
|
24
|
+
size?: ButtonSize;
|
|
25
|
+
/** Fully rounded ends. */
|
|
26
|
+
pill?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The action is under way: the button says so (`aria-busy`), keeps its color and focus, and
|
|
29
|
+
* ignores clicks until it is done.
|
|
30
|
+
*/
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
/** Render the child element (a link) with the button's classes instead of a `<button>`. */
|
|
33
|
+
asChild?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** A button (`.pk-button`). Ink is the primary action; the accent fills only the accent variants. */
|
|
36
|
+
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
37
|
+
export interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
38
|
+
/** `frame` is for the dark top bar. */
|
|
39
|
+
variant?: 'default' | 'frame';
|
|
40
|
+
/** An icon button has no text, so it must have a name. */
|
|
41
|
+
'aria-label': string;
|
|
42
|
+
asChild?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** A square button that holds one icon (`.pk-icon-button`). shadcn: `Button size="icon"`. */
|
|
45
|
+
export declare const IconButton: import("react").ForwardRefExoticComponent<IconButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Slot } from 'radix-ui';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { cx } from '../lib/cx.js';
|
|
5
|
+
const VARIANT = {
|
|
6
|
+
default: null,
|
|
7
|
+
outline: null,
|
|
8
|
+
secondary: null,
|
|
9
|
+
primary: 'pk-button--primary',
|
|
10
|
+
ghost: 'pk-button--ghost',
|
|
11
|
+
danger: 'pk-button--danger',
|
|
12
|
+
destructive: 'pk-button--danger',
|
|
13
|
+
accent: 'pk-button--accent',
|
|
14
|
+
'accent-tint': 'pk-button--accent-tint',
|
|
15
|
+
'accent-secondary': 'pk-button--accent-secondary',
|
|
16
|
+
'accent-secondary-tint': 'pk-button--accent-secondary-tint',
|
|
17
|
+
frame: 'pk-button--frame',
|
|
18
|
+
};
|
|
19
|
+
const SIZE = {
|
|
20
|
+
default: null,
|
|
21
|
+
sm: null,
|
|
22
|
+
md: 'pk-button--md',
|
|
23
|
+
lg: 'pk-button--lg',
|
|
24
|
+
};
|
|
25
|
+
/** The class names of a Polykit button, for an element that is not a `Button` (a router link). */
|
|
26
|
+
export function buttonClassName({ variant = 'default', size = 'default', pill = false, className, } = {}) {
|
|
27
|
+
return cx('pk-button', VARIANT[variant], SIZE[size], pill && 'pk-button--pill', className);
|
|
28
|
+
}
|
|
29
|
+
/** A button (`.pk-button`). Ink is the primary action; the accent fills only the accent variants. */
|
|
30
|
+
export const Button = forwardRef(function Button({ variant, size, pill, loading, asChild, className, type, onClick, ...props }, ref) {
|
|
31
|
+
const Comp = asChild ? Slot.Root : 'button';
|
|
32
|
+
return (_jsx(Comp, { ref: ref, className: buttonClassName({ variant, size, pill, className }), type: asChild ? type : (type ?? 'button'), "aria-busy": loading || undefined, onClick: (event) => {
|
|
33
|
+
if (loading) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
onClick?.(event);
|
|
38
|
+
}, ...props }));
|
|
39
|
+
});
|
|
40
|
+
/** A square button that holds one icon (`.pk-icon-button`). shadcn: `Button size="icon"`. */
|
|
41
|
+
export const IconButton = forwardRef(function IconButton({ variant = 'default', asChild, className, type, ...props }, ref) {
|
|
42
|
+
const Comp = asChild ? Slot.Root : 'button';
|
|
43
|
+
return (_jsx(Comp, { ref: ref, className: cx('pk-icon-button', variant === 'frame' && 'pk-icon-button--frame', className), type: asChild ? type : (type ?? 'button'), ...props }));
|
|
44
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Switch as SwitchPrimitive, Toggle } from 'radix-ui';
|
|
2
|
+
import { type ComponentPropsWithoutRef, type HTMLAttributes, type InputHTMLAttributes, type LabelHTMLAttributes } from 'react';
|
|
3
|
+
/** The label that lines a checkbox, radio or switch up with its text (`.pk-choice`). */
|
|
4
|
+
export declare const Choice: import("react").ForwardRefExoticComponent<LabelHTMLAttributes<HTMLLabelElement> & import("react").RefAttributes<HTMLLabelElement>>;
|
|
5
|
+
export type CheckedState = boolean | 'indeterminate';
|
|
6
|
+
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'checked' | 'defaultChecked'> {
|
|
7
|
+
checked?: CheckedState;
|
|
8
|
+
defaultChecked?: boolean;
|
|
9
|
+
/** shadcn's change handler; `onChange` works too. */
|
|
10
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A checkbox (`.pk-checkbox`): the browser's own input, so forms, the keyboard and screen readers
|
|
14
|
+
* work as usual. `checked="indeterminate"` shows the dash. Wrap it in a `Choice` with its text.
|
|
15
|
+
*/
|
|
16
|
+
export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
17
|
+
export interface RadioGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
|
|
18
|
+
value?: string;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
onValueChange?: (value: string) => void;
|
|
21
|
+
/** The radios' shared name; one is made up when it is left out. */
|
|
22
|
+
name?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A set of radios (`role="radiogroup"`). Name it with `aria-label` or `aria-labelledby`, and put a
|
|
28
|
+
* `RadioGroupItem` in a `Choice` for each option. The radios are native, so the arrow keys move
|
|
29
|
+
* between them.
|
|
30
|
+
*/
|
|
31
|
+
export declare const RadioGroup: import("react").ForwardRefExoticComponent<RadioGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
32
|
+
export interface RadioGroupItemProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'value' | 'name'> {
|
|
33
|
+
value: string;
|
|
34
|
+
}
|
|
35
|
+
/** One radio (`.pk-radio`) in a `RadioGroup`. */
|
|
36
|
+
export declare const RadioGroupItem: import("react").ForwardRefExoticComponent<RadioGroupItemProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
37
|
+
export type SwitchProps = ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>;
|
|
38
|
+
/**
|
|
39
|
+
* A switch (`.pk-switch`): an on/off setting that takes effect at once. A Radix switch (a button
|
|
40
|
+
* with `role="switch"`); name it with a `Choice` around it or `aria-label`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<Omit<SwitchPrimitive.SwitchProps & import("react").RefAttributes<HTMLButtonElement>, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
43
|
+
export interface CheckRoundProps extends ComponentPropsWithoutRef<typeof Toggle.Root> {
|
|
44
|
+
/** Name it after what it completes ("Mark Draft the brief done"). */
|
|
45
|
+
'aria-label': string;
|
|
46
|
+
/** The completion is being saved. */
|
|
47
|
+
loading?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The completion control (`.pk-check-round`): a round toggle that turns green when pressed. Pair
|
|
51
|
+
* it with an Undo toast. Its tick is the sprite's `check-bold`.
|
|
52
|
+
*/
|
|
53
|
+
export declare const CheckRound: import("react").ForwardRefExoticComponent<CheckRoundProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Switch as SwitchPrimitive, Toggle } from 'radix-ui';
|
|
4
|
+
import { createContext, forwardRef, useContext, useEffect, useId, useRef, } from 'react';
|
|
5
|
+
import { composeRefs } from '../lib/compose-refs.js';
|
|
6
|
+
import { cx } from '../lib/cx.js';
|
|
7
|
+
import { useControllableState } from '../lib/use-controllable.js';
|
|
8
|
+
import { Icon } from './icon.js';
|
|
9
|
+
/** The label that lines a checkbox, radio or switch up with its text (`.pk-choice`). */
|
|
10
|
+
export const Choice = forwardRef(function Choice({ className, ...props }, ref) {
|
|
11
|
+
return _jsx("label", { ref: ref, className: cx('pk-choice', className), ...props });
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* A checkbox (`.pk-checkbox`): the browser's own input, so forms, the keyboard and screen readers
|
|
15
|
+
* work as usual. `checked="indeterminate"` shows the dash. Wrap it in a `Choice` with its text.
|
|
16
|
+
*/
|
|
17
|
+
export const Checkbox = forwardRef(function Checkbox({ checked, onCheckedChange, onChange, className, ...props }, ref) {
|
|
18
|
+
const inner = useRef(null);
|
|
19
|
+
const indeterminate = checked === 'indeterminate';
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (inner.current)
|
|
22
|
+
inner.current.indeterminate = indeterminate;
|
|
23
|
+
}, [indeterminate]);
|
|
24
|
+
return (_jsx("input", { ref: composeRefs(inner, ref), type: "checkbox", className: cx('pk-checkbox', className), checked: checked === undefined ? undefined : checked === true, "aria-checked": indeterminate ? 'mixed' : undefined, onChange: (event) => {
|
|
25
|
+
onChange?.(event);
|
|
26
|
+
onCheckedChange?.(event.currentTarget.checked);
|
|
27
|
+
}, ...props }));
|
|
28
|
+
});
|
|
29
|
+
const RadioContext = createContext(null);
|
|
30
|
+
/**
|
|
31
|
+
* A set of radios (`role="radiogroup"`). Name it with `aria-label` or `aria-labelledby`, and put a
|
|
32
|
+
* `RadioGroupItem` in a `Choice` for each option. The radios are native, so the arrow keys move
|
|
33
|
+
* between them.
|
|
34
|
+
*/
|
|
35
|
+
export const RadioGroup = forwardRef(function RadioGroup({ value, defaultValue, onValueChange, name, disabled, required, ...props }, ref) {
|
|
36
|
+
const auto = useId();
|
|
37
|
+
const [current, setValue] = useControllableState(value, defaultValue, (next) => {
|
|
38
|
+
if (next !== undefined)
|
|
39
|
+
onValueChange?.(next);
|
|
40
|
+
});
|
|
41
|
+
return (_jsx(RadioContext.Provider, { value: {
|
|
42
|
+
name: name ?? `pk-radio-${auto}`,
|
|
43
|
+
value: current,
|
|
44
|
+
setValue,
|
|
45
|
+
disabled,
|
|
46
|
+
required,
|
|
47
|
+
}, children: _jsx("div", { ref: ref, role: "radiogroup", ...props }) }));
|
|
48
|
+
});
|
|
49
|
+
/** One radio (`.pk-radio`) in a `RadioGroup`. */
|
|
50
|
+
export const RadioGroupItem = forwardRef(function RadioGroupItem({ value, className, disabled, onChange, ...props }, ref) {
|
|
51
|
+
const group = useContext(RadioContext);
|
|
52
|
+
if (!group)
|
|
53
|
+
throw new Error('RadioGroupItem must be inside a RadioGroup.');
|
|
54
|
+
return (_jsx("input", { ref: ref, type: "radio", className: cx('pk-radio', className), name: group.name, value: value, checked: group.value === value, disabled: disabled ?? group.disabled, required: group.required, onChange: (event) => {
|
|
55
|
+
onChange?.(event);
|
|
56
|
+
if (event.currentTarget.checked)
|
|
57
|
+
group.setValue(value);
|
|
58
|
+
}, ...props }));
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* A switch (`.pk-switch`): an on/off setting that takes effect at once. A Radix switch (a button
|
|
62
|
+
* with `role="switch"`); name it with a `Choice` around it or `aria-label`.
|
|
63
|
+
*/
|
|
64
|
+
export const Switch = forwardRef(function Switch({ className, ...props }, ref) {
|
|
65
|
+
return _jsx(SwitchPrimitive.Root, { ref: ref, className: cx('pk-switch', className), ...props });
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* The completion control (`.pk-check-round`): a round toggle that turns green when pressed. Pair
|
|
69
|
+
* it with an Undo toast. Its tick is the sprite's `check-bold`.
|
|
70
|
+
*/
|
|
71
|
+
export const CheckRound = forwardRef(function CheckRound({ className, loading, children, ...props }, ref) {
|
|
72
|
+
return (_jsx(Toggle.Root, { ref: ref, className: cx('pk-check-round', className), "aria-busy": loading || undefined, ...props, children: children ?? _jsx(Icon, { name: "check-bold" }) }));
|
|
73
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type DialogHTMLAttributes, type FormHTMLAttributes, type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface DialogProps {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
defaultOpen?: boolean;
|
|
5
|
+
onOpenChange?: (open: boolean) => void;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A modal dialog on the native `<dialog>` (`.pk-dialog`): the browser gives the backdrop, the
|
|
10
|
+
* focus trap, Escape and the top layer. The parts and props follow shadcn's Dialog.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Dialog({ open, defaultOpen, onOpenChange, children }: DialogProps): import("react").JSX.Element;
|
|
13
|
+
/** An alert dialog: the same, with `role="alertdialog"` on its content. shadcn: AlertDialog. */
|
|
14
|
+
export declare const AlertDialog: typeof Dialog;
|
|
15
|
+
interface AsChildButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
16
|
+
asChild?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Opens the dialog. Its label should end with "…". */
|
|
19
|
+
export declare const DialogTrigger: import("react").ForwardRefExoticComponent<AsChildButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
20
|
+
export declare const AlertDialogTrigger: import("react").ForwardRefExoticComponent<AsChildButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
21
|
+
/** Closes the dialog. In an alert dialog, the first one (Cancel) gets the focus when it opens. */
|
|
22
|
+
export declare const DialogClose: import("react").ForwardRefExoticComponent<AsChildButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
23
|
+
export declare const AlertDialogCancel: import("react").ForwardRefExoticComponent<AsChildButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
24
|
+
export interface DialogContentProps extends DialogHTMLAttributes<HTMLDialogElement> {
|
|
25
|
+
/** `lg` is a little wider. */
|
|
26
|
+
size?: 'default' | 'lg';
|
|
27
|
+
/** The dialog is one form: the form (`DialogForm`) supplies the padding. */
|
|
28
|
+
form?: boolean;
|
|
29
|
+
/** `alertdialog` for a confirmation of something that cannot be undone. */
|
|
30
|
+
role?: 'dialog' | 'alertdialog';
|
|
31
|
+
/** A click on the backdrop closes it. Leave it off for destructive confirmations. */
|
|
32
|
+
closeOnBackdrop?: boolean;
|
|
33
|
+
/** Keep the children in the page while the dialog is closed (it keeps their state). */
|
|
34
|
+
forceMount?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** The dialog itself. Name it with a `DialogTitle`. */
|
|
37
|
+
export declare const DialogContent: import("react").ForwardRefExoticComponent<DialogContentProps & import("react").RefAttributes<HTMLDialogElement>>;
|
|
38
|
+
export declare const AlertDialogContent: import("react").ForwardRefExoticComponent<DialogContentProps & import("react").RefAttributes<HTMLDialogElement>>;
|
|
39
|
+
export interface DialogHeaderProps extends HTMLAttributes<HTMLDivElement> {
|
|
40
|
+
/** The close button in the corner (the sprite's `x`). On by default, as in shadcn. */
|
|
41
|
+
showCloseButton?: boolean;
|
|
42
|
+
/** The close button's name. */
|
|
43
|
+
closeLabel?: string;
|
|
44
|
+
}
|
|
45
|
+
/** The head (`.pk-dialog__head`): the title and lede, and the close button. */
|
|
46
|
+
export declare const DialogHeader: import("react").ForwardRefExoticComponent<DialogHeaderProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
47
|
+
export declare const AlertDialogHeader: import("react").ForwardRefExoticComponent<DialogHeaderProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
48
|
+
export interface DialogTitleProps extends HTMLAttributes<HTMLHeadingElement> {
|
|
49
|
+
/** The smaller heading, for a dialog that is one form. */
|
|
50
|
+
size?: 'default' | 'md';
|
|
51
|
+
}
|
|
52
|
+
/** The dialog's name (`.pk-dialog__title`). A destructive confirm names the thing. */
|
|
53
|
+
export declare const DialogTitle: import("react").ForwardRefExoticComponent<DialogTitleProps & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
54
|
+
export declare const AlertDialogTitle: import("react").ForwardRefExoticComponent<DialogTitleProps & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
55
|
+
/** A line under the title (`.pk-dialog__lede`). */
|
|
56
|
+
export declare const DialogDescription: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLParagraphElement> & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
57
|
+
export declare const AlertDialogDescription: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLParagraphElement> & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
58
|
+
/** The body (`.pk-dialog__body`). */
|
|
59
|
+
export declare const DialogBody: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
60
|
+
/** The buttons (`.pk-dialog__actions`): Cancel, then the main button. */
|
|
61
|
+
export declare const DialogFooter: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
62
|
+
export declare const AlertDialogFooter: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
63
|
+
/** A dialog that is one form (`DialogContent form`): the form holds the fields and the buttons. */
|
|
64
|
+
export declare const DialogForm: import("react").ForwardRefExoticComponent<FormHTMLAttributes<HTMLFormElement> & import("react").RefAttributes<HTMLFormElement>>;
|
|
65
|
+
export {};
|