@kanso-labs/react-native-kanso-ui 0.8.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.
Files changed (253) hide show
  1. package/README.md +4 -3
  2. package/dist/autocomplete/index.js +15 -1
  3. package/dist/autocomplete/index.js.map +1 -1
  4. package/dist/badge/index.js +9 -70
  5. package/dist/badge/index.js.map +1 -1
  6. package/dist/button/group.d.ts +5 -0
  7. package/dist/button/group.js +115 -0
  8. package/dist/button/group.js.map +1 -0
  9. package/dist/button/index.d.ts +4 -1
  10. package/dist/button/index.js +45 -23
  11. package/dist/button/index.js.map +1 -1
  12. package/dist/button/palettes.d.ts +2 -0
  13. package/dist/button/slots.js +2 -1
  14. package/dist/button/slots.js.map +1 -1
  15. package/dist/calendar/index.js +351 -182
  16. package/dist/calendar/index.js.map +1 -1
  17. package/dist/calendar/styles.js +33 -2
  18. package/dist/calendar/styles.js.map +1 -1
  19. package/dist/carousel/arrangement.d.ts +5 -0
  20. package/dist/carousel/arrangement.js +123 -0
  21. package/dist/carousel/arrangement.js.map +1 -0
  22. package/dist/chequer/index.js +95 -0
  23. package/dist/chequer/index.js.map +1 -0
  24. package/dist/collection/index.d.ts +157 -0
  25. package/dist/collection/index.js +1331 -0
  26. package/dist/collection/index.js.map +1 -0
  27. package/dist/color-thumb/index.js +56 -0
  28. package/dist/color-thumb/index.js.map +1 -0
  29. package/dist/components/badge/index.d.ts +48 -0
  30. package/dist/components/badge/index.js +122 -0
  31. package/dist/components/badge/index.js.map +1 -0
  32. package/dist/{badge → components/badge}/styles.js +10 -6
  33. package/dist/components/badge/styles.js.map +1 -0
  34. package/dist/components/breadcrumbs/index.d.ts +66 -0
  35. package/dist/components/breadcrumbs/index.js +285 -0
  36. package/dist/components/breadcrumbs/index.js.map +1 -0
  37. package/dist/components/button/index.d.ts +4 -2
  38. package/dist/components/button/index.js +227 -188
  39. package/dist/components/button/index.js.map +1 -1
  40. package/dist/components/button-group/index.d.ts +87 -0
  41. package/dist/components/button-group/index.js +275 -0
  42. package/dist/components/button-group/index.js.map +1 -0
  43. package/dist/components/calendar/index.d.ts +11 -3
  44. package/dist/components/calendar/index.js +60 -45
  45. package/dist/components/calendar/index.js.map +1 -1
  46. package/dist/components/carousel/index.d.ts +72 -0
  47. package/dist/components/carousel/index.js +496 -0
  48. package/dist/components/carousel/index.js.map +1 -0
  49. package/dist/components/checkbox/index.d.ts +7 -1
  50. package/dist/components/checkbox/index.js +183 -138
  51. package/dist/components/checkbox/index.js.map +1 -1
  52. package/dist/components/checkbox-group/index.d.ts +92 -0
  53. package/dist/components/checkbox-group/index.js +306 -0
  54. package/dist/components/checkbox-group/index.js.map +1 -0
  55. package/dist/components/code/index.d.ts +25 -0
  56. package/dist/components/code/index.js +87 -0
  57. package/dist/components/code/index.js.map +1 -0
  58. package/dist/components/color-area/index.d.ts +85 -0
  59. package/dist/components/color-area/index.js +630 -0
  60. package/dist/components/color-area/index.js.map +1 -0
  61. package/dist/components/color-field/index.d.ts +144 -0
  62. package/dist/components/color-field/index.js +516 -0
  63. package/dist/components/color-field/index.js.map +1 -0
  64. package/dist/components/color-picker/index.d.ts +74 -0
  65. package/dist/components/color-picker/index.js +317 -0
  66. package/dist/components/color-picker/index.js.map +1 -0
  67. package/dist/components/color-slider/index.d.ts +82 -0
  68. package/dist/components/color-slider/index.js +456 -0
  69. package/dist/components/color-slider/index.js.map +1 -0
  70. package/dist/components/color-swatch/index.d.ts +46 -0
  71. package/dist/components/color-swatch/index.js +127 -0
  72. package/dist/components/color-swatch/index.js.map +1 -0
  73. package/dist/components/color-swatch-picker/index.d.ts +81 -0
  74. package/dist/components/color-swatch-picker/index.js +287 -0
  75. package/dist/components/color-swatch-picker/index.js.map +1 -0
  76. package/dist/components/color-wheel/index.d.ts +71 -0
  77. package/dist/components/color-wheel/index.js +407 -0
  78. package/dist/components/color-wheel/index.js.map +1 -0
  79. package/dist/components/combo-box/index.d.ts +193 -0
  80. package/dist/components/combo-box/index.js +616 -0
  81. package/dist/components/combo-box/index.js.map +1 -0
  82. package/dist/components/container/index.d.ts +47 -0
  83. package/dist/components/container/index.js +85 -0
  84. package/dist/components/container/index.js.map +1 -0
  85. package/dist/components/date-field/index.d.ts +120 -0
  86. package/dist/components/date-field/index.js +111 -0
  87. package/dist/components/date-field/index.js.map +1 -0
  88. package/dist/components/date-picker/index.d.ts +130 -0
  89. package/dist/components/date-picker/index.js +310 -0
  90. package/dist/components/date-picker/index.js.map +1 -0
  91. package/dist/components/date-range-picker/index.d.ts +139 -0
  92. package/dist/components/date-range-picker/index.js +421 -0
  93. package/dist/components/date-range-picker/index.js.map +1 -0
  94. package/dist/components/disclosure/index.d.ts +94 -0
  95. package/dist/components/disclosure/index.js +365 -0
  96. package/dist/components/disclosure/index.js.map +1 -0
  97. package/dist/components/disclosure-group/index.d.ts +61 -0
  98. package/dist/components/disclosure-group/index.js +100 -0
  99. package/dist/components/disclosure-group/index.js.map +1 -0
  100. package/dist/components/drop-zone/index.d.ts +113 -0
  101. package/dist/components/drop-zone/index.js +304 -0
  102. package/dist/components/drop-zone/index.js.map +1 -0
  103. package/dist/components/fab/index.d.ts +80 -0
  104. package/dist/components/fab/index.js +246 -0
  105. package/dist/components/fab/index.js.map +1 -0
  106. package/dist/components/fab-menu/index.d.ts +120 -0
  107. package/dist/components/fab-menu/index.js +640 -0
  108. package/dist/components/fab-menu/index.js.map +1 -0
  109. package/dist/components/feed/index.d.ts +57 -0
  110. package/dist/components/feed/index.js +167 -0
  111. package/dist/components/feed/index.js.map +1 -0
  112. package/dist/components/form/index.d.ts +3 -2
  113. package/dist/components/form/index.js.map +1 -1
  114. package/dist/components/icon-button/index.d.ts +4 -2
  115. package/dist/components/icon-button/index.js +204 -171
  116. package/dist/components/icon-button/index.js.map +1 -1
  117. package/dist/components/keycap/index.d.ts +27 -0
  118. package/dist/components/keycap/index.js +136 -0
  119. package/dist/components/keycap/index.js.map +1 -0
  120. package/dist/components/list/index.d.ts +15 -158
  121. package/dist/components/list/index.js +21 -1047
  122. package/dist/components/list/index.js.map +1 -1
  123. package/dist/components/list-box/index.d.ts +73 -0
  124. package/dist/components/list-box/index.js +82 -0
  125. package/dist/components/list-box/index.js.map +1 -0
  126. package/dist/components/loading-indicator/index.d.ts +32 -0
  127. package/dist/components/loading-indicator/index.js +174 -0
  128. package/dist/components/loading-indicator/index.js.map +1 -0
  129. package/dist/components/menu/index.js +1 -1
  130. package/dist/components/navigation-tree/index.d.ts +117 -0
  131. package/dist/components/navigation-tree/index.js +135 -0
  132. package/dist/components/navigation-tree/index.js.map +1 -0
  133. package/dist/components/number-field/index.js +132 -143
  134. package/dist/components/number-field/index.js.map +1 -1
  135. package/dist/components/range-calendar/index.d.ts +69 -0
  136. package/dist/components/range-calendar/index.js +144 -0
  137. package/dist/components/range-calendar/index.js.map +1 -0
  138. package/dist/components/search-view/index.d.ts +78 -0
  139. package/dist/components/search-view/index.js +570 -0
  140. package/dist/components/search-view/index.js.map +1 -0
  141. package/dist/components/select/index.d.ts +152 -0
  142. package/dist/components/select/index.js +419 -0
  143. package/dist/components/select/index.js.map +1 -0
  144. package/dist/components/separator/index.d.ts +3 -2
  145. package/dist/components/separator/index.js +29 -26
  146. package/dist/components/separator/index.js.map +1 -1
  147. package/dist/components/slider/index.d.ts +111 -0
  148. package/dist/components/slider/index.js +673 -0
  149. package/dist/components/slider/index.js.map +1 -0
  150. package/dist/components/split-button/index.d.ts +77 -0
  151. package/dist/components/split-button/index.js +354 -0
  152. package/dist/components/split-button/index.js.map +1 -0
  153. package/dist/components/supporting-pane/index.d.ts +44 -0
  154. package/dist/components/supporting-pane/index.js +109 -0
  155. package/dist/components/supporting-pane/index.js.map +1 -0
  156. package/dist/components/tabs/index.d.ts +196 -0
  157. package/dist/components/tabs/index.js +1137 -0
  158. package/dist/components/tabs/index.js.map +1 -0
  159. package/dist/components/text/index.d.ts +1 -1
  160. package/dist/components/text/index.js +49 -21
  161. package/dist/components/text/index.js.map +1 -1
  162. package/dist/components/text-area/index.d.ts +145 -0
  163. package/dist/components/text-area/index.js +231 -0
  164. package/dist/components/text-area/index.js.map +1 -0
  165. package/dist/components/time-field/index.d.ts +43 -0
  166. package/dist/components/time-field/index.js +107 -0
  167. package/dist/components/time-field/index.js.map +1 -0
  168. package/dist/components/time-picker/index.d.ts +65 -0
  169. package/dist/components/time-picker/index.js +1168 -0
  170. package/dist/components/time-picker/index.js.map +1 -0
  171. package/dist/components/toolbar/index.d.ts +53 -0
  172. package/dist/components/toolbar/index.js +185 -0
  173. package/dist/components/toolbar/index.js.map +1 -0
  174. package/dist/components/tooltip/index.d.ts +101 -0
  175. package/dist/components/tooltip/index.js +223 -0
  176. package/dist/components/tooltip/index.js.map +1 -0
  177. package/dist/components/tree/index.d.ts +112 -0
  178. package/dist/components/tree/index.js +157 -0
  179. package/dist/components/tree/index.js.map +1 -0
  180. package/dist/control/group.js +23 -0
  181. package/dist/control/group.js.map +1 -0
  182. package/dist/disclosure/chevron.js +75 -0
  183. package/dist/disclosure/chevron.js.map +1 -0
  184. package/dist/disclosure/index.js +7 -0
  185. package/dist/disclosure/index.js.map +1 -0
  186. package/dist/drop/index.d.ts +54 -0
  187. package/dist/drop/index.js +161 -0
  188. package/dist/drop/index.js.map +1 -0
  189. package/dist/fab/index.d.ts +19 -0
  190. package/dist/fab/index.js +147 -0
  191. package/dist/fab/index.js.map +1 -0
  192. package/dist/field/chevron.js +74 -0
  193. package/dist/field/chevron.js.map +1 -0
  194. package/dist/field/index.d.ts +2 -1
  195. package/dist/field/index.js +350 -153
  196. package/dist/field/index.js.map +1 -1
  197. package/dist/field/styles.js +27 -0
  198. package/dist/field/styles.js.map +1 -1
  199. package/dist/files/index.d.ts +18 -0
  200. package/dist/files/index.js +107 -0
  201. package/dist/files/index.js.map +1 -0
  202. package/dist/form/index.d.ts +6 -4
  203. package/dist/form/index.js +64 -85
  204. package/dist/form/index.js.map +1 -1
  205. package/dist/glyphs/index.js +92 -1
  206. package/dist/glyphs/index.js.map +1 -1
  207. package/dist/i18n/index.js +20 -1
  208. package/dist/i18n/index.js.map +1 -1
  209. package/dist/i18n/messages.js +1394 -34
  210. package/dist/i18n/messages.js.map +1 -1
  211. package/dist/index.d.ts +51 -6
  212. package/dist/index.js +47 -4
  213. package/dist/indicator/paths.js +23 -1
  214. package/dist/indicator/paths.js.map +1 -1
  215. package/dist/modal/index.js +96 -68
  216. package/dist/modal/index.js.map +1 -1
  217. package/dist/navigation/index.js +8 -5
  218. package/dist/navigation/index.js.map +1 -1
  219. package/dist/number/keyboard.js +16 -0
  220. package/dist/number/keyboard.js.map +1 -0
  221. package/dist/overlay/anchored.js +68 -38
  222. package/dist/overlay/anchored.js.map +1 -1
  223. package/dist/overlay/keyboard.js +57 -0
  224. package/dist/overlay/keyboard.js.map +1 -0
  225. package/dist/overlay/panel.js +173 -19
  226. package/dist/overlay/panel.js.map +1 -1
  227. package/dist/overlay/placement.js +16 -2
  228. package/dist/overlay/placement.js.map +1 -1
  229. package/dist/picker/index.js +322 -0
  230. package/dist/picker/index.js.map +1 -0
  231. package/dist/press/index.d.ts +2 -0
  232. package/dist/press/index.js +102 -100
  233. package/dist/press/index.js.map +1 -1
  234. package/dist/row/index.js +77 -69
  235. package/dist/row/index.js.map +1 -1
  236. package/dist/row/styles.js +13 -2
  237. package/dist/row/styles.js.map +1 -1
  238. package/dist/segments/field.js +277 -0
  239. package/dist/segments/field.js.map +1 -0
  240. package/dist/segments/index.js +574 -0
  241. package/dist/segments/index.js.map +1 -0
  242. package/dist/segments/styles.js +24 -0
  243. package/dist/segments/styles.js.map +1 -0
  244. package/dist/separator/index.js +7 -0
  245. package/dist/separator/index.js.map +1 -0
  246. package/dist/slider/index.js +145 -0
  247. package/dist/slider/index.js.map +1 -0
  248. package/dist/swatch/index.js +56 -0
  249. package/dist/swatch/index.js.map +1 -0
  250. package/dist/typography/size.js +14 -0
  251. package/dist/typography/size.js.map +1 -0
  252. package/package.json +11 -2
  253. package/dist/badge/styles.js.map +0 -1
