cleanplate 0.2.0 → 0.2.2
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/AGENTS.md +45 -0
- package/README.md +205 -60
- package/dist/components/icon/material-icon-names.d.ts +5 -5
- package/dist/components/icon/material-icon-names.d.ts.map +1 -1
- package/docs/Accordion.md +125 -0
- package/docs/Alert.md +131 -0
- package/docs/Animated.md +101 -0
- package/docs/AppShell.md +145 -0
- package/docs/Avatar.md +130 -0
- package/docs/Badge.md +83 -0
- package/docs/BottomSheet.md +78 -0
- package/docs/BreadCrumb.md +133 -0
- package/docs/Button.md +189 -0
- package/docs/ConfirmDialog.md +139 -0
- package/docs/Container.md +230 -0
- package/docs/Dropdown.md +175 -0
- package/docs/Footer.md +93 -0
- package/docs/FormControls.md +115 -0
- package/docs/Header.md +115 -0
- package/docs/Icon.md +225 -0
- package/docs/MediaObject.md +303 -0
- package/docs/MenuList.md +113 -0
- package/docs/Modal.md +152 -0
- package/docs/PageHeader.md +134 -0
- package/docs/Pagination.md +142 -0
- package/docs/Pills.md +104 -0
- package/docs/Spinner.md +115 -0
- package/docs/Stepper.md +131 -0
- package/docs/Table.md +194 -0
- package/docs/Toast.md +96 -0
- package/docs/Typography.md +231 -0
- package/llms.txt +293 -0
- package/package.json +7 -2
package/docs/Spinner.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Spinner Component
|
|
2
|
+
|
|
3
|
+
Purpose: A loading indicator that shows a rotating Material icon. Use it for progress or activity states. Supports six icon options (all animate when rotated), sizes, light/dark variant, and margin spacing.
|
|
4
|
+
|
|
5
|
+
## Props / Inputs
|
|
6
|
+
|
|
7
|
+
| Prop | Type | Required | Default | Description |
|
|
8
|
+
| --- | --- | --- | --- | --- |
|
|
9
|
+
| size | "small" \| "medium" \| "large" | no | "medium" | Size of the spinner. |
|
|
10
|
+
| variant | "light" \| "dark" | no | "light" | Visual variant; use dark on dark backgrounds. |
|
|
11
|
+
| icon | SpinnerIcon | no | "progress_activity" | Icon to display as the spinner. One of: progress_activity, autorenew, sync, refresh, cached, loop. |
|
|
12
|
+
| margin | string \| string[] | no | "0" | Spacing **suffix** for outer margin. The component adds the `m-` prefix (e.g. `"0"` → m-0, `"b-2"` → m-b-2). Use a single string or array. |
|
|
13
|
+
| className | string | no | "" | Additional class names for the wrapper. |
|
|
14
|
+
|
|
15
|
+
## Types
|
|
16
|
+
|
|
17
|
+
### SpinnerSize
|
|
18
|
+
```typescript
|
|
19
|
+
type SpinnerSize = "small" | "medium" | "large";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### SpinnerVariant
|
|
23
|
+
```typescript
|
|
24
|
+
type SpinnerVariant = "light" | "dark";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### SpinnerIcon
|
|
28
|
+
```typescript
|
|
29
|
+
type SpinnerIcon =
|
|
30
|
+
| "progress_activity"
|
|
31
|
+
| "autorenew"
|
|
32
|
+
| "sync"
|
|
33
|
+
| "refresh"
|
|
34
|
+
| "cached"
|
|
35
|
+
| "loop";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### SpacingOption
|
|
39
|
+
```typescript
|
|
40
|
+
type SpacingOption = (typeof SPACING_OPTIONS)[number];
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### SpinnerMargin
|
|
44
|
+
```typescript
|
|
45
|
+
type SpinnerMargin = string | SpacingOption[];
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### SpinnerProps
|
|
49
|
+
```typescript
|
|
50
|
+
interface SpinnerProps {
|
|
51
|
+
size?: SpinnerSize;
|
|
52
|
+
variant?: SpinnerVariant;
|
|
53
|
+
icon?: SpinnerIcon;
|
|
54
|
+
margin?: SpinnerMargin;
|
|
55
|
+
className?: string;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage Examples
|
|
60
|
+
|
|
61
|
+
### Basic
|
|
62
|
+
|
|
63
|
+
```jsx
|
|
64
|
+
import { Spinner } from "cleanplate";
|
|
65
|
+
|
|
66
|
+
export const Example = () => <Spinner size="medium" variant="light" />;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Icon options
|
|
70
|
+
|
|
71
|
+
All of these icons rotate via the same CSS animation.
|
|
72
|
+
|
|
73
|
+
```jsx
|
|
74
|
+
import { Spinner } from "cleanplate";
|
|
75
|
+
|
|
76
|
+
<Spinner /> // progress_activity (default)
|
|
77
|
+
<Spinner icon="autorenew" /> // Circular arrows
|
|
78
|
+
<Spinner icon="sync" /> // Sync arrows
|
|
79
|
+
<Spinner icon="refresh" /> // Refresh arrows
|
|
80
|
+
<Spinner icon="cached" /> // Cache/refresh arrows
|
|
81
|
+
<Spinner icon="loop" /> // Circular loop
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Sizes and variants
|
|
85
|
+
|
|
86
|
+
```jsx
|
|
87
|
+
<Spinner size="small" />
|
|
88
|
+
<Spinner size="medium" />
|
|
89
|
+
<Spinner size="large" />
|
|
90
|
+
<Spinner variant="light" />
|
|
91
|
+
<Spinner variant="dark" />
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### With Container
|
|
95
|
+
|
|
96
|
+
```jsx
|
|
97
|
+
import { Spinner, Container } from "cleanplate";
|
|
98
|
+
|
|
99
|
+
export const Example = () => (
|
|
100
|
+
<Container padding="4">
|
|
101
|
+
<Spinner icon="sync" size="medium" margin="b-2" />
|
|
102
|
+
</Container>
|
|
103
|
+
);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Behavior Notes
|
|
107
|
+
|
|
108
|
+
- **Animation:** The icon is rotated continuously via CSS (class `cp-spinner-icon`). All six icon options work with this rotation.
|
|
109
|
+
- **Layout:** Spinner renders a Container wrapping an Icon; size and variant classes apply to the wrapper.
|
|
110
|
+
- **Spacing:** `margin` accepts the **spacing suffix**; the component adds the `m-` prefix via `getSpacingClass`. Use suffix form (e.g. `"0"`, `"b-2"`) when passing values.
|
|
111
|
+
|
|
112
|
+
## Related Components / Links
|
|
113
|
+
|
|
114
|
+
- Container (used internally as the wrapper; use for layout around the spinner)
|
|
115
|
+
- Icon (used internally to render the Material icon that rotates)
|
package/docs/Stepper.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Stepper Component
|
|
2
|
+
|
|
3
|
+
Purpose: Displays a sequence of steps (e.g. for a wizard or checkout). Each step has a label, optional active/completed state, and can be clickable. Use it for multi-step flows and progress indication. Supports horizontal and vertical layout.
|
|
4
|
+
|
|
5
|
+
## Props / Inputs
|
|
6
|
+
|
|
7
|
+
| Prop | Type | Required | Default | Description |
|
|
8
|
+
| --- | --- | --- | --- | --- |
|
|
9
|
+
| variant | "horizontal" \| "vertical" | no | — | Layout direction. |
|
|
10
|
+
| margin | string \| string[] | no | "0" | Spacing **suffix** for outer margin. The component adds the `m-` prefix (e.g. `"0"` → m-0, `"b-2"` → m-b-2). Use a single string or array. |
|
|
11
|
+
| className | string | no | "" | Additional class names for the root element. |
|
|
12
|
+
| config | StepperStepConfig[] | yes | — | Step definitions: each has label, key, and optionally isCompleted, isActive. |
|
|
13
|
+
| onClick | (step: StepperStepConfig) => void | no | — | Called when a step is clicked; receives the step config. |
|
|
14
|
+
|
|
15
|
+
## Types
|
|
16
|
+
|
|
17
|
+
### StepperStepConfig
|
|
18
|
+
```typescript
|
|
19
|
+
interface StepperStepConfig {
|
|
20
|
+
label: string; // Display label
|
|
21
|
+
key: string; // Unique key (e.g. href fragment or route path)
|
|
22
|
+
isCompleted?: boolean;
|
|
23
|
+
isActive?: boolean;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### StepperVariant
|
|
28
|
+
```typescript
|
|
29
|
+
type StepperVariant = "horizontal" | "vertical";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### SpacingOption
|
|
33
|
+
```typescript
|
|
34
|
+
type SpacingOption = (typeof SPACING_OPTIONS)[number];
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### StepperMargin
|
|
38
|
+
```typescript
|
|
39
|
+
type StepperMargin = string | SpacingOption[];
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### StepperProps
|
|
43
|
+
```typescript
|
|
44
|
+
interface StepperProps {
|
|
45
|
+
variant?: StepperVariant;
|
|
46
|
+
margin?: StepperMargin;
|
|
47
|
+
className?: string;
|
|
48
|
+
config: StepperStepConfig[];
|
|
49
|
+
onClick?: (step: StepperStepConfig) => void;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage Examples
|
|
54
|
+
|
|
55
|
+
### Basic
|
|
56
|
+
|
|
57
|
+
```jsx
|
|
58
|
+
import { Stepper } from "cleanplate";
|
|
59
|
+
|
|
60
|
+
const config = [
|
|
61
|
+
{ label: "Details", key: "/details", isActive: true },
|
|
62
|
+
{ label: "Review", key: "/review", isCompleted: true },
|
|
63
|
+
{ label: "Confirm", key: "/confirm" },
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
export const Example = () => (
|
|
67
|
+
<Stepper config={config} variant="horizontal" />
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### With onClick
|
|
72
|
+
|
|
73
|
+
```jsx
|
|
74
|
+
import { Stepper } from "cleanplate";
|
|
75
|
+
import { useState } from "react";
|
|
76
|
+
|
|
77
|
+
const Example = () => {
|
|
78
|
+
const [active, setActive] = useState("step1");
|
|
79
|
+
const config = [
|
|
80
|
+
{ label: "Step 1", key: "step1", isActive: active === "step1" },
|
|
81
|
+
{ label: "Step 2", key: "step2", isActive: active === "step2" },
|
|
82
|
+
];
|
|
83
|
+
return (
|
|
84
|
+
<Stepper config={config} onClick={(step) => setActive(step.key)} />
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Horizontal and vertical
|
|
90
|
+
|
|
91
|
+
```jsx
|
|
92
|
+
<Stepper config={config} variant="horizontal" />
|
|
93
|
+
<Stepper config={config} variant="vertical" />
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### With completed steps
|
|
97
|
+
|
|
98
|
+
```jsx
|
|
99
|
+
<Stepper
|
|
100
|
+
config={[
|
|
101
|
+
{ label: "Step 1", key: "1", isCompleted: true },
|
|
102
|
+
{ label: "Step 2", key: "2", isCompleted: true },
|
|
103
|
+
{ label: "Step 3", key: "3", isActive: true },
|
|
104
|
+
{ label: "Step 4", key: "4" },
|
|
105
|
+
]}
|
|
106
|
+
variant="horizontal"
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### With Container
|
|
111
|
+
|
|
112
|
+
```jsx
|
|
113
|
+
import { Stepper, Container } from "cleanplate";
|
|
114
|
+
|
|
115
|
+
<Container padding="4">
|
|
116
|
+
<Stepper config={config} variant="horizontal" margin="b-2" />
|
|
117
|
+
</Container>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Behavior Notes
|
|
121
|
+
|
|
122
|
+
- **Links:** Each step label is an `<a href={step.key}>`. The component calls `preventDefault()` on click and invokes `onClick(step)` so you can control navigation (e.g. router) without following the href.
|
|
123
|
+
- **Completed:** When `step.isCompleted` is true, the step number is replaced with a done icon.
|
|
124
|
+
- **Active:** When `step.isActive` is true, the step gets the active CSS class.
|
|
125
|
+
- **Spacing:** `margin` accepts the **spacing suffix**; the component adds the `m-` prefix via `getSpacingClass`.
|
|
126
|
+
|
|
127
|
+
## Related Components / Links
|
|
128
|
+
|
|
129
|
+
- Container (layout and spacing around the stepper)
|
|
130
|
+
- Typography (headings above or near the stepper)
|
|
131
|
+
- Icon (used internally for the done icon on completed steps)
|
package/docs/Table.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Table Component
|
|
2
|
+
|
|
3
|
+
Purpose: Displays structured data in a table with configurable columns, optional built-in pagination, and a responsive mobile view. Each row is an object; column `id` values match row keys for default cell rendering. Use `customRender` per column for badges, buttons, or custom content. When viewport is under 768px and `mobileColumns` is set, rows are shown as MediaObject cards instead of a table. Optional `onRowClick(rowData)` for clickable rows.
|
|
4
|
+
|
|
5
|
+
## Props / Inputs
|
|
6
|
+
|
|
7
|
+
| Prop | Type | Required | Default | Description |
|
|
8
|
+
| --- | --- | --- | --- | --- |
|
|
9
|
+
| columns | TableColumn[] | yes | — | Column definitions (id, title, textAlign?, widthPercentage?, customRender?). |
|
|
10
|
+
| data | TableRow[] | yes | — | Array of row objects; keys should match column `id`s. |
|
|
11
|
+
| variant | "default" \| "compact" | no | "default" | Visual variant. |
|
|
12
|
+
| margin | string \| SpacingOption[] | no | "0" | Margin spacing. Suffix or array of spacing suffixes; component adds `m-` prefix. |
|
|
13
|
+
| className | string | no | "" | Additional class names for the root element. |
|
|
14
|
+
| onRowClick | (rowData: TableRow) => void | no | — | Called when a row is clicked; receives the row object. |
|
|
15
|
+
| totalItems | number | no | 0 | Total item count for built-in Pagination; 0 or omitted hides pagination. |
|
|
16
|
+
| totalLabel | string | no | "Items" | Label for the pagination total (e.g. "Items"). |
|
|
17
|
+
| currentPage | number | no | 1 | Current 1-based page (controlled). |
|
|
18
|
+
| rowsPerPage | number | no | 10 | Rows per page. |
|
|
19
|
+
| rowsPerPageOptions | PaginationRowsPerPageOption[] | no | — | Options for rows-per-page select (same shape as Pagination). |
|
|
20
|
+
| onPageChange | (page, rowsPerPage) => void | no | — | Called when page changes; receives (page, rowsPerPage). |
|
|
21
|
+
| onRowsPerPageChange | (rowsPerPage: number) => void | no | — | Called when rows per page changes. |
|
|
22
|
+
| hidePagination | boolean | no | false | If true, hides the built-in pagination bar even when totalItems > 0. |
|
|
23
|
+
| mobileColumns | TableMobileColumns \| null | no | null | When set and viewport < 768px, rows render as MediaObjects; keys map row keys to title, description, media. |
|
|
24
|
+
|
|
25
|
+
## Types
|
|
26
|
+
|
|
27
|
+
### SpacingOption
|
|
28
|
+
```typescript
|
|
29
|
+
type SpacingOption = (typeof SPACING_OPTIONS)[number];
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### TableVariant
|
|
33
|
+
```typescript
|
|
34
|
+
type TableVariant = "default" | "compact";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### TableMargin
|
|
38
|
+
```typescript
|
|
39
|
+
type TableMargin = string | SpacingOption[];
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### TableColumnTextAlign
|
|
43
|
+
```typescript
|
|
44
|
+
type TableColumnTextAlign = "left" | "center" | "right";
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### TableRow
|
|
48
|
+
```typescript
|
|
49
|
+
type TableRow = Record<string, unknown>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### TableColumn
|
|
53
|
+
```typescript
|
|
54
|
+
interface TableColumn {
|
|
55
|
+
id: string;
|
|
56
|
+
title: string;
|
|
57
|
+
textAlign?: TableColumnTextAlign;
|
|
58
|
+
customRender?: (rowData: TableRow, column: TableColumn) => React.ReactNode;
|
|
59
|
+
widthPercentage?: string;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### TableMobileColumns
|
|
64
|
+
```typescript
|
|
65
|
+
interface TableMobileColumns {
|
|
66
|
+
title: string; // row key for MediaObject title
|
|
67
|
+
description?: string; // row key for description
|
|
68
|
+
mediaAvatar?: string; // row key for avatar value
|
|
69
|
+
mediaIcon?: string; // static icon name for all rows
|
|
70
|
+
mediaImage?: string; // static image URL
|
|
71
|
+
className?: string;
|
|
72
|
+
margin?: TableMargin;
|
|
73
|
+
padding?: string | SpacingOption[];
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### TableProps
|
|
78
|
+
```typescript
|
|
79
|
+
interface TableProps {
|
|
80
|
+
variant?: TableVariant;
|
|
81
|
+
margin?: TableMargin;
|
|
82
|
+
className?: string;
|
|
83
|
+
columns: TableColumn[];
|
|
84
|
+
data: TableRow[];
|
|
85
|
+
onRowClick?: (rowData: TableRow) => void;
|
|
86
|
+
totalItems?: number;
|
|
87
|
+
totalLabel?: string;
|
|
88
|
+
currentPage?: number;
|
|
89
|
+
rowsPerPage?: number;
|
|
90
|
+
rowsPerPageOptions?: PaginationRowsPerPageOption[];
|
|
91
|
+
onPageChange?: (page: number, rowsPerPage: number) => void;
|
|
92
|
+
onRowsPerPageChange?: (rowsPerPage: number) => void;
|
|
93
|
+
hidePagination?: boolean;
|
|
94
|
+
mobileColumns?: TableMobileColumns | null;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage Examples
|
|
99
|
+
|
|
100
|
+
### Basic
|
|
101
|
+
|
|
102
|
+
```jsx
|
|
103
|
+
import { Table } from "cleanplate";
|
|
104
|
+
|
|
105
|
+
const columns = [
|
|
106
|
+
{ id: "name", title: "Name" },
|
|
107
|
+
{ id: "email", title: "Email" },
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
const data = [
|
|
111
|
+
{ name: "John Doe", email: "john@doe.com" },
|
|
112
|
+
{ name: "Jane Doe", email: "jane@doe.com" },
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
<Table columns={columns} data={data} />
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### With pagination
|
|
119
|
+
|
|
120
|
+
```jsx
|
|
121
|
+
import { Table } from "cleanplate";
|
|
122
|
+
import { useState } from "react";
|
|
123
|
+
|
|
124
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
125
|
+
const [rowsPerPage, setRowsPerPage] = useState(10);
|
|
126
|
+
|
|
127
|
+
<Table
|
|
128
|
+
columns={columns}
|
|
129
|
+
data={data}
|
|
130
|
+
totalItems={100}
|
|
131
|
+
currentPage={currentPage}
|
|
132
|
+
rowsPerPage={rowsPerPage}
|
|
133
|
+
onPageChange={(page) => setCurrentPage(page)}
|
|
134
|
+
onRowsPerPageChange={(rpp) => {
|
|
135
|
+
setRowsPerPage(rpp);
|
|
136
|
+
setCurrentPage(1);
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Custom cell (customRender)
|
|
142
|
+
|
|
143
|
+
```jsx
|
|
144
|
+
const columns = [
|
|
145
|
+
{ id: "name", title: "Name", widthPercentage: "50%" },
|
|
146
|
+
{
|
|
147
|
+
id: "status",
|
|
148
|
+
title: "Status",
|
|
149
|
+
textAlign: "right",
|
|
150
|
+
customRender: (rowData, column) => (
|
|
151
|
+
<Badge label={String(rowData.status)} variant="success" />
|
|
152
|
+
),
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
<Table columns={columns} data={data} />;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Mobile view (mobileColumns)
|
|
159
|
+
|
|
160
|
+
```jsx
|
|
161
|
+
<Table
|
|
162
|
+
columns={columns}
|
|
163
|
+
data={data}
|
|
164
|
+
mobileColumns={{
|
|
165
|
+
title: "name",
|
|
166
|
+
description: "email",
|
|
167
|
+
mediaAvatar: "avatarUrl",
|
|
168
|
+
}}
|
|
169
|
+
/>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Row click
|
|
173
|
+
|
|
174
|
+
```jsx
|
|
175
|
+
<Table
|
|
176
|
+
columns={columns}
|
|
177
|
+
data={data}
|
|
178
|
+
onRowClick={(rowData) => console.log(rowData)}
|
|
179
|
+
/>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Behavior Notes
|
|
183
|
+
|
|
184
|
+
- **Required:** `columns` and `data` are required. Each column must have `id` and `title`; row keys should match `id` for default cell display.
|
|
185
|
+
- **Pagination:** Built-in Pagination is shown when `totalItems` > 0 and `hidePagination` is false. Pass `onPageChange` and optionally `onRowsPerPageChange`; keep `currentPage` and `rowsPerPage` in parent state.
|
|
186
|
+
- **Mobile:** When viewport width < 768px and `mobileColumns` is set, the table is replaced by a list of MediaObject items; `title` (and optionally `description`, `mediaAvatar`) are row keys whose values are passed to MediaObject.
|
|
187
|
+
- **customRender:** Receives `(rowData, column)` and returns a React node; use for badges, buttons, or any custom cell content.
|
|
188
|
+
- **Spacing:** `margin` uses the suffix API; the component adds the `m-` prefix via `getSpacingClass`.
|
|
189
|
+
|
|
190
|
+
## Related Components / Links
|
|
191
|
+
|
|
192
|
+
- Pagination (used inside Table when totalItems > 0 and hidePagination is false; same props as standalone Pagination)
|
|
193
|
+
- MediaObject (used for mobile view when mobileColumns is set)
|
|
194
|
+
- Typography, Container (used for headers and cells; Container often used in customRender with Badge)
|
package/docs/Toast.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Toast Component
|
|
2
|
+
|
|
3
|
+
Purpose: Displays transient messages in a portal (fixed top-right). Use a ref to call `addMessage({ mode, message })` imperatively. The parent does not manage toast state; the component handles rendering, stacking, and optional auto-close. Use for success/error feedback, notifications, or short-lived messages.
|
|
4
|
+
|
|
5
|
+
## Props / Inputs
|
|
6
|
+
|
|
7
|
+
| Prop | Type | Required | Default | Description |
|
|
8
|
+
| --- | --- | --- | --- | --- |
|
|
9
|
+
| autoClose | boolean | no | false | Whether toasts auto-close after autoCloseTime. |
|
|
10
|
+
| autoCloseTime | number | no | 5000 | Duration in ms before auto-closing when autoClose is true. |
|
|
11
|
+
|
|
12
|
+
## Imperative API
|
|
13
|
+
|
|
14
|
+
| Method | Signature | Description |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| addMessage | (toast: ToastMessage) => void | Add a toast. toast has `mode` (info \| error \| warning \| success) and `message` (string). |
|
|
17
|
+
|
|
18
|
+
## Types
|
|
19
|
+
|
|
20
|
+
### ToastVariant
|
|
21
|
+
```typescript
|
|
22
|
+
type ToastVariant = "info" | "error" | "warning" | "success";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### ToastMessage
|
|
26
|
+
```typescript
|
|
27
|
+
interface ToastMessage {
|
|
28
|
+
mode: ToastVariant;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### ToastRefHandle
|
|
34
|
+
```typescript
|
|
35
|
+
interface ToastRefHandle {
|
|
36
|
+
addMessage: (toast: ToastMessage) => void;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ToastProps
|
|
41
|
+
```typescript
|
|
42
|
+
interface ToastProps {
|
|
43
|
+
autoClose?: boolean;
|
|
44
|
+
autoCloseTime?: number;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage Examples
|
|
49
|
+
|
|
50
|
+
### Basic
|
|
51
|
+
|
|
52
|
+
```jsx
|
|
53
|
+
import { useRef } from "react";
|
|
54
|
+
import { Toast, Button } from "cleanplate";
|
|
55
|
+
|
|
56
|
+
const App = () => {
|
|
57
|
+
const toastRef = useRef(null);
|
|
58
|
+
const showToast = () => {
|
|
59
|
+
toastRef.current?.addMessage({ mode: "success", message: "Saved!" });
|
|
60
|
+
};
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<Button onClick={showToast}>Save</Button>
|
|
64
|
+
<Toast ref={toastRef} />
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Variants
|
|
71
|
+
|
|
72
|
+
```jsx
|
|
73
|
+
toastRef.current?.addMessage({ mode: "info", message: "Info message" });
|
|
74
|
+
toastRef.current?.addMessage({ mode: "error", message: "Error message" });
|
|
75
|
+
toastRef.current?.addMessage({ mode: "warning", message: "Warning message" });
|
|
76
|
+
toastRef.current?.addMessage({ mode: "success", message: "Success message" });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### With auto close
|
|
80
|
+
|
|
81
|
+
```jsx
|
|
82
|
+
<Toast ref={toastRef} autoClose autoCloseTime={5000} />
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Behavior Notes
|
|
86
|
+
|
|
87
|
+
- **Imperative handle:** `forwardRef` + `useImperativeHandle` expose `addMessage` on the ref. The parent never manages a toast list.
|
|
88
|
+
- **Portal:** Toasts render in a div prepended to `document.body`, fixed at top-right (16px).
|
|
89
|
+
- **Icon:** Each mode maps to an icon via `getVariantIcon` (error → "error", success → "check_circle", info → "info").
|
|
90
|
+
- **Click to dismiss:** Clicking a toast removes it.
|
|
91
|
+
|
|
92
|
+
## Related Components / Links
|
|
93
|
+
|
|
94
|
+
- Alert (inline feedback; use when the message should stay in the layout)
|
|
95
|
+
- Button (commonly used to trigger toasts)
|
|
96
|
+
- Container (layout around trigger buttons)
|