@mrpelz/uikit-ish 7.26.2 → 7.29.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/dist/components/accordion/style.css +0 -3
- package/dist/components/activity-view/style.css +17 -17
- package/dist/components/alert/style.css +12 -10
- package/dist/components/avatar/style.css +2 -2
- package/dist/components/badge/style.css +1 -1
- package/dist/components/button/style.css +12 -12
- package/dist/components/card/buttons.d.ts +35 -0
- package/dist/components/card/buttons.d.ts.map +1 -0
- package/dist/components/card/buttons.js +60 -0
- package/dist/components/card/buttons.js.map +1 -0
- package/dist/components/card/channels.d.ts +43 -0
- package/dist/components/card/channels.d.ts.map +1 -0
- package/dist/components/card/channels.js +321 -0
- package/dist/components/card/channels.js.map +1 -0
- package/dist/components/card/color.d.ts +21 -0
- package/dist/components/card/color.d.ts.map +1 -0
- package/dist/components/card/color.js +100 -0
- package/dist/components/card/color.js.map +1 -0
- package/dist/components/card/main.d.ts +67 -39
- package/dist/components/card/main.d.ts.map +1 -1
- package/dist/components/card/main.js +79 -274
- package/dist/components/card/main.js.map +1 -1
- package/dist/components/card/parts.css +769 -0
- package/dist/components/card/press.d.ts +25 -0
- package/dist/components/card/press.d.ts.map +1 -0
- package/dist/components/card/press.js +111 -0
- package/dist/components/card/press.js.map +1 -0
- package/dist/components/card/progress.d.ts +43 -0
- package/dist/components/card/progress.d.ts.map +1 -0
- package/dist/components/card/progress.js +122 -0
- package/dist/components/card/progress.js.map +1 -0
- package/dist/components/card/props.d.ts +324 -14
- package/dist/components/card/props.d.ts.map +1 -1
- package/dist/components/card/root.d.ts +100 -0
- package/dist/components/card/root.d.ts.map +1 -0
- package/dist/components/card/root.js +388 -0
- package/dist/components/card/root.js.map +1 -0
- package/dist/components/card/rows.d.ts +19 -0
- package/dist/components/card/rows.d.ts.map +1 -0
- package/dist/components/card/rows.js +185 -0
- package/dist/components/card/rows.js.map +1 -0
- package/dist/components/card/segmented.d.ts +61 -0
- package/dist/components/card/segmented.d.ts.map +1 -0
- package/dist/components/card/segmented.js +289 -0
- package/dist/components/card/segmented.js.map +1 -0
- package/dist/components/card/shared.d.ts +55 -0
- package/dist/components/card/shared.d.ts.map +1 -0
- package/dist/components/card/shared.js +80 -0
- package/dist/components/card/shared.js.map +1 -0
- package/dist/components/card/slider.d.ts +16 -0
- package/dist/components/card/slider.d.ts.map +1 -0
- package/dist/components/card/slider.js +48 -0
- package/dist/components/card/slider.js.map +1 -0
- package/dist/components/card/stages.d.ts +18 -0
- package/dist/components/card/stages.d.ts.map +1 -0
- package/dist/components/card/stages.js +37 -0
- package/dist/components/card/stages.js.map +1 -0
- package/dist/components/card/style.css +125 -66
- package/dist/components/checkbox/style.css +10 -5
- package/dist/components/collapsible/style.css +0 -3
- package/dist/components/color-picker/color.d.ts +2 -2
- package/dist/components/color-picker/color.d.ts.map +1 -1
- package/dist/components/color-picker/color.js +7 -7
- package/dist/components/color-picker/color.js.map +1 -1
- package/dist/components/color-picker/main.d.ts +11 -5
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +128 -57
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/props.d.ts +216 -6
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +8 -8
- package/dist/components/control-cards/main.d.ts +6 -17
- package/dist/components/control-cards/main.d.ts.map +1 -1
- package/dist/components/control-cards/main.js +119 -758
- package/dist/components/control-cards/main.js.map +1 -1
- package/dist/components/control-cards/props.d.ts +79 -250
- package/dist/components/control-cards/props.d.ts.map +1 -1
- package/dist/components/control-cards/style.css +2 -492
- package/dist/components/date-picker/main.d.ts +8 -3
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +71 -29
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/pager.d.ts.map +1 -1
- package/dist/components/date-picker/pager.js +9 -2
- package/dist/components/date-picker/pager.js.map +1 -1
- package/dist/components/date-picker/props.d.ts +81 -5
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +24 -16
- package/dist/components/edit-menu/style.css +2 -2
- package/dist/components/glass/style.css +38 -5
- package/dist/components/grid/main.d.ts +1 -1
- package/dist/components/grid/main.d.ts.map +1 -1
- package/dist/components/grid/main.js +104 -21
- package/dist/components/grid/main.js.map +1 -1
- package/dist/components/grid/props.d.ts +75 -5
- package/dist/components/grid/props.d.ts.map +1 -1
- package/dist/components/grid/style.css +68 -38
- package/dist/components/header/style.css +12 -6
- package/dist/components/index.d.ts +10 -8
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +6 -4
- package/dist/components/index.js.map +1 -1
- package/dist/components/layout/style.css +0 -3
- package/dist/components/list/main.d.ts +5 -3
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +42 -5
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +5 -0
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/reorder.d.ts +34 -0
- package/dist/components/list/reorder.d.ts.map +1 -1
- package/dist/components/list/reorder.js +40 -17
- package/dist/components/list/reorder.js.map +1 -1
- package/dist/components/list/style.css +101 -73
- package/dist/components/menu/style.css +38 -30
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +35 -13
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/style.css +7 -0
- package/dist/components/page-control/main.d.ts.map +1 -1
- package/dist/components/page-control/main.js +32 -15
- package/dist/components/page-control/main.js.map +1 -1
- package/dist/components/page-control/props.d.ts +6 -0
- package/dist/components/page-control/props.d.ts.map +1 -1
- package/dist/components/page-control/style.css +36 -0
- package/dist/components/pager/main.d.ts +12 -0
- package/dist/components/pager/main.d.ts.map +1 -0
- package/dist/components/pager/main.js +368 -0
- package/dist/components/pager/main.js.map +1 -0
- package/dist/components/pager/props.d.ts +36 -0
- package/dist/components/pager/props.d.ts.map +1 -0
- package/dist/components/pager/props.js +2 -0
- package/dist/components/pager/props.js.map +1 -0
- package/dist/components/pager/style.css +42 -0
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +3 -2
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/style.css +4 -10
- package/dist/components/roll/style.css +2 -2
- package/dist/components/segmented/style.css +16 -7
- package/dist/components/settings/main.d.ts +35 -1
- package/dist/components/settings/main.d.ts.map +1 -1
- package/dist/components/settings/main.js +297 -68
- package/dist/components/settings/main.js.map +1 -1
- package/dist/components/settings/props.d.ts +45 -4
- package/dist/components/settings/props.d.ts.map +1 -1
- package/dist/components/settings/region.d.ts +3 -0
- package/dist/components/settings/region.d.ts.map +1 -0
- package/dist/components/settings/region.js +120 -0
- package/dist/components/settings/region.js.map +1 -0
- package/dist/components/settings/style.css +2 -2
- package/dist/components/sheet/snap.d.ts.map +1 -1
- package/dist/components/sheet/snap.js +13 -5
- package/dist/components/sheet/snap.js.map +1 -1
- package/dist/components/sheet/style.css +48 -3
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +5 -2
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/style.css +6 -6
- package/dist/components/stack/main.d.ts +8 -0
- package/dist/components/stack/main.d.ts.map +1 -0
- package/dist/components/stack/main.js +25 -0
- package/dist/components/stack/main.js.map +1 -0
- package/dist/components/stack/props.d.ts +42 -0
- package/dist/components/stack/props.d.ts.map +1 -0
- package/dist/components/stack/props.js +2 -0
- package/dist/components/stack/props.js.map +1 -0
- package/dist/components/stack/style.css +68 -0
- package/dist/components/stepper/main.d.ts +3 -1
- package/dist/components/stepper/main.d.ts.map +1 -1
- package/dist/components/stepper/main.js +4 -0
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +2 -2
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +5 -1
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +4 -1
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +36 -13
- package/dist/components/text-field/style.css +28 -17
- package/dist/components/toolbar/main.d.ts +5 -2
- package/dist/components/toolbar/main.d.ts.map +1 -1
- package/dist/components/toolbar/main.js +18 -0
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/props.d.ts +15 -0
- package/dist/components/toolbar/props.d.ts.map +1 -1
- package/dist/components/toolbar/style.css +126 -10
- package/dist/components/tooltip/style.css +2 -2
- package/dist/components/typography/main.d.ts +1 -0
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +1 -0
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/sizes.css +456 -0
- package/dist/components/typography/style.css +24 -456
- package/dist/components/utils/main.d.ts +23 -6
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +60 -7
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/viewport/edge-effect.d.ts.map +1 -1
- package/dist/components/viewport/edge-effect.js +6 -2
- package/dist/components/viewport/edge-effect.js.map +1 -1
- package/dist/components/viewport/focus-scroll.d.ts.map +1 -1
- package/dist/components/viewport/focus-scroll.js +2 -1
- package/dist/components/viewport/focus-scroll.js.map +1 -1
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +34 -2
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/style.css +7 -13
- package/dist/styles.css +287 -120
- package/package.json +1 -1
|
@@ -1,835 +1,196 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import '../card/style.css';
|
|
3
|
-
import '../
|
|
4
|
-
import '../progress/style.css';
|
|
3
|
+
import '../card/parts.css';
|
|
5
4
|
import './style.css';
|
|
6
|
-
import {
|
|
7
|
-
import { RadioGroup as BaseRadioGroup } from '@base-ui/react/radio-group';
|
|
8
|
-
import { createContext, forwardRef, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
5
|
+
import { forwardRef, useCallback, useMemo, useState, } from 'react';
|
|
9
6
|
import { Badge } from '../badge/main.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { Slider } from '../slider/main.js';
|
|
7
|
+
import { OpenButtonHintContext } from '../card/buttons.js';
|
|
8
|
+
import { ChannelsHostContext } from '../card/channels.js';
|
|
9
|
+
import { Card } from '../card/main.js';
|
|
10
|
+
import { SegmentedHostContext, useSegmentedOptions, } from '../card/segmented.js';
|
|
11
|
+
import { formatted, percentFormat, useControlled, useIsLarge, } from '../card/shared.js';
|
|
12
|
+
import { useGridItem } from '../grid/main.js';
|
|
13
|
+
import { forwardClick } from '../list/main.js';
|
|
14
|
+
import { useLocale } from '../settings/main.js';
|
|
19
15
|
import { Symbol } from '../symbol/main.js';
|
|
20
|
-
import { cn,
|
|
21
|
-
// Control cards: ready-made cards
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
/**
|
|
30
|
-
const
|
|
31
|
-
const [state, setState] = useState(defaultValue);
|
|
32
|
-
return [value === undefined ? state : value, setState];
|
|
33
|
-
};
|
|
34
|
-
/** The document's language, if it says (none: the runtime's default). */
|
|
35
|
-
const documentLocale = () => typeof document === 'undefined'
|
|
36
|
-
? undefined
|
|
37
|
-
: document.documentElement.lang || undefined;
|
|
38
|
-
/** A number, formatted (see `ControlCardFormat`). */
|
|
39
|
-
const formatted = (value, { format, locale }) => new Intl.NumberFormat(locale ?? documentLocale(), format).format(value);
|
|
40
|
-
/**
|
|
41
|
-
* Whether its card shows its large layout: its tile at least 2x2 (a full
|
|
42
|
-
* width's: wide), however it got there (expanded, resized), or open above
|
|
43
|
-
* the page.
|
|
44
|
-
*/
|
|
45
|
-
const useIsLarge = () => {
|
|
46
|
-
const item = useGridItem();
|
|
47
|
-
if (!item)
|
|
48
|
-
return false;
|
|
49
|
-
const [columns = '1', rows = '1'] = item.size.split('x');
|
|
50
|
-
return (item.open ||
|
|
51
|
-
((columns === '*' || Number(columns) >= 2) && Number(rows) >= 2));
|
|
52
|
-
};
|
|
16
|
+
import { cn, withStyle } from '../utils/main.js';
|
|
17
|
+
// Control cards: ready-made cards for what a home's devices show and
|
|
18
|
+
// control (a state, a switch, a value, a slider, a momentary button, a
|
|
19
|
+
// progress, a run of stages, a light of several channels, a summary in
|
|
20
|
+
// rows, a few modes), each a `Card.Root` and Card's parts, composed. A
|
|
21
|
+
// namespace, not one component's parts: each card stands on its own, its
|
|
22
|
+
// other props its `Card.Root`'s. Its `children` added after its parts
|
|
23
|
+
// (e.g. a corner button); a composed card's (a progress, stages, a light,
|
|
24
|
+
// rows, a choice) its own parts too, Card's, as the app shows them.
|
|
25
|
+
/** The words for on and off, unless given. */
|
|
26
|
+
const onOff = ['On', 'Off'];
|
|
53
27
|
/** Its symbol: its icon, or its emphasized one while on. */
|
|
54
28
|
const symbolOf = ({ emphasizedIcon, icon }, children) => (_jsx(Symbol, { box: "square", emphasizedIcon: emphasizedIcon, icon: icon, children: children }));
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
* value its state's words (e.g. a door open or closed).
|
|
58
|
-
*/
|
|
59
|
-
const State = forwardRef(({ active, children, className, emphasizedIcon, icon, name, states = ['On', 'Off'], ...props }, ref) => (_jsxs(Card.Root, { ref: ref, active: active, ...props, className: cn('uikit-control-cards-state', className), "data-control-cards-part": "state", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: name }), _jsx(Card.Value, { children: active ? states[0] : states[1] }), children] })));
|
|
60
|
-
/**
|
|
61
|
-
* A binary control: a switch at its top trailing corner, a press on the
|
|
62
|
-
* card toggling it; lit while on.
|
|
63
|
-
*/
|
|
64
|
-
const SwitchCard = forwardRef(({ checked, children, className, defaultChecked = false, emphasizedIcon, icon, name, onCheckedChange, onClick, states = ['On', 'Off'], tint, ...props }, ref) => {
|
|
29
|
+
/** Its switching: on or off, controlled or its own, told as it changes. */
|
|
30
|
+
const useSwitching = (checked, defaultChecked, onCheckedChange) => {
|
|
65
31
|
const [isOn, setIsOn] = useControlled(checked, defaultChecked);
|
|
66
32
|
const switchTo = (next) => {
|
|
67
33
|
setIsOn(next);
|
|
68
34
|
onCheckedChange?.(next);
|
|
69
35
|
};
|
|
70
|
-
return
|
|
71
|
-
});
|
|
72
|
-
/** A trend's arrow (see `Trend`): pointing ahead, turned by its angle. */
|
|
73
|
-
const trendIcon = iconOf('control-cards.trend', polyline([-4.5, 0], [4.5, 0]) + polyline([0.5, -4], [4.5, 0], [0.5, 4]));
|
|
74
|
-
/** A trend's words, by its angle (see `Trend`). */
|
|
75
|
-
const trendOf = (angle) => {
|
|
76
|
-
if (angle > 10)
|
|
77
|
-
return 'rising';
|
|
78
|
-
return angle < -10 ? 'falling' : 'steady';
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* A value's trend: an arrow pointing up as steeply as it rises (`angle`,
|
|
82
|
-
* -90 to 90 degrees: 0 steady), named for assistive technology. It turns
|
|
83
|
-
* to a new angle by its own transform.
|
|
84
|
-
*/
|
|
85
|
-
const Trend = ({ angle }) => {
|
|
86
|
-
const clamped = Math.max(-90, Math.min(90, angle));
|
|
87
|
-
return (_jsx("span", { "aria-label": trendOf(clamped), className: "uikit-control-cards-trend", role: "img", style: { '--uikit-control-cards-trend': String(clamped) }, children: _jsx(Symbol, { icon: trendIcon }) }));
|
|
36
|
+
return [isOn, switchTo];
|
|
88
37
|
};
|
|
89
38
|
/**
|
|
90
|
-
* A
|
|
91
|
-
*
|
|
39
|
+
* A binary display: its state lit (`active`), its symbol emphasized, its
|
|
40
|
+
* value its state's words (e.g. a door open or closed).
|
|
92
41
|
*/
|
|
93
|
-
const
|
|
94
|
-
? formatted(value, { format, locale })
|
|
95
|
-
: value, trend === undefined ? null : _jsx(Trend, { angle: trend })] }), children] })));
|
|
96
|
-
// How far a press moves before it's a drag (px; the grid's resize
|
|
97
|
-
// handle's, see Grid's edit.ts); a touch's (or a pen's), before it's told
|
|
98
|
-
// a drag (along the slider) from a scroll (across it), as a browser tells
|
|
99
|
-
// a pan.
|
|
100
|
-
const pressSlop = 4;
|
|
101
|
-
const touchSlop = 8;
|
|
102
|
-
// (A press handed on to the slider (see `pressProps`): let through; one
|
|
103
|
-
// held back, not yet a drag or a click: its touch held back too.)
|
|
104
|
-
let isHandingOn = false;
|
|
105
|
-
let isHolding = false;
|
|
42
|
+
const State = forwardRef(({ active, children, className, emphasizedIcon, icon, label, states = onOff, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, active: active, ...props, className: cn('uikit-control-cards-state', className), "data-control-cards-part": "state", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: label }), _jsx(Card.Value, { children: active ? states[0] : states[1] }), children] })));
|
|
106
43
|
/**
|
|
107
|
-
* A
|
|
108
|
-
*
|
|
109
|
-
* even as the page scrolls, see Base UI's SliderControl):
|
|
110
|
-
* - Moved (`pressSlop`; a touch, `touchSlop`) along it (a mouse, any
|
|
111
|
-
* way): a drag, handed on to the slider (the press again, where it
|
|
112
|
-
* started).
|
|
113
|
-
* - A touch moved across it, or the browser panning (it's cancelled): a
|
|
114
|
-
* scroll, the page's, the slider never told.
|
|
115
|
-
* - Released before: `onClick`'s, the slider never told (its value
|
|
116
|
-
* kept); its click, if the browser moves it to a control near it (e.g.
|
|
117
|
-
* the card's switch, a tap's target adjusted, as WebKit's on iOS), not
|
|
118
|
-
* that control's too (toggled back): swallowed (not the click deciding:
|
|
119
|
-
* on iOS, none may come to it). No `onClick`: handed on to the slider as
|
|
120
|
-
* it's released (its value set where it was pressed).
|
|
44
|
+
* A binary control: a switch at its top trailing corner, a press on the
|
|
45
|
+
* card toggling it; lit while on.
|
|
121
46
|
*/
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
event.stopPropagation();
|
|
127
|
-
// (The DOM's event: React's wraps it, Preact's is it.)
|
|
128
|
-
const pressed = event.nativeEvent ??
|
|
129
|
-
event;
|
|
130
|
-
const { clientX, clientY, pointerId, pointerType, target } = pressed;
|
|
131
|
-
const isMouse = pointerType === 'mouse';
|
|
132
|
-
const slop = isMouse ? pressSlop : touchSlop;
|
|
133
|
-
const root = event.currentTarget;
|
|
134
|
-
const handOn = () => {
|
|
135
|
-
isHandingOn = true;
|
|
136
|
-
try {
|
|
137
|
-
target?.dispatchEvent(new PointerEvent('pointerdown', pressed));
|
|
138
|
-
}
|
|
139
|
-
finally {
|
|
140
|
-
isHandingOn = false;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const listening = new AbortController();
|
|
144
|
-
const options = { capture: true, signal: listening.signal };
|
|
145
|
-
isHolding = true;
|
|
146
|
-
listening.signal.addEventListener('abort', () => {
|
|
147
|
-
isHolding = false;
|
|
148
|
-
});
|
|
149
|
-
addEventListener('pointermove', (move) => {
|
|
150
|
-
if (move.pointerId !== pointerId)
|
|
151
|
-
return;
|
|
152
|
-
const across = Math.abs(move.clientX - clientX);
|
|
153
|
-
const upright = Math.abs(move.clientY - clientY);
|
|
154
|
-
if (Math.hypot(across, upright) < slop)
|
|
155
|
-
return;
|
|
156
|
-
listening.abort();
|
|
157
|
-
// (A touch across it: a scroll, let go.)
|
|
158
|
-
const along = orientation === 'vertical' ? upright : across;
|
|
159
|
-
const crossing = orientation === 'vertical' ? across : upright;
|
|
160
|
-
if (!isMouse && crossing > along)
|
|
161
|
-
return;
|
|
162
|
-
handOn();
|
|
163
|
-
}, options);
|
|
164
|
-
addEventListener('pointerup', (up) => {
|
|
165
|
-
if (up.pointerId !== pointerId)
|
|
166
|
-
return;
|
|
167
|
-
listening.abort();
|
|
168
|
-
// (No click of its own: the slider's, its value set there; this
|
|
169
|
-
// release ending it, as it goes on.)
|
|
170
|
-
if (onClick === undefined) {
|
|
171
|
-
handOn();
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
onClick();
|
|
175
|
-
// (Its click next, if any, elsewhere: swallowed; none before
|
|
176
|
-
// another press or key, nothing.)
|
|
177
|
-
const clicking = new AbortController();
|
|
178
|
-
const once = { capture: true, signal: clicking.signal };
|
|
179
|
-
addEventListener('click', (clicked) => {
|
|
180
|
-
clicking.abort();
|
|
181
|
-
if (root.contains(clicked.target))
|
|
182
|
-
return;
|
|
183
|
-
clicked.preventDefault();
|
|
184
|
-
clicked.stopPropagation();
|
|
185
|
-
}, once);
|
|
186
|
-
for (const type of ['pointerdown', 'keydown']) {
|
|
187
|
-
addEventListener(type, () => clicking.abort(), once);
|
|
188
|
-
}
|
|
189
|
-
}, options);
|
|
190
|
-
addEventListener('pointercancel', (cancel) => {
|
|
191
|
-
if (cancel.pointerId === pointerId)
|
|
192
|
-
listening.abort();
|
|
193
|
-
}, options);
|
|
194
|
-
},
|
|
195
|
-
// (The slider takes a touch's start too, unless its pointer's started
|
|
196
|
-
// it (see Base UI's SliderControl), following it past a pan: held back
|
|
197
|
-
// with it.)
|
|
198
|
-
onTouchStartCapture: (event) => {
|
|
199
|
-
if (isHolding)
|
|
200
|
-
event.stopPropagation();
|
|
201
|
-
},
|
|
47
|
+
const SwitchCard = forwardRef(({ checked, children, className, defaultChecked = false, disabled, emphasizedIcon, icon, label, onCheckedChange, onClick, states = onOff, tint, ...props }, ref) => {
|
|
48
|
+
const [isOn, switchTo] = useSwitching(checked, defaultChecked, onCheckedChange);
|
|
49
|
+
return (_jsxs(Card.Root, { ref: ref, active: isOn, ...props, className: cn('uikit-control-cards-switch', className), "data-control-cards-part": "switch", onClick: onClick ??
|
|
50
|
+
(disabled ? undefined : forwardClick('[role=switch]:not([disabled])')), children: [_jsx(Card.Symbol, { tint: tint, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: label }), _jsx(Card.Value, { children: isOn ? states[0] : states[1] }), _jsx(Card.Switch, { "aria-label": label, checked: isOn, disabled: disabled, tint: tint, onCheckedChange: switchTo }), children] }));
|
|
202
51
|
});
|
|
203
52
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* Its tint's, read where it's drawn (its `light-dark()` resolved there), not
|
|
207
|
-
* what's painted: off, with a switch, the fill isn't drawn (see Card), and
|
|
208
|
-
* its tone is still wanted as it's switched on.
|
|
209
|
-
*/
|
|
210
|
-
const useFillScheme = (indicator, tint) => {
|
|
211
|
-
const { colorScheme } = useSettings();
|
|
212
|
-
const [tone, setTone] = useState();
|
|
213
|
-
useLayoutEffect(() => {
|
|
214
|
-
const { current: element } = indicator;
|
|
215
|
-
if (!element)
|
|
216
|
-
return;
|
|
217
|
-
// (Read once it's laid out: its color computed, a var's resolved, by a
|
|
218
|
-
// probe in it, gone again.)
|
|
219
|
-
const read = () => {
|
|
220
|
-
const probe = document.createElement('span');
|
|
221
|
-
probe.style.color = 'var(--uikit-slider-tint)';
|
|
222
|
-
element.append(probe);
|
|
223
|
-
const { color } = getComputedStyle(probe);
|
|
224
|
-
probe.remove();
|
|
225
|
-
setTone((last) => toneOfColor(color, last));
|
|
226
|
-
};
|
|
227
|
-
read();
|
|
228
|
-
}, [colorScheme, indicator, tint]);
|
|
229
|
-
if (tone === undefined)
|
|
230
|
-
return undefined;
|
|
231
|
-
return tone === 'bright' ? 'light' : 'dark';
|
|
232
|
-
};
|
|
233
|
-
/**
|
|
234
|
-
* A slider card's switch (see `ControlCardSliderProps.checked`): whether
|
|
235
|
-
* it has one, whether it's on (with none: on), switching it.
|
|
236
|
-
*/
|
|
237
|
-
const useSliderSwitch = (checked, defaultChecked, onCheckedChange) => {
|
|
238
|
-
const hasSwitch = checked !== undefined || defaultChecked !== undefined;
|
|
239
|
-
const [isOn, setIsOn] = useControlled(checked, defaultChecked ?? true);
|
|
240
|
-
const switchTo = (next) => {
|
|
241
|
-
setIsOn(next);
|
|
242
|
-
onCheckedChange?.(next);
|
|
243
|
-
};
|
|
244
|
-
return { hasSwitch, isOn, switchTo };
|
|
245
|
-
};
|
|
246
|
-
/** A value text (see `getValueText`) as `Slider.Value`'s children. */
|
|
247
|
-
const valueTextOf = (getValueText) => getValueText
|
|
248
|
-
? (formattedValues, values) => getValueText(formattedValues[0] ?? '', values[0] ?? 0)
|
|
249
|
-
: undefined;
|
|
250
|
-
const FillCopies = ({ layerRef, name, orientation, scheme, ticks, valueText, }) => (_jsxs("span", { ref: layerRef, "aria-hidden": true, inert: true, className: "uikit-card-blend", "data-color-scheme": scheme, "data-orientation": orientation, style: colorSchemeStyle(scheme), children: [_jsx("span", { className: "uikit-slider-label", "data-card-copy": "", children: name }), _jsx(Slider.Value, { "data-card-copy": "", children: valueText }), ticks === undefined ? null : (_jsx(Slider.Ticks, { count: ticks, "data-card-copy": "" }))] }));
|
|
251
|
-
/**
|
|
252
|
-
* A slider filling its card (a `Card.Root`'s, among its parts): its fill
|
|
253
|
-
* the card's background (from its leading edge, or from its bottom upright,
|
|
254
|
-
* by its tile's shape), ticks at its steps (`step`), its label and value at
|
|
255
|
-
* the card's bottom. What's over the fill (its label, value and ticks, the
|
|
256
|
-
* card's symbol and corner buttons) drawn twice: on the card, and again
|
|
257
|
-
* inside the fill in the fill's color scheme (dark on a bright fill, light
|
|
258
|
-
* on a dim one), clipped by its edge, so it reads whatever its tint. With
|
|
259
|
-
* an `onPress`, a click on it is that (e.g. a switch toggled), a drag sets
|
|
260
|
-
* its value.
|
|
53
|
+
* A numerical display: its value, formatted as the app says, and its
|
|
54
|
+
* trend (a `Card.Trend` after it), if given.
|
|
261
55
|
*/
|
|
262
|
-
const
|
|
263
|
-
const orientation = useCardOrientation();
|
|
264
|
-
const [current, setCurrent] = useControlled(value, defaultValue ?? min);
|
|
265
|
-
// (Its fill's color scheme; the layer in it registered with its card,
|
|
266
|
-
// see `CardBlendScope`.)
|
|
267
|
-
const indicator = useRef(null);
|
|
268
|
-
const scheme = useFillScheme(indicator, tint);
|
|
269
|
-
const setLayer = useContext(CardBlendScope)?.setLayer;
|
|
270
|
-
const ticks = step === undefined ? undefined : Math.round((max - min) / step) + 1;
|
|
271
|
-
const valueText = valueTextOf(getValueText);
|
|
272
|
-
return (_jsxs(Slider.Root, { ref: ref, className: cn('uikit-control-cards-slider-fill', className), "data-control-cards-part": "slider-fill", format: format, locale: locale, max: max, min: min, orientation: orientation, step: step ?? (max - min) / 100, tint: tint, value: current, onValueChange: (next) => {
|
|
273
|
-
setCurrent(next);
|
|
274
|
-
onValueChange?.(next);
|
|
275
|
-
}, ...pressProps(onPress, orientation), children: [_jsx(Slider.Control, { children: _jsxs(Slider.Track, { children: [_jsx(Slider.Indicator, { ref: indicator, children: scheme ? (_jsx(FillCopies, { layerRef: setLayer, name: name, orientation: orientation, scheme: scheme, ticks: ticks, valueText: valueText })) : null }), ticks === undefined ? null : _jsx(Slider.Ticks, { count: ticks }), _jsx(Slider.Thumb, { "aria-label": name, getAriaValueText: getValueText })] }) }), _jsx(Slider.Label, { children: name }), _jsx(Slider.Value, { children: valueText })] }));
|
|
276
|
-
});
|
|
56
|
+
const Value = forwardRef(({ children, className, emphasizedIcon, format, icon, label, locale, trend, value, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-value', className), "data-control-cards-part": "value", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: label }), _jsxs(Card.Value, { format: format, locale: locale, value: typeof value === 'number' ? value : undefined, children: [typeof value === 'number' ? null : value, trend === undefined ? null : _jsx(Card.Trend, { angle: trend })] }), children] })));
|
|
277
57
|
/**
|
|
278
58
|
* A slider card's value text by default (see `getValueText`): with a
|
|
279
59
|
* switch, its state's word and its number (“On · 60%”); without one, its
|
|
280
60
|
* number.
|
|
281
61
|
*/
|
|
282
|
-
const defaultValueText = (formattedValue, { checked, states: [on, off] }) => checked === undefined
|
|
62
|
+
const defaultValueText = (formattedValue, _value, { checked, states: [on, off] }) => checked === undefined
|
|
283
63
|
? formattedValue
|
|
284
64
|
: `${checked ? on : off} · ${formattedValue}`;
|
|
285
65
|
/**
|
|
286
|
-
* A numerical control: a `
|
|
66
|
+
* A numerical control: a `Card.Slider` in a card, its symbol at its top.
|
|
287
67
|
* Optionally a switch (`checked`): on and off, its value kept; a click on
|
|
288
68
|
* the card toggles it, a drag sets its value.
|
|
289
69
|
*/
|
|
290
|
-
const SliderCard = forwardRef(({ brightness = false, checked, children, className, defaultChecked, defaultValue, emphasizedIcon, format, getValueText, icon, locale, max = 100, min = 0,
|
|
70
|
+
const SliderCard = forwardRef(({ brightness = false, checked, children, className, defaultChecked, defaultValue, disabled, emphasizedIcon, format, getValueText = defaultValueText, icon, label, locale, max = 100, min = 0, onCheckedChange, onValueChange, states = onOff, step, tint, value, ...props }, ref) => {
|
|
291
71
|
const [current, setCurrent] = useControlled(value, defaultValue ?? min);
|
|
292
|
-
const
|
|
72
|
+
const hasSwitch = checked !== undefined || defaultChecked !== undefined;
|
|
73
|
+
const [isOn, switchTo] = useSwitching(checked, defaultChecked ?? true, onCheckedChange);
|
|
293
74
|
// (Its symbol on: a brightness's above its minimum, while on; else, as
|
|
294
75
|
// its switch, if any.)
|
|
295
76
|
const isOnAtAll = !hasSwitch || isOn;
|
|
296
77
|
const isSymbolOn = brightness
|
|
297
78
|
? isOnAtAll && current > min
|
|
298
79
|
: hasSwitch && isOn;
|
|
80
|
+
const details = { checked: hasSwitch ? isOn : undefined, states };
|
|
81
|
+
const text = (formattedValue, number) => getValueText(formattedValue, number, details);
|
|
299
82
|
return (_jsxs(Card.Root, { ref: ref,
|
|
300
83
|
// (A brightness's: never lit, its dark glass and its fill telling
|
|
301
84
|
// how much light; else, its glass the color scheme's.)
|
|
302
|
-
active: brightness ? false : undefined, ...props, className: cn('uikit-control-cards-slider', className), "data-control-cards-part": "slider", children: [_jsx(Card.Symbol, { active: isSymbolOn, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(
|
|
303
|
-
const isChecked = hasSwitch ? isOn : undefined;
|
|
304
|
-
if (getValueText) {
|
|
305
|
-
return getValueText(formattedValue, number, {
|
|
306
|
-
checked: isChecked,
|
|
307
|
-
states,
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
return defaultValueText(formattedValue, {
|
|
311
|
-
checked: isChecked,
|
|
312
|
-
states,
|
|
313
|
-
});
|
|
314
|
-
}, onPress: hasSwitch ? () => switchTo(!isOn) : undefined, onValueChange: (next) => {
|
|
85
|
+
active: brightness ? false : undefined, ...props, className: cn('uikit-control-cards-slider', className), "data-control-cards-part": "slider", children: [_jsx(Card.Symbol, { active: isSymbolOn, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Slider, { disabled: disabled, format: format, getAriaValueText: text, label: label, locale: locale, max: max, min: min, step: step, tint: tint, value: current, onPress: hasSwitch && !disabled ? () => switchTo(!isOn) : undefined, onValueChange: (next) => {
|
|
315
86
|
setCurrent(next);
|
|
316
87
|
onValueChange?.(next);
|
|
317
|
-
} }), hasSwitch ? (_jsx(Card.Switch, { "aria-label":
|
|
88
|
+
}, children: text }), hasSwitch ? (_jsx(Card.Switch, { "aria-label": label, checked: isOn, disabled: disabled, tint: tint, onCheckedChange: switchTo })) : null, children] }));
|
|
318
89
|
});
|
|
319
90
|
/**
|
|
320
|
-
* A momentary button: a press does something once (e.g. a
|
|
321
|
-
* all lights off); it lights up for a moment and fades
|
|
322
|
-
* app flashes it (`actionsRef`). A badge on its symbol,
|
|
91
|
+
* A momentary button: a press (its `onClick`) does something once (e.g. a
|
|
92
|
+
* doorbell rung, all lights off); it lights up for a moment and fades
|
|
93
|
+
* back, also as the app flashes it (`actionsRef`). A badge on its symbol,
|
|
94
|
+
* if given.
|
|
323
95
|
*/
|
|
324
|
-
const Button = forwardRef(({ badge, children, className, emphasizedIcon, icon,
|
|
325
|
-
onPress?.();
|
|
326
|
-
onClick?.(event);
|
|
327
|
-
}, children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }, badge === undefined || badge === null ? null : (_jsx(Badge, { placement: "symbol", children: badge }))) }), _jsx(Card.Title, { children: name }), status === undefined ? null : _jsx(Card.Value, { children: status }), children] })));
|
|
96
|
+
const Button = forwardRef(({ badge, children, className, emphasizedIcon, icon, label, status, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, momentary: true, ...props, className: cn('uikit-control-cards-button', className), "data-control-cards-part": "button", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }, badge === undefined || badge === null ? null : (_jsx(Badge, { placement: "symbol", children: badge }))) }), _jsx(Card.Title, { children: label }), status === undefined ? null : _jsx(Card.Value, { children: status }), children] })));
|
|
328
97
|
/**
|
|
329
|
-
* A progress (e.g. a washer's
|
|
330
|
-
*
|
|
98
|
+
* A device's progress (e.g. a washer's run): its symbol (in its tint) and
|
|
99
|
+
* its title; its parts composed in it (its children: a `Card.Progress`
|
|
100
|
+
* holding a `Card.Subtitle`, a `Card.ProgressValue`, a `Card.ProgressBar`),
|
|
101
|
+
* as the app shows them; its bar's fill in its tint (unless the bar's own).
|
|
331
102
|
*/
|
|
332
|
-
const ProgressCard = forwardRef(({ active, children, className, emphasizedIcon, icon,
|
|
103
|
+
const ProgressCard = forwardRef(({ active, children, className, emphasizedIcon, icon, label, style, tint, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, active: active, ...props, className: cn('uikit-control-cards-progress', className), "data-control-cards-part": "progress", style: withStyle({ '--uikit-card-progress-tint': tint }, style), children: [_jsx(Card.Symbol, { tint: tint ?? 'var(--color-ui-primary)', children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: label }), children] })));
|
|
333
104
|
/**
|
|
334
|
-
* A
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
105
|
+
* A run of stages in order (e.g. a washer's: Wash, Rinse, Spin, Done),
|
|
106
|
+
* shown, not chosen: its symbol (in its tint) and its title, its parts
|
|
107
|
+
* composed in it (its children: a `Card.Subtitle`, a `Card.StageList` of
|
|
108
|
+
* `Card.Stage`s, its current one its `value`), its stages in its tint
|
|
109
|
+
* (unless the list's own). Never 1x1 (see `cardSizes.stagesDisplay`).
|
|
338
110
|
*/
|
|
339
|
-
const
|
|
340
|
-
const [, rows = '1'] = (useGridItem()?.size ?? '2x2').split('x');
|
|
341
|
-
const orientation = rows === '1' ? 'horizontal' : 'vertical';
|
|
342
|
-
return (_jsx("div", { ref: ref, className: cn('uikit-control-cards-channels', className), "data-control-cards-part": "channels", "data-orientation": orientation, children: channels.map(({ label, name, tint }, index) => (_jsxs(Slider.Root, { format: { style: 'percent' }, max: 1, min: 0, orientation: orientation, step: 0.01, tint: tint, value: value[index] ?? 0, onValueChange: (next) => onValueChange?.(index, next), children: [_jsx(Slider.Control, { children: _jsxs(Slider.Track, { children: [_jsx(Slider.Indicator, {}), _jsx(Slider.Thumb, { "aria-label": name })] }) }), _jsx(Slider.Label, { "aria-hidden": "true", children: label })] }, name))) }));
|
|
343
|
-
});
|
|
111
|
+
const StagesCard = forwardRef(({ active, children, className, emphasizedIcon, icon, label, style, tint, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, active: active, ...props, className: cn('uikit-control-cards-stages', className), "data-control-cards-part": "stages", style: withStyle({ '--uikit-card-stages-tint': tint }, style), children: [_jsx(Card.Symbol, { tint: tint ?? 'var(--color-ui-primary)', children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: label }), children] })));
|
|
344
112
|
/**
|
|
345
|
-
*
|
|
346
|
-
*
|
|
113
|
+
* A light's value text by default (see `getValueText`): on, its
|
|
114
|
+
* brightness; off, its off word.
|
|
347
115
|
*/
|
|
348
|
-
const
|
|
349
|
-
const lit = channels
|
|
350
|
-
.map(({ tint }, index) => ({ tint, value: values[index] ?? 0 }))
|
|
351
|
-
.filter(({ value }) => value > 0);
|
|
352
|
-
const total = lit.reduce((sum, { value }) => sum + value, 0);
|
|
353
|
-
if (total === 0)
|
|
354
|
-
return undefined;
|
|
355
|
-
// (color-mix of two at a time, each step weighting the next by its share
|
|
356
|
-
// of what's mixed so far.)
|
|
357
|
-
let mixed = lit[0]?.tint ?? '';
|
|
358
|
-
let sum = lit[0]?.value ?? 0;
|
|
359
|
-
for (const { tint, value } of lit.slice(1)) {
|
|
360
|
-
sum += value;
|
|
361
|
-
const share = Math.round((value / sum) * 100);
|
|
362
|
-
mixed = `color-mix(in oklab, ${tint} ${String(share)}%, ${mixed})`;
|
|
363
|
-
}
|
|
364
|
-
return mixed;
|
|
365
|
-
};
|
|
116
|
+
const lightValueText = (formattedValue, _value, { checked, states: [, off] }) => (checked ? formattedValue : off);
|
|
366
117
|
/**
|
|
367
118
|
* A light of several channels (e.g. red, green, blue): a switch, lit while
|
|
368
|
-
* on, its symbol in the color
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
119
|
+
* on, its symbol in the color its channels make (see `Card.Channels`'
|
|
120
|
+
* light), its value its brightness (its strongest amount channel's share).
|
|
121
|
+
* Its channels composed in it (a `Card.Channels`, its children), shown
|
|
122
|
+
* while it's large (expanded, resized, opened). A press on its body (not on
|
|
123
|
+
* its channels: theirs, see `forwardClick`) toggles it.
|
|
124
|
+
*/
|
|
125
|
+
const Light = forwardRef(({ checked, children, className, defaultChecked = false, disabled, emphasizedIcon, format = percentFormat, getValueText = lightValueText, icon, label, locale, onCheckedChange, onClick, states = onOff, ...props }, ref) => {
|
|
126
|
+
const [isOn, switchTo] = useSwitching(checked, defaultChecked, onCheckedChange);
|
|
127
|
+
const resolvedLocale = useLocale(locale);
|
|
375
128
|
const isLarge = useIsLarge();
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
onCheckedChange?.(next);
|
|
380
|
-
};
|
|
381
|
-
return (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-light', className), "data-control-cards-part": "light", onClick: onClick ??
|
|
382
|
-
(isLarge ? undefined : forwardClick('[role=switch]:not([disabled])')), children: [_jsx(Card.Symbol, { style: color ? { color } : undefined, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Switch, { "aria-label": name, checked: isOn, tint: color, onCheckedChange: switchTo }), isLarge ? (_jsx(Channels, { channels: channels, value: values, onValueChange: (index, next) => {
|
|
383
|
-
const all = values.map((each, at) => at === index ? next : each);
|
|
384
|
-
setValues(all);
|
|
385
|
-
onValueChange?.(all);
|
|
386
|
-
} })) : null, _jsx(Card.Title, { children: name }), _jsx(Card.Value, { children: isOn
|
|
387
|
-
? formatted(Math.max(0, ...values), { format, locale })
|
|
388
|
-
: offLabel }), children] }));
|
|
389
|
-
});
|
|
390
|
-
/**
|
|
391
|
-
* A corner button expanding its card in place and making it small again
|
|
392
|
-
* (bottom trailing; its grid item's size is the app's, see Grid).
|
|
393
|
-
*/
|
|
394
|
-
const ExpandButton = ({ collapsedSize, expanded, expandedSize, label, onExpandedChange, }) => {
|
|
395
|
-
// (Each size as its item would be it now (see `useGridItem`'s
|
|
396
|
-
// `sizeOf`): the same, expanding changes nothing, hidden; outside a
|
|
397
|
-
// grid, as given.)
|
|
398
|
-
const item = useGridItem();
|
|
399
|
-
const small = item?.sizeOf(collapsedSize).size ?? collapsedSize;
|
|
400
|
-
const large = item?.sizeOf(expandedSize).size ?? expandedSize;
|
|
401
|
-
// (Its icon by where it goes: larger, expanding; smaller, collapsing
|
|
402
|
-
// (e.g. expanded smaller than it's stored).)
|
|
403
|
-
const [from, to] = expanded ? [large, small] : [small, large];
|
|
404
|
-
return (_jsx(Card.CornerButton, { mirrored: true, "aria-expanded": expanded, "aria-label": label, visible: small !== large, icon: measureOf(to) > measureOf(from) ? gridIcons.expand : gridIcons.collapse, onClick: () => onExpandedChange(!expanded) }));
|
|
405
|
-
};
|
|
406
|
-
/**
|
|
407
|
-
* How many rows of its list fit in it whole (its box filling its room in
|
|
408
|
-
* the card, see Card; a row's height its `--uikit-list-row-min-height`, as
|
|
409
|
-
* Card sets it, opened above the page too): by its height, at least one;
|
|
410
|
-
* as the card's size changes too.
|
|
411
|
-
*/
|
|
412
|
-
const rowsIn = (list) => {
|
|
413
|
-
const row = Number.parseFloat(getComputedStyle(list).getPropertyValue('--uikit-list-row-min-height')) || 30;
|
|
414
|
-
return Math.max(1, Math.floor(list.clientHeight / row));
|
|
415
|
-
};
|
|
416
|
-
const useRowsThatFit = () => {
|
|
417
|
-
const [list, setList] = useState(null);
|
|
418
|
-
const [count, setCount] = useState(1);
|
|
419
|
-
useLayoutEffect(() => {
|
|
420
|
-
if (!list)
|
|
421
|
-
return undefined;
|
|
422
|
-
const observer = new ResizeObserver(() => setCount(rowsIn(list)));
|
|
423
|
-
observer.observe(list);
|
|
424
|
-
return () => observer.disconnect();
|
|
425
|
-
}, [list]);
|
|
426
|
-
// (Also after each render, before it's painted: its tile resized in it
|
|
427
|
-
// (e.g. collapsed), its rows counted at once, not a frame late (a frame
|
|
428
|
-
// of the rows of the size it had, its last row a new one after).)
|
|
429
|
-
useLayoutEffect(() => {
|
|
430
|
-
if (!list)
|
|
431
|
-
return;
|
|
432
|
-
const read = () => setCount(rowsIn(list));
|
|
433
|
-
read();
|
|
129
|
+
const [light, setLight] = useState({
|
|
130
|
+
brightness: 1,
|
|
131
|
+
color: undefined,
|
|
434
132
|
});
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
* duration and easing): from the height it had, animated, started with
|
|
446
|
-
* the frames (see Grid's `startWithFrame`: a long task laying the page out
|
|
447
|
-
* anew, e.g. its tile expanding, not past it already, as a transition
|
|
448
|
-
* would be).
|
|
449
|
-
*/
|
|
450
|
-
const useLastRowHeight = (list, count) => {
|
|
451
|
-
const last = useRef(undefined);
|
|
452
|
-
useLayoutEffect(() => {
|
|
453
|
-
const row = list?.querySelector(':scope .uikit-list-item:last-child .uikit-list-row');
|
|
454
|
-
if (!row) {
|
|
455
|
-
last.current = undefined;
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
for (const animation of row.getAnimations()) {
|
|
459
|
-
if (animation.id === lastRowId)
|
|
460
|
-
animation.cancel();
|
|
461
|
-
}
|
|
462
|
-
const height = getComputedStyle(row).minHeight;
|
|
463
|
-
const before = last.current;
|
|
464
|
-
last.current = { count, height };
|
|
465
|
-
if (!before ||
|
|
466
|
-
before.count === count ||
|
|
467
|
-
before.height === height ||
|
|
468
|
-
reducedMotionOf(row).matches) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
startWithFrame(row.animate([{ minHeight: before.height }, { minHeight: height }], {
|
|
472
|
-
duration: reflowDuration,
|
|
473
|
-
easing: reflowEasing,
|
|
474
|
-
id: lastRowId,
|
|
475
|
-
}));
|
|
476
|
-
}, [count, list]);
|
|
477
|
-
};
|
|
478
|
-
const actionIcons = {
|
|
479
|
-
expand: gridIcons.expand,
|
|
480
|
-
less: gridIcons.collapse,
|
|
481
|
-
more: undefined,
|
|
482
|
-
open: gridIcons.open,
|
|
483
|
-
};
|
|
484
|
-
/**
|
|
485
|
-
* What a list card's last row does (see `ListCard`): open above the page,
|
|
486
|
-
* none; expanded, making it small again; rows left out, expanding it (only
|
|
487
|
-
* where that'd change its size, as `ExpandButton`), else opening it, else
|
|
488
|
-
* only counting them; none.
|
|
489
|
-
*/
|
|
490
|
-
const useListAction = ({ expansion, isLeftOut, opening, }) => {
|
|
491
|
-
const item = useGridItem();
|
|
492
|
-
if (item?.open === true)
|
|
493
|
-
return undefined;
|
|
494
|
-
const canExpand = expansion !== undefined &&
|
|
495
|
-
(item?.sizeOf(expansion.collapsedSize).size ?? expansion.collapsedSize) !==
|
|
496
|
-
(item?.sizeOf(expansion.expandedSize).size ?? expansion.expandedSize);
|
|
497
|
-
if (canExpand && expansion.expanded) {
|
|
498
|
-
return { kind: 'less', onPress: () => expansion.onExpandedChange(false) };
|
|
499
|
-
}
|
|
500
|
-
if (!isLeftOut)
|
|
501
|
-
return undefined;
|
|
502
|
-
if (canExpand) {
|
|
503
|
-
return { kind: 'expand', onPress: () => expansion.onExpandedChange(true) };
|
|
504
|
-
}
|
|
505
|
-
return opening
|
|
506
|
-
? { kind: 'open', onPress: () => item?.setOpen(true) }
|
|
507
|
-
: { kind: 'more' };
|
|
508
|
-
};
|
|
509
|
-
/**
|
|
510
|
-
* A list card's last row (see `ListCard`): its label where its rows' are
|
|
511
|
-
* (after their symbols' room, if they have them), pressed doing its
|
|
512
|
-
* action; the corner symbol for it where a value is.
|
|
513
|
-
*/
|
|
514
|
-
const ActionRow = ({ action, hasIcons, label, }) => {
|
|
515
|
-
const icon = actionIcons[action.kind];
|
|
516
|
-
const isExpanding = action.kind === 'expand' || action.kind === 'less';
|
|
517
|
-
return (_jsxs(List.Item, { "data-control-cards-part": "list-action", children: [hasIcons ? (_jsx(List.Leading, { children: _jsx(List.Image, { variant: "symbol" }) })) : null, _jsx(List.Content, { children: _jsx(List.Title, { render: action.onPress ? (_jsx("button", { "aria-expanded": isExpanding ? action.kind === 'less' : undefined, type: "button", onClick: action.onPress })) : undefined, children: label }) }), icon ? (_jsx(List.Trailing, { children: _jsx(List.Detail, { children: _jsx(Symbol, { icon: icon }) }) })) : null] }));
|
|
518
|
-
};
|
|
519
|
-
/**
|
|
520
|
-
* A summary in rows (e.g. a room's, a device's details): its symbol, its
|
|
521
|
-
* title and status beside it at its top, a glass list of rows (as many as
|
|
522
|
-
* fit whole) in a well at its bottom. Rows left out, its last row counts
|
|
523
|
-
* them, expanding or opening it (`expansion`, `opening`); expanded, it
|
|
524
|
-
* makes it small again. No rows, no list (its corner buttons instead);
|
|
525
|
-
* open above the page, an x in its top trailing corner closes it.
|
|
526
|
-
*/
|
|
527
|
-
const ListCard = forwardRef(({ children, className, emphasizedIcon, expansion, getMoreLabel = (count) => `${String(count)} more`, icon, lessLabel = 'Less', name, opening, rows, status, ...props }, ref) => {
|
|
528
|
-
const [list, fit, listElement] = useRowsThatFit();
|
|
529
|
-
const item = useGridItem();
|
|
530
|
-
const isOpen = item?.open === true;
|
|
531
|
-
const action = useListAction({
|
|
532
|
-
expansion,
|
|
533
|
-
isLeftOut: rows.length > fit,
|
|
534
|
-
opening,
|
|
133
|
+
const onLightChange = useCallback((next) => {
|
|
134
|
+
setLight((last) => last.brightness === next.brightness && last.color === next.color
|
|
135
|
+
? last
|
|
136
|
+
: next);
|
|
137
|
+
}, []);
|
|
138
|
+
const host = useMemo(() => ({ isShown: isLarge, onLightChange }), [isLarge, onLightChange]);
|
|
139
|
+
const color = isOn ? light.color : undefined;
|
|
140
|
+
const formattedValue = formatted(light.brightness, {
|
|
141
|
+
format,
|
|
142
|
+
locale: resolvedLocale,
|
|
535
143
|
});
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
: getMoreLabel(rows.length - shown.length) }, "action")) : null] }) }) })), rows.length > 0 && action?.onPress ? (_jsx(Card.CornerButton, { "aria-hidden": true, className: "uikit-control-cards-hit-area", icon: actionIcons[action.kind] ?? gridIcons.open, tabIndex: -1, onClick: action.onPress })) : null, rows.length === 0 && expansion ? (_jsx(ExpandButton, { ...expansion })) : null, rows.length === 0 && opening && !expansion ? (_jsx(Card.CornerButton, { "aria-label": opening.label, icon: gridIcons.open, visible: !isOpen, onClick: () => item?.setOpen(true) })) : null, opening ? (_jsx(Card.CornerButton, { "aria-label": opening.closeLabel, corner: "top-trailing", icon: gridIcons.close, visible: isOpen, onClick: () => item?.setOpen(false) })) : null, children] }));
|
|
542
|
-
});
|
|
543
|
-
/**
|
|
544
|
-
* Corner buttons opening its card above the page (its grid item's `open`,
|
|
545
|
-
* see `Grid.Item`), bottom trailing, and closing it (top leading), each
|
|
546
|
-
* shown as it applies.
|
|
547
|
-
*/
|
|
548
|
-
const OpenButtons = ({ closeLabel, label, }) => {
|
|
549
|
-
const item = useGridItem();
|
|
550
|
-
const isOpen = item?.open === true;
|
|
551
|
-
return (_jsxs(_Fragment, { children: [_jsx(Card.CornerButton, { "aria-label": label, icon: gridIcons.open, visible: !isOpen, onClick: () => item?.setOpen(true) }), _jsx(Card.CornerButton, { "aria-label": closeLabel, corner: "top-trailing", icon: gridIcons.close, visible: isOpen, onClick: () => item?.setOpen(false) })] }));
|
|
552
|
-
};
|
|
553
|
-
/**
|
|
554
|
-
* Its layout by its size (open above the page, that one) and its
|
|
555
|
-
* orientation (the app's; none, by its size): taller than a row, its
|
|
556
|
-
* options stacked (`upright`: vertical, or one wide) or side by side, a
|
|
557
|
-
* symbol over its words (`tall`: horizontal, or wider); one row, side by
|
|
558
|
-
* side across it (`row`: wider, not vertical); else none (`compact`: 1x1,
|
|
559
|
-
* or vertical in one row, no room to stack them). Outside a grid, a row,
|
|
560
|
-
* or stacked (vertical).
|
|
561
|
-
*/
|
|
562
|
-
const layoutOf = (orientation, isWide, isTall) => {
|
|
563
|
-
if (isTall) {
|
|
564
|
-
if (orientation === undefined)
|
|
565
|
-
return isWide ? 'tall' : 'upright';
|
|
566
|
-
return orientation === 'vertical' ? 'upright' : 'tall';
|
|
567
|
-
}
|
|
568
|
-
return isWide && orientation !== 'vertical' ? 'row' : 'compact';
|
|
569
|
-
};
|
|
570
|
-
/** Its layout (see `layoutOf`), and whether it's one wide (narrow). */
|
|
571
|
-
const useSegmentedLayout = (orientation) => {
|
|
572
|
-
const item = useGridItem();
|
|
573
|
-
if (!item)
|
|
574
|
-
return [orientation === 'vertical' ? 'upright' : 'row', false];
|
|
575
|
-
const [columns = '1', rows = '1'] = (item.open ? item.openSize : item.size).split('x');
|
|
576
|
-
const isWide = columns === '*' || Number(columns) >= 2;
|
|
577
|
-
return [layoutOf(orientation, isWide, Number(rows) >= 2), !isWide];
|
|
578
|
-
};
|
|
579
|
-
/** A segmented card's thumb, placed on an option's box (see below). */
|
|
580
|
-
const placeThumb = (thumb, on) => {
|
|
581
|
-
thumb.hidden = !on;
|
|
582
|
-
if (!on)
|
|
583
|
-
return;
|
|
584
|
-
thumb.style.setProperty('--uikit-control-cards-thumb-x', `${String(on.offsetLeft)}px`);
|
|
585
|
-
thumb.style.setProperty('--uikit-control-cards-thumb-y', `${String(on.offsetTop)}px`);
|
|
586
|
-
thumb.style.setProperty('--uikit-control-cards-thumb-width', `${String(on.offsetWidth)}px`);
|
|
587
|
-
thumb.style.setProperty('--uikit-control-cards-thumb-height', `${String(on.offsetHeight)}px`);
|
|
588
|
-
};
|
|
589
|
-
/** The option nearest a point, along the options (see `dragProps`). */
|
|
590
|
-
const nearestOption = (root, isUpright, { clientX, clientY }) => {
|
|
591
|
-
let nearest;
|
|
592
|
-
let distance = Infinity;
|
|
593
|
-
for (const option of root.querySelectorAll('[role="radio"]')) {
|
|
594
|
-
if (Object.hasOwn(option.dataset, 'disabled'))
|
|
595
|
-
continue;
|
|
596
|
-
const box = option.getBoundingClientRect();
|
|
597
|
-
const away = isUpright
|
|
598
|
-
? Math.abs(box.top + box.height / 2 - clientY)
|
|
599
|
-
: Math.abs(box.left + box.width / 2 - clientX);
|
|
600
|
-
if (!(away < distance)) {
|
|
601
|
-
continue;
|
|
602
|
-
}
|
|
603
|
-
distance = away;
|
|
604
|
-
nearest = option;
|
|
605
|
-
}
|
|
606
|
-
return nearest;
|
|
607
|
-
};
|
|
608
|
-
/**
|
|
609
|
-
* Dragging between a segmented card's options (as Segmented's, no lens:
|
|
610
|
-
* its thumb what moves): held back until it moves (`pressSlop`; a touch,
|
|
611
|
-
* `touchSlop`), then along the options (a mouse, any way), the nearest one
|
|
612
|
-
* chosen as it's reached (its thumb going there); a touch across them, or
|
|
613
|
-
* the browser panning first (it's cancelled), a scroll, let go (as a
|
|
614
|
-
* slider card's, see `pressProps`). Dragging, the page doesn't pan (see
|
|
615
|
-
* `SegmentedChoice`). Released before, a press: the option's own (its
|
|
616
|
-
* click).
|
|
617
|
-
*/
|
|
618
|
-
const dragProps = (isUpright, onChoose) => ({
|
|
619
|
-
onPointerDown: (event) => {
|
|
620
|
-
if (event.button !== 0)
|
|
621
|
-
return;
|
|
622
|
-
const root = event.currentTarget;
|
|
623
|
-
const { clientX, clientY, pointerId, pointerType } = event;
|
|
624
|
-
const isMouse = pointerType === 'mouse';
|
|
625
|
-
const slop = isMouse ? pressSlop : touchSlop;
|
|
626
|
-
let isDragging = false;
|
|
627
|
-
let under;
|
|
628
|
-
const listening = new AbortController();
|
|
629
|
-
const options = { capture: true, signal: listening.signal };
|
|
630
|
-
const end = () => {
|
|
631
|
-
listening.abort();
|
|
632
|
-
delete root.dataset.dragging;
|
|
633
|
-
};
|
|
634
|
-
addEventListener('pointermove', (move) => {
|
|
635
|
-
if (move.pointerId !== pointerId)
|
|
636
|
-
return;
|
|
637
|
-
if (!isDragging) {
|
|
638
|
-
const across = Math.abs(move.clientX - clientX);
|
|
639
|
-
const upright = Math.abs(move.clientY - clientY);
|
|
640
|
-
if (Math.hypot(across, upright) < slop)
|
|
641
|
-
return;
|
|
642
|
-
const along = isUpright ? upright : across;
|
|
643
|
-
const crossing = isUpright ? across : upright;
|
|
644
|
-
// (A touch across them: a scroll, let go.)
|
|
645
|
-
if (!isMouse && crossing > along) {
|
|
646
|
-
end();
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
isDragging = true;
|
|
650
|
-
root.dataset.dragging = '';
|
|
651
|
-
}
|
|
652
|
-
// (Its nearest option chosen as it's reached.)
|
|
653
|
-
const next = nearestOption(root, isUpright, move);
|
|
654
|
-
if (!next || next === under)
|
|
655
|
-
return;
|
|
656
|
-
under = next;
|
|
657
|
-
const { value } = next.dataset;
|
|
658
|
-
if (value !== undefined && !Object.hasOwn(next.dataset, 'checked')) {
|
|
659
|
-
onChoose(value);
|
|
660
|
-
}
|
|
661
|
-
}, options);
|
|
662
|
-
addEventListener('pointerup', (up) => {
|
|
663
|
-
if (up.pointerId !== pointerId)
|
|
664
|
-
return;
|
|
665
|
-
end();
|
|
666
|
-
if (!isDragging)
|
|
667
|
-
return;
|
|
668
|
-
// (Its click next, if any: not an option's (dragged, not pressed);
|
|
669
|
-
// none before another press or key, nothing.)
|
|
670
|
-
const clicking = new AbortController();
|
|
671
|
-
const once = { capture: true, signal: clicking.signal };
|
|
672
|
-
addEventListener('click', (clicked) => {
|
|
673
|
-
clicking.abort();
|
|
674
|
-
clicked.preventDefault();
|
|
675
|
-
clicked.stopPropagation();
|
|
676
|
-
}, once);
|
|
677
|
-
for (const type of ['pointerdown', 'keydown']) {
|
|
678
|
-
addEventListener(type, () => clicking.abort(), once);
|
|
679
|
-
}
|
|
680
|
-
}, options);
|
|
681
|
-
addEventListener('pointercancel', (cancel) => {
|
|
682
|
-
if (cancel.pointerId === pointerId)
|
|
683
|
-
end();
|
|
684
|
-
}, options);
|
|
685
|
-
},
|
|
144
|
+
return (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-light', className), "data-control-cards-part": "light", onClick: onClick ??
|
|
145
|
+
(disabled ? undefined : forwardClick('[role=switch]:not([disabled])')), children: [_jsx(Card.Symbol, { style: color ? { color } : undefined, children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Switch, { "aria-label": label, checked: isOn, disabled: disabled, tint: color, onCheckedChange: switchTo }), _jsx(Card.Title, { children: label }), _jsx(Card.Value, { children: getValueText(formattedValue, light.brightness, {
|
|
146
|
+
checked: isOn,
|
|
147
|
+
states,
|
|
148
|
+
}) }), _jsx(ChannelsHostContext.Provider, { value: host, children: children })] }));
|
|
686
149
|
});
|
|
687
|
-
const SegmentedContext = createContext(undefined);
|
|
688
|
-
/**
|
|
689
|
-
* Its options, as they've told it (in the order they did: theirs), see
|
|
690
|
-
* `SegmentedItem`.
|
|
691
|
-
*/
|
|
692
|
-
const useSegmentedOptions = () => {
|
|
693
|
-
const [options, setOptions] = useState(() => new Map());
|
|
694
|
-
const register = useCallback((value, info) => {
|
|
695
|
-
setOptions((current) => new Map(current).set(value, info));
|
|
696
|
-
return () => setOptions((current) => {
|
|
697
|
-
const next = new Map(current);
|
|
698
|
-
next.delete(value);
|
|
699
|
-
return next;
|
|
700
|
-
});
|
|
701
|
-
}, []);
|
|
702
|
-
return [options, register];
|
|
703
|
-
};
|
|
704
|
-
/**
|
|
705
|
-
* Its options' segments (a radio group, Base UI's; its options its
|
|
706
|
-
* children, see `SegmentedItem`): in a well, the chosen one's raised (a
|
|
707
|
-
* thumb, moved to it as it's chosen, by its box: its corners the well's
|
|
708
|
-
* less its padding, a pill while short); dragged between (see
|
|
709
|
-
* `dragProps`). None shown (1x1): there all the same, unseen, its options
|
|
710
|
-
* telling the card theirs.
|
|
711
|
-
*/
|
|
712
|
-
const SegmentedChoice = ({ children, isNarrow, layout, name, onValueChange, value, }) => {
|
|
713
|
-
const group = useRef(null);
|
|
714
|
-
const isShown = layout !== 'compact';
|
|
715
|
-
// (Its thumb on the chosen segment, as it's chosen and as its box
|
|
716
|
-
// changes; moved (transitioned) once it's been placed.)
|
|
717
|
-
useLayoutEffect(() => {
|
|
718
|
-
const root = group.current;
|
|
719
|
-
const thumb = root?.querySelector('[data-part="thumb"]');
|
|
720
|
-
if (!root || !thumb || !isShown)
|
|
721
|
-
return undefined;
|
|
722
|
-
const place = () => {
|
|
723
|
-
placeThumb(thumb, root.querySelector('[data-checked]'));
|
|
724
|
-
};
|
|
725
|
-
place();
|
|
726
|
-
let frame = requestAnimationFrame(() => {
|
|
727
|
-
root.dataset.placed = '';
|
|
728
|
-
});
|
|
729
|
-
// (Its box changing (e.g. its card resized, opened): there at once, as
|
|
730
|
-
// its options are; moved only as another's chosen. Its first report
|
|
731
|
-
// (as it's observed, each choice: this effect's again) no change.)
|
|
732
|
-
let size = `${String(root.offsetWidth)}x${String(root.offsetHeight)}`;
|
|
733
|
-
const observer = new ResizeObserver(() => {
|
|
734
|
-
const next = `${String(root.offsetWidth)}x${String(root.offsetHeight)}`;
|
|
735
|
-
if (next === size)
|
|
736
|
-
return;
|
|
737
|
-
size = next;
|
|
738
|
-
cancelAnimationFrame(frame);
|
|
739
|
-
delete root.dataset.placed;
|
|
740
|
-
place();
|
|
741
|
-
frame = requestAnimationFrame(() => {
|
|
742
|
-
root.dataset.placed = '';
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
observer.observe(root);
|
|
746
|
-
// (Its options changing (added, removed, laid out anew), or another
|
|
747
|
-
// marked chosen (Base UI's radios a render after its value): placed
|
|
748
|
-
// again.)
|
|
749
|
-
const mutations = new MutationObserver(place);
|
|
750
|
-
mutations.observe(root, {
|
|
751
|
-
attributeFilter: ['data-checked'],
|
|
752
|
-
childList: true,
|
|
753
|
-
subtree: true,
|
|
754
|
-
});
|
|
755
|
-
return () => {
|
|
756
|
-
cancelAnimationFrame(frame);
|
|
757
|
-
observer.disconnect();
|
|
758
|
-
mutations.disconnect();
|
|
759
|
-
};
|
|
760
|
-
}, [isShown, layout, value]);
|
|
761
|
-
// (Dragged (see `dragProps`): its touch's moves not the page's, its pan
|
|
762
|
-
// not starting as the finger strays across its options; not passive, as
|
|
763
|
-
// React's listeners are.)
|
|
764
|
-
useLayoutEffect(() => {
|
|
765
|
-
const root = group.current;
|
|
766
|
-
if (!root)
|
|
767
|
-
return undefined;
|
|
768
|
-
const hold = (move) => {
|
|
769
|
-
if (Object.hasOwn(root.dataset, 'dragging') && move.cancelable) {
|
|
770
|
-
move.preventDefault();
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
root.addEventListener('touchmove', hold, { passive: false });
|
|
774
|
-
return () => root.removeEventListener('touchmove', hold);
|
|
775
|
-
}, []);
|
|
776
|
-
return (_jsxs(BaseRadioGroup, { ref: group, "aria-label": name, className: "uikit-control-cards-segmented-choice", "data-control-cards-part": "segmented-choice", "data-layout": layout, "data-narrow": isNarrow ? '' : undefined, hidden: !isShown, value: value, onValueChange: (next) => onValueChange(next), ...dragProps(layout === 'upright', onValueChange), children: [_jsx("span", { "aria-hidden": "true", className: "uikit-control-cards-segmented-thumb", "data-part": "thumb" }), children] }));
|
|
777
|
-
};
|
|
778
150
|
/**
|
|
779
|
-
* A
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
151
|
+
* A summary in rows (e.g. a room's, a device's details): its symbol, its
|
|
152
|
+
* title and status beside it at its top, its rows (a `Card.Rows`, its
|
|
153
|
+
* children) in a well at its bottom, as many as fit whole; rows left out,
|
|
154
|
+
* its last row counts them, expanding or opening its tile (see
|
|
155
|
+
* `Card.Rows`).
|
|
784
156
|
*/
|
|
785
|
-
const
|
|
786
|
-
const context = useContext(SegmentedContext);
|
|
787
|
-
const register = context?.register;
|
|
788
|
-
useLayoutEffect(() => register?.(value, { icon, label: children, tint }), [children, icon, register, tint, value]);
|
|
789
|
-
const content = context?.content ?? 'both';
|
|
790
|
-
const hasIcon = icon !== undefined && content !== 'label';
|
|
791
|
-
const isIconOnly = hasIcon && content === 'icon';
|
|
792
|
-
return (_jsxs(BaseRadio.Root, { ref: ref, ...props, className: cn('uikit-control-cards-segmented-item', className), "data-control-cards-part": "segmented-item", "data-value": value, value: value, children: [hasIcon ? _jsx(Symbol, { icon: icon }) : null, _jsxs("span", { className: "uikit-control-cards-segmented-text", "data-unseen": isIconOnly ? '' : undefined, children: [_jsx("span", { className: "uikit-control-cards-segmented-label", children: children }), context?.layout !== 'row' && subtitle !== undefined ? (_jsx("span", { className: "uikit-control-cards-segmented-subtitle", children: subtitle })) : null] })] }));
|
|
793
|
-
});
|
|
157
|
+
const ListCard = forwardRef(({ children, className, emphasizedIcon, icon, label, status, ...props }, ref) => (_jsxs(Card.Root, { ref: ref, ...props, className: cn('uikit-control-cards-list', className), "data-control-cards-part": "list", children: [_jsx(Card.Symbol, { children: symbolOf({ emphasizedIcon, icon }) }), _jsx(Card.Title, { children: label }), status === undefined ? null : _jsx(Card.Value, { children: status }), children] })));
|
|
794
158
|
/**
|
|
795
159
|
* A device of a few modes (e.g. a heat pump's Off, Heat, Cool, Auto): its
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* its `offValue`; its symbol and tint the
|
|
801
|
-
|
|
802
|
-
|
|
160
|
+
* choice composed in it (a `Card.Segmented` of `Card.SegmentedItem`s, its
|
|
161
|
+
* children), laid out by its size; 1x1, its chosen option's words only, a
|
|
162
|
+
* press on it opening it above the page (its grid item's `openSize` given;
|
|
163
|
+
* a `Card.OpenButton` and a `Card.CloseButton` among its children). Lit
|
|
164
|
+
* while its chosen option isn't (one of) its `offValue`; its symbol and tint the
|
|
165
|
+
* chosen option's.
|
|
166
|
+
*/
|
|
167
|
+
const SegmentedCard = forwardRef(({ children, className, emphasizedIcon, icon, label, offValue, onClick, tint, ...props }, ref) => {
|
|
803
168
|
const [options, register] = useSegmentedOptions();
|
|
804
|
-
|
|
805
|
-
const
|
|
806
|
-
|
|
807
|
-
|
|
169
|
+
const [{ layout, value }, setReported] = useState({ layout: undefined, value: undefined });
|
|
170
|
+
const report = useCallback((next, nextLayout) => setReported((last) => last.value === next && last.layout === nextLayout
|
|
171
|
+
? last
|
|
172
|
+
: { layout: nextLayout, value: next }), []);
|
|
173
|
+
const host = useMemo(() => ({ register, report }), [register, report]);
|
|
808
174
|
const item = useGridItem();
|
|
809
|
-
const chosen = options.get(
|
|
175
|
+
const chosen = value === undefined ? undefined : options.get(value);
|
|
810
176
|
const isCompact = layout === 'compact';
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
177
|
+
return (_jsxs(Card.Root, { ref: ref, active: offValue === undefined || value === undefined
|
|
178
|
+
? undefined
|
|
179
|
+
: !(typeof offValue === 'string'
|
|
180
|
+
? value === offValue
|
|
181
|
+
: offValue.includes(value)), ...props, className: cn('uikit-control-cards-segmented', className), "data-control-cards-part": "segmented", onClick: onClick ??
|
|
182
|
+
(isCompact && item?.canOpen ? () => item.setOpen(true) : undefined), children: [_jsx(Card.Symbol, { tint: chosen?.tint ?? tint, children: chosen?.icon ? (_jsx(Symbol, { box: "square", icon: chosen.icon })) : (symbolOf({ emphasizedIcon, icon })) }), _jsx(Card.Title, { children: label }), layout === 'row' ? null : _jsx(Card.Value, { children: chosen?.label }), _jsx(SegmentedHostContext.Provider, { value: host, children: _jsx(OpenButtonHintContext.Provider, { value: isCompact, children: children }) })] }));
|
|
817
183
|
});
|
|
818
184
|
export const ControlCards = {
|
|
819
185
|
State,
|
|
820
186
|
Switch: SwitchCard,
|
|
821
187
|
Value,
|
|
822
188
|
Slider: SliderCard,
|
|
823
|
-
SliderFill,
|
|
824
189
|
Button,
|
|
825
190
|
Progress: ProgressCard,
|
|
191
|
+
Stages: StagesCard,
|
|
826
192
|
Light,
|
|
827
193
|
List: ListCard,
|
|
828
194
|
Segmented: SegmentedCard,
|
|
829
|
-
SegmentedItem,
|
|
830
|
-
Channels,
|
|
831
|
-
Trend,
|
|
832
|
-
ExpandButton,
|
|
833
|
-
OpenButtons,
|
|
834
195
|
};
|
|
835
196
|
//# sourceMappingURL=main.js.map
|