@shiftbloom-studio/circadian-ui 0.2.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/LICENSE +22 -0
- package/README.md +275 -0
- package/dist/index.cjs +890 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +850 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +216 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +73 -0
- package/dist/server.d.ts +73 -0
- package/dist/server.js +212 -0
- package/dist/server.js.map +1 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) YEAR YOUR_NAME
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# Circadian UI
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@shiftbloom-studio/circadian-ui)
|
|
4
|
+
[](https://github.com/shiftbloom-studio/circadian-ui/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Automatic, accessible, Tailwind-friendly time-of-day theming for React and Next.js. Circadian UI adapts your design tokens based on local time, optional sunrise/sunset data, system preferences, and user overrides — all while keeping contrast WCAG-conscious.
|
|
8
|
+
|
|
9
|
+
## Why this matters
|
|
10
|
+
|
|
11
|
+
- **Readable at any hour**: avoid low-contrast screens at night or overly-bright palettes at dawn.
|
|
12
|
+
- **Reduced eye strain**: thoughtful shifts in luminance and contrast help users stay comfortable.
|
|
13
|
+
- **Consistent branding**: keep your token system intact while letting Circadian UI handle timing and accessibility.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @shiftbloom-studio/circadian-ui
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quickstart (React)
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { CircadianProvider, CircadianScript } from "@shiftbloom-studio/circadian-ui";
|
|
25
|
+
|
|
26
|
+
export function App({ children }: { children: React.ReactNode }) {
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
<CircadianScript />
|
|
30
|
+
<CircadianProvider>{children}</CircadianProvider>
|
|
31
|
+
</>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Next.js (App Router)
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// app/layout.tsx
|
|
40
|
+
import "./globals.css";
|
|
41
|
+
import { CircadianProvider, CircadianScript } from "@shiftbloom-studio/circadian-ui";
|
|
42
|
+
|
|
43
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
44
|
+
return (
|
|
45
|
+
<html lang="en">
|
|
46
|
+
<body>
|
|
47
|
+
<CircadianScript />
|
|
48
|
+
<CircadianProvider>{children}</CircadianProvider>
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Next.js (Pages Router)
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
// pages/_document.tsx
|
|
59
|
+
import Document, { Head, Html, Main, NextScript } from "next/document";
|
|
60
|
+
import { CircadianScript } from "@shiftbloom-studio/circadian-ui";
|
|
61
|
+
|
|
62
|
+
export default class MyDocument extends Document {
|
|
63
|
+
render() {
|
|
64
|
+
return (
|
|
65
|
+
<Html lang="en">
|
|
66
|
+
<Head>
|
|
67
|
+
<CircadianScript />
|
|
68
|
+
</Head>
|
|
69
|
+
<body>
|
|
70
|
+
<Main />
|
|
71
|
+
<NextScript />
|
|
72
|
+
</body>
|
|
73
|
+
</Html>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Tailwind setup
|
|
80
|
+
|
|
81
|
+
### CSS variables only (recommended)
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// tailwind.config.ts
|
|
85
|
+
import type { Config } from "tailwindcss";
|
|
86
|
+
|
|
87
|
+
const config: Config = {
|
|
88
|
+
content: ["./app/**/*.{ts,tsx}", "./components/**/*.{ts,tsx}"],
|
|
89
|
+
theme: {
|
|
90
|
+
extend: {
|
|
91
|
+
colors: {
|
|
92
|
+
background: "hsl(var(--cui-bg) / <alpha-value>)",
|
|
93
|
+
foreground: "hsl(var(--cui-fg) / <alpha-value>)",
|
|
94
|
+
muted: "hsl(var(--cui-muted) / <alpha-value>)",
|
|
95
|
+
"muted-foreground": "hsl(var(--cui-muted-fg) / <alpha-value>)",
|
|
96
|
+
card: "hsl(var(--cui-card) / <alpha-value>)",
|
|
97
|
+
"card-foreground": "hsl(var(--cui-card-fg) / <alpha-value>)",
|
|
98
|
+
border: "hsl(var(--cui-border) / <alpha-value>)",
|
|
99
|
+
ring: "hsl(var(--cui-ring) / <alpha-value>)",
|
|
100
|
+
accent: "hsl(var(--cui-accent) / <alpha-value>)",
|
|
101
|
+
"accent-foreground": "hsl(var(--cui-accent-fg) / <alpha-value>)",
|
|
102
|
+
destructive: "hsl(var(--cui-destructive) / <alpha-value>)",
|
|
103
|
+
"destructive-foreground": "hsl(var(--cui-destructive-fg) / <alpha-value>)"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default config;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Tailwind preset + plugin
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// tailwind.config.ts
|
|
116
|
+
import type { Config } from "tailwindcss";
|
|
117
|
+
import plugin from "tailwindcss/plugin";
|
|
118
|
+
import { circadianPlugin, circadianTailwindPreset } from "@shiftbloom-studio/circadian-ui";
|
|
119
|
+
|
|
120
|
+
const config: Config = {
|
|
121
|
+
presets: [circadianTailwindPreset()],
|
|
122
|
+
plugins: [plugin(circadianPlugin())]
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default config;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Configuration examples
|
|
129
|
+
|
|
130
|
+
### Custom time windows
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
<CircadianProvider
|
|
134
|
+
config={{
|
|
135
|
+
schedule: {
|
|
136
|
+
dawn: { start: "06:00", end: "09:00" },
|
|
137
|
+
day: { start: "09:00", end: "18:00" },
|
|
138
|
+
dusk: { start: "18:00", end: "22:00" },
|
|
139
|
+
night: { start: "22:00", end: "06:00" }
|
|
140
|
+
}
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
{children}
|
|
144
|
+
</CircadianProvider>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Manual override UI
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { useCircadian } from "@shiftbloom-studio/circadian-ui";
|
|
151
|
+
|
|
152
|
+
const ModeToggle = () => {
|
|
153
|
+
const { mode, setMode, setPhaseOverride } = useCircadian();
|
|
154
|
+
return (
|
|
155
|
+
<div>
|
|
156
|
+
<button onClick={() => setMode("time")}>Auto</button>
|
|
157
|
+
<button onClick={() => setPhaseOverride("night")}>Night</button>
|
|
158
|
+
<span>Current mode: {mode}</span>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Sun-times provider
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import type { SunTimesProvider } from "@shiftbloom-studio/circadian-ui";
|
|
168
|
+
|
|
169
|
+
const provider: SunTimesProvider = (date) => {
|
|
170
|
+
// Plug in your own sunrise/sunset provider
|
|
171
|
+
return {
|
|
172
|
+
sunrise: new Date(date.getFullYear(), date.getMonth(), date.getDate(), 6, 12),
|
|
173
|
+
sunset: new Date(date.getFullYear(), date.getMonth(), date.getDate(), 19, 48)
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
<CircadianProvider config={{ mode: "sun", sunTimesProvider: provider }} />;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Disable persistence
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
<CircadianProvider config={{ persist: false }} />
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Strict contrast mode
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
<CircadianProvider
|
|
190
|
+
config={{
|
|
191
|
+
accessibility: {
|
|
192
|
+
enforceContrast: true,
|
|
193
|
+
minimumRatio: 7
|
|
194
|
+
}
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Accessibility notes
|
|
200
|
+
|
|
201
|
+
Circadian UI enforces WCAG-conscious contrast by default. Foreground tokens are nudged in lightness until they meet the configured ratio. You can tune ratios for normal and large text via `accessibility.minimumRatio` and `accessibility.largeTextRatio`.
|
|
202
|
+
|
|
203
|
+
## Design tokens
|
|
204
|
+
|
|
205
|
+
| Token | CSS Variable |
|
|
206
|
+
| ---------------------- | ---------------------- |
|
|
207
|
+
| Background | `--cui-bg` |
|
|
208
|
+
| Foreground | `--cui-fg` |
|
|
209
|
+
| Muted | `--cui-muted` |
|
|
210
|
+
| Muted Foreground | `--cui-muted-fg` |
|
|
211
|
+
| Card | `--cui-card` |
|
|
212
|
+
| Card Foreground | `--cui-card-fg` |
|
|
213
|
+
| Border | `--cui-border` |
|
|
214
|
+
| Ring | `--cui-ring` |
|
|
215
|
+
| Accent | `--cui-accent` |
|
|
216
|
+
| Accent Foreground | `--cui-accent-fg` |
|
|
217
|
+
| Destructive | `--cui-destructive` |
|
|
218
|
+
| Destructive Foreground | `--cui-destructive-fg` |
|
|
219
|
+
|
|
220
|
+
## API reference
|
|
221
|
+
|
|
222
|
+
### React
|
|
223
|
+
|
|
224
|
+
- `CircadianProvider`
|
|
225
|
+
- Props: `{ config?: CircadianConfig; children: React.ReactNode }`
|
|
226
|
+
- Sets `data-cui-phase` and CSS vars on the document root.
|
|
227
|
+
- `useCircadian()`
|
|
228
|
+
- Returns `{ phase, mode, setMode, setPhaseOverride, clearOverride, tokens, isAuto, nextChangeAt }`.
|
|
229
|
+
- `useCircadianTokens()`
|
|
230
|
+
- Returns `{ tokens, cssVars, applyToStyle }` for inline usage.
|
|
231
|
+
- `CircadianScript`
|
|
232
|
+
- Inline script component to prevent flash before hydration.
|
|
233
|
+
|
|
234
|
+
### Core utilities
|
|
235
|
+
|
|
236
|
+
- `getPhaseFromTime(date, schedule)`
|
|
237
|
+
- `getPhaseFromSunTimes(date, sunTimes, options)`
|
|
238
|
+
- `computeNextTransition(date, schedule)`
|
|
239
|
+
- `ensureContrast(tokens, options)`
|
|
240
|
+
- `resolveMode(userMode, systemPrefs, config)`
|
|
241
|
+
- `createInlineScript(config)`
|
|
242
|
+
|
|
243
|
+
### Tailwind
|
|
244
|
+
|
|
245
|
+
- `circadianTailwindPreset()`
|
|
246
|
+
- `circadianPlugin()` (wrap with `tailwindcss/plugin`)
|
|
247
|
+
|
|
248
|
+
## Configuration schema
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
interface CircadianConfig {
|
|
252
|
+
schedule?: Partial<CircadianSchedule>;
|
|
253
|
+
tokens?: Partial<Record<Phase, Partial<CircadianTokens>>>;
|
|
254
|
+
mode?: "time" | "sun" | "manual";
|
|
255
|
+
sunTimesProvider?: SunTimesProvider;
|
|
256
|
+
sunSchedule?: Partial<SunScheduleOptions>;
|
|
257
|
+
persist?: boolean;
|
|
258
|
+
storageKey?: string;
|
|
259
|
+
accessibility?: Partial<AccessibilityOptions>;
|
|
260
|
+
system?: Partial<SystemPreferenceOptions>;
|
|
261
|
+
colorSchemeBias?: Partial<ColorSchemeBias>;
|
|
262
|
+
transition?: Partial<TransitionOptions>;
|
|
263
|
+
setAttributeOn?: "html" | "body";
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Development
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
npm ci
|
|
271
|
+
npm run lint
|
|
272
|
+
npm run typecheck
|
|
273
|
+
npm run test
|
|
274
|
+
npm run build
|
|
275
|
+
```
|