@knitui/components 0.8.1 → 0.10.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/lib/commonjs/ActionIcon/ActionIcon.js +4 -2
- package/lib/commonjs/ActionIcon/ActionIcon.js.map +1 -1
- package/lib/commonjs/Affix/Affix.js +3 -1
- package/lib/commonjs/Affix/Affix.js.map +1 -1
- package/lib/commonjs/Button/Button.js +38 -3
- package/lib/commonjs/Button/Button.js.map +1 -1
- package/lib/commonjs/CloseButton/CloseButton.js +7 -0
- package/lib/commonjs/CloseButton/CloseButton.js.map +1 -1
- package/lib/commonjs/Modal/modal-base.js +4 -2
- package/lib/commonjs/Modal/modal-base.js.map +1 -1
- package/lib/commonjs/Pill/Pill.js +1 -1
- package/lib/commonjs/Popover/Popover.shared.js +3 -1
- package/lib/commonjs/Popover/Popover.shared.js.map +1 -1
- package/lib/commonjs/Portal/OverlayHost.js +147 -0
- package/lib/commonjs/Portal/OverlayHost.js.map +1 -0
- package/lib/commonjs/Portal/index.js +25 -0
- package/lib/commonjs/Portal/index.js.map +1 -1
- package/lib/commonjs/SegmentedControl/SegmentedControl.js +7 -1
- package/lib/commonjs/SegmentedControl/SegmentedControl.js.map +1 -1
- package/lib/commonjs/Tabs/Tabs.js +8 -1
- package/lib/commonjs/Tabs/Tabs.js.map +1 -1
- package/lib/commonjs/Tooltip/Tooltip.js +3 -1
- package/lib/commonjs/Tooltip/Tooltip.js.map +1 -1
- package/lib/commonjs/floating/platform.js +4 -1
- package/lib/commonjs/floating/platform.js.map +1 -1
- package/lib/commonjs/floating/platform.native.js +15 -5
- package/lib/commonjs/floating/platform.native.js.map +1 -1
- package/lib/commonjs/floating/use-position.js +9 -3
- package/lib/commonjs/floating/use-position.js.map +1 -1
- package/lib/commonjs/index.js +24 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/control-icon-size.js +5 -1
- package/lib/commonjs/internal/control-icon-size.js.map +1 -1
- package/lib/commonjs/internal/control-metrics.js +13 -9
- package/lib/commonjs/internal/control-metrics.js.map +1 -1
- package/lib/commonjs/internal/style-props.js +36 -6
- package/lib/commonjs/internal/style-props.js.map +1 -1
- package/lib/module/ActionIcon/ActionIcon.js +5 -3
- package/lib/module/ActionIcon/ActionIcon.js.map +1 -1
- package/lib/module/Affix/Affix.js +4 -2
- package/lib/module/Affix/Affix.js.map +1 -1
- package/lib/module/Button/Button.js +40 -5
- package/lib/module/Button/Button.js.map +1 -1
- package/lib/module/CloseButton/CloseButton.js +8 -1
- package/lib/module/CloseButton/CloseButton.js.map +1 -1
- package/lib/module/Modal/modal-base.js +5 -3
- package/lib/module/Modal/modal-base.js.map +1 -1
- package/lib/module/Pill/Pill.js +1 -1
- package/lib/module/Popover/Popover.shared.js +4 -2
- package/lib/module/Popover/Popover.shared.js.map +1 -1
- package/lib/module/Portal/OverlayHost.js +138 -0
- package/lib/module/Portal/OverlayHost.js.map +1 -0
- package/lib/module/Portal/index.js +5 -0
- package/lib/module/Portal/index.js.map +1 -1
- package/lib/module/SegmentedControl/SegmentedControl.js +9 -3
- package/lib/module/SegmentedControl/SegmentedControl.js.map +1 -1
- package/lib/module/Tabs/Tabs.js +9 -2
- package/lib/module/Tabs/Tabs.js.map +1 -1
- package/lib/module/Tooltip/Tooltip.js +4 -2
- package/lib/module/Tooltip/Tooltip.js.map +1 -1
- package/lib/module/floating/platform.js +4 -1
- package/lib/module/floating/platform.js.map +1 -1
- package/lib/module/floating/platform.native.js +15 -5
- package/lib/module/floating/platform.native.js.map +1 -1
- package/lib/module/floating/use-position.js +9 -3
- package/lib/module/floating/use-position.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/control-icon-size.js +5 -1
- package/lib/module/internal/control-icon-size.js.map +1 -1
- package/lib/module/internal/control-metrics.js +13 -9
- package/lib/module/internal/control-metrics.js.map +1 -1
- package/lib/module/internal/style-props.js +33 -4
- package/lib/module/internal/style-props.js.map +1 -1
- package/lib/typescript/ActionIcon/ActionIcon.d.ts +5 -0
- package/lib/typescript/ActionIcon/ActionIcon.d.ts.map +1 -1
- package/lib/typescript/Affix/Affix.d.ts.map +1 -1
- package/lib/typescript/Button/Button.d.ts +6 -0
- package/lib/typescript/Button/Button.d.ts.map +1 -1
- package/lib/typescript/CloseButton/CloseButton.d.ts.map +1 -1
- package/lib/typescript/Input/shared.d.ts +3 -3
- package/lib/typescript/Modal/modal-base.d.ts.map +1 -1
- package/lib/typescript/Popover/Popover.shared.d.ts.map +1 -1
- package/lib/typescript/Portal/OverlayHost.d.ts +46 -0
- package/lib/typescript/Portal/OverlayHost.d.ts.map +1 -0
- package/lib/typescript/Portal/index.d.ts +6 -1
- package/lib/typescript/Portal/index.d.ts.map +1 -1
- package/lib/typescript/Portal/types.d.ts +10 -0
- package/lib/typescript/Portal/types.d.ts.map +1 -1
- package/lib/typescript/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/lib/typescript/Tabs/Tabs.d.ts.map +1 -1
- package/lib/typescript/Tooltip/Tooltip.d.ts.map +1 -1
- package/lib/typescript/floating/platform.d.ts +1 -1
- package/lib/typescript/floating/platform.d.ts.map +1 -1
- package/lib/typescript/floating/platform.native.d.ts +7 -1
- package/lib/typescript/floating/platform.native.d.ts.map +1 -1
- package/lib/typescript/floating/use-position.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/internal/control-icon-size.d.ts.map +1 -1
- package/lib/typescript/internal/control-metrics.d.ts +13 -9
- package/lib/typescript/internal/control-metrics.d.ts.map +1 -1
- package/lib/typescript/internal/style-props.d.ts +23 -4
- package/lib/typescript/internal/style-props.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/ActionIcon/ActionIcon.tsx +10 -3
- package/src/Affix/Affix.tsx +4 -2
- package/src/Button/Button.tsx +69 -19
- package/src/CloseButton/CloseButton.tsx +7 -1
- package/src/Modal/modal-base.tsx +5 -3
- package/src/Pill/Pill.tsx +1 -1
- package/src/Popover/Popover.shared.tsx +4 -2
- package/src/Portal/OverlayHost.tsx +141 -0
- package/src/Portal/index.ts +11 -1
- package/src/Portal/types.ts +11 -0
- package/src/SegmentedControl/SegmentedControl.tsx +8 -2
- package/src/Tabs/Tabs.tsx +9 -1
- package/src/Tooltip/Tooltip.tsx +4 -2
- package/src/floating/platform.native.ts +13 -4
- package/src/floating/platform.ts +3 -0
- package/src/floating/use-position.tsx +13 -3
- package/src/index.ts +5 -0
- package/src/internal/control-icon-size.ts +5 -1
- package/src/internal/control-metrics.ts +13 -9
- package/src/internal/style-props.ts +32 -4
|
@@ -5,12 +5,13 @@ import { useUncontrolled } from "@knitui/hooks";
|
|
|
5
5
|
|
|
6
6
|
import { Box, type BoxProps } from "../Box";
|
|
7
7
|
import { HiddenInput } from "../internal/hidden-input";
|
|
8
|
-
import { useReducedTransition } from "../internal/motion";
|
|
8
|
+
import { usePressScale, useReducedTransition } from "../internal/motion";
|
|
9
9
|
import {
|
|
10
10
|
animateOnlyProps,
|
|
11
11
|
controlFontVariant,
|
|
12
12
|
controlVariant,
|
|
13
13
|
focusRingStyle,
|
|
14
|
+
pressScaleStyle,
|
|
14
15
|
radiusVariant,
|
|
15
16
|
shadowVariant,
|
|
16
17
|
type SizeKey,
|
|
@@ -101,6 +102,8 @@ const SegmentedControlControl = styled(Box, {
|
|
|
101
102
|
backgroundColor: "transparent",
|
|
102
103
|
zIndex: 1,
|
|
103
104
|
...focusRingStyle,
|
|
105
|
+
// The shared control press dip (see Tabs) — a segment had no press state at all.
|
|
106
|
+
...pressScaleStyle,
|
|
104
107
|
|
|
105
108
|
variants: {
|
|
106
109
|
size: {
|
|
@@ -123,7 +126,7 @@ const SegmentedControlControl = styled(Box, {
|
|
|
123
126
|
true: { flex: 1 },
|
|
124
127
|
},
|
|
125
128
|
itemDisabled: {
|
|
126
|
-
true: { opacity: 0.
|
|
129
|
+
true: { opacity: 0.6, pointerEvents: "none", ...webCursor("default") },
|
|
127
130
|
},
|
|
128
131
|
} as const,
|
|
129
132
|
|
|
@@ -250,6 +253,8 @@ const SegmentedControlBase = SegmentedControlRoot.styleable<SegmentedControlProp
|
|
|
250
253
|
...rest
|
|
251
254
|
} = props;
|
|
252
255
|
|
|
256
|
+
// Reduced-motion-aware easing for each segment's press dip.
|
|
257
|
+
const press = usePressScale();
|
|
253
258
|
const indicatorTransition = useReducedTransition(
|
|
254
259
|
timedTransition(transitionDuration, transitionTimingFunction),
|
|
255
260
|
);
|
|
@@ -388,6 +393,7 @@ const SegmentedControlBase = SegmentedControlRoot.styleable<SegmentedControlProp
|
|
|
388
393
|
/>
|
|
389
394
|
) : null}
|
|
390
395
|
<SegmentedControlControl
|
|
396
|
+
{...press}
|
|
391
397
|
size={size}
|
|
392
398
|
active={active}
|
|
393
399
|
grow={fullWidth}
|
package/src/Tabs/Tabs.tsx
CHANGED
|
@@ -5,11 +5,13 @@ import { useId, useUncontrolled } from "@knitui/hooks";
|
|
|
5
5
|
|
|
6
6
|
import { Box, type BoxProps } from "../Box";
|
|
7
7
|
import { controlMetrics as M } from "../internal/control-metrics";
|
|
8
|
+
import { usePressScale } from "../internal/motion";
|
|
8
9
|
import { renderTextChild } from "../internal/render-text-child";
|
|
9
10
|
import {
|
|
10
11
|
controlFontVariant,
|
|
11
12
|
controlVariant,
|
|
12
13
|
focusRingStyle,
|
|
14
|
+
pressScaleStyle,
|
|
13
15
|
radiusVariant,
|
|
14
16
|
type SizeKey,
|
|
15
17
|
webCursor,
|
|
@@ -246,6 +248,10 @@ const TabTabFrame = styled(Box, {
|
|
|
246
248
|
...webCursor("pointer"),
|
|
247
249
|
userSelect: "none",
|
|
248
250
|
position: "relative",
|
|
251
|
+
// The press dip every other kit control has (Button, ActionIcon, Chip). A tab
|
|
252
|
+
// swapped its colour and nothing else, so it was the one control whose press
|
|
253
|
+
// didn't feel like a press. Eased by `usePressScale()` at render.
|
|
254
|
+
...pressScaleStyle,
|
|
249
255
|
|
|
250
256
|
variants: {
|
|
251
257
|
variant: {
|
|
@@ -292,7 +298,7 @@ const TabTabFrame = styled(Box, {
|
|
|
292
298
|
xxl: { ...controlVariant.xxl, gap: M.xxl.gap },
|
|
293
299
|
},
|
|
294
300
|
disabled: {
|
|
295
|
-
true: { opacity: 0.
|
|
301
|
+
true: { opacity: 0.6, pointerEvents: "none" },
|
|
296
302
|
},
|
|
297
303
|
} as const,
|
|
298
304
|
|
|
@@ -382,6 +388,7 @@ export interface TabsTabProps extends Omit<
|
|
|
382
388
|
}
|
|
383
389
|
|
|
384
390
|
const TabsTab = TabTabFrame.styleable<TabsTabProps>(function TabsTab(props, ref) {
|
|
391
|
+
const press = usePressScale();
|
|
385
392
|
const { value, children, leftSection, rightSection, disabled, ...rest } = props;
|
|
386
393
|
const ctx = React.useContext(TabsContext);
|
|
387
394
|
const s = useTabsSlots();
|
|
@@ -453,6 +460,7 @@ const TabsTab = TabTabFrame.styleable<TabsTabProps>(function TabsTab(props, ref)
|
|
|
453
460
|
return (
|
|
454
461
|
<TabTabFrame
|
|
455
462
|
ref={ref}
|
|
463
|
+
{...press}
|
|
456
464
|
variant={ctx.variant}
|
|
457
465
|
size={ctx.size}
|
|
458
466
|
active={isActive}
|
package/src/Tooltip/Tooltip.tsx
CHANGED
|
@@ -33,7 +33,7 @@ import { type MotionPresetName } from "../internal/motion";
|
|
|
33
33
|
import { useOverlayChrome } from "../internal/overlay-chrome";
|
|
34
34
|
import { radiusVariant, shadowVariant } from "../internal/style-props";
|
|
35
35
|
import { type SlotStyles } from "../internal/styles";
|
|
36
|
-
import { Portal } from "../Portal";
|
|
36
|
+
import { Portal, useOverlayHost } from "../Portal";
|
|
37
37
|
import { Text } from "../Text";
|
|
38
38
|
import {
|
|
39
39
|
type OverlayTransitionConfig,
|
|
@@ -478,6 +478,8 @@ const TooltipBase = TooltipLabelFrame.styleable<TooltipProps>(function Tooltip(p
|
|
|
478
478
|
);
|
|
479
479
|
|
|
480
480
|
const themeName = useThemeName();
|
|
481
|
+
// The nearest scoped `OverlayHost` (a native modal screen), else "root".
|
|
482
|
+
const overlayHost = useOverlayHost();
|
|
481
483
|
// Enter/exit animation via the shared `Transition` engine (honours reduced
|
|
482
484
|
// motion; label now also animates OUT before unmounting).
|
|
483
485
|
const t = useOverlayTransition({ mounted: open, keepMounted, animation, ...transitionProps });
|
|
@@ -574,7 +576,7 @@ const TooltipBase = TooltipLabelFrame.styleable<TooltipProps>(function Tooltip(p
|
|
|
574
576
|
const dropdownSlot = s.get("dropdown");
|
|
575
577
|
|
|
576
578
|
const labelNode = !t.rendered ? null : (
|
|
577
|
-
<Portal hostName={withinPortal ?
|
|
579
|
+
<Portal hostName={withinPortal ? overlayHost : undefined}>
|
|
578
580
|
<Theme name={themeName}>
|
|
579
581
|
<TooltipLabelFrame
|
|
580
582
|
ref={floatingRef}
|
|
@@ -142,23 +142,32 @@ export function getViewport(): Rect {
|
|
|
142
142
|
* consumer reports it from `onLayout` — reliable and timely); otherwise it's
|
|
143
143
|
* measured as a fallback. The container origin accounts for the Android status
|
|
144
144
|
* bar so the window-space placement lands correctly in the full-screen host.
|
|
145
|
+
*
|
|
146
|
+
* `hostNode` is a scoped `OverlayHost`'s frame, when the floating element
|
|
147
|
+
* teleports into one instead of the root host. That host is NOT at the window
|
|
148
|
+
* origin (an iOS `formSheet` starts below the status bar), so its origin is
|
|
149
|
+
* measured in the same window space as the reference — which also makes the
|
|
150
|
+
* Android status-bar correction unnecessary for it.
|
|
145
151
|
*/
|
|
146
152
|
export async function measure(
|
|
147
153
|
referenceNode: TamaguiElement | null,
|
|
148
154
|
floatingNode: TamaguiElement | null,
|
|
149
155
|
_strategy: Strategy,
|
|
150
156
|
floatingSize?: Dimensions | null,
|
|
157
|
+
hostNode?: unknown,
|
|
151
158
|
): Promise<MeasureResult> {
|
|
152
159
|
const hasSize =
|
|
153
160
|
!!floatingSize && isFiniteNumber(floatingSize.width) && isFiniteNumber(floatingSize.height);
|
|
154
161
|
|
|
155
|
-
const [reference, floating] = await Promise.all([
|
|
162
|
+
const [reference, floating, host] = await Promise.all([
|
|
156
163
|
measureWindowRect(referenceNode),
|
|
157
164
|
hasSize ? Promise.resolve(null) : measureWindowRect(floatingNode),
|
|
165
|
+
hostNode ? measureWindowRect(hostNode as TamaguiElement) : Promise.resolve(null),
|
|
158
166
|
]);
|
|
167
|
+
const containerOrigin = host ? { x: host.x, y: host.y } : getHostOrigin();
|
|
159
168
|
|
|
160
169
|
if (!reference) {
|
|
161
|
-
return { reference: null, floating: null, containerOrigin
|
|
170
|
+
return { reference: null, floating: null, containerOrigin };
|
|
162
171
|
}
|
|
163
172
|
|
|
164
173
|
const size: Dimensions | null = hasSize
|
|
@@ -168,10 +177,10 @@ export async function measure(
|
|
|
168
177
|
: null;
|
|
169
178
|
|
|
170
179
|
if (!size) {
|
|
171
|
-
return { reference: null, floating: null, containerOrigin
|
|
180
|
+
return { reference: null, floating: null, containerOrigin };
|
|
172
181
|
}
|
|
173
182
|
|
|
174
|
-
return { reference, floating: size, containerOrigin
|
|
183
|
+
return { reference, floating: size, containerOrigin };
|
|
175
184
|
}
|
|
176
185
|
|
|
177
186
|
/**
|
package/src/floating/platform.ts
CHANGED
|
@@ -54,6 +54,9 @@ export function measure(
|
|
|
54
54
|
// Web reads the floating size synchronously from the DOM, so the `onLayout`
|
|
55
55
|
// size hint the native platform uses is accepted for signature parity only.
|
|
56
56
|
_floatingSize?: Dimensions | null,
|
|
57
|
+
// A scoped `OverlayHost` frame (native only): web derives the container origin
|
|
58
|
+
// from the floating element's own `offsetParent`, wherever it was teleported.
|
|
59
|
+
_hostNode?: unknown,
|
|
57
60
|
): Promise<MeasureResult> {
|
|
58
61
|
const reference = asHTMLElement(referenceNode);
|
|
59
62
|
const floating = asHTMLElement(floatingNode);
|
|
@@ -11,6 +11,7 @@ import * as React from "react";
|
|
|
11
11
|
|
|
12
12
|
import type { TamaguiElement } from "@knitui/core";
|
|
13
13
|
|
|
14
|
+
import { useOverlayHostFrame } from "../Portal/OverlayHost";
|
|
14
15
|
import {
|
|
15
16
|
computePosition,
|
|
16
17
|
type Dimensions,
|
|
@@ -135,10 +136,13 @@ export function usePosition(props: UsePositionProps): UsePositionReturn {
|
|
|
135
136
|
// final layout's measurement is never dropped).
|
|
136
137
|
const measuringRef = React.useRef(false);
|
|
137
138
|
const pendingRef = React.useRef(false);
|
|
139
|
+
// A scoped `OverlayHost`'s frame when this overlay renders inside one (native
|
|
140
|
+
// measures its window origin); `null` under the root host.
|
|
141
|
+
const hostFrameRef = useOverlayHostFrame();
|
|
138
142
|
|
|
139
143
|
// Latest config, read by the stable `update` callback so it never goes stale.
|
|
140
|
-
const latest = React.useRef({ placement, strategy, middleware });
|
|
141
|
-
latest.current = { placement, strategy, middleware };
|
|
144
|
+
const latest = React.useRef({ placement, strategy, middleware, hostFrameRef });
|
|
145
|
+
latest.current = { placement, strategy, middleware, hostFrameRef };
|
|
142
146
|
|
|
143
147
|
const [data, setData] = React.useState<PositionData>({
|
|
144
148
|
x: null,
|
|
@@ -178,7 +182,13 @@ export function usePosition(props: UsePositionProps): UsePositionReturn {
|
|
|
178
182
|
pendingRef.current = false;
|
|
179
183
|
|
|
180
184
|
const cfg = latest.current;
|
|
181
|
-
void measure(
|
|
185
|
+
void measure(
|
|
186
|
+
reference,
|
|
187
|
+
floating,
|
|
188
|
+
cfg.strategy,
|
|
189
|
+
floatingSizeRef.current,
|
|
190
|
+
cfg.hostFrameRef?.current ?? null,
|
|
191
|
+
)
|
|
182
192
|
.then((m) => {
|
|
183
193
|
if (!mountedRef.current || !m.reference || !m.floating) return;
|
|
184
194
|
// Wait for real layout: a 0×0 box means the element hasn't laid out yet,
|
package/src/index.ts
CHANGED
|
@@ -393,13 +393,18 @@ export {
|
|
|
393
393
|
type PopoverWidth,
|
|
394
394
|
} from "./Popover";
|
|
395
395
|
export {
|
|
396
|
+
OverlayHost,
|
|
397
|
+
type OverlayHostProps,
|
|
396
398
|
Portal,
|
|
397
399
|
PortalHost,
|
|
398
400
|
type PortalHostProps,
|
|
399
401
|
type PortalProps,
|
|
400
402
|
PortalProvider,
|
|
401
403
|
type PortalProviderProps,
|
|
404
|
+
ROOT_OVERLAY_HOST,
|
|
405
|
+
useOverlayHost,
|
|
402
406
|
usePortal,
|
|
407
|
+
useTopmostOverlayHost,
|
|
403
408
|
} from "./Portal";
|
|
404
409
|
export {
|
|
405
410
|
Progress,
|
|
@@ -43,5 +43,9 @@ const isSizeKey = (value: unknown): value is SizeKey =>
|
|
|
43
43
|
*/
|
|
44
44
|
export const controlIconSize = (size: SizeKey | number | string | undefined): number => {
|
|
45
45
|
if (typeof size === "number") return size;
|
|
46
|
-
|
|
46
|
+
// A size TOKEN (`"$sm"`) names the same step as its bare key. Callers holding
|
|
47
|
+
// token-typed sizes (Pill's remove button passes `iconSize="$sm"`) used to fall
|
|
48
|
+
// through to the `md` 20px here, so every Pill's ✕ drew at 20px whatever its size.
|
|
49
|
+
const key = typeof size === "string" && size.startsWith("$") ? size.slice(1) : size;
|
|
50
|
+
return isSizeKey(key) ? CONTROL_ICON_SIZE[key] : CONTROL_ICON_SIZE.md;
|
|
47
51
|
};
|
|
@@ -15,17 +15,21 @@ import { getTokenValue } from "@knitui/core";
|
|
|
15
15
|
* design rationale (balanced text-to-height ratio, capped radius curve).
|
|
16
16
|
*
|
|
17
17
|
* key height font ratio padX padX(pill) gap radius
|
|
18
|
-
* xxs
|
|
19
|
-
* xs
|
|
20
|
-
* sm 32 14 .44
|
|
21
|
-
* md 40
|
|
22
|
-
* lg 48 20 .42
|
|
23
|
-
* xl
|
|
24
|
-
* xxl
|
|
18
|
+
* xxs 18 12 .67 2 4 2 2
|
|
19
|
+
* xs 24 12 .50 4 8 2 2
|
|
20
|
+
* sm 32 14 .44 8 12 4 4
|
|
21
|
+
* md 40 16 .40 12 16 4 4
|
|
22
|
+
* lg 48 20 .42 16 24 8 8
|
|
23
|
+
* xl 64 24 .38 24 24 8 8
|
|
24
|
+
* xxl 96 28 .29 32 32 12 16
|
|
25
|
+
*
|
|
26
|
+
* (Resolved from `core/config/scales.ts`; this table had drifted from it.)
|
|
25
27
|
*
|
|
26
28
|
* `fontSize` is intentionally CLAMPED at the bottom two steps (xxs/xs borrow the
|
|
27
29
|
* 12px `$xxs` font instead of their same-key font) so tiny controls aren't
|
|
28
|
-
* dominated by text
|
|
30
|
+
* dominated by text. `md` takes `$sm` (16), not its same-key 18: 18px put the
|
|
31
|
+
* default 40px control's label at heading size — larger than the body text
|
|
32
|
+
* around it — and left no 16 step between `sm` (14) and `lg` (20). `borderRadius` is
|
|
29
33
|
* CAPPED at `$lg` (16) so large controls stay rectangles, not accidental pills.
|
|
30
34
|
* `paddingHorizontalPill` is the standard padding bumped one space step — the one
|
|
31
35
|
* sanctioned divergence, used by the pill family (Badge/Chip/Pill).
|
|
@@ -57,7 +61,7 @@ export const controlMetrics = {
|
|
|
57
61
|
},
|
|
58
62
|
md: {
|
|
59
63
|
height: "$md",
|
|
60
|
-
fontSize: "$
|
|
64
|
+
fontSize: "$sm",
|
|
61
65
|
paddingHorizontal: "$md",
|
|
62
66
|
paddingHorizontalPill: "$lg",
|
|
63
67
|
gap: "$xs",
|
|
@@ -165,6 +165,16 @@ export const squareSizeVariant = {
|
|
|
165
165
|
xxl: { minWidth: M.xxl.height, width: M.xxl.height, height: M.xxl.height },
|
|
166
166
|
} as const;
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* The corner a square control (`ActionIcon`, `ThemeIcon`) takes from `sm` to `xl`
|
|
170
|
+
* — `$md` (8), the SAME corner `Button` uses at every size. They used to read
|
|
171
|
+
* `controlMetrics.borderRadius` (4 at sm/md), so an icon button beside a labelled
|
|
172
|
+
* one at the same height was visibly squarer than it. The tiny steps keep the
|
|
173
|
+
* table's 2px (an 8px corner on an 18–24px square reads as a circle); `xxl` keeps
|
|
174
|
+
* its 16.
|
|
175
|
+
*/
|
|
176
|
+
const SQUARE_CONTROL_RADIUS = "$md";
|
|
177
|
+
|
|
168
178
|
export const squareSizeRoundedVariant = {
|
|
169
179
|
xxs: {
|
|
170
180
|
minWidth: M.xxs.height,
|
|
@@ -182,25 +192,25 @@ export const squareSizeRoundedVariant = {
|
|
|
182
192
|
minWidth: M.sm.height,
|
|
183
193
|
width: M.sm.height,
|
|
184
194
|
height: M.sm.height,
|
|
185
|
-
borderRadius:
|
|
195
|
+
borderRadius: SQUARE_CONTROL_RADIUS,
|
|
186
196
|
},
|
|
187
197
|
md: {
|
|
188
198
|
minWidth: M.md.height,
|
|
189
199
|
width: M.md.height,
|
|
190
200
|
height: M.md.height,
|
|
191
|
-
borderRadius:
|
|
201
|
+
borderRadius: SQUARE_CONTROL_RADIUS,
|
|
192
202
|
},
|
|
193
203
|
lg: {
|
|
194
204
|
minWidth: M.lg.height,
|
|
195
205
|
width: M.lg.height,
|
|
196
206
|
height: M.lg.height,
|
|
197
|
-
borderRadius:
|
|
207
|
+
borderRadius: SQUARE_CONTROL_RADIUS,
|
|
198
208
|
},
|
|
199
209
|
xl: {
|
|
200
210
|
minWidth: M.xl.height,
|
|
201
211
|
width: M.xl.height,
|
|
202
212
|
height: M.xl.height,
|
|
203
|
-
borderRadius:
|
|
213
|
+
borderRadius: SQUARE_CONTROL_RADIUS,
|
|
204
214
|
},
|
|
205
215
|
xxl: {
|
|
206
216
|
minWidth: M.xxl.height,
|
|
@@ -491,6 +501,24 @@ export const WEB_BUTTON_PROPS: { render?: "button"; type?: string } = Object.fre
|
|
|
491
501
|
|
|
492
502
|
export const webButton = (): { render?: "button"; type?: string } => WEB_BUTTON_PROPS;
|
|
493
503
|
|
|
504
|
+
/**
|
|
505
|
+
* {@link WEB_BUTTON_PROPS}, or — when the control NAVIGATES — a real `<a href>`
|
|
506
|
+
* with `role="link"`. A control that goes somewhere must be a link on web, or
|
|
507
|
+
* middle-click / ⌘-click / "copy link" / the hover URL preview all silently fail;
|
|
508
|
+
* wrapping a `<button>` in an `<a>` instead nests interactive content (an axe
|
|
509
|
+
* `nested-interactive` failure). So the button-like frames take `href` and swap
|
|
510
|
+
* their host element here. Native has no link host: `href` is dropped there and
|
|
511
|
+
* the caller's `onPress` does the navigating.
|
|
512
|
+
*
|
|
513
|
+
* The anchor keeps the browser's default click behaviour; an app that routes
|
|
514
|
+
* in-app cancels it itself (e.g. `preventDefault` in a capture-phase click
|
|
515
|
+
* handler for plain clicks, letting modified clicks through).
|
|
516
|
+
*/
|
|
517
|
+
export const webButtonOrLink = (
|
|
518
|
+
href: string | undefined,
|
|
519
|
+
): { render?: "button" | "a"; type?: string; href?: string; role?: "link" } =>
|
|
520
|
+
isWeb && href ? { render: "a", href, role: "link" } : WEB_BUTTON_PROPS;
|
|
521
|
+
|
|
494
522
|
/**
|
|
495
523
|
* Web-only reset for the native `<button>` user-agent `text-align: center`.
|
|
496
524
|
* Returned as a raw `style` fragment to spread onto the element's `style` prop —
|