@seed-design/react 2.2.2 → 2.4.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/components/ActionButton/ActionButton.cjs +5 -2
- package/lib/components/ActionButton/ActionButton.d.ts.map +1 -1
- package/lib/components/ActionButton/ActionButton.js +5 -2
- package/lib/components/AttachmentDisplay/AttachmentDisplayItem.cjs +9 -6
- package/lib/components/AttachmentDisplay/AttachmentDisplayItem.d.ts.map +1 -1
- package/lib/components/AttachmentDisplay/AttachmentDisplayItem.js +9 -6
- package/lib/components/AttachmentDisplay/AttachmentDisplayTrigger.cjs +2 -1
- package/lib/components/AttachmentDisplay/AttachmentDisplayTrigger.d.ts.map +1 -1
- package/lib/components/AttachmentDisplay/AttachmentDisplayTrigger.js +2 -1
- package/lib/components/AttachmentInput/AttachmentInputItem.cjs +9 -6
- package/lib/components/AttachmentInput/AttachmentInputItem.d.ts.map +1 -1
- package/lib/components/AttachmentInput/AttachmentInputItem.js +9 -6
- package/lib/components/AttachmentInput/AttachmentInputTrigger.cjs +2 -1
- package/lib/components/AttachmentInput/AttachmentInputTrigger.d.ts.map +1 -1
- package/lib/components/AttachmentInput/AttachmentInputTrigger.js +2 -1
- package/lib/components/BottomSheet/BottomSheet.cjs +5 -3
- package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/lib/components/BottomSheet/BottomSheet.js +5 -3
- package/lib/components/Callout/Callout.cjs +3 -2
- package/lib/components/Callout/Callout.d.ts.map +1 -1
- package/lib/components/Callout/Callout.js +3 -2
- package/lib/components/Checkbox/Checkbox.cjs +2 -1
- package/lib/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/lib/components/Checkbox/Checkbox.js +2 -1
- package/lib/components/Chip/Chip.cjs +2 -1
- package/lib/components/Chip/Chip.d.ts.map +1 -1
- package/lib/components/Chip/Chip.js +2 -1
- package/lib/components/ChipTabs/ChipTabs.cjs +2 -1
- package/lib/components/ChipTabs/ChipTabs.d.ts.map +1 -1
- package/lib/components/ChipTabs/ChipTabs.js +2 -1
- package/lib/components/ContentDialog/ContentDialog.cjs +5 -3
- package/lib/components/ContentDialog/ContentDialog.d.ts.map +1 -1
- package/lib/components/ContentDialog/ContentDialog.js +5 -3
- package/lib/components/ContextualFloatingButton/ContextualFloatingButton.cjs +5 -2
- package/lib/components/ContextualFloatingButton/ContextualFloatingButton.d.ts.map +1 -1
- package/lib/components/ContextualFloatingButton/ContextualFloatingButton.js +5 -2
- package/lib/components/DatePicker/DatePicker.cjs +2 -2
- package/lib/components/DatePicker/DatePicker.d.ts +10 -4
- package/lib/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/lib/components/DatePicker/DatePicker.js +2 -2
- package/lib/components/DatePicker/index.d.ts +1 -1
- package/lib/components/DatePicker/index.d.ts.map +1 -1
- package/lib/components/FieldButton/FieldButton.cjs +2 -1
- package/lib/components/FieldButton/FieldButton.d.ts.map +1 -1
- package/lib/components/FieldButton/FieldButton.js +2 -1
- package/lib/components/FloatingActionButton/FloatingActionButton.cjs +2 -1
- package/lib/components/FloatingActionButton/FloatingActionButton.d.ts.map +1 -1
- package/lib/components/FloatingActionButton/FloatingActionButton.js +2 -1
- package/lib/components/HelpBubble/HelpBubble.cjs +2 -1
- package/lib/components/HelpBubble/HelpBubble.d.ts.map +1 -1
- package/lib/components/HelpBubble/HelpBubble.js +2 -1
- package/lib/components/ImageFrame/ImageFrame.cjs +5 -2
- package/lib/components/ImageFrame/ImageFrame.d.ts.map +1 -1
- package/lib/components/ImageFrame/ImageFrame.js +5 -2
- package/lib/components/LoadingIndicator/usePendingButton.d.ts +57 -57
- package/lib/components/MenuSheet/MenuSheet.cjs +2 -1
- package/lib/components/MenuSheet/MenuSheet.d.ts.map +1 -1
- package/lib/components/MenuSheet/MenuSheet.js +2 -1
- package/lib/components/PageBanner/PageBanner.cjs +3 -2
- package/lib/components/PageBanner/PageBanner.d.ts.map +1 -1
- package/lib/components/PageBanner/PageBanner.js +3 -2
- package/lib/components/QuantityPicker/QuantityPicker.cjs +8 -4
- package/lib/components/QuantityPicker/QuantityPicker.d.ts.map +1 -1
- package/lib/components/QuantityPicker/QuantityPicker.js +8 -4
- package/lib/components/RadioGroup/RadioGroup.cjs +2 -1
- package/lib/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/lib/components/RadioGroup/RadioGroup.js +2 -1
- package/lib/components/ReactionButton/ReactionButton.cjs +5 -2
- package/lib/components/ReactionButton/ReactionButton.d.ts.map +1 -1
- package/lib/components/ReactionButton/ReactionButton.js +5 -2
- package/lib/components/ScrollFog/ScrollFog.d.ts +4 -6
- package/lib/components/ScrollFog/ScrollFog.d.ts.map +1 -1
- package/lib/components/ScrollFog/ScrollFog.test.d.ts +2 -0
- package/lib/components/ScrollFog/ScrollFog.test.d.ts.map +1 -0
- package/lib/components/SideNavigation/SideNavigation.cjs +1 -1
- package/lib/components/SideNavigation/SideNavigation.js +1 -1
- package/lib/components/SidePanel/SidePanel.cjs +5 -3
- package/lib/components/SidePanel/SidePanel.d.ts.map +1 -1
- package/lib/components/SidePanel/SidePanel.js +5 -3
- package/lib/components/Slider/Slider.cjs +1 -1
- package/lib/components/Slider/Slider.js +1 -1
- package/lib/components/Snackbar/Snackbar.cjs +2 -1
- package/lib/components/Snackbar/Snackbar.d.ts.map +1 -1
- package/lib/components/Snackbar/Snackbar.js +2 -1
- package/lib/components/SwipeableMenuSheet/SwipeableMenuSheet.cjs +2 -1
- package/lib/components/SwipeableMenuSheet/SwipeableMenuSheet.d.ts.map +1 -1
- package/lib/components/SwipeableMenuSheet/SwipeableMenuSheet.js +2 -1
- package/lib/components/Switch/Switch.cjs +2 -1
- package/lib/components/Switch/Switch.d.ts.map +1 -1
- package/lib/components/Switch/Switch.js +2 -1
- package/lib/components/Tabs/Tabs.cjs +2 -1
- package/lib/components/Tabs/Tabs.d.ts.map +1 -1
- package/lib/components/Tabs/Tabs.js +2 -1
- package/lib/components/TextField/TextField.cjs +1 -1
- package/lib/components/TextField/TextField.js +1 -1
- package/lib/components/TextField/useTextFieldWithGraphemes.cjs +2 -5
- package/lib/components/TextField/useTextFieldWithGraphemes.d.ts.map +1 -1
- package/lib/components/TextField/useTextFieldWithGraphemes.js +3 -6
- package/lib/components/ToggleButton/ToggleButton.cjs +5 -2
- package/lib/components/ToggleButton/ToggleButton.d.ts.map +1 -1
- package/lib/components/ToggleButton/ToggleButton.js +5 -2
- package/lib/components/WheelPicker/WheelPicker.cjs +94 -0
- package/lib/components/WheelPicker/WheelPicker.d.ts +56 -0
- package/lib/components/WheelPicker/WheelPicker.d.ts.map +1 -0
- package/lib/components/WheelPicker/WheelPicker.js +89 -0
- package/lib/components/WheelPicker/WheelPicker.namespace.cjs +15 -0
- package/lib/components/WheelPicker/WheelPicker.namespace.d.ts +2 -0
- package/lib/components/WheelPicker/WheelPicker.namespace.d.ts.map +1 -0
- package/lib/components/WheelPicker/WheelPicker.namespace.js +10 -0
- package/lib/components/WheelPicker/WheelPicker.test.d.ts +2 -0
- package/lib/components/WheelPicker/WheelPicker.test.d.ts.map +1 -0
- package/lib/components/WheelPicker/index.cjs +12 -0
- package/lib/components/WheelPicker/index.d.ts +3 -0
- package/lib/components/WheelPicker/index.d.ts.map +1 -0
- package/lib/components/WheelPicker/index.js +3 -0
- package/lib/components/index.cjs +11 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.d.ts.map +1 -1
- package/lib/components/index.js +3 -1
- package/lib/components/private/WheelPicker.cjs +2 -3
- package/lib/components/private/WheelPicker.d.ts +3 -3
- package/lib/components/private/WheelPicker.d.ts.map +1 -1
- package/lib/components/private/WheelPicker.js +3 -3
- package/lib/components/private/useDismissible.d.ts +123 -123
- package/lib/index.cjs +14 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -1
- package/lib/utils/elementSizeVars.cjs +76 -0
- package/lib/utils/elementSizeVars.d.ts +15 -0
- package/lib/utils/elementSizeVars.d.ts.map +1 -0
- package/lib/utils/elementSizeVars.js +74 -0
- package/lib/utils/scaleFeedback.cjs +99 -0
- package/lib/utils/scaleFeedback.d.ts +58 -0
- package/lib/utils/scaleFeedback.d.ts.map +1 -0
- package/lib/utils/scaleFeedback.js +94 -0
- package/package.json +7 -7
- package/src/components/ActionButton/ActionButton.tsx +5 -2
- package/src/components/AttachmentDisplay/AttachmentDisplayItem.tsx +14 -9
- package/src/components/AttachmentDisplay/AttachmentDisplayTrigger.tsx +7 -4
- package/src/components/AttachmentInput/AttachmentInputItem.tsx +14 -9
- package/src/components/AttachmentInput/AttachmentInputTrigger.tsx +3 -3
- package/src/components/BottomSheet/BottomSheet.tsx +5 -3
- package/src/components/Callout/Callout.tsx +9 -4
- package/src/components/Checkbox/Checkbox.tsx +3 -3
- package/src/components/Chip/Chip.tsx +2 -1
- package/src/components/ChipTabs/ChipTabs.tsx +3 -3
- package/src/components/ContentDialog/ContentDialog.tsx +5 -3
- package/src/components/ContextualFloatingButton/ContextualFloatingButton.tsx +5 -2
- package/src/components/DatePicker/DatePicker.test.tsx +70 -0
- package/src/components/DatePicker/DatePicker.tsx +17 -16
- package/src/components/DatePicker/index.ts +2 -0
- package/src/components/FieldButton/FieldButton.tsx +6 -3
- package/src/components/FloatingActionButton/FloatingActionButton.tsx +4 -4
- package/src/components/HelpBubble/HelpBubble.tsx +7 -4
- package/src/components/HelpBubbleTooltip/HelpBubbleTooltip.tsx +1 -1
- package/src/components/ImageFrame/ImageFrame.tsx +8 -1
- package/src/components/MenuSheet/MenuSheet.tsx +6 -3
- package/src/components/PageBanner/PageBanner.tsx +5 -6
- package/src/components/QuantityPicker/QuantityPicker.tsx +8 -4
- package/src/components/RadioGroup/RadioGroup.tsx +7 -4
- package/src/components/ReactionButton/ReactionButton.tsx +5 -2
- package/src/components/ScrollFog/ScrollFog.test.tsx +13 -0
- package/src/components/ScrollFog/ScrollFog.tsx +5 -7
- package/src/components/SidePanel/SidePanel.tsx +5 -3
- package/src/components/Snackbar/Snackbar.tsx +6 -3
- package/src/components/SwipeableMenuSheet/SwipeableMenuSheet.tsx +7 -4
- package/src/components/Switch/Switch.tsx +3 -3
- package/src/components/Tabs/Tabs.tsx +3 -3
- package/src/components/TextField/useTextFieldWithGraphemes.ts +3 -7
- package/src/components/ToggleButton/ToggleButton.tsx +5 -2
- package/src/components/WheelPicker/WheelPicker.namespace.ts +9 -0
- package/src/components/WheelPicker/WheelPicker.test.tsx +270 -0
- package/src/components/WheelPicker/WheelPicker.tsx +210 -0
- package/src/components/WheelPicker/index.ts +11 -0
- package/src/components/index.ts +1 -0
- package/src/components/private/WheelPicker.test.tsx +1 -0
- package/src/components/private/WheelPicker.tsx +6 -6
- package/src/index.ts +2 -0
- package/src/utils/elementSizeVars.tsx +112 -0
- package/src/utils/scaleFeedback.tsx +128 -0
- package/lib/components/TextField/memoize.cjs +0 -13
- package/lib/components/TextField/memoize.d.ts +0 -2
- package/lib/components/TextField/memoize.d.ts.map +0 -1
- package/lib/components/TextField/memoize.js +0 -13
- package/src/components/TextField/memoize.ts +0 -14
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SCALE_FEEDBACK_CLASS_NAME } from "@seed-design/css/scale-feedback";
|
|
2
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3
|
+
import { createSlot } from "@radix-ui/react-slot";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { useElementSizeVars } from "./elementSizeVars";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Opts an element into scale feedback: put `scaleFeedbackRef` and
|
|
10
|
+
* `scaleFeedbackClassName` on the same element, and it publishes
|
|
11
|
+
* `--seed-feedback-scale`, a ratio that shrinks it by a fixed 2px when consumed.
|
|
12
|
+
* `ScaleFeedback` pairs them up for an element you render; reach for the hook when
|
|
13
|
+
* you can't wrap one, such as inside a component already assembling its own
|
|
14
|
+
* `ref` and `className`.
|
|
15
|
+
*
|
|
16
|
+
* The two halves belong together — the size vars `useElementSizeVars` publishes,
|
|
17
|
+
* and the class that derives the ratio from them — so the hook hands them back
|
|
18
|
+
* as a pair. If one goes missing the derivation stays guaranteed-invalid and
|
|
19
|
+
* `--seed-feedback-scale` resolves to 1: a mistake costs the effect rather than
|
|
20
|
+
* producing a wrong scale.
|
|
21
|
+
*
|
|
22
|
+
* Applying the ratio is yours, because the selector that scales the element is
|
|
23
|
+
* usually the same one that changes its background, and splitting them across
|
|
24
|
+
* two rules lets them fire under different conditions:
|
|
25
|
+
*
|
|
26
|
+
* .my-button {
|
|
27
|
+
* transition: background-color 0.2s, var(--seed-feedback-scale-transition);
|
|
28
|
+
* }
|
|
29
|
+
* .my-button:active {
|
|
30
|
+
* background-color: ...;
|
|
31
|
+
* scale: var(--seed-feedback-scale);
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* The resting `scale: 1` comes with the class rather than with the rule above:
|
|
35
|
+
* it keeps the element a stacking context throughout, instead of becoming one
|
|
36
|
+
* mid-press and dragging `position: fixed` descendants with it.
|
|
37
|
+
*/
|
|
38
|
+
export function useScaleFeedback() {
|
|
39
|
+
const { sizeVarsRef } = useElementSizeVars();
|
|
40
|
+
|
|
41
|
+
return { scaleFeedbackRef: sizeVarsRef, scaleFeedbackClassName: SCALE_FEEDBACK_CLASS_NAME };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ScaleFeedbackSlot = createSlot("ScaleFeedback");
|
|
45
|
+
|
|
46
|
+
export interface ScaleFeedbackProps {
|
|
47
|
+
children: React.ReactElement;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Opts its child into scale feedback, so the ref and the class can no longer
|
|
52
|
+
* land on different elements or go missing one at a time. The child keeps its own
|
|
53
|
+
* `ref` and `className`, and applying the ratio is still yours — see
|
|
54
|
+
* `useScaleFeedback` for the rule this expects you to write.
|
|
55
|
+
*
|
|
56
|
+
* There is no `asChild` prop because rendering an element of our own is never the
|
|
57
|
+
* right answer: that element would be the one measured, and a block wrapper around
|
|
58
|
+
* an inline-block button reports the container's width, so the ratio would come
|
|
59
|
+
* out wrong rather than absent. The resting `scale: 1` would settle on the wrapper
|
|
60
|
+
* too, leaving the child to become a stacking context mid-press.
|
|
61
|
+
*/
|
|
62
|
+
export const ScaleFeedback = React.forwardRef<HTMLElement, ScaleFeedbackProps>(
|
|
63
|
+
({ children }, ref) => {
|
|
64
|
+
const { scaleFeedbackRef, scaleFeedbackClassName } = useScaleFeedback();
|
|
65
|
+
|
|
66
|
+
const childRef = React.useRef<HTMLElement | null>(null);
|
|
67
|
+
const composedRef = useComposedRefs(scaleFeedbackRef, childRef, ref);
|
|
68
|
+
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
if (process.env.NODE_ENV === "production") return;
|
|
71
|
+
|
|
72
|
+
// Slot throws on children it can't slot onto, but a Fragment child is a valid
|
|
73
|
+
// element it silently declines to hand a ref to, and a component child is free
|
|
74
|
+
// to drop what it is handed. Both leave a ratio of 1 and no other trace.
|
|
75
|
+
const node = childRef.current;
|
|
76
|
+
if (!node) {
|
|
77
|
+
console.warn(
|
|
78
|
+
"ScaleFeedback: the child never forwarded `ref` to a DOM element, so its size is never measured. A Fragment cannot receive one.",
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!node.classList.contains(SCALE_FEEDBACK_CLASS_NAME)) {
|
|
84
|
+
console.warn(
|
|
85
|
+
"ScaleFeedback: the child dropped the `className` it was handed, so no ratio is derived. Forward `className` to the element that takes `ref`.",
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<ScaleFeedbackSlot ref={composedRef} className={scaleFeedbackClassName}>
|
|
92
|
+
{children}
|
|
93
|
+
</ScaleFeedbackSlot>
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
ScaleFeedback.displayName = "ScaleFeedback";
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Wraps a component so its element opts into scale feedback — for one-liner
|
|
102
|
+
* factory components (`withContext`/`withProvider` results). Hand-written
|
|
103
|
+
* forwardRef components call `useScaleFeedback` directly instead.
|
|
104
|
+
*/
|
|
105
|
+
export function withScaleFeedback<P>(
|
|
106
|
+
Component: React.ForwardRefExoticComponent<P>,
|
|
107
|
+
): React.ForwardRefExoticComponent<P>;
|
|
108
|
+
export function withScaleFeedback(
|
|
109
|
+
Component: React.ForwardRefExoticComponent<
|
|
110
|
+
React.RefAttributes<HTMLElement> & { className?: string }
|
|
111
|
+
>,
|
|
112
|
+
): React.ForwardRefExoticComponent<React.RefAttributes<HTMLElement> & { className?: string }> {
|
|
113
|
+
const Pressable = React.forwardRef<HTMLElement, { className?: string }>((props, ref) => {
|
|
114
|
+
const { scaleFeedbackRef, scaleFeedbackClassName } = useScaleFeedback();
|
|
115
|
+
const composedRef = useComposedRefs(scaleFeedbackRef, ref);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<Component
|
|
119
|
+
{...props}
|
|
120
|
+
ref={composedRef}
|
|
121
|
+
className={clsx(scaleFeedbackClassName, props.className)}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
Pressable.displayName = Component.displayName;
|
|
127
|
+
return Pressable;
|
|
128
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
//#region src/components/TextField/memoize.ts
|
|
3
|
-
function memoize(fn) {
|
|
4
|
-
const cache = /* @__PURE__ */ new Map();
|
|
5
|
-
return (arg) => {
|
|
6
|
-
if (cache.has(arg)) return cache.get(arg);
|
|
7
|
-
const result = fn(arg);
|
|
8
|
-
cache.set(arg, result);
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
exports.memoize = memoize;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/memoize.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAanF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
//#region src/components/TextField/memoize.ts
|
|
3
|
-
function memoize(fn) {
|
|
4
|
-
const cache = /* @__PURE__ */ new Map();
|
|
5
|
-
return (arg) => {
|
|
6
|
-
if (cache.has(arg)) return cache.get(arg);
|
|
7
|
-
const result = fn(arg);
|
|
8
|
-
cache.set(arg, result);
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { memoize };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function memoize<Arg, Result>(fn: (arg: Arg) => Result): (arg: Arg) => Result {
|
|
2
|
-
const cache = new Map<Arg, Result>();
|
|
3
|
-
|
|
4
|
-
return (arg: Arg) => {
|
|
5
|
-
if (cache.has(arg)) {
|
|
6
|
-
return cache.get(arg) as Result;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const result = fn(arg);
|
|
10
|
-
cache.set(arg, result);
|
|
11
|
-
|
|
12
|
-
return result;
|
|
13
|
-
};
|
|
14
|
-
}
|