@eschoolbase/client-ui 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/README.md +193 -2
- package/dist/components/AccountPanel/AccountPanel.d.ts +8 -0
- package/dist/components/AccountPanel/AccountPanel.types.d.ts +65 -0
- package/dist/components/AccountPanel/index.d.ts +2 -0
- package/dist/components/Avatar/Avatar.d.ts +4 -0
- package/dist/components/Avatar/Avatar.types.d.ts +14 -0
- package/dist/components/Avatar/index.d.ts +2 -0
- package/dist/components/Button/Button.d.ts +2 -0
- package/dist/components/Button/Button.types.d.ts +14 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/FormField/FormField.d.ts +2 -0
- package/dist/components/FormField/FormField.types.d.ts +43 -0
- package/dist/components/FormField/FormFieldContext.d.ts +8 -0
- package/dist/components/FormField/index.d.ts +3 -0
- package/dist/components/FormSection/FormSection.d.ts +6 -0
- package/dist/components/FormSection/FormSection.types.d.ts +15 -0
- package/dist/components/FormSection/index.d.ts +2 -0
- package/dist/components/Input/Input.d.ts +2 -0
- package/dist/components/Input/Input.types.d.ts +15 -0
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Select/Select.d.ts +7 -0
- package/dist/components/Select/Select.types.d.ts +57 -0
- package/dist/components/Select/SelectControl.d.ts +2 -0
- package/dist/components/Select/index.d.ts +2 -0
- package/dist/components/Typography/Typography.d.ts +3 -0
- package/dist/components/Typography/Typography.types.d.ts +22 -0
- package/dist/components/Typography/index.d.ts +2 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +984 -0
- package/dist/index.js.map +1 -0
- package/dist/license/UnlicensedNotice.d.ts +2 -0
- package/dist/license/hash.d.ts +1 -0
- package/dist/license/index.d.ts +2 -0
- package/dist/license/keys.d.ts +6 -0
- package/dist/license/license.d.ts +7 -0
- package/dist/styles.css +2 -0
- package/dist/theme/ThemeProvider.d.ts +4 -0
- package/dist/theme/ThemeProvider.types.d.ts +19 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/utils/cn.d.ts +3 -0
- package/package.json +75 -4
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# client-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A shared React + TypeScript design system: design tokens, a theme system and reusable form/UI components. It contains no business logic, API calls or routing, and works in plain React, Vite and Next.js apps.
|
|
4
|
+
|
|
5
|
+
Published as `@company/client-ui` (the scope is configurable in `package.json` → `name`).
|
|
6
|
+
|
|
7
|
+
Included in v0.1: `ThemeProvider`, `Button`, `Input`, `Select`, `FormField`, and the `cn()` helper.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @company/client-ui
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`react` and `react-dom` (^18 or ^19) are peer dependencies, so your app's single React instance is used.
|
|
16
|
+
|
|
17
|
+
## Basic usage
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import '@company/client-ui/styles.css';
|
|
21
|
+
import { Button, FormField, Input, Select, ThemeProvider } from '@company/client-ui';
|
|
22
|
+
|
|
23
|
+
export function App() {
|
|
24
|
+
return (
|
|
25
|
+
<ThemeProvider>
|
|
26
|
+
<FormField label="Email" required error="Email is required">
|
|
27
|
+
<Input type="email" />
|
|
28
|
+
</FormField>
|
|
29
|
+
<Select
|
|
30
|
+
label="Class"
|
|
31
|
+
placeholder="Select a class"
|
|
32
|
+
options={[{ label: 'Class 10', value: '10' }]}
|
|
33
|
+
/>
|
|
34
|
+
<Button type="submit">Save</Button>
|
|
35
|
+
</ThemeProvider>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Importing the CSS
|
|
41
|
+
|
|
42
|
+
- **Vite / CRA / any bundler:** `import '@company/client-ui/styles.css';` once in your entry file.
|
|
43
|
+
- **Next.js App Router:** import it in `app/layout.tsx`. **Pages Router:** import it in `pages/_app.tsx`.
|
|
44
|
+
|
|
45
|
+
`styles.css` contains the design tokens, the themes and all component styles. It does not include a global reset; if you want one, copy `src/styles/reset.css` / `globals.css` or use your own.
|
|
46
|
+
|
|
47
|
+
The bundle starts with `"use client"`, so components can be imported from React Server Component files in Next.js.
|
|
48
|
+
|
|
49
|
+
## Theme setup
|
|
50
|
+
|
|
51
|
+
Themes are CSS variables scoped by a `data-theme` attribute. `ThemeProvider` renders a wrapper `<div data-theme="…">` that also sets the background, text color and font.
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
<ThemeProvider defaultTheme="dark">…</ThemeProvider> {/* uncontrolled */}
|
|
55
|
+
<ThemeProvider theme={theme} onThemeChange={setTheme}>…</ThemeProvider> {/* controlled */}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Switch themes from anywhere inside the provider:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { useTheme } from '@company/client-ui';
|
|
62
|
+
|
|
63
|
+
const { theme, setTheme } = useTheme();
|
|
64
|
+
<Button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>Toggle</Button>;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Customizing / adding themes
|
|
68
|
+
|
|
69
|
+
All tokens are `--cui-*` variables (see `src/theme/tokens.css` and `themes.css`). Override them in your own CSS, loaded after `styles.css`:
|
|
70
|
+
|
|
71
|
+
```css
|
|
72
|
+
[data-theme='brand-x'] {
|
|
73
|
+
--cui-color-primary: #7c3aed;
|
|
74
|
+
--cui-color-primary-hover: #6d28d9;
|
|
75
|
+
--cui-color-primary-active: #5b21b6;
|
|
76
|
+
--cui-color-primary-subtle: #f5f3ff;
|
|
77
|
+
--cui-color-border-focus: #7c3aed;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<ThemeProvider defaultTheme="brand-x">…</ThemeProvider>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Token groups: colors, typography (`--cui-font-*`, `--cui-line-height`), spacing (`--cui-space-*`), radius, shadows, control heights (`--cui-control-height-*`). Components only reference tokens, never hardcoded values.
|
|
86
|
+
|
|
87
|
+
## License key
|
|
88
|
+
|
|
89
|
+
All components require a valid license key. Without one they render a small "missing or invalid license key" notice instead of the component, and one `[client-ui]` error is logged to the console.
|
|
90
|
+
|
|
91
|
+
Provide the key in either way (the `ThemeProvider` prop takes priority):
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { setLicenseKey, ThemeProvider } from '@company/client-ui';
|
|
95
|
+
|
|
96
|
+
setLicenseKey(import.meta.env.VITE_CLIENT_UI_KEY); // once at app start (Next.js: process.env.NEXT_PUBLIC_CLIENT_UI_KEY)
|
|
97
|
+
|
|
98
|
+
<ThemeProvider licenseKey={import.meta.env.VITE_CLIENT_UI_KEY}>...</ThemeProvider>;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Issuing and revoking keys (maintainers)
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
node scripts/license.mjs generate "Customer name" # prints a key and its hash
|
|
105
|
+
node scripts/license.mjs hash <existing-key> # hash for a key you already have
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Add the printed hash to `VALID_KEY_HASHES` in `src/license/keys.ts`, then release. Give the plain key to the customer. To revoke, remove the hash and release (existing installs keep working until they upgrade).
|
|
109
|
+
|
|
110
|
+
Keys are matched as hashes, so the plain keys are not in the bundle. This is a deterrent, not security: anything shipped to a browser can be bypassed by someone determined. `src/license/dev.ts` holds the development key used by Storybook and the playground; it is not exported from the package.
|
|
111
|
+
|
|
112
|
+
## Components
|
|
113
|
+
|
|
114
|
+
| Component | Highlights |
|
|
115
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
116
|
+
| `Button` | `variant`: primary, secondary, outline, ghost, danger, link · `size`: sm/md/lg · `loading` · `disabled` · `fullWidth`. Defaults to `type="button"`. |
|
|
117
|
+
| `Input` | `label`, `helperText`, `error`, `required`, `prefix`, `suffix`, `size`; forwards `ref`; all native input props. |
|
|
118
|
+
| `Select` | Custom dropdown (like the app's AdvancedSelect): popover list, type-to-search, `multiple`, clear button, `onSearch` + `loading` for server-side search, `name` for forms. `onChange` receives the value (`string`, or `string[]` when `multiple`). Ref points at the trigger button. |
|
|
119
|
+
| `FormField` | Wraps any control: label, required marker, helper text, error, and `aria-describedby` / `aria-invalid` wiring. |
|
|
120
|
+
| `FormSection` | Titled group of fields: heading, subtitle, divider and a responsive grid (`columns` 1-3, `headingLevel`). Renders a labelled `<section>`. |
|
|
121
|
+
| `Typography` | Themed text: `variant` (h1-h4, body, body-sm, caption, label), `as` to change the element, `color`, `weight`, `align`, `truncate`. |
|
|
122
|
+
| `AccountPanel` | Logged-in user button (header avatar or sidebar row) that opens a panel: greeting, role, detail rows, action pills, an app launcher grid and a log out action. Ported from the Engage portal; router-agnostic via `renderLink`. |
|
|
123
|
+
| `Avatar` | Photo or name initials with a stable color; sizes xs-xl. |
|
|
124
|
+
| `ThemeProvider` | Applies `data-theme`; `useTheme()` for reading/changing it. |
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
<Input label="Amount" prefix="₹" helperText="Excluding tax" />
|
|
128
|
+
<Input label="Email" error="Enter a valid email" />
|
|
129
|
+
<Button variant="danger" loading>Deleting…</Button>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`Input` and `Select` render their own label/messages when given `label`, `helperText` or `error`. Without them they pick up the surrounding `FormField` automatically, so both styles are equivalent:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
<Input label="Email" error="Required" />
|
|
136
|
+
|
|
137
|
+
<FormField label="Email" error="Required">
|
|
138
|
+
<Input />
|
|
139
|
+
</FormField>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Building a new control (Textarea, Checkbox…)? Call `useFormFieldControl({ id, required, disabled, error })` to get the `id`, `required`, `disabled`, `aria-invalid` and `aria-describedby` props to put on the native element.
|
|
143
|
+
|
|
144
|
+
Errors are announced with `role="alert"`; an error replaces helper text while present.
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
npm install
|
|
150
|
+
npm run dev # playground at http://localhost:5173 (playground/main.tsx)
|
|
151
|
+
npm run storybook # component docs at http://localhost:6006
|
|
152
|
+
npm run typecheck
|
|
153
|
+
npm run lint
|
|
154
|
+
npm run format
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Each component lives in `src/components/<Name>/` with `<Name>.tsx`, `.types.ts`, `.module.css`, `.test.tsx`, `.stories.tsx` and `index.ts`. Export new components and their types from `src/index.ts`.
|
|
158
|
+
|
|
159
|
+
## Storybook
|
|
160
|
+
|
|
161
|
+
`npm run storybook` serves the design-system documentation (autodocs + a11y checks). Use the **Theme** toolbar item to switch light/dark. `npm run build-storybook` creates a static site in `storybook-static/`.
|
|
162
|
+
|
|
163
|
+
## Testing
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm run test # single run (Vitest + React Testing Library, jsdom)
|
|
167
|
+
npm run test:watch
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Build
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
npm run build
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Produces `dist/` with `index.js` (ESM), `index.cjs` (CommonJS), `styles.css`, and TypeScript declarations (`index.d.ts` + per-module `.d.ts`). React is external.
|
|
177
|
+
|
|
178
|
+
## Publishing
|
|
179
|
+
|
|
180
|
+
1. Set the real scope in `package.json` (`"name": "@your-scope/client-ui"`) and point npm at your private registry (`.npmrc`, e.g. `@your-scope:registry=https://…`).
|
|
181
|
+
2. `npm version patch|minor|major`
|
|
182
|
+
3. `npm publish --access public` (`prepublishOnly` runs typecheck, lint, tests and build first).
|
|
183
|
+
|
|
184
|
+
To try it locally in an app before publishing: `npm pack`, then `npm install ../client-ui/your-scope-client-ui-0.1.0.tgz`.
|
|
185
|
+
|
|
186
|
+
## Versioning
|
|
187
|
+
|
|
188
|
+
Semantic Versioning: **patch** for fixes, **minor** for new components/props/tokens, **major** for breaking API, behavior or token-name changes. Removed or renamed `--cui-*` variables count as breaking.
|
|
189
|
+
|
|
190
|
+
## Roadmap-friendly design
|
|
191
|
+
|
|
192
|
+
- `Select` takes `options` as data; async options and grouping can be added behind new props.
|
|
193
|
+
- Form controls share `FormField` context, so Textarea, Checkbox, etc. plug in via `useFormFieldControl`.
|
|
194
|
+
- Themes are plain CSS blocks, so multiple brands or white-labeling need no code changes. Layout uses logical properties (`margin-inline-start`, `inset-inline-end`) to keep RTL open.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AccountPanelProps } from './AccountPanel.types';
|
|
2
|
+
/**
|
|
3
|
+
* The logged-in user's button and account panel: greeting, role, detail rows,
|
|
4
|
+
* quick actions, an app launcher and a log out action. It holds no auth or
|
|
5
|
+
* routing logic; the app passes the user, the actions and (optionally) a
|
|
6
|
+
* `renderLink` for its router.
|
|
7
|
+
*/
|
|
8
|
+
export declare function AccountPanel({ user, apps, actions, placement, collapsed, appsTitle, greeting, renderLink, className, }: AccountPanelProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface AccountPanelDetail {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AccountPanelUser {
|
|
7
|
+
name: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
role?: string;
|
|
10
|
+
/** Photo URL. Initials are used when absent. */
|
|
11
|
+
avatarUrl?: string | null;
|
|
12
|
+
/** Label/value rows shown under the profile (e.g. School, Academic session). */
|
|
13
|
+
details?: AccountPanelDetail[];
|
|
14
|
+
}
|
|
15
|
+
export type AccountPanelAppTone = 'primary' | 'info' | 'success' | 'warning' | 'danger' | 'neutral';
|
|
16
|
+
export interface AccountPanelApp {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Icon element, e.g. an inline SVG or an icon-library component. */
|
|
21
|
+
icon: ReactNode;
|
|
22
|
+
/** Color of the icon tile. Defaults to `primary`. */
|
|
23
|
+
tone?: AccountPanelAppTone;
|
|
24
|
+
url: string;
|
|
25
|
+
/** The app the panel is rendered in. It opens through `renderLink` (client-side routing) instead of a new tab. */
|
|
26
|
+
current?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface AccountPanelAction {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
icon?: ReactNode;
|
|
32
|
+
/** Internal route (goes through `renderLink`) or external URL (with `external`). Omit for a button. */
|
|
33
|
+
href?: string;
|
|
34
|
+
onClick?: () => void;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
title?: string;
|
|
37
|
+
/** Opens `href` in a new tab as a plain link and shows an external-link hint. */
|
|
38
|
+
external?: boolean;
|
|
39
|
+
/** `danger` actions (e.g. Log out) are listed at the bottom of the panel. */
|
|
40
|
+
tone?: 'default' | 'danger';
|
|
41
|
+
}
|
|
42
|
+
export interface RenderLinkArgs {
|
|
43
|
+
href: string;
|
|
44
|
+
className: string;
|
|
45
|
+
title?: string;
|
|
46
|
+
onClick: () => void;
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
export interface AccountPanelProps {
|
|
50
|
+
user: AccountPanelUser;
|
|
51
|
+
/** Apps shown as a launcher grid. */
|
|
52
|
+
apps?: AccountPanelApp[];
|
|
53
|
+
actions?: AccountPanelAction[];
|
|
54
|
+
/** `header`: round avatar button, panel drops down right-aligned. `sidebar`: full-width user row, panel opens beside it. */
|
|
55
|
+
placement?: 'header' | 'sidebar';
|
|
56
|
+
/** Sidebar only: show the avatar alone. */
|
|
57
|
+
collapsed?: boolean;
|
|
58
|
+
/** Title above the app grid. Defaults to "All Apps". */
|
|
59
|
+
appsTitle?: string;
|
|
60
|
+
/** Greeting word before the first name. Defaults to "Hi". */
|
|
61
|
+
greeting?: string;
|
|
62
|
+
/** Render internal links (current app + internal actions) with your router. Defaults to a plain `<a>`. */
|
|
63
|
+
renderLink?: (args: RenderLinkArgs) => ReactNode;
|
|
64
|
+
className?: string;
|
|
65
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AvatarProps } from './Avatar.types';
|
|
2
|
+
export declare function getInitials(name?: string | null): string;
|
|
3
|
+
/** A photo when available, otherwise initials on a color derived from the name. */
|
|
4
|
+
export declare function Avatar({ name, src, size, tone, className, ...rest }: AvatarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
3
|
+
export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
/** Drives the initials and the fallback color. */
|
|
5
|
+
name?: string | null;
|
|
6
|
+
/** Photo URL. Initials are shown when absent or when it fails to load. */
|
|
7
|
+
src?: string | null;
|
|
8
|
+
/** Defaults to `md` (40px). */
|
|
9
|
+
size?: AvatarSize;
|
|
10
|
+
/**
|
|
11
|
+
* `auto` (default) picks a soft color from the name; `primary` is a solid brand-colored avatar.
|
|
12
|
+
*/
|
|
13
|
+
tone?: 'auto' | 'primary';
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import type { ComponentSize } from '../../types';
|
|
3
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger' | 'link';
|
|
4
|
+
export type ButtonSize = ComponentSize;
|
|
5
|
+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
6
|
+
/** Visual style. Defaults to `primary`. */
|
|
7
|
+
variant?: ButtonVariant;
|
|
8
|
+
/** Defaults to `md`. */
|
|
9
|
+
size?: ButtonSize;
|
|
10
|
+
/** Shows a spinner and disables interaction. */
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
/** Stretch to the width of the container. */
|
|
13
|
+
fullWidth?: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface FormFieldProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'id'> {
|
|
3
|
+
/** The control(s) to wrap, e.g. `<Input />` or `<Select />`. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
label?: ReactNode;
|
|
6
|
+
/** Shows a required indicator and marks the wrapped control as required. */
|
|
7
|
+
required?: boolean;
|
|
8
|
+
helperText?: ReactNode;
|
|
9
|
+
/** Error message. When set, the field is invalid and the message replaces the helper text. */
|
|
10
|
+
error?: ReactNode;
|
|
11
|
+
/** Dims the label and marks the wrapped control as disabled. */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Id for the wrapped control. Generated when omitted. */
|
|
14
|
+
id?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Values a FormField shares with the control it wraps. */
|
|
17
|
+
export interface FormFieldContextValue {
|
|
18
|
+
id: string;
|
|
19
|
+
/** Id of the helper or error element, to be used in `aria-describedby`. */
|
|
20
|
+
describedById?: string;
|
|
21
|
+
/** Id of the label element, when the field has a label. */
|
|
22
|
+
labelId?: string;
|
|
23
|
+
required: boolean;
|
|
24
|
+
disabled: boolean;
|
|
25
|
+
invalid: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface UseFormFieldControlOptions {
|
|
28
|
+
id?: string;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
error?: ReactNode;
|
|
32
|
+
'aria-describedby'?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface FormFieldControlProps {
|
|
35
|
+
id: string;
|
|
36
|
+
required: boolean;
|
|
37
|
+
disabled: boolean;
|
|
38
|
+
invalid: boolean;
|
|
39
|
+
/** Id of the surrounding FormField's label, for `aria-labelledby`. */
|
|
40
|
+
labelId: string | undefined;
|
|
41
|
+
'aria-invalid': true | undefined;
|
|
42
|
+
'aria-describedby': string | undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FormFieldContextValue, FormFieldControlProps, UseFormFieldControlOptions } from './FormField.types';
|
|
2
|
+
export declare const FormFieldContext: import("react").Context<FormFieldContextValue | null>;
|
|
3
|
+
/**
|
|
4
|
+
* Connects a form control to the surrounding FormField (if any) and returns
|
|
5
|
+
* the id / required / disabled / aria props it should apply to its native element.
|
|
6
|
+
* Form controls (Input, Select, future Textarea...) should all use this hook.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useFormFieldControl(options: UseFormFieldControlOptions): FormFieldControlProps;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FormSectionProps } from './FormSection.types';
|
|
2
|
+
/**
|
|
3
|
+
* A titled group of form fields: heading + optional subtitle, a divider line,
|
|
4
|
+
* then the fields in a grid. Use it to split long forms into readable sections.
|
|
5
|
+
*/
|
|
6
|
+
export declare function FormSection({ title, subtitle, children, columns, headingLevel, className, ...rest }: FormSectionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export type FormSectionColumns = 1 | 2 | 3;
|
|
3
|
+
export type FormSectionHeadingLevel = 2 | 3 | 4 | 5 | 6;
|
|
4
|
+
export interface FormSectionProps extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
|
5
|
+
/** Section heading. */
|
|
6
|
+
title?: ReactNode;
|
|
7
|
+
/** Short description under the title. */
|
|
8
|
+
subtitle?: ReactNode;
|
|
9
|
+
/** Fields in the section, laid out in a grid. */
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** Grid columns from the `md` breakpoint up; always 1 column on small screens. Defaults to 1. */
|
|
12
|
+
columns?: FormSectionColumns;
|
|
13
|
+
/** Semantic level of the title element. Defaults to 3. */
|
|
14
|
+
headingLevel?: FormSectionHeadingLevel;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { ComponentSize } from '../../types';
|
|
3
|
+
export type InputSize = ComponentSize;
|
|
4
|
+
export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'prefix' | 'size'> {
|
|
5
|
+
label?: ReactNode;
|
|
6
|
+
helperText?: ReactNode;
|
|
7
|
+
/** Error message. When set, the input is marked invalid. */
|
|
8
|
+
error?: ReactNode;
|
|
9
|
+
/** Content rendered before the text, e.g. a currency symbol or icon. */
|
|
10
|
+
prefix?: ReactNode;
|
|
11
|
+
/** Content rendered after the text, e.g. a unit or icon. */
|
|
12
|
+
suffix?: ReactNode;
|
|
13
|
+
/** Defaults to `md`. */
|
|
14
|
+
size?: InputSize;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SelectProps } from './Select.types';
|
|
2
|
+
/**
|
|
3
|
+
* Select with a popover list, type-to-search, optional multi-select, a clear
|
|
4
|
+
* button and server-side search. Controlled (`value`) or uncontrolled
|
|
5
|
+
* (`defaultValue`). The ref points at the trigger button.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Select: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { ComponentSize } from '../../types';
|
|
3
|
+
export type SelectSize = ComponentSize;
|
|
4
|
+
export interface SelectOption {
|
|
5
|
+
label: string;
|
|
6
|
+
value: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SelectBaseProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'defaultValue' | 'onChange' | 'children' | 'placeholder'> {
|
|
10
|
+
/** Options to choose from. */
|
|
11
|
+
options: SelectOption[];
|
|
12
|
+
label?: ReactNode;
|
|
13
|
+
helperText?: ReactNode;
|
|
14
|
+
/** Error message. When set, the select is marked invalid. */
|
|
15
|
+
error?: ReactNode;
|
|
16
|
+
required?: boolean;
|
|
17
|
+
/** Text shown while nothing is selected. Defaults to "Select an option". */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/** Defaults to `md`. */
|
|
20
|
+
size?: SelectSize;
|
|
21
|
+
/** Submitted with a surrounding `<form>` (one hidden input per value when `multiple`). */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** Show a button to clear the selection. Defaults to `true`. */
|
|
24
|
+
clearable?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Server-side search. When provided, options are not filtered locally: the
|
|
27
|
+
* callback is called (debounced) with the typed text and the parent supplies
|
|
28
|
+
* the matching `options`. Also called once with `""` when the menu opens.
|
|
29
|
+
*/
|
|
30
|
+
onSearch?: (query: string) => void;
|
|
31
|
+
/** Shows a spinner in the menu while options load. */
|
|
32
|
+
loading?: boolean;
|
|
33
|
+
/** Text shown when no option matches. */
|
|
34
|
+
emptyMessage?: string;
|
|
35
|
+
/** Class name for the options list. */
|
|
36
|
+
listClassName?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface SingleSelectProps extends SelectBaseProps {
|
|
39
|
+
multiple?: false;
|
|
40
|
+
value?: string;
|
|
41
|
+
defaultValue?: string;
|
|
42
|
+
onChange?: (value: string) => void;
|
|
43
|
+
}
|
|
44
|
+
export interface MultiSelectProps extends SelectBaseProps {
|
|
45
|
+
multiple: true;
|
|
46
|
+
value?: string[];
|
|
47
|
+
defaultValue?: string[];
|
|
48
|
+
onChange?: (value: string[]) => void;
|
|
49
|
+
}
|
|
50
|
+
export type SelectProps = SingleSelectProps | MultiSelectProps;
|
|
51
|
+
/** Non-union props used inside the component; the public API is the single/multi union above. */
|
|
52
|
+
export interface SelectControlProps extends Omit<SelectBaseProps, 'label' | 'helperText'> {
|
|
53
|
+
multiple?: boolean;
|
|
54
|
+
value?: string | string[];
|
|
55
|
+
defaultValue?: string | string[];
|
|
56
|
+
onChange?: (value: string | string[]) => void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TypographyProps } from './Typography.types';
|
|
2
|
+
/** Themed text. Pick the look with `variant` and the HTML element with `as`. */
|
|
3
|
+
export declare function Typography({ variant, as, color, weight, align, truncate, className, ...rest }: TypographyProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export type TypographyVariant = 'h1' | 'h2' | 'h3' | 'h4' | 'body' | 'body-sm' | 'caption' | 'label';
|
|
3
|
+
export type TypographyColor = 'default' | 'secondary' | 'muted' | 'disabled' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
|
|
4
|
+
export type TypographyWeight = 'normal' | 'medium' | 'semibold' | 'bold';
|
|
5
|
+
export type TypographyAlign = 'start' | 'center' | 'end';
|
|
6
|
+
export type TypographyElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span' | 'div' | 'label' | 'small' | 'strong' | 'em';
|
|
7
|
+
export interface TypographyProps extends HTMLAttributes<HTMLElement> {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
/** Visual style. Defaults to `body`. */
|
|
10
|
+
variant?: TypographyVariant;
|
|
11
|
+
/** Rendered element. Defaults to the semantic element for the variant (e.g. `h1` for `h1`, `p` for `body`). */
|
|
12
|
+
as?: TypographyElement;
|
|
13
|
+
/** Text color token. Defaults to `default`. */
|
|
14
|
+
color?: TypographyColor;
|
|
15
|
+
/** Overrides the weight of the variant. */
|
|
16
|
+
weight?: TypographyWeight;
|
|
17
|
+
align?: TypographyAlign;
|
|
18
|
+
/** Single line with an ellipsis. */
|
|
19
|
+
truncate?: boolean;
|
|
20
|
+
/** Only for `as="label"`. */
|
|
21
|
+
htmlFor?: string;
|
|
22
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("react-dom");function r(...e){return e.filter(Boolean).join(` `)}var i=`client-ui:`;function a(e){let t=i+e.trim(),n=3735928559,r=1103547991;for(let e=0;e<t.length;e++){let i=t.charCodeAt(e);n=Math.imul(n^i,2654435761),r=Math.imul(r^i,1597334677)}return n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(n^n>>>13,3266489909),(4294967296*(2097151&r)+(n>>>0)).toString(16).padStart(14,`0`)}var o=[`1cd9d9bd20471f`],s=``,c=new Set,l=!1,u=(0,e.createContext)(null);function d(e){s=e,l=!1,c.forEach(e=>e())}function f(e){return!e||!e.trim()?!1:o.includes(a(e))}var p=e=>(c.add(e),()=>{c.delete(e)}),m=()=>s;function h(){let t=(0,e.useContext)(u),n=(0,e.useSyncExternalStore)(p,m,m),r=f(t??n);return(0,e.useEffect)(()=>{r||l||(l=!0,console.error(`[client-ui] Missing or invalid license key. Components are disabled. Pass licenseKey to <ThemeProvider> or call setLicenseKey() once at app start.`))},[r]),r}var g={root:`cui-UnlicensedNotice-module__root--FdnRG`};function _(){return(0,t.jsx)(`span`,{role:`alert`,className:g.root,children:`client-ui: missing or invalid license key`})}var v={button:`cui-Button-module__button--2ZuB7`,sm:`cui-Button-module__sm--NhG0g`,md:`cui-Button-module__md--hH4h3`,lg:`cui-Button-module__lg--2plQf`,fullWidth:`cui-Button-module__fullWidth--36oJT`,primary:`cui-Button-module__primary--s1sM6`,secondary:`cui-Button-module__secondary--R0waJ`,outline:`cui-Button-module__outline--F5jq-`,ghost:`cui-Button-module__ghost--1KINV`,danger:`cui-Button-module__danger--V4fX8`,link:`cui-Button-module__link--Zt5hw`,spinner:`cui-Button-module__spinner--ZExvW`,spin:`cui-Button-module__spin--JvkZu`},y=(0,e.forwardRef)(function({variant:e=`primary`,size:n=`md`,loading:i=!1,fullWidth:a=!1,type:o=`button`,disabled:s,className:c,children:l,...u},d){return h()?(0,t.jsxs)(`button`,{...u,ref:d,type:o,disabled:s||i,"aria-busy":i||void 0,"data-variant":e,"data-size":n,className:r(v.button,v[e],v[n],a&&v.fullWidth,c),children:[i?(0,t.jsx)(`span`,{className:v.spinner,"aria-hidden":`true`}):null,l]}):(0,t.jsx)(_,{})}),b=(0,e.createContext)(null);function x(t){let n=(0,e.useContext)(b),r=(0,e.useId)(),i=n?.id??t.id??r,a=!!(t.required??n?.required),o=!!(t.disabled??n?.disabled),s=!!t.error||!!n?.invalid,c=[t[`aria-describedby`],n?.describedById].filter(Boolean).join(` `)||void 0;return{id:i,required:a,disabled:o,invalid:s,labelId:n?.labelId,"aria-invalid":s?!0:void 0,"aria-describedby":c}}var S={root:`cui-FormField-module__root--QkVj-`,label:`cui-FormField-module__label--98wVM`,labelDisabled:`cui-FormField-module__labelDisabled--I5V6c`,required:`cui-FormField-module__required--Erm4t`,message:`cui-FormField-module__message--FUq3k`,helper:`cui-FormField-module__helper--JuBZ6`,error:`cui-FormField-module__error--4SHKr`};function C({children:n,label:i,required:a=!1,helperText:o,error:s,disabled:c=!1,id:l,className:u,...d}){let f=(0,e.useId)(),p=l??f,m=!!s,g=m?`${p}-error`:o?`${p}-helper`:void 0,v=(0,e.useMemo)(()=>({id:p,describedById:g,labelId:i?`${p}-label`:void 0,required:a,disabled:c,invalid:m}),[p,g,i,a,c,m]);return h()?(0,t.jsx)(b.Provider,{value:v,children:(0,t.jsxs)(`div`,{...d,className:r(S.root,u),children:[i?(0,t.jsxs)(`label`,{id:`${p}-label`,htmlFor:p,className:r(S.label,c&&S.labelDisabled),children:[i,a?(0,t.jsx)(`span`,{className:S.required,"aria-hidden":`true`,children:`*`}):null]}):null,n,m?(0,t.jsx)(`p`,{id:g,className:r(S.message,S.error),role:`alert`,children:s}):o?(0,t.jsx)(`p`,{id:g,className:r(S.message,S.helper),children:o}):null]})}):(0,t.jsx)(_,{})}var w={control:`cui-Input-module__control--e3jPo`,disabled:`cui-Input-module__disabled--nzcnQ`,invalid:`cui-Input-module__invalid--VyrnA`,sm:`cui-Input-module__sm--SCPkT`,md:`cui-Input-module__md--weRbk`,lg:`cui-Input-module__lg--ic8a4`,input:`cui-Input-module__input--WjT81`,affix:`cui-Input-module__affix--zz0Xe`,readOnly:`cui-Input-module__readOnly--0ag-W`},T=(0,e.forwardRef)(function({id:e,required:n,disabled:i,error:a,"aria-describedby":o,prefix:s,suffix:c,size:l=`md`,readOnly:u,className:d,...f},p){let m=x({id:e,required:n,disabled:i,error:a,"aria-describedby":o});return(0,t.jsxs)(`div`,{className:r(w.control,w[l],m.invalid&&w.invalid,m.disabled&&w.disabled,u&&w.readOnly,d),children:[s?(0,t.jsx)(`span`,{className:w.affix,children:s}):null,(0,t.jsx)(`input`,{...f,ref:p,id:m.id,required:m.required,disabled:m.disabled,readOnly:u,"aria-invalid":m[`aria-invalid`],"aria-describedby":m[`aria-describedby`],className:w.input}),c?(0,t.jsx)(`span`,{className:w.affix,children:c}):null]})}),E=(0,e.forwardRef)(function({label:e,helperText:n,...r},i){return h()?!e&&!n&&!r.error?(0,t.jsx)(T,{...r,ref:i}):(0,t.jsx)(C,{id:r.id,label:e,helperText:n,error:r.error,required:r.required,disabled:r.disabled,children:(0,t.jsx)(T,{...r,ref:i})}):(0,t.jsx)(_,{})}),D={control:`cui-Select-module__control--OqOfI`,trigger:`cui-Select-module__trigger--ECKfC`,open:`cui-Select-module__open--PADOK`,value:`cui-Select-module__value--7CDNo`,placeholder:`cui-Select-module__placeholder--yUgBU`,sm:`cui-Select-module__sm--TPJwf`,md:`cui-Select-module__md--nOV6u`,lg:`cui-Select-module__lg--NGPOa`,chevron:`cui-Select-module__chevron--PLUsh`,clear:`cui-Select-module__clear--2OgzI`,invalid:`cui-Select-module__invalid--opDrx`,disabled:`cui-Select-module__disabled--8YgjS`,popover:`cui-Select-module__popover--VnWAu`,"cui-select-in":`cui-Select-module__cui-select-in--VGYFd`,top:`cui-Select-module__top--v5FSw`,"cui-select-in-top":`cui-Select-module__cui-select-in-top--fwYA4`,searchWrap:`cui-Select-module__searchWrap--YBOFZ`,search:`cui-Select-module__search--FrUXx`,list:`cui-Select-module__list--CI08p`,option:`cui-Select-module__option--Hvo8n`,optionLabel:`cui-Select-module__optionLabel--FGiUZ`,selected:`cui-Select-module__selected--8A13A`,highlighted:`cui-Select-module__highlighted--YIVPT`,optionDisabled:`cui-Select-module__optionDisabled--FhDw-`,check:`cui-Select-module__check--RxZrV`,empty:`cui-Select-module__empty--KmYrm`,spinner:`cui-Select-module__spinner--OxCAP`,"cui-select-spin":`cui-Select-module__cui-select-spin--MQqaM`},O=4,ee=280,te=500,k=e=>Array.isArray(e)?e:e?[e]:[],A=(0,e.forwardRef)(function({options:i,placeholder:a=`Select an option`,size:o=`md`,multiple:s=!1,clearable:c=!0,onSearch:l,loading:u=!1,emptyMessage:d=`No options found.`,listClassName:f,name:p,value:m,defaultValue:h,onChange:g,id:_,required:v,disabled:y,error:b,"aria-describedby":S,className:C,onKeyDown:w,onClick:T,...E},A){let j=x({id:_,required:v,disabled:y,error:b,"aria-describedby":S}),M=(0,e.useId)(),N=`${M}-list`,P=`${M}-value`,F=e=>`${M}-option-${e}`,I=(0,e.useRef)(null),L=(0,e.useRef)(null),R=(0,e.useRef)(null),z=(0,e.useRef)(null),B=(0,e.useRef)(null),[V,H]=(0,e.useState)(!1),[U,ne]=(0,e.useState)(null),[W,G]=(0,e.useState)(``),[K,q]=(0,e.useState)(!1),[J,Y]=(0,e.useState)(0),X=m!==void 0,[re,Z]=(0,e.useState)(()=>k(h)),Q=X?k(m):re,ie=(0,e.useCallback)(e=>{L.current=e,typeof A==`function`?A(e):A&&(A.current=e)},[A]),$=(0,e.useMemo)(()=>{if(l||!W)return i;let e=W.toLowerCase();return i.filter(t=>t.label.toLowerCase().includes(e))},[i,W,l]),ae=e=>{X||Z(e),g?.(s?e:e[0]??``)},oe=e=>{let t=e.findIndex(e=>!e.disabled);return t===-1?0:t},se=(0,e.useCallback)(()=>{let e=I.current;if(!e)return;let t=e.getBoundingClientRect(),n=window.innerHeight-t.bottom,r=n<ee&&t.top>n?`top`:`bottom`,i={left:t.left,width:t.width};r===`bottom`?i.top=t.bottom+O:i.bottom=window.innerHeight-t.top+O,ne({style:i,placement:r})},[]),ce=()=>{if(j.disabled)return;se(),G(``),q(!1);let e=i.findIndex(e=>Q.includes(e.value));Y(e===-1?oe(i):e),H(!0)},le=(e=!0)=>{H(!1),e&&L.current?.focus({preventScroll:!0})},ue=e=>{e.disabled||(s?ae(Q.includes(e.value)?Q.filter(t=>t!==e.value):[...Q,e.value]):(ae([e.value]),le()),G(``),q(!1))},de=e=>{if(!$.length)return;let t=J;for(let n=0;n<$.length&&(t=(t+e+$.length)%$.length,$[t]?.disabled);n++);Y(t)};(0,e.useEffect)(()=>{V&&z.current?.focus({preventScroll:!0})},[V]),(0,e.useEffect)(()=>{K&&B.current?.focus({preventScroll:!0})},[K]);let fe=(0,e.useRef)(l);(0,e.useEffect)(()=>{fe.current=l},[l]),(0,e.useEffect)(()=>{if(!V||!fe.current)return;let e=setTimeout(()=>fe.current?.(W),te);return()=>clearTimeout(e)},[W,V]),(0,e.useEffect)(()=>{if(!V)return;let e=()=>requestAnimationFrame(se);return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[V,se]),(0,e.useEffect)(()=>{if(!V)return;let e=e=>{let t=e.target;!I.current?.contains(t)&&!R.current?.contains(t)&&H(!1)};return document.addEventListener(`mousedown`,e,!0),()=>document.removeEventListener(`mousedown`,e,!0)},[V]),(0,e.useEffect)(()=>{if(!V)return;let e=z.current,t=e?.children[J];e&&t&&(t.offsetTop<e.scrollTop?e.scrollTop=t.offsetTop:t.offsetTop+t.offsetHeight>e.scrollTop+e.clientHeight&&(e.scrollTop=t.offsetTop+t.offsetHeight-e.clientHeight))},[J,V]);let pe=e=>{w?.(e),!e.defaultPrevented&&!V&&(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),ce())},me=e=>{switch(e.key){case`Escape`:e.preventDefault(),e.stopPropagation(),le();return;case`ArrowDown`:e.preventDefault(),de(1);return;case`ArrowUp`:e.preventDefault(),de(-1);return;case`Home`:if(K)return;e.preventDefault(),Y(oe($));return;case`End`:if(K)return;e.preventDefault(),Y(Math.max($.length-1,0));return;case`Enter`:e.preventDefault(),e.stopPropagation(),$[J]&&ue($[J]);return;case`Tab`:H(!1),L.current?.focus({preventScroll:!0});return;case` `:if(K)return;e.preventDefault(),$[J]&&ue($[J]);return}let t=e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey;!K&&t&&(e.preventDefault(),G(e.key),Y(0),q(!0))},he=i.filter(e=>Q.includes(e.value)),ge=Q.length>0,_e=Q.length>1?`${Q.length} selected`:he[0]?.label??a,ve=c&&ge&&!j.disabled,ye=V?I.current?.closest(`[data-theme]`)?.getAttribute(`data-theme`):void 0,be=V&&$[J]?F(J):void 0,xe=j.labelId?`${j.labelId} ${P}`:void 0;return(0,t.jsxs)(`div`,{ref:I,className:r(D.control,D[o],j.invalid&&D.invalid,j.disabled&&D.disabled,V&&D.open,C),children:[(0,t.jsx)(`button`,{...E,ref:ie,id:j.id,type:`button`,role:`combobox`,"aria-haspopup":`listbox`,"aria-expanded":V,"aria-controls":V?N:void 0,"aria-labelledby":xe,"aria-invalid":j[`aria-invalid`],"aria-describedby":j[`aria-describedby`],"aria-required":j.required||void 0,disabled:j.disabled,className:r(D.trigger,!he.length&&D.placeholder),onClick:e=>{T?.(e),!e.defaultPrevented&&(V?le(!1):ce())},onKeyDown:pe,children:(0,t.jsx)(`span`,{id:P,className:D.value,children:_e})}),ve?(0,t.jsx)(`button`,{type:`button`,className:D.clear,"aria-label":`Clear selection`,onClick:()=>{ae([]),L.current?.focus({preventScroll:!0})},children:(0,t.jsx)(`svg`,{viewBox:`0 0 20 20`,"aria-hidden":`true`,focusable:`false`,children:(0,t.jsx)(`path`,{d:`M6 6l8 8M14 6l-8 8`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})})}):null,(0,t.jsx)(`svg`,{className:D.chevron,viewBox:`0 0 20 20`,"aria-hidden":`true`,focusable:`false`,children:(0,t.jsx)(`path`,{d:`M5 7.5l5 5 5-5`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),p?Q.length>0?Q.map(e=>(0,t.jsx)(`input`,{type:`hidden`,name:p,value:e},e)):!s&&(0,t.jsx)(`input`,{type:`hidden`,name:p,value:``}):null,V&&U?(0,n.createPortal)((0,t.jsxs)(`div`,{ref:R,className:r(D.popover,D[U.placement]),style:U.style,"data-theme":ye??void 0,onKeyDown:me,children:[K?(0,t.jsx)(`div`,{className:D.searchWrap,children:(0,t.jsx)(`input`,{ref:B,type:`text`,className:D.search,placeholder:`Search options...`,"aria-label":`Search options`,"aria-controls":N,"aria-activedescendant":be,autoComplete:`off`,value:W,onChange:e=>{let t=e.target.value;G(t),Y(0),t===``&&(q(!1),z.current?.focus({preventScroll:!0}))}})}):null,(0,t.jsx)(`ul`,{ref:z,id:N,role:`listbox`,tabIndex:-1,"aria-labelledby":xe,"aria-multiselectable":s||void 0,"aria-activedescendant":K?void 0:be,className:r(D.list,f),children:$.length>0?$.map((e,n)=>{let i=Q.includes(e.value);return(0,t.jsxs)(`li`,{id:F(n),role:`option`,"aria-selected":i,"aria-disabled":e.disabled||void 0,className:r(D.option,i&&D.selected,n===J&&D.highlighted,e.disabled&&D.optionDisabled),onMouseEnter:()=>!e.disabled&&Y(n),onClick:()=>ue(e),children:[(0,t.jsx)(`span`,{className:D.optionLabel,children:e.label}),i?(0,t.jsx)(`svg`,{className:D.check,viewBox:`0 0 20 20`,"aria-hidden":`true`,focusable:`false`,children:(0,t.jsx)(`path`,{d:`M4.5 10.5l3.5 3.5 7.5-8`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}):null]},e.value)}):(0,t.jsx)(`li`,{className:D.empty,role:`presentation`,children:u?(0,t.jsx)(`span`,{className:D.spinner,role:`status`,"aria-label":`Loading`}):d})})]}),document.body):null]})}),j=(0,e.forwardRef)(function({label:e,helperText:n,...r},i){if(!h())return(0,t.jsx)(_,{});let a=r;return!e&&!n&&!r.error?(0,t.jsx)(A,{...a,ref:i}):(0,t.jsx)(C,{id:r.id,label:e,helperText:n,error:r.error,required:r.required,disabled:r.disabled,children:(0,t.jsx)(A,{...a,ref:i})})}),M={root:`cui-FormSection-module__root--M70AE`,header:`cui-FormSection-module__header--xTDAF`,heading:`cui-FormSection-module__heading--QU0-u`,title:`cui-FormSection-module__title--cw5qX`,subtitle:`cui-FormSection-module__subtitle--cIB53`,divider:`cui-FormSection-module__divider--954nY`,fields:`cui-FormSection-module__fields--ALVzc`,columns2:`cui-FormSection-module__columns2--IgG6n`,columns3:`cui-FormSection-module__columns3--q-4XF`};function N({title:n,subtitle:i,children:a,columns:o=1,headingLevel:s=3,className:c,...l}){let u=(0,e.useId)(),d=!!(n||i);return h()?(0,t.jsxs)(`section`,{...l,"aria-labelledby":n?u:l[`aria-labelledby`],className:r(M.root,c),children:[d?(0,t.jsxs)(`div`,{className:M.header,children:[(0,t.jsxs)(`div`,{className:M.heading,children:[n?(0,e.createElement)(`h${s}`,{id:u,className:M.title},n):null,i?(0,t.jsx)(`p`,{className:M.subtitle,children:i}):null]}),(0,t.jsx)(`span`,{className:M.divider,"aria-hidden":`true`})]}):null,(0,t.jsx)(`div`,{className:r(M.fields,M[`columns${o}`]),children:a})]}):(0,t.jsx)(_,{})}var P={root:`cui-Avatar-module__root--fXu-J`,xs:`cui-Avatar-module__xs--oSaLL`,sm:`cui-Avatar-module__sm--sZ2bk`,md:`cui-Avatar-module__md--Fdkbz`,lg:`cui-Avatar-module__lg--pTTUA`,xl:`cui-Avatar-module__xl--mW58F`,image:`cui-Avatar-module__image--ieqGp`,fallback:`cui-Avatar-module__fallback--BWBXY`,tone0:`cui-Avatar-module__tone0--NoD23`,tone1:`cui-Avatar-module__tone1--xFqRb`,tone2:`cui-Avatar-module__tone2--nxsRe`,tone3:`cui-Avatar-module__tone3--goa6z`,tone4:`cui-Avatar-module__tone4--g6kRy`,primary:`cui-Avatar-module__primary--HKPgn`},F=[P.tone0,P.tone1,P.tone2,P.tone3,P.tone4];function I(e){let t=(e??``).trim().split(/\s+/).filter(Boolean);return t.length===0?``:((t[0]?.[0]??``)+(t.length>1?t[t.length-1]?.[0]??``:``)).toUpperCase()}function L(e){let t=e??``,n=0;for(let e=0;e<t.length;e++)n=n*31+t.charCodeAt(e)>>>0;return F[n%F.length]}function R({name:n,src:i,size:a=`md`,tone:o=`auto`,className:s,...c}){let[l,u]=(0,e.useState)(null),d=!!i&&i!==l,f=I(n);return h()?(0,t.jsx)(`span`,{role:c[`aria-hidden`]?void 0:`img`,"aria-label":c[`aria-hidden`]||!n?void 0:n,...c,className:r(P.root,P[a],!d&&(o===`primary`?P.primary:L(n)),s),children:d?(0,t.jsx)(`img`,{className:P.image,src:i??void 0,alt:``,onError:()=>u(i??null)}):f?(0,t.jsx)(`span`,{"aria-hidden":`true`,children:f}):(0,t.jsxs)(`svg`,{className:P.fallback,viewBox:`0 0 24 24`,"aria-hidden":`true`,focusable:`false`,children:[(0,t.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`,fill:`currentColor`}),(0,t.jsx)(`path`,{d:`M4 21c0-4.4 3.6-7 8-7s8 2.6 8 7z`,fill:`currentColor`})]})}):(0,t.jsx)(_,{})}var z={root:`cui-AccountPanel-module__root--Twbp0`,rootSidebar:`cui-AccountPanel-module__rootSidebar--OMB7L`,contents:`cui-AccountPanel-module__contents--OFL-r`,triggerHeader:`cui-AccountPanel-module__triggerHeader--ib8Bi`,triggerOpen:`cui-AccountPanel-module__triggerOpen--NbT3m`,triggerSidebar:`cui-AccountPanel-module__triggerSidebar--FeaXc`,collapsed:`cui-AccountPanel-module__collapsed--c8z-m`,identityText:`cui-AccountPanel-module__identityText--eziAT`,triggerName:`cui-AccountPanel-module__triggerName--f56mY`,triggerRole:`cui-AccountPanel-module__triggerRole--KpeeO`,panel:`cui-AccountPanel-module__panel--PinlA`,"cui-account-in":`cui-AccountPanel-module__cui-account-in--QVNEb`,panelSidebar:`cui-AccountPanel-module__panelSidebar--EuGZh`,identity:`cui-AccountPanel-module__identity--lZRA7`,email:`cui-AccountPanel-module__email--Ze3OW`,avatarRing:`cui-AccountPanel-module__avatarRing--FQrz4`,avatarInner:`cui-AccountPanel-module__avatarInner--5ZfEz`,greeting:`cui-AccountPanel-module__greeting--am-j3`,role:`cui-AccountPanel-module__role--E9lrf`,pills:`cui-AccountPanel-module__pills--5gSce`,pill:`cui-AccountPanel-module__pill--vK7aC`,actionIcon:`cui-AccountPanel-module__actionIcon--oReIE`,externalIcon:`cui-AccountPanel-module__externalIcon--dJc16`,details:`cui-AccountPanel-module__details--MGxxd`,detailRow:`cui-AccountPanel-module__detailRow--VzvVD`,apps:`cui-AccountPanel-module__apps--KRMBA`,appsTitle:`cui-AccountPanel-module__appsTitle--mcvnH`,grid:`cui-AccountPanel-module__grid--KYmem`,app:`cui-AccountPanel-module__app--Dj--X`,tile:`cui-AccountPanel-module__tile--YKNda`,tonePrimary:`cui-AccountPanel-module__tonePrimary--lAexZ`,toneInfo:`cui-AccountPanel-module__toneInfo--yb-xj`,toneSuccess:`cui-AccountPanel-module__toneSuccess--XIJic`,toneWarning:`cui-AccountPanel-module__toneWarning--oz2d6`,toneDanger:`cui-AccountPanel-module__toneDanger--MP2rJ`,toneNeutral:`cui-AccountPanel-module__toneNeutral--diEHz`,appName:`cui-AccountPanel-module__appName--MJc25`,danger:`cui-AccountPanel-module__danger--t0t-L`,dangerAction:`cui-AccountPanel-module__dangerAction--jvJ7-`},B=8,V=12,H=352,U=`a[href], button:not([disabled])`,ne=({href:e,className:n,title:r,onClick:i,children:a})=>(0,t.jsx)(`a`,{href:e,className:n,title:r,onClick:i,children:a}),W={primary:z.tonePrimary,info:z.toneInfo,success:z.toneSuccess,warning:z.toneWarning,danger:z.toneDanger,neutral:z.toneNeutral};function G(){return(0,t.jsx)(`svg`,{className:z.externalIcon,viewBox:`0 0 20 20`,"aria-hidden":`true`,focusable:`false`,children:(0,t.jsx)(`path`,{d:`M8 5H5v10h10v-3M11 5h4v4M15 5l-7 7`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function K({user:i,apps:a=[],actions:o=[],placement:s=`header`,collapsed:c=!1,appsTitle:l=`All Apps`,greeting:u=`Hi`,renderLink:d=ne,className:f}){let p=s===`sidebar`,m=(0,e.useId)(),g=(0,e.useRef)(null),v=(0,e.useRef)(null),y=(0,e.useRef)(null),[b,x]=(0,e.useState)(!1),[S,C]=(0,e.useState)(null),[w,T]=(0,e.useState)(),E=()=>{let e=v.current;if(!e)return;let t=e.getBoundingClientRect();if(p){let e=Math.min(H,window.innerWidth-24);C({left:Math.max(V,Math.min(t.right+B,window.innerWidth-e-V)),bottom:Math.max(V,window.innerHeight-t.bottom)})}else C({top:t.bottom+B,right:Math.max(V,window.innerWidth-t.right)})},D=()=>{E(),T(g.current?.closest(`[data-theme]`)?.getAttribute(`data-theme`)??void 0),x(!0)},O=()=>x(!1);(0,e.useEffect)(()=>{b&&y.current?.focus({preventScroll:!0})},[b]),(0,e.useEffect)(()=>{if(!b)return;let e=()=>requestAnimationFrame(E),t=e=>{let t=e.target;!g.current?.contains(t)&&!y.current?.contains(t)&&O()};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),document.addEventListener(`mousedown`,t,!0),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e),document.removeEventListener(`mousedown`,t,!0)}},[b,p]);let ee=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),O(),v.current?.focus({preventScroll:!0});return}if(e.key!==`Tab`)return;let t=Array.from(y.current?.querySelectorAll(U)??[]),n=t[0],r=t[t.length-1];n&&r&&(e.shiftKey&&(document.activeElement===n||document.activeElement===y.current)?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus()))};if(!h())return(0,t.jsx)(_,{});let te=i.name.trim().split(/\s+/)[0]??i.name,k=o.filter(e=>e.tone!==`danger`),A=o.filter(e=>e.tone===`danger`),j=e=>{e.onClick?.(),O()},M=(0,t.jsxs)(`div`,{ref:y,id:m,role:`dialog`,"aria-label":`Account`,tabIndex:-1,className:r(z.panel,p&&z.panelSidebar),style:S??void 0,"data-theme":w,onKeyDown:ee,children:[(0,t.jsxs)(`div`,{className:z.identity,children:[i.email?(0,t.jsx)(`p`,{className:z.email,children:i.email}):null,(0,t.jsx)(`span`,{className:z.avatarRing,children:(0,t.jsx)(`span`,{className:z.avatarInner,children:(0,t.jsx)(R,{name:i.name,src:i.avatarUrl,size:`xl`,tone:`primary`,"aria-hidden":`true`})})}),(0,t.jsxs)(`p`,{className:z.greeting,children:[u,`, `,te,`!`]}),i.role?(0,t.jsx)(`span`,{className:z.role,children:i.role}):null,k.length>0?(0,t.jsx)(`div`,{className:z.pills,children:k.map(e=>{let n=(0,t.jsxs)(t.Fragment,{children:[e.icon?(0,t.jsx)(`span`,{className:z.actionIcon,"aria-hidden":`true`,children:e.icon}):null,(0,t.jsx)(`span`,{children:e.label}),e.external?(0,t.jsx)(G,{}):null]});return e.href&&!e.disabled?e.external?(0,t.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,title:e.title,className:z.pill,onClick:()=>O(),children:n},e.id):(0,t.jsx)(`span`,{className:z.contents,children:d({href:e.href,className:z.pill??``,title:e.title,onClick:()=>O(),children:n})},e.id):(0,t.jsx)(`button`,{type:`button`,disabled:e.disabled,title:e.title,className:z.pill,onClick:()=>j(e),children:n},e.id)})}):null]}),i.details?.length?(0,t.jsx)(`dl`,{className:z.details,children:i.details.map(e=>(0,t.jsxs)(`div`,{className:z.detailRow,children:[(0,t.jsx)(`dt`,{children:e.label}),(0,t.jsx)(`dd`,{children:e.value})]},e.label))}):null,a.length>0?(0,t.jsxs)(`section`,{className:z.apps,"aria-label":l,children:[(0,t.jsx)(`p`,{className:z.appsTitle,children:l}),(0,t.jsx)(`div`,{className:z.grid,children:a.map(e=>{let n=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`span`,{className:r(z.tile,W[e.tone??`primary`]),"aria-hidden":`true`,children:e.icon}),(0,t.jsx)(`span`,{className:z.appName,children:e.name})]});return e.current?(0,t.jsx)(`span`,{className:z.contents,children:d({href:e.url,className:z.app??``,title:e.description,onClick:()=>O(),children:n})},e.id):(0,t.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,title:e.description,className:z.app,children:n},e.id)})})]}):null,A.length>0?(0,t.jsx)(`div`,{className:z.danger,children:A.map(e=>(0,t.jsxs)(`button`,{type:`button`,disabled:e.disabled,title:e.title,className:z.dangerAction,onClick:()=>j(e),children:[e.icon?(0,t.jsx)(`span`,{className:z.actionIcon,"aria-hidden":`true`,children:e.icon}):null,e.label]},e.id))}):null]});return(0,t.jsxs)(`div`,{ref:g,className:r(z.root,p&&z.rootSidebar,f),children:[(0,t.jsxs)(`button`,{ref:v,type:`button`,"aria-label":`Account: ${i.name}`,"aria-haspopup":`dialog`,"aria-expanded":b,"aria-controls":b?m:void 0,className:r(p?z.triggerSidebar:z.triggerHeader,p&&c&&z.collapsed,b&&z.triggerOpen),onClick:()=>b?O():D(),children:[(0,t.jsx)(R,{name:i.name,src:i.avatarUrl,size:`sm`,tone:`primary`,"aria-hidden":`true`}),p&&!c?(0,t.jsxs)(`span`,{className:z.identityText,children:[(0,t.jsx)(`span`,{className:z.triggerName,children:i.name}),i.role?(0,t.jsx)(`span`,{className:z.triggerRole,children:i.role}):null]}):null]}),b&&S?(0,n.createPortal)(M,document.body):null]})}var q={root:`cui-Typography-module__root--PebSf`,h1:`cui-Typography-module__h1--pJqnF`,h2:`cui-Typography-module__h2--8YqGv`,h3:`cui-Typography-module__h3--DT-DL`,h4:`cui-Typography-module__h4--UsocF`,body:`cui-Typography-module__body--s-YlR`,bodySm:`cui-Typography-module__bodySm--RPpZ5`,caption:`cui-Typography-module__caption--K-n4O`,label:`cui-Typography-module__label---CGg4`,"color-default":`cui-Typography-module__color-default--U4Xg0`,"color-secondary":`cui-Typography-module__color-secondary--5wnuV`,"color-muted":`cui-Typography-module__color-muted--GLLRl`,"color-disabled":`cui-Typography-module__color-disabled--bBBVc`,"color-primary":`cui-Typography-module__color-primary--B-bVH`,"color-success":`cui-Typography-module__color-success--hXHcS`,"color-warning":`cui-Typography-module__color-warning---oLwA`,"color-danger":`cui-Typography-module__color-danger--sStkk`,"color-info":`cui-Typography-module__color-info--4uSt5`,"weight-normal":`cui-Typography-module__weight-normal--fFcMp`,"weight-medium":`cui-Typography-module__weight-medium--5RtTe`,"weight-semibold":`cui-Typography-module__weight-semibold--TDOgV`,"weight-bold":`cui-Typography-module__weight-bold--YahG3`,"align-start":`cui-Typography-module__align-start--mX51I`,"align-center":`cui-Typography-module__align-center--2Ng2u`,"align-end":`cui-Typography-module__align-end--6LwA3`,truncate:`cui-Typography-module__truncate--3B0O4`},J={h1:`h1`,h2:`h2`,h3:`h3`,h4:`h4`,body:`p`,"body-sm":`p`,caption:`span`,label:`span`},Y={h1:q.h1,h2:q.h2,h3:q.h3,h4:q.h4,body:q.body,"body-sm":q.bodySm,caption:q.caption,label:q.label};function X({variant:n=`body`,as:i,color:a=`default`,weight:o,align:s,truncate:c=!1,className:l,...u}){return h()?(0,e.createElement)(i??J[n],{...u,className:r(q.root,Y[n],q[`color-${a}`],o&&q[`weight-${o}`],s&&q[`align-${s}`],c&&q.truncate,l)}):(0,t.jsx)(_,{})}var re={root:`cui-ThemeProvider-module__root--2DEGi`},Z=(0,e.createContext)(null);function Q({children:n,theme:i,defaultTheme:a=`light`,onThemeChange:o,licenseKey:s,className:c,...l}){let[d,f]=(0,e.useState)(a),p=i??d,m=(0,e.useCallback)(e=>{i===void 0&&f(e),o?.(e)},[i,o]),h=(0,e.useMemo)(()=>({theme:p,setTheme:m}),[p,m]),g=(0,e.useContext)(u);return(0,t.jsx)(Z.Provider,{value:h,children:(0,t.jsx)(u.Provider,{value:s??g,children:(0,t.jsx)(`div`,{...l,"data-theme":p,className:r(re.root,c),children:n})})})}function ie(){let t=(0,e.useContext)(Z);if(!t)throw Error(`useTheme must be used within a <ThemeProvider>.`);return t}exports.AccountPanel=K,exports.Avatar=R,exports.Button=y,exports.FormField=C,exports.FormSection=N,exports.Input=E,exports.Select=j,exports.ThemeProvider=Q,exports.Typography=X,exports.cn=r,exports.getInitials=I,exports.setLicenseKey=d,exports.useFormFieldControl=x,exports.useTheme=ie;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|