@omer-x/tailwind-ui-kit 1.0.0-alpha.41 → 1.0.0-alpha.43
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 +279 -1
- package/dist/components/feedback/BaseToast.d.ts +72 -0
- package/dist/components/feedback/BaseToast.js +49 -0
- package/dist/components/feedback/BaseToastAction.d.ts +14 -0
- package/dist/components/feedback/BaseToastAction.js +10 -0
- package/dist/components/feedback/BaseToastArrow.d.ts +18 -0
- package/dist/components/feedback/BaseToastArrow.js +10 -0
- package/dist/components/feedback/BaseToastClose.d.ts +14 -0
- package/dist/components/feedback/BaseToastClose.js +10 -0
- package/dist/components/feedback/BaseToastContent.d.ts +17 -0
- package/dist/components/feedback/BaseToastContent.js +14 -0
- package/dist/components/feedback/BaseToastDescription.d.ts +12 -0
- package/dist/components/feedback/BaseToastDescription.js +10 -0
- package/dist/components/feedback/BaseToastTitle.d.ts +15 -0
- package/dist/components/feedback/BaseToastTitle.js +10 -0
- package/dist/components/feedback/BaseToastViewport.d.ts +21 -0
- package/dist/components/feedback/BaseToastViewport.js +24 -0
- package/dist/components/feedback/createToastManager.d.ts +6 -0
- package/dist/components/feedback/createToastManager.js +10 -0
- package/dist/components/feedback/index.d.ts +9 -0
- package/dist/components/feedback/index.js +4 -0
- package/dist/components/feedback/toastStyles.d.ts +2 -0
- package/dist/components/feedback/toastStyles.js +47 -0
- package/dist/components/feedback/toastTypes.d.ts +81 -0
- package/dist/components/feedback/toastTypes.js +1 -0
- package/dist/components/feedback/useToast.d.ts +7 -0
- package/dist/components/feedback/useToast.js +8 -0
- package/dist/components/menu/menuTypes.d.ts +1 -1
- package/dist/components/overlay/BaseTooltip.d.ts +92 -0
- package/dist/components/overlay/BaseTooltip.js +24 -0
- package/dist/components/overlay/BaseTooltipArrow.d.ts +20 -0
- package/dist/components/overlay/BaseTooltipArrow.js +10 -0
- package/dist/components/overlay/BaseTooltipPopup.d.ts +106 -0
- package/dist/components/overlay/BaseTooltipPopup.js +38 -0
- package/dist/components/overlay/BaseTooltipTrigger.d.ts +31 -0
- package/dist/components/overlay/BaseTooltipTrigger.js +14 -0
- package/dist/components/overlay/BaseTooltipViewport.d.ts +20 -0
- package/dist/components/overlay/BaseTooltipViewport.js +11 -0
- package/dist/components/overlay/createTooltipHandle.d.ts +30 -0
- package/dist/components/overlay/createTooltipHandle.js +27 -0
- package/dist/components/overlay/index.d.ts +7 -0
- package/dist/components/overlay/index.js +3 -0
- package/dist/components/providers/ToastProvider.d.ts +23 -0
- package/dist/components/providers/ToastProvider.js +13 -0
- package/dist/components/providers/TooltipProvider.d.ts +19 -0
- package/dist/components/providers/TooltipProvider.js +10 -0
- package/dist/components/providers/index.d.ts +3 -0
- package/dist/components/providers/index.js +3 -0
- package/package.json +13 -1
package/README.md
CHANGED
|
@@ -459,8 +459,9 @@ const FormAlerts = () => {
|
|
|
459
459
|
// Toasts: fire once per submission, not on every re-render
|
|
460
460
|
const FormToasts = () => {
|
|
461
461
|
const { messages, submissionId } = useFormMessages();
|
|
462
|
+
const { add } = useToast();
|
|
462
463
|
useEffect(() => {
|
|
463
|
-
messages.forEach(m =>
|
|
464
|
+
messages.forEach(m => add({ type: m.type, description: m.text }));
|
|
464
465
|
}, [submissionId]);
|
|
465
466
|
return null;
|
|
466
467
|
};
|
|
@@ -1131,6 +1132,137 @@ import { BaseMenubar } from "@omer-x/tailwind-ui-kit/menu";
|
|
|
1131
1132
|
| `loopFocus` | `boolean` | `true` | Arrow keys wrap from the last trigger to the first |
|
|
1132
1133
|
| `render` | `RenderProp<"div", MenubarState>` | | The state is `{ orientation, modal, hasSubmenuOpen }` |
|
|
1133
1134
|
|
|
1135
|
+
### `@omer-x/tailwind-ui-kit/overlay`
|
|
1136
|
+
|
|
1137
|
+
#### `BaseTooltip`
|
|
1138
|
+
|
|
1139
|
+
A Base UI [`Tooltip`](https://base-ui.com/react/components/tooltip): a popup that shows a hint when its trigger is hovered or focused. `Popup` brings its portal and positioner, so a tooltip needs no more than this:
|
|
1140
|
+
|
|
1141
|
+
```tsx
|
|
1142
|
+
import { BaseTooltip } from "@omer-x/tailwind-ui-kit/overlay";
|
|
1143
|
+
|
|
1144
|
+
<BaseTooltip>
|
|
1145
|
+
<BaseTooltip.Trigger render={<Button />}>Save</BaseTooltip.Trigger>
|
|
1146
|
+
<BaseTooltip.Popup className="rounded bg-neutral-900 px-2 py-1 text-xs text-white" sideOffset={8}>
|
|
1147
|
+
Saves your changes
|
|
1148
|
+
<BaseTooltip.Arrow className="size-2 rotate-45 bg-neutral-900 data-[side=top]:-bottom-1 data-[side=bottom]:-top-1" />
|
|
1149
|
+
</BaseTooltip.Popup>
|
|
1150
|
+
</BaseTooltip>
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
The parts use dot notation, so build tooltips in a `"use client"` file. A tooltip is only a visual hint: it isn't announced to screen readers, so keep the trigger's accessible name (text or `aria-label`) meaningful without it.
|
|
1154
|
+
|
|
1155
|
+
| Part | Renders | Description |
|
|
1156
|
+
|------|---------|-------------|
|
|
1157
|
+
| `BaseTooltip` | nothing | Groups the parts and holds the open state |
|
|
1158
|
+
| `BaseTooltip.Trigger` | `<button>` | Opens the tooltip on hover (after `delay`) or keyboard focus. `data-popup-open` while its tooltip is open, `data-trigger-disabled` when `disabled` |
|
|
1159
|
+
| `BaseTooltip.Popup` | `<div>` | The tooltip, portaled and placed against the trigger, with scale and fade transitions (skipped while `data-instant`) |
|
|
1160
|
+
| `BaseTooltip.Arrow` | `<div>` | An arrow pointing at the trigger, inside `Popup`. `data-side`, `data-align`, `data-uncentered`. Draw it yourself |
|
|
1161
|
+
| `BaseTooltip.Viewport` | `<div>` | Animates the content when one tooltip is opened by several triggers and its content depends on the trigger. `data-activation-direction`, `data-transitioning` |
|
|
1162
|
+
| `BaseTooltip.Provider` | nothing | The same component as [`TooltipProvider`](#tooltipprovider) |
|
|
1163
|
+
|
|
1164
|
+
`BaseTooltip` props:
|
|
1165
|
+
|
|
1166
|
+
| Prop | Type | Default | Description |
|
|
1167
|
+
|------|------|---------|-------------|
|
|
1168
|
+
| `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
|
|
1169
|
+
| `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
|
|
1170
|
+
| `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
|
|
1171
|
+
| `disableHoverablePopup` | `boolean` | `false` | Closes the tooltip as soon as the pointer leaves the trigger, even onto the popup |
|
|
1172
|
+
| `trackCursorAxis` | `"none" \| "x" \| "y" \| "both"` | `"none"` | Makes the popup follow the pointer along this axis |
|
|
1173
|
+
| `disabled` | `boolean` | `false` | No trigger opens the tooltip |
|
|
1174
|
+
| `actionsRef` | `RefObject<TooltipActions>` | | `actionsRef.current?.close()` |
|
|
1175
|
+
| `handle` | `TooltipHandle<Payload>` | | Connects triggers outside the tooltip and opens it from code (see below) |
|
|
1176
|
+
| `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open tooltip belongs to |
|
|
1177
|
+
| `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the tooltip |
|
|
1178
|
+
|
|
1179
|
+
`BaseTooltip.Trigger` props:
|
|
1180
|
+
|
|
1181
|
+
| Prop | Type | Default | Description |
|
|
1182
|
+
|------|------|---------|-------------|
|
|
1183
|
+
| `delay` | `number` | `600` | The wait before opening on hover, in ms. Overrides `TooltipProvider`'s |
|
|
1184
|
+
| `closeDelay` | `number` | `0` | The wait before closing, in ms. Overrides `TooltipProvider`'s |
|
|
1185
|
+
| `closeOnClick` | `boolean` | `true` | Closes the tooltip when the trigger is clicked |
|
|
1186
|
+
| `disabled` | `boolean` | `false` | Stops this trigger from opening the tooltip. The element stays enabled: to disable the button too, pass `disabled` to the `render` element |
|
|
1187
|
+
| `handle` / `payload` | `TooltipHandle<Payload>` / `Payload` | | Connects a trigger outside its `BaseTooltip`, and the payload it passes (see below) |
|
|
1188
|
+
| `render` | `RenderProp<"button", TooltipTriggerState>` | | The state is `{ open }`. Use it to render your themed button, or any other element |
|
|
1189
|
+
|
|
1190
|
+
`BaseTooltip.Popup` props:
|
|
1191
|
+
|
|
1192
|
+
| Prop | Type | Default | Description |
|
|
1193
|
+
|------|------|---------|-------------|
|
|
1194
|
+
| `side` / `align` | `TooltipSide` / `TooltipAlign` | `"top"` / `"center"` | Where the popup sits against the trigger (`"top"`, `"bottom"`, `"left"`, `"right"`, `"inline-start"`, `"inline-end"` / `"start"`, `"center"`, `"end"`). It flips when there's no room |
|
|
1195
|
+
| `sideOffset` / `alignOffset` | `number \| TooltipOffsetFunction` | | Offsets from the anchor, in pixels, or a function of the placement and sizes |
|
|
1196
|
+
| `collisionPadding` | `number \| { top, right, bottom, left }` | `5` | Space kept from the viewport edges |
|
|
1197
|
+
| `collisionBoundary` / `collisionAvoidance` | | `"clipping-ancestors"` | The area the popup stays inside, and how it avoids its edges (flip or shift) |
|
|
1198
|
+
| `anchor` | `Element \| RefObject \| () => Element \| null` | the trigger | The element the popup is placed against |
|
|
1199
|
+
| `disableAnchorTracking` | `boolean` | `false` | Stops following the anchor when it moves |
|
|
1200
|
+
| `arrowPadding` | `number` | `5` | Minimum distance between an `Arrow` and the popup's corners |
|
|
1201
|
+
| `sticky` | `boolean` | `false` | Stays in view while the anchor scrolls away |
|
|
1202
|
+
| `positionMethod` | `"absolute" \| "fixed"` | `"absolute"` | Use `"fixed"` when the anchor is inside a fixed container |
|
|
1203
|
+
| `positionerClassName` / `renderPositioner` | `string` / `RenderProp<"div", TooltipPositionerState>` | | Style or replace the positioner, the `<div>` around the popup that places it (`z-50`) |
|
|
1204
|
+
| `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
|
|
1205
|
+
| `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
|
|
1206
|
+
| `render` | `RenderProp<"div", TooltipPopupState>` | | The state is `{ open, side, align, instant }` |
|
|
1207
|
+
|
|
1208
|
+
Data attributes: the popup has `data-open` / `data-closed`, `data-side`, `data-align` and `data-starting-style` / `data-ending-style` during transitions. `data-instant` is set when the transition should be skipped: `"delay"` (another tooltip was just open), `"focus"` (opened by keyboard focus) or `"dismiss"` (closed by Escape or a click). The popup's own transition is turned off then (`data-instant:transition-none`).
|
|
1209
|
+
|
|
1210
|
+
#### `createTooltipHandle`
|
|
1211
|
+
|
|
1212
|
+
Opens one tooltip from triggers anywhere on the page, or from code. Each trigger can pass a `payload`, which the tooltip's function children receive:
|
|
1213
|
+
|
|
1214
|
+
```tsx
|
|
1215
|
+
import { BaseTooltip, createTooltipHandle } from "@omer-x/tailwind-ui-kit/overlay";
|
|
1216
|
+
|
|
1217
|
+
const shortcutTooltip = createTooltipHandle<{ id: string, keys: string }>();
|
|
1218
|
+
|
|
1219
|
+
// triggers anywhere on the page
|
|
1220
|
+
<BaseTooltip.Trigger id={`shortcut-${s.id}`} handle={shortcutTooltip} payload={s} render={<Button />}>{s.label}</BaseTooltip.Trigger>
|
|
1221
|
+
|
|
1222
|
+
// one tooltip on the page
|
|
1223
|
+
<BaseTooltip handle={shortcutTooltip}>
|
|
1224
|
+
{({ payload }) => payload && (
|
|
1225
|
+
<BaseTooltip.Popup>{payload.keys}</BaseTooltip.Popup>
|
|
1226
|
+
)}
|
|
1227
|
+
</BaseTooltip>
|
|
1228
|
+
|
|
1229
|
+
// from code
|
|
1230
|
+
shortcutTooltip.open("shortcut-copy");
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
A `TooltipHandle<Payload>` has `open(triggerId)`, `close()` and `isOpen`. Like `MenuHandle`, it has no `openWithPayload`: a tooltip is placed against its trigger, so `open` needs the `id` of a trigger with the same handle.
|
|
1234
|
+
|
|
1235
|
+
- Calls are **ignored while the tooltip isn't mounted**. Keep the `BaseTooltip` with the handle rendered.
|
|
1236
|
+
- Call them **from event handlers or effects, never during render**.
|
|
1237
|
+
|
|
1238
|
+
### `@omer-x/tailwind-ui-kit/providers`
|
|
1239
|
+
|
|
1240
|
+
#### `TooltipProvider`
|
|
1241
|
+
|
|
1242
|
+
Shares the hover delay between the tooltips inside it: once one tooltip is shown, the next one opens instantly. Place it once around your app (or a toolbar) in a `"use client"` file. It renders no element and is also available as `BaseTooltip.Provider`.
|
|
1243
|
+
|
|
1244
|
+
```tsx
|
|
1245
|
+
import { TooltipProvider } from "@omer-x/tailwind-ui-kit/providers";
|
|
1246
|
+
|
|
1247
|
+
<TooltipProvider delay={300}>{children}</TooltipProvider>
|
|
1248
|
+
```
|
|
1249
|
+
|
|
1250
|
+
| Prop | Type | Default | Description |
|
|
1251
|
+
|------|------|---------|-------------|
|
|
1252
|
+
| `delay` | `number` | `600` | The wait before opening a tooltip on hover, in ms. A trigger's own `delay` wins |
|
|
1253
|
+
| `closeDelay` | `number` | `0` | The wait before closing a tooltip, in ms. A trigger's own `closeDelay` wins |
|
|
1254
|
+
| `timeout` | `number` | `400` | A tooltip opened within this time after another one closed opens without a delay, in ms |
|
|
1255
|
+
|
|
1256
|
+
#### `ToastProvider`
|
|
1257
|
+
|
|
1258
|
+
Holds the toasts of the app (or a part of it). [`useToast`](#usetoast) and [`BaseToast.Viewport`](#basetoast) work inside it. Renders no element and is also available as `BaseToast.Provider`.
|
|
1259
|
+
|
|
1260
|
+
| Prop | Type | Default | Description |
|
|
1261
|
+
|------|------|---------|-------------|
|
|
1262
|
+
| `timeout` | `number` | `5000` | Milliseconds before a toast closes by itself. `0` keeps toasts open until they are closed |
|
|
1263
|
+
| `limit` | `number` | `3` | The most toasts shown at once. Older ones get `data-limited`, and the kit hides them |
|
|
1264
|
+
| `manager` | `ToastManager` | | Shows the toasts of a [`createToastManager`](#createtoastmanager) manager |
|
|
1265
|
+
|
|
1134
1266
|
### `@omer-x/tailwind-ui-kit/disclosure`
|
|
1135
1267
|
|
|
1136
1268
|
#### `BaseAccordion`
|
|
@@ -1364,6 +1496,152 @@ To place the parts yourself, e.g. the value inside the track, pass them as child
|
|
|
1364
1496
|
|
|
1365
1497
|
Render functions get `MeterState`, which is empty for now. The meter sets no data attributes: style value ranges in your wrapper (e.g. pick the indicator color from `value`).
|
|
1366
1498
|
|
|
1499
|
+
### `@omer-x/tailwind-ui-kit/feedback`
|
|
1500
|
+
|
|
1501
|
+
#### `BaseToast`
|
|
1502
|
+
|
|
1503
|
+
A Base UI [`Toast`](https://base-ui.com/react/components/toast): short notifications that stack in a corner of the screen and close by themselves. Toasts live in a [`ToastProvider`](#toastprovider), are created with [`useToast`](#usetoast) (or a [`createToastManager`](#createtoastmanager) manager outside React) and are shown by one `BaseToast.Viewport`, which renders each toast with your parts.
|
|
1504
|
+
|
|
1505
|
+
Theme it once, next to the provider:
|
|
1506
|
+
|
|
1507
|
+
```tsx
|
|
1508
|
+
// src/components/Toasts.tsx
|
|
1509
|
+
"use client";
|
|
1510
|
+
import { BaseToast } from "@omer-x/tailwind-ui-kit/feedback";
|
|
1511
|
+
import { ToastProvider } from "@omer-x/tailwind-ui-kit/providers";
|
|
1512
|
+
import type { ReactNode } from "react";
|
|
1513
|
+
|
|
1514
|
+
const Toasts = ({ children }: { children: ReactNode }) => (
|
|
1515
|
+
<ToastProvider>
|
|
1516
|
+
{children}
|
|
1517
|
+
<BaseToast.Viewport>
|
|
1518
|
+
{toast => (
|
|
1519
|
+
<BaseToast
|
|
1520
|
+
toast={toast}
|
|
1521
|
+
className="rounded-md border bg-white p-4 shadow-lg data-[type=error]:border-red-300 data-[type=error]:bg-red-50"
|
|
1522
|
+
>
|
|
1523
|
+
<BaseToast.Content className="pr-6">
|
|
1524
|
+
<BaseToast.Title className="font-semibold" />
|
|
1525
|
+
<BaseToast.Description className="text-neutral-600" />
|
|
1526
|
+
<BaseToast.Action className="mt-2 rounded border px-2 py-1 text-xs" />
|
|
1527
|
+
<BaseToast.Close aria-label="Close" className="absolute top-2 right-2"><XIcon /></BaseToast.Close>
|
|
1528
|
+
</BaseToast.Content>
|
|
1529
|
+
</BaseToast>
|
|
1530
|
+
)}
|
|
1531
|
+
</BaseToast.Viewport>
|
|
1532
|
+
</ToastProvider>
|
|
1533
|
+
);
|
|
1534
|
+
|
|
1535
|
+
export default Toasts;
|
|
1536
|
+
```
|
|
1537
|
+
|
|
1538
|
+
Then show toasts from any client component inside it:
|
|
1539
|
+
|
|
1540
|
+
```tsx
|
|
1541
|
+
const { add } = useToast();
|
|
1542
|
+
|
|
1543
|
+
add({ title: "Saved", description: "Your changes were saved.", type: "success" });
|
|
1544
|
+
```
|
|
1545
|
+
|
|
1546
|
+
| Part | Renders | Description |
|
|
1547
|
+
|------|---------|-------------|
|
|
1548
|
+
| `BaseToast.Viewport` | `<div>` | The region the toasts are shown in (`role="region"`, `aria-label="Notifications"`: pass your own `aria-label` to translate it), with its portal. Fixed to the bottom right corner (`fixed right-4 bottom-4 w-80`); move it with `className`. F6 moves focus into it. `data-expanded` while hovered or focused |
|
|
1549
|
+
| `BaseToast` | `<div>` | One toast (`role="dialog"`, or `"alertdialog"` for `priority: "high"`), named by its title and described by its description. In the viewport, toasts stack from the bottom: the newest in front, older ones peeking behind it, all of them spread out while the viewport is expanded. It can be swiped away. An anchored toast is placed next to its anchor instead (see below) |
|
|
1550
|
+
| `BaseToast.Content` | `<div>` | The toast's content. Hidden (`data-behind`) while the toast is behind another one in a collapsed stack |
|
|
1551
|
+
| `BaseToast.Title` | `<h2>` | Shows the toast's `title` unless it has children. Renders nothing when both are empty |
|
|
1552
|
+
| `BaseToast.Description` | `<p>` | Shows the toast's `description` unless it has children. Renders nothing when both are empty |
|
|
1553
|
+
| `BaseToast.Action` | `<button>` | Gets the toast's `actionProps` (`children`, `onClick`, …). Renders nothing without children |
|
|
1554
|
+
| `BaseToast.Close` | `<button>` | Closes the toast. Give it an `aria-label` when its content is an icon. It is `aria-hidden` until the viewport is expanded or focus is inside the toast |
|
|
1555
|
+
| `BaseToast.Arrow` | `<div>` | Points at an anchored toast's anchor. Size and draw it with `className` or `children`. `data-side`, `data-align`, `data-uncentered` |
|
|
1556
|
+
|
|
1557
|
+
Every part takes `className` and `render`.
|
|
1558
|
+
|
|
1559
|
+
`BaseToast.Viewport` props:
|
|
1560
|
+
|
|
1561
|
+
| Prop | Type | Default | Description |
|
|
1562
|
+
|------|------|---------|-------------|
|
|
1563
|
+
| `children` | `(toast: ToastObject<Data>) => ReactNode` | | Renders one toast, usually a `BaseToast` (no `key` needed) |
|
|
1564
|
+
| `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the viewport is portaled to |
|
|
1565
|
+
| `render` | `RenderProp<"div", ToastViewportState>` | | The state is `{ expanded }` |
|
|
1566
|
+
|
|
1567
|
+
`BaseToast` props:
|
|
1568
|
+
|
|
1569
|
+
| Prop | Type | Default | Description |
|
|
1570
|
+
|------|------|---------|-------------|
|
|
1571
|
+
| `toast` | `ToastObject` | | The toast to show, from the viewport's children function |
|
|
1572
|
+
| `swipeDirection` | `ToastSwipeDirection \| ToastSwipeDirection[]` | `["down", "right"]` | The directions (`"up"`, `"down"`, `"left"`, `"right"`) it can be swiped to close it. Anchored toasts can't be swiped |
|
|
1573
|
+
| `positionerClassName` | `string` | | Classes for an anchored toast's positioner, the `<div>` that places it (`z-50`) |
|
|
1574
|
+
| `renderPositioner` | `RenderProp<"div", ToastPositionerState>` | | The state is `{ side, align, anchorHidden }` |
|
|
1575
|
+
| `render` | `RenderProp<"div", ToastState>` | | The state is `{ transitionStatus, expanded, limited, type, swiping, swipeDirection }` |
|
|
1576
|
+
|
|
1577
|
+
`Title`, `Description`, `Action` and `Close` render functions get `{ type }`. `Action` and `Close` take `nativeButton={false}` when `render` isn't a `<button>`.
|
|
1578
|
+
|
|
1579
|
+
Data attributes: every part except the viewport and the arrow has `data-type` (the toast's `type`). `BaseToast` also has `data-expanded`, `data-limited` (over the provider's `limit`; the kit hides it), `data-swiping`, `data-swipe-direction` and `data-starting-style` / `data-ending-style` during its transitions. `BaseToast.Content` has `data-expanded` and `data-behind`.
|
|
1580
|
+
|
|
1581
|
+
**Types.** `type` is any string, set as `data-type`. The kit defines no type names: style yours with `data-[type=…]:` variants. Form messages fit as they are: `add({ type: m.type, description: m.text })` for each message of [`useFormMessages`](#useformmessages) (`"error"` or `"warning"`).
|
|
1582
|
+
|
|
1583
|
+
**Anchored toasts.** A toast created with `positionerProps.anchor` is wrapped in a positioner and placed against that element, like a tooltip that closes by itself (e.g. "Copied" next to a copy button). It fades and scales in instead of stacking. Put a `BaseToast.Arrow` in it to point at the anchor:
|
|
1584
|
+
|
|
1585
|
+
```tsx
|
|
1586
|
+
add({ title: "Copied", positionerProps: { anchor: buttonRef.current, side: "top", sideOffset: 8 } });
|
|
1587
|
+
```
|
|
1588
|
+
|
|
1589
|
+
`positionerProps` (`ToastPositionerOptions`) takes `anchor`, `side` (`"top"`), `align` (`"center"`), `sideOffset` (`0`), `alignOffset` (`0`), `collisionPadding` (`5`), `arrowPadding` (`5`), `sticky`, `positionMethod` (`"absolute"`) and `disableAnchorTracking`. Anchored and stacked toasts usually get separate providers (and viewports) so they don't share a stack and a `limit`.
|
|
1590
|
+
|
|
1591
|
+
#### `useToast`
|
|
1592
|
+
|
|
1593
|
+
Shows, updates and closes the toasts of the surrounding `ToastProvider`. Pass a type for your toasts' custom `data`: `useToast<{ icon: string }>()`.
|
|
1594
|
+
|
|
1595
|
+
```ts
|
|
1596
|
+
const { toasts, add, update, close, promise } = useToast();
|
|
1597
|
+
|
|
1598
|
+
const id = add({ title: "Uploading…", timeout: 0 });
|
|
1599
|
+
update(id, { title: "Uploaded", type: "success", timeout: 5000 });
|
|
1600
|
+
close(id); // or close() for every toast
|
|
1601
|
+
|
|
1602
|
+
await promise(upload(file), {
|
|
1603
|
+
loading: "Uploading…", // a string is a shortcut for { description }
|
|
1604
|
+
success: result => ({ title: "Uploaded", description: result.name, type: "success" }),
|
|
1605
|
+
error: error => ({ title: "Upload failed", type: "error" }),
|
|
1606
|
+
});
|
|
1607
|
+
```
|
|
1608
|
+
|
|
1609
|
+
`add` options (`ToastOptions`):
|
|
1610
|
+
|
|
1611
|
+
| Option | Type | Default | Description |
|
|
1612
|
+
|--------|------|---------|-------------|
|
|
1613
|
+
| `title` | `ReactNode` | | |
|
|
1614
|
+
| `description` | `ReactNode` | | |
|
|
1615
|
+
| `type` | `string` | | Set as `data-type` |
|
|
1616
|
+
| `timeout` | `number` | the provider's | Milliseconds before it closes by itself. `0` keeps it open. Timers pause while the viewport is hovered or focused, or the window loses focus |
|
|
1617
|
+
| `priority` | `"low" \| "high"` | `"low"` | Announced politely, or urgently (`role="alertdialog"`) |
|
|
1618
|
+
| `id` | `string` | generated | Adding a toast with an existing `id` updates it in place and restarts its timer |
|
|
1619
|
+
| `actionProps` | `ComponentProps<"button">` | | Props of `BaseToast.Action` |
|
|
1620
|
+
| `data` | `Data` | | Your own data, e.g. to pick an icon in the viewport |
|
|
1621
|
+
| `onClose` | `() => void` | | Called when it starts closing |
|
|
1622
|
+
| `onRemove` | `() => void` | | Called when it is removed, after its exit transition |
|
|
1623
|
+
| `positionerProps` | `ToastPositionerOptions` | | Anchors the toast to an element |
|
|
1624
|
+
|
|
1625
|
+
`toasts` (`ToastObject[]`, newest first) are the shown toasts, with their `id`. `BaseToast.Viewport` already renders them; use it to show a count, for example.
|
|
1626
|
+
|
|
1627
|
+
#### `createToastManager`
|
|
1628
|
+
|
|
1629
|
+
Creates a toast manager (`ToastManager`, with `add`, `update`, `close` and `promise` as in `useToast`) for code outside React, such as a fetch wrapper. Give it to a provider, which shows its toasts. Calls are ignored while no provider uses it.
|
|
1630
|
+
|
|
1631
|
+
```ts
|
|
1632
|
+
// src/toasts.ts
|
|
1633
|
+
export const toastManager = createToastManager();
|
|
1634
|
+
|
|
1635
|
+
// anywhere
|
|
1636
|
+
toastManager.add({ title: "Session expired", type: "error" });
|
|
1637
|
+
```
|
|
1638
|
+
|
|
1639
|
+
```tsx
|
|
1640
|
+
<ToastProvider manager={toastManager}>…</ToastProvider>
|
|
1641
|
+
```
|
|
1642
|
+
|
|
1643
|
+
`useToast` inside that provider manages the same toasts.
|
|
1644
|
+
|
|
1367
1645
|
### `@omer-x/tailwind-ui-kit/layout`
|
|
1368
1646
|
|
|
1369
1647
|
#### `Container`
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ToastAlign, ToastManager, ToastObject, ToastSide, ToastSwipeDirection } from "./toastTypes.js";
|
|
2
|
+
import { ToastViewportState } from "./BaseToastViewport.js";
|
|
3
|
+
import { ToastContentState } from "./BaseToastContent.js";
|
|
4
|
+
import { ToastPartState } from "./BaseToastTitle.js";
|
|
5
|
+
import { ToastArrowState } from "./BaseToastArrow.js";
|
|
6
|
+
import { RenderProp } from "../../utils/render.js";
|
|
7
|
+
import { ComponentProps } from "react";
|
|
8
|
+
export type ToastState = {
|
|
9
|
+
/** `"starting"` while it enters, `"ending"` while it leaves. */
|
|
10
|
+
transitionStatus: "starting" | "ending" | "idle" | undefined;
|
|
11
|
+
/** Whether the viewport's stack is expanded (hovered or focused). */
|
|
12
|
+
expanded: boolean;
|
|
13
|
+
/** Whether it is hidden because more than `limit` toasts are shown. */
|
|
14
|
+
limited: boolean;
|
|
15
|
+
type: string | undefined;
|
|
16
|
+
swiping: boolean;
|
|
17
|
+
swipeDirection: ToastSwipeDirection | undefined;
|
|
18
|
+
};
|
|
19
|
+
export type ToastPositionerState = {
|
|
20
|
+
side: ToastSide;
|
|
21
|
+
align: ToastAlign;
|
|
22
|
+
/** Whether the anchor is scrolled out of view. */
|
|
23
|
+
anchorHidden: boolean;
|
|
24
|
+
};
|
|
25
|
+
type BaseToastProps = ComponentProps<"div"> & {
|
|
26
|
+
/** The toast to show, from `BaseToast.Viewport`'s children function (or `useToast().toasts`). */
|
|
27
|
+
toast: ToastObject<object>;
|
|
28
|
+
render?: RenderProp<"div", ToastState>;
|
|
29
|
+
/**
|
|
30
|
+
* The directions it can be swiped to close it. Anchored toasts can't be swiped.
|
|
31
|
+
* @default ["down", "right"]
|
|
32
|
+
*/
|
|
33
|
+
swipeDirection?: ToastSwipeDirection | ToastSwipeDirection[];
|
|
34
|
+
/** Classes for the positioner, the `<div>` that places an anchored toast. */
|
|
35
|
+
positionerClassName?: string;
|
|
36
|
+
/** Style or replace an anchored toast's positioner. A `className` on the element wins over the kit's conflicting classes. */
|
|
37
|
+
renderPositioner?: RenderProp<"div", ToastPositionerState>;
|
|
38
|
+
};
|
|
39
|
+
declare const _default: (({ toast, swipeDirection, positionerClassName, renderPositioner, className, ...otherProps }: BaseToastProps) => import("react").JSX.Element) & {
|
|
40
|
+
Provider: <Data extends object = object>({ manager, ...otherProps }: {
|
|
41
|
+
children?: import("react").ReactNode;
|
|
42
|
+
timeout?: number;
|
|
43
|
+
limit?: number;
|
|
44
|
+
manager?: ToastManager<Data> | undefined;
|
|
45
|
+
}) => import("react").JSX.Element;
|
|
46
|
+
Viewport: <Data extends object = object>({ container, children, className, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "children"> & {
|
|
47
|
+
render?: RenderProp<"div", ToastViewportState>;
|
|
48
|
+
container?: HTMLElement | ShadowRoot | import("react").RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
49
|
+
children: (toast: ToastObject<Data>) => import("react").ReactNode;
|
|
50
|
+
}) => import("react").JSX.Element;
|
|
51
|
+
Content: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
52
|
+
render?: RenderProp<"div", ToastContentState>;
|
|
53
|
+
}) => import("react").JSX.Element;
|
|
54
|
+
Title: (props: import("react").ClassAttributes<HTMLHeadingElement> & import("react").HTMLAttributes<HTMLHeadingElement> & {
|
|
55
|
+
render?: RenderProp<"h2", ToastPartState>;
|
|
56
|
+
}) => import("react").JSX.Element;
|
|
57
|
+
Description: (props: import("react").ClassAttributes<HTMLParagraphElement> & import("react").HTMLAttributes<HTMLParagraphElement> & {
|
|
58
|
+
render?: RenderProp<"p", ToastPartState>;
|
|
59
|
+
}) => import("react").JSX.Element;
|
|
60
|
+
Action: (props: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
61
|
+
render?: RenderProp<"button", ToastPartState>;
|
|
62
|
+
nativeButton?: boolean;
|
|
63
|
+
}) => import("react").JSX.Element;
|
|
64
|
+
Close: (props: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
65
|
+
render?: RenderProp<"button", ToastPartState>;
|
|
66
|
+
nativeButton?: boolean;
|
|
67
|
+
}) => import("react").JSX.Element;
|
|
68
|
+
Arrow: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
69
|
+
render?: RenderProp<"div", ToastArrowState>;
|
|
70
|
+
}) => import("react").JSX.Element;
|
|
71
|
+
};
|
|
72
|
+
export { _default as default };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { splitClassName } from "../../utils/split-class-name.js";
|
|
5
|
+
import ToastProvider from "../providers/ToastProvider.js";
|
|
6
|
+
import BaseToastAction from "./BaseToastAction.js";
|
|
7
|
+
import BaseToastArrow from "./BaseToastArrow.js";
|
|
8
|
+
import BaseToastClose from "./BaseToastClose.js";
|
|
9
|
+
import BaseToastContent from "./BaseToastContent.js";
|
|
10
|
+
import BaseToastDescription from "./BaseToastDescription.js";
|
|
11
|
+
import BaseToastTitle from "./BaseToastTitle.js";
|
|
12
|
+
import BaseToastViewport from "./BaseToastViewport.js";
|
|
13
|
+
import { anchoredToastClassName, stackedToastClassName } from "./toastStyles.js";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
// src/components/feedback/BaseToast.tsx
|
|
16
|
+
/**
|
|
17
|
+
* One toast. Renders a `<div>` (`role="dialog"`, or `"alertdialog"` for `priority: "high"`)
|
|
18
|
+
* with `data-type`, `data-expanded`, `data-limited`, `data-swiping`, `data-swipe-direction` and transition attributes.
|
|
19
|
+
* In the viewport, toasts stack; a toast with `positionerProps.anchor` is placed against its anchor instead.
|
|
20
|
+
*/
|
|
21
|
+
const BaseToast = ({ toast, swipeDirection, positionerClassName, renderPositioner, className, ...otherProps }) => {
|
|
22
|
+
const baseUIToast = toast;
|
|
23
|
+
const anchored = toast.positionerProps?.anchor !== void 0;
|
|
24
|
+
const root = /* @__PURE__ */ jsx(Toast.Root, {
|
|
25
|
+
...otherProps,
|
|
26
|
+
toast: baseUIToast,
|
|
27
|
+
swipeDirection,
|
|
28
|
+
className: cn(anchored ? anchoredToastClassName : stackedToastClassName, className)
|
|
29
|
+
});
|
|
30
|
+
if (!anchored) return root;
|
|
31
|
+
const positionerElement = splitClassName(renderPositioner);
|
|
32
|
+
return /* @__PURE__ */ jsx(Toast.Positioner, {
|
|
33
|
+
toast: baseUIToast,
|
|
34
|
+
render: positionerElement.render,
|
|
35
|
+
className: cn("z-50", positionerClassName, positionerElement.className),
|
|
36
|
+
children: root
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var BaseToast_default = Object.assign(BaseToast, {
|
|
40
|
+
Provider: ToastProvider,
|
|
41
|
+
Viewport: BaseToastViewport,
|
|
42
|
+
Content: BaseToastContent,
|
|
43
|
+
Title: BaseToastTitle,
|
|
44
|
+
Description: BaseToastDescription,
|
|
45
|
+
Action: BaseToastAction,
|
|
46
|
+
Close: BaseToastClose,
|
|
47
|
+
Arrow: BaseToastArrow
|
|
48
|
+
});
|
|
49
|
+
export { BaseToast_default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ToastPartState } from "./BaseToastTitle.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type BaseToastActionProps = ComponentProps<"button"> & {
|
|
5
|
+
render?: RenderProp<"button", ToastPartState>;
|
|
6
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
7
|
+
nativeButton?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A button for the toast's action. The toast's `actionProps` are merged into it, and it renders nothing without children.
|
|
11
|
+
* Renders a `<button>` with `data-type`.
|
|
12
|
+
*/
|
|
13
|
+
declare const BaseToastAction: (props: BaseToastActionProps) => import("react").JSX.Element;
|
|
14
|
+
export { BaseToastAction as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/feedback/BaseToastAction.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A button for the toast's action. The toast's `actionProps` are merged into it, and it renders nothing without children.
|
|
7
|
+
* Renders a `<button>` with `data-type`.
|
|
8
|
+
*/
|
|
9
|
+
const BaseToastAction = (props) => /* @__PURE__ */ jsx(Toast.Action, { ...props });
|
|
10
|
+
export { BaseToastAction as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ToastAlign, ToastSide } from "./toastTypes.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
export type ToastArrowState = {
|
|
5
|
+
side: ToastSide;
|
|
6
|
+
align: ToastAlign;
|
|
7
|
+
/** Whether the arrow can't point at the center of the anchor. */
|
|
8
|
+
uncentered: boolean;
|
|
9
|
+
};
|
|
10
|
+
type BaseToastArrowProps = ComponentProps<"div"> & {
|
|
11
|
+
render?: RenderProp<"div", ToastArrowState>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* An arrow that points at an anchored toast's anchor. Put it inside `BaseToast`.
|
|
15
|
+
* Renders a `<div>` with `data-side` and `data-align`. Size and draw it with `className` or `children`.
|
|
16
|
+
*/
|
|
17
|
+
declare const BaseToastArrow: (props: BaseToastArrowProps) => import("react").JSX.Element;
|
|
18
|
+
export { BaseToastArrow as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/feedback/BaseToastArrow.tsx
|
|
5
|
+
/**
|
|
6
|
+
* An arrow that points at an anchored toast's anchor. Put it inside `BaseToast`.
|
|
7
|
+
* Renders a `<div>` with `data-side` and `data-align`. Size and draw it with `className` or `children`.
|
|
8
|
+
*/
|
|
9
|
+
const BaseToastArrow = (props) => /* @__PURE__ */ jsx(Toast.Arrow, { ...props });
|
|
10
|
+
export { BaseToastArrow as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ToastPartState } from "./BaseToastTitle.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type BaseToastCloseProps = ComponentProps<"button"> & {
|
|
5
|
+
render?: RenderProp<"button", ToastPartState>;
|
|
6
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
7
|
+
nativeButton?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A button that closes the toast. Give it an `aria-label` when its content is an icon.
|
|
11
|
+
* Renders a `<button>` with `data-type`.
|
|
12
|
+
*/
|
|
13
|
+
declare const BaseToastClose: (props: BaseToastCloseProps) => import("react").JSX.Element;
|
|
14
|
+
export { BaseToastClose as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/feedback/BaseToastClose.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A button that closes the toast. Give it an `aria-label` when its content is an icon.
|
|
7
|
+
* Renders a `<button>` with `data-type`.
|
|
8
|
+
*/
|
|
9
|
+
const BaseToastClose = (props) => /* @__PURE__ */ jsx(Toast.Close, { ...props });
|
|
10
|
+
export { BaseToastClose as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type ToastContentState = {
|
|
4
|
+
/** Whether the viewport's stack is expanded. */
|
|
5
|
+
expanded: boolean;
|
|
6
|
+
/** Whether the toast is behind the frontmost one in a collapsed stack. */
|
|
7
|
+
behind: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseToastContentProps = ComponentProps<"div"> & {
|
|
10
|
+
render?: RenderProp<"div", ToastContentState>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The toast's content. Hidden while the toast is behind another one in a collapsed stack.
|
|
14
|
+
* Renders a `<div>` with `data-behind` and `data-expanded`.
|
|
15
|
+
*/
|
|
16
|
+
declare const BaseToastContent: ({ className, ...otherProps }: BaseToastContentProps) => import("react").JSX.Element;
|
|
17
|
+
export { BaseToastContent as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/feedback/BaseToastContent.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The toast's content. Hidden while the toast is behind another one in a collapsed stack.
|
|
8
|
+
* Renders a `<div>` with `data-behind` and `data-expanded`.
|
|
9
|
+
*/
|
|
10
|
+
const BaseToastContent = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Toast.Content, {
|
|
11
|
+
...otherProps,
|
|
12
|
+
className: cn("overflow-hidden", "transition-opacity", "duration-250", "data-behind:pointer-events-none", "data-behind:opacity-0", "data-expanded:pointer-events-auto", "data-expanded:opacity-100", className)
|
|
13
|
+
});
|
|
14
|
+
export { BaseToastContent as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ToastPartState } from "./BaseToastTitle.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type BaseToastDescriptionProps = ComponentProps<"p"> & {
|
|
5
|
+
render?: RenderProp<"p", ToastPartState>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The toast's message, which also describes the toast. Shows the toast's `description` unless it has children,
|
|
9
|
+
* and renders nothing when both are empty. Renders a `<p>` with `data-type`.
|
|
10
|
+
*/
|
|
11
|
+
declare const BaseToastDescription: (props: BaseToastDescriptionProps) => import("react").JSX.Element;
|
|
12
|
+
export { BaseToastDescription as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/feedback/BaseToastDescription.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The toast's message, which also describes the toast. Shows the toast's `description` unless it has children,
|
|
7
|
+
* and renders nothing when both are empty. Renders a `<p>` with `data-type`.
|
|
8
|
+
*/
|
|
9
|
+
const BaseToastDescription = (props) => /* @__PURE__ */ jsx(Toast.Description, { ...props });
|
|
10
|
+
export { BaseToastDescription as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
/** The state of the toast's title, description, action and close button. */
|
|
4
|
+
export type ToastPartState = {
|
|
5
|
+
type: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
type BaseToastTitleProps = ComponentProps<"h2"> & {
|
|
8
|
+
render?: RenderProp<"h2", ToastPartState>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The toast's heading, which also names the toast. Shows the toast's `title` unless it has children,
|
|
12
|
+
* and renders nothing when both are empty. Renders an `<h2>` with `data-type`.
|
|
13
|
+
*/
|
|
14
|
+
declare const BaseToastTitle: (props: BaseToastTitleProps) => import("react").JSX.Element;
|
|
15
|
+
export { BaseToastTitle as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/feedback/BaseToastTitle.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The toast's heading, which also names the toast. Shows the toast's `title` unless it has children,
|
|
7
|
+
* and renders nothing when both are empty. Renders an `<h2>` with `data-type`.
|
|
8
|
+
*/
|
|
9
|
+
const BaseToastTitle = (props) => /* @__PURE__ */ jsx(Toast.Title, { ...props });
|
|
10
|
+
export { BaseToastTitle as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode, RefObject } from "react";
|
|
2
|
+
import { ToastObject } from "./toastTypes.js";
|
|
3
|
+
import { RenderProp } from "../../utils/render.js";
|
|
4
|
+
export type ToastViewportState = {
|
|
5
|
+
/** Whether the stack is expanded (hovered or focused). */
|
|
6
|
+
expanded: boolean;
|
|
7
|
+
};
|
|
8
|
+
type BaseToastViewportProps<Data extends object> = Omit<ComponentProps<"div">, "children"> & {
|
|
9
|
+
render?: RenderProp<"div", ToastViewportState>;
|
|
10
|
+
/** Where the viewport is portaled to. Defaults to `<body>`. */
|
|
11
|
+
container?: HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
12
|
+
/** Renders one toast, usually a `BaseToast`. Called for every toast of the provider. */
|
|
13
|
+
children: (toast: ToastObject<Data>) => ReactNode;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The region the toasts are shown in, with its portal. Put it once inside `ToastProvider`.
|
|
17
|
+
* Renders a `<div>` fixed to the bottom right corner (move it with `className`) with `data-expanded`.
|
|
18
|
+
* F6 moves focus into it.
|
|
19
|
+
*/
|
|
20
|
+
declare const BaseToastViewport: <Data extends object = object>({ container, children, className, ...otherProps }: BaseToastViewportProps<Data>) => import("react").JSX.Element;
|
|
21
|
+
export { BaseToastViewport as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Toast } from "@base-ui/react/toast";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { Fragment } from "react";
|
|
5
|
+
import useToast from "./useToast.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/feedback/BaseToastViewport.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The region the toasts are shown in, with its portal. Put it once inside `ToastProvider`.
|
|
10
|
+
* Renders a `<div>` fixed to the bottom right corner (move it with `className`) with `data-expanded`.
|
|
11
|
+
* F6 moves focus into it.
|
|
12
|
+
*/
|
|
13
|
+
const BaseToastViewport = ({ container, children, className, ...otherProps }) => {
|
|
14
|
+
const { toasts } = useToast();
|
|
15
|
+
return /* @__PURE__ */ jsx(Toast.Portal, {
|
|
16
|
+
container,
|
|
17
|
+
children: /* @__PURE__ */ jsx(Toast.Viewport, {
|
|
18
|
+
...otherProps,
|
|
19
|
+
className: cn("fixed", "right-4", "bottom-4", "z-50", "w-80", "max-w-[calc(100vw-2rem)]", "outline-hidden", className),
|
|
20
|
+
children: toasts.map((toast) => /* @__PURE__ */ jsx(Fragment, { children: children(toast) }, toast.id))
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export { BaseToastViewport as default };
|