@moltenship/calendar 1.0.0-rc.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/docs/accessibility.md +305 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +116 -0
- package/docs/agents/connect.md +444 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +511 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +355 -0
- package/docs/annotations.md +198 -0
- package/docs/api/changes.md +264 -0
- package/docs/api/components.md +245 -0
- package/docs/api/dnd-kit.md +265 -0
- package/docs/api/events.md +153 -0
- package/docs/api/primitives.md +218 -0
- package/docs/api/store.md +92 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +576 -0
- package/docs/comparison.md +278 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +163 -0
- package/docs/concepts/how-it-works.md +112 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +168 -0
- package/docs/customization.md +271 -0
- package/docs/frameworks.md +116 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/ics/feed.md +484 -0
- package/docs/ics/import.md +183 -0
- package/docs/ics/reference.md +482 -0
- package/docs/ics.md +142 -0
- package/docs/index.md +149 -0
- package/docs/installation.md +209 -0
- package/docs/interactions.md +441 -0
- package/docs/llms.txt +99 -0
- package/docs/migrating-to-2.md +497 -0
- package/docs/quick-start.md +163 -0
- package/docs/recurrence/calendar.md +598 -0
- package/docs/recurrence/model.md +128 -0
- package/docs/recurrence/reference.md +547 -0
- package/docs/recurrence.md +122 -0
- package/docs/stylex.md +290 -0
- package/docs/temporal/daylight-saving-time.md +172 -0
- package/docs/temporal/month-grid.md +119 -0
- package/docs/temporal/reference.md +167 -0
- package/docs/temporal.md +105 -0
- package/docs/testing.md +600 -0
- package/docs/theme-builder.md +82 -0
- package/docs/theming.md +275 -0
- package/docs/undo-redo.md +347 -0
- package/docs/views/agenda.md +222 -0
- package/docs/views/custom-views.md +195 -0
- package/docs/views/month.md +110 -0
- package/docs/views/resource-columns.md +265 -0
- package/docs/views/resource-timeline.md +226 -0
- package/docs/views/scrolling.md +193 -0
- package/docs/views/week-and-day.md +258 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +42 -14
- package/skills/moltenship-time/SKILL.md +77 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +175 -0
- package/skills/moltenship-time/references/mistakes.md +100 -0
- package/skills/moltenship-time/references/solid.md +213 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Theme builder
|
|
2
|
+
|
|
3
|
+
Change the calendar's tokens in light and dark, see them live, and copy the CSS or a StyleX theme.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/theme-builder
|
|
6
|
+
|
|
7
|
+
Pick a preset or change a token, and the calendar follows. Light and dark have their own values:
|
|
8
|
+
the preview starts in the docs' theme, and **Light** and **Dark** above it switch the theme you see
|
|
9
|
+
and edit. Your changes stay in the preview, and nothing is saved.
|
|
10
|
+
|
|
11
|
+
> Live example: see it at https://time.molten.sh/docs/react/theme-builder
|
|
12
|
+
|
|
13
|
+
## Paste the CSS into your app
|
|
14
|
+
|
|
15
|
+
The CSS has the shape of `calendar-theme.css`: tokens inside `@layer base`, light values on
|
|
16
|
+
`:root` and dark ones on `.dark`. Paste it at the end of your global CSS, after the calendar's own
|
|
17
|
+
rules (the `@layer base` rules `shadcn add` wrote there, or the line that imports
|
|
18
|
+
`calendar-theme.css`), so it comes later in the same layer and wins. A shading recipe comes after
|
|
19
|
+
the tokens, outside the layer, as on [Availability](./availability.md#customize-the-shading).
|
|
20
|
+
|
|
21
|
+
- **Changed tokens** copies what differs from the theme as it ships. A token you changed only in
|
|
22
|
+
light mode is restated in `.dark` too, so the dark theme keeps its own value.
|
|
23
|
+
- **All tokens** copies the whole theme, so your CSS restates every token.
|
|
24
|
+
|
|
25
|
+
Rules your app writes outside a layer win over the pasted ones: its own shadcn theme, or overrides
|
|
26
|
+
like those in [Changing tokens](./theming.md#changing-tokens). Change those tokens there instead.
|
|
27
|
+
|
|
28
|
+
## Use the StyleX theme
|
|
29
|
+
|
|
30
|
+
Below the preview, **Tailwind + shadcn** gives the CSS above and **StyleX** gives a theme for the
|
|
31
|
+
[StyleX flavour](./stylex.md). The preview is the Tailwind-rendered calendar either way: the views
|
|
32
|
+
read the same tokens, so it shows your theme, and compiling StyleX inside these docs isn't worth it.
|
|
33
|
+
The **Monochrome** preset sets every base color, as an app does that
|
|
34
|
+
[maps its design system's colors](./stylex.md#use-your-design-systems-colors) onto the calendar's.
|
|
35
|
+
|
|
36
|
+
Paste the code into a file of your own, then apply the theme on a wrapper around the calendar. The
|
|
37
|
+
calendar's popovers, tooltips and toasts open inside it, in the browser's top layer, so the theme
|
|
38
|
+
reaches them too:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import * as stylex from "@stylexjs/stylex";
|
|
42
|
+
|
|
43
|
+
import { calendarTheme } from "./calendar-theme";
|
|
44
|
+
|
|
45
|
+
<div {...stylex.props(calendarTheme)}>
|
|
46
|
+
<TeamCalendar meetings={meetings} />
|
|
47
|
+
</div>;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Changed tokens** copies what differs from the theme as it ships, in either mode, with one value
|
|
51
|
+
for both through `light-dark()`. It adds the tokens that read one you changed: on a wrapper they'd
|
|
52
|
+
keep the value they got on `:root`. So changing `--primary` also restates `--calendar-event-border`.
|
|
53
|
+
- **All tokens** copies the whole theme. It pins the base colors too, so they stop following a
|
|
54
|
+
mapping of your design system's colors.
|
|
55
|
+
- A palette color you changed, or any change to what the colors derive, comes as each color's three
|
|
56
|
+
tokens, such as `--calendar-event-blue`, with the hue and chroma filled in.
|
|
57
|
+
- A shading recipe comes last, in a comment: StyleX can't select the closed-time band, so it goes in
|
|
58
|
+
your global CSS.
|
|
59
|
+
|
|
60
|
+
## What you can change
|
|
61
|
+
|
|
62
|
+
- **Colors.** The tokens in [Theming](./theming.md#tokens), and the shadcn tokens under **Base
|
|
63
|
+
colors**. Many calendar tokens derive from those: grid lines are `var(--border)`, and the default
|
|
64
|
+
event fill mixes `--primary` into `--background`. A derived token follows its source until you
|
|
65
|
+
set it. `--calendar-surface` isn't here: it's unset, and you set it on a container, as Theming
|
|
66
|
+
shows.
|
|
67
|
+
- **Density.** The hour height and the event padding in time grids, and `--radius`, which rounds
|
|
68
|
+
events, buttons and badges.
|
|
69
|
+
- **Availability.** The tints for closed time and closed days, a shading recipe for closed time in
|
|
70
|
+
time grids, the busy and free dots, and the outlines of changes the policies reject or flag. The
|
|
71
|
+
recipes are the ones on Availability, but the tint stays the **Closed time** token's.
|
|
72
|
+
- **Event palette.** Each color's hue and chroma, and how every color derives its fill, text and
|
|
73
|
+
edge from them, per theme. To add a color, see [Adding a color](./theming.md#adding-a-color).
|
|
74
|
+
|
|
75
|
+
**Contrast** checks, as the preview paints them, the pairs the theme's own test holds to WCAG AA on
|
|
76
|
+
the background, plus body text and the hour labels: 4.5:1 for text, 3:1 for the now line, the
|
|
77
|
+
focus ring and the status marks. When event text falls short, it names the palette color with the
|
|
78
|
+
lowest contrast.
|
|
79
|
+
|
|
80
|
+
Menus, tooltips and popovers open outside the preview, in the docs' own theme. A light preview on
|
|
81
|
+
a dark page also keeps a few dark-mode touches of the shadcn controls, such as the **Today**
|
|
82
|
+
button's fill, since the page's `dark` class reaches them.
|
package/docs/theming.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# Theming
|
|
2
|
+
|
|
3
|
+
Calendar color tokens, dark mode, the event color palette, and controls of your own.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/theming
|
|
6
|
+
|
|
7
|
+
The packages don't ship any CSS. The styled parts in the registry read their colors and sizes from
|
|
8
|
+
CSS variables defined in `calendar-theme.css`. The `calendar-theme` item, which every view brings,
|
|
9
|
+
adds its tokens and rules to your global CSS, as described in
|
|
10
|
+
[UI source](./installation.md#ui-source-optional). Override the variables in your own CSS to
|
|
11
|
+
restyle the calendar, as [Changing tokens](#changing-tokens) shows: each `shadcn add` writes the
|
|
12
|
+
theme's own block again. To try changes live and copy the CSS, use the
|
|
13
|
+
[Theme builder](./theme-builder.md).
|
|
14
|
+
|
|
15
|
+
This page covers the Tailwind baseline. The `stylex-*` items keep the same token names, as StyleX
|
|
16
|
+
variables you override with `stylex.createTheme`; see [StyleX](./stylex.md#change-the-tokens).
|
|
17
|
+
|
|
18
|
+
## Tokens
|
|
19
|
+
|
|
20
|
+
`calendar-theme.css` defines the standard shadcn/ui tokens (`--background`, `--primary`,
|
|
21
|
+
`--border`, and so on) plus these calendar tokens. `shadcn add` adds only the calendar tokens, since
|
|
22
|
+
your app has its own shadcn theme:
|
|
23
|
+
|
|
24
|
+
| Variable | Used for | Tailwind class |
|
|
25
|
+
| ----------------------------- | ----------------------------------------------------- | --------------------------------- |
|
|
26
|
+
| `--calendar-surface` | Behind sticky headers, between events | `bg-calendar-surface` |
|
|
27
|
+
| `--calendar-grid` | Lines between days and hours | `border-calendar-grid` |
|
|
28
|
+
| `--calendar-axis` | Hour and weekday labels | `text-calendar-axis` |
|
|
29
|
+
| `--calendar-today` | Today's date marker | `bg-calendar-today` |
|
|
30
|
+
| `--calendar-today-foreground` | Text on today's marker | `text-calendar-today-foreground` |
|
|
31
|
+
| `--calendar-now` | The current-time line | `bg-calendar-now` |
|
|
32
|
+
| `--calendar-selection` | Selected days and time ranges | `bg-calendar-selection` |
|
|
33
|
+
| `--calendar-weekend` | Weekend background | `bg-calendar-weekend` |
|
|
34
|
+
| `--calendar-unavailable` | Closed time in time grids and timelines | `bg-calendar-unavailable` |
|
|
35
|
+
| `--calendar-closed` | Closed days in the month and year views | `bg-calendar-closed` |
|
|
36
|
+
| `--calendar-busy` | A resource status's busy dot | `bg-calendar-busy` |
|
|
37
|
+
| `--calendar-free` | A resource status's free dot | `bg-calendar-free` |
|
|
38
|
+
| `--calendar-invalid` | A preview the policies would reject | `outline-calendar-invalid` |
|
|
39
|
+
| `--calendar-warning` | A preview the policies would flag | `outline-calendar-warning` |
|
|
40
|
+
| `--calendar-event` | Event background | `bg-calendar-event` |
|
|
41
|
+
| `--calendar-event-foreground` | Event text | `text-calendar-event-foreground` |
|
|
42
|
+
| `--calendar-event-border` | Event accent edge | `border-calendar-event-border` |
|
|
43
|
+
| `--calendar-hour-height` | Height of one hour in time grids (`3rem`) | `h-(--calendar-hour-height)` |
|
|
44
|
+
| `--calendar-event-padding-x` | Padding at the sides of time-grid events (`0.375rem`) | `px-(--calendar-event-padding-x)` |
|
|
45
|
+
| `--calendar-event-padding-y` | Padding above and below time-grid events (`0.25rem`) | `py-(--calendar-event-padding-y)` |
|
|
46
|
+
|
|
47
|
+
The color tokens work with any Tailwind color utility, so `text-calendar-today` and
|
|
48
|
+
`ring-calendar-now` work too. Most calendar tokens derive from the shadcn tokens: `--calendar-grid`
|
|
49
|
+
is your `--border`, and the default event colors mix your `--primary` into `--background`.
|
|
50
|
+
|
|
51
|
+
The event padding tokens set how roomy events are in the week, day and resource columns views,
|
|
52
|
+
along with `--calendar-hour-height`. The views fall back to the default padding where they read
|
|
53
|
+
them, so a copy of `calendar-theme.css` from before these tokens keeps working.
|
|
54
|
+
|
|
55
|
+
## Changing tokens
|
|
56
|
+
|
|
57
|
+
Every token is declared inside `@layer base`, so a plain rule in your own CSS wins without
|
|
58
|
+
`!important`. Set the light values on `:root` and the dark values on `.dark`:
|
|
59
|
+
|
|
60
|
+
```css title="globals.css"
|
|
61
|
+
:root {
|
|
62
|
+
--calendar-today: oklch(0.55 0.17 150);
|
|
63
|
+
--calendar-hour-height: 4rem;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.dark {
|
|
67
|
+
--calendar-today: oklch(0.72 0.15 150);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
If your app already defines the shadcn tokens, the calendar follows them automatically.
|
|
72
|
+
|
|
73
|
+
`--calendar-surface` is unset by default and falls back to `--background`. Set it on the
|
|
74
|
+
calendar's container when that container has its own background, such as a card, so sticky
|
|
75
|
+
headers and gutters match it:
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<main className="bg-card [--calendar-surface:var(--card)]">
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Dark mode
|
|
82
|
+
|
|
83
|
+
The theme switches when an ancestor of the calendar has the `dark` class, which is how shadcn/ui
|
|
84
|
+
and `next-themes` work. shadcn apps already define the matching Tailwind `dark` variant. If yours
|
|
85
|
+
doesn't, add `@custom-variant dark (&:is(.dark *));` below the imports in your global CSS.
|
|
86
|
+
|
|
87
|
+
## Event colors
|
|
88
|
+
|
|
89
|
+
The theme has a palette of nine event colors: `blue`, `green`, `red`, `orange`, `yellow`,
|
|
90
|
+
`purple`, `pink`, `teal`, and `gray`. Put one in a `data-color` attribute and that element's three
|
|
91
|
+
event tokens switch to the color, in both light and dark mode:
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<div data-color="green" class="bg-calendar-event text-calendar-event-foreground">Standup</div>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`EventChip`, the event button in `registry/calendar`, sets `data-color` from its `color` prop. The
|
|
98
|
+
names are exported from `event-colors.ts` as `calendarEventColors`, with the type
|
|
99
|
+
`CalendarEventColor`.
|
|
100
|
+
|
|
101
|
+
### Choosing a color per event
|
|
102
|
+
|
|
103
|
+
Every built-in view takes an optional `getEventColor` option: a function from your event record to
|
|
104
|
+
a color name. Pass it when you create the view, as the [Quick start](./quick-start.md) does, or
|
|
105
|
+
per calendar with the `viewOptions` prop on `Root`:
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
const getEventColor = (meeting: Meeting) => (meeting.title === "Standup" ? "green" : "blue");
|
|
109
|
+
|
|
110
|
+
// On Root:
|
|
111
|
+
viewOptions={{ month: { getEventColor }, agenda: { getEventColor } }}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Define the function outside your component, so it keeps its identity between renders. See
|
|
115
|
+
[Performance](./guides/performance.md#keep-functions-in-options-stable). Without `getEventColor`,
|
|
116
|
+
events use the theme's default event tokens.
|
|
117
|
+
|
|
118
|
+
To support it in your own view, add it to the view's options and pass the result to `EventChip`:
|
|
119
|
+
|
|
120
|
+
```tsx title="upcoming-view.tsx"
|
|
121
|
+
import {
|
|
122
|
+
defineCalendarView,
|
|
123
|
+
plainDateInterval,
|
|
124
|
+
type CalendarViewProjectionInput,
|
|
125
|
+
} from "@moltenship/calendar";
|
|
126
|
+
|
|
127
|
+
import { EventChip } from "@/components/calendar/event-chip";
|
|
128
|
+
import type { CalendarEventColor } from "@/components/calendar/event-colors";
|
|
129
|
+
|
|
130
|
+
import type { Meeting } from "./quick-start";
|
|
131
|
+
|
|
132
|
+
interface UpcomingOptions {
|
|
133
|
+
readonly getEventColor?: (meeting: Meeting) => CalendarEventColor;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const upcomingView = defineCalendarView({
|
|
137
|
+
name: "upcoming",
|
|
138
|
+
defaultOptions: {},
|
|
139
|
+
strategy: {
|
|
140
|
+
getRange: (anchor) => plainDateInterval(anchor, anchor.add({ days: 7 })),
|
|
141
|
+
navigate: (anchor, delta) => anchor.add({ weeks: delta }),
|
|
142
|
+
getTitle: (range, { locale }) => range.start.toLocaleString(locale, { dateStyle: "medium" }),
|
|
143
|
+
project: ({ snapshot, instantRange }: CalendarViewProjectionInput<UpcomingOptions, Meeting>) =>
|
|
144
|
+
snapshot.queryTimed(instantRange),
|
|
145
|
+
},
|
|
146
|
+
Renderer: ({ projection, options }) => (
|
|
147
|
+
<ul>
|
|
148
|
+
{projection.map(({ event }) => (
|
|
149
|
+
<li key={event.id}>
|
|
150
|
+
<EventChip color={options.getEventColor?.(event)}>{event.title}</EventChip>
|
|
151
|
+
</li>
|
|
152
|
+
))}
|
|
153
|
+
</ul>
|
|
154
|
+
),
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Adding a color
|
|
159
|
+
|
|
160
|
+
Each palette entry only sets a hue and a chroma; the `[data-color]` rule turns them into the three
|
|
161
|
+
event tokens for light and dark mode. To add a color, add its name to `calendarEventColors` in
|
|
162
|
+
`event-colors.ts` and give it a hue and chroma in your CSS:
|
|
163
|
+
|
|
164
|
+
```css title="globals.css"
|
|
165
|
+
[data-color="brand"] {
|
|
166
|
+
--calendar-event-hue: 285;
|
|
167
|
+
--calendar-event-chroma: 0.2;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Use your own controls
|
|
172
|
+
|
|
173
|
+
The kit's files are your app's code once you add them: a default to edit or replace. Swapping a
|
|
174
|
+
control is one of four ways to change the calendar's UI, and
|
|
175
|
+
[Customization](./customization.md) sets it beside the other three.
|
|
176
|
+
|
|
177
|
+
The Tailwind views take their buttons, badges, tooltips, the view select, popovers, dialogs and
|
|
178
|
+
toasts from the files `calendar-ui` adds to `components/calendar/ui/`. They don't import ui-sdk themselves, and they
|
|
179
|
+
don't reach into a control's parts or attributes. To use a control of your own, replace the body
|
|
180
|
+
of its file: keep the file's name, the names it exports and the props below, and render your
|
|
181
|
+
component. The views stay as they are.
|
|
182
|
+
|
|
183
|
+
With shadcn's button, from a Base UI style, the button file is a few lines:
|
|
184
|
+
|
|
185
|
+
```tsx title="components/calendar/ui/button.tsx"
|
|
186
|
+
import type { ComponentProps } from "react";
|
|
187
|
+
|
|
188
|
+
import { Button as AppButton, buttonVariants } from "@/components/ui/button";
|
|
189
|
+
|
|
190
|
+
export type ButtonProps = ComponentProps<typeof AppButton>;
|
|
191
|
+
|
|
192
|
+
export function Button(props: ButtonProps) {
|
|
193
|
+
return <AppButton {...props} />;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { buttonVariants };
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Pass on every other prop, `aria-*` and `data-*` included, to the element your control renders,
|
|
200
|
+
around its children. The views set them, and their CSS and tests read some of them. What the views
|
|
201
|
+
import from each file, and what they pass:
|
|
202
|
+
|
|
203
|
+
| File | The views import | What the views pass |
|
|
204
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
205
|
+
| `button.tsx` | `Button` | `variant` (`outline`, `ghost`), `size` (`default`, `lg`, `icon`, `icon-sm`, `icon-xs`), `className`, `onClick`, `disabled`, `tabIndex`, `ref`, `aria-*`, `data-scope`, and `render` |
|
|
206
|
+
| `badge.tsx` | `Badge` | `variant="outline"`, `className`, `title`, and `data-slot="resource-status"` with `data-state`, which colours the status dot inside it |
|
|
207
|
+
| `tooltip.tsx` | `Tooltip`, `TooltipTrigger`, `TooltipContent`, `createTooltipHandle`, `TooltipHandle` | `Tooltip`: `delay`, and for one tooltip many triggers share, `handle`, `trackCursorAxis="y"`, `onOpenChange` with `details.cancel()` and `details.payload`, and children as a function of `{ payload }`. `TooltipTrigger`: `render`, the element it shows on, and `handle` and `payload`. `TooltipContent`: the text, and `side`, `align`, `sideOffset`, `className` and `aria-label` |
|
|
208
|
+
| `select.tsx` | `Select`, `SelectTrigger`, `SelectValue`, `SelectContent`, `SelectGroup`, `SelectItem` | `Select`: `items` (`{ label, value }`), `value` and `onValueChange`, which gets the new value. `SelectTrigger`: `aria-label` and `className`. `SelectContent`: `align` and `alignItemWithTrigger`. `SelectItem`: `value`, `label`, and the label with its shortcut as children |
|
|
209
|
+
| `popover.tsx` | `Popover`, `PopoverTrigger`, `PopoverContent`, `PopoverTitle`, `PopoverClose`, `createPopoverHandle`, `PopoverHandle` | `createPopoverHandle()`: one popover for many triggers, with `open(triggerId)`, `close()` and `getPayload()`. `Popover`: `handle`, `modal`, `onOpenChange`, and children as a function of `{ payload }`. `PopoverTrigger`: `handle`, `payload`, `id`, `render`, `aria-label`, `className`, `style`, `tabIndex` and `onMouseDown`. `PopoverContent`: `aria-label`, `side` (`inline-start` and `inline-end` too), `align`, `sideOffset`, `className`, `ref`, `initialFocus` (a ref) and `finalFocus` (`false`, or a function that returns the element). `PopoverClose`: `render` |
|
|
210
|
+
| `dialog.tsx` | `Dialog`, `DialogContent`, `DialogHeader`, `DialogFooter`, `DialogTitle`, `DialogDescription`, `DialogClose` | `Dialog`: `open`, `onOpenChange` and `onOpenChangeComplete`; it's modal. `DialogContent`: `className` and `initialFocus` (a ref). `DialogClose`: `render`, the button. The rest: children and `className` |
|
|
211
|
+
| `toast.tsx` | `ToastViewport`, `Toast`, `ToastTitle`, `ToastDescription`, `ToastAction`, `ToastClose`, `createToastManager`, `ToastManager` | `createToastManager()`: `add({ id, title, description, timeout, actionProps, onRemove })`, where `timeout: 0` keeps a toast and `actionProps.onClick` gets `{ input }`, and `close(id)`. `ToastViewport`: `manager`, `aria-label` and one toast's parts as children. `ToastClose`: `aria-label`. The parts render the toast's own text |
|
|
212
|
+
|
|
213
|
+
The kit's files also export `buttonVariants`, `badgeVariants`, `SelectGroupLabel` and
|
|
214
|
+
`SelectSeparator` for your own code. Keep them, or remove what you don't use. Beside them,
|
|
215
|
+
`tooltip-handle.ts`, `popover-handle.ts` and `toast-manager.ts` hold the kit's tooltip, popover
|
|
216
|
+
and toast state, and `popup-side.ts` maps `inline-start` and `inline-end` for the tooltip and the
|
|
217
|
+
popover. A control you replace can stop importing them; keep each one another kit file still
|
|
218
|
+
imports.
|
|
219
|
+
|
|
220
|
+
`render` is an element to render in place of the `<button>`. The toolbar passes the calendar's
|
|
221
|
+
`TodayTrigger`, `PreviousTrigger` and `NextTrigger` this way: the trigger keeps its own props and
|
|
222
|
+
runs the command, and your button adds its look and passes on `disabled`. If your button takes
|
|
223
|
+
`asChild` instead, as a Radix style's does, render the `render` element as its child with
|
|
224
|
+
`asChild`. Typing on the view select matches each item's `label`, so pass it on to your select's
|
|
225
|
+
items.
|
|
226
|
+
|
|
227
|
+
The year's day popover and the annotations each open one popover from many triggers, so a view
|
|
228
|
+
never mounts hundreds of roots. With shadcn's popover, build the handle
|
|
229
|
+
on Base UI's `Popover.createHandle()`: it opens a trigger by its `id` and closes, and your
|
|
230
|
+
`getPayload()` returns the `payload` of the trigger that opened it last. The views move focus
|
|
231
|
+
themselves where `finalFocus` says, so map `false` to Base UI's `finalFocus={false}`. The
|
|
232
|
+
calendar's own tests swap in shadcn's popover and dialog this way, and the views keep working by
|
|
233
|
+
pointer and by keyboard.
|
|
234
|
+
|
|
235
|
+
A control that isn't built on ui-sdk gives up two things:
|
|
236
|
+
|
|
237
|
+
- **What an agent sees.** An [agent bridge](./agents/connect.md) lists ui-sdk's components. It
|
|
238
|
+
reads your control only as far as your component tells it, and a stock shadcn control tells it
|
|
239
|
+
nothing. The calendar stays on the bridge, so an agent can still change the view with its
|
|
240
|
+
`setView` action.
|
|
241
|
+
- **The same control in React and Solid.** ui-sdk has the same components in both frameworks, so
|
|
242
|
+
a control built on it behaves alike in both. Yours behaves as your component does, so a Solid
|
|
243
|
+
app needs its own version of it. The Solid registry's controls are in its `calendar-ui` item.
|
|
244
|
+
|
|
245
|
+
### In the StyleX items
|
|
246
|
+
|
|
247
|
+
The `stylex-` views take the same controls from `stylex-calendar-ui`, in
|
|
248
|
+
`components/calendar-stylex/ui/`: the same files, exports and props as in the table, with StyleX
|
|
249
|
+
styles in place of class names. Where the table says `className`, the StyleX views pass `xstyle`, a
|
|
250
|
+
value of `stylex.create`, and a control applies it after its own styles:
|
|
251
|
+
|
|
252
|
+
```tsx title="components/calendar-stylex/ui/button.tsx"
|
|
253
|
+
import type { ComponentProps, CSSProperties } from "react";
|
|
254
|
+
|
|
255
|
+
import { Button as AppButton } from "@/components/ui/button";
|
|
256
|
+
import { buttonVariants } from "@/components/calendar-stylex/ui/button.styles";
|
|
257
|
+
import { type XStyle, xprops } from "@/components/calendar-stylex/xprops";
|
|
258
|
+
|
|
259
|
+
// Base UI's className and style can be functions of state; the views pass plain values.
|
|
260
|
+
export interface ButtonProps extends Omit<ComponentProps<typeof AppButton>, "className" | "style"> {
|
|
261
|
+
readonly className?: string;
|
|
262
|
+
readonly style?: CSSProperties;
|
|
263
|
+
readonly xstyle?: XStyle;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function Button({ className, style, xstyle, ...props }: ButtonProps) {
|
|
267
|
+
return <AppButton {...props} {...xprops({ className, style }, xstyle)} />;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { buttonVariants };
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
`xprops`, from the StyleX theme item, merges the styles with a `className` and `style` the element
|
|
274
|
+
also gets. A control from a StyleX design system that takes `xstyle` itself can take it as it
|
|
275
|
+
comes.
|