@zyncat/ui 0.15.0 → 0.17.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 +32 -202
- package/dist/alert.css +1 -1
- package/dist/alert.js +18 -10
- package/dist/alert.js.map +1 -1
- package/dist/avatar.css +3 -2
- package/dist/badge.css +1 -1
- package/dist/bloom-HV23M4AW.js +81 -0
- package/dist/bloom-HV23M4AW.js.map +1 -0
- package/dist/button.css +21 -24
- package/dist/button.js +3 -1
- package/dist/checkbox.css +1 -1
- package/dist/chunk-2YGHPQ66.js +16 -0
- package/dist/chunk-2YGHPQ66.js.map +1 -0
- package/dist/{chunk-K45CWVHS.js → chunk-3MLUH2QL.js} +4 -4
- package/dist/{chunk-K45CWVHS.js.map → chunk-3MLUH2QL.js.map} +1 -1
- package/dist/{chunk-FVPNICF4.js → chunk-4PQDVK23.js} +4 -4
- package/dist/{chunk-FVPNICF4.js.map → chunk-4PQDVK23.js.map} +1 -1
- package/dist/{chunk-FLQVOSFC.js → chunk-6IXLW7QA.js} +7 -7
- package/dist/{chunk-FLQVOSFC.js.map → chunk-6IXLW7QA.js.map} +1 -1
- package/dist/chunk-7NHY2CRA.js +132 -0
- package/dist/chunk-7NHY2CRA.js.map +1 -0
- package/dist/{chunk-BH4JFWXQ.js → chunk-7VTWJL72.js} +19 -16
- package/dist/chunk-7VTWJL72.js.map +1 -0
- package/dist/chunk-7ZSIUUC3.js +50 -0
- package/dist/chunk-7ZSIUUC3.js.map +1 -0
- package/dist/{chunk-6X3G4GIM.js → chunk-DH7DT6EO.js} +3 -3
- package/dist/{chunk-6X3G4GIM.js.map → chunk-DH7DT6EO.js.map} +1 -1
- package/dist/{chunk-QGVFFT2B.js → chunk-EOWWVFBF.js} +3 -3
- package/dist/{chunk-QGVFFT2B.js.map → chunk-EOWWVFBF.js.map} +1 -1
- package/dist/{chunk-RBSHRRNO.js → chunk-FLDIRXFU.js} +5 -5
- package/dist/{chunk-RBSHRRNO.js.map → chunk-FLDIRXFU.js.map} +1 -1
- package/dist/{chunk-5GBV45YD.js → chunk-GWCBTD63.js} +3 -3
- package/dist/{chunk-5GBV45YD.js.map → chunk-GWCBTD63.js.map} +1 -1
- package/dist/chunk-GZ6UMHCK.js +103 -0
- package/dist/chunk-GZ6UMHCK.js.map +1 -0
- package/dist/{chunk-FEXUS4SV.js → chunk-HWDIVGME.js} +11 -5
- package/dist/chunk-HWDIVGME.js.map +1 -0
- package/dist/chunk-KSAJ6DED.js +16 -0
- package/dist/chunk-KSAJ6DED.js.map +1 -0
- package/dist/{chunk-UYSXJ7MH.js → chunk-LH2UIEKN.js} +7 -17
- package/dist/chunk-LH2UIEKN.js.map +1 -0
- package/dist/{chunk-CAXQJSIE.js → chunk-M2A6PZ7J.js} +6 -6
- package/dist/{chunk-CAXQJSIE.js.map → chunk-M2A6PZ7J.js.map} +1 -1
- package/dist/chunk-NYQQH4R5.js +40 -0
- package/dist/chunk-NYQQH4R5.js.map +1 -0
- package/dist/{chunk-BTF6DAE3.js → chunk-ODRO3KS6.js} +4 -4
- package/dist/{chunk-BTF6DAE3.js.map → chunk-ODRO3KS6.js.map} +1 -1
- package/dist/{chunk-GJTHWB6O.js → chunk-QDAN43B6.js} +3 -3
- package/dist/{chunk-GJTHWB6O.js.map → chunk-QDAN43B6.js.map} +1 -1
- package/dist/{chunk-MDSRZ4QR.js → chunk-RY35IU3G.js} +3 -3
- package/dist/{chunk-MDSRZ4QR.js.map → chunk-RY35IU3G.js.map} +1 -1
- package/dist/{chunk-GOLSYGRA.js → chunk-TBLPZQSI.js} +84 -48
- package/dist/chunk-TBLPZQSI.js.map +1 -0
- package/dist/{chunk-5X3MJRIM.js → chunk-UKPX3RIP.js} +3 -3
- package/dist/{chunk-5X3MJRIM.js.map → chunk-UKPX3RIP.js.map} +1 -1
- package/dist/{chunk-CFRGQJ23.js → chunk-VZXML7EH.js} +4 -4
- package/dist/{chunk-CFRGQJ23.js.map → chunk-VZXML7EH.js.map} +1 -1
- package/dist/{chunk-PWQVSVXR.js → chunk-WC45VSST.js} +8 -8
- package/dist/{chunk-PWQVSVXR.js.map → chunk-WC45VSST.js.map} +1 -1
- package/dist/chunk-WQKWPI6V.js +196 -0
- package/dist/chunk-WQKWPI6V.js.map +1 -0
- package/dist/{chunk-N2GJEO5Z.js → chunk-ZHMOH62S.js} +4 -4
- package/dist/chunk-ZHMOH62S.js.map +1 -0
- package/dist/cli.js +259 -43
- package/dist/collapse.css +8 -5
- package/dist/confetti.css +3 -3
- package/dist/confetti.js +2 -2
- package/dist/date-field.js +16 -14
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.css +168 -43
- package/dist/date-range-field.js +38 -23
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +17 -15
- package/dist/datetime-field.js.map +1 -1
- package/dist/dialog.css +4 -3
- package/dist/dialog.js +8 -8
- package/dist/digit-strip.css +1 -1
- package/dist/dropdown.css +1 -1
- package/dist/dropdown.js +8 -8
- package/dist/emoji-picker.js +14 -14
- package/dist/facebook-feed.css +1 -1
- package/dist/flow-field.css +4 -4
- package/dist/flow-field.js +3 -3
- package/dist/flow-field.js.map +1 -1
- package/dist/glide.js +3 -3
- package/dist/icon.css +1 -1
- package/dist/input.css +7 -4
- package/dist/instagram-feed.css +1 -1
- package/dist/instagram-feed.js +2 -2
- package/dist/lens.css +1 -2
- package/dist/lens.js +2 -2
- package/dist/mcp.js +1 -1
- package/dist/menu-surface.css +1 -1
- package/dist/modal.css +1 -1
- package/dist/modal.js +6 -6
- package/dist/morphing-text.css +2 -2
- package/dist/morphing-text.js +2 -2
- package/dist/motion-devtools.css +77 -2
- package/dist/motion-devtools.js +194 -37
- package/dist/motion-devtools.js.map +1 -1
- package/dist/motion-tokens.js +1 -1
- package/dist/multi-select.js +9 -9
- package/dist/number-field.js +3 -3
- package/dist/odometer.css +1 -1
- package/dist/odometer.js +2 -2
- package/dist/overlay.css +1 -1
- package/dist/pagination.css +1 -1
- package/dist/pagination.js +6 -4
- package/dist/pagination.js.map +1 -1
- package/dist/paint-CJQCM6ZO.js +260 -0
- package/dist/paint-CJQCM6ZO.js.map +1 -0
- package/dist/popover.css +1 -1
- package/dist/popover.js +6 -6
- package/dist/radio-group.css +6 -4
- package/dist/radio-group.js +6 -6
- package/dist/select.css +1 -1
- package/dist/select.js +9 -9
- package/dist/sheet.css +1 -1
- package/dist/sheet.js +7 -7
- package/dist/spinner.css +115 -0
- package/dist/spinner.js +4 -0
- package/dist/spinner.js.map +1 -0
- package/dist/status-badge.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/support-rail.css +76 -238
- package/dist/support-rail.js +97 -105
- package/dist/support-rail.js.map +1 -1
- package/dist/table.css +2 -2
- package/dist/table.js +8 -6
- package/dist/table.js.map +1 -1
- package/dist/tabs.css +10 -14
- package/dist/tabs.js +6 -6
- package/dist/tag.css +1 -1
- package/dist/tag.js +6 -6
- package/dist/text-field.js +3 -3
- package/dist/textarea.css +1 -1
- package/dist/textarea.js +2 -2
- package/dist/theme-grid.js +11 -0
- package/dist/theme-grid.js.map +1 -0
- package/dist/theme-switcher.css +107 -0
- package/dist/theme-switcher.js +70 -0
- package/dist/theme-switcher.js.map +1 -0
- package/dist/theme-transition-LLC644ZR.js +346 -0
- package/dist/theme-transition-LLC644ZR.js.map +1 -0
- package/dist/theme-transition.css +48 -0
- package/dist/theme.js +57 -26
- package/dist/theme.js.map +1 -1
- package/dist/tide-DJZMDAFT.js +57 -0
- package/dist/tide-DJZMDAFT.js.map +1 -0
- package/dist/tiktok.css +2 -3
- package/dist/tiktok.js +2 -2
- package/dist/time-field.js +4 -4
- package/dist/toast.css +2 -14
- package/dist/toast.js +11 -9
- package/dist/toast.js.map +1 -1
- package/dist/toggle-tag.js +2 -2
- package/dist/toggle.css +1 -1
- package/dist/tooltip.css +1 -1
- package/dist/tooltip.js +5 -5
- package/dist/trigger.css +1 -1
- package/dist/types/components/composites/date-picker/month-jump.d.ts +11 -0
- package/dist/types/components/composites/theme-switcher/ThemeGrid.d.ts +20 -0
- package/dist/types/components/composites/theme-switcher/ThemeSwitcher.d.ts +24 -0
- package/dist/types/components/compound/support-rail/SupportRail.d.ts +10 -8
- package/dist/types/components/dev/MotionDevtools.d.ts +10 -5
- package/dist/types/components/expressive/theme-transition/bloom.d.ts +2 -0
- package/dist/types/components/expressive/theme-transition/paint.d.ts +2 -0
- package/dist/types/components/expressive/theme-transition/scene.d.ts +24 -0
- package/dist/types/components/expressive/theme-transition/theme-transition.d.ts +19 -0
- package/dist/types/components/expressive/theme-transition/tide.d.ts +2 -0
- package/dist/types/components/internal/icon/Icon.d.ts +1 -0
- package/dist/types/components/primitives/button/Button.d.ts +9 -12
- package/dist/types/components/primitives/button/button-style.d.ts +15 -0
- package/dist/types/components/primitives/spinner/Spinner.d.ts +27 -0
- package/dist/types/engine/animate.d.ts +1 -0
- package/dist/types/tokens/component-styles.generated.d.ts +35 -38
- package/dist/types/tokens/motion-tokens.d.ts +2 -2
- package/dist/types/tokens/theme-store.d.ts +47 -0
- package/dist/types/tokens/theme-sync.d.ts +7 -1
- package/dist/types/tokens/theme-tokens.generated.d.ts +121 -109
- package/dist/types/tokens/theme.d.ts +28 -5
- package/dist/typing-lines.css +1 -1
- package/dist/typing-lines.js +2 -2
- package/dist/weight-field.css +2 -2
- package/dist/youtube.css +1 -1
- package/dist/youtube.js +2 -2
- package/package.json +25 -31
- package/skills/zyncat-ui/references/components.md +5 -2
- package/src/components/composites/alert/Alert.tsx +7 -3
- package/src/components/composites/alert/alert.css +1 -1
- package/src/components/composites/date-picker/calendar-panel.tsx +10 -4
- package/src/components/composites/date-picker/date-picker.css +168 -43
- package/src/components/composites/date-picker/month-jump.tsx +192 -0
- package/src/components/composites/date-picker/range-panel.tsx +20 -5
- package/src/components/composites/dialog/dialog.css +4 -3
- package/src/components/composites/dropdown/dropdown.css +1 -1
- package/src/components/composites/emoji-picker/styles.css +1 -1
- package/src/components/composites/modal/modal.css +1 -1
- package/src/components/composites/pagination/pagination.css +1 -1
- package/src/components/composites/popover/popover.css +1 -1
- package/src/components/composites/select/select.css +1 -1
- package/src/components/composites/sheet/sheet.css +1 -1
- package/src/components/composites/table/table.css +2 -2
- package/src/components/composites/tabs/tabs.css +10 -14
- package/src/components/composites/theme-switcher/ThemeGrid.tsx +133 -0
- package/src/components/composites/theme-switcher/ThemeGrid.usage.md +20 -0
- package/src/components/composites/theme-switcher/ThemeSwitcher.tsx +75 -0
- package/src/components/composites/theme-switcher/ThemeSwitcher.usage.md +21 -0
- package/src/components/composites/theme-switcher/theme-switcher.css +107 -0
- package/src/components/composites/toast/Toast.tsx +2 -1
- package/src/components/composites/toast/toast.css +2 -14
- package/src/components/composites/tooltip/tooltip.css +1 -1
- package/src/components/compound/support-rail/SupportRail.tsx +116 -128
- package/src/components/compound/support-rail/SupportRail.usage.md +7 -6
- package/src/components/compound/support-rail/support-rail.css +76 -238
- package/src/components/dev/MotionDevtools.tsx +252 -42
- package/src/components/dev/MotionDevtools.usage.md +12 -4
- package/src/components/dev/motion-devtools.css +77 -2
- package/src/components/dev/slowmo-engine.ts +1 -1
- package/src/components/expressive/confetti/confetti.css +3 -3
- package/src/components/expressive/facebook-feed/facebook-feed.css +1 -1
- package/src/components/expressive/flow-field/FlowField.tsx +1 -1
- package/src/components/expressive/flow-field/flow-field.css +4 -4
- package/src/components/expressive/instagram-feed/instagram-feed.css +1 -1
- package/src/components/expressive/lens/lens.css +1 -2
- package/src/components/expressive/morphing-text/morphing-text.css +2 -2
- package/src/components/expressive/odometer/odometer.css +1 -1
- package/src/components/expressive/theme-transition/bloom.ts +88 -0
- package/src/components/expressive/theme-transition/paint.ts +296 -0
- package/src/components/expressive/theme-transition/scene.ts +38 -0
- package/src/components/expressive/theme-transition/theme-transition.css +48 -0
- package/src/components/expressive/theme-transition/theme-transition.ts +423 -0
- package/src/components/expressive/theme-transition/tide.ts +65 -0
- package/src/components/expressive/tiktok/tiktok.css +2 -3
- package/src/components/expressive/typing-lines/typing-lines.css +1 -1
- package/src/components/expressive/weight-field/weight-field.css +2 -2
- package/src/components/expressive/youtube/youtube.css +1 -1
- package/src/components/internal/glass/glass.css +1 -1
- package/src/components/internal/icon/Icon.tsx +2 -0
- package/src/components/internal/icon/icon.css +1 -1
- package/src/components/internal/menu/menu-surface.css +1 -1
- package/src/components/internal/overlay/overlay.css +1 -1
- package/src/components/internal/overlay/trigger.css +1 -1
- package/src/components/primitives/avatar/avatar.css +3 -2
- package/src/components/primitives/badge/badge.css +1 -1
- package/src/components/primitives/badge/digit-strip.css +1 -1
- package/src/components/primitives/button/Button.tsx +12 -26
- package/src/components/primitives/button/button-style.ts +28 -0
- package/src/components/primitives/button/button.css +21 -24
- package/src/components/primitives/checkbox/checkbox.css +1 -1
- package/src/components/primitives/collapse/collapse.css +8 -5
- package/src/components/primitives/input/input.css +7 -4
- package/src/components/primitives/radio-group/radio-group.css +6 -4
- package/src/components/primitives/spinner/Spinner.tsx +70 -0
- package/src/components/primitives/spinner/Spinner.usage.md +19 -0
- package/src/components/primitives/spinner/spinner.css +115 -0
- package/src/components/primitives/tag/tag.css +1 -1
- package/src/components/primitives/textarea/textarea.css +1 -1
- package/src/components/primitives/toggle/toggle.css +1 -1
- package/src/engine/animate.ts +10 -2
- package/src/mcp/server.ts +2 -1
- package/src/styles.css +3 -3
- package/src/tokens/base.css +5 -5
- package/src/tokens/color.css +8 -9
- package/src/tokens/component-styles.generated.ts +36 -38
- package/src/tokens/dark.css +8 -13
- package/src/tokens/decisions.css +5 -8
- package/src/tokens/elevation.css +18 -26
- package/src/tokens/glass.css +3 -2
- package/src/tokens/motion-defaults.generated.ts +1 -1
- package/src/tokens/motion-tokens.ts +3 -3
- package/src/tokens/motion.css +9 -9
- package/src/tokens/radius.css +3 -2
- package/src/tokens/reset.css +36 -0
- package/src/tokens/semantic.css +10 -18
- package/src/tokens/spacing.css +1 -1
- package/src/tokens/theme-store.ts +187 -0
- package/src/tokens/theme-sync.tsx +49 -2
- package/src/tokens/theme-tokens.generated.ts +124 -110
- package/src/tokens/theme.tsx +96 -24
- package/src/tokens/theme.usage.md +25 -24
- package/src/tokens/typography.css +4 -3
- package/tailwind.css +7 -13
- package/dist/chunk-6SUHSSOK.js +0 -25
- package/dist/chunk-6SUHSSOK.js.map +0 -1
- package/dist/chunk-BH4JFWXQ.js.map +0 -1
- package/dist/chunk-FEXUS4SV.js.map +0 -1
- package/dist/chunk-GOLSYGRA.js.map +0 -1
- package/dist/chunk-N2GJEO5Z.js.map +0 -1
- package/dist/chunk-UYSXJ7MH.js.map +0 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState, type KeyboardEvent } from 'react';
|
|
4
|
+
|
|
5
|
+
import { animate } from '../../../engine';
|
|
6
|
+
import { GlidePill, useGlide } from '../../../motion/glide';
|
|
7
|
+
import { slideIn } from '../../../motion/presets';
|
|
8
|
+
import { UIMotion } from '../../../tokens/motion-tokens';
|
|
9
|
+
import { Icon } from '../../internal/icon/Icon';
|
|
10
|
+
import { activationProps, type ActivateOn } from '../../internal/utils/activation';
|
|
11
|
+
import { cx } from '../../internal/utils/cx';
|
|
12
|
+
import { Popover } from '../popover/Popover';
|
|
13
|
+
import { MONTHS, parse, toKey } from './date-utils';
|
|
14
|
+
|
|
15
|
+
const YEARS_PER_PAGE = 3;
|
|
16
|
+
const MONTH_COLUMNS = 3;
|
|
17
|
+
const UNBOUNDED_YEAR_REACH = 100;
|
|
18
|
+
const GRID_PARTS = '.zc-dtp__dow, .zc-dtp__days';
|
|
19
|
+
|
|
20
|
+
function gridBox(trigger: HTMLElement | null): DOMRect | null {
|
|
21
|
+
const cal = trigger && trigger.closest('.zc-dtp__cal');
|
|
22
|
+
const parts = cal && cal.querySelectorAll(GRID_PARTS);
|
|
23
|
+
if (!parts || parts.length === 0) return null;
|
|
24
|
+
const head = parts[0].getBoundingClientRect();
|
|
25
|
+
const tail = parts[parts.length - 1].getBoundingClientRect();
|
|
26
|
+
return new DOMRect(head.left, head.top, Math.max(head.width, tail.width), tail.bottom - head.top);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface MonthJumpProps {
|
|
30
|
+
y: number;
|
|
31
|
+
m: number;
|
|
32
|
+
min?: string;
|
|
33
|
+
max?: string;
|
|
34
|
+
onPick: (y: number, m: number) => void;
|
|
35
|
+
activateOn?: ActivateOn;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function MonthJump({ y, m, min, max, onPick, activateOn }: MonthJumpProps) {
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
const [page, setPage] = useState(y - 1);
|
|
41
|
+
const [year, setYear] = useState(y);
|
|
42
|
+
const [cursor, setCursor] = useState(m);
|
|
43
|
+
|
|
44
|
+
const [box, setBox] = useState<{ width: number; height: number } | null>(null);
|
|
45
|
+
|
|
46
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
47
|
+
const monthsRef = useRef<HTMLDivElement>(null);
|
|
48
|
+
const stripRef = useRef<HTMLDivElement>(null);
|
|
49
|
+
|
|
50
|
+
const monthGlide = useGlide(monthsRef);
|
|
51
|
+
const yearGlide = useGlide(stripRef);
|
|
52
|
+
|
|
53
|
+
const minYear = min ? parse(min).getFullYear() : y - UNBOUNDED_YEAR_REACH;
|
|
54
|
+
const maxYear = max ? parse(max).getFullYear() : y + UNBOUNDED_YEAR_REACH;
|
|
55
|
+
|
|
56
|
+
const monthEnabled = (yy: number, mm: number): boolean => {
|
|
57
|
+
const first = toKey(new Date(yy, mm, 1));
|
|
58
|
+
const last = toKey(new Date(yy, mm + 1, 0));
|
|
59
|
+
return (!min || last >= min) && (!max || first <= max);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function toggle(next: boolean) {
|
|
63
|
+
if (next) {
|
|
64
|
+
const grid = gridBox(triggerRef.current);
|
|
65
|
+
setBox(grid ? { width: grid.width, height: grid.height } : null);
|
|
66
|
+
setPage(y - 1);
|
|
67
|
+
setYear(y);
|
|
68
|
+
setCursor(m);
|
|
69
|
+
}
|
|
70
|
+
setOpen(next);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!open) return;
|
|
75
|
+
monthsRef.current?.querySelector<HTMLButtonElement>('[tabindex="0"]')?.focus();
|
|
76
|
+
}, [open, cursor]);
|
|
77
|
+
|
|
78
|
+
function turn(dir: number) {
|
|
79
|
+
const next = page + dir * YEARS_PER_PAGE;
|
|
80
|
+
if (next + YEARS_PER_PAGE - 1 < minYear || next > maxYear) return;
|
|
81
|
+
setPage(next);
|
|
82
|
+
yearGlide.leave();
|
|
83
|
+
const el = stripRef.current;
|
|
84
|
+
if (el) animate(el, slideIn(dir * UIMotion.dist.md, UIMotion.t.enter));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function moveCursor(delta: number) {
|
|
88
|
+
const next = cursor + delta;
|
|
89
|
+
if (next < 0 || next > MONTHS.length - 1) return;
|
|
90
|
+
setCursor(next);
|
|
91
|
+
}
|
|
92
|
+
function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {
|
|
93
|
+
const k = e.key;
|
|
94
|
+
if (k === 'ArrowLeft') moveCursor(-1);
|
|
95
|
+
else if (k === 'ArrowRight') moveCursor(1);
|
|
96
|
+
else if (k === 'ArrowUp') moveCursor(-MONTH_COLUMNS);
|
|
97
|
+
else if (k === 'ArrowDown') moveCursor(MONTH_COLUMNS);
|
|
98
|
+
else return;
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function pick(mm: number) {
|
|
103
|
+
onPick(year, mm);
|
|
104
|
+
setOpen(false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const years: number[] = [];
|
|
108
|
+
for (let i = 0; i < YEARS_PER_PAGE; i++) years.push(page + i);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Popover
|
|
112
|
+
open={open}
|
|
113
|
+
onOpenChange={toggle}
|
|
114
|
+
side="bottom"
|
|
115
|
+
align="center"
|
|
116
|
+
arrow
|
|
117
|
+
activateOn={activateOn}
|
|
118
|
+
htmlProps={box ? { style: box } : undefined}
|
|
119
|
+
trigger={
|
|
120
|
+
<button
|
|
121
|
+
type="button"
|
|
122
|
+
ref={triggerRef}
|
|
123
|
+
className="zc-dtp__jump"
|
|
124
|
+
aria-label={'Change month - ' + MONTHS[m] + ' ' + y}
|
|
125
|
+
>
|
|
126
|
+
<span className="zc-dtp__month" aria-live="polite">
|
|
127
|
+
{MONTHS[m]} <span className="zc-dtp__year">{y}</span>
|
|
128
|
+
</span>
|
|
129
|
+
<Icon name="caret-down" size="sm" className="zc-dtp__jumpCaret" />
|
|
130
|
+
</button>
|
|
131
|
+
}
|
|
132
|
+
>
|
|
133
|
+
<div className="zc-dtp__jumpPanel" role="group" aria-label="Jump to month" onKeyDown={onKeyDown}>
|
|
134
|
+
<div className="zc-dtp__jumpYears">
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
className="zc-dtp__nav"
|
|
138
|
+
aria-label="Earlier years"
|
|
139
|
+
disabled={page <= minYear}
|
|
140
|
+
{...activationProps<HTMLButtonElement>(() => turn(-1), { on: activateOn })}
|
|
141
|
+
>
|
|
142
|
+
<Icon name="caret-left" size="sm" />
|
|
143
|
+
</button>
|
|
144
|
+
<div className="zc-dtp__jumpStrip" ref={stripRef} onPointerLeave={yearGlide.leave}>
|
|
145
|
+
{years.map((yy) => (
|
|
146
|
+
<button
|
|
147
|
+
key={yy}
|
|
148
|
+
type="button"
|
|
149
|
+
className={cx('zc-dtp__jumpOpt', 'zc-dtp__jumpYear', yy === year && 'zc-is-active')}
|
|
150
|
+
disabled={yy < minYear || yy > maxYear}
|
|
151
|
+
aria-pressed={yy === year}
|
|
152
|
+
onPointerEnter={(e) => yearGlide.enter(e.currentTarget)}
|
|
153
|
+
{...activationProps<HTMLButtonElement>(() => setYear(yy), { on: activateOn })}
|
|
154
|
+
>
|
|
155
|
+
{yy}
|
|
156
|
+
</button>
|
|
157
|
+
))}
|
|
158
|
+
<GlidePill className="zc-dtp__jumpGlide" glide={yearGlide} />
|
|
159
|
+
</div>
|
|
160
|
+
<button
|
|
161
|
+
type="button"
|
|
162
|
+
className="zc-dtp__nav"
|
|
163
|
+
aria-label="Later years"
|
|
164
|
+
disabled={page + YEARS_PER_PAGE - 1 >= maxYear}
|
|
165
|
+
{...activationProps<HTMLButtonElement>(() => turn(1), { on: activateOn })}
|
|
166
|
+
>
|
|
167
|
+
<Icon name="caret-right" size="sm" />
|
|
168
|
+
</button>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div className="zc-dtp__jumpMonths" ref={monthsRef} onPointerLeave={monthGlide.leave}>
|
|
172
|
+
{MONTHS.map((name, mm) => (
|
|
173
|
+
<button
|
|
174
|
+
key={name}
|
|
175
|
+
type="button"
|
|
176
|
+
className={cx('zc-dtp__jumpOpt', year === y && mm === m && 'zc-is-active')}
|
|
177
|
+
disabled={!monthEnabled(year, mm)}
|
|
178
|
+
tabIndex={mm === cursor ? 0 : -1}
|
|
179
|
+
aria-pressed={year === y && mm === m}
|
|
180
|
+
aria-label={name + ' ' + year}
|
|
181
|
+
onPointerEnter={(e) => monthGlide.enter(e.currentTarget)}
|
|
182
|
+
{...activationProps<HTMLButtonElement>(() => pick(mm), { on: activateOn })}
|
|
183
|
+
>
|
|
184
|
+
{name.slice(0, 3)}
|
|
185
|
+
</button>
|
|
186
|
+
))}
|
|
187
|
+
<GlidePill className="zc-dtp__jumpGlide" glide={monthGlide} />
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
</Popover>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
@@ -11,6 +11,7 @@ import { Icon } from '../../internal/icon/Icon';
|
|
|
11
11
|
import { activationProps, type ActivateOn } from '../../internal/utils/activation';
|
|
12
12
|
import { Button } from '../../primitives/button/Button';
|
|
13
13
|
import { add, col, DOW, grid, MONTHS, pad, parse, today, toKey, tzLabel, within } from './date-utils';
|
|
14
|
+
import { MonthJump } from './month-jump';
|
|
14
15
|
import { useDayFocus } from './use-day-focus';
|
|
15
16
|
|
|
16
17
|
const CAP_FLIP = { timing: UIMotion.t.settle };
|
|
@@ -153,11 +154,20 @@ export function DrpPanel({
|
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
const prevViewIdxRef = useRef(viewIdx);
|
|
156
|
-
const
|
|
157
|
+
const jumpedRef = useRef(false);
|
|
158
|
+
const navDir =
|
|
159
|
+
prevViewIdxRef.current === viewIdx || jumpedRef.current ? 0 : viewIdx > prevViewIdxRef.current ? 1 : -1;
|
|
157
160
|
useEffect(() => {
|
|
158
161
|
prevViewIdxRef.current = viewIdx;
|
|
162
|
+
jumpedRef.current = false;
|
|
159
163
|
}, [viewIdx]);
|
|
160
164
|
|
|
165
|
+
function jumpToMonth(y: number, m: number, offset: number) {
|
|
166
|
+
jumpedRef.current = true;
|
|
167
|
+
const base = new Date(y, m - offset, 1);
|
|
168
|
+
setView({ y: base.getFullYear(), m: base.getMonth() });
|
|
169
|
+
}
|
|
170
|
+
|
|
161
171
|
function moveFocus(deltaDays: number, deltaMonths = 0) {
|
|
162
172
|
const d = parse(focusKey);
|
|
163
173
|
if (deltaMonths) d.setMonth(d.getMonth() + deltaMonths);
|
|
@@ -276,7 +286,7 @@ export function DrpPanel({
|
|
|
276
286
|
const nextStart = toKey(new Date(y, m + 1, 1));
|
|
277
287
|
return (
|
|
278
288
|
<div className="zc-dtp__cal" key={offset}>
|
|
279
|
-
<div className=
|
|
289
|
+
<div className="zc-drp__mhead">
|
|
280
290
|
{withPrev ? (
|
|
281
291
|
<button
|
|
282
292
|
type="button"
|
|
@@ -288,9 +298,14 @@ export function DrpPanel({
|
|
|
288
298
|
<Icon name="caret-left" size="sm" />
|
|
289
299
|
</button>
|
|
290
300
|
) : null}
|
|
291
|
-
<
|
|
292
|
-
|
|
293
|
-
|
|
301
|
+
<MonthJump
|
|
302
|
+
y={y}
|
|
303
|
+
m={m}
|
|
304
|
+
min={min}
|
|
305
|
+
max={max}
|
|
306
|
+
activateOn={activateOn}
|
|
307
|
+
onPick={(py, pm) => jumpToMonth(py, pm, offset)}
|
|
308
|
+
/>
|
|
294
309
|
{withNext ? (
|
|
295
310
|
<button
|
|
296
311
|
type="button"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
2
|
|
|
3
3
|
@layer zyncat.components {
|
|
4
4
|
.zc-overlay-layer--dialog {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
display: flex;
|
|
43
43
|
align-items: flex-start;
|
|
44
44
|
gap: var(--space-3);
|
|
45
|
-
padding: var(--space-5) var(--space-5) var(--space-4);
|
|
45
|
+
padding: var(--space-5) var(--space-5) calc(var(--space-4) - var(--ring-gutter));
|
|
46
46
|
transition:
|
|
47
47
|
border-color var(--duration-base) var(--ease-standard),
|
|
48
48
|
box-shadow var(--duration-base) var(--ease-standard);
|
|
@@ -126,7 +126,8 @@
|
|
|
126
126
|
min-height: 0;
|
|
127
127
|
overflow-y: auto;
|
|
128
128
|
overscroll-behavior: contain;
|
|
129
|
-
padding:
|
|
129
|
+
scroll-padding: var(--ring-gutter);
|
|
130
|
+
padding: var(--ring-gutter) var(--space-5) var(--space-5);
|
|
130
131
|
color: var(--text-body);
|
|
131
132
|
font: var(--type-body);
|
|
132
133
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
2
|
|
|
3
3
|
@layer zyncat.components {
|
|
4
4
|
.zc-tbl,
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
min-height: 0;
|
|
42
42
|
overflow: auto;
|
|
43
43
|
overscroll-behavior-x: contain;
|
|
44
|
-
scroll-padding: var(--ring-
|
|
44
|
+
scroll-padding: var(--ring-gutter);
|
|
45
45
|
}
|
|
46
46
|
.zc-tbl[data-y-scroll] .zc-tbl__scroll {
|
|
47
47
|
overscroll-behavior-y: contain;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
@layer zyncat.tokens, zyncat.components;
|
|
1
|
+
@layer zyncat.reset, zyncat.tokens, zyncat.components;
|
|
2
2
|
|
|
3
3
|
@layer zyncat.components {
|
|
4
4
|
.zc-tabs {
|
|
5
5
|
/* 2px, not --border-emphasis: 1.5px renders as sub-pixel fuzz on 1x screens. */
|
|
6
6
|
--tabs-ink-h: 2px;
|
|
7
|
-
/* The pill variant's segment radius. The track rounds one pad wider, staying concentric. */
|
|
8
7
|
--tabs-pill-radius: var(--radius-md);
|
|
9
8
|
position: relative;
|
|
10
9
|
}
|
|
@@ -26,9 +25,8 @@
|
|
|
26
25
|
scrollbar-width: none;
|
|
27
26
|
margin-inline: calc(var(--space-2) * -1);
|
|
28
27
|
padding-inline: var(--space-2);
|
|
29
|
-
|
|
30
|
-
padding-
|
|
31
|
-
scroll-padding: var(--ring-width);
|
|
28
|
+
padding-block: max(var(--ring-gutter), calc(var(--tabs-ink-h) + var(--space-px)));
|
|
29
|
+
scroll-padding-inline: var(--space-2);
|
|
32
30
|
|
|
33
31
|
--tabs-fade-start: 0px;
|
|
34
32
|
--tabs-fade-end: 0px;
|
|
@@ -55,15 +53,18 @@
|
|
|
55
53
|
border: 0;
|
|
56
54
|
background: none;
|
|
57
55
|
margin: 0;
|
|
58
|
-
padding: 0
|
|
56
|
+
padding: 0;
|
|
59
57
|
flex: none;
|
|
60
58
|
display: block;
|
|
61
59
|
font-family: var(--font-body);
|
|
62
60
|
cursor: pointer;
|
|
63
61
|
-webkit-tap-highlight-color: transparent;
|
|
62
|
+
border-radius: var(--radius-md);
|
|
63
|
+
outline: var(--ring-rest);
|
|
64
|
+
transition: var(--transition-control);
|
|
64
65
|
}
|
|
65
66
|
.zc-tab:focus-visible {
|
|
66
|
-
outline:
|
|
67
|
+
outline: var(--ring-accent);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
.zc-tab__pad {
|
|
@@ -81,7 +82,6 @@
|
|
|
81
82
|
transition:
|
|
82
83
|
var(--transition-control),
|
|
83
84
|
transform var(--duration-fast) var(--ease-standard);
|
|
84
|
-
outline: var(--ring-rest);
|
|
85
85
|
}
|
|
86
86
|
.zc-tab__pad .zc-icon {
|
|
87
87
|
display: inline-flex;
|
|
@@ -97,9 +97,6 @@
|
|
|
97
97
|
.zc-tab.zc-is-selected:hover:not(:disabled) .zc-tab__pad {
|
|
98
98
|
color: var(--text-strong);
|
|
99
99
|
}
|
|
100
|
-
.zc-tab:focus-visible .zc-tab__pad {
|
|
101
|
-
outline: var(--ring-accent);
|
|
102
|
-
}
|
|
103
100
|
.zc-tab:disabled {
|
|
104
101
|
cursor: not-allowed;
|
|
105
102
|
}
|
|
@@ -142,7 +139,7 @@
|
|
|
142
139
|
.zc-tabs__ink {
|
|
143
140
|
position: absolute;
|
|
144
141
|
left: 0;
|
|
145
|
-
bottom:
|
|
142
|
+
bottom: 0;
|
|
146
143
|
height: var(--tabs-ink-h);
|
|
147
144
|
border-radius: var(--radius-full);
|
|
148
145
|
background: var(--accent);
|
|
@@ -170,7 +167,7 @@
|
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
.zc-tabs--pill .zc-tab {
|
|
173
|
-
|
|
170
|
+
border-radius: var(--tabs-pill-radius);
|
|
174
171
|
}
|
|
175
172
|
.zc-tabs--pill .zc-tab__pad {
|
|
176
173
|
z-index: 1;
|
|
@@ -198,7 +195,6 @@
|
|
|
198
195
|
}
|
|
199
196
|
.zc-tab-panel:focus-visible {
|
|
200
197
|
outline: var(--ring-accent);
|
|
201
|
-
outline-offset: var(--ring-inset);
|
|
202
198
|
border-radius: var(--radius-md);
|
|
203
199
|
}
|
|
204
200
|
.zc-tab-panel__inner {
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import './theme-switcher.css';
|
|
4
|
+
|
|
5
|
+
import { useId, type CSSProperties, type HTMLAttributes, type KeyboardEvent, type MouseEvent } from 'react';
|
|
6
|
+
|
|
7
|
+
import type { DataAttributes } from '../../../dom-props';
|
|
8
|
+
import { Motion } from '../../../motion/element';
|
|
9
|
+
import { setThemePreference, type Polarity, type PolarityPreference } from '../../../tokens/theme-store';
|
|
10
|
+
import { useTheme, useThemeTarget } from '../../../tokens/theme-sync';
|
|
11
|
+
import { cx } from '../../internal/utils/cx';
|
|
12
|
+
|
|
13
|
+
const POLARITIES: readonly PolarityPreference[] = ['system', 'light', 'dark'];
|
|
14
|
+
const CAPTIONS: Record<PolarityPreference, string> = { system: 'System', light: 'Light', dark: 'Dark' };
|
|
15
|
+
const STEPS: Record<string, number[]> = { ArrowUp: [-1, 0], ArrowDown: [1, 0], ArrowLeft: [0, -1], ArrowRight: [0, 1] };
|
|
16
|
+
|
|
17
|
+
const focusOnMount = (node: HTMLElement | null) => node?.focus({ preventScroll: true });
|
|
18
|
+
|
|
19
|
+
const centreOf = (element: Element): [number, number] => {
|
|
20
|
+
const box = element.getBoundingClientRect();
|
|
21
|
+
return [box.left + box.width / 2, box.top + box.height / 2];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface ThemeGridProps {
|
|
25
|
+
/** Overrides the palette's own `name`, keyed like `themes`. For names that come from a translation. */
|
|
26
|
+
labels?: Record<string, string>;
|
|
27
|
+
/** Accessible name of the radio group. @default 'Theme' */
|
|
28
|
+
label?: string;
|
|
29
|
+
/** Focus the selected card on mount - for a grid that opens inside an overlay. @default false */
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
/** Enter or Tab on a card. `ThemeSwitcher` closes its panel with it; inline, leave it unset. */
|
|
32
|
+
onDismiss?: () => void;
|
|
33
|
+
/** Extra class(es) merged onto the grid. */
|
|
34
|
+
className?: string;
|
|
35
|
+
/** Inline styles merged onto the grid. */
|
|
36
|
+
style?: CSSProperties;
|
|
37
|
+
/** Standard <div> attributes (aria-*, data-*, ...) forwarded to the grid. */
|
|
38
|
+
htmlProps?: HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function Mini({ palette, polarity, half }: { palette: string; polarity: Polarity; half?: boolean }) {
|
|
42
|
+
return (
|
|
43
|
+
<span
|
|
44
|
+
className={cx('zc-theme-switcher__mini', half && 'zc-theme-switcher__mini--half')}
|
|
45
|
+
data-theme={palette}
|
|
46
|
+
data-polarity={polarity}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function ThemeGrid({
|
|
52
|
+
labels,
|
|
53
|
+
label = 'Theme',
|
|
54
|
+
autoFocus = false,
|
|
55
|
+
onDismiss,
|
|
56
|
+
className,
|
|
57
|
+
style,
|
|
58
|
+
htmlProps,
|
|
59
|
+
}: ThemeGridProps) {
|
|
60
|
+
const { themes, themeNames } = useTheme();
|
|
61
|
+
const { theme, polarity } = useThemeTarget();
|
|
62
|
+
const ringId = useId();
|
|
63
|
+
const nameOf = (palette: string) => labels?.[palette] ?? themeNames[palette] ?? palette;
|
|
64
|
+
|
|
65
|
+
const onKeyDown = (event: KeyboardEvent, row: number, col: number) => {
|
|
66
|
+
if (event.key === 'Enter' || event.key === 'Tab') {
|
|
67
|
+
if (!onDismiss) return;
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
onDismiss();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const step = STEPS[event.key];
|
|
73
|
+
if (!step) return;
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
setThemePreference(
|
|
76
|
+
{
|
|
77
|
+
theme: themes[(row + step[0] + themes.length) % themes.length],
|
|
78
|
+
polarity: POLARITIES[(col + step[1] + POLARITIES.length) % POLARITIES.length],
|
|
79
|
+
},
|
|
80
|
+
{ origin: centreOf(event.currentTarget) },
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const onPick = (event: MouseEvent<HTMLButtonElement>, palette: string, choice: PolarityPreference) =>
|
|
85
|
+
setThemePreference({ theme: palette, polarity: choice }, { origin: centreOf(event.currentTarget) });
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div
|
|
89
|
+
{...htmlProps}
|
|
90
|
+
data-theme-lead=""
|
|
91
|
+
role="radiogroup"
|
|
92
|
+
aria-label={label}
|
|
93
|
+
style={style}
|
|
94
|
+
className={cx('zc-theme-switcher__grid', className)}
|
|
95
|
+
>
|
|
96
|
+
{themes.map((palette, row) => (
|
|
97
|
+
<div key={palette} className="zc-theme-switcher__row">
|
|
98
|
+
{themes.length > 1 && (
|
|
99
|
+
<span className="zc-theme-switcher__row-label" aria-hidden="true">
|
|
100
|
+
{nameOf(palette)}
|
|
101
|
+
</span>
|
|
102
|
+
)}
|
|
103
|
+
{POLARITIES.map((choice, col) => {
|
|
104
|
+
const checked = palette === theme && choice === polarity;
|
|
105
|
+
return (
|
|
106
|
+
<button
|
|
107
|
+
key={choice}
|
|
108
|
+
ref={checked && autoFocus ? focusOnMount : undefined}
|
|
109
|
+
type="button"
|
|
110
|
+
role="radio"
|
|
111
|
+
aria-checked={checked}
|
|
112
|
+
aria-label={`${nameOf(palette)}, ${CAPTIONS[choice]}`}
|
|
113
|
+
tabIndex={checked ? 0 : -1}
|
|
114
|
+
className={cx('zc-theme-switcher__card', checked && 'zc-is-selected')}
|
|
115
|
+
onClick={(event) => onPick(event, palette, choice)}
|
|
116
|
+
onKeyDown={(event) => onKeyDown(event, row, col)}
|
|
117
|
+
>
|
|
118
|
+
<span className="zc-theme-switcher__preview">
|
|
119
|
+
<Mini palette={palette} polarity={choice === 'dark' ? 'dark' : 'light'} />
|
|
120
|
+
{choice === 'system' && <Mini palette={palette} polarity="dark" half />}
|
|
121
|
+
{checked && (
|
|
122
|
+
<Motion as="span" layoutId={ringId} className="zc-theme-switcher__ring" aria-hidden="true" />
|
|
123
|
+
)}
|
|
124
|
+
</span>
|
|
125
|
+
{CAPTIONS[choice]}
|
|
126
|
+
</button>
|
|
127
|
+
);
|
|
128
|
+
})}
|
|
129
|
+
</div>
|
|
130
|
+
))}
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# ThemeGrid - @zyncat/ui/theme-grid
|
|
2
|
+
|
|
3
|
+
Group: overlays
|
|
4
|
+
Docs: https://ui.zyncat.app/theme-switcher
|
|
5
|
+
|
|
6
|
+
The theme picker without a surface: a radio grid of miniatures, one card per palette and side plus a split System card, each drawn from that theme's real tokens.
|
|
7
|
+
|
|
8
|
+
This is what `ThemeSwitcher` puts in its popover, exported on its own so it can sit in a settings page,
|
|
9
|
+
a `Sheet`, a `Dialog` or a preferences panel. It imports no overlay, paints no background, and needs no
|
|
10
|
+
props: mount `ZyncatTheme` once and the grid lists every palette it declared, `default` first. A click
|
|
11
|
+
applies the theme live. Arrow keys move as a radio group and select as they go - left and right change
|
|
12
|
+
the side, up and down the palette. Each palette shows its own `name`; `labels` overrides that per key,
|
|
13
|
+
for names that come from a translation. `label` is the accessible name of the group, and `autoFocus`
|
|
14
|
+
puts focus on the selected card at mount, for a grid
|
|
15
|
+
that opens inside an overlay; leave it off inline. `onDismiss` fires on Enter or Tab, for the surface
|
|
16
|
+
around it to close - without it both keys stay inert.
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
<ThemeGrid />
|
|
20
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import './theme-switcher.css';
|
|
4
|
+
|
|
5
|
+
import { useState, type CSSProperties } from 'react';
|
|
6
|
+
|
|
7
|
+
import type { DisableableAnimation } from '../../../motion/timing';
|
|
8
|
+
import { useTheme, useThemeTarget } from '../../../tokens/theme-sync';
|
|
9
|
+
import { cx } from '../../internal/utils/cx';
|
|
10
|
+
import { Button, type ButtonProps } from '../../primitives/button/Button';
|
|
11
|
+
import { Popover } from '../popover/Popover';
|
|
12
|
+
import { ThemeGrid, type ThemeGridProps } from './ThemeGrid';
|
|
13
|
+
|
|
14
|
+
const CAPTIONS: Record<string, string> = { system: 'System', light: 'Light', dark: 'Dark' };
|
|
15
|
+
|
|
16
|
+
export interface ThemeSwitcherProps {
|
|
17
|
+
/** Overrides the palette's own `name`, keyed like `themes`. For names that come from a translation. */
|
|
18
|
+
labels?: ThemeGridProps['labels'];
|
|
19
|
+
/** Accessible name of the control and its grid. @default 'Theme' */
|
|
20
|
+
label?: string;
|
|
21
|
+
/** Preferred side of the panel; flips to the opposite side when cramped. @default 'bottom' */
|
|
22
|
+
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
23
|
+
/** Cross-axis alignment of the panel against the chip. @default 'end' */
|
|
24
|
+
align?: 'start' | 'center' | 'end';
|
|
25
|
+
/** Open/close timing - motion tokens only, or `null` to disable. @default open 'base'/'entrance', close 'fast'/'exit' */
|
|
26
|
+
animation?: DisableableAnimation;
|
|
27
|
+
/** Extra class(es) merged onto the chip. */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** Inline styles merged onto the chip. */
|
|
30
|
+
style?: CSSProperties;
|
|
31
|
+
/** Standard <button> attributes (aria-*, data-*, ...) forwarded to the chip. */
|
|
32
|
+
htmlProps?: ButtonProps['htmlProps'];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function ThemeSwitcher({
|
|
36
|
+
labels,
|
|
37
|
+
label = 'Theme',
|
|
38
|
+
side = 'bottom',
|
|
39
|
+
align = 'end',
|
|
40
|
+
animation,
|
|
41
|
+
className,
|
|
42
|
+
style,
|
|
43
|
+
htmlProps,
|
|
44
|
+
}: ThemeSwitcherProps) {
|
|
45
|
+
const [open, setOpen] = useState(false);
|
|
46
|
+
const { themeNames } = useTheme();
|
|
47
|
+
const { theme, polarity } = useThemeTarget();
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Popover
|
|
51
|
+
open={open}
|
|
52
|
+
onOpenChange={setOpen}
|
|
53
|
+
side={side}
|
|
54
|
+
align={align}
|
|
55
|
+
animation={animation}
|
|
56
|
+
htmlProps={{ className: 'zc-theme-switcher__panel', 'data-theme-lead': '' }}
|
|
57
|
+
trigger={
|
|
58
|
+
<Button
|
|
59
|
+
variant="ghost"
|
|
60
|
+
size="sm"
|
|
61
|
+
className={cx('zc-theme-switcher', className)}
|
|
62
|
+
style={style}
|
|
63
|
+
aria-label={`${label}: ${labels?.[theme] ?? themeNames[theme] ?? theme}, ${CAPTIONS[polarity]}`}
|
|
64
|
+
htmlProps={{ 'data-theme-lead': '', ...htmlProps }}
|
|
65
|
+
>
|
|
66
|
+
<span className="zc-theme-switcher__preview zc-theme-switcher__preview--chip" aria-hidden="true">
|
|
67
|
+
<span className="zc-theme-switcher__mini" />
|
|
68
|
+
</span>
|
|
69
|
+
</Button>
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<ThemeGrid labels={labels} label={label} autoFocus onDismiss={() => setOpen(false)} />
|
|
73
|
+
</Popover>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ThemeSwitcher - @zyncat/ui/theme-switcher
|
|
2
|
+
|
|
3
|
+
Group: overlays
|
|
4
|
+
Docs: https://ui.zyncat.app/theme-switcher
|
|
5
|
+
|
|
6
|
+
The theme control: a chip painted in the live palette opens a grid of miniatures, one card per palette and side plus a split System card, each drawn from that theme's real tokens.
|
|
7
|
+
|
|
8
|
+
Needs no props: mount `ZyncatTheme` once for the palettes and the flash-free boot, and the grid lists
|
|
9
|
+
every palette it declared, `default` first. A click applies the theme live and leaves the panel open to
|
|
10
|
+
compare; Escape, Enter, Tab or an outside press closes it and focus returns to the chip. Arrow keys
|
|
11
|
+
move through the grid as a radio group and select as they go - left and right change the side, up and
|
|
12
|
+
down the palette. Each palette shows its own `name`; `labels` overrides that per key, for names that
|
|
13
|
+
come from a translation. `label` is the accessible name, `side` and `align` place the panel,
|
|
14
|
+
`animation` retimes it. The chip is the miniature under the
|
|
15
|
+
page's current tokens, so it is right before hydration and after a change made elsewhere. For the grid
|
|
16
|
+
on its own surface - a settings page, a `Sheet` - reach for `@zyncat/ui/theme-grid`, which is the panel
|
|
17
|
+
body without the popover.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
<ThemeSwitcher align="end" />
|
|
21
|
+
```
|