@kanso-labs/react-native-kanso-ui 0.9.0 → 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/README.md +4 -3
- package/dist/autocomplete/index.js +15 -1
- package/dist/autocomplete/index.js.map +1 -1
- package/dist/button/group.d.ts +5 -0
- package/dist/button/group.js +115 -0
- package/dist/button/group.js.map +1 -0
- package/dist/button/index.d.ts +4 -1
- package/dist/button/index.js +44 -22
- package/dist/button/index.js.map +1 -1
- package/dist/button/slots.js +2 -1
- package/dist/button/slots.js.map +1 -1
- package/dist/calendar/index.js +351 -182
- package/dist/calendar/index.js.map +1 -1
- package/dist/calendar/styles.js +33 -2
- package/dist/calendar/styles.js.map +1 -1
- package/dist/carousel/arrangement.d.ts +5 -0
- package/dist/carousel/arrangement.js +123 -0
- package/dist/carousel/arrangement.js.map +1 -0
- package/dist/chequer/index.js +95 -0
- package/dist/chequer/index.js.map +1 -0
- package/dist/collection/index.d.ts +157 -0
- package/dist/collection/index.js +1331 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/color-thumb/index.js +56 -0
- package/dist/color-thumb/index.js.map +1 -0
- package/dist/components/button/index.d.ts +4 -2
- package/dist/components/button/index.js +227 -188
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button-group/index.d.ts +87 -0
- package/dist/components/button-group/index.js +275 -0
- package/dist/components/button-group/index.js.map +1 -0
- package/dist/components/calendar/index.d.ts +11 -3
- package/dist/components/calendar/index.js +60 -45
- package/dist/components/calendar/index.js.map +1 -1
- package/dist/components/carousel/index.d.ts +72 -0
- package/dist/components/carousel/index.js +496 -0
- package/dist/components/carousel/index.js.map +1 -0
- package/dist/components/checkbox-group/index.d.ts +3 -4
- package/dist/components/checkbox-group/index.js +1 -1
- package/dist/components/checkbox-group/index.js.map +1 -1
- package/dist/components/color-area/index.d.ts +85 -0
- package/dist/components/color-area/index.js +630 -0
- package/dist/components/color-area/index.js.map +1 -0
- package/dist/components/color-field/index.d.ts +144 -0
- package/dist/components/color-field/index.js +516 -0
- package/dist/components/color-field/index.js.map +1 -0
- package/dist/components/color-picker/index.d.ts +74 -0
- package/dist/components/color-picker/index.js +317 -0
- package/dist/components/color-picker/index.js.map +1 -0
- package/dist/components/color-slider/index.d.ts +82 -0
- package/dist/components/color-slider/index.js +456 -0
- package/dist/components/color-slider/index.js.map +1 -0
- package/dist/components/color-swatch/index.d.ts +46 -0
- package/dist/components/color-swatch/index.js +127 -0
- package/dist/components/color-swatch/index.js.map +1 -0
- package/dist/components/color-swatch-picker/index.d.ts +81 -0
- package/dist/components/color-swatch-picker/index.js +287 -0
- package/dist/components/color-swatch-picker/index.js.map +1 -0
- package/dist/components/color-wheel/index.d.ts +71 -0
- package/dist/components/color-wheel/index.js +407 -0
- package/dist/components/color-wheel/index.js.map +1 -0
- package/dist/components/combo-box/index.d.ts +193 -0
- package/dist/components/combo-box/index.js +616 -0
- package/dist/components/combo-box/index.js.map +1 -0
- package/dist/components/date-field/index.d.ts +120 -0
- package/dist/components/date-field/index.js +111 -0
- package/dist/components/date-field/index.js.map +1 -0
- package/dist/components/date-picker/index.d.ts +130 -0
- package/dist/components/date-picker/index.js +310 -0
- package/dist/components/date-picker/index.js.map +1 -0
- package/dist/components/date-range-picker/index.d.ts +139 -0
- package/dist/components/date-range-picker/index.js +421 -0
- package/dist/components/date-range-picker/index.js.map +1 -0
- package/dist/components/disclosure/index.d.ts +94 -0
- package/dist/components/disclosure/index.js +365 -0
- package/dist/components/disclosure/index.js.map +1 -0
- package/dist/components/disclosure-group/index.d.ts +61 -0
- package/dist/components/disclosure-group/index.js +100 -0
- package/dist/components/disclosure-group/index.js.map +1 -0
- package/dist/components/drop-zone/index.d.ts +113 -0
- package/dist/components/drop-zone/index.js +304 -0
- package/dist/components/drop-zone/index.js.map +1 -0
- package/dist/components/fab/index.d.ts +1 -1
- package/dist/components/fab/index.js +91 -76
- package/dist/components/fab/index.js.map +1 -1
- package/dist/components/form/index.d.ts +3 -2
- package/dist/components/form/index.js.map +1 -1
- package/dist/components/icon-button/index.d.ts +4 -2
- package/dist/components/icon-button/index.js +204 -171
- package/dist/components/icon-button/index.js.map +1 -1
- package/dist/components/list/index.d.ts +15 -158
- package/dist/components/list/index.js +21 -1047
- package/dist/components/list/index.js.map +1 -1
- package/dist/components/list-box/index.d.ts +73 -0
- package/dist/components/list-box/index.js +82 -0
- package/dist/components/list-box/index.js.map +1 -0
- package/dist/components/loading-indicator/index.d.ts +32 -0
- package/dist/components/loading-indicator/index.js +174 -0
- package/dist/components/loading-indicator/index.js.map +1 -0
- package/dist/components/navigation-tree/index.d.ts +117 -0
- package/dist/components/navigation-tree/index.js +135 -0
- package/dist/components/navigation-tree/index.js.map +1 -0
- package/dist/components/number-field/index.js +132 -143
- package/dist/components/number-field/index.js.map +1 -1
- package/dist/components/range-calendar/index.d.ts +69 -0
- package/dist/components/range-calendar/index.js +144 -0
- package/dist/components/range-calendar/index.js.map +1 -0
- package/dist/components/search-view/index.d.ts +78 -0
- package/dist/components/search-view/index.js +570 -0
- package/dist/components/search-view/index.js.map +1 -0
- package/dist/components/select/index.d.ts +152 -0
- package/dist/components/select/index.js +419 -0
- package/dist/components/select/index.js.map +1 -0
- package/dist/components/slider/index.d.ts +111 -0
- package/dist/components/slider/index.js +673 -0
- package/dist/components/slider/index.js.map +1 -0
- package/dist/components/split-button/index.d.ts +77 -0
- package/dist/components/split-button/index.js +354 -0
- package/dist/components/split-button/index.js.map +1 -0
- package/dist/components/tabs/index.d.ts +196 -0
- package/dist/components/tabs/index.js +1137 -0
- package/dist/components/tabs/index.js.map +1 -0
- package/dist/components/time-field/index.d.ts +43 -0
- package/dist/components/time-field/index.js +107 -0
- package/dist/components/time-field/index.js.map +1 -0
- package/dist/components/time-picker/index.d.ts +65 -0
- package/dist/components/time-picker/index.js +1168 -0
- package/dist/components/time-picker/index.js.map +1 -0
- package/dist/components/tooltip/index.d.ts +101 -0
- package/dist/components/tooltip/index.js +223 -0
- package/dist/components/tooltip/index.js.map +1 -0
- package/dist/components/tree/index.d.ts +112 -0
- package/dist/components/tree/index.js +157 -0
- package/dist/components/tree/index.js.map +1 -0
- package/dist/disclosure/chevron.js +75 -0
- package/dist/disclosure/chevron.js.map +1 -0
- package/dist/disclosure/index.js +7 -0
- package/dist/disclosure/index.js.map +1 -0
- package/dist/drop/index.d.ts +54 -0
- package/dist/drop/index.js +161 -0
- package/dist/drop/index.js.map +1 -0
- package/dist/field/chevron.js +74 -0
- package/dist/field/chevron.js.map +1 -0
- package/dist/field/index.d.ts +2 -1
- package/dist/field/index.js +310 -154
- package/dist/field/index.js.map +1 -1
- package/dist/field/styles.js +9 -0
- package/dist/field/styles.js.map +1 -1
- package/dist/files/index.d.ts +18 -0
- package/dist/files/index.js +107 -0
- package/dist/files/index.js.map +1 -0
- package/dist/form/index.d.ts +5 -2
- package/dist/form/index.js +64 -85
- package/dist/form/index.js.map +1 -1
- package/dist/glyphs/index.js +92 -1
- package/dist/glyphs/index.js.map +1 -1
- package/dist/i18n/index.js +20 -1
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/messages.js +1394 -34
- package/dist/i18n/messages.js.map +1 -1
- package/dist/index.d.ts +35 -3
- package/dist/index.js +34 -3
- package/dist/indicator/paths.js +23 -1
- package/dist/indicator/paths.js.map +1 -1
- package/dist/modal/index.js +92 -77
- package/dist/modal/index.js.map +1 -1
- package/dist/number/keyboard.js +16 -0
- package/dist/number/keyboard.js.map +1 -0
- package/dist/overlay/anchored.js +68 -38
- package/dist/overlay/anchored.js.map +1 -1
- package/dist/overlay/keyboard.js +57 -0
- package/dist/overlay/keyboard.js.map +1 -0
- package/dist/overlay/panel.js +173 -19
- package/dist/overlay/panel.js.map +1 -1
- package/dist/overlay/placement.js +13 -1
- package/dist/overlay/placement.js.map +1 -1
- package/dist/picker/index.js +322 -0
- package/dist/picker/index.js.map +1 -0
- package/dist/press/index.d.ts +2 -0
- package/dist/press/index.js +102 -100
- package/dist/press/index.js.map +1 -1
- package/dist/row/index.js +77 -69
- package/dist/row/index.js.map +1 -1
- package/dist/row/styles.js +13 -2
- package/dist/row/styles.js.map +1 -1
- package/dist/segments/field.js +277 -0
- package/dist/segments/field.js.map +1 -0
- package/dist/segments/index.js +574 -0
- package/dist/segments/index.js.map +1 -0
- package/dist/segments/styles.js +24 -0
- package/dist/segments/styles.js.map +1 -0
- package/dist/slider/index.js +145 -0
- package/dist/slider/index.js.map +1 -0
- package/dist/swatch/index.js +56 -0
- package/dist/swatch/index.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { useTheme } from "../../theme/scope.js";
|
|
2
|
+
import { composeStyles, themedStyles } from "../../theme/styles.js";
|
|
3
|
+
import { useLocaleOf } from "../../i18n/provider.js";
|
|
4
|
+
import { HIDDEN } from "../../glyphs/hidden.js";
|
|
5
|
+
import { ColorThumb } from "../../color-thumb/index.js";
|
|
6
|
+
import { ADJUSTABLE } from "../../slider/index.js";
|
|
7
|
+
import { usePickedColor } from "../../swatch/index.js";
|
|
8
|
+
import { c } from "react/compiler-runtime";
|
|
9
|
+
import { I18nManager, StyleSheet, View } from "react-native";
|
|
10
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import Svg, { Path } from "react-native-svg";
|
|
13
|
+
import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
|
|
14
|
+
import { useColorWheelState } from "react-stately/useColorWheelState";
|
|
15
|
+
//#region src/components/color-wheel/index.tsx
|
|
16
|
+
const DEFAULT_OUTER_RADIUS = 100;
|
|
17
|
+
const DEFAULT_THICKNESS = 16;
|
|
18
|
+
const SLOP = 10;
|
|
19
|
+
const TARGET = 48;
|
|
20
|
+
const OVERLAP = .5;
|
|
21
|
+
const HUES = Array.from({ length: 360 }, (_, hue) => hue);
|
|
22
|
+
const styles = StyleSheet.create({
|
|
23
|
+
root: { boxSizing: "border-box" },
|
|
24
|
+
seat: {
|
|
25
|
+
alignItems: "center",
|
|
26
|
+
height: TARGET,
|
|
27
|
+
justifyContent: "center",
|
|
28
|
+
marginStart: -24,
|
|
29
|
+
marginTop: -24,
|
|
30
|
+
position: "absolute",
|
|
31
|
+
width: TARGET
|
|
32
|
+
},
|
|
33
|
+
thumb: { pointerEvents: "none" }
|
|
34
|
+
});
|
|
35
|
+
const stylesOf = themedStyles(({ stateLayerOpacity }) => StyleSheet.create({ disabled: { opacity: stateLayerOpacity.disabledContent } }));
|
|
36
|
+
function adjustOf(state, isDisabled) {
|
|
37
|
+
return (event) => {
|
|
38
|
+
const { actionName } = event.nativeEvent;
|
|
39
|
+
if (isDisabled || actionName !== "increment" && actionName !== "decrement") return;
|
|
40
|
+
state.setDragging(true);
|
|
41
|
+
if (actionName === "increment") state.increment(state.step);
|
|
42
|
+
else state.decrement(state.step);
|
|
43
|
+
state.setDragging(false);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hue as a ring, with a handle on it. Its state is React Stately's, as web's
|
|
48
|
+
* is: pass `value` with `onChange` to control it, or `defaultValue`, as a
|
|
49
|
+
* CSS colour string or a `Color` from `parseColor`, which this package
|
|
50
|
+
* re-exports.
|
|
51
|
+
*
|
|
52
|
+
* ```tsx
|
|
53
|
+
* <ColorWheel defaultValue="hsl(200, 100%, 50%)" />
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* A wheel moves hue and nothing else, so unlike `ColorSlider` and
|
|
57
|
+
* `ColorArea` it names no channel and there is no space for one to be
|
|
58
|
+
* missing from: a hex value works here.
|
|
59
|
+
*
|
|
60
|
+
* The middle is empty rather than filled, so a `ColorArea` or a
|
|
61
|
+
* `ColorSwatch` can sit inside one. A press on the ring moves the handle
|
|
62
|
+
* there, and a drag carries it round. A screen reader hears "Hue", or
|
|
63
|
+
* `aria-label`, with the value. `style`, `ref` and `testID` land on the
|
|
64
|
+
* wheel, whose size comes from `outerRadius`. With a `testID`, the drag and
|
|
65
|
+
* the press are registered with Gesture Handler as `<testID>-pan` and
|
|
66
|
+
* `<testID>-tap`, which its `getByGestureTestId` finds in a test.
|
|
67
|
+
*
|
|
68
|
+
* Inside a `ColorPicker` it takes the picker's colour where it is given no
|
|
69
|
+
* `value`, and reports a change to the picker before its own `onChange`.
|
|
70
|
+
*/
|
|
71
|
+
function ColorWheel(t0) {
|
|
72
|
+
const $ = c(64);
|
|
73
|
+
const { "aria-label": ariaLabel, defaultValue, isDisabled: t1, onChange, onChangeEnd, outerRadius: t2, ref, style, testID, thickness: t3, value } = t0;
|
|
74
|
+
const isDisabled = t1 === void 0 ? false : t1;
|
|
75
|
+
const outerRadius = t2 === void 0 ? DEFAULT_OUTER_RADIUS : t2;
|
|
76
|
+
const thickness = t3 === void 0 ? DEFAULT_THICKNESS : t3;
|
|
77
|
+
const own = stylesOf(useTheme());
|
|
78
|
+
const locale = useLocaleOf(void 0);
|
|
79
|
+
const picked = usePickedColor(value, onChange);
|
|
80
|
+
let t4;
|
|
81
|
+
if ($[0] !== defaultValue || $[1] !== isDisabled || $[2] !== onChangeEnd || $[3] !== picked.onChange || $[4] !== picked.value) {
|
|
82
|
+
t4 = {
|
|
83
|
+
defaultValue,
|
|
84
|
+
isDisabled,
|
|
85
|
+
onChange: picked.onChange,
|
|
86
|
+
onChangeEnd,
|
|
87
|
+
value: picked.value
|
|
88
|
+
};
|
|
89
|
+
$[0] = defaultValue;
|
|
90
|
+
$[1] = isDisabled;
|
|
91
|
+
$[2] = onChangeEnd;
|
|
92
|
+
$[3] = picked.onChange;
|
|
93
|
+
$[4] = picked.value;
|
|
94
|
+
$[5] = t4;
|
|
95
|
+
} else t4 = $[5];
|
|
96
|
+
const state = useColorWheelState(t4);
|
|
97
|
+
const innerRadius = Math.max(0, outerRadius - thickness);
|
|
98
|
+
const thumbRadius = (innerRadius + outerRadius) / 2;
|
|
99
|
+
const t5 = Math.max(outerRadius - innerRadius, TARGET) / 2;
|
|
100
|
+
let t6;
|
|
101
|
+
if ($[6] !== isDisabled || $[7] !== outerRadius || $[8] !== state || $[9] !== t5 || $[10] !== testID || $[11] !== thumbRadius) {
|
|
102
|
+
t6 = {
|
|
103
|
+
isDisabled,
|
|
104
|
+
outerRadius,
|
|
105
|
+
reach: t5,
|
|
106
|
+
state,
|
|
107
|
+
testID,
|
|
108
|
+
thumbRadius
|
|
109
|
+
};
|
|
110
|
+
$[6] = isDisabled;
|
|
111
|
+
$[7] = outerRadius;
|
|
112
|
+
$[8] = state;
|
|
113
|
+
$[9] = t5;
|
|
114
|
+
$[10] = testID;
|
|
115
|
+
$[11] = thumbRadius;
|
|
116
|
+
$[12] = t6;
|
|
117
|
+
} else t6 = $[12];
|
|
118
|
+
const gesture = useWheelGesture(t6);
|
|
119
|
+
let t7;
|
|
120
|
+
if ($[13] !== state || $[14] !== thumbRadius) {
|
|
121
|
+
t7 = state.getThumbPosition(thumbRadius);
|
|
122
|
+
$[13] = state;
|
|
123
|
+
$[14] = thumbRadius;
|
|
124
|
+
$[15] = t7;
|
|
125
|
+
} else t7 = $[15];
|
|
126
|
+
const { x, y } = t7;
|
|
127
|
+
const color = state.value;
|
|
128
|
+
let t8;
|
|
129
|
+
if ($[16] !== color) {
|
|
130
|
+
t8 = color.getChannelRange("hue");
|
|
131
|
+
$[16] = color;
|
|
132
|
+
$[17] = t8;
|
|
133
|
+
} else t8 = $[17];
|
|
134
|
+
const { maxValue, minValue } = t8;
|
|
135
|
+
const T0 = View;
|
|
136
|
+
const t9 = composeStyles(styles.root, {
|
|
137
|
+
height: outerRadius * 2,
|
|
138
|
+
width: outerRadius * 2
|
|
139
|
+
}, isDisabled ? own.disabled : void 0, style);
|
|
140
|
+
let t10;
|
|
141
|
+
if ($[18] !== innerRadius || $[19] !== outerRadius) {
|
|
142
|
+
t10 = /* @__PURE__ */ jsx(Ring, {
|
|
143
|
+
innerRadius,
|
|
144
|
+
outerRadius
|
|
145
|
+
});
|
|
146
|
+
$[18] = innerRadius;
|
|
147
|
+
$[19] = outerRadius;
|
|
148
|
+
$[20] = t10;
|
|
149
|
+
} else t10 = $[20];
|
|
150
|
+
let t11;
|
|
151
|
+
if ($[21] !== ariaLabel || $[22] !== color || $[23] !== locale) {
|
|
152
|
+
t11 = ariaLabel ?? color.getChannelName("hue", locale);
|
|
153
|
+
$[21] = ariaLabel;
|
|
154
|
+
$[22] = color;
|
|
155
|
+
$[23] = locale;
|
|
156
|
+
$[24] = t11;
|
|
157
|
+
} else t11 = $[24];
|
|
158
|
+
const t12 = state.hue;
|
|
159
|
+
let t13;
|
|
160
|
+
if ($[25] !== color || $[26] !== locale) {
|
|
161
|
+
t13 = color.formatChannelValue("hue", locale);
|
|
162
|
+
$[25] = color;
|
|
163
|
+
$[26] = locale;
|
|
164
|
+
$[27] = t13;
|
|
165
|
+
} else t13 = $[27];
|
|
166
|
+
let t14;
|
|
167
|
+
if ($[28] !== color || $[29] !== locale) {
|
|
168
|
+
t14 = color.getHueName(locale);
|
|
169
|
+
$[28] = color;
|
|
170
|
+
$[29] = locale;
|
|
171
|
+
$[30] = t14;
|
|
172
|
+
} else t14 = $[30];
|
|
173
|
+
const t15 = `${t13}, ${t14}`;
|
|
174
|
+
let t16;
|
|
175
|
+
if ($[31] !== isDisabled || $[32] !== state) {
|
|
176
|
+
t16 = adjustOf(state, isDisabled);
|
|
177
|
+
$[31] = isDisabled;
|
|
178
|
+
$[32] = state;
|
|
179
|
+
$[33] = t16;
|
|
180
|
+
} else t16 = $[33];
|
|
181
|
+
const t17 = outerRadius + (I18nManager.isRTL ? -x : x);
|
|
182
|
+
const t18 = outerRadius + y;
|
|
183
|
+
let t19;
|
|
184
|
+
if ($[34] !== t17 || $[35] !== t18) {
|
|
185
|
+
t19 = composeStyles(styles.seat, {
|
|
186
|
+
start: t17,
|
|
187
|
+
top: t18
|
|
188
|
+
});
|
|
189
|
+
$[34] = t17;
|
|
190
|
+
$[35] = t18;
|
|
191
|
+
$[36] = t19;
|
|
192
|
+
} else t19 = $[36];
|
|
193
|
+
let t20;
|
|
194
|
+
if ($[37] !== state) {
|
|
195
|
+
t20 = state.getDisplayColor();
|
|
196
|
+
$[37] = state;
|
|
197
|
+
$[38] = t20;
|
|
198
|
+
} else t20 = $[38];
|
|
199
|
+
let t21;
|
|
200
|
+
if ($[39] !== state.isDragging || $[40] !== t20) {
|
|
201
|
+
t21 = /* @__PURE__ */ jsx(View, {
|
|
202
|
+
style: styles.thumb,
|
|
203
|
+
children: /* @__PURE__ */ jsx(ColorThumb, {
|
|
204
|
+
color: t20,
|
|
205
|
+
dragging: state.isDragging
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
$[39] = state.isDragging;
|
|
209
|
+
$[40] = t20;
|
|
210
|
+
$[41] = t21;
|
|
211
|
+
} else t21 = $[41];
|
|
212
|
+
let t22;
|
|
213
|
+
if ($[42] !== isDisabled || $[43] !== maxValue || $[44] !== minValue || $[45] !== state.hue || $[46] !== t11 || $[47] !== t15 || $[48] !== t16 || $[49] !== t19 || $[50] !== t21) {
|
|
214
|
+
t22 = /* @__PURE__ */ jsx(View, {
|
|
215
|
+
accessibilityActions: ADJUSTABLE,
|
|
216
|
+
accessible: true,
|
|
217
|
+
"aria-disabled": isDisabled,
|
|
218
|
+
"aria-label": t11,
|
|
219
|
+
"aria-valuemax": maxValue,
|
|
220
|
+
"aria-valuemin": minValue,
|
|
221
|
+
"aria-valuenow": t12,
|
|
222
|
+
"aria-valuetext": t15,
|
|
223
|
+
onAccessibilityAction: t16,
|
|
224
|
+
role: "slider",
|
|
225
|
+
style: t19,
|
|
226
|
+
children: t21
|
|
227
|
+
});
|
|
228
|
+
$[42] = isDisabled;
|
|
229
|
+
$[43] = maxValue;
|
|
230
|
+
$[44] = minValue;
|
|
231
|
+
$[45] = state.hue;
|
|
232
|
+
$[46] = t11;
|
|
233
|
+
$[47] = t15;
|
|
234
|
+
$[48] = t16;
|
|
235
|
+
$[49] = t19;
|
|
236
|
+
$[50] = t21;
|
|
237
|
+
$[51] = t22;
|
|
238
|
+
} else t22 = $[51];
|
|
239
|
+
let t23;
|
|
240
|
+
if ($[52] !== t10 || $[53] !== t22) {
|
|
241
|
+
t23 = /* @__PURE__ */ jsxs(View, {
|
|
242
|
+
style: StyleSheet.absoluteFill,
|
|
243
|
+
children: [t10, t22]
|
|
244
|
+
});
|
|
245
|
+
$[52] = t10;
|
|
246
|
+
$[53] = t22;
|
|
247
|
+
$[54] = t23;
|
|
248
|
+
} else t23 = $[54];
|
|
249
|
+
let t24;
|
|
250
|
+
if ($[55] !== gesture || $[56] !== t23) {
|
|
251
|
+
t24 = /* @__PURE__ */ jsx(GestureHandlerRootView, {
|
|
252
|
+
style: StyleSheet.absoluteFill,
|
|
253
|
+
children: /* @__PURE__ */ jsx(GestureDetector, {
|
|
254
|
+
gesture,
|
|
255
|
+
children: t23
|
|
256
|
+
})
|
|
257
|
+
});
|
|
258
|
+
$[55] = gesture;
|
|
259
|
+
$[56] = t23;
|
|
260
|
+
$[57] = t24;
|
|
261
|
+
} else t24 = $[57];
|
|
262
|
+
let t25;
|
|
263
|
+
if ($[58] !== T0 || $[59] !== ref || $[60] !== t24 || $[61] !== t9 || $[62] !== testID) {
|
|
264
|
+
t25 = /* @__PURE__ */ jsx(T0, {
|
|
265
|
+
ref,
|
|
266
|
+
style: t9,
|
|
267
|
+
testID,
|
|
268
|
+
children: t24
|
|
269
|
+
});
|
|
270
|
+
$[58] = T0;
|
|
271
|
+
$[59] = ref;
|
|
272
|
+
$[60] = t24;
|
|
273
|
+
$[61] = t9;
|
|
274
|
+
$[62] = testID;
|
|
275
|
+
$[63] = t25;
|
|
276
|
+
} else t25 = $[63];
|
|
277
|
+
return t25;
|
|
278
|
+
}
|
|
279
|
+
function pointOf(outerRadius, radius, degrees) {
|
|
280
|
+
const radians = degrees * Math.PI / 180;
|
|
281
|
+
const across = outerRadius + radius * Math.cos(radians);
|
|
282
|
+
const down = outerRadius + radius * Math.sin(radians);
|
|
283
|
+
return `${across.toFixed(3)} ${down.toFixed(3)}`;
|
|
284
|
+
}
|
|
285
|
+
function Ring(t0) {
|
|
286
|
+
const $ = c(7);
|
|
287
|
+
const { innerRadius, outerRadius } = t0;
|
|
288
|
+
const t1 = outerRadius * 2;
|
|
289
|
+
const t2 = outerRadius * 2;
|
|
290
|
+
let t3;
|
|
291
|
+
if ($[0] !== innerRadius || $[1] !== outerRadius) {
|
|
292
|
+
t3 = HUES.map((hue) => /* @__PURE__ */ jsx(Path, {
|
|
293
|
+
d: sliceOf(hue, innerRadius, outerRadius),
|
|
294
|
+
fill: `hsl(${hue}, 100%, 50%)`
|
|
295
|
+
}, hue));
|
|
296
|
+
$[0] = innerRadius;
|
|
297
|
+
$[1] = outerRadius;
|
|
298
|
+
$[2] = t3;
|
|
299
|
+
} else t3 = $[2];
|
|
300
|
+
let t4;
|
|
301
|
+
if ($[3] !== t1 || $[4] !== t2 || $[5] !== t3) {
|
|
302
|
+
t4 = /* @__PURE__ */ jsx(Svg, {
|
|
303
|
+
...HIDDEN,
|
|
304
|
+
height: t1,
|
|
305
|
+
style: StyleSheet.absoluteFill,
|
|
306
|
+
width: t2,
|
|
307
|
+
children: t3
|
|
308
|
+
});
|
|
309
|
+
$[3] = t1;
|
|
310
|
+
$[4] = t2;
|
|
311
|
+
$[5] = t3;
|
|
312
|
+
$[6] = t4;
|
|
313
|
+
} else t4 = $[6];
|
|
314
|
+
return t4;
|
|
315
|
+
}
|
|
316
|
+
function sliceOf(hue, innerRadius, outerRadius) {
|
|
317
|
+
const from = hue - 1 / 2;
|
|
318
|
+
const to = hue + 1 / 2 + OVERLAP;
|
|
319
|
+
return [
|
|
320
|
+
`M ${pointOf(outerRadius, outerRadius, from)}`,
|
|
321
|
+
`A ${outerRadius} ${outerRadius} 0 0 1 ${pointOf(outerRadius, outerRadius, to)}`,
|
|
322
|
+
`L ${pointOf(outerRadius, innerRadius, to)}`,
|
|
323
|
+
`A ${innerRadius} ${innerRadius} 0 0 0 ${pointOf(outerRadius, innerRadius, from)}`,
|
|
324
|
+
"Z"
|
|
325
|
+
].join(" ");
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The wheel's pan and tap. Each reads a press against the wheel's centre and
|
|
329
|
+
* sets the hue from its angle, and counts only a press that begins within
|
|
330
|
+
* `reach` of the band's middle. The pan holds the wheel as dragged until it
|
|
331
|
+
* lets go, which lifts the handle and is what `onChangeEnd` waits for; the
|
|
332
|
+
* tap moves it and lets it go at once.
|
|
333
|
+
*
|
|
334
|
+
* Both run on the JavaScript thread, since every move sets React state.
|
|
335
|
+
*/
|
|
336
|
+
function useWheelGesture(t0) {
|
|
337
|
+
const $ = c(13);
|
|
338
|
+
const { isDisabled, outerRadius, reach, state, testID, thumbRadius } = t0;
|
|
339
|
+
const held = useSharedValue(false);
|
|
340
|
+
let t1;
|
|
341
|
+
if ($[0] !== outerRadius || $[1] !== reach || $[2] !== thumbRadius) {
|
|
342
|
+
t1 = function reaches(x, y) {
|
|
343
|
+
const distance = Math.hypot(x - outerRadius, y - outerRadius);
|
|
344
|
+
return Math.abs(distance - thumbRadius) <= reach;
|
|
345
|
+
};
|
|
346
|
+
$[0] = outerRadius;
|
|
347
|
+
$[1] = reach;
|
|
348
|
+
$[2] = thumbRadius;
|
|
349
|
+
$[3] = t1;
|
|
350
|
+
} else t1 = $[3];
|
|
351
|
+
const reaches = t1;
|
|
352
|
+
let t2;
|
|
353
|
+
if ($[4] !== outerRadius || $[5] !== state) {
|
|
354
|
+
t2 = function setFrom(x_0, y_0) {
|
|
355
|
+
const across = x_0 - outerRadius;
|
|
356
|
+
const down = y_0 - outerRadius;
|
|
357
|
+
const distance_0 = Math.hypot(across, down);
|
|
358
|
+
if (distance_0 > 0) state.setHueFromPoint(across, down, distance_0);
|
|
359
|
+
};
|
|
360
|
+
$[4] = outerRadius;
|
|
361
|
+
$[5] = state;
|
|
362
|
+
$[6] = t2;
|
|
363
|
+
} else t2 = $[6];
|
|
364
|
+
const setFrom = t2;
|
|
365
|
+
let t6;
|
|
366
|
+
if ($[7] !== state) {
|
|
367
|
+
t6 = () => {
|
|
368
|
+
state.setDragging(false);
|
|
369
|
+
};
|
|
370
|
+
$[7] = state;
|
|
371
|
+
$[8] = t6;
|
|
372
|
+
} else t6 = $[8];
|
|
373
|
+
const pan = Gesture.Pan().minDistance(SLOP).enabled(!isDisabled).runOnJS(true).onBegin((t3) => {
|
|
374
|
+
const { x: x_1, y: y_1 } = t3;
|
|
375
|
+
held.set(reaches(x_1, y_1));
|
|
376
|
+
}).onStart((t4) => {
|
|
377
|
+
const { x: x_2, y: y_2 } = t4;
|
|
378
|
+
if (held.get()) {
|
|
379
|
+
state.setDragging(true);
|
|
380
|
+
setFrom(x_2, y_2);
|
|
381
|
+
}
|
|
382
|
+
}).onUpdate((t5) => {
|
|
383
|
+
const { x: x_3, y: y_3 } = t5;
|
|
384
|
+
if (held.get()) setFrom(x_3, y_3);
|
|
385
|
+
}).onFinalize(t6);
|
|
386
|
+
let t7;
|
|
387
|
+
if ($[9] !== reaches || $[10] !== setFrom || $[11] !== state) {
|
|
388
|
+
t7 = (t8, success) => {
|
|
389
|
+
const { x: x_4, y: y_4 } = t8;
|
|
390
|
+
if (success && reaches(x_4, y_4)) {
|
|
391
|
+
state.setDragging(true);
|
|
392
|
+
setFrom(x_4, y_4);
|
|
393
|
+
state.setDragging(false);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
$[9] = reaches;
|
|
397
|
+
$[10] = setFrom;
|
|
398
|
+
$[11] = state;
|
|
399
|
+
$[12] = t7;
|
|
400
|
+
} else t7 = $[12];
|
|
401
|
+
const tap = Gesture.Tap().maxDistance(SLOP).enabled(!isDisabled).runOnJS(true).onEnd(t7);
|
|
402
|
+
return Gesture.Race(testID === void 0 ? pan : pan.withTestId(`${testID}-pan`), testID === void 0 ? tap : tap.withTestId(`${testID}-tap`));
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
405
|
+
export { ColorWheel };
|
|
406
|
+
|
|
407
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ComponentRef","Ref","AccessibilityActionEvent","StyleProp","ViewStyle","SharedValue","Color","ColorWheelState","I18nManager","StyleSheet","View","Gesture","GestureDetector","GestureHandlerRootView","useSharedValue","Svg","Path","useColorWheelState","ColorThumb","HIDDEN","useLocaleOf","ADJUSTABLE","usePickedColor","useTheme","composeStyles","themedStyles","ColorWheelProps","defaultValue","isDisabled","onChange","value","onChangeEnd","outerRadius","ref","style","testID","thickness","DEFAULT_OUTER_RADIUS","DEFAULT_THICKNESS","SLOP","TARGET","OVERLAP","HUES","Array","from","length","_","hue","styles","create","root","boxSizing","seat","alignItems","height","justifyContent","marginStart","marginTop","position","width","thumb","pointerEvents","stylesOf","stateLayerOpacity","disabled","opacity","disabledContent","adjustOf","state","event","actionName","nativeEvent","setDragging","increment","step","decrement","ColorWheel","t0","$","_c","ariaLabel","t1","t2","t3","undefined","own","locale","picked","t4","innerRadius","Math","max","thumbRadius","t5","t6","reach","gesture","useWheelGesture","t7","getThumbPosition","x","y","color","t8","getChannelRange","maxValue","minValue","T0","t9","t10","t11","getChannelName","t12","t13","formatChannelValue","t14","getHueName","t15","t16","t17","isRTL","t18","t19","start","top","t20","getDisplayColor","t21","isDragging","t22","t23","absoluteFill","t24","t25","pointOf","radius","degrees","radians","PI","across","cos","down","sin","toFixed","Ring","map","sliceOf","to","join","held","reaches","distance","hypot","abs","setFrom","x_0","y_0","distance_0","setHueFromPoint","pan","Pan","minDistance","enabled","runOnJS","onBegin","x_1","y_1","set","onStart","x_2","y_2","get","onUpdate","x_3","y_3","onFinalize","success","x_4","y_4","tap","Tap","maxDistance","onEnd","Race","withTestId","_c"],"sources":["../../../src/components/color-wheel/index.tsx"],"sourcesContent":["import type { ComponentRef, Ref } from 'react'\nimport type {\n AccessibilityActionEvent,\n StyleProp,\n ViewStyle,\n} from 'react-native'\nimport type { SharedValue } from 'react-native-reanimated'\nimport type { Color } from 'react-stately'\nimport type { ColorWheelState } from 'react-stately/useColorWheelState'\n\nimport { I18nManager, StyleSheet, View } from 'react-native'\nimport {\n Gesture,\n GestureDetector,\n GestureHandlerRootView,\n} from 'react-native-gesture-handler'\nimport { useSharedValue } from 'react-native-reanimated'\nimport Svg, { Path } from 'react-native-svg'\nimport { useColorWheelState } from 'react-stately/useColorWheelState'\n\nimport { ColorThumb } from '../../color-thumb'\nimport { HIDDEN } from '../../glyphs/hidden'\nimport { useLocaleOf } from '../../i18n/provider'\nimport { ADJUSTABLE } from '../../slider'\nimport { usePickedColor } from '../../swatch'\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles, themedStyles } from '../../theme/styles'\n\n// kanso-ui's ColorWheel: hue as a ring, with ColorSlider's ringed handle on\n// it. No Material Design page draws one, so what is here is web's, each\n// choice for web's reason, drawn and pressed as the platform allows.\n//\n// **The band is the sliders page's 16dp track**, a hue slider's thickness,\n// since a hue wheel and a hue slider are one control in two shapes. The\n// thickness is a prop and the inner radius is not: it is the thickness in\n// from `outerRadius`, so the two cannot disagree, and a band wider than the\n// wheel leaves no hole rather than a negative one.\n//\n// **The ring is slices, and the middle is empty.** react-native-svg has no\n// conic gradient, so the band is drawn as 360 slices, one per degree of hue,\n// each the hue at its middle and a little wider than its degree, so no seam\n// shows between neighbours. React Aria's gradient runs straight between its\n// stops, which is what hue at full saturation does, so the slices draw it to\n// within half a degree. Nothing is drawn inside the band, so whatever the\n// wheel sits over shows through, and a ColorArea or a swatch can sit in it.\n//\n// **Hue runs as React Aria's does**: 0° at three o'clock, rising clockwise,\n// and the same right to left, since a ring has no reading direction.\n//\n// **A press counts across the 48dp target.** The 16dp band is narrower than\n// the target Material Design asks a touch to have, so a press or a drag that\n// begins within 24dp of the band's middle, or anywhere on a wider band, moves\n// the handle there, and one beginning in the hole or a corner moves nothing.\n// Once begun, a drag follows the angle wherever it goes, as web's does.\n//\n// **A screen reader adjusts the handle**, named \"Hue\", or by `aria-label` in\n// its place, as React Aria names it, and hears the hue and its name, \"200°,\n// cyan blue\", in the provider's locale. It steps by a degree, past 360 back\n// to 0. `onChangeEnd` comes once as a drag, a press or a step ends.\n// Disabled, the wheel fades and takes nothing.\n\ntype ColorWheelProps = {\n /** What a screen reader calls the wheel, in place of \"Hue\". */\n readonly 'aria-label'?: string\n /**\n * The colour the wheel starts at, when it keeps its own: a CSS colour\n * string in any notation, or a `Color` from `parseColor`. Red when neither\n * this nor `value` is given.\n */\n readonly defaultValue?: Color | string\n /**\n * Draws the wheel disabled, and takes no presses, drags or screen reader\n * actions.\n * @default false\n */\n readonly isDisabled?: boolean\n /** Called with the colour as its hue moves. */\n readonly onChange?: (value: Color) => void\n /** Called with the colour once a drag, a press or an action has ended. */\n readonly onChangeEnd?: (value: Color) => void\n /**\n * How far the ring reaches from the centre, in dp. The wheel is twice this\n * across.\n * @default 100\n */\n readonly outerRadius?: number\n readonly ref?: Ref<ComponentRef<typeof View>>\n /** Lands on the wheel. Its size comes from `outerRadius`. */\n readonly style?: StyleProp<ViewStyle>\n readonly testID?: string\n /**\n * How wide the band is, in dp. The inner radius is this in from\n * `outerRadius`, so the two cannot disagree.\n * @default 16\n */\n readonly thickness?: number\n /** The colour, for a call site holding it itself with `onChange`. */\n readonly value?: Color | string\n}\n\nconst DEFAULT_OUTER_RADIUS = 100\n// The sliders page's track, which is what a hue slider draws.\nconst DEFAULT_THICKNESS = 16\n\n// How far a press moves before it is a drag rather than a tap: Gesture\n// Handler's own default distance for a pan, as Slider's.\nconst SLOP = 10\n\n// The target a press counts across, and the frame a screen reader outlines\n// the handle in: the sliders page's 48dp, centred on the band's middle.\nconst TARGET = 48\n\n// How far past its degree each slice reaches, which covers the hairline a\n// renderer can leave between two shapes that only meet.\nconst OVERLAP = 0.5\n\n// One slice per degree of hue.\nconst HUES = Array.from({ length: 360 }, (_, hue) => hue)\n\nconst styles = StyleSheet.create({\n root: {\n boxSizing: 'border-box',\n },\n // Where the handle sits: the frame centred on the band, with the handle\n // centred in it.\n seat: {\n alignItems: 'center',\n height: TARGET,\n justifyContent: 'center',\n marginStart: -TARGET / 2,\n marginTop: -TARGET / 2,\n position: 'absolute',\n width: TARGET,\n },\n // The handle, taking none of the frame's presses.\n thumb: {\n pointerEvents: 'none',\n },\n})\n\nconst stylesOf = themedStyles(({ stateLayerOpacity }) =>\n StyleSheet.create({\n disabled: {\n opacity: stateLayerOpacity.disabledContent,\n },\n }),\n)\n\n// Runs the step a screen reader asks for, as a move that starts and ends at\n// once, so `onChangeEnd` comes once as it does for a key on web.\nfunction adjustOf(state: ColorWheelState, isDisabled: boolean) {\n return (event: AccessibilityActionEvent) => {\n const { actionName } = event.nativeEvent\n if (\n isDisabled ||\n (actionName !== 'increment' && actionName !== 'decrement')\n ) {\n return\n }\n state.setDragging(true)\n if (actionName === 'increment') {\n state.increment(state.step)\n } else {\n state.decrement(state.step)\n }\n state.setDragging(false)\n }\n}\n\n/**\n * Hue as a ring, with a handle on it. Its state is React Stately's, as web's\n * is: pass `value` with `onChange` to control it, or `defaultValue`, as a\n * CSS colour string or a `Color` from `parseColor`, which this package\n * re-exports.\n *\n * ```tsx\n * <ColorWheel defaultValue=\"hsl(200, 100%, 50%)\" />\n * ```\n *\n * A wheel moves hue and nothing else, so unlike `ColorSlider` and\n * `ColorArea` it names no channel and there is no space for one to be\n * missing from: a hex value works here.\n *\n * The middle is empty rather than filled, so a `ColorArea` or a\n * `ColorSwatch` can sit inside one. A press on the ring moves the handle\n * there, and a drag carries it round. A screen reader hears \"Hue\", or\n * `aria-label`, with the value. `style`, `ref` and `testID` land on the\n * wheel, whose size comes from `outerRadius`. With a `testID`, the drag and\n * the press are registered with Gesture Handler as `<testID>-pan` and\n * `<testID>-tap`, which its `getByGestureTestId` finds in a test.\n *\n * Inside a `ColorPicker` it takes the picker's colour where it is given no\n * `value`, and reports a change to the picker before its own `onChange`.\n */\nfunction ColorWheel({\n 'aria-label': ariaLabel,\n defaultValue,\n isDisabled = false,\n onChange,\n onChangeEnd,\n outerRadius = DEFAULT_OUTER_RADIUS,\n ref,\n style,\n testID,\n thickness = DEFAULT_THICKNESS,\n value,\n}: ColorWheelProps) {\n const own = stylesOf(useTheme())\n const locale = useLocaleOf(undefined)\n const picked = usePickedColor(value, onChange)\n const state = useColorWheelState({\n defaultValue,\n isDisabled,\n onChange: picked.onChange,\n onChangeEnd,\n value: picked.value,\n })\n const innerRadius = Math.max(0, outerRadius - thickness)\n // The middle of the band, which is where the handle rides.\n const thumbRadius = (innerRadius + outerRadius) / 2\n const gesture = useWheelGesture({\n isDisabled,\n outerRadius,\n reach: Math.max(outerRadius - innerRadius, TARGET) / 2,\n state,\n testID,\n thumbRadius,\n })\n const { x, y } = state.getThumbPosition(thumbRadius)\n const color = state.value\n const { maxValue, minValue } = color.getChannelRange('hue')\n\n return (\n <View\n ref={ref}\n style={composeStyles<ViewStyle>(\n styles.root,\n { height: outerRadius * 2, width: outerRadius * 2 },\n isDisabled ? own.disabled : undefined,\n style,\n )}\n testID={testID}\n >\n <GestureHandlerRootView style={StyleSheet.absoluteFill}>\n <GestureDetector gesture={gesture}>\n <View style={StyleSheet.absoluteFill}>\n <Ring innerRadius={innerRadius} outerRadius={outerRadius} />\n <View\n accessibilityActions={ADJUSTABLE}\n accessible\n aria-disabled={isDisabled}\n aria-label={ariaLabel ?? color.getChannelName('hue', locale)}\n aria-valuemax={maxValue}\n aria-valuemin={minValue}\n aria-valuenow={state.hue}\n aria-valuetext={`${color.formatChannelValue('hue', locale)}, ${color.getHueName(locale)}`}\n onAccessibilityAction={adjustOf(state, isDisabled)}\n role=\"slider\"\n style={composeStyles<ViewStyle>(styles.seat, {\n // `start` turns over right to left, so the handle is put\n // back where its hue is.\n start: outerRadius + (I18nManager.isRTL ? -x : x),\n top: outerRadius + y,\n })}\n >\n <View style={styles.thumb}>\n <ColorThumb\n color={state.getDisplayColor()}\n dragging={state.isDragging}\n />\n </View>\n </View>\n </View>\n </GestureDetector>\n </GestureHandlerRootView>\n </View>\n )\n}\n\n// A point `radius` from the wheel's centre at `degrees` of hue, as React\n// Aria places hue: 0° at three o'clock, rising clockwise.\nfunction pointOf(outerRadius: number, radius: number, degrees: number) {\n const radians = (degrees * Math.PI) / 180\n const across = outerRadius + radius * Math.cos(radians)\n const down = outerRadius + radius * Math.sin(radians)\n return `${across.toFixed(3)} ${down.toFixed(3)}`\n}\n\n// The band, one slice of it per degree of hue.\nfunction Ring({\n innerRadius,\n outerRadius,\n}: {\n readonly innerRadius: number\n readonly outerRadius: number\n}) {\n return (\n <Svg\n {...HIDDEN}\n height={outerRadius * 2}\n style={StyleSheet.absoluteFill}\n width={outerRadius * 2}\n >\n {HUES.map((hue) => (\n <Path\n d={sliceOf(hue, innerRadius, outerRadius)}\n fill={`hsl(${hue}, 100%, 50%)`}\n key={hue}\n />\n ))}\n </Svg>\n )\n}\n\n// The band's slice for one degree of hue, centred on it: out along the outer\n// edge clockwise, in, and back along the inner edge.\nfunction sliceOf(hue: number, innerRadius: number, outerRadius: number) {\n const from = hue - 1 / 2\n const to = hue + 1 / 2 + OVERLAP\n return [\n `M ${pointOf(outerRadius, outerRadius, from)}`,\n `A ${outerRadius} ${outerRadius} 0 0 1 ${pointOf(outerRadius, outerRadius, to)}`,\n `L ${pointOf(outerRadius, innerRadius, to)}`,\n `A ${innerRadius} ${innerRadius} 0 0 0 ${pointOf(outerRadius, innerRadius, from)}`,\n 'Z',\n ].join(' ')\n}\n\n/**\n * The wheel's pan and tap. Each reads a press against the wheel's centre and\n * sets the hue from its angle, and counts only a press that begins within\n * `reach` of the band's middle. The pan holds the wheel as dragged until it\n * lets go, which lifts the handle and is what `onChangeEnd` waits for; the\n * tap moves it and lets it go at once.\n *\n * Both run on the JavaScript thread, since every move sets React state.\n */\nfunction useWheelGesture({\n isDisabled,\n outerRadius,\n reach,\n state,\n testID,\n thumbRadius,\n}: {\n readonly isDisabled: boolean\n readonly outerRadius: number\n readonly reach: number\n readonly state: ColorWheelState\n readonly testID: string | undefined\n readonly thumbRadius: number\n}) {\n // Whether the pan began on the ring. A shared value rather than a ref: the\n // gesture's callbacks are built while rendering, and the React Compiler\n // lets no ref reach them.\n const held: SharedValue<boolean> = useSharedValue(false)\n\n function reaches(x: number, y: number) {\n const distance = Math.hypot(x - outerRadius, y - outerRadius)\n return Math.abs(distance - thumbRadius) <= reach\n }\n\n // Sets the hue from a press's angle. The very centre has none, and moves\n // nothing.\n function setFrom(x: number, y: number) {\n const across = x - outerRadius\n const down = y - outerRadius\n const distance = Math.hypot(across, down)\n if (distance > 0) {\n state.setHueFromPoint(across, down, distance)\n }\n }\n\n // Gesture Handler 3 deprecates these builders for hooks that version 2 does\n // not have, and the peer range admits both, so the builders stay while it\n // does.\n // oxlint-disable-next-line react/capitalized-calls, typescript/no-deprecated -- a builder named after its gesture, not a component; see above\n const pan = Gesture.Pan()\n .minDistance(SLOP)\n .enabled(!isDisabled)\n .runOnJS(true)\n .onBegin(({ x, y }) => {\n held.set(reaches(x, y))\n })\n .onStart(({ x, y }) => {\n if (held.get()) {\n state.setDragging(true)\n setFrom(x, y)\n }\n })\n .onUpdate(({ x, y }) => {\n if (held.get()) {\n setFrom(x, y)\n }\n })\n // A pan the tap beat, or one begun off the ring, never started, and\n // letting go of a wheel nothing holds ends nothing, so this needs no\n // guard.\n .onFinalize(() => {\n state.setDragging(false)\n })\n // oxlint-disable-next-line react/capitalized-calls, typescript/no-deprecated -- as above\n const tap = Gesture.Tap()\n .maxDistance(SLOP)\n .enabled(!isDisabled)\n .runOnJS(true)\n .onEnd(({ x, y }, success) => {\n if (success && reaches(x, y)) {\n state.setDragging(true)\n setFrom(x, y)\n state.setDragging(false)\n }\n })\n\n // oxlint-disable-next-line react/capitalized-calls, typescript/no-deprecated -- as above\n return Gesture.Race(\n testID === undefined ? pan : pan.withTestId(`${testID}-pan`),\n testID === undefined ? tap : tap.withTestId(`${testID}-tap`),\n )\n}\n\nexport { ColorWheel }\nexport type { ColorWheelProps }\n"],"mappings":";;;;;;;;;;;;;;;AAoGA,MAAMqC,uBAAu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,KAAIsB,IAAK,GACXjB,QAAQtD,KAAGC,GAAC;CACb,CACF,CAAC,CAAA0E,WAIUjF,EAEX;CAAC,IAAAI;CAAA,IAAApB,EAAA,OAAAwE,WAAAxE,EAAA,QAAA4E,WAAA5E,EAAA,QAAAV,OAAA;EAMK8B,MAAAK,IAAAyE,YAAA;GAAC,MAAA,EAAA5E,GAAA6E,KAAA5E,GAAA6E,QAAA3E;GACN,IAAIyE,WAAW1B,QAAQlD,KAAGC,GAAC,GAAC;IAC1BjC,MAAKI,YAAa,IAAI;IACtBkF,QAAQtD,KAAGC,GAAC;IACZjC,MAAKI,YAAa,KAAK;GAAC;EACzB;EACFM,EAAA,KAAAwE;EAAAxE,EAAA,MAAA4E;EAAA5E,EAAA,MAAAV;EAAAU,EAAA,MAAAoB;CAAA,OAAAA,KAAApB,EAAA;CAVH,MAAAqG,MAAYxK,QAAOyK,IAAK,CAAC,CAAAC,YACV9I,IAAI,CAAC,CAAA2H,QACT,CAACtI,UAAU,CAAC,CAAAuI,QACZ,IAAI,CAAC,CAAAmB,MACPpF,EAMN;CAAC,OAGGvF,QAAO4K,KACZpJ,WAAWiD,KAAAA,IAAX2E,MAA6BA,IAAGyB,WAAY,GAAGrJ,OAAM,KAAM,GAC3DA,WAAWiD,KAAAA,IAAX+F,MAA6BA,IAAGK,WAAY,GAAGrJ,OAAM,KAAM,CAC7D;AAAC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { ValidationResult } from "../../form/index.js";
|
|
2
|
+
import { FieldVariant } from "../../field/index.js";
|
|
3
|
+
import { StyleProp, TextInput, View, ViewStyle } from "react-native";
|
|
4
|
+
import { ComponentRef, ReactElement, ReactNode, Ref } from "react";
|
|
5
|
+
import { Key } from "react-stately";
|
|
6
|
+
import { ComboBoxValidationValue, MenuTriggerAction } from "react-stately/useComboBoxState";
|
|
7
|
+
import { ChangeValueType, ValueType } from "react-stately/useSelectState";
|
|
8
|
+
//#region src/components/combo-box/index.d.ts
|
|
9
|
+
type ComboBoxProps<T extends object = object, M extends ComboBoxSelectionMode = 'single'> = {
|
|
10
|
+
/**
|
|
11
|
+
* Lets the field keep text that matches no option. With it on, the text is
|
|
12
|
+
* what the field holds and submits; with it off, the text goes back to the
|
|
13
|
+
* chosen option's as the field loses focus.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
readonly allowsCustomValue?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Lets the list open with no options in it, showing its empty state. Left
|
|
19
|
+
* off, the list closes when a search leaves nothing.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
readonly allowsEmptyCollection?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Which options a search keeps, handed an option's text and what has been
|
|
25
|
+
* typed. Left out, an option is kept when its text contains what has been
|
|
26
|
+
* typed anywhere in it, ignoring case and accents.
|
|
27
|
+
*/
|
|
28
|
+
readonly defaultFilter?: (textValue: string, inputValue: string) => boolean;
|
|
29
|
+
/** The text the field opens with, when it keeps its own. */
|
|
30
|
+
readonly defaultInputValue?: string;
|
|
31
|
+
/** The items the options are built from, when the field keeps its own. */
|
|
32
|
+
readonly defaultItems?: Iterable<T>;
|
|
33
|
+
/**
|
|
34
|
+
* What is chosen at first, when the field keeps its own value: an
|
|
35
|
+
* option's `id`, or a list of them with `selectionMode="multiple"`.
|
|
36
|
+
*/
|
|
37
|
+
readonly defaultValue?: ValueType<M>;
|
|
38
|
+
/**
|
|
39
|
+
* A hint shown under the field. Replaced by `error` when there is one, so
|
|
40
|
+
* the two never stack.
|
|
41
|
+
*/
|
|
42
|
+
readonly description?: string;
|
|
43
|
+
/** The `id`s of the options drawn disabled, which take no presses. */
|
|
44
|
+
readonly disabledKeys?: Iterable<Key>;
|
|
45
|
+
/**
|
|
46
|
+
* The problem with the current value, in words. Its presence is what puts
|
|
47
|
+
* the field in its error state: the message, the error colours, and the
|
|
48
|
+
* error a screen reader reads with the field all follow from it. The line
|
|
49
|
+
* under the field arrives with the message, so the field grows when this
|
|
50
|
+
* does, unless it is inside a `Form`, which keeps the line drawn. It wins
|
|
51
|
+
* over what `validate` and the form say, and holds a `native` form back.
|
|
52
|
+
*/
|
|
53
|
+
readonly error?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the label sits in the empty box and floats to the top once the
|
|
56
|
+
* field is focused or holds a value. `false` keeps it small at the top in
|
|
57
|
+
* every state.
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
readonly floatingLabel?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Whether the `Form` around the field submits the chosen option's `id` or
|
|
63
|
+
* the text in the field. A field allowing a custom value, which may hold
|
|
64
|
+
* text that is no option's, always submits the text, and one choosing
|
|
65
|
+
* several always submits the list of their `id`s.
|
|
66
|
+
* @default 'key'
|
|
67
|
+
*/
|
|
68
|
+
readonly formValue?: 'key' | 'text';
|
|
69
|
+
/**
|
|
70
|
+
* A ref to the field's own `TextInput`, which is what a call site moves
|
|
71
|
+
* focus to, after a server's error, say. `ref` is the field as a whole.
|
|
72
|
+
*/
|
|
73
|
+
readonly inputRef?: Ref<ComponentRef<typeof TextInput>>;
|
|
74
|
+
/** The text in the field, when the call site holds it. */
|
|
75
|
+
readonly inputValue?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Draws the field disabled: it takes no focus and no input, and its list
|
|
78
|
+
* never opens.
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
readonly isDisabled?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Shows the value and takes focus, but takes no input, and its list never
|
|
84
|
+
* opens.
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
readonly isReadOnly?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Marks the label with an asterisk, as the text fields page marks a field
|
|
90
|
+
* that must be filled. Inside a `native` form, a field with nothing chosen
|
|
91
|
+
* holds the form back, or with nothing typed where it submits its text.
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
readonly isRequired?: boolean;
|
|
95
|
+
/** The items the options are built from, when the call site holds them. */
|
|
96
|
+
readonly items?: Iterable<T>;
|
|
97
|
+
/**
|
|
98
|
+
* What the field is for, and the name a screen reader reads for it.
|
|
99
|
+
* Required, since a combo box with no label is a box nobody can name.
|
|
100
|
+
*/
|
|
101
|
+
readonly label: string;
|
|
102
|
+
/**
|
|
103
|
+
* An icon at the start of the box, before the label and the value: the
|
|
104
|
+
* page's 24dp leading icon, in the muted role. The slot hands it that
|
|
105
|
+
* colour and size through `useIconStyle()`.
|
|
106
|
+
*/
|
|
107
|
+
readonly leadingIcon?: ReactNode;
|
|
108
|
+
/**
|
|
109
|
+
* What opens the list besides the chevron: typing into the field, the
|
|
110
|
+
* field taking focus, or nothing else.
|
|
111
|
+
* @default 'input'
|
|
112
|
+
*/
|
|
113
|
+
readonly menuTrigger?: MenuTriggerAction;
|
|
114
|
+
/**
|
|
115
|
+
* The name the value is submitted under by the `Form` around the field,
|
|
116
|
+
* and the key its `validationErrors` reach the field by. What is
|
|
117
|
+
* submitted is set out under `formValue`.
|
|
118
|
+
*/
|
|
119
|
+
readonly name?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Called with what is chosen whenever it changes: an option's `id`, or
|
|
122
|
+
* the list of them with `selectionMode="multiple"`.
|
|
123
|
+
*/
|
|
124
|
+
readonly onChange?: (value: ChangeValueType<M>) => void;
|
|
125
|
+
/** Called with the text in the field whenever an edit changes it. */
|
|
126
|
+
readonly onInputChange?: (value: string) => void;
|
|
127
|
+
/**
|
|
128
|
+
* Called with whether the list is open whenever that changes, and, as it
|
|
129
|
+
* opens, with what opened it.
|
|
130
|
+
*/
|
|
131
|
+
readonly onOpenChange?: (isOpen: boolean, menuTrigger?: MenuTriggerAction) => void;
|
|
132
|
+
/**
|
|
133
|
+
* The options, a `ListBox.Item` for each and `ListBox.Section` to group
|
|
134
|
+
* them. The list is a ListBox's, and draws every slot one does. Give
|
|
135
|
+
* every option an `id`, which is what the value holds. With `items` or
|
|
136
|
+
* `defaultItems`, a function from an item to its option.
|
|
137
|
+
*/
|
|
138
|
+
readonly options?: ((item: T) => ReactElement) | ReactNode;
|
|
139
|
+
readonly ref?: Ref<ComponentRef<typeof View>>;
|
|
140
|
+
/**
|
|
141
|
+
* Whether one option is chosen, or several.
|
|
142
|
+
* @default 'single'
|
|
143
|
+
*/
|
|
144
|
+
readonly selectionMode?: M;
|
|
145
|
+
/** Positions and sizes the field as a whole. */
|
|
146
|
+
readonly style?: StyleProp<ViewStyle>;
|
|
147
|
+
/** The test id of the field's `TextInput`, which is the control. */
|
|
148
|
+
readonly testID?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Checks the value, handed the text in the field and what is chosen, and
|
|
151
|
+
* returns its problem in words, or several, where there is one, and
|
|
152
|
+
* `true`, `null` or `undefined` where there is none. Under the default
|
|
153
|
+
* `aria` validation the error shows as the value changes; inside a
|
|
154
|
+
* `native` form it shows once a submission is tried, or once the field
|
|
155
|
+
* loses focus after an edit, and holds the form back.
|
|
156
|
+
*/
|
|
157
|
+
readonly validate?: (value: ComboBoxValidationValue<M>) => ValidationResult;
|
|
158
|
+
/** What is chosen, when the call site holds it. */
|
|
159
|
+
readonly value?: ValueType<M>;
|
|
160
|
+
/**
|
|
161
|
+
* The filled box, or the outlined one, as the text fields page draws them.
|
|
162
|
+
* @default 'filled'
|
|
163
|
+
*/
|
|
164
|
+
readonly variant?: FieldVariant;
|
|
165
|
+
};
|
|
166
|
+
type ComboBoxSelectionMode = 'multiple' | 'single';
|
|
167
|
+
/**
|
|
168
|
+
* A labelled text field that filters a list of options as it is typed. Its
|
|
169
|
+
* value is React Stately's: pass `value` with `onChange` to hold which
|
|
170
|
+
* option is chosen, `inputValue` with `onInputChange` to hold the text, or
|
|
171
|
+
* the `default` forms of either to let it keep its own. The value is an
|
|
172
|
+
* option's `id`, so give every option one; with `selectionMode="multiple"`
|
|
173
|
+
* it is a list of them.
|
|
174
|
+
*
|
|
175
|
+
* ```tsx
|
|
176
|
+
* <ComboBox
|
|
177
|
+
* label="Label"
|
|
178
|
+
* options={[
|
|
179
|
+
* <ListBox.Item id="first" key="first">First item</ListBox.Item>,
|
|
180
|
+
* <ListBox.Item id="second" key="second">Second item</ListBox.Item>,
|
|
181
|
+
* ]}
|
|
182
|
+
* />
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* The box, the label, the input, the supporting line and the error are the
|
|
186
|
+
* field chrome every field here draws; the list is a ListBox's, on the
|
|
187
|
+
* surface every anchored panel here draws. `style` and `ref` are the field
|
|
188
|
+
* as a whole, and `inputRef` and `testID` its `TextInput`.
|
|
189
|
+
*/
|
|
190
|
+
declare function ComboBox<T extends object = object, M extends ComboBoxSelectionMode = 'single'>({ allowsCustomValue, allowsEmptyCollection, defaultFilter, defaultInputValue, defaultItems, defaultValue, description, disabledKeys, error, floatingLabel, formValue, inputRef, inputValue, isDisabled, isReadOnly, isRequired, items, label, leadingIcon, menuTrigger, name, onChange, onInputChange, onOpenChange, options, ref, selectionMode, style, testID, validate, value, variant }: ComboBoxProps<T, M>): import("react").JSX.Element;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { ComboBox, type ComboBoxProps, type ComboBoxSelectionMode };
|
|
193
|
+
//# sourceMappingURL=index.d.ts.map
|