@capra/core 1.5.3 → 1.6.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/dist/index.cjs +23 -23
- package/dist/index.d.cts +9 -9
- package/dist/index.d.mts +9 -9
- package/dist/index.mjs +23 -23
- package/dist/style.css +62 -32
- package/docs/conventions--docs.md +186 -0
- package/docs/core-alert--design.md +110 -0
- package/docs/core-alert--usage.md +13 -0
- package/docs/core-anchor--design.md +39 -0
- package/docs/core-anchor--usage.md +39 -0
- package/docs/core-autocompletefield--design.md +91 -0
- package/docs/core-autocompletefield--usage.md +18 -0
- package/docs/core-badge--design.md +70 -0
- package/docs/core-badge--usage.md +13 -0
- package/docs/core-breadcrumbs--design.md +65 -0
- package/docs/core-breadcrumbs--usage.md +16 -0
- package/docs/core-button--design.md +97 -0
- package/docs/core-button--usage.md +17 -0
- package/docs/core-buttonlink--design.md +7 -0
- package/docs/core-buttonlink--usage.md +24 -0
- package/docs/core-card--design.md +100 -0
- package/docs/core-card--usage.md +5 -0
- package/docs/core-checkbox--design.md +66 -0
- package/docs/core-checkbox--usage.md +34 -0
- package/docs/core-collapse--design.md +28 -0
- package/docs/core-collapse--usage.md +20 -0
- package/docs/core-datepickerfield--design.md +71 -0
- package/docs/core-datepickerfield--usage.md +57 -0
- package/docs/core-daterangepickerfield--design.md +76 -0
- package/docs/core-daterangepickerfield--usage.md +62 -0
- package/docs/core-divider--design.md +35 -0
- package/docs/core-divider--usage.md +8 -0
- package/docs/core-drawer--design.md +87 -0
- package/docs/core-drawer--usage.md +9 -0
- package/docs/core-emptystate--design.md +45 -0
- package/docs/core-emptystate--usage.md +13 -0
- package/docs/core-helpertext--design.md +30 -0
- package/docs/core-helpertext--usage.md +11 -0
- package/docs/core-iconbutton--design.md +87 -0
- package/docs/core-iconbutton--usage.md +15 -0
- package/docs/core-inputrow--design.md +85 -0
- package/docs/core-inputrow--usage.md +6 -0
- package/docs/core-label--design.md +27 -0
- package/docs/core-label--usage.md +17 -0
- package/docs/core-link--design.md +58 -0
- package/docs/core-link--usage.md +16 -0
- package/docs/core-listitem--design.md +70 -0
- package/docs/core-listitem--usage.md +6 -0
- package/docs/core-menu--design.md +106 -0
- package/docs/core-menu--usage.md +16 -0
- package/docs/core-modal--design.md +39 -0
- package/docs/core-modal--usage.md +11 -0
- package/docs/core-numberfield--design.md +12 -0
- package/docs/core-numberfield--usage.md +14 -0
- package/docs/core-pagination--design.md +30 -0
- package/docs/core-pagination--usage.md +13 -0
- package/docs/core-passwordfield--design.md +7 -0
- package/docs/core-passwordfield--usage.md +3 -0
- package/docs/core-pill--design.md +94 -0
- package/docs/core-pill--usage.md +10 -0
- package/docs/core-popover--design.md +25 -0
- package/docs/core-popover--usage.md +8 -0
- package/docs/core-radio--design.md +39 -0
- package/docs/core-radio--usage.md +8 -0
- package/docs/core-radiogroup--design.md +5 -0
- package/docs/core-radiogroup--usage.md +12 -0
- package/docs/core-radiotile--design.md +5 -0
- package/docs/core-radiotile--usage.md +10 -0
- package/docs/core-ribbon--design.md +39 -0
- package/docs/core-ribbon--usage.md +12 -0
- package/docs/core-skeleton--design.md +88 -0
- package/docs/core-skeleton--usage.md +13 -0
- package/docs/core-skeletongroup--design.md +50 -0
- package/docs/core-skeletongroup--usage.md +10 -0
- package/docs/core-spinner--design.md +99 -0
- package/docs/core-spinner--usage.md +11 -0
- package/docs/core-switch--design.md +145 -0
- package/docs/core-switch--usage.md +8 -0
- package/docs/core-tabnav--design.md +77 -0
- package/docs/core-tabnav--usage.md +63 -0
- package/docs/core-tag--design.md +21 -0
- package/docs/core-tag--usage.md +11 -0
- package/docs/core-text--design.md +32 -0
- package/docs/core-text--usage.md +10 -0
- package/docs/core-textarea--design.md +74 -0
- package/docs/core-textarea--usage.md +18 -0
- package/docs/core-textfield--design.md +81 -0
- package/docs/core-textfield--usage.md +12 -0
- package/docs/core-textinput--design.md +72 -0
- package/docs/core-textinput--usage.md +19 -0
- package/docs/core-toast--design.md +100 -0
- package/docs/core-toast--usage.md +11 -0
- package/docs/core-tooltip--design.md +61 -0
- package/docs/core-tooltip--usage.md +48 -0
- package/docs/core-topnav--design.md +75 -0
- package/docs/core-topnav--usage.md +6 -0
- package/docs/core-verticalnavigation--design.md +31 -0
- package/docs/core-verticalnavigation--usage.md +17 -0
- package/docs/core-visuallyhidden--design.md +87 -0
- package/docs/core-visuallyhidden--usage.md +35 -0
- package/docs/history-changelogs-capra-core--docs.md +49 -0
- package/docs/index.md +110 -0
- package/docs/using-capra--docs.md +39 -0
- package/package.json +5 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Conventions
|
|
2
|
+
|
|
3
|
+
When building and consuming Capra components, we follow specific conventions to maintain a healthy codebase.
|
|
4
|
+
|
|
5
|
+
### Semantic Properties
|
|
6
|
+
|
|
7
|
+
Certain properties of Capra components have well-defined, consistent uses.
|
|
8
|
+
|
|
9
|
+
| Prop | Purpose | Possible Values |
|
|
10
|
+
| ------------ | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------- |
|
|
11
|
+
| `appearance` | Change the colors of a component using semantic intent, e.g. a danger `Button` when deleting | `default`, `info`, `danger`, `warning`, `success`, `highlight` |
|
|
12
|
+
| `color` | Change the color of a component to a specific color, e.g. a teal `Ribbon` | Component-specific |
|
|
13
|
+
| `layout` | Alter the component's layout, e.g. a horizontal input field with label | Component-specific |
|
|
14
|
+
| `size` | Specify the size of the component | `xs`, `sm`, `md`, `lg`, `xl` |
|
|
15
|
+
| `variant` | Specify a different visual treatment for the component, e.g. a dot `Badge` vs. a counter `Badge` | Component-specific |
|
|
16
|
+
|
|
17
|
+
For props where the possible values are pre-defined, a component may utilize the full set or a subset of the possible values.
|
|
18
|
+
|
|
19
|
+
### Styling Overrides
|
|
20
|
+
|
|
21
|
+
Capra components are built according to our design system specifications. They should rarely need to be styled differently than what is provided out-of-the-box. In the event custom styling is required, we provide a consistent escape hatch across all of our components for passing a CSS class name: `FORCE__className`.
|
|
22
|
+
|
|
23
|
+
In your application, you can apply a style override like this:
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { Text } from '@capra/core';
|
|
27
|
+
import styles from './Component.modules.css';
|
|
28
|
+
|
|
29
|
+
export function Component(props) {
|
|
30
|
+
return <Text FORCE__className={styles.text}>Hello world</Text>;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Note that using this prop should be a rarity. Adding styles here is also somewhat brittle. While we do provide this escape hatch, we make no guarantees that the styles applied will apply correctly across version updates, e.g. a style override targeting a specific HTML structure within a Capra component breaks because the component was refactored to use a different HTML structure. The inner workings of Capra components are implementation details and this escape hatch gives one access to those implementation details. Please use it responsibly.
|
|
35
|
+
|
|
36
|
+
## Client-side Routing
|
|
37
|
+
|
|
38
|
+
Capra components such as `Link` and `ButtonLink` render links that perform navigation when the user interacts with them. Each component that supports link behavior accepts an `href` prop, which is passed to the underlying `<a>` element.
|
|
39
|
+
|
|
40
|
+
By default, links perform native browser navigation when they are interacted with. However, Capra supports overriding this behavior using a client-side router of your choice. Set this up once in the root of your app, and any Capra link component will automatically navigate using your router.
|
|
41
|
+
|
|
42
|
+
Note that external links to different origins will not trigger client side routing, and will use native browser navigation. Additionally, if the link has a target other than `"_self"`, uses the `download` attribute, or the user presses modifier keys such as `Command` or `Alt` to change the default behavior, browser native navigation will occur instead of client side routing.
|
|
43
|
+
|
|
44
|
+
### `RouterProvider`
|
|
45
|
+
|
|
46
|
+
The `RouterProvider` component accepts two props: `navigate` and `useHref`. `navigate` should be set to a function received from your router for performing a client side navigation programmatically. `useHref` is an optional prop that converts a router-specific href to a native HTML href, e.g. prepending a base path. The following example shows the general pattern. Framework-specific examples are shown below.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import {RouterProvider} from '@capra/core';
|
|
50
|
+
import {useNavigate, useHref} from 'your-router';
|
|
51
|
+
|
|
52
|
+
function App() {
|
|
53
|
+
const navigate = useNavigate();
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<RouterProvider navigate={navigate} useHref={useHref}>
|
|
57
|
+
{/* ... */}
|
|
58
|
+
</RouterProvider>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Router Options
|
|
64
|
+
|
|
65
|
+
All Capra link components accept a `routerOptions` prop, which is an object that is passed through to the client side router's `navigate` function as the second argument. This can be used to control any router-specific behaviors, such as scrolling, replacing instead of pushing to the history, etc.
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
<Link href="/login" routerOptions={{replace: true}}>{/* ...*/}</Link>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
When using TypeScript, you can configure the `RouterConfig` type globally so that all link components have auto complete and type safety using a type provided by your router.
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import type {RouterOptions} from 'your-router';
|
|
75
|
+
|
|
76
|
+
declare module '@capra/core' {
|
|
77
|
+
interface RouterConfig {
|
|
78
|
+
routerOptions: RouterOptions
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### React Router
|
|
84
|
+
|
|
85
|
+
The [useNavigate](https://reactrouter.com/en/main/hooks/use-navigate) hook from `react-router-dom` returns a `navigate` function you can pass to `RouterProvider`. The [useHref](https://reactrouter.com/en/main/hooks/use-href) hook can also be provided if you're using React Router's `basename` option. Ensure that the component that calls `useNavigate` and renders `RouterProvider` is inside the router component (e.g. `BrowserRouter`) so that it has access to React Router's internal context. The React Router `<Routes>` element should also be defined inside Capra's `<RouterProvider>` so that links inside the rendered routes have access to the router.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import {BrowserRouter, useNavigate, useHref, type NavigateOptions} from 'react-router-dom';
|
|
89
|
+
import {RouterProvider} from '@capra/core';
|
|
90
|
+
|
|
91
|
+
declare module '@capra/core' {
|
|
92
|
+
interface RouterConfig {
|
|
93
|
+
routerOptions: NavigateOptions
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function App() {
|
|
98
|
+
const navigate = useNavigate();
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<RouterProvider navigate={navigate} useHref={useHref}>
|
|
102
|
+
{/* Your app here... */}
|
|
103
|
+
<Routes>
|
|
104
|
+
<Route path="/" element={<HomePage />} />
|
|
105
|
+
{/* ... */}
|
|
106
|
+
</Routes>
|
|
107
|
+
</RouterProvider>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
<BrowserRouter>
|
|
112
|
+
<App />
|
|
113
|
+
</BrowserRouter>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Next.js App Router
|
|
117
|
+
|
|
118
|
+
The [useRouter](https://nextjs.org/docs/app/api-reference/functions/use-router) hook from `next/navigation` returns a router object that can be used to perform navigation. `RouterProvider` should be rendered from a client component at the root of each page or layout that includes Capra links. You can create a new client component for this, or combine it with other top-level providers as described in the [Next.js docs](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers).
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
// app/provider.tsx
|
|
122
|
+
"use client";
|
|
123
|
+
|
|
124
|
+
import {useRouter} from 'next/navigation';
|
|
125
|
+
import {RouterProvider} from '@capra/core';
|
|
126
|
+
|
|
127
|
+
declare module '@capra/core' {
|
|
128
|
+
interface RouterConfig {
|
|
129
|
+
routerOptions: NonNullable<Parameters<ReturnType<typeof useRouter>['push']>[1]>
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function ClientProviders({children}) {
|
|
134
|
+
const router = useRouter();
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<RouterProvider navigate={router.push}>
|
|
138
|
+
{children}
|
|
139
|
+
</RouterProvider>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Then, in your page or layout server component, wrap your app in the `ClientProviders` component that you defined.
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
// app/layout.tsx
|
|
148
|
+
import {ClientProviders} from './provider';
|
|
149
|
+
|
|
150
|
+
export default function RootLayout({children}) {
|
|
151
|
+
return (
|
|
152
|
+
<html>
|
|
153
|
+
<body>
|
|
154
|
+
<ClientProviders>{children}</ClientProviders>
|
|
155
|
+
</body>
|
|
156
|
+
</html>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Next.js Pages Router
|
|
162
|
+
|
|
163
|
+
The [useRouter](https://nextjs.org/docs/pages/api-reference/functions/use-router) hook from `next/router` returns a router object that can be used to perform navigation. `RouterProvider` should be rendered at the root of each page that includes Capra links, or in `pages/_app.tsx` to add it to all pages.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
// pages/_app.tsx
|
|
167
|
+
import type { AppProps } from 'next/app';
|
|
168
|
+
import {useRouter, type NextRouter} from 'next/router';
|
|
169
|
+
import {RouterProvider} from '@capra/core';
|
|
170
|
+
|
|
171
|
+
declare module '@capra/core' {
|
|
172
|
+
interface RouterConfig {
|
|
173
|
+
routerOptions: NonNullable<Parameters<NextRouter['push']>[2]>
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export default function MyApp({Component, pageProps}: AppProps) {
|
|
178
|
+
const router = useRouter();
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<RouterProvider navigate={(href, opts) => router.push(href, undefined, opts)}>
|
|
182
|
+
<Component {...pageProps} />
|
|
183
|
+
</RouterProvider>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Core/Alert - Design
|
|
2
|
+
|
|
3
|
+
Alerts are used to communicate important information to the user.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Use an Alert to surface contextual feedback in the page: the outcome of an action (success or failure), a condition that needs attention before the user continues, or information that should stay visible while they keep working in the same view.
|
|
8
|
+
|
|
9
|
+
Keep alerts scoped to the page or region they refer to. Prefer one alert per region so the message stays easy to scan; when several conditions apply at once, combine them into a single alert when it makes sense.
|
|
10
|
+
|
|
11
|
+
## Properties
|
|
12
|
+
|
|
13
|
+
### Appearances
|
|
14
|
+
|
|
15
|
+
### Info
|
|
16
|
+
|
|
17
|
+
General information like recommend actions to accelerate a user's workflow, helpful information, or tips.
|
|
18
|
+
|
|
19
|
+
### Error
|
|
20
|
+
|
|
21
|
+
Problems that must be resolved before the user can complete a task, such as an error on a form.
|
|
22
|
+
|
|
23
|
+
### Warning
|
|
24
|
+
|
|
25
|
+
Notify users of cautionary/temporary information affecting the user's workflow, but does not block a user from
|
|
26
|
+
completing the action or workflow.
|
|
27
|
+
|
|
28
|
+
### Success
|
|
29
|
+
|
|
30
|
+
Brings special attention to the user that an action has been completed, or a status has been updated.
|
|
31
|
+
|
|
32
|
+
### Layout
|
|
33
|
+
|
|
34
|
+
### Section
|
|
35
|
+
|
|
36
|
+
Section notifications communicate the status of a section to the user.
|
|
37
|
+
|
|
38
|
+
### Inline
|
|
39
|
+
|
|
40
|
+
Inline notifications are low-priority messages about a single element, like a tile or row item.
|
|
41
|
+
|
|
42
|
+
### Additional properties
|
|
43
|
+
|
|
44
|
+
### Title
|
|
45
|
+
|
|
46
|
+
A title is recommended, but optional. Use a title to quickly summarize the purpose of the notification. Keep titles
|
|
47
|
+
short, no more than 60 characters, and avoid repeating the body text.
|
|
48
|
+
|
|
49
|
+
### Body
|
|
50
|
+
|
|
51
|
+
The body text is required for all notifications. If the notification is actionable, the text should inform the user
|
|
52
|
+
of the next step.
|
|
53
|
+
|
|
54
|
+
### Action
|
|
55
|
+
|
|
56
|
+
Actionable notifications are recommended to help the user resolve the issue.
|
|
57
|
+
|
|
58
|
+
### Dismiss
|
|
59
|
+
|
|
60
|
+
Alert banners can include a dismiss button that removes the notice from the page layout. Error banners can not be
|
|
61
|
+
dismissed.
|
|
62
|
+
|
|
63
|
+
## Layout and spacing
|
|
64
|
+
|
|
65
|
+
* Alerts span the full width of their container.
|
|
66
|
+
|
|
67
|
+
## Behavior
|
|
68
|
+
|
|
69
|
+
* Alerts are static by default; they do not auto-dismiss.
|
|
70
|
+
* If the user triggers an action that resolves the alert condition, remove the alert programmatically.
|
|
71
|
+
* When an alert is injected into the DOM, announce it to screen readers via `aria-live`.
|
|
72
|
+
|
|
73
|
+
## Content
|
|
74
|
+
|
|
75
|
+
* Title: sentence case, no trailing punctuation, max 60 characters.
|
|
76
|
+
* Body: one to two sentences. State the problem and the resolution path. Use punctuation.
|
|
77
|
+
* Action label: verb-first, 1-3 words (e.g., "Retry", "View details").
|
|
78
|
+
* Avoid technical jargon in user-facing alert text.
|
|
79
|
+
|
|
80
|
+
## Best Practices
|
|
81
|
+
|
|
82
|
+
Do:
|
|
83
|
+
|
|
84
|
+
* Do use `appearance="danger"` for blocking error states.
|
|
85
|
+
* Do provide an action when the user has a clear path to resolution.
|
|
86
|
+
|
|
87
|
+
Don't:
|
|
88
|
+
|
|
89
|
+
* Don't use Alert for transient, auto-dismissing notifications — use Toast.
|
|
90
|
+
* Don't use Alert for individual form field validation errors — use the field's error state.
|
|
91
|
+
* Don't use Alert when the message isn't tied to the current page or task context.
|
|
92
|
+
* Don't stack Alerts in the same region.
|
|
93
|
+
* Don't make `appearance="danger"` Alerts dismissable — the component prevents this automatically.
|
|
94
|
+
|
|
95
|
+
## Accessibility
|
|
96
|
+
|
|
97
|
+
* Use `role="alert"` for errors and warnings so they are announced immediately by screen readers.
|
|
98
|
+
* Use `role="status"` for informational and success alerts, which are announced at a lower priority.
|
|
99
|
+
* Don't rely solely on color to convey alert type — the icon and/or title must distinguish the appearance.
|
|
100
|
+
* Ensure the dismiss button has an accessible label (e.g., `aria-label="Dismiss alert"`).
|
|
101
|
+
|
|
102
|
+
### Keyboard interaction
|
|
103
|
+
|
|
104
|
+
* Alerts exist in the page's natural tab sequence, their actions reachable via `tab` and `shift`+`tab` keys.
|
|
105
|
+
|
|
106
|
+
## Related components
|
|
107
|
+
|
|
108
|
+
* [Toast](?path=/docs/core-toast--design) — For non-blocking, auto-dismissing notifications.
|
|
109
|
+
* [Pill](?path=/docs/core-pill--design) — For inline semantic status indicators without body copy.
|
|
110
|
+
* [Modal](?path=/docs/core-modal--design) — When the error or warning requires an immediate blocking decision.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Core/Alert - Usage
|
|
2
|
+
|
|
3
|
+
Alerts are used to communicate important information to the user.
|
|
4
|
+
|
|
5
|
+
| Prop | Type | Required | Default | Description |
|
|
6
|
+
| --- | --- | --- | --- | --- |
|
|
7
|
+
| `layout` | `(typeof layouts)[number]` | No | 'section' | The layout of the alert.<br><br>@default 'section'<br><br><ul><br> <li>'section' - The alert is displayed in a full width container.</li><br> <li>'compact' - @deprecated Use 'section' instead. Will be removed in a future version.</li><br> <li>'inline' - Inline notifications are low-priority messages about a single element, like a tile or row item.</li><br></ul> |
|
|
8
|
+
| `appearance` | `(typeof appearances)[number]` | No | 'info' | The appearance of the alert.<br><br>@default 'info'<br><br><ul><br> <li>'info' - Informational alerts provide general information or an important property.</li><br> <li>'warning' - Warning alerts notify users of cautionary information.</li><br> <li>'danger' - Danger alerts indicate problems that must be resolved.</li><br> <li>'success' - Success alerts confirm an action has been completed.</li><br></ul> |
|
|
9
|
+
| `title` | `string` | No | `--` | The title of the alert. This is optional. |
|
|
10
|
+
| `children` | `React.ReactNode` | Yes | `--` | The description of the alert. This is required.<br><br>@required |
|
|
11
|
+
| `action` | `{ label: string; onClick: (e: React.MouseEvent<HTMLButtonElement>) => void; } \| React.ReactElement` | No | `--` | The configuration of the action button. The object must contain a label displayed on the button and an onClick callback function. This is optional.<br><br>When the object is not provided, the alert will not render the action button. |
|
|
12
|
+
| `onDismiss` | `true \| (() => void)` | No | `--` | Optional function to call when the user dismisses the alert.<br><br>If this is not provided, the alert will not render the dismiss button.<br><br>Alerts with `appearance="danger"` cannot be dismissed and will not render the dismiss button.<br><br>**Integration note:** while the `Alert` will handle its own dismissal, this is non-persistent.<br>Persistent dismissal should be handled by the parent component. |
|
|
13
|
+
| `FORCE__className` | `string` | No | `--` | 🚨 This prop is meant to be an escape hatch. 🚨<br><br>If the desired style cannot be achieved using component props, use this as a last resort. The inner workings of Capra components are implementation details and this escape hatch gives one access to those implementation details. We cannot make any guarantees that styles will applied correctly across version updates. Please use it responsibly.<br><br>Add a CSS class to the component. |
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Core/Anchor - Design
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
Anchors are used to navigate users to a different section within the current page.
|
|
6
|
+
|
|
7
|
+
## Properties
|
|
8
|
+
|
|
9
|
+
### Label
|
|
10
|
+
|
|
11
|
+
Labels should be concise and descriptive, m Use title case (e.g., "Dashboard", "Settings"). Labels should ideally be
|
|
12
|
+
less than 12 characters, with a maximum of 32 characters.atching the destination heading.
|
|
13
|
+
|
|
14
|
+
## Best Practices
|
|
15
|
+
|
|
16
|
+
Do:
|
|
17
|
+
|
|
18
|
+
* Do match the label to the section heading the anchor points to.
|
|
19
|
+
* Do use the active state for the current page in a navigation region.
|
|
20
|
+
* Do use the disabled state when navigation is temporarily unavailable.
|
|
21
|
+
|
|
22
|
+
Don't:
|
|
23
|
+
|
|
24
|
+
* Don't mark more than one anchor as active in the same navigation context.
|
|
25
|
+
* Don't hide anchors instead of disabling them when a destination exists but is unavailable.
|
|
26
|
+
* Don't use confuse Anchor with Tab.
|
|
27
|
+
|
|
28
|
+
## Accessibility
|
|
29
|
+
|
|
30
|
+
### Keyboard interaction
|
|
31
|
+
|
|
32
|
+
| Key | Function |
|
|
33
|
+
| ------- | --------------------------------------------------------------------- |
|
|
34
|
+
| `Tab` | Moves focus to the anchor when navigating through focusable elements. |
|
|
35
|
+
| `Enter` | Activates the anchor when focused. |
|
|
36
|
+
|
|
37
|
+
### ARIA attributes
|
|
38
|
+
|
|
39
|
+
* `aria-current="page"`: Applied when the anchor is active, indicating the current page in navigation.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Core/Anchor - Usage
|
|
2
|
+
|
|
3
|
+
| Prop | Type | Required | Default | Description |
|
|
4
|
+
| --- | --- | --- | --- | --- |
|
|
5
|
+
| `children` | `React.ReactNode` | Yes | `--` | The label text to display in the anchor. Anchor labels should be one or two words, using title case (Tab Label). Labels should be less than 12 characters, with a maximum of 32 characters. |
|
|
6
|
+
| `href` | `string` | No | `--` | The href attribute of the anchor. |
|
|
7
|
+
| `isActive` | `boolean` | No | `--` | Whether the anchor is active. |
|
|
8
|
+
| `isDisabled` | `boolean` | No | `--` | Whether the anchor is disabled. |
|
|
9
|
+
| `as` | `As` | No | `--` | The underlying element rendered by the anchor. Defaults to `a`. |
|
|
10
|
+
| `FORCE__className` | `string` | No | `--` | 🚨 This prop is meant to be an escape hatch. 🚨<br><br>If the desired style cannot be achieved using component props, use this as a last resort. The inner workings of Capra components are implementation details and this escape hatch gives one access to those implementation details. We cannot make any guarantees that styles will applied correctly across version updates. Please use it responsibly.<br><br>Add a CSS class to the component. |
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Anchor } from '@cribl/capra-core';
|
|
16
|
+
|
|
17
|
+
// Basic usage
|
|
18
|
+
<Anchor href="/dashboard">Dashboard</Anchor>
|
|
19
|
+
|
|
20
|
+
// Active state
|
|
21
|
+
<Anchor href="/settings" isActive>Settings</Anchor>
|
|
22
|
+
|
|
23
|
+
// Disabled state
|
|
24
|
+
<Anchor href="/admin" isDisabled>Admin</Anchor>
|
|
25
|
+
|
|
26
|
+
// Polymorphic - render as button
|
|
27
|
+
<Anchor as="button" onClick={handleClick}>Action</Anchor>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Polymorphic Component
|
|
31
|
+
|
|
32
|
+
The Anchor component supports the `as` prop, allowing it to be rendered as different HTML elements or custom components. This is particularly useful when integrating with routing libraries like React Router.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { Link } from 'react-router-dom';
|
|
36
|
+
|
|
37
|
+
// Using with React Router
|
|
38
|
+
<Anchor as={Link} to="/dashboard">Dashboard</Anchor>
|
|
39
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Core/AutocompleteField - Design
|
|
2
|
+
|
|
3
|
+
AutocompleteField combines a text field with a suggestions list. Consumers can supply static `AutocompleteField.Item` children or an `items` collection with an optional default item renderer. The field allows custom values that are not in the list.
|
|
4
|
+
|
|
5
|
+
## Anatomy
|
|
6
|
+
|
|
7
|
+
1. **Text input** — Entry is through a standard text input. The field keeps focus while the list is open so typing and keyboard
|
|
8
|
+
navigation stay in one place.
|
|
9
|
+
2. **ListBox** — Filtered results appear in a ListBox under the field.
|
|
10
|
+
|
|
11
|
+
## Properties
|
|
12
|
+
|
|
13
|
+
### Label
|
|
14
|
+
|
|
15
|
+
A label is required for input fields and succinctly describes the field’s purpose. If another text element is acting
|
|
16
|
+
as the label, like a section title, ensure the proper aria relationships are linked.
|
|
17
|
+
|
|
18
|
+
### Placeholder text
|
|
19
|
+
|
|
20
|
+
<p>
|
|
21
|
+
Placeholder text is visible until a character is entered.
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<p>
|
|
25
|
+
Because the placeholder text disappears, putting instructions or requirements as placeholder text is not
|
|
26
|
+
accessible. Helper text is the preferred method to convey this information.
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
### Helper text
|
|
30
|
+
|
|
31
|
+
Helper text is placed below the field and informs the user of any requirements, disclaimers, and errors. Helper text
|
|
32
|
+
is shown persistently but is replaced by error text when an error occurs.
|
|
33
|
+
|
|
34
|
+
### Layout
|
|
35
|
+
|
|
36
|
+
There are two layouts available for text fields, vertical and horizontal. Vertical labels are the preferred layout,
|
|
37
|
+
appearing above the field. Horizontal labels appear on the leading side of the field, and should only be used when
|
|
38
|
+
space is limited.
|
|
39
|
+
|
|
40
|
+
## Layout and spacing
|
|
41
|
+
|
|
42
|
+
* Input renders identically to [TextField](?path=/docs/core-textfield--design).
|
|
43
|
+
* Suggestions are presented using a ListBox.
|
|
44
|
+
|
|
45
|
+
## Behavior
|
|
46
|
+
|
|
47
|
+
### Autocomplete vs. Select
|
|
48
|
+
|
|
49
|
+
<p>
|
|
50
|
+
**Autocomplete** is an input box with text hints that users can type freely into. Hints are presented and refined
|
|
51
|
+
ina selection list as the user types. Freeform entry is allowed.
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
<p>
|
|
55
|
+
**Select**
|
|
56
|
+
|
|
57
|
+
allows selecting options only among a given set of choices.
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
### Filtering
|
|
61
|
+
|
|
62
|
+
As the user types into the text field options are filtered based on the value.
|
|
63
|
+
|
|
64
|
+
## Best Practices
|
|
65
|
+
|
|
66
|
+
Do:
|
|
67
|
+
|
|
68
|
+
* Do show a "no results" message when the filter returns nothing.
|
|
69
|
+
* Do support keyboard-only navigation of suggestions.
|
|
70
|
+
|
|
71
|
+
Don't:
|
|
72
|
+
|
|
73
|
+
* Don't use AutocompleteField for small mutually exclusive sets (about seven or fewer visible options) — use [RadioGroup](?path=/docs/core-radiogroup--design) or Select.
|
|
74
|
+
* Don't use AutocompleteField for plain freeform text with no list validation — use [TextField](?path=/docs/core-textfield--design).
|
|
75
|
+
* Don't require picking from the list while still allowing arbitrary text without explaining that behavior.
|
|
76
|
+
|
|
77
|
+
## Accessibility
|
|
78
|
+
|
|
79
|
+
* `role="combobox"` on the input, `aria-expanded` reflects list open state.
|
|
80
|
+
* `aria-controls` references the suggestion list `id`.
|
|
81
|
+
* `aria-activedescendant` references the currently focused suggestion.
|
|
82
|
+
* Suggestion list: `role="listbox"`, each suggestion: `role="option"`.
|
|
83
|
+
|
|
84
|
+
### Keyboard interaction
|
|
85
|
+
|
|
86
|
+
* Keyboard interactions follow Select and ListBox.
|
|
87
|
+
|
|
88
|
+
## Related components
|
|
89
|
+
|
|
90
|
+
* [TextField](?path=/docs/core-textfield--design) — For freeform text without suggestions.
|
|
91
|
+
* [RadioGroup](?path=/docs/core-radiogroup--design) — For small mutually exclusive option sets.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Core/AutocompleteField - Usage
|
|
2
|
+
|
|
3
|
+
AutocompleteField combines a text field with a suggestions list. Consumers can supply static `AutocompleteField.Item` children or an `items` collection with an optional default item renderer. The field allows custom values that are not in the list.
|
|
4
|
+
|
|
5
|
+
| Prop | Type | Required | Default | Description |
|
|
6
|
+
| --- | --- | --- | --- | --- |
|
|
7
|
+
| `canClear` | `boolean` | No | `--` | Whether to show a clear button for the input. |
|
|
8
|
+
| `children` | `React.ReactNode \| (( values: T & { defaultChildren: React.ReactNode \| undefined; }, ) => React.ReactNode)` | No | `--` | The children to render in the dropdown. |
|
|
9
|
+
| `itemFilter` | `(textValue: string, inputValue: string) => boolean` | No | `--` | A function that filters the items based on the input value. |
|
|
10
|
+
| `onChange` | `(value: string) => void` | No | `--` | A callback function that is called when the input value changes. |
|
|
11
|
+
| `onOpenChange` | `(isOpen: boolean) => void` | No | `--` | A callback function that is called when the dropdown is opened or closed. |
|
|
12
|
+
| `items` | `AutocompleteItem[]` | No | `--` | The items to display in the dropdown. |
|
|
13
|
+
| `value` | `AutocompleteItem['value']` | No | `--` | The value of the input. |
|
|
14
|
+
| `shouldAutoSizeDropdown` | `boolean` | No | `--` | Whether to automatically size the dropdown to the width of the input. Defaults to `true` |
|
|
15
|
+
| `FORCE__className` | `string` | No | `--` | 🚨 This prop is meant to be an escape hatch. 🚨<br><br>If the desired style cannot be achieved using component props, use this as a last resort. The inner workings of Capra components are implementation details and this escape hatch gives one access to those implementation details. We cannot make any guarantees that styles will applied correctly across version updates. Please use it responsibly.<br><br>Add a CSS class to the component. |
|
|
16
|
+
| `helperText` | `string` | No | `--` | Helper text below the field. Replaced by error message when status is error. Use for requirements, disclaimers. |
|
|
17
|
+
| `label` | `string` | No | `--` | Label for the field. Required for accessibility; use aria-label if another element acts as label. |
|
|
18
|
+
| `layout` | `'vertical' \| 'horizontal'` | No | `--` | Label and field layout: vertical (label above) or horizontal (label on leading side). Prefer vertical; use horizontal when space is limited. |
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Core/Badge - Design
|
|
2
|
+
|
|
3
|
+
Badges display an indicator/counter on an associated component.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### Label
|
|
8
|
+
|
|
9
|
+
A label is required to indicate the number of notifications.
|
|
10
|
+
|
|
11
|
+
### Size
|
|
12
|
+
|
|
13
|
+
Badges come in 3 sizes to support ones, tens, and values above 100.
|
|
14
|
+
|
|
15
|
+
### Dot
|
|
16
|
+
|
|
17
|
+
Use a dot to show notifications without a count.
|
|
18
|
+
|
|
19
|
+
### Appearance
|
|
20
|
+
|
|
21
|
+
Badges can be colored based on their status. The `attention` appearance is the general purpose color used for numbered badges and does not necessarily communicate severity.
|
|
22
|
+
|
|
23
|
+
Using color as the only means to communicate status should be avoided (WCAG SC 1.4.1: Use of Color, Level A). Badges that communicate status must be accompanied by supplementary information that clearly communicates the status.
|
|
24
|
+
|
|
25
|
+
## Behavior
|
|
26
|
+
|
|
27
|
+
### Corner attachment
|
|
28
|
+
|
|
29
|
+
Badges are placed in the top-right of the parent component to avoid obscuring the parent content.
|
|
30
|
+
|
|
31
|
+
### Inline
|
|
32
|
+
|
|
33
|
+
When used with text labels, badges are placed on the trailing side and vertically aligned to the text's line height.
|
|
34
|
+
|
|
35
|
+
## Content
|
|
36
|
+
|
|
37
|
+
### Maximum
|
|
38
|
+
|
|
39
|
+
The maximum number shown in 99. When there are more than 99 notifications a "+" is appended to the label.
|
|
40
|
+
|
|
41
|
+
## Best Practices
|
|
42
|
+
|
|
43
|
+
Do:
|
|
44
|
+
|
|
45
|
+
* Do cap displayed values at 99 with a "99+" label.
|
|
46
|
+
* Do use the dot variant for simple presence indicators.
|
|
47
|
+
* Do include count context in the parent's accessible label.
|
|
48
|
+
|
|
49
|
+
Don't:
|
|
50
|
+
|
|
51
|
+
* Don't use Badge for semantic status text — use Pill.
|
|
52
|
+
* Don't use Badge for labels or tags — use Tag.
|
|
53
|
+
* Don't place Badge on non-interactive decorative elements.
|
|
54
|
+
* Don't use Badge colors as the only method to communicate status.
|
|
55
|
+
|
|
56
|
+
## Accessibility
|
|
57
|
+
|
|
58
|
+
* The badge is a nested static element; it is announced as part of its parent.
|
|
59
|
+
* The parent element's accessible label should include the count context (e.g., "Notifications, 5 unread").
|
|
60
|
+
* Use `aria-live="polite"` on the parent for dynamic badge updates.
|
|
61
|
+
|
|
62
|
+
## Content
|
|
63
|
+
|
|
64
|
+
* Numeric only.
|
|
65
|
+
* Max displayed value: 99; use "99+" for larger counts.
|
|
66
|
+
|
|
67
|
+
## Related components
|
|
68
|
+
|
|
69
|
+
* [Pill](?path=/docs/core-pill--design) — For semantic status labels.
|
|
70
|
+
* [Tag](?path=/docs/core-tag--design) — For removable text chips.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Core/Badge - Usage
|
|
2
|
+
|
|
3
|
+
Badges display an indicator/counter on an associated component.
|
|
4
|
+
|
|
5
|
+
| Prop | Type | Required | Default | Description |
|
|
6
|
+
| --- | --- | --- | --- | --- |
|
|
7
|
+
| `variant` | `'counter' \| 'dot'` | No | `--` | The variant of the badge. 'counter' displays a count, 'dot' displays only a dot.<br>@default 'counter' |
|
|
8
|
+
| `appearance` | `'danger' \| 'info' \| 'success' \| 'warning'` | No | 'danger' | Controls the Badge color.<br>@default 'danger' |
|
|
9
|
+
| `count` | `number` | No | 0 | The number to display in the badge. Default is 0. |
|
|
10
|
+
| `showZero` | `boolean` | No | false | Whether to display the badge when the count is zero. Default is false. |
|
|
11
|
+
| `overflowCount` | `number` | No | 99 | The number to display in the badge when the count is greater than the overflow count. Default is 99. |
|
|
12
|
+
| `FORCE__className` | `string` | No | `--` | 🚨 This prop is meant to be an escape hatch. 🚨<br><br>If the desired style cannot be achieved using component props, use this as a last resort. The inner workings of Capra components are implementation details and this escape hatch gives one access to those implementation details. We cannot make any guarantees that styles will applied correctly across version updates. Please use it responsibly.<br><br>Add a CSS class to the component. |
|
|
13
|
+
| `aria-live` | `React.AriaAttributes['aria-live']` | No | `--` | `--` |
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Core/Breadcrumbs - Design
|
|
2
|
+
|
|
3
|
+
Renders a breadcrumb trail with built-in support for collection behavior, keyboard support, and current-page semantics. Wrap items with {@link Breadcrumb}. The last item should represent the current page (typically without an `href`).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Use Breadcrumbs on views that sit deeper than the home or root level so people see where they are in the hierarchy and can jump to ancestors.
|
|
8
|
+
|
|
9
|
+
Place them above the page title, keep labels aligned with each destination's title, and render every segment except the current page as a link.
|
|
10
|
+
|
|
11
|
+
## Layout and spacing
|
|
12
|
+
|
|
13
|
+
* Place above the page heading.
|
|
14
|
+
|
|
15
|
+
## Behavior
|
|
16
|
+
|
|
17
|
+
* Current page item is not a link (no click interaction).
|
|
18
|
+
|
|
19
|
+
## Content
|
|
20
|
+
|
|
21
|
+
* Use the same label as the page heading for each item.
|
|
22
|
+
* Title case.
|
|
23
|
+
* Keep each label concise (1-3 words).
|
|
24
|
+
|
|
25
|
+
## Best Practices
|
|
26
|
+
|
|
27
|
+
Do:
|
|
28
|
+
|
|
29
|
+
* Do make all items except the last one clickable links.
|
|
30
|
+
* Do mark the current page with `aria-current="page"`.
|
|
31
|
+
|
|
32
|
+
Don't:
|
|
33
|
+
|
|
34
|
+
* Don't show breadcrumbs on top-level pages — there is no trail to show.
|
|
35
|
+
* Don't use breadcrumbs when the IA is flat and would produce a single segment.
|
|
36
|
+
* Don't use custom separator text that is read by screen readers.
|
|
37
|
+
|
|
38
|
+
## Accessibility
|
|
39
|
+
|
|
40
|
+
* Wrap in a `<nav aria-label="breadcrumb">` element.
|
|
41
|
+
* Current page item uses `aria-current="page"`.
|
|
42
|
+
* Separator characters are `aria-hidden="true"`.
|
|
43
|
+
|
|
44
|
+
### Keyboard interaction
|
|
45
|
+
|
|
46
|
+
| Key | Function |
|
|
47
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `Tab` | Move focus forward along the breadcrumb trail. |
|
|
49
|
+
| `Shift + Tab` | Move focus back along the breadcrumb trail. |
|
|
50
|
+
| `Enter` | Activates the currently focused link. If a dropdown crumb has focus, opens the menu and gives focus to the currently selected option. If a menu item has focus, activates the item and closes the menu. |
|
|
51
|
+
| `Space` | If a dropdown crumb has focus, opens the menu and gives focus to the currently selected option. |
|
|
52
|
+
| `Down Arrow` | If a dropdown crumb has focus, opens the menu and gives focus to the currently selected option. If a menu item has focus, moves focus to the next item. |
|
|
53
|
+
| `Up Arrow` | If a menu item has focus, moves focus to the previous item. |
|
|
54
|
+
| `Esc` | If a dropdown crumb is open, closes the menu and returns focus to the trigger. |
|
|
55
|
+
|
|
56
|
+
* If a dropdown crumb is open: the `tab` and `shift`+`tab` keys do not navigate.
|
|
57
|
+
|
|
58
|
+
### Labeling
|
|
59
|
+
|
|
60
|
+
* Breadcrumbs represent a hierarchy and need to announce themselves accordingly. Using `aria-label`, a crumb should identify itself and its parents.
|
|
61
|
+
* Use `aria-current=”page”` to indicate the last page in the breadcrumb order.
|
|
62
|
+
|
|
63
|
+
## Related components
|
|
64
|
+
|
|
65
|
+
* [TabNav](?path=/docs/core-tabnav--design) — For in-page section navigation.
|