@@ -0,0 +1,136 @@
1
+ import { useTheme } from "../../theme/scope.js";
2
+ import { composeStyles, themedStyles } from "../../theme/styles.js";
3
+ import { useFontFamily } from "../../typography/fonts.js";
4
+ import { familyStyle } from "../../typography/roles.js";
5
+ import { useTextSize } from "../../typography/size.js";
6
+ import { c } from "react/compiler-runtime";
7
+ import { Platform, StyleSheet, Text, View } from "react-native";
8
+ import { isValidElement } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ //#region src/components/keycap/index.tsx
11
+ const SHARE = .8125;
12
+ const LINE = 1.4;
13
+ const RULE = 1;
14
+ function baselineOf(size) {
15
+ return RULE + .31149999999999994 * size;
16
+ }
17
+ const styles = StyleSheet.create({ alone: { alignSelf: "flex-start" } });
18
+ const HIDDEN = {
19
+ accessibilityElementsHidden: true,
20
+ importantForAccessibility: "no-hide-descendants"
21
+ };
22
+ const stylesOf = themedStyles(({ colors, radii, spacing }) => StyleSheet.create({
23
+ cap: {
24
+ borderColor: colors.outline,
25
+ borderRadius: radii.xs,
26
+ borderWidth: RULE,
27
+ paddingHorizontal: spacing.xxs
28
+ },
29
+ text: { color: colors.onSurface }
30
+ }));
31
+ function holdsKeycap(node) {
32
+ if (Array.isArray(node)) return node.some((part) => holdsKeycap(part));
33
+ if (!isValidElement(node)) return false;
34
+ return node.type === Keycap || holdsKeycap(node.props.children);
35
+ }
36
+ /**
37
+ * A single key on a keyboard, as an instruction names it: `Enter`, `Esc`,
38
+ * `Ctrl`. A chord is several of these, combined at the call site.
39
+ *
40
+ * ```tsx
41
+ * <Text variant="bodyLarge">
42
+ * Press <Keycap>Esc</Keycap> to dismiss
43
+ * </Text>
44
+ * ```
45
+ *
46
+ * It takes its size from the Text around it, so a key named in a heading and
47
+ * one named in a footnote are the same component, and stays part of that
48
+ * Text's sentence to a screen reader. `style`, `ref` and `testID` land on the
49
+ * cap's `View`, and a `style` there applies over its own.
50
+ */
51
+ function Keycap(t0) {
52
+ const $ = c(14);
53
+ let children;
54
+ let props;
55
+ let style;
56
+ if ($[0] !== t0) {
57
+ ({children, style, ...props} = t0);
58
+ $[0] = t0;
59
+ $[1] = children;
60
+ $[2] = props;
61
+ $[3] = style;
62
+ } else {
63
+ children = $[1];
64
+ props = $[2];
65
+ style = $[3];
66
+ }
67
+ const theme = useTheme();
68
+ const own = stylesOf(theme);
69
+ const around = useTextSize();
70
+ const mono = useFontFamily(theme.typography.fontFamilyMono);
71
+ const size = (around ?? theme.typography.bodyMediumSize) * SHARE;
72
+ const inline = around !== void 0;
73
+ const native = Platform.OS !== "web";
74
+ const lowered = inline && native ? { transform: [{ translateY: baselineOf(size) }] } : null;
75
+ const T0 = View;
76
+ const t1 = inline && native ? HIDDEN : null;
77
+ const t2 = composeStyles(own.cap, inline ? null : styles.alone, lowered, style);
78
+ const T1 = Text;
79
+ const t3 = 1;
80
+ const t4 = composeStyles(own.text, familyStyle(mono), {
81
+ fontSize: size,
82
+ lineHeight: size * LINE
83
+ });
84
+ let t5;
85
+ if ($[4] !== T1 || $[5] !== children || $[6] !== t4) {
86
+ t5 = /* @__PURE__ */ jsx(T1, {
87
+ numberOfLines: t3,
88
+ style: t4,
89
+ children
90
+ });
91
+ $[4] = T1;
92
+ $[5] = children;
93
+ $[6] = t4;
94
+ $[7] = t5;
95
+ } else t5 = $[7];
96
+ let t6;
97
+ if ($[8] !== T0 || $[9] !== props || $[10] !== t1 || $[11] !== t2 || $[12] !== t5) {
98
+ t6 = /* @__PURE__ */ jsx(T0, {
99
+ ...t1,
100
+ ...props,
101
+ style: t2,
102
+ children: t5
103
+ });
104
+ $[8] = T0;
105
+ $[9] = props;
106
+ $[10] = t1;
107
+ $[11] = t2;
108
+ $[12] = t5;
109
+ $[13] = t6;
110
+ } else t6 = $[13];
111
+ return t6;
112
+ }
113
+ /**
114
+ * The words a Text holding a Keycap says to a screen reader on iOS and
115
+ * Android, with each key's name in its place, or `undefined` for one holding
116
+ * no Keycap, or anything whose words cannot be read off its children.
117
+ */
118
+ function sentenceLabel(children) {
119
+ if (Platform.OS === "web" || !holdsKeycap(children)) return;
120
+ return spoken(children) ?? void 0;
121
+ }
122
+ function spoken(node) {
123
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
124
+ if (typeof node === "string" || typeof node === "number") return String(node);
125
+ if (Array.isArray(node)) {
126
+ const parts = node.map((part) => spoken(part));
127
+ return parts.includes(null) ? null : parts.join("");
128
+ }
129
+ if (!isValidElement(node)) return null;
130
+ if (node.props.onPress !== void 0 || node.props.children === void 0) return null;
131
+ return spoken(node.props.children);
132
+ }
133
+ //#endregion
134
+ export { Keycap, sentenceLabel };
135
+
136
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["ComponentRef","ReactNode","Ref","TextStyle","ViewProps","ViewStyle","isValidElement","Text","NativeText","Platform","StyleSheet","View","useTheme","composeStyles","themedStyles","useFontFamily","familyStyle","useTextSize","SHARE","LINE","ASCENT","DESCENT","RULE","baselineOf","size","styles","create","alone","alignSelf","HIDDEN","accessibilityElementsHidden","importantForAccessibility","stylesOf","colors","radii","spacing","cap","borderColor","outline","borderRadius","xs","borderWidth","paddingHorizontal","xxs","text","color","onSurface","KeycapProps","Omit","children","ref","holdsKeycap","node","Array","isArray","some","part","type","Keycap","props","t0","$","_c","style","theme","own","around","mono","typography","fontFamilyMono","bodyMediumSize","inline","undefined","native","OS","lowered","transform","translateY","T0","t1","t2","T1","t3","t4","fontSize","lineHeight","t5","t6","sentenceLabel","spoken","String","parts","map","includes","join","onPress","_c","NativeText"],"sources":["../../../src/components/keycap/index.tsx"],"sourcesContent":["import type { ComponentRef, ReactNode, Ref } from 'react'\nimport type { TextStyle, ViewProps, ViewStyle } from 'react-native'\n\nimport { isValidElement } from 'react'\nimport { Text as NativeText, Platform, StyleSheet, View } from 'react-native'\n\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles, themedStyles } from '../../theme/styles'\nimport { useFontFamily } from '../../typography/fonts'\nimport { familyStyle } from '../../typography/roles'\nimport { useTextSize } from '../../typography/size'\n\n// kanso-ui's Keycap: one key on a keyboard, as an instruction names it, drawn\n// as a small outlined cap in the line of text around it. A chord or a path\n// through a menu is several of them, with the sentence's own words between.\n//\n// No Material Design page draws a key, so it keeps web's reading of the chips\n// spec page: the assist chip's 1dp rule in the outline role, and the\n// extra-small corner rather than the chip's small one, since a box the height\n// of a line has no room for 8dp. No fill, so a keycap inside a Card or a Sheet\n// does not read as a nested surface. The text is on surface in the mono face,\n// at 0.8125 of the size around it on a 1.4 line height, a share smaller than\n// Code's because the rule adds height the glyphs do not, and on one line,\n// since 'Enter' broken across two stops reading as one key.\n//\n// A Text nested in another draws no border on iOS or Android, so the cap is a\n// View laid inline in the Text around it, which both platforms place on the\n// line, holding a Text of its own. Its size is the share of the one the\n// library's Text provides, as Code's is, and body medium's outside a Text.\n//\n// **iOS and Android stand an inline View on the baseline by its bottom edge**,\n// where React Native Web lays one out as an `inline-flex` box, which shares\n// its text's baseline with the line. So on native the cap is moved down by\n// how far its own baseline sits above its bottom edge: the 1dp rule, half the\n// leading the 1.4 line height adds, and the face's descent. The figures are\n// Roboto Mono's, the mono token's first family, measured in Chromium from the\n// face kanso-ui ships: 1.048em of ascent and 0.271em of descent, so 1.319em of\n// glyph box in a 1.4em line, and the baseline 0.3115em above the line box's\n// bottom. Neither platform's own placement has been measured on a device yet.\n//\n// A screen reader on iOS or Android reads the Text around the cap as one\n// element whose words leave the cap out, since an inline View is not text. So\n// the cap is hidden from it there, and the library's Text, when a Keycap is\n// among its children, speaks the sentence with the key's name in its place,\n// through `sentenceLabel` below. React Native Web reads the cap in its place\n// in the sentence as it is.\n\n// The size against the text around it, web's `0.8125em`.\nconst SHARE = 0.8125\n\n// The line height against the cap's own size, web's `1.4`.\nconst LINE = 1.4\n\n// Roboto Mono's ascent and descent against its size.\nconst ASCENT = 1.048\nconst DESCENT = 0.271\n\n// The rule around the cap, web's `1px`.\nconst RULE = 1\n\n// How far the cap's baseline sits above its bottom edge at a size: the rule,\n// half the leading and the descent.\nfunction baselineOf(size: number) {\n return RULE + ((LINE - ASCENT - DESCENT) / 2 + DESCENT) * size\n}\n\nconst styles = StyleSheet.create({\n // A cap standing on its own shrinks to its key rather than stretching\n // across the column it sits in.\n alone: {\n alignSelf: 'flex-start',\n },\n})\n\n// Kept from a screen reader on iOS and Android, where the Text around the cap\n// speaks its key instead.\nconst HIDDEN: ViewProps = {\n accessibilityElementsHidden: true,\n importantForAccessibility: 'no-hide-descendants',\n}\n\nconst stylesOf = themedStyles(({ colors, radii, spacing }) =>\n StyleSheet.create({\n cap: {\n borderColor: colors.outline,\n borderRadius: radii.xs,\n borderWidth: RULE,\n paddingHorizontal: spacing.xxs,\n },\n text: {\n color: colors.onSurface,\n },\n }),\n)\n\ntype KeycapProps = Omit<ViewProps, 'children'> & {\n /** The key's name, as the instruction writes it, such as `Enter` or `Esc`. */\n readonly children?: ReactNode\n readonly ref?: Ref<ComponentRef<typeof View>>\n}\n\n// Whether a Keycap is among the nodes, at any depth.\nfunction holdsKeycap(node: ReactNode): boolean {\n if (Array.isArray(node)) {\n return node.some((part: ReactNode) => holdsKeycap(part))\n }\n if (!isValidElement<{ children?: ReactNode }>(node)) {\n return false\n }\n return node.type === Keycap || holdsKeycap(node.props.children)\n}\n\n/**\n * A single key on a keyboard, as an instruction names it: `Enter`, `Esc`,\n * `Ctrl`. A chord is several of these, combined at the call site.\n *\n * ```tsx\n * <Text variant=\"bodyLarge\">\n * Press <Keycap>Esc</Keycap> to dismiss\n * </Text>\n * ```\n *\n * It takes its size from the Text around it, so a key named in a heading and\n * one named in a footnote are the same component, and stays part of that\n * Text's sentence to a screen reader. `style`, `ref` and `testID` land on the\n * cap's `View`, and a `style` there applies over its own.\n */\nfunction Keycap({ children, style, ...props }: KeycapProps) {\n const theme = useTheme()\n const own = stylesOf(theme)\n const around = useTextSize()\n const mono = useFontFamily(theme.typography.fontFamilyMono)\n const size = (around ?? theme.typography.bodyMediumSize) * SHARE\n const inline = around !== undefined\n const native = Platform.OS !== 'web'\n const lowered: null | ViewStyle =\n inline && native ? { transform: [{ translateY: baselineOf(size) }] } : null\n\n return (\n <View\n {...(inline && native ? HIDDEN : null)}\n {...props}\n style={composeStyles<ViewStyle>(\n own.cap,\n inline ? null : styles.alone,\n lowered,\n style,\n )}\n >\n <NativeText\n numberOfLines={1}\n style={composeStyles<TextStyle>(own.text, familyStyle(mono), {\n fontSize: size,\n lineHeight: size * LINE,\n })}\n >\n {children}\n </NativeText>\n </View>\n )\n}\n\n/**\n * The words a Text holding a Keycap says to a screen reader on iOS and\n * Android, with each key's name in its place, or `undefined` for one holding\n * no Keycap, or anything whose words cannot be read off its children.\n */\nfunction sentenceLabel(children: ReactNode): string | undefined {\n if (Platform.OS === 'web' || !holdsKeycap(children)) {\n return undefined\n }\n return spoken(children) ?? undefined\n}\n\n// What a node says in a sentence, with each Keycap's name in its place, or\n// `null` where it holds something whose words cannot be read off its\n// children, such as a component that draws its own text or one that presses,\n// which the Text around it then leaves to the platform.\nfunction spoken(node: ReactNode): null | string {\n if (node === null || node === undefined || typeof node === 'boolean') {\n return ''\n }\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node)\n }\n if (Array.isArray(node)) {\n const parts = node.map((part: ReactNode) => spoken(part))\n return parts.includes(null) ? null : parts.join('')\n }\n if (!isValidElement<{ children?: ReactNode; onPress?: unknown }>(node)) {\n return null\n }\n if (node.props.onPress !== undefined || node.props.children === undefined) {\n return null\n }\n return spoken(node.props.children)\n}\n\nexport type { KeycapProps }\n\nexport { Keycap, sentenceLabel }\n"],"mappings":";;;;;;;;;;AAgDA,MAAMkB,QAAQ;AAGd,MAAMC,OAAO;AAOb,MAAMG,OAAO;AAIb,SAASC,WAAWC,MAAc;CAChC,OAAOF,OAAQ,qBAA2CE;AAC5D;AAEA,MAAMC,SAASf,WAAWgB,OAAO,EAG/BC,OAAO,EACLC,WAAW,aACb,EACF,CAAC;AAID,MAAMC,SAAoB;CACxBC,6BAA6B;CAC7BC,2BAA2B;AAC7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WACzD,OAAO;CAET,IAAI,OAAOA,SAAS,YAAY,OAAOA,SAAS,UAC9C,OAAOsC,OAAOtC,IAAI;CAEpB,IAAIC,MAAMC,QAAQF,IAAI,GAAG;EACvB,MAAMuC,QAAQvC,KAAKwC,KAAKpC,SAAoBiC,OAAOjC,IAAI,CAAC;EACxD,OAAOmC,MAAME,SAAS,IAAI,IAAI,OAAOF,MAAMG,KAAK,EAAE;CACpD;CACA,IAAI,CAACxF,eAA4D8C,IAAI,GACnE,OAAO;CAET,IAAIA,KAAKO,MAAMoC,YAAYvB,KAAAA,KAAapB,KAAKO,MAAMV,aAAauB,KAAAA,GAC9D,OAAO;CAET,OAAOiB,OAAOrC,KAAKO,MAAMV,QAAQ;AACnC"}
@@ -1,138 +1,16 @@
1
- import { FlatList, HostInstance, PressableProps, ScrollViewProps, StyleProp, ViewStyle } from "react-native";
2
- import { ReactElement, ReactNode, Ref } from "react";
3
- import { Key, Selection, SelectionMode } from "react-stately";
1
+ import { CollectionLoadMoreProps, CollectionProps, CollectionRowProps, CollectionSectionProps, loaderNode, rowNode, sectionNode } from "../../collection/index.js";
4
2
  //#region src/components/list/index.d.ts
