@kanso-labs/react-native-kanso-ui 0.8.0 → 0.9.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.
Files changed (78) hide show
  1. package/dist/badge/index.js +9 -70
  2. package/dist/badge/index.js.map +1 -1
  3. package/dist/button/index.js +1 -1
  4. package/dist/button/palettes.d.ts +2 -0
  5. package/dist/components/badge/index.d.ts +48 -0
  6. package/dist/components/badge/index.js +122 -0
  7. package/dist/components/badge/index.js.map +1 -0
  8. package/dist/{badge → components/badge}/styles.js +10 -6
  9. package/dist/components/badge/styles.js.map +1 -0
  10. package/dist/components/breadcrumbs/index.d.ts +66 -0
  11. package/dist/components/breadcrumbs/index.js +285 -0
  12. package/dist/components/breadcrumbs/index.js.map +1 -0
  13. package/dist/components/checkbox/index.d.ts +7 -1
  14. package/dist/components/checkbox/index.js +183 -138
  15. package/dist/components/checkbox/index.js.map +1 -1
  16. package/dist/components/checkbox-group/index.d.ts +93 -0
  17. package/dist/components/checkbox-group/index.js +306 -0
  18. package/dist/components/checkbox-group/index.js.map +1 -0
  19. package/dist/components/code/index.d.ts +25 -0
  20. package/dist/components/code/index.js +87 -0
  21. package/dist/components/code/index.js.map +1 -0
  22. package/dist/components/container/index.d.ts +47 -0
  23. package/dist/components/container/index.js +85 -0
  24. package/dist/components/container/index.js.map +1 -0
  25. package/dist/components/fab/index.d.ts +80 -0
  26. package/dist/components/fab/index.js +231 -0
  27. package/dist/components/fab/index.js.map +1 -0
  28. package/dist/components/fab-menu/index.d.ts +120 -0
  29. package/dist/components/fab-menu/index.js +640 -0
  30. package/dist/components/fab-menu/index.js.map +1 -0
  31. package/dist/components/feed/index.d.ts +57 -0
  32. package/dist/components/feed/index.js +167 -0
  33. package/dist/components/feed/index.js.map +1 -0
  34. package/dist/components/keycap/index.d.ts +27 -0
  35. package/dist/components/keycap/index.js +136 -0
  36. package/dist/components/keycap/index.js.map +1 -0
  37. package/dist/components/menu/index.js +1 -1
  38. package/dist/components/separator/index.d.ts +3 -2
  39. package/dist/components/separator/index.js +29 -26
  40. package/dist/components/separator/index.js.map +1 -1
  41. package/dist/components/supporting-pane/index.d.ts +44 -0
  42. package/dist/components/supporting-pane/index.js +109 -0
  43. package/dist/components/supporting-pane/index.js.map +1 -0
  44. package/dist/components/text/index.d.ts +1 -1
  45. package/dist/components/text/index.js +49 -21
  46. package/dist/components/text/index.js.map +1 -1
  47. package/dist/components/text-area/index.d.ts +145 -0
  48. package/dist/components/text-area/index.js +231 -0
  49. package/dist/components/text-area/index.js.map +1 -0
  50. package/dist/components/toolbar/index.d.ts +53 -0
  51. package/dist/components/toolbar/index.js +185 -0
  52. package/dist/components/toolbar/index.js.map +1 -0
  53. package/dist/control/group.js +23 -0
  54. package/dist/control/group.js.map +1 -0
  55. package/dist/fab/index.d.ts +19 -0
  56. package/dist/fab/index.js +147 -0
  57. package/dist/fab/index.js.map +1 -0
  58. package/dist/field/index.js +84 -43
  59. package/dist/field/index.js.map +1 -1
  60. package/dist/field/styles.js +18 -0
  61. package/dist/field/styles.js.map +1 -1
  62. package/dist/form/index.d.ts +1 -2
  63. package/dist/form/index.js +1 -1
  64. package/dist/form/index.js.map +1 -1
  65. package/dist/index.d.ts +17 -4
  66. package/dist/index.js +15 -3
  67. package/dist/modal/index.js +59 -46
  68. package/dist/modal/index.js.map +1 -1
  69. package/dist/navigation/index.js +8 -5
  70. package/dist/navigation/index.js.map +1 -1
  71. package/dist/overlay/placement.js +3 -1
  72. package/dist/overlay/placement.js.map +1 -1
  73. package/dist/separator/index.js +7 -0
  74. package/dist/separator/index.js.map +1 -0
  75. package/dist/typography/size.js +14 -0
  76. package/dist/typography/size.js.map +1 -0
  77. package/package.json +1 -1
  78. package/dist/badge/styles.js.map +0 -1
@@ -4,9 +4,10 @@ import { hitSlop, usePressFeedback } from "../../press/index.js";
4
4
  import { controlStylesOf } from "../../control/styles.js";
5
5
  import { ControlLabel, ControlMessage, describedBy, messageOf } from "../../control/index.js";
6
6
  import { CheckboxBox } from "../../control/checkbox-box.js";
7
+ import { CheckboxGroupContext } from "../../control/group.js";
7
8
  import { c } from "react/compiler-runtime";
8
9
  import { Pressable, View } from "react-native";
9
- import { useId } from "react";
10
+ import { use, useEffect, useId, useRef } from "react";
10
11
  import { jsx, jsxs } from "react/jsx-runtime";
11
12
  import { useToggleState } from "react-stately/useToggleState";
12
13
  //#region src/components/checkbox/index.tsx
