@teamofsilicons/silicon-ui 0.0.0-stage → 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 +81 -2
- package/check.mjs +236 -0
- package/components/accordion/accordion.d.ts +13 -0
- package/components/accordion/accordion.js +35 -0
- package/components/accordion/accordion.module.css +15 -0
- package/components/action-button/action-button.d.ts +11 -0
- package/components/action-button/action-button.js +57 -0
- package/components/action-button/action-button.module.css +15 -0
- package/components/activity-heatmap/activity-heatmap.d.ts +37 -0
- package/components/activity-heatmap/activity-heatmap.js +303 -0
- package/components/activity-heatmap/activity-heatmap.module.css +83 -0
- package/components/alert/alert.d.ts +13 -0
- package/components/alert/alert.js +79 -0
- package/components/alert/alert.module.css +15 -0
- package/components/animated-counter/animated-counter.d.ts +13 -0
- package/components/animated-counter/animated-counter.js +73 -0
- package/components/animated-counter/animated-counter.module.css +12 -0
- package/components/announcement-bar/announcement-bar.d.ts +53 -0
- package/components/announcement-bar/announcement-bar.js +187 -0
- package/components/announcement-bar/announcement-bar.module.css +60 -0
- package/components/avatar/avatar.d.ts +8 -0
- package/components/avatar/avatar.js +18 -0
- package/components/avatar/avatar.module.css +60 -0
- package/components/avatar-group/avatar-group.d.ts +13 -0
- package/components/avatar-group/avatar-group.js +24 -0
- package/components/avatar-group/avatar-group.module.css +27 -0
- package/components/badge/badge.d.ts +10 -0
- package/components/badge/badge.js +66 -0
- package/components/badge/badge.module.css +52 -0
- package/components/bar-chart/bar-chart.d.ts +32 -0
- package/components/bar-chart/bar-chart.js +327 -0
- package/components/bar-chart/bar-chart.module.css +49 -0
- package/components/billing-toggle/billing-toggle.d.ts +35 -0
- package/components/billing-toggle/billing-toggle.js +83 -0
- package/components/billing-toggle/billing-toggle.module.css +139 -0
- package/components/bottom-sheet/bottom-sheet.d.ts +27 -0
- package/components/bottom-sheet/bottom-sheet.js +386 -0
- package/components/bottom-sheet/bottom-sheet.module.css +69 -0
- package/components/breadcrumb/breadcrumb.d.ts +13 -0
- package/components/breadcrumb/breadcrumb.js +19 -0
- package/components/breadcrumb/breadcrumb.module.css +12 -0
- package/components/brush-chart/brush-chart.d.ts +45 -0
- package/components/brush-chart/brush-chart.js +426 -0
- package/components/brush-chart/brush-chart.module.css +69 -0
- package/components/button/button.d.ts +10 -0
- package/components/button/button.js +97 -0
- package/components/button/button.module.css +39 -0
- package/components/button-group/button-group.d.ts +59 -0
- package/components/button-group/button-group.js +280 -0
- package/components/button-group/button-group.module.css +87 -0
- package/components/button-link/button-link.d.ts +24 -0
- package/components/button-link/button-link.js +11 -0
- package/components/button-link/button-link.module.css +7 -0
- package/components/calendar/calendar.d.ts +22 -0
- package/components/calendar/calendar.js +253 -0
- package/components/calendar/calendar.module.css +51 -0
- package/components/card/card.d.ts +19 -0
- package/components/card/card.js +108 -0
- package/components/card/card.module.css +51 -0
- package/components/card-stack/card-stack.d.ts +34 -0
- package/components/card-stack/card-stack.js +291 -0
- package/components/card-stack/card-stack.module.css +63 -0
- package/components/carousel/carousel.d.ts +28 -0
- package/components/carousel/carousel.js +332 -0
- package/components/carousel/carousel.module.css +42 -0
- package/components/chat-thread/chat-thread.d.ts +135 -0
- package/components/chat-thread/chat-thread.js +406 -0
- package/components/chat-thread/chat-thread.module.css +242 -0
- package/components/checkbox/checkbox.d.ts +7 -0
- package/components/checkbox/checkbox.js +23 -0
- package/components/checkbox/checkbox.module.css +15 -0
- package/components/chip-group/chip-group.d.ts +24 -0
- package/components/chip-group/chip-group.js +196 -0
- package/components/chip-group/chip-group.module.css +38 -0
- package/components/code-block/code-block.d.ts +11 -0
- package/components/code-block/code-block.js +133 -0
- package/components/code-block/code-block.module.css +43 -0
- package/components/color-picker/color-picker.d.ts +40 -0
- package/components/color-picker/color-picker.js +449 -0
- package/components/color-picker/color-picker.module.css +111 -0
- package/components/combobox/combobox.d.ts +19 -0
- package/components/combobox/combobox.js +167 -0
- package/components/combobox/combobox.module.css +28 -0
- package/components/command-palette/command-palette.d.ts +20 -0
- package/components/command-palette/command-palette.js +151 -0
- package/components/command-palette/command-palette.module.css +94 -0
- package/components/comment-thread/comment-thread.d.ts +120 -0
- package/components/comment-thread/comment-thread.js +343 -0
- package/components/comment-thread/comment-thread.module.css +195 -0
- package/components/confirm-morph/confirm-morph.d.ts +65 -0
- package/components/confirm-morph/confirm-morph.js +355 -0
- package/components/confirm-morph/confirm-morph.module.css +146 -0
- package/components/context-menu/context-menu.d.ts +18 -0
- package/components/context-menu/context-menu.js +148 -0
- package/components/context-menu/context-menu.module.css +17 -0
- package/components/copy-button/copy-button.d.ts +10 -0
- package/components/copy-button/copy-button.js +69 -0
- package/components/copy-button/copy-button.module.css +21 -0
- package/components/countdown/countdown.d.ts +31 -0
- package/components/countdown/countdown.js +177 -0
- package/components/countdown/countdown.module.css +49 -0
- package/components/date-picker/date-picker.d.ts +17 -0
- package/components/date-picker/date-picker.js +100 -0
- package/components/date-picker/date-picker.module.css +34 -0
- package/components/date-range-picker/date-range-picker.d.ts +44 -0
- package/components/date-range-picker/date-range-picker.js +534 -0
- package/components/date-range-picker/date-range-picker.module.css +214 -0
- package/components/dialog/dialog.d.ts +11 -0
- package/components/dialog/dialog.js +52 -0
- package/components/dialog/dialog.module.css +36 -0
- package/components/donut-chart/donut-chart.d.ts +46 -0
- package/components/donut-chart/donut-chart.js +382 -0
- package/components/donut-chart/donut-chart.module.css +48 -0
- package/components/drawer/drawer.d.ts +20 -0
- package/components/drawer/drawer.js +111 -0
- package/components/drawer/drawer.module.css +97 -0
- package/components/dropdown-menu/dropdown-menu.d.ts +16 -0
- package/components/dropdown-menu/dropdown-menu.js +39 -0
- package/components/dropdown-menu/dropdown-menu.module.css +38 -0
- package/components/elastic-slider/elastic-slider.d.ts +39 -0
- package/components/elastic-slider/elastic-slider.js +261 -0
- package/components/elastic-slider/elastic-slider.module.css +40 -0
- package/components/empty-state/empty-state.d.ts +12 -0
- package/components/empty-state/empty-state.js +69 -0
- package/components/empty-state/empty-state.module.css +13 -0
- package/components/expandable-card/expandable-card.d.ts +13 -0
- package/components/expandable-card/expandable-card.js +89 -0
- package/components/expandable-card/expandable-card.module.css +22 -0
- package/components/expanding-button-group/expanding-button-group.d.ts +41 -0
- package/components/expanding-button-group/expanding-button-group.js +258 -0
- package/components/expanding-button-group/expanding-button-group.module.css +44 -0
- package/components/expanding-search/expanding-search.d.ts +38 -0
- package/components/expanding-search/expanding-search.js +242 -0
- package/components/expanding-search/expanding-search.module.css +52 -0
- package/components/file-dropzone/file-dropzone.d.ts +44 -0
- package/components/file-dropzone/file-dropzone.js +379 -0
- package/components/file-dropzone/file-dropzone.module.css +115 -0
- package/components/file-upload/file-upload.d.ts +22 -0
- package/components/file-upload/file-upload.js +192 -0
- package/components/file-upload/file-upload.module.css +49 -0
- package/components/filter-toolbar/filter-toolbar.d.ts +48 -0
- package/components/filter-toolbar/filter-toolbar.js +446 -0
- package/components/filter-toolbar/filter-toolbar.module.css +70 -0
- package/components/floating-button-group/floating-button-group.d.ts +51 -0
- package/components/floating-button-group/floating-button-group.js +215 -0
- package/components/floating-button-group/floating-button-group.module.css +74 -0
- package/components/gauge/gauge.d.ts +18 -0
- package/components/gauge/gauge.js +101 -0
- package/components/gauge/gauge.module.css +22 -0
- package/components/hold-to-confirm/hold-to-confirm.d.ts +25 -0
- package/components/hold-to-confirm/hold-to-confirm.js +165 -0
- package/components/hold-to-confirm/hold-to-confirm.module.css +20 -0
- package/components/hover-card/hover-card.d.ts +38 -0
- package/components/hover-card/hover-card.js +145 -0
- package/components/hover-card/hover-card.module.css +20 -0
- package/components/image-compare/image-compare.d.ts +27 -0
- package/components/image-compare/image-compare.js +267 -0
- package/components/image-compare/image-compare.module.css +25 -0
- package/components/in-view-title/in-view-title.d.ts +17 -0
- package/components/in-view-title/in-view-title.js +70 -0
- package/components/in-view-title/in-view-title.module.css +13 -0
- package/components/inline-edit/inline-edit.d.ts +27 -0
- package/components/inline-edit/inline-edit.js +315 -0
- package/components/inline-edit/inline-edit.module.css +73 -0
- package/components/input/input.d.ts +7 -0
- package/components/input/input.js +60 -0
- package/components/input/input.module.css +22 -0
- package/components/json-viewer/json-viewer.d.ts +48 -0
- package/components/json-viewer/json-viewer.js +463 -0
- package/components/json-viewer/json-viewer.module.css +92 -0
- package/components/line-chart/line-chart.d.ts +58 -0
- package/components/line-chart/line-chart.js +383 -0
- package/components/line-chart/line-chart.module.css +60 -0
- package/components/mention-input/mention-input.d.ts +72 -0
- package/components/mention-input/mention-input.js +417 -0
- package/components/mention-input/mention-input.module.css +134 -0
- package/components/metric-card/metric-card.d.ts +8 -0
- package/components/metric-card/metric-card.js +44 -0
- package/components/metric-card/metric-card.module.css +18 -0
- package/components/money-input/money-input.d.ts +48 -0
- package/components/money-input/money-input.js +503 -0
- package/components/money-input/money-input.module.css +77 -0
- package/components/morph-select/morph-select.d.ts +50 -0
- package/components/morph-select/morph-select.js +395 -0
- package/components/morph-select/morph-select.module.css +88 -0
- package/components/multi-select/multi-select.d.ts +18 -0
- package/components/multi-select/multi-select.js +105 -0
- package/components/multi-select/multi-select.module.css +37 -0
- package/components/notification-center/notification-center.d.ts +24 -0
- package/components/notification-center/notification-center.js +146 -0
- package/components/notification-center/notification-center.module.css +79 -0
- package/components/number-field/number-field.d.ts +41 -0
- package/components/number-field/number-field.js +455 -0
- package/components/number-field/number-field.module.css +71 -0
- package/components/otp-input/otp-input.d.ts +13 -0
- package/components/otp-input/otp-input.js +129 -0
- package/components/otp-input/otp-input.module.css +28 -0
- package/components/pagination/pagination.d.ts +7 -0
- package/components/pagination/pagination.js +60 -0
- package/components/pagination/pagination.module.css +16 -0
- package/components/password-field/password-field.d.ts +14 -0
- package/components/password-field/password-field.js +51 -0
- package/components/password-field/password-field.module.css +27 -0
- package/components/password-strength/password-strength.d.ts +107 -0
- package/components/password-strength/password-strength.js +161 -0
- package/components/password-strength/password-strength.module.css +57 -0
- package/components/phone-input/phone-input.d.ts +73 -0
- package/components/phone-input/phone-input.js +612 -0
- package/components/phone-input/phone-input.module.css +98 -0
- package/components/popover/popover.d.ts +6 -0
- package/components/popover/popover.js +19 -0
- package/components/popover/popover.module.css +32 -0
- package/components/progress/progress.d.ts +8 -0
- package/components/progress/progress.js +42 -0
- package/components/progress/progress.module.css +1 -0
- package/components/radio-cards/radio-cards.d.ts +35 -0
- package/components/radio-cards/radio-cards.js +110 -0
- package/components/radio-cards/radio-cards.module.css +84 -0
- package/components/radio-group/radio-group.d.ts +13 -0
- package/components/radio-group/radio-group.js +55 -0
- package/components/radio-group/radio-group.module.css +30 -0
- package/components/resizable-panels/resizable-panels.d.ts +37 -0
- package/components/resizable-panels/resizable-panels.js +338 -0
- package/components/resizable-panels/resizable-panels.module.css +40 -0
- package/components/rich-text-editor/rich-text-editor.d.ts +55 -0
- package/components/rich-text-editor/rich-text-editor.js +1733 -0
- package/components/rich-text-editor/rich-text-editor.module.css +201 -0
- package/components/ridgeline/ridgeline.d.ts +37 -0
- package/components/ridgeline/ridgeline.js +346 -0
- package/components/ridgeline/ridgeline.module.css +58 -0
- package/components/scroll-area/scroll-area.d.ts +40 -0
- package/components/scroll-area/scroll-area.js +153 -0
- package/components/scroll-area/scroll-area.module.css +79 -0
- package/components/search-field/search-field.d.ts +7 -0
- package/components/search-field/search-field.js +20 -0
- package/components/search-field/search-field.module.css +17 -0
- package/components/segmented-control/segmented-control.d.ts +16 -0
- package/components/segmented-control/segmented-control.js +56 -0
- package/components/segmented-control/segmented-control.module.css +15 -0
- package/components/select/select.d.ts +15 -0
- package/components/select/select.js +36 -0
- package/components/select/select.module.css +35 -0
- package/components/shortcut-recorder/shortcut-recorder.d.ts +108 -0
- package/components/shortcut-recorder/shortcut-recorder.js +380 -0
- package/components/shortcut-recorder/shortcut-recorder.module.css +85 -0
- package/components/signature-pad/signature-pad.d.ts +72 -0
- package/components/signature-pad/signature-pad.js +450 -0
- package/components/signature-pad/signature-pad.module.css +84 -0
- package/components/skeleton/skeleton.d.ts +13 -0
- package/components/skeleton/skeleton.js +53 -0
- package/components/skeleton/skeleton.module.css +11 -0
- package/components/slider/slider.d.ts +45 -0
- package/components/slider/slider.js +347 -0
- package/components/slider/slider.module.css +45 -0
- package/components/slope-chart/slope-chart.d.ts +38 -0
- package/components/slope-chart/slope-chart.js +183 -0
- package/components/slope-chart/slope-chart.module.css +51 -0
- package/components/slot-text/slot-text.d.ts +26 -0
- package/components/slot-text/slot-text.js +119 -0
- package/components/slot-text/slot-text.module.css +19 -0
- package/components/sortable-data-table/sortable-data-table.d.ts +38 -0
- package/components/sortable-data-table/sortable-data-table.js +240 -0
- package/components/sortable-data-table/sortable-data-table.module.css +116 -0
- package/components/sparkline/sparkline.d.ts +19 -0
- package/components/sparkline/sparkline.js +239 -0
- package/components/sparkline/sparkline.module.css +26 -0
- package/components/split-button/split-button.d.ts +19 -0
- package/components/split-button/split-button.js +33 -0
- package/components/split-button/split-button.module.css +51 -0
- package/components/stepper/stepper.d.ts +36 -0
- package/components/stepper/stepper.js +108 -0
- package/components/stepper/stepper.module.css +74 -0
- package/components/streamgraph/streamgraph.d.ts +51 -0
- package/components/streamgraph/streamgraph.js +376 -0
- package/components/streamgraph/streamgraph.module.css +55 -0
- package/components/swipe-actions/swipe-actions.d.ts +35 -0
- package/components/swipe-actions/swipe-actions.js +330 -0
- package/components/swipe-actions/swipe-actions.module.css +64 -0
- package/components/switch/switch.d.ts +7 -0
- package/components/switch/switch.js +45 -0
- package/components/switch/switch.module.css +12 -0
- package/components/tabs/tabs.d.ts +8 -0
- package/components/tabs/tabs.js +138 -0
- package/components/tabs/tabs.module.css +27 -0
- package/components/tag-input/tag-input.d.ts +15 -0
- package/components/tag-input/tag-input.js +150 -0
- package/components/tag-input/tag-input.module.css +34 -0
- package/components/text-morph/text-morph.d.ts +13 -0
- package/components/text-morph/text-morph.js +69 -0
- package/components/text-morph/text-morph.module.css +8 -0
- package/components/text-reveal/text-reveal.d.ts +14 -0
- package/components/text-reveal/text-reveal.js +20 -0
- package/components/text-reveal/text-reveal.module.css +13 -0
- package/components/text-shimmer/text-shimmer.d.ts +18 -0
- package/components/text-shimmer/text-shimmer.js +90 -0
- package/components/text-shimmer/text-shimmer.module.css +9 -0
- package/components/textarea/textarea.d.ts +7 -0
- package/components/textarea/textarea.js +56 -0
- package/components/textarea/textarea.module.css +22 -0
- package/components/theme-switch/theme-switch.d.ts +11 -0
- package/components/theme-switch/theme-switch.js +37 -0
- package/components/theme-switch/theme-switch.module.css +31 -0
- package/components/time-picker/time-picker.d.ts +13 -0
- package/components/time-picker/time-picker.js +95 -0
- package/components/time-picker/time-picker.module.css +23 -0
- package/components/timeline/timeline.d.ts +47 -0
- package/components/timeline/timeline.js +171 -0
- package/components/timeline/timeline.module.css +51 -0
- package/components/toast/toast.d.ts +8 -0
- package/components/toast/toast.js +118 -0
- package/components/toast/toast.module.css +100 -0
- package/components/toast-stack/toast-stack.d.ts +57 -0
- package/components/toast-stack/toast-stack.js +399 -0
- package/components/toast-stack/toast-stack.module.css +61 -0
- package/components/tooltip/tooltip.d.ts +8 -0
- package/components/tooltip/tooltip.js +62 -0
- package/components/tooltip/tooltip.module.css +18 -0
- package/components/tree-view/tree-view.d.ts +17 -0
- package/components/tree-view/tree-view.js +147 -0
- package/components/tree-view/tree-view.module.css +22 -0
- package/components/treemap/treemap.d.ts +35 -0
- package/components/treemap/treemap.js +375 -0
- package/components/treemap/treemap.module.css +59 -0
- package/components/usage-meter/usage-meter.d.ts +24 -0
- package/components/usage-meter/usage-meter.js +296 -0
- package/components/usage-meter/usage-meter.module.css +61 -0
- package/components/user-menu/user-menu.d.ts +62 -0
- package/components/user-menu/user-menu.js +316 -0
- package/components/user-menu/user-menu.module.css +97 -0
- package/components/waffle-chart/waffle-chart.d.ts +39 -0
- package/components/waffle-chart/waffle-chart.js +244 -0
- package/components/waffle-chart/waffle-chart.module.css +52 -0
- package/components.json +1330 -0
- package/eslint.js +53 -0
- package/lib/escape.d.ts +19 -0
- package/lib/escape.js +50 -0
- package/lib/media.d.ts +353 -0
- package/lib/media.js +65 -0
- package/lib/menu-highlight.d.ts +28 -0
- package/lib/menu-highlight.js +43 -0
- package/lib/motion-tokens.d.ts +60 -0
- package/lib/motion-tokens.js +25 -0
- package/lib/return-focus.d.ts +9 -0
- package/lib/return-focus.js +53 -0
- package/lib/silicon-provider.d.ts +60 -0
- package/lib/silicon-provider.js +47 -0
- package/lib/use-copy-feedback.d.ts +8 -0
- package/lib/use-copy-feedback.js +36 -0
- package/lib/use-today.d.ts +2 -0
- package/lib/use-today.js +29 -0
- package/package.json +76 -4
- package/styles.css +218 -0
- package/styles.css.d.ts +1 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
6
|
+
import { ChevronDown, LoaderCircle, LogOut, Monitor, Moon, Sun, SunMoon } from "lucide-react";
|
|
7
|
+
import { motionTokens } from "../../lib/motion-tokens.js";
|
|
8
|
+
import styles from "./user-menu.module.css";
|
|
9
|
+
/** Statuses in menu order. Each one has its own dot shape as well as color: solid, barred, or hollow. */
|
|
10
|
+
export const userStatuses = [
|
|
11
|
+
{ value: "available", label: "Available" },
|
|
12
|
+
{ value: "busy", label: "Busy" },
|
|
13
|
+
{ value: "away", label: "Away" },
|
|
14
|
+
];
|
|
15
|
+
const themes = [
|
|
16
|
+
{ value: "light", label: "Light", icon: _jsx(Sun, { size: 14, strokeWidth: 1.75, "aria-hidden": "true" }) },
|
|
17
|
+
{ value: "dark", label: "Dark", icon: _jsx(Moon, { size: 14, strokeWidth: 1.75, "aria-hidden": "true" }) },
|
|
18
|
+
{ value: "system", label: "System", icon: _jsx(Monitor, { size: 14, strokeWidth: 1.75, "aria-hidden": "true" }) },
|
|
19
|
+
];
|
|
20
|
+
const compactQuery = "(max-width: 639px)";
|
|
21
|
+
const subscribeCompact = (change) => { const query = window.matchMedia(compactQuery); query.addEventListener("change", change); return () => query.removeEventListener("change", change); };
|
|
22
|
+
const subscribeNothing = () => () => { };
|
|
23
|
+
const statusLabel = (status) => userStatuses.find(option => option.value === status)?.label ?? status;
|
|
24
|
+
const enter = [...motionTokens.ease.enter];
|
|
25
|
+
const standard = [...motionTokens.ease.standard];
|
|
26
|
+
const exitEase = [0.4, 0, 1, 1];
|
|
27
|
+
/** The panel grows out of the trigger on a critically damped spring; rows follow a beat later. Closing is a short fade. */
|
|
28
|
+
const panelMotion = {
|
|
29
|
+
closed: { opacity: 0, scale: .94 },
|
|
30
|
+
open: { opacity: 1, scale: 1, transition: { type: "spring", visualDuration: .3, bounce: 0, opacity: { duration: motionTokens.duration.fast, ease: enter }, delayChildren: .03, staggerChildren: .016 } },
|
|
31
|
+
exit: { opacity: 0, scale: .97, transition: { duration: motionTokens.duration.instant, ease: exitEase } },
|
|
32
|
+
};
|
|
33
|
+
const sheetMotion = {
|
|
34
|
+
closed: { y: "100%" },
|
|
35
|
+
open: { y: 0, transition: { ...motionTokens.spring.smooth, visualDuration: .36, delayChildren: .06, staggerChildren: .02 } },
|
|
36
|
+
exit: { y: "100%", transition: { duration: .22, ease: exitEase } },
|
|
37
|
+
};
|
|
38
|
+
const stillMotion = { closed: { opacity: 0 }, open: { opacity: 1, transition: { duration: motionTokens.duration.instant } }, exit: { opacity: 0, transition: { duration: motionTokens.duration.instant } } };
|
|
39
|
+
const rowMotion = { closed: { opacity: 0, y: 3 }, open: { opacity: 1, y: 0, transition: { duration: .2, ease: enter } } };
|
|
40
|
+
/** A presence mark that morphs between statuses: the color crossfades while a hole opens for away and a bar slides in for busy. */
|
|
41
|
+
export function PresenceDot({ status, className }) {
|
|
42
|
+
return _jsx("span", { className: [styles.dot, className].filter(Boolean).join(" "), "data-status": status, "aria-hidden": "true" });
|
|
43
|
+
}
|
|
44
|
+
function Portrait({ user }) {
|
|
45
|
+
const [failed, setFailed] = useState();
|
|
46
|
+
if (!user.avatarSrc || failed === user.avatarSrc) {
|
|
47
|
+
const initials = user.name.trim().split(/\s+/).slice(0, 2).map(part => part[0]?.toUpperCase()).join("");
|
|
48
|
+
return _jsx("span", { className: `${styles.portrait} ${styles.initials}`, "aria-hidden": "true", children: initials });
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line @next/next/no-img-element -- registry components stay framework agnostic; pass optimized URLs as avatarSrc and avatarSrcSet.
|
|
51
|
+
return _jsx("img", { className: styles.portrait, src: user.avatarSrc, srcSet: user.avatarSrcSet, alt: "", decoding: "async", draggable: false, onError: () => setFailed(user.avatarSrc) });
|
|
52
|
+
}
|
|
53
|
+
function Face({ user, status, size }) {
|
|
54
|
+
return _jsxs("span", { className: styles.face, "data-size": size, children: [_jsx(Portrait, { user: user }), status && _jsx(PresenceDot, { status: status })] });
|
|
55
|
+
}
|
|
56
|
+
/** Changing text rises out of a small blur while the old text lifts away. */
|
|
57
|
+
function Rise({ text, reduced }) {
|
|
58
|
+
return _jsx(AnimatePresence, { mode: "popLayout", initial: false, children: _jsx(motion.span, { className: styles.rise, initial: reduced ? { opacity: 0 } : { opacity: 0, y: "0.35em", filter: `blur(${motionTokens.blur.subtle}px)` }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, exit: reduced ? { opacity: 0, transition: { duration: 0 } } : { opacity: 0, y: "-0.35em", filter: `blur(${motionTokens.blur.subtle}px)`, transition: { duration: motionTokens.duration.fast, ease: standard } }, transition: reduced ? { duration: 0 } : { duration: motionTokens.duration.standard, ease: enter }, children: text }, text) });
|
|
59
|
+
}
|
|
60
|
+
function Keys({ keys }) {
|
|
61
|
+
return _jsx("kbd", { className: styles.keys, "aria-hidden": "true", children: keys.map((key, index) => _jsx("kbd", { className: styles.key, children: key }, `${key}-${index}`)) });
|
|
62
|
+
}
|
|
63
|
+
/** A compact inline switch. It is one stop in the menu: up and down pass over it, left and right choose within it. */
|
|
64
|
+
function Segmented({ label, icon, value, options, onChange, variants }) {
|
|
65
|
+
const index = Math.max(0, options.findIndex(option => option.value === value));
|
|
66
|
+
return _jsxs(motion.div, { className: styles.row, "data-stop": "group", "data-label": label, variants: variants, children: [_jsx("span", { className: styles.icon, "aria-hidden": "true", children: icon }), _jsx("span", { className: styles.rowLabel, "aria-hidden": "true", children: label }), _jsxs("div", { className: styles.segments, role: "group", "aria-label": label, style: { "--index": index, "--count": options.length }, children: [_jsx("span", { className: styles.thumb, "aria-hidden": "true" }), options.map(option => _jsx("button", { type: "button", role: "menuitemradio", tabIndex: -1, "aria-checked": option.value === value, "aria-label": option.label, title: option.label, className: styles.segment, onClick: () => onChange(option.value), children: option.icon }, option.value))] })] });
|
|
67
|
+
}
|
|
68
|
+
const getStops = (root) => Array.from(root?.querySelectorAll("[data-stop]") ?? []);
|
|
69
|
+
function focusStop(stop) {
|
|
70
|
+
if (!stop)
|
|
71
|
+
return;
|
|
72
|
+
const target = stop.dataset.stop === "group" ? stop.querySelector('[aria-checked="true"]') ?? stop.querySelector("button") : stop;
|
|
73
|
+
target?.focus({ preventScroll: true });
|
|
74
|
+
}
|
|
75
|
+
export function UserMenu({ user, status: statusProp, defaultStatus = "available", onStatusChange, theme: themeProp, defaultTheme = "system", onThemeChange, showTheme = true, items = [], onSignOut, signOutKeys, align = "end", showName = false, open: openProp, defaultOpen = false, onOpenChange, portal = true, ref, className }) {
|
|
76
|
+
const id = useId();
|
|
77
|
+
const menuId = `${id}-menu`;
|
|
78
|
+
const triggerId = `${id}-trigger`;
|
|
79
|
+
const reduced = !!useReducedMotion();
|
|
80
|
+
const hydrated = useSyncExternalStore(subscribeNothing, () => true, () => false);
|
|
81
|
+
const compact = useSyncExternalStore(subscribeCompact, () => window.matchMedia(compactQuery).matches, () => false);
|
|
82
|
+
const [innerOpen, setInnerOpen] = useState(defaultOpen);
|
|
83
|
+
const [innerStatus, setInnerStatus] = useState(defaultStatus);
|
|
84
|
+
const [innerTheme, setInnerTheme] = useState(defaultTheme);
|
|
85
|
+
const [signingOut, setSigningOut] = useState(false);
|
|
86
|
+
const [highlight, setHighlight] = useState(null);
|
|
87
|
+
const open = openProp ?? innerOpen;
|
|
88
|
+
const showStatus = statusProp !== undefined || onStatusChange !== undefined;
|
|
89
|
+
const status = statusProp ?? innerStatus;
|
|
90
|
+
const theme = themeProp ?? innerTheme;
|
|
91
|
+
const rootRef = useRef(null);
|
|
92
|
+
const triggerRef = useRef(null);
|
|
93
|
+
const surfaceRef = useRef(null);
|
|
94
|
+
const listRef = useRef(null);
|
|
95
|
+
const reason = useRef(null);
|
|
96
|
+
const typed = useRef({ text: "", timer: 0 });
|
|
97
|
+
const mounted = useRef(true);
|
|
98
|
+
const pending = useRef(false);
|
|
99
|
+
const sheet = hydrated && compact;
|
|
100
|
+
const inline = !portal && !sheet;
|
|
101
|
+
useEffect(() => { mounted.current = true; const current = typed.current; return () => { mounted.current = false; window.clearTimeout(current.timer); }; }, []);
|
|
102
|
+
function setTriggerRef(node) {
|
|
103
|
+
triggerRef.current = node;
|
|
104
|
+
if (typeof ref === "function")
|
|
105
|
+
ref(node);
|
|
106
|
+
else if (ref)
|
|
107
|
+
ref.current = node;
|
|
108
|
+
}
|
|
109
|
+
function setOpen(next, why = null) {
|
|
110
|
+
reason.current = next ? why : null;
|
|
111
|
+
if (next)
|
|
112
|
+
setSigningOut(pending.current);
|
|
113
|
+
setHighlight(null);
|
|
114
|
+
setInnerOpen(next);
|
|
115
|
+
onOpenChange?.(next);
|
|
116
|
+
}
|
|
117
|
+
function close(returnFocus) {
|
|
118
|
+
setOpen(false);
|
|
119
|
+
if (returnFocus)
|
|
120
|
+
triggerRef.current?.focus({ preventScroll: true });
|
|
121
|
+
}
|
|
122
|
+
// Focus moves in only when a person opened the menu, so a menu that starts open never steals focus or scrolls the page.
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!open)
|
|
125
|
+
return;
|
|
126
|
+
const why = reason.current;
|
|
127
|
+
reason.current = null;
|
|
128
|
+
if (!why)
|
|
129
|
+
return;
|
|
130
|
+
const frame = requestAnimationFrame(() => {
|
|
131
|
+
const stops = getStops(listRef.current);
|
|
132
|
+
if (why === "first")
|
|
133
|
+
focusStop(stops[0]);
|
|
134
|
+
else if (why === "last")
|
|
135
|
+
focusStop(stops.at(-1));
|
|
136
|
+
else
|
|
137
|
+
surfaceRef.current?.focus({ preventScroll: true });
|
|
138
|
+
});
|
|
139
|
+
return () => cancelAnimationFrame(frame);
|
|
140
|
+
}, [open, sheet]);
|
|
141
|
+
// The panel is placed against the trigger and scales from the avatar's center, flipping above when there is no room below.
|
|
142
|
+
useLayoutEffect(() => {
|
|
143
|
+
if (!open || sheet)
|
|
144
|
+
return;
|
|
145
|
+
const place = () => {
|
|
146
|
+
const panel = surfaceRef.current, trigger = triggerRef.current;
|
|
147
|
+
if (!panel || !trigger)
|
|
148
|
+
return;
|
|
149
|
+
const rect = trigger.getBoundingClientRect();
|
|
150
|
+
const width = panel.offsetWidth, height = panel.offsetHeight;
|
|
151
|
+
let left, top;
|
|
152
|
+
if (inline) {
|
|
153
|
+
const root = rootRef.current?.getBoundingClientRect();
|
|
154
|
+
left = (root?.left ?? 0) + panel.offsetLeft;
|
|
155
|
+
top = (root?.top ?? 0) + panel.offsetTop;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const wanted = align === "start" ? rect.left : align === "center" ? rect.left + rect.width / 2 - width / 2 : rect.right - width;
|
|
159
|
+
left = Math.min(Math.max(12, wanted), window.innerWidth - width - 12);
|
|
160
|
+
const below = rect.bottom + 8;
|
|
161
|
+
top = below + height > window.innerHeight - 12 && rect.top - 8 - height > 12 ? rect.top - 8 - height : below;
|
|
162
|
+
panel.style.left = `${left}px`;
|
|
163
|
+
panel.style.top = `${top}px`;
|
|
164
|
+
}
|
|
165
|
+
const faceCenter = rect.left + Math.min(rect.width, 40) / 2;
|
|
166
|
+
const originX = align === "end" && rect.width > 40 ? rect.right - 20 - left : faceCenter - left;
|
|
167
|
+
panel.style.setProperty("--origin-x", `${Math.min(Math.max(0, originX), width)}px`);
|
|
168
|
+
panel.style.setProperty("--origin-y", top < rect.top ? `${height}px` : "0px");
|
|
169
|
+
};
|
|
170
|
+
place();
|
|
171
|
+
if (inline)
|
|
172
|
+
return;
|
|
173
|
+
window.addEventListener("resize", place);
|
|
174
|
+
window.addEventListener("scroll", place, true);
|
|
175
|
+
return () => { window.removeEventListener("resize", place); window.removeEventListener("scroll", place, true); };
|
|
176
|
+
}, [open, sheet, inline, align]);
|
|
177
|
+
// Outside presses close the panel. The sheet has its own scrim.
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (!open || sheet)
|
|
180
|
+
return;
|
|
181
|
+
const onPointerDown = (event) => {
|
|
182
|
+
const target = event.target;
|
|
183
|
+
if (surfaceRef.current?.contains(target) || triggerRef.current?.contains(target))
|
|
184
|
+
return;
|
|
185
|
+
reason.current = null;
|
|
186
|
+
setHighlight(null);
|
|
187
|
+
setInnerOpen(false);
|
|
188
|
+
onOpenChange?.(false);
|
|
189
|
+
};
|
|
190
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
191
|
+
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
|
192
|
+
}, [open, sheet, onOpenChange]);
|
|
193
|
+
// The page behind the sheet stays put.
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!open || !sheet)
|
|
196
|
+
return;
|
|
197
|
+
const root = document.documentElement;
|
|
198
|
+
const previous = root.style.overflow;
|
|
199
|
+
root.style.overflow = "hidden";
|
|
200
|
+
return () => { root.style.overflow = previous; };
|
|
201
|
+
}, [open, sheet]);
|
|
202
|
+
function changeStatus(value) { setInnerStatus(value); onStatusChange?.(value); }
|
|
203
|
+
function changeTheme(value) { setInnerTheme(value); onThemeChange?.(value); }
|
|
204
|
+
function signOut() {
|
|
205
|
+
if (pending.current)
|
|
206
|
+
return;
|
|
207
|
+
const result = onSignOut?.();
|
|
208
|
+
if (!result || typeof result.then !== "function") {
|
|
209
|
+
close(true);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// Async sign out keeps the menu open with its progress on the item, then closes once it settles.
|
|
213
|
+
pending.current = true;
|
|
214
|
+
setSigningOut(true);
|
|
215
|
+
const done = () => { pending.current = false; if (mounted.current)
|
|
216
|
+
close(false); };
|
|
217
|
+
result.then(done, done);
|
|
218
|
+
}
|
|
219
|
+
function onListFocus(event) {
|
|
220
|
+
const stop = event.target instanceof HTMLElement ? event.target.closest("[data-stop]") : null;
|
|
221
|
+
if (!stop) {
|
|
222
|
+
setHighlight(null);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
setHighlight(current => ({ top: stop.offsetTop, height: stop.offsetHeight, tone: stop.dataset.tone, glide: current !== null }));
|
|
226
|
+
}
|
|
227
|
+
// Focus follows a mouse or pen, so the keyboard carries on from wherever the pointer left the highlight.
|
|
228
|
+
function onItemPointerMove(event) {
|
|
229
|
+
if (event.pointerType === "touch")
|
|
230
|
+
return;
|
|
231
|
+
if (document.activeElement !== event.currentTarget)
|
|
232
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
233
|
+
}
|
|
234
|
+
// The inline switches are not rows, so the pointer over them releases the highlight instead of dragging it along.
|
|
235
|
+
function onListPointerMove(event) {
|
|
236
|
+
if (event.pointerType === "touch" || !highlight)
|
|
237
|
+
return;
|
|
238
|
+
const group = event.target instanceof HTMLElement ? event.target.closest('[data-stop="group"]') : null;
|
|
239
|
+
if (!group || group.contains(document.activeElement))
|
|
240
|
+
return;
|
|
241
|
+
setHighlight(null);
|
|
242
|
+
surfaceRef.current?.focus({ preventScroll: true });
|
|
243
|
+
}
|
|
244
|
+
function onListPointerLeave(event) {
|
|
245
|
+
if (event.pointerType === "touch")
|
|
246
|
+
return;
|
|
247
|
+
setHighlight(null);
|
|
248
|
+
surfaceRef.current?.focus({ preventScroll: true });
|
|
249
|
+
}
|
|
250
|
+
function onKeyDown(event) {
|
|
251
|
+
const stops = getStops(listRef.current);
|
|
252
|
+
const active = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
253
|
+
const current = active?.closest("[data-stop]") ?? null;
|
|
254
|
+
const index = current ? stops.indexOf(current) : -1;
|
|
255
|
+
const step = (to) => { event.preventDefault(); focusStop(to); };
|
|
256
|
+
switch (event.key) {
|
|
257
|
+
case "ArrowDown": return step(stops[(index + 1) % stops.length]);
|
|
258
|
+
case "ArrowUp": return step(stops[index <= 0 ? stops.length - 1 : index - 1]);
|
|
259
|
+
case "Home": return step(stops[0]);
|
|
260
|
+
case "End": return step(stops.at(-1));
|
|
261
|
+
case "Escape":
|
|
262
|
+
case "Tab":
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
return close(true);
|
|
265
|
+
case "ArrowLeft":
|
|
266
|
+
case "ArrowRight": {
|
|
267
|
+
if (current?.dataset.stop !== "group")
|
|
268
|
+
return;
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
const segments = Array.from(current.querySelectorAll('[role="menuitemradio"]'));
|
|
271
|
+
const at = Math.max(0, segments.findIndex(segment => segment.getAttribute("aria-checked") === "true"));
|
|
272
|
+
const next = segments[(at + (event.key === "ArrowRight" ? 1 : -1) + segments.length) % segments.length];
|
|
273
|
+
next?.focus({ preventScroll: true });
|
|
274
|
+
next?.click();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey || event.key === " ")
|
|
279
|
+
return;
|
|
280
|
+
// Typeahead: letters jump to the next row whose label starts with what was typed.
|
|
281
|
+
const memory = typed.current;
|
|
282
|
+
window.clearTimeout(memory.timer);
|
|
283
|
+
memory.text += event.key.toLowerCase();
|
|
284
|
+
memory.timer = window.setTimeout(() => { memory.text = ""; }, 500);
|
|
285
|
+
const ordered = [...stops.slice(index + 1), ...stops.slice(0, index + 1)];
|
|
286
|
+
const search = memory.text.length > 1 && current?.dataset.label?.toLowerCase().startsWith(memory.text) ? [current] : ordered;
|
|
287
|
+
const match = search.find(stop => stop.dataset.label?.toLowerCase().startsWith(memory.text));
|
|
288
|
+
if (match)
|
|
289
|
+
step(match);
|
|
290
|
+
}
|
|
291
|
+
function onTriggerClick(event) {
|
|
292
|
+
if (open) {
|
|
293
|
+
close(false);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
setOpen(true, event.detail === 0 ? "first" : "pointer");
|
|
297
|
+
}
|
|
298
|
+
function onTriggerKeyDown(event) {
|
|
299
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
|
|
300
|
+
return;
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
setOpen(true, event.key === "ArrowDown" ? "first" : "last");
|
|
303
|
+
}
|
|
304
|
+
function onDragEnd(_, info) {
|
|
305
|
+
if (info.offset.y > 80 || info.velocity.y > 500)
|
|
306
|
+
close(true);
|
|
307
|
+
}
|
|
308
|
+
const glide = highlight?.glide && !reduced ? motionTokens.spring.snappy : { duration: 0 };
|
|
309
|
+
const row = reduced ? undefined : rowMotion;
|
|
310
|
+
const menuProps = { id: menuId, role: "menu", "aria-labelledby": triggerId, tabIndex: -1, onKeyDown };
|
|
311
|
+
const content = _jsxs(_Fragment, { children: [_jsxs(motion.div, { className: styles.header, variants: row, children: [_jsx(Face, { user: user, status: showStatus ? status : undefined, size: "md" }), _jsxs("div", { className: styles.identity, children: [_jsxs("div", { className: styles.nameRow, children: [_jsx("span", { className: styles.name, children: user.name }), user.plan && _jsx("span", { className: styles.plan, children: user.plan })] }), _jsx("span", { className: styles.email, title: user.email, children: user.email })] })] }), _jsxs("div", { ref: listRef, className: styles.list, onFocus: onListFocus, onPointerMove: onListPointerMove, onPointerLeave: onListPointerLeave, children: [_jsx(motion.span, { className: styles.highlight, "data-tone": highlight?.tone, "aria-hidden": "true", initial: false, animate: highlight ? { y: highlight.top, height: highlight.height, opacity: 1 } : { opacity: 0 }, transition: { default: glide, opacity: { duration: reduced ? 0 : motionTokens.duration.instant } } }), items.length > 0 && _jsxs(_Fragment, { children: [_jsx("div", { className: styles.separator, role: "separator" }), items.map(item => _jsxs(motion.button, { type: "button", role: "menuitem", tabIndex: -1, className: styles.item, "data-stop": "item", "data-label": item.label, variants: row, onPointerMove: onItemPointerMove, onClick: () => { close(true); item.onSelect?.(); }, children: [_jsx("span", { className: styles.icon, "aria-hidden": "true", children: item.icon }), _jsx("span", { className: styles.itemLabel, children: item.label }), item.keys && _jsx(Keys, { keys: item.keys })] }, item.label))] }), (showTheme || showStatus) && _jsxs(_Fragment, { children: [_jsx("div", { className: styles.separator, role: "separator" }), showStatus && _jsx(Segmented, { label: "Status", icon: _jsx(PresenceDot, { status: status }), value: status, onChange: changeStatus, options: userStatuses.map(option => ({ ...option, icon: _jsx(PresenceDot, { status: option.value }) })), variants: row }), showTheme && _jsx(Segmented, { label: "Theme", icon: _jsx(SunMoon, { size: 16, strokeWidth: 1.75 }), value: theme, onChange: changeTheme, options: themes, variants: row })] }), _jsx("div", { className: styles.separator, role: "separator" }), _jsxs(motion.button, { type: "button", role: "menuitem", tabIndex: -1, className: styles.item, "data-stop": "item", "data-tone": "danger", "data-label": "Sign out", variants: row, "aria-busy": signingOut || undefined, onPointerMove: onItemPointerMove, onClick: signOut, children: [_jsx("span", { className: styles.icon, "aria-hidden": "true", children: signingOut ? _jsx(LoaderCircle, { className: styles.spinner, size: 16, strokeWidth: 1.75 }) : _jsx(LogOut, { size: 16, strokeWidth: 1.75 }) }), _jsx("span", { className: styles.itemLabel, children: _jsx(Rise, { text: signingOut ? "Signing out" : "Sign out", reduced: reduced }) }), signOutKeys && _jsx(Keys, { keys: signOutKeys })] })] })] });
|
|
312
|
+
const panel = _jsx(AnimatePresence, { children: open && !sheet && _jsx(motion.div, { ref: surfaceRef, ...menuProps, className: styles.panel, "data-inline": inline || undefined, "data-align": align, variants: reduced ? stillMotion : panelMotion, initial: "closed", animate: "open", exit: "exit", children: content }, "panel") });
|
|
313
|
+
const bottomSheet = _jsxs(AnimatePresence, { children: [open && sheet && _jsx(motion.div, { className: styles.scrim, "aria-hidden": "true", initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: reduced ? .1 : .2, ease: standard }, onClick: () => close(true) }, "scrim"), open && sheet && _jsxs(motion.div, { ref: surfaceRef, ...menuProps, className: `${styles.panel} ${styles.sheet}`, "aria-modal": "true", variants: reduced ? stillMotion : sheetMotion, initial: "closed", animate: "open", exit: "exit", drag: reduced ? false : "y", dragConstraints: { top: 0, bottom: 0 }, dragElastic: { top: .04, bottom: .9 }, dragMomentum: false, onDragEnd: onDragEnd, children: [_jsx("span", { className: styles.handle, "aria-hidden": "true" }), content] }, "sheet")] });
|
|
314
|
+
return _jsxs("span", { ref: rootRef, className: styles.root, children: [_jsxs("button", { ref: setTriggerRef, id: triggerId, type: "button", className: [styles.trigger, className].filter(Boolean).join(" "), "data-state": open ? "open" : "closed", "data-name": showName || undefined, "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": open ? menuId : undefined, "aria-label": `Account menu, ${user.name}, ${user.name.trim().split(/\s+/).slice(0, 2).map(part => part[0]?.toUpperCase()).join("")}${showStatus ? `, ${statusLabel(status)}` : ""}`, onClick: onTriggerClick, onKeyDown: onTriggerKeyDown, children: [_jsx(Face, { user: user, status: showStatus ? status : undefined, size: "sm" }), showName && _jsxs(_Fragment, { children: [_jsx("span", { className: styles.triggerName, children: user.name }), _jsx(ChevronDown, { className: styles.chevron, size: 16, strokeWidth: 1.75, "aria-hidden": "true" })] })] }), sheet ? createPortal(bottomSheet, document.body) : inline ? panel : hydrated ? createPortal(panel, document.body) : null] });
|
|
315
|
+
}
|
|
316
|
+
export default UserMenu;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
.root { position: relative; display: inline-flex; flex: none; vertical-align: middle; }
|
|
2
|
+
|
|
3
|
+
/* The trigger anchors the menu, so it answers hover and press with color, never with scale. */
|
|
4
|
+
.trigger { --presence-surface: var(--user-menu-surface, var(--surface)); position: relative; display: inline-flex; height: 40px; flex: none; align-items: center; gap: var(--space-related); margin: 0; padding: 4px; border: 0; border-radius: var(--radius-full); corner-shape: round; background: transparent; color: var(--foreground); font: inherit; font-family: var(--font-body); font-size: var(--text-sm); letter-spacing: var(--tracking-body); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color var(--duration-fast) var(--ease-standard); }
|
|
5
|
+
.trigger[data-name] { padding-right: 10px; }
|
|
6
|
+
@media (hover: hover) and (pointer: fine) { .trigger:hover { --presence-surface: var(--surface-muted); background: var(--surface-muted); } }
|
|
7
|
+
.trigger[data-state="open"] { --presence-surface: var(--surface-muted); background: var(--surface-muted); }
|
|
8
|
+
.trigger:active { --presence-surface: color-mix(in oklab, var(--surface-muted), var(--foreground) 8%); background: color-mix(in oklab, var(--surface-muted), var(--foreground) 8%); }
|
|
9
|
+
.triggerName { max-width: 11rem; overflow: hidden; font-weight: 500; line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
|
|
10
|
+
.chevron { flex: none; margin-left: -2px; color: var(--text-muted); transition: transform var(--duration-spring) var(--ease-spring), color var(--duration-fast) var(--ease-standard); }
|
|
11
|
+
.trigger:hover .chevron, .trigger[data-state="open"] .chevron { color: var(--foreground); }
|
|
12
|
+
.trigger[data-state="open"] .chevron { transform: rotate(180deg); }
|
|
13
|
+
@media (max-width: 639px) {
|
|
14
|
+
.trigger[data-name] { padding-right: 4px; }
|
|
15
|
+
.triggerName, .chevron { display: none; }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.face { position: relative; display: inline-grid; width: var(--face-size); height: var(--face-size); flex: none; }
|
|
19
|
+
.face[data-size="sm"] { --face-size: 32px; --dot-size: 11px; }
|
|
20
|
+
.face[data-size="md"] { --face-size: 34px; --dot-size: 10px; }
|
|
21
|
+
.portrait { display: block; width: 100%; height: 100%; border-radius: var(--avatar-radius); corner-shape: var(--avatar-corner-shape); background: var(--surface-muted); object-fit: cover; object-position: 50% 15%; outline: 1px solid color-mix(in oklab, var(--foreground) 9%, transparent); outline-offset: -1px; user-select: none; }
|
|
22
|
+
.initials { display: grid; place-items: center; color: var(--text-secondary); font-size: calc(var(--face-size) * .36); font-weight: 500; line-height: 1; }
|
|
23
|
+
.face .dot { position: absolute; right: -1px; bottom: -1px; box-shadow: 0 0 0 2px var(--presence-surface, var(--surface)); }
|
|
24
|
+
|
|
25
|
+
/* One mark, three shapes: solid for available, a bar for busy, a ring for away. Color and shape change together, so status never rests on color alone. */
|
|
26
|
+
.dot { --dot-color: var(--success); position: relative; display: inline-block; width: var(--dot-size, 10px); height: var(--dot-size, 10px); flex: none; border-radius: var(--radius-full); corner-shape: round; background: var(--dot-color); transition: background-color var(--duration-standard) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard); }
|
|
27
|
+
.dot::before, .dot::after { content: ""; position: absolute; inset: 0; margin: auto; background: var(--presence-surface, var(--surface)); transition: transform var(--duration-spring) var(--ease-spring), background-color var(--duration-fast) var(--ease-standard); }
|
|
28
|
+
.dot::before { width: 46%; height: 46%; border-radius: var(--radius-full); corner-shape: round; transform: scale(0); }
|
|
29
|
+
.dot::after { width: 58%; height: 22%; min-height: 1.5px; border-radius: var(--radius-full); corner-shape: round; transform: scaleX(0); }
|
|
30
|
+
.dot[data-status="busy"] { --dot-color: var(--danger); }
|
|
31
|
+
.dot[data-status="busy"]::after { transform: scaleX(1); }
|
|
32
|
+
.dot[data-status="away"] { --dot-color: var(--warning); }
|
|
33
|
+
.dot[data-status="away"]::before, .dot[data-status="offline"]::before { transform: scale(1); }
|
|
34
|
+
.dot[data-status="offline"] { --dot-color: var(--text-muted); }
|
|
35
|
+
|
|
36
|
+
/* The panel scales out of the avatar it belongs to; the component sets the origin once it is placed. */
|
|
37
|
+
.panel { --presence-surface: var(--surface-raised); --row: 32px; --inset: 4px; --menu-radius: var(--radius-detail); --menu-line: color-mix(in oklab, var(--foreground) 9%, transparent); position: fixed; top: 0; left: 0; z-index: 60; box-sizing: border-box; width: 15.5rem; max-width: calc(100vw - 24px); padding: var(--inset); border: .5px solid var(--border); border-radius: var(--menu-radius); background: var(--surface-raised); box-shadow: var(--shadow-floating); color: var(--foreground); font-family: var(--font-body); letter-spacing: -.01em; line-height: 1.3; text-align: left; outline: none; transform-origin: var(--origin-x, 100%) var(--origin-y, 0px); }
|
|
38
|
+
.panel[data-inline] { position: absolute; top: calc(100% + 8px); left: auto; }
|
|
39
|
+
.panel[data-inline][data-align="end"] { right: 0; }
|
|
40
|
+
.panel[data-inline][data-align="start"] { left: 0; }
|
|
41
|
+
.panel[data-inline][data-align="center"] { left: 50%; margin-left: -7.75rem; }
|
|
42
|
+
|
|
43
|
+
.header { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px; }
|
|
44
|
+
.identity { display: grid; min-width: 0; flex: 1; gap: 2px; }
|
|
45
|
+
/* The name keeps its room; a long plan or role shrinks and truncates first. */
|
|
46
|
+
.nameRow { display: flex; min-width: 0; align-items: center; gap: 6px; }
|
|
47
|
+
.name { min-width: 0; flex: 0 1 auto; overflow: hidden; color: var(--foreground); font-size: 13px; font-weight: 500; letter-spacing: -.012em; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
|
|
48
|
+
.plan { display: inline-block; min-width: 0; max-width: 55%; flex: 0 100 auto; overflow: hidden; height: 17px; padding: 0 5px; border: .5px solid var(--menu-line); border-radius: var(--radius-detail); corner-shape: var(--corner-shape); background: color-mix(in oklab, var(--foreground) 4%, transparent); color: var(--text-secondary); font-size: 11px; font-weight: 500; letter-spacing: -.005em; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }
|
|
49
|
+
.email { overflow: hidden; color: var(--text-muted); font-size: 12px; letter-spacing: -.008em; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
|
|
50
|
+
|
|
51
|
+
.list { position: relative; }
|
|
52
|
+
.separator { height: .5px; margin: var(--inset) calc(var(--inset) * -1); background: var(--menu-line); }
|
|
53
|
+
@media (max-resolution: 1dppx) { .separator { height: 1px; background: color-mix(in oklab, var(--foreground) 6%, transparent); } }
|
|
54
|
+
|
|
55
|
+
/* One highlight follows the pointer and the keyboard. It is the only hover treatment in the menu. */
|
|
56
|
+
.highlight { position: absolute; top: 0; right: 0; left: 0; border-radius: var(--radius-detail); corner-shape: var(--corner-shape); background: color-mix(in oklab, var(--foreground) 6%, transparent); opacity: 0; pointer-events: none; }
|
|
57
|
+
|
|
58
|
+
.item { position: relative; display: flex; width: 100%; height: var(--row); box-sizing: border-box; align-items: center; gap: 10px; margin: 0; padding: 0 8px; border: 0; border-radius: var(--radius-detail); corner-shape: var(--corner-shape); background: transparent; color: var(--foreground); font: inherit; font-size: 13px; text-align: left; cursor: pointer; outline: none; user-select: none; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard); }
|
|
59
|
+
.icon { display: inline-grid; width: 16px; flex: none; place-items: center; color: var(--text-secondary); transition: color var(--duration-fast) var(--ease-standard); }
|
|
60
|
+
.item:focus .icon { color: var(--foreground); }
|
|
61
|
+
.itemLabel { position: relative; display: inline-flex; min-width: 0; flex: 1; }
|
|
62
|
+
.rise { display: inline-block; white-space: nowrap; }
|
|
63
|
+
/* Sign out is not destructive, so it stays neutral like every other row. */
|
|
64
|
+
@media (hover: none) { .item:active { background: var(--surface-muted); } }
|
|
65
|
+
|
|
66
|
+
.keys { display: inline-flex; flex: none; align-items: center; gap: 1px; margin-left: auto; color: var(--text-muted); font-family: var(--font-body); font-size: var(--text-xs); letter-spacing: 0; opacity: .8; font-variant-numeric: tabular-nums; }
|
|
67
|
+
.key { display: inline-block; min-width: 1.05em; font: inherit; text-align: center; }
|
|
68
|
+
|
|
69
|
+
.row { position: relative; display: flex; height: 36px; align-items: center; gap: 10px; padding: 0 4px 0 8px; }
|
|
70
|
+
.rowLabel { flex: 1; color: var(--foreground); font-size: 13px; }
|
|
71
|
+
.row .icon .dot { --dot-size: 10px; }
|
|
72
|
+
/* The thumb slides under the icons; the group owns the stacking context. */
|
|
73
|
+
.segments { --segment: 28px; position: relative; isolation: isolate; display: inline-grid; height: 26px; flex: none; grid-auto-columns: var(--segment); grid-auto-flow: column; padding: 2px; border-radius: var(--radius-detail); corner-shape: var(--corner-shape); background: color-mix(in oklab, var(--foreground) 5%, transparent); }
|
|
74
|
+
.thumb { position: absolute; z-index: -1; top: 2px; bottom: 2px; left: 2px; width: var(--segment); border-radius: var(--radius-detail); corner-shape: var(--corner-shape); background: var(--surface-raised); box-shadow: 0 1px 1.5px oklch(0% 0 0 / .08), 0 0 0 .5px var(--menu-line); transform: translateX(calc(var(--index) * 100%)); transition: transform var(--duration-spring) var(--ease-spring); }
|
|
75
|
+
:global([data-theme="dark"]) .thumb { background: color-mix(in oklab, var(--foreground) 20%, var(--surface-raised)); box-shadow: none; }
|
|
76
|
+
.segment { display: grid; place-items: center; margin: 0; padding: 0; border: 0; border-radius: var(--radius-detail); corner-shape: var(--corner-shape); background: transparent; color: var(--text-muted); cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard); }
|
|
77
|
+
.segment .dot { --dot-size: 9px; --presence-surface: var(--surface-raised); }
|
|
78
|
+
@media (hover: hover) and (pointer: fine) { .segment:hover { color: var(--text-secondary); } }
|
|
79
|
+
.segment[aria-checked="true"] { color: var(--foreground); }
|
|
80
|
+
|
|
81
|
+
.spinner { animation: user-menu-spin .8s linear infinite; }
|
|
82
|
+
@keyframes user-menu-spin { to { transform: rotate(360deg); } }
|
|
83
|
+
|
|
84
|
+
/* Below 640px the same content rises as a bottom sheet with larger rows. */
|
|
85
|
+
.scrim { position: fixed; inset: 0; z-index: 70; background: oklch(0% 0 0 / .32); -webkit-tap-highlight-color: transparent; }
|
|
86
|
+
.sheet { --row: 46px; --inset: 10px; position: fixed; top: auto; right: 0; bottom: 0; left: 0; z-index: 71; width: auto; max-width: none; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; padding: 8px var(--inset) calc(12px + env(safe-area-inset-bottom)); border-bottom: 0; border-radius: var(--radius-container) var(--radius-container) 0 0; corner-shape: var(--corner-shape); }
|
|
87
|
+
.handle { display: block; width: 36px; height: 5px; margin: 0 auto 10px; border-radius: var(--radius-full); corner-shape: round; background: var(--border-strong); cursor: grab; }
|
|
88
|
+
.sheet .header { padding: 4px 8px 12px; }
|
|
89
|
+
.sheet .item, .sheet .rowLabel { font-size: var(--text-base); }
|
|
90
|
+
.sheet .row { height: 52px; }
|
|
91
|
+
.sheet .segments { --segment: 40px; height: 34px; }
|
|
92
|
+
.sheet .keys { display: none; }
|
|
93
|
+
|
|
94
|
+
@media (prefers-reduced-motion: reduce) {
|
|
95
|
+
.trigger, .chevron, .dot, .dot::before, .dot::after, .segment, .thumb, .item, .icon { transition: none; }
|
|
96
|
+
.spinner { animation-duration: 2.4s; }
|
|
97
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Ref } from "react";
|
|
2
|
+
export interface WaffleCategory {
|
|
3
|
+
/** Stable identity. Cells keep following their category when the data changes, so a new dataset flows instead of repainting. */
|
|
4
|
+
key: string;
|
|
5
|
+
/** Name in the legend, the tooltip, and the data table. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Raw amount. Shares are computed from the total; negatives count as zero. */
|
|
8
|
+
value: number;
|
|
9
|
+
/** Any CSS color. Defaults to the first series for accentKey, the supporting series for the next three, then neutral steps. */
|
|
10
|
+
color?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A unit chart: every cell is one share of the whole, so parts of a total read as countable squares. */
|
|
13
|
+
export interface WaffleChartProps {
|
|
14
|
+
/** Categories in fill order. The first fills from the bottom-left corner, column by column. */
|
|
15
|
+
data: WaffleCategory[];
|
|
16
|
+
/** What the whole is, such as "Electricity generation, 2023". Names the chart for assistive technology. */
|
|
17
|
+
label: string;
|
|
18
|
+
/** Unit after each raw value in the tooltip and table, such as "TWh". */
|
|
19
|
+
unit?: string;
|
|
20
|
+
formatValue?: (value: number, category: WaffleCategory) => string;
|
|
21
|
+
/** Grid rows. rows × columns cells make the whole; 10 × 10 means one cell per percent. */
|
|
22
|
+
rows?: number;
|
|
23
|
+
columns?: number;
|
|
24
|
+
/** The category painted in the accent. Pass null to keep every category neutral. Defaults to the first category. */
|
|
25
|
+
accentKey?: string | null;
|
|
26
|
+
/** Controlled focused category. Others dim while one is focused. */
|
|
27
|
+
activeKey?: string | null;
|
|
28
|
+
defaultActiveKey?: string | null;
|
|
29
|
+
onActiveChange?: (key: string | null) => void;
|
|
30
|
+
/** Category list with shares that roll to their new value. */
|
|
31
|
+
legend?: boolean;
|
|
32
|
+
/** Decimal places for shares. */
|
|
33
|
+
decimals?: number;
|
|
34
|
+
emptyLabel?: string;
|
|
35
|
+
ref?: Ref<HTMLElement>;
|
|
36
|
+
className?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function WaffleChart({ data, label, unit, formatValue, rows, columns, accentKey, activeKey, defaultActiveKey, onActiveChange, legend, decimals, emptyLabel, ref, className }: WaffleChartProps): import("react").JSX.Element;
|
|
39
|
+
export default WaffleChart;
|