5
- type ListLoadMoreProps = {
6
- /**
7
- * Draws the ring in a row of its own while more items are being fetched.
8
- * @default false
9
- */
10
- readonly isLoading?: boolean;
11
- /**
12
- * What a screen reader calls the ring, and hears as it appears. Left out,
13
- * it is the word for it in the `I18nProvider`'s language, or the device's
14
- * outside one, "Loading more" in English.
15
- */
16
- readonly label?: string;
17
- /**
18
- * Called when the end of the list comes within `scrollOffset` of its
19
- * visible end, while nothing is loading. Called once for each length the
20
- * list reaches, so a load that adds nothing does not start another.
21
- */
22
- readonly onLoadMore?: () => void;
23
- /**
24
- * How far past the visible end of the list the next items are asked for,
25
- * as a share of the list's visible height.
26
- * @default 1
27
- */
28
- readonly scrollOffset?: number;
29
- readonly style?: StyleProp<ViewStyle>;
30
- readonly testID?: string;
31
- };
32
- type ListProps<T extends object = object> = Omit<ScrollViewProps, 'children' | 'role' | 'stickyHeaderIndices' | 'style'> & {
33
- /**
34
- * The rows, each a `List.Item`, `List.Section` or `List.LoadMore`. With
35
- * `items`, a function from an item to its part, called for each item in
36
- * turn.
37
- */
38
- readonly children?: ((item: T) => ReactElement) | ReactNode;
39
- /** The keys selected at first, when the list keeps its own selection. */
40
- readonly defaultSelectedKeys?: 'all' | Iterable<Key>;
41
- /** The keys of the rows drawn disabled, which take no presses. */
42
- readonly disabledKeys?: Iterable<Key>;
43
- /**
44
- * Keeps the last selected row selected, so a press on it changes nothing.
45
- * @default false
46
- */
47
- readonly disallowEmptySelection?: boolean;
48
- /** The entries `children` draws a part for, when it is a function. */
49
- readonly items?: Iterable<T>;
50
- /**
51
- * Called with a row's key when a press runs its action. A row's own
52
- * `onAction` takes its place for that row.
53
- */
54
- readonly onAction?: (key: Key) => void;
55
- /** Called with the selected keys whenever a press changes them. */
56
- readonly onSelectionChange?: (keys: Selection) => void;
57
- readonly ref?: Ref<FlatList>;
58
- /**
59
- * What the list shows when it has no rows and nothing is loading. Left
60
- * out, it is a muted row saying "No results" in the `I18nProvider`'s
61
- * language, or the device's outside one, so the list keeps a row's height.
62
- */
63
- readonly renderEmptyState?: () => ReactNode;
64
- /**
65
- * The selected keys, for a call site holding the selection itself with
66
- * `onSelectionChange`.
67
- */
68
- readonly selectedKeys?: 'all' | Iterable<Key>;
69
- /**
70
- * Whether rows can be selected: one at a time, several, or none. A list
71
- * that selects draws a checkbox on every row.
72
- * @default 'none'
73
- */
74
- readonly selectionMode?: SelectionMode;
75
- /**
76
- * What selecting a row is called, for a screen reader: the accessibility
77
- * action each selectable row offers, which is what its checkbox does. The
78
- * row's own text is what names the row. Left out, it is the word for it in
79
- * the `I18nProvider`'s language, or the device's outside one, "Select" in
80
- * English.
81
- */
82
- readonly selectLabel?: string;
83
- readonly style?: StyleProp<ViewStyle>;
84
- };
85
- type ListRowProps = Omit<PressableProps, 'children' | 'disabled' | 'id' | 'role' | 'style'> & {
86
- /** The row's headline, the one thing it is mostly about. */
87
- readonly children?: ReactNode;
88
- /** The key the row is selected and reported by. Give one to every row. */
89
- readonly id?: Key;
90
- /**
91
- * Draws the row disabled, and takes no presses on it, as a key in the
92
- * list's `disabledKeys` does.
93
- * @default false
94
- */
95
- readonly isDisabled?: boolean;
96
- /** Content before the headline: an avatar, an icon. */
97
- readonly leading?: ReactNode;
98
- /**
99
- * Called when a press runs the row's action, in place of the list's
100
- * `onAction` for this row.
101
- */
102
- readonly onAction?: () => void;
103
- /**
104
- * A line above the headline, in label small and the muted role. Given
105
- * beside `supporting`, it makes the row the three-line item.
106
- */
107
- readonly overline?: ReactNode;
108
- readonly ref?: Ref<HostInstance>;
109
- readonly style?: StyleProp<ViewStyle>;
110
- /** A second line under the headline, in body medium and the muted role. */
111
- readonly supporting?: ReactNode;
112
- /**
113
- * The row's text, read off `children` when they are a plain string, so a
114
- * row whose headline is an element passes it.
115
- */
116
- readonly textValue?: string;
117
- /** Content after the headline, such as an amount or a control. */
118
- readonly trailing?: ReactNode;
119
- };
120
- type ListSectionProps = {
121
- /** The rows in the section. */
122
- readonly children?: ReactNode;
123
- /**
124
- * The section's heading, which stays at the top of the list while the
125
- * section's rows scroll under it. A section without one is its rows alone.
126
- */
127
- readonly header?: ReactNode;
128
- readonly id?: Key;
129
- };
3
+ type ListLoadMoreProps = CollectionLoadMoreProps;
4
+ type ListProps<T extends object = object> = CollectionProps<T>;
5
+ type ListRowProps = CollectionRowProps;
6
+ type ListSectionProps = CollectionSectionProps;
130
7
  /**
131
8
  * A list of rows, one or more of which can be selected. Selection is React
132
9
  * Stately's, as web's is React Aria's: set `selectionMode` to `single` or
133
10
  * `multiple`, and pass `selectedKeys` with `onSelectionChange` to control
134
- * it or `defaultSelectedKeys` to let it keep its own. A list whose rows do
135
- * something takes `onAction`, or an `onAction` on each row.
11
+ * it or `defaultSelectedKeys` to let it keep its own. A list that selects
12
+ * draws a checkbox on every row. A list whose rows do something takes
13
+ * `onAction`, or an `onAction` on each row.
136
14
  *
137
15
  * ```tsx
138
16
  * <List aria-label="Label" selectionMode="multiple">
@@ -146,14 +24,15 @@ type ListSectionProps = {
146
24
  * list draws from their props, so none of them renders anything on its
147
25
  * own. Name the list with `aria-label`. It scrolls by itself, so it wants a
148
26
  * height to fill: a short list on a page that scrolls takes
149
- * `scrollEnabled={false}` and is laid out at its full length. `style` and
150
- * `ref` land on the `FlatList`.
27
+ * `scrollEnabled={false}` and is laid out at its full length. It is drawn
28
+ * on surface, and a section's header stays at the top while its rows scroll
29
+ * under it. `style` and `ref` land on the `FlatList`.
151
30
  *
152
31
  * Inside an `Autocomplete`, the list shows the rows the search keeps and
153
32
  * says how many there are to a screen reader, and a tap on a row reaches it
154
33
  * while the keyboard is up.
155
34
  */