@@ -45,7 +46,7 @@ const LAYERS = {
45
46
  * positions.
46
47
  */
47
48
  function Checkbox(t0) {
48
- const $ = c(69);
49
+ const $ = c(76);
49
50
  let ariaLabel;
50
51
  let children;
51
52
  let defaultSelected;
@@ -58,8 +59,9 @@ function Checkbox(t0) {
58
59
  let t1;
59
60
  let t2;
60
61
  let t3;
62
+ let value;
61
63
  if ($[0] !== t0) {
62
- ({"aria-label": ariaLabel, children, defaultSelected, description, error, isDisabled: t1, isIndeterminate: t2, isReadOnly: t3, isSelected, onChange, style, ...props} = t0);
64
+ ({"aria-label": ariaLabel, children, defaultSelected, description, error, isDisabled: t1, isIndeterminate: t2, isReadOnly: t3, isSelected, onChange, style, value, ...props} = t0);
63
65
  $[0] = t0;
64
66
  $[1] = ariaLabel;
65
67
  $[2] = children;
@@ -73,6 +75,7 @@ function Checkbox(t0) {
73
75
  $[10] = t1;
74
76
  $[11] = t2;
75
77
  $[12] = t3;
78
+ $[13] = value;
76
79
  } else {
77
80
  ariaLabel = $[1];
78
81
  children = $[2];
@@ -86,95 +89,126 @@ function Checkbox(t0) {
86
89
  t1 = $[10];
87
90
  t2 = $[11];
88
91
  t3 = $[12];
92
+ value = $[13];
89
93
  }
90
- const isDisabled = t1 === void 0 ? false : t1;
94
+ const ownDisabled = t1 === void 0 ? false : t1;
91
95
  const isIndeterminate = t2 === void 0 ? false : t2;
92
- const isReadOnly = t3 === void 0 ? false : t3;
96
+ const ownReadOnly = t3 === void 0 ? false : t3;
93
97
  const theme = useTheme();
98
+ const group = use(CheckboxGroupContext);
99
+ const messageId = useId();
100
+ const control = useRef(null);
101
+ const members = group?.members;
102
+ if (group !== null && value === void 0) throw new Error("A Checkbox inside a CheckboxGroup names the entry it stands for with `value`.");
103
+ const isDisabled = ownDisabled || (group?.isDisabled ?? false);
104
+ const isReadOnly = ownReadOnly || (group?.isReadOnly ?? false);
94
105
  let t4;
95
- if ($[13] !== defaultSelected || $[14] !== isReadOnly || $[15] !== isSelected || $[16] !== onChange) {
96
- t4 = {
106
+ if ($[14] !== defaultSelected || $[15] !== group || $[16] !== isReadOnly || $[17] !== isSelected || $[18] !== onChange || $[19] !== value) {
107
+ t4 = group === null || value === void 0 ? {
97
108
  defaultSelected,
98
109
  isReadOnly,
99
110
  isSelected,
100
111
  onChange
101
- };
102
- $[13] = defaultSelected;
103
- $[14] = isReadOnly;
104
- $[15] = isSelected;
105
- $[16] = onChange;
106
- $[17] = t4;
107
- } else t4 = $[17];
112
+ } : memberOf(group, value, {
113
+ isReadOnly,
114
+ onChange
115
+ });
116
+ $[14] = defaultSelected;
117
+ $[15] = group;
118
+ $[16] = isReadOnly;
119
+ $[17] = isSelected;
120
+ $[18] = onChange;
121
+ $[19] = value;
122
+ $[20] = t4;
123
+ } else t4 = $[20];
108
124
  const state = useToggleState(t4);
109
- const messageId = useId();
125
+ let t5;
126
+ let t6;
127
+ if ($[21] !== members || $[22] !== messageId) {
128
+ t5 = () => {
129
+ members?.add(messageId, control);
130
+ return () => {
131
+ members?.remove(messageId);
132
+ };
133
+ };
134
+ t6 = [members, messageId];
135
+ $[21] = members;
136
+ $[22] = messageId;
137
+ $[23] = t5;
138
+ $[24] = t6;
139
+ } else {
140
+ t5 = $[23];
141
+ t6 = $[24];
142
+ }
143
+ useEffect(t5, t6);
110
144
  const { colors, radii } = theme;
111
145
  const marked = state.isSelected || isIndeterminate;
112
146
  const interactive = !isDisabled && !isReadOnly;
113
- const tone = error === void 0 ? marked ? "marked" : "unmarked" : "error";
114
- const t5 = colors[LAYERS[tone].hover];
115
- let t6;
116
- if ($[18] !== radii.circle) {
117
- t6 = { borderRadius: radii.circle };
118
- $[18] = radii.circle;
119
- $[19] = t6;
120
- } else t6 = $[19];
121
- const t7 = !interactive;
122
- const t8 = colors[LAYERS[tone].pressed];
123
- let t9;
124
- if ($[20] !== t5 || $[21] !== t6 || $[22] !== t7 || $[23] !== t8) {
125
- t9 = {
126
- color: t5,
127
- corners: t6,
128
- disabled: t7,
147
+ const tone = error !== void 0 || (group?.isInvalid ?? false) ? "error" : marked ? "marked" : "unmarked";
148
+ const t7 = colors[LAYERS[tone].hover];
149
+ let t8;
150
+ if ($[25] !== radii.circle) {
151
+ t8 = { borderRadius: radii.circle };
152
+ $[25] = radii.circle;
153
+ $[26] = t8;
154
+ } else t8 = $[26];
155
+ const t9 = !interactive;
156
+ const t10 = colors[LAYERS[tone].pressed];
157
+ let t11;
158
+ if ($[27] !== t10 || $[28] !== t7 || $[29] !== t8 || $[30] !== t9) {
159
+ t11 = {
160
+ color: t7,
161
+ corners: t8,
162
+ disabled: t9,
129
163
  disc: 40,
130
- pressedColor: t8
164
+ pressedColor: t10
131
165
  };
132
- $[20] = t5;
133
- $[21] = t6;
134
- $[22] = t7;
135
- $[23] = t8;
136
- $[24] = t9;
137
- } else t9 = $[24];
138
- const feedback = usePressFeedback(t9);
166
+ $[27] = t10;
167
+ $[28] = t7;
168
+ $[29] = t8;
169
+ $[30] = t9;
170
+ $[31] = t11;
171
+ } else t11 = $[31];
172
+ const feedback = usePressFeedback(t11);
139
173
  const active = feedback.hovered || feedback.pressed || feedback.ring !== void 0;
140
- const t10 = isIndeterminate ? "mixed" : state.isSelected;
141
- let t11;
142
- if ($[25] !== description || $[26] !== error || $[27] !== messageId) {
143
- t11 = describedBy(messageId, messageOf(description, error));
144
- $[25] = description;
145
- $[26] = error;
146
- $[27] = messageId;
147
- $[28] = t11;
148
- } else t11 = $[28];
149
- const t12 = feedback.handlers;
174
+ const t12 = isIndeterminate ? "mixed" : state.isSelected;
150
175
  let t13;
151
- if ($[29] === Symbol.for("react.memo_cache_sentinel")) {
152
- t13 = hitSlop(40, 40);
153
- $[29] = t13;
154
- } else t13 = $[29];
155
- let t14;
156
- if ($[30] !== state) {
157
- t14 = toggleOf(state);
158
- $[30] = state;
159
- $[31] = t14;
160
- } else t14 = $[31];
176
+ if ($[32] !== description || $[33] !== error || $[34] !== messageId) {
177
+ t13 = describedBy(messageId, messageOf(description, error));
178
+ $[32] = description;
179
+ $[33] = error;
180
+ $[34] = messageId;
181
+ $[35] = t13;
182
+ } else t13 = $[35];
183
+ const t14 = feedback.handlers;
161
184
  let t15;
162
- if ($[32] !== theme) {
163
- t15 = controlStylesOf(theme);
164
- $[32] = theme;
165
- $[33] = t15;
166
- } else t15 = $[33];
167
- const t16 = t15.row;
185
+ if ($[36] === Symbol.for("react.memo_cache_sentinel")) {
186
+ t15 = hitSlop(40, 40);
187
+ $[36] = t15;
188
+ } else t15 = $[36];
189
+ let t16;
190
+ if ($[37] !== state) {
191
+ t16 = toggleOf(state);
192
+ $[37] = state;
193
+ $[38] = t16;
194
+ } else t16 = $[38];
168
195
  let t17;
169
- if ($[34] !== feedback.ring || $[35] !== theme) {
170
- t17 = composeStyles(controlStylesOf(theme).disc, feedback.ring);
171
- $[34] = feedback.ring;
172
- $[35] = theme;
173
- $[36] = t17;
174
- } else t17 = $[36];
175
- let t18;
176
- if ($[37] !== active || $[38] !== isDisabled || $[39] !== isIndeterminate || $[40] !== state.isSelected || $[41] !== tone) {
177
- t18 = /* @__PURE__ */ jsx(CheckboxBox, {
196
+ if ($[39] !== theme) {
197
+ t17 = controlStylesOf(theme);
198
+ $[39] = theme;
199
+ $[40] = t17;
200
+ } else t17 = $[40];
201
+ const t18 = t17.row;
202
+ let t19;
203
+ if ($[41] !== feedback.ring || $[42] !== theme) {
204
+ t19 = composeStyles(controlStylesOf(theme).disc, feedback.ring);
205
+ $[41] = feedback.ring;
206
+ $[42] = theme;
207
+ $[43] = t19;
208
+ } else t19 = $[43];
209
+ let t20;
210
+ if ($[44] !== active || $[45] !== isDisabled || $[46] !== isIndeterminate || $[47] !== state.isSelected || $[48] !== tone) {
211
+ t20 = /* @__PURE__ */ jsx(CheckboxBox, {
178
212
  active,
179
213
  isDisabled,
180
214
  isIndeterminate,
@@ -182,85 +216,96 @@ function Checkbox(t0) {
182
216
  tone,
183
217
  within: 40
184
218
  });
185
- $[37] = active;
186
- $[38] = isDisabled;
187
- $[39] = isIndeterminate;
188
- $[40] = state.isSelected;
189
- $[41] = tone;
190
- $[42] = t18;
191
- } else t18 = $[42];
192
- let t19;
193
- if ($[43] !== feedback.layer || $[44] !== t17 || $[45] !== t18) {
194
- t19 = /* @__PURE__ */ jsxs(View, {
195
- style: t17,
196
- children: [feedback.layer, t18]
219
+ $[44] = active;
220
+ $[45] = isDisabled;
221
+ $[46] = isIndeterminate;
222
+ $[47] = state.isSelected;
223
+ $[48] = tone;
224
+ $[49] = t20;
225
+ } else t20 = $[49];
226
+ let t21;
227
+ if ($[50] !== feedback.layer || $[51] !== t19 || $[52] !== t20) {
228
+ t21 = /* @__PURE__ */ jsxs(View, {
229
+ style: t19,
230
+ children: [feedback.layer, t20]
197
231
  });
198
- $[43] = feedback.layer;
199
- $[44] = t17;
200
- $[45] = t18;
201
- $[46] = t19;
202
- } else t19 = $[46];
203
- let t20;
204
- if ($[47] !== children || $[48] !== isDisabled) {
205
- t20 = /* @__PURE__ */ jsx(ControlLabel, {
232
+ $[50] = feedback.layer;
233
+ $[51] = t19;
234
+ $[52] = t20;
235
+ $[53] = t21;
236
+ } else t21 = $[53];
237
+ let t22;
238
+ if ($[54] !== children || $[55] !== isDisabled) {
239
+ t22 = /* @__PURE__ */ jsx(ControlLabel, {
206
240
  isDisabled,
207
241
  children
208
242
  });
209
- $[47] = children;
210
- $[48] = isDisabled;
211
- $[49] = t20;
212
- } else t20 = $[49];
213
- let t21;
214
- if ($[50] !== ariaLabel || $[51] !== feedback.handlers || $[52] !== isDisabled || $[53] !== t10 || $[54] !== t11 || $[55] !== t14 || $[56] !== t15.row || $[57] !== t19 || $[58] !== t20) {
215
- t21 = /* @__PURE__ */ jsxs(Pressable, {
216
- "aria-checked": t10,
243
+ $[54] = children;
244
+ $[55] = isDisabled;
245
+ $[56] = t22;
246
+ } else t22 = $[56];
247
+ let t23;
248
+ if ($[57] !== ariaLabel || $[58] !== feedback.handlers || $[59] !== isDisabled || $[60] !== t12 || $[61] !== t13 || $[62] !== t16 || $[63] !== t17.row || $[64] !== t21 || $[65] !== t22) {
249
+ t23 = /* @__PURE__ */ jsxs(Pressable, {
250
+ "aria-checked": t12,
217
251
  "aria-label": ariaLabel,
218
252
  role: "checkbox",
219
- ...t11,
220
- ...t12,
253
+ ...t13,
254
+ ...t14,
221
255
  disabled: isDisabled,
222
- hitSlop: t13,
223
- onPress: t14,
224
- style: t16,
225
- children: [t19, t20]
256
+ hitSlop: t15,
257
+ onPress: t16,
258
+ ref: control,
259
+ style: t18,
260
+ children: [t21, t22]
226
261
  });
227
- $[50] = ariaLabel;
228
- $[51] = feedback.handlers;
229
- $[52] = isDisabled;
230
- $[53] = t10;
231
- $[54] = t11;
232
- $[55] = t14;
233
- $[56] = t15.row;
234
- $[57] = t19;
235
- $[58] = t20;
236
- $[59] = t21;
237
- } else t21 = $[59];
238
- let t22;
239
- if ($[60] !== description || $[61] !== error || $[62] !== messageId) {
240
- t22 = /* @__PURE__ */ jsx(ControlMessage, {
262
+ $[57] = ariaLabel;
263
+ $[58] = feedback.handlers;
264
+ $[59] = isDisabled;
265
+ $[60] = t12;
266
+ $[61] = t13;
267
+ $[62] = t16;
268
+ $[63] = t17.row;
269
+ $[64] = t21;
270
+ $[65] = t22;
271
+ $[66] = t23;
272
+ } else t23 = $[66];
273
+ let t24;
274
+ if ($[67] !== description || $[68] !== error || $[69] !== messageId) {
275
+ t24 = /* @__PURE__ */ jsx(ControlMessage, {
241
276
  description,
242
277
  error,
243
278
  id: messageId
244
279
  });
245
- $[60] = description;
246
- $[61] = error;
247
- $[62] = messageId;
248
- $[63] = t22;
249
- } else t22 = $[63];
250
- let t23;
251
- if ($[64] !== props || $[65] !== style || $[66] !== t21 || $[67] !== t22) {
252
- t23 = /* @__PURE__ */ jsxs(View, {
280
+ $[67] = description;
281
+ $[68] = error;
282
+ $[69] = messageId;
283
+ $[70] = t24;
284
+ } else t24 = $[70];
285
+ let t25;
286
+ if ($[71] !== props || $[72] !== style || $[73] !== t23 || $[74] !== t24) {
287
+ t25 = /* @__PURE__ */ jsxs(View, {
253
288
  ...props,
254
289
  style,
255
- children: [t21, t22]
290
+ children: [t23, t24]
256
291
  });
257
- $[64] = props;
258
- $[65] = style;
259
- $[66] = t21;
260
- $[67] = t22;
261
- $[68] = t23;
262
- } else t23 = $[68];
263
- return t23;
292
+ $[71] = props;
293
+ $[72] = style;
294
+ $[73] = t23;
295
+ $[74] = t24;
296
+ $[75] = t25;
297
+ } else t25 = $[75];
298
+ return t25;
299
+ }
300
+ function memberOf(group, value, { isReadOnly, onChange }) {
301
+ return {
302
+ isReadOnly,
303
+ isSelected: group.isSelected(value),
304
+ onChange: (isSelected) => {
305
+ group.set(value, isSelected);
306
+ onChange?.(isSelected);
307
+ }
308
+ };
264
309
  }
265
310
  function toggleOf(state) {
266
311
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ComponentRef","ReactNode","Ref","StyleProp","ViewProps","ViewStyle","ToggleState","useId","Pressable","View","useToggleState","CheckboxTone","ResolvedTheme","ControlLabel","ControlMessage","describedBy","LAYER_SIZE","messageOf","CheckboxBox","controlStylesOf","hitSlop","usePressFeedback","useTheme","composeStyles","CheckboxProps","Omit","children","defaultSelected","description","error","isDisabled","isIndeterminate","isReadOnly","isSelected","onChange","ref","style","LAYERS","Readonly","Record","hover","pressed","marked","unmarked","Checkbox","t0","$","_c","ariaLabel","props","t1","t2","t3","undefined","theme","t4","state","messageId","colors","radii","interactive","tone","t5","t6","circle","borderRadius","t7","t8","t9","color","corners","disabled","disc","pressedColor","feedback","active","hovered","ring","t10","t11","t12","handlers","t13","Symbol","for","t14","toggleOf","t15","t16","row","t17","t18","t19","layer","t20","t21","t22","t23","toggle","_c"],"sources":["../../../src/components/checkbox/index.tsx"],"sourcesContent":["import type { ComponentRef, ReactNode, Ref } from 'react'\nimport type { StyleProp, ViewProps, ViewStyle } from 'react-native'\nimport type { ToggleState } from 'react-stately/useToggleState'\n\nimport { useId } from 'react'\nimport { Pressable, View } from 'react-native'\nimport { useToggleState } from 'react-stately/useToggleState'\n\nimport type { CheckboxTone } from '../../control/checkbox-box'\nimport type { ResolvedTheme } from '../../theme/scope'\n\nimport {\n ControlLabel,\n ControlMessage,\n describedBy,\n LAYER_SIZE,\n messageOf,\n} from '../../control'\nimport { CheckboxBox } from '../../control/checkbox-box'\nimport { controlStylesOf } from '../../control/styles'\nimport { hitSlop, usePressFeedback } from '../../press'\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles } from '../../theme/styles'\n\n// The checkbox page, as kanso-ui's Checkbox draws it: an 18dp box with a 2dp\n// corner and an 18dp glyph, inside a 40dp state layer, with a 48dp target.\n// Unselected, the box is a 2dp rule in on surface variant that turns on\n// surface while hovered, pressed or focused; selected or indeterminate, it\n// fills with primary and the glyph takes on primary. The error pair is error\n// and on error, and disabled is on surface at the disabled opacity for the\n// rule or the fill, with the glyph in surface. The state layer is on surface\n// over an unselected box and primary over a selected one while hovered, and\n// the two swap once pressed.\n//\n// The box eases between its colours over the motion tokens' short duration\n// on the standard curve, as web's transition does, and at once for a reader\n// who asks the device for reduced motion. The glyph arrives with the fill.\n//\n// The row, the label and the line under it are src/control's, which Radio\n// and Switch draw through as well. The whole row is the `Pressable`, so a\n// press on the label toggles the box, as a press on web's label does. The\n// line under it is outside the row, as web's is outside its label.\n//\n// The corner is a literal: the page's 2dp is a step the shape scale does not\n// carry.\n\ntype CheckboxProps = Omit<ViewProps, 'children' | 'style'> & {\n /**\n * The label, beside the box. A checkbox that a row labels some other way\n * leaves it out and passes `aria-label` instead.\n */\n readonly children?: ReactNode\n /**\n * Whether the checkbox starts selected, when it keeps its own state.\n * @default false\n */\n readonly defaultSelected?: boolean\n /**\n * A hint under the label. Replaced by `error` when there is one, so the\n * two never stack.\n */\n readonly description?: string\n /**\n * The problem with the current value, in words. Its presence is what puts\n * the checkbox in its error state: the message and the error colours both\n * follow from it.\n */\n readonly error?: string\n /**\n * Draws the checkbox disabled, and takes no presses.\n * @default false\n */\n readonly isDisabled?: boolean\n /**\n * Draws the dash for a box that stands for a partly selected set, and\n * reports the box as mixed to a screen reader. It is the call site's to\n * clear: a press still changes `isSelected` underneath.\n * @default false\n */\n readonly isIndeterminate?: boolean\n /**\n * Shows the state without letting a press change it.\n * @default false\n */\n readonly isReadOnly?: boolean\n /**\n * Whether the checkbox is selected, for a call site holding the state\n * itself with `onChange`.\n */\n readonly isSelected?: boolean\n /** Called with the new state whenever a press changes it. */\n readonly onChange?: (isSelected: boolean) => void\n readonly ref?: Ref<ComponentRef<typeof View>>\n readonly style?: StyleProp<ViewStyle>\n}\n\n// The state layer's colour roles, hovered or focused and pressed. Error is\n// error throughout; otherwise the two swap once pressed.\nconst LAYERS: Readonly<\n Record<\n CheckboxTone,\n {\n readonly hover: keyof ResolvedTheme['colors']\n readonly pressed: keyof ResolvedTheme['colors']\n }\n >\n> = {\n error: { hover: 'error', pressed: 'error' },\n marked: { hover: 'primary', pressed: 'onSurface' },\n unmarked: { hover: 'onSurface', pressed: 'primary' },\n}\n\n/**\n * A checkbox with its label, and optionally a description or an error under\n * it. Its state is React Stately's, as web's is: pass `isSelected` with\n * `onChange` to control it, or `defaultSelected` to let it keep its own.\n * `isIndeterminate` draws the dash for a box that stands for a partly\n * selected set.\n *\n * ```tsx\n * <Checkbox defaultSelected description=\"Supporting line\">\n * Label\n * </Checkbox>\n * ```\n *\n * A screen reader hears it as a checkbox named by its label, checked,\n * unchecked or mixed, followed by the line under it. A press anywhere on the\n * box or the label toggles it, and the row takes presses over the 48dp target\n * the page asks of the box. `style`, `ref` and `testID` land on the view\n * holding the row and the line under it, which is the element a layout\n * positions.\n */\nfunction Checkbox({\n 'aria-label': ariaLabel,\n children,\n defaultSelected,\n description,\n error,\n isDisabled = false,\n isIndeterminate = false,\n isReadOnly = false,\n isSelected,\n onChange,\n style,\n ...props\n}: CheckboxProps) {\n const theme = useTheme()\n const state = useToggleState({\n defaultSelected,\n isReadOnly,\n isSelected,\n onChange,\n })\n const messageId = useId()\n\n const { colors, radii } = theme\n const marked = state.isSelected || isIndeterminate\n const interactive = !isDisabled && !isReadOnly\n const tone: CheckboxTone =\n error === undefined ? (marked ? 'marked' : 'unmarked') : 'error'\n\n const feedback = usePressFeedback({\n color: colors[LAYERS[tone].hover],\n corners: { borderRadius: radii.circle },\n disabled: !interactive,\n disc: LAYER_SIZE,\n pressedColor: colors[LAYERS[tone].pressed],\n })\n const active =\n feedback.hovered || feedback.pressed || feedback.ring !== undefined\n\n return (\n <View {...props} style={style}>\n <Pressable\n aria-checked={isIndeterminate ? 'mixed' : state.isSelected}\n aria-label={ariaLabel}\n role=\"checkbox\"\n {...describedBy(messageId, messageOf(description, error))}\n {...feedback.handlers}\n disabled={isDisabled}\n hitSlop={hitSlop(LAYER_SIZE, LAYER_SIZE)}\n onPress={toggleOf(state)}\n style={controlStylesOf(theme).row}\n >\n <View\n style={composeStyles<ViewStyle>(\n controlStylesOf(theme).disc,\n feedback.ring,\n )}\n >\n {feedback.layer}\n <CheckboxBox\n active={active}\n isDisabled={isDisabled}\n isIndeterminate={isIndeterminate}\n isSelected={state.isSelected}\n tone={tone}\n within={LAYER_SIZE}\n />\n </View>\n <ControlLabel isDisabled={isDisabled}>{children}</ControlLabel>\n </Pressable>\n <ControlMessage description={description} error={error} id={messageId} />\n </View>\n )\n}\n\n// A press's toggle. Built by a call rather than declared in the component,\n// which is what react-perf's jsx-no-new-function-as-prop is after; the React\n// Compiler memoises the result on its input.\nfunction toggleOf(state: ToggleState) {\n return () => {\n state.toggle()\n }\n}\n\nexport { Checkbox }\nexport type { CheckboxProps }\n"],"mappings":";;;;;;;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","ToggleState","ToggleStateOptions","use","useEffect","useId","useRef","Pressable","View","useToggleState","CheckboxTone","CheckboxGroupContextValue","ResolvedTheme","ControlLabel","ControlMessage","describedBy","LAYER_SIZE","messageOf","CheckboxBox","CheckboxGroupContext","controlStylesOf","hitSlop","usePressFeedback","useTheme","composeStyles","CheckboxProps","Omit","children","defaultSelected","description","error","isDisabled","isIndeterminate","isReadOnly","isSelected","onChange","ref","style","value","LAYERS","Readonly","Record","hover","pressed","marked","unmarked","Checkbox","t0","$","_c","ariaLabel","props","t1","t2","t3","ownDisabled","undefined","ownReadOnly","theme","group","messageId","control","members","Error","t4","memberOf","state","t5","t6","add","remove","colors","radii","interactive","invalid","isInvalid","tone","t7","t8","circle","borderRadius","t9","t10","t11","color","corners","disabled","disc","pressedColor","feedback","active","hovered","ring","t12","t13","t14","handlers","t15","Symbol","for","t16","toggleOf","t17","t18","row","t19","t20","t21","layer","t22","t23","t24","t25","Pick","set","toggle","_c"],"sources":["../../../src/components/checkbox/index.tsx"],"sourcesContent":["import type { ComponentRef, ReactNode, Ref } from 'react'\nimport type { StyleProp, ViewProps, ViewStyle } from 'react-native'\nimport type {\n ToggleState,\n ToggleStateOptions,\n} from 'react-stately/useToggleState'\n\nimport { use, useEffect, useId, useRef } from 'react'\nimport { Pressable, View } from 'react-native'\nimport { useToggleState } from 'react-stately/useToggleState'\n\nimport type { CheckboxTone } from '../../control/checkbox-box'\nimport type { CheckboxGroupContextValue } from '../../control/group'\nimport type { ResolvedTheme } from '../../theme/scope'\n\nimport {\n ControlLabel,\n ControlMessage,\n describedBy,\n LAYER_SIZE,\n messageOf,\n} from '../../control'\nimport { CheckboxBox } from '../../control/checkbox-box'\nimport { CheckboxGroupContext } from '../../control/group'\nimport { controlStylesOf } from '../../control/styles'\nimport { hitSlop, usePressFeedback } from '../../press'\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles } from '../../theme/styles'\n\n// The checkbox page, as kanso-ui's Checkbox draws it: an 18dp box with a 2dp\n// corner and an 18dp glyph, inside a 40dp state layer, with a 48dp target.\n// Unselected, the box is a 2dp rule in on surface variant that turns on\n// surface while hovered, pressed or focused; selected or indeterminate, it\n// fills with primary and the glyph takes on primary. The error pair is error\n// and on error, and disabled is on surface at the disabled opacity for the\n// rule or the fill, with the glyph in surface. The state layer is on surface\n// over an unselected box and primary over a selected one while hovered, and\n// the two swap once pressed.\n//\n// The box eases between its colours over the motion tokens' short duration\n// on the standard curve, as web's transition does, and at once for a reader\n// who asks the device for reduced motion. The glyph arrives with the fill.\n//\n// The row, the label and the line under it are src/control's, which Radio\n// and Switch draw through as well. The whole row is the `Pressable`, so a\n// press on the label toggles the box, as a press on web's label does. The\n// line under it is outside the row, as web's is outside its label.\n//\n// Inside a CheckboxGroup the selection is the group's, as web's Checkbox\n// reads React Aria's group state: the box stands for the entry its `value`\n// names, a press selects or clears that entry, and the group's disabled,\n// read-only and error states reach the box as its own would.\n//\n// The corner is a literal: the page's 2dp is a step the shape scale does not\n// carry.\n\ntype CheckboxProps = Omit<ViewProps, 'children' | 'style'> & {\n /**\n * The label, beside the box. A checkbox that a row labels some other way\n * leaves it out and passes `aria-label` instead.\n */\n readonly children?: ReactNode\n /**\n * Whether the checkbox starts selected, when it keeps its own state.\n * @default false\n */\n readonly defaultSelected?: boolean\n /**\n * A hint under the label. Replaced by `error` when there is one, so the\n * two never stack.\n */\n readonly description?: string\n /**\n * The problem with the current value, in words. Its presence is what puts\n * the checkbox in its error state: the message and the error colours both\n * follow from it.\n */\n readonly error?: string\n /**\n * Draws the checkbox disabled, and takes no presses.\n * @default false\n */\n readonly isDisabled?: boolean\n /**\n * Draws the dash for a box that stands for a partly selected set, and\n * reports the box as mixed to a screen reader. It is the call site's to\n * clear: a press still changes `isSelected` underneath.\n * @default false\n */\n readonly isIndeterminate?: boolean\n /**\n * Shows the state without letting a press change it.\n * @default false\n */\n readonly isReadOnly?: boolean\n /**\n * Whether the checkbox is selected, for a call site holding the state\n * itself with `onChange`.\n */\n readonly isSelected?: boolean\n /** Called with the new state whenever a press changes it. */\n readonly onChange?: (isSelected: boolean) => void\n readonly ref?: Ref<ComponentRef<typeof View>>\n readonly style?: StyleProp<ViewStyle>\n /**\n * The entry this checkbox stands for inside a `CheckboxGroup`, which the\n * group's value holds while it is selected. Required there, and unused\n * outside one.\n */\n readonly value?: string\n}\n\n// The state layer's colour roles, hovered or focused and pressed. Error is\n// error throughout; otherwise the two swap once pressed.\nconst LAYERS: Readonly<\n Record<\n CheckboxTone,\n {\n readonly hover: keyof ResolvedTheme['colors']\n readonly pressed: keyof ResolvedTheme['colors']\n }\n >\n> = {\n error: { hover: 'error', pressed: 'error' },\n marked: { hover: 'primary', pressed: 'onSurface' },\n unmarked: { hover: 'onSurface', pressed: 'primary' },\n}\n\n/**\n * A checkbox with its label, and optionally a description or an error under\n * it. Its state is React Stately's, as web's is: pass `isSelected` with\n * `onChange` to control it, or `defaultSelected` to let it keep its own.\n * `isIndeterminate` draws the dash for a box that stands for a partly\n * selected set.\n *\n * ```tsx\n * <Checkbox defaultSelected description=\"Supporting line\">\n * Label\n * </Checkbox>\n * ```\n *\n * A screen reader hears it as a checkbox named by its label, checked,\n * unchecked or mixed, followed by the line under it. A press anywhere on the\n * box or the label toggles it, and the row takes presses over the 48dp target\n * the page asks of the box. `style`, `ref` and `testID` land on the view\n * holding the row and the line under it, which is the element a layout\n * positions.\n */\nfunction Checkbox({\n 'aria-label': ariaLabel,\n children,\n defaultSelected,\n description,\n error,\n isDisabled: ownDisabled = false,\n isIndeterminate = false,\n isReadOnly: ownReadOnly = false,\n isSelected,\n onChange,\n style,\n value,\n ...props\n}: CheckboxProps) {\n const theme = useTheme()\n const group = use(CheckboxGroupContext)\n const messageId = useId()\n const control = useRef<ComponentRef<typeof Pressable>>(null)\n const members = group?.members\n\n if (group !== null && value === undefined) {\n throw new Error(\n 'A Checkbox inside a CheckboxGroup names the entry it stands for with `value`.',\n )\n }\n\n const isDisabled = ownDisabled || (group?.isDisabled ?? false)\n const isReadOnly = ownReadOnly || (group?.isReadOnly ?? false)\n const state = useToggleState(\n group === null || value === undefined\n ? { defaultSelected, isReadOnly, isSelected, onChange }\n : memberOf(group, value, { isReadOnly, onChange }),\n )\n\n // Joins the group's list of checkboxes once, in the order the tree mounts\n // them, so a native form holding the group back focuses the first.\n useEffect(() => {\n members?.add(messageId, control)\n return () => {\n members?.remove(messageId)\n }\n }, [members, messageId])\n\n const { colors, radii } = theme\n const marked = state.isSelected || isIndeterminate\n const interactive = !isDisabled && !isReadOnly\n const invalid = error !== undefined || (group?.isInvalid ?? false)\n const tone: CheckboxTone = invalid ? 'error' : marked ? 'marked' : 'unmarked'\n\n const feedback = usePressFeedback({\n color: colors[LAYERS[tone].hover],\n corners: { borderRadius: radii.circle },\n disabled: !interactive,\n disc: LAYER_SIZE,\n pressedColor: colors[LAYERS[tone].pressed],\n })\n const active =\n feedback.hovered || feedback.pressed || feedback.ring !== undefined\n\n return (\n <View {...props} style={style}>\n <Pressable\n aria-checked={isIndeterminate ? 'mixed' : state.isSelected}\n aria-label={ariaLabel}\n role=\"checkbox\"\n {...describedBy(messageId, messageOf(description, error))}\n {...feedback.handlers}\n disabled={isDisabled}\n hitSlop={hitSlop(LAYER_SIZE, LAYER_SIZE)}\n onPress={toggleOf(state)}\n ref={control}\n style={controlStylesOf(theme).row}\n >\n <View\n style={composeStyles<ViewStyle>(\n controlStylesOf(theme).disc,\n feedback.ring,\n )}\n >\n {feedback.layer}\n <CheckboxBox\n active={active}\n isDisabled={isDisabled}\n isIndeterminate={isIndeterminate}\n isSelected={state.isSelected}\n tone={tone}\n within={LAYER_SIZE}\n />\n </View>\n <ControlLabel isDisabled={isDisabled}>{children}</ControlLabel>\n </Pressable>\n <ControlMessage description={description} error={error} id={messageId} />\n </View>\n )\n}\n\n// The toggle state of a checkbox in a group: selected while the group's\n// value holds its entry, and a change made to the group's value, reported to\n// the checkbox's own `onChange` as well, as React Aria's group item does.\nfunction memberOf(\n group: CheckboxGroupContextValue,\n value: string,\n {\n isReadOnly,\n onChange,\n }: Pick<ToggleStateOptions, 'onChange'> & { readonly isReadOnly: boolean },\n): ToggleStateOptions {\n return {\n isReadOnly,\n isSelected: group.isSelected(value),\n onChange: (isSelected) => {\n group.set(value, isSelected)\n onChange?.(isSelected)\n },\n }\n}\n\n// A press's toggle. Built by a call rather than declared in the component,\n// which is what react-perf's jsx-no-new-function-as-prop is after; the React\n// Compiler memoises the result on its input.\nfunction toggleOf(state: ToggleState) {\n return () => {\n state.toggle()\n }\n}\n\nexport { Checkbox }\nexport type { CheckboxProps }\n"],"mappings":";;;;;;;;;;;;;AAkHA,MAAM4C,SAQF;CACFT,OAAO;EAAEY,OAAO;EAASC,SAAS;CAAQ;CAC1CC,QAAQ;EAAEF,OAAO;EAAWC,SAAS;CAAY;CACjDE,UAAU;EAAEH,OAAO;EAAaC,SAAS;CAAU;AACrD;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAAG,SAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;CAAA,IAAAvB;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAI;CAAA,IAAAC;CAAA,IAAAgB;CAAA,IAAAd;CAAA,IAAAe;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAhB;CAAA,IAAAU,EAAA,OAAAD,IAAA;EAAkB,CAAA,CAAA,cAAAG,WAAAvB,UAAAC,iBAAAC,aAAAC,OAAAC,YAAAqB,IAAApB,iBAAAqB,IAAApB,YAAAqB,IAAApB,YAAAC,UAAAE,OAAAC,OAAA,GAAAa,SAAAJ;EAcFC,EAAA,KAAAD;EAAAC,EAAA,KAAAE;EAAAF,EAAA,KAAArB;EAAAqB,EAAA,KAAApB;EAAAoB,EAAA,KAAAnB;EAAAmB,EAAA,KAAAlB;EAAAkB,EAAA,KAAAd;EAAAc,EAAA,KAAAb;EAAAa,EAAA,KAAAG;EAAAH,EAAA,KAAAX;EAAAW,EAAA,MAAAI;EAAAJ,EAAA,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AE,YAEkB;CACpB,OAAO;EACLF;EACAC,YAAYyB,MAAMzB,WAAWI,KAAK;EAClCH,WAAWD,eAAe;GACxByB,MAAMuD,IAAI5E,OAAOJ,UAAU;GAC3BC,WAAWD,UAAU;EACvB;CACF;AACF;AAKA,SAASmE,SAASnC,OAAoB;CACpC,aAAa;EACXA,MAAMiD,OAAO;CACf;AACF"}
@@ -0,0 +1,93 @@
1
+ import { ValidationResult } from "../../form/index.js";
2
+ import { StyleProp, View, ViewProps, ViewStyle } from "react-native";
3
+ import { ComponentRef, ReactNode, Ref } from "react";
4
+ //#region src/components/checkbox-group/index.d.ts
5
+ type CheckboxGroupProps = Omit<ViewProps, 'children' | 'style'> & {
6
+ /** The checkboxes, each with a `value` of its own. */
7
+ readonly children?: ReactNode;
8
+ /** The entries selected at first, when the group keeps its own value. */
9
+ readonly defaultValue?: readonly string[];
10
+ /**
11
+ * A hint under the group. Replaced by `error` when there is one, so the
12
+ * two never stack.
13
+ */
14
+ readonly description?: string;
15
+ /**
16
+ * The problem with the current selection, in words. Its presence is what
17
+ * puts the group in its error state: the message, the label's colour and
18
+ * every box's error colours follow from it.
19
+ *
20
+ * Outside a `Form` the line under the group arrives with the message, so
21
+ * the group grows when this does and moves what is under it. A `Form`
22
+ * holds that space from the start; so does a permanent `description`.
23
+ */
24
+ readonly error?: string;
25
+ /**
26
+ * Draws every checkbox disabled, and takes no presses.
27
+ * @default false
28
+ */
29
+ readonly isDisabled?: boolean;
30
+ /**
31
+ * Shows the selection without letting a press change it.
32
+ * @default false
33
+ */
34
+ readonly isReadOnly?: boolean;
35
+ /**
36
+ * Marks the group's label, and has a `native` form hold submission back
37
+ * while nothing is selected.
38
+ * @default false
39
+ */
40
+ readonly isRequired?: boolean;
41
+ /**
42
+ * What the group is for. Required rather than optional: a group of
43
+ * checkboxes with no name is a set of boxes a screen reader cannot
44
+ * introduce.
45
+ */
46
+ readonly label: string;
47
+ /**
48
+ * The name the form around the group knows it by, which its
49
+ * `validationErrors` are keyed on. A form hands `onSubmit` one string per
50
+ * name, so a group's selection is not among those values: read it through
51
+ * `onChange`, or hold it with `value`.
52
+ */
53
+ readonly name?: string;
54
+ /** Called with the newly selected entries whenever a press changes them. */
55
+ readonly onChange?: (value: string[]) => void;
56
+ readonly ref?: Ref<ComponentRef<typeof View>>;
57
+ readonly style?: StyleProp<ViewStyle>;
58
+ /**
59
+ * Checks the selection, returning its problem in words, or `true`, `null`
60
+ * or `undefined` when there is none. Shown as it changes, or under a
61
+ * `native` form once a submission is tried.
62
+ */
63
+ readonly validate?: (value: readonly string[]) => ValidationResult;
64
+ /**
65
+ * The selected entries, for a call site holding the value itself with
66
+ * `onChange`.
67
+ */
68
+ readonly value?: readonly string[];
69
+ };
70
+ /**
71
+ * A labelled set of checkboxes with one value between them. The value is
72
+ * React Stately's, as web's is React Aria's: pass `value` with `onChange` to
73
+ * control it, or `defaultValue` to let the group keep its own, and each
74
+ * `Checkbox` inside names the entry it stands for with `value`. Disabled,
75
+ * read-only and the error state reach every checkbox from here.
76
+ *
77
+ * ```tsx
78
+ * <CheckboxGroup defaultValue={['first']} label="Label">
79
+ * <Checkbox value="first">First item</Checkbox>
80
+ * <Checkbox value="second">Second item</Checkbox>
81
+ * </CheckboxGroup>
82
+ * ```
83
+ *
84
+ * A screen reader hears it as a group named by its label. On the web the
85
+ * line under it describes the group, as web's does; on iOS and Android it is
86
+ * read after the checkboxes, where it sits, and an error is announced as it
87
+ * arrives. `style`, `ref` and `testID` land on the group as a whole, which is
88
+ * the element a layout positions.
89
+ */
90
+ declare function CheckboxGroup({ children, defaultValue, description, error, isDisabled, isReadOnly, isRequired, label, name, onChange, style, validate, value, ...props }: CheckboxGroupProps): import("react").JSX.Element;
91
+ //#endregion
92
+ export { CheckboxGroup, type CheckboxGroupProps };
93
+ //# sourceMappingURL=index.d.ts.map