156
- declare function List<T extends object = object>({ children, contentContainerStyle, defaultSelectedKeys, disabledKeys, disallowEmptySelection, items, keyboardShouldPersistTaps, onAction, onSelectionChange, ref, renderEmptyState, selectedKeys, selectionMode, selectLabel, style, ...props }: ListProps<T>): import("react").JSX.Element;
35
+ declare function List<T extends object = object>(props: ListProps<T>): import("react").JSX.Element;
157
36
  declare namespace List {
158
37
  var Item: typeof ListRow;
159
38
  var LoadMore: typeof ListLoadMore;
@@ -167,12 +46,7 @@ declare namespace List {
167
46
  */
168
47
  declare function ListLoadMore(_props: ListLoadMoreProps): null;
169
48
  declare namespace ListLoadMore {
170
- var getCollectionNode: (props: ListLoadMoreProps) => Generator<{
171
- hasChildNodes: boolean;
172
- props: ListLoadMoreProps;
173
- rendered: null;
174
- type: string;
175
- }, void, unknown>;
49
+ var getCollectionNode: typeof loaderNode;
176
50
  }
177
51
  /**
178
52
  * One row. Its slots are ListItem's: `leading`, the headline as children,
@@ -185,15 +59,7 @@ declare namespace ListLoadMore {
185
59
  */
186
60
  declare function ListRow(_props: ListRowProps): null;
187
61
  declare namespace ListRow {
188
- var getCollectionNode: (props: ListRowProps) => Generator<{
189
- 'aria-label': string | undefined;
190
- hasChildNodes: boolean;
191
- key: Key | undefined;
192
- props: ListRowProps;
193
- rendered: ReactNode;
194
- textValue: string;
195
- type: string;
196
- }, void, unknown>;
62
+ var getCollectionNode: typeof rowNode;
197
63
  }
198
64
  /**
199
65
  * A group of rows under a heading, which stays at the top of the list while
@@ -201,16 +67,7 @@ declare namespace ListRow {
201
67
  */
202
68
  declare function ListSection(_props: ListSectionProps): null;
203
69
  declare namespace ListSection {
204
- var getCollectionNode: (props: ListSectionProps) => Generator<{
205
- childNodes(): Generator<{
206
- element: ReactNode;
207
- }, void, unknown>;
208
- hasChildNodes: boolean;
209
- key: Key | undefined;
210
- props: ListSectionProps;
211
- rendered: ReactNode;
212
- type: string;
213
- }, void, unknown>;
70
+ var getCollectionNode: typeof sectionNode;
214
71
  }
215
72
  //#endregion
216
73
  export { List, ListLoadMore, type ListLoadMoreProps, type ListProps, ListRow, type ListRowProps, ListSection, type ListSectionProps };