@kanso-labs/react-native-kanso-ui 0.7.0 → 0.8.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 (80) hide show
  1. package/README.md +37 -0
  2. package/dist/badge/index.js +25 -23
  3. package/dist/badge/index.js.map +1 -1
  4. package/dist/button/index.d.ts +2 -1
  5. package/dist/button/index.js.map +1 -1
  6. package/dist/button/pending.js +17 -21
  7. package/dist/button/pending.js.map +1 -1
  8. package/dist/calendar/index.js +1 -1
  9. package/dist/components/autocomplete/index.js +28 -26
  10. package/dist/components/autocomplete/index.js.map +1 -1
  11. package/dist/components/avatar/index.d.ts +2 -2
  12. package/dist/components/avatar/index.js +2 -2
  13. package/dist/components/avatar/index.js.map +1 -1
  14. package/dist/components/calendar/index.d.ts +1 -1
  15. package/dist/components/calendar/index.js +77 -38
  16. package/dist/components/calendar/index.js.map +1 -1
  17. package/dist/components/chip-group/index.d.ts +4 -3
  18. package/dist/components/chip-group/index.js +47 -45
  19. package/dist/components/chip-group/index.js.map +1 -1
  20. package/dist/components/copy-field/index.d.ts +5 -5
  21. package/dist/components/copy-field/index.js +30 -28
  22. package/dist/components/copy-field/index.js.map +1 -1
  23. package/dist/components/currency/index.d.ts +2 -2
  24. package/dist/components/currency/index.js +3 -1
  25. package/dist/components/currency/index.js.map +1 -1
  26. package/dist/components/list/index.d.ts +6 -5
  27. package/dist/components/list/index.js +97 -106
  28. package/dist/components/list/index.js.map +1 -1
  29. package/dist/components/menu/index.d.ts +4 -3
  30. package/dist/components/menu/index.js +32 -39
  31. package/dist/components/menu/index.js.map +1 -1
  32. package/dist/components/meter/index.d.ts +2 -1
  33. package/dist/components/meter/index.js +9 -7
  34. package/dist/components/meter/index.js.map +1 -1
  35. package/dist/components/number-field/index.d.ts +7 -3
  36. package/dist/components/number-field/index.js +214 -192
  37. package/dist/components/number-field/index.js.map +1 -1
  38. package/dist/components/product-icon/index.d.ts +2 -2
  39. package/dist/components/product-icon/index.js +2 -2
  40. package/dist/components/product-icon/index.js.map +1 -1
  41. package/dist/components/progress-indicator/index.d.ts +2 -1
  42. package/dist/components/progress-indicator/index.js +15 -13
  43. package/dist/components/progress-indicator/index.js.map +1 -1
  44. package/dist/components/search-field/index.d.ts +3 -3
  45. package/dist/components/search-field/index.js +105 -104
  46. package/dist/components/search-field/index.js.map +1 -1
  47. package/dist/components/sheet/index.d.ts +2 -2
  48. package/dist/components/sheet/index.js +22 -26
  49. package/dist/components/sheet/index.js.map +1 -1
  50. package/dist/components/snackbar/index.d.ts +3 -3
  51. package/dist/components/snackbar/index.js +36 -34
  52. package/dist/components/snackbar/index.js.map +1 -1
  53. package/dist/components/tag/index.d.ts +58 -0
  54. package/dist/components/tag/index.js +205 -0
  55. package/dist/components/tag/index.js.map +1 -0
  56. package/dist/components/text-field/index.d.ts +6 -3
  57. package/dist/components/text-field/index.js +3 -0
  58. package/dist/components/text-field/index.js.map +1 -1
  59. package/dist/field/index.js +39 -36
  60. package/dist/field/index.js.map +1 -1
  61. package/dist/i18n/index.js +12 -1
  62. package/dist/i18n/index.js.map +1 -1
  63. package/dist/i18n/messages.js +367 -0
  64. package/dist/i18n/messages.js.map +1 -1
  65. package/dist/i18n/provider.d.ts +53 -0
  66. package/dist/i18n/provider.js +96 -0
  67. package/dist/i18n/provider.js.map +1 -0
  68. package/dist/index.d.ts +3 -1
  69. package/dist/index.js +3 -1
  70. package/dist/indicator/index.js +1 -2
  71. package/dist/indicator/index.js.map +1 -1
  72. package/dist/mark/index.js +77 -117
  73. package/dist/mark/index.js.map +1 -1
  74. package/dist/mark/initials.js.map +1 -1
  75. package/dist/number/count.js +15 -0
  76. package/dist/number/count.js.map +1 -0
  77. package/dist/number/locale.js.map +1 -1
  78. package/dist/overlay/host.js +30 -21
  79. package/dist/overlay/host.js.map +1 -1
  80. package/package.json +1 -1
@@ -2,6 +2,7 @@ import { useTheme } from "../../theme/scope.js";
2
2
  import { composeStyles, themedStyles } from "../../theme/styles.js";
3
3
  import { hitSlop, usePressFeedback } from "../../press/index.js";
4
4
  import { useTypeRole } from "../../typography/roles.js";
5
+ import { useMessages } from "../../i18n/provider.js";
5
6
  import { CloseGlyph } from "../../glyphs/index.js";
6
7
  import { useWindowSizeClass } from "../../hooks/useWindowSizeClass.js";
7
8
  import { Overlay } from "../../overlay/host.js";
@@ -200,39 +201,40 @@ function measureInto(height) {
200
201
  */
201
202
  function Snackbar(t0) {
202
203
  const $ = c(24);
204
+ let ownCloseLabel;
203
205
  let props;
204
206
  let queue;
205
207
  let style;
206
- let t1;
207
208
  if ($[0] !== t0) {
208
- ({closeLabel: t1, queue, style, ...props} = t0);
209
+ ({closeLabel: ownCloseLabel, queue, style, ...props} = t0);
209
210
  $[0] = t0;
210
- $[1] = props;
211
- $[2] = queue;
212
- $[3] = style;
213
- $[4] = t1;
211
+ $[1] = ownCloseLabel;
212
+ $[2] = props;
213
+ $[3] = queue;
214
+ $[4] = style;
214
215
  } else {
215
- props = $[1];
216
- queue = $[2];
217
- style = $[3];
218
- t1 = $[4];
216
+ ownCloseLabel = $[1];
217
+ props = $[2];
218
+ queue = $[3];
219
+ style = $[4];
219
220
  }
220
- const closeLabel = t1 === void 0 ? "Close" : t1;
221
+ const messages = useMessages();
222
+ const closeLabel = ownCloseLabel ?? messages.close;
221
223
  const theme = useTheme();
222
224
  const insets = use(SafeAreaInsetsContext) ?? NO_INSETS;
223
225
  const wide = useWindowSizeClass() !== "compact";
224
226
  const shown = useSyncExternalStore(queue.subscribe, queue.visible);
225
- let t2;
227
+ let t1;
226
228
  if ($[5] !== queue) {
227
- t2 = () => queue.visible()?.key;
229
+ t1 = () => queue.visible()?.key;
228
230
  $[5] = queue;
229
- $[6] = t2;
230
- } else t2 = $[6];
231
- const [standing] = useState(t2);
231
+ $[6] = t1;
232
+ } else t1 = $[6];
233
+ const [standing] = useState(t1);
232
234
  const { spacing } = theme;
233
- let t3;
235
+ let t2;
234
236
  if ($[7] !== insets.bottom || $[8] !== insets.left || $[9] !== insets.right || $[10] !== spacing.sm || $[11] !== style || $[12] !== theme) {
235
- t3 = composeStyles(stylesOf(theme).region, {
237
+ t2 = composeStyles(stylesOf(theme).region, {
236
238
  paddingBottom: spacing.sm + insets.bottom,
237
239
  paddingLeft: spacing.sm + insets.left,
238
240
  paddingRight: spacing.sm + insets.right
@@ -243,11 +245,11 @@ function Snackbar(t0) {
243
245
  $[10] = spacing.sm;
244
246
  $[11] = style;
245
247
  $[12] = theme;
246
- $[13] = t3;
247
- } else t3 = $[13];
248
- let t4;
248
+ $[13] = t2;
249
+ } else t2 = $[13];
250
+ let t3;
249
251
  if ($[14] !== closeLabel || $[15] !== queue || $[16] !== shown || $[17] !== standing || $[18] !== wide) {
250
- t4 = shown === null ? null : /* @__PURE__ */ jsx(SnackbarStrip, {
252
+ t3 = shown === null ? null : /* @__PURE__ */ jsx(SnackbarStrip, {
251
253
  arrives: shown.key !== standing,
252
254
  closeLabel,
253
255
  queue,
@@ -259,22 +261,22 @@ function Snackbar(t0) {
259
261
  $[16] = shown;
260
262
  $[17] = standing;
261
263
  $[18] = wide;
262
- $[19] = t4;
263
- } else t4 = $[19];
264
- let t5;
265
- if ($[20] !== props || $[21] !== t3 || $[22] !== t4) {
266
- t5 = /* @__PURE__ */ jsx(Overlay, { children: /* @__PURE__ */ jsx(View, {
264
+ $[19] = t3;
265
+ } else t3 = $[19];
266
+ let t4;
267
+ if ($[20] !== props || $[21] !== t2 || $[22] !== t3) {
268
+ t4 = /* @__PURE__ */ jsx(Overlay, { children: /* @__PURE__ */ jsx(View, {
267
269
  "aria-live": Platform.OS === "web" ? "polite" : void 0,
268
270
  ...props,
269
- style: t3,
270
- children: t4
271
+ style: t2,
272
+ children: t3
271
273
  }) });
272
274
  $[20] = props;
273
- $[21] = t3;
274
- $[22] = t4;
275
- $[23] = t5;
276
- } else t5 = $[23];
277
- return t5;
275
+ $[21] = t2;
276
+ $[22] = t3;
277
+ $[23] = t4;
278
+ } else t4 = $[23];
279
+ return t4;
278
280
  }
279
281
  /**
280
282
  * One of the snackbar's two controls, a pill drawing the state layer, the
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ComponentRef","ReactNode","Ref","LayoutChangeEvent","StyleProp","TextStyle","ViewProps","ViewStyle","AnimatedStyle","SharedValue","use","useEffect","useRef","useState","useSyncExternalStore","AccessibilityInfo","Text","NativeText","Platform","Pressable","StyleSheet","View","Animated","Easing","useAnimatedStyle","useReducedMotion","useSharedValue","withTiming","SafeAreaInsetsContext","CloseGlyph","useWindowSizeClass","Overlay","hitSlop","usePressFeedback","useTheme","composeStyles","themedStyles","useTypeRole","MESSAGE_MS","UNTIL_CLOSED","MIN_WIDE","MAX_WIDE","MESSAGE_BLOCK_PADDING","RING_WIDTH","RING_OFFSET","NO_INSETS","bottom","left","right","top","stylesOf","colors","radii","shadows","sizing","spacing","create","action","alignItems","justifyContent","minHeight","controlSm","paddingHorizontal","md","paddingVertical","sm","actionLabel","color","inversePrimary","actionRing","outlineColor","outlineOffset","outlineStyle","outlineWidth","close","height","controlMd","width","closeRing","inverseOnSurface","control","borderRadius","pill","message","flexBasis","flexGrow","marginHorizontal","minWidth","messageText","region","paddingTop","pointerEvents","position","strip","backgroundColor","inverseSurface","xs","boxShadow","elevation3","flexDirection","flexWrap","styles","controls","flexShrink","marginStart","wide","maxWidth","ShownMessage","SnackbarAction","key","onClose","showCloseButton","timeout","label","onPress","SnackbarOptions","SnackbarProps","Omit","closeLabel","queue","SnackbarQueue","ref","style","added","listeners","Set","shown","add","options","clear","String","undefined","changed","subscribe","listener","delete","visible","#changed","actionOf","closeOf","flagOf","set","value","measureInto","event","nativeEvent","layout","Snackbar","t0","$","_c","props","t1","theme","insets","t2","standing","t3","paddingBottom","paddingLeft","paddingRight","t4","t5","OS","SnackbarButton","ariaLabel","children","onFocusChange","ring","corners","feedback","onBlur","onFocus","T0","handlers","t6","t7","layer","SnackbarStrip","arrives","themed","body","reduceMotion","focused","setFocused","hovered","setHovered","motion","rises","arrived","rise","progress","get","opacity","transform","translateY","duration","durationMedium1","easing","bezier","easingEmphasizedDecelerate","announceForAccessibilityWithOptions","useExpiry","useShownFor","t8","Symbol","for","paused","expire","remaining","current","started","Date","now","timer","setTimeout","clearTimeout","recommended","setRecommended","asks","ask","milliseconds","getRecommendedTimeoutMillis","Queue","_c","NativeText"],"sources":["../../../src/components/snackbar/index.tsx"],"sourcesContent":["import type { ComponentRef, ReactNode, Ref } from 'react'\nimport type {\n LayoutChangeEvent,\n StyleProp,\n TextStyle,\n ViewProps,\n ViewStyle,\n} from 'react-native'\nimport type { AnimatedStyle, SharedValue } from 'react-native-reanimated'\n\nimport { use, useEffect, useRef, useState, useSyncExternalStore } from 'react'\nimport {\n AccessibilityInfo,\n Text as NativeText,\n Platform,\n Pressable,\n StyleSheet,\n View,\n} from 'react-native'\nimport Animated, {\n Easing,\n useAnimatedStyle,\n useReducedMotion,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated'\nimport { SafeAreaInsetsContext } from 'react-native-safe-area-context'\n\nimport { CloseGlyph } from '../../glyphs'\nimport { useWindowSizeClass } from '../../hooks/useWindowSizeClass'\nimport { Overlay } from '../../overlay'\nimport { hitSlop, usePressFeedback } from '../../press'\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles, themedStyles } from '../../theme/styles'\nimport { useTypeRole } from '../../typography/roles'\n\n// The snackbar page's brief message at the bottom of the screen, with an\n// optional action beside it and an optional close button after that, as\n// kanso-ui's Snackbar draws it. The page's container is the inverse surface\n// at a 4dp corner and elevation 3, its supporting text is body-medium in\n// inverse on surface, its action label is inverse primary, and its close icon\n// takes the supporting text's colour. The measurements are the page's too: 8dp\n// of margin from the edges of the screen, 8dp of padding inside the container\n// with another 8dp either side of the message, 14dp above and below on a\n// single line, and between 320 and 576dp wide from the 600dp breakpoint up,\n// the width of the window less its margins below it. The margin is counted\n// from the safe area, so a message clears the home indicator and the gesture\n// bar.\n//\n// One at a time, as on web. The page shows a single snackbar and replaces it\n// rather than stacking, so a message added while another is up closes that\n// one, whose `onClose` runs, and takes its place. Nothing waits behind it, so\n// an Undo never comes back long after the thing it undid.\n//\n// The queue is web's API: `add` a message with its options from anywhere, and\n// mount one `Snackbar` with the queue near the root. It draws in the overlay\n// host of the outermost `ThemeScope`, so it floats above every screen in the\n// theme around it.\n//\n// **A message is read out as it arrives.** On iOS and Android it is\n// announced through `AccessibilityInfo`, after whatever VoiceOver is already\n// saying, which is how CopyField says its confirmation too. Under React Native\n// Web the region it appears in is a polite live region instead, as web's is,\n// and the browser's screen reader reads it as it changes. Android is not given\n// a live region as well, since TalkBack would then read each message twice.\n//\n// **A message is a string, where web takes a node.** The announcement is the\n// message's words, and a node has none to hand VoiceOver.\n//\n// **The action and the close button are drawn here rather than through\n// Button and IconButton**, as on web: the page colours them inverse primary\n// and inverse on surface, which no variant of either carries. They take the\n// state layer, the ripple and the focus ring from src/press, with the ring\n// drawn 2dp inside the control rather than outside it: the close button is\n// 48dp in a strip 48dp tall, so a ring outside it crossed the strip's edges\n// onto the screen, in a colour chosen to read on the strip rather than on\n// the screen around it.\n\n// How long a message is shown when the call site names no `timeout`, web's\n// durations from the snackbar's guidelines and accessibility pages. A message\n// alone leaves after five seconds, which Android lengthens from the reader's\n// own accessibility setting, as its own snackbar does. A message with an\n// action stays until the action is taken or something closes it, since no\n// timer knows how long a reader needs to reach it.\nconst MESSAGE_MS = 5000\nconst UNTIL_CLOSED = 0\n\n// The width from the 600dp breakpoint up, the page's. Literals, as on web:\n// they bound the strip rather than measure anything a theme would resize.\nconst MIN_WIDE = 320\nconst MAX_WIDE = 576\n\n// The page's 14dp above and below the message, which with its 20dp line makes\n// a single-line strip 48dp tall. A literal, as on web, since no spacing step\n// is 14.\nconst MESSAGE_BLOCK_PADDING = 14\n\n// The ring's 2dp, drawn 4dp in from the control's edge so all of it lies\n// inside.\nconst RING_WIDTH = 2\nconst RING_OFFSET = -4\n\n// Outside a SafeAreaProvider the insets are unknown, and the window's own edge\n// is the best bound there is.\nconst NO_INSETS = { bottom: 0, left: 0, right: 0, top: 0 }\n\nconst stylesOf = themedStyles(({ colors, radii, shadows, sizing, spacing }) =>\n StyleSheet.create({\n // Material Design's text button in the page's inverse primary, at the\n // label large the page gives it: 40dp tall, as Button's medium size is,\n // over a 48dp target, which is the strip's own height. A least height\n // rather than a height, so a type scale with a taller line grows the\n // button instead of clipping its label.\n action: {\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: sizing.controlSm,\n paddingHorizontal: spacing.md,\n paddingVertical: spacing.sm,\n },\n actionLabel: {\n color: colors.inversePrimary,\n },\n actionRing: {\n outlineColor: colors.inversePrimary,\n outlineOffset: RING_OFFSET,\n outlineStyle: 'solid',\n outlineWidth: RING_WIDTH,\n },\n // The page's 24dp icon in the supporting text's colour, in a 48dp box,\n // the least press area the icon buttons page allows.\n close: {\n alignItems: 'center',\n height: sizing.controlMd,\n justifyContent: 'center',\n width: sizing.controlMd,\n },\n closeRing: {\n outlineColor: colors.inverseOnSurface,\n outlineOffset: RING_OFFSET,\n outlineStyle: 'solid',\n outlineWidth: RING_WIDTH,\n },\n // Both controls are pills, which the state layer and the ripple clip to.\n control: {\n borderRadius: radii.pill,\n },\n // The message: its 8dp either side inside the strip's own 8dp, and the\n // 14dp above and below. The height is the message's rather than the\n // strip's, which is what lets a 48dp close button sit beside it without\n // making the strip taller than the page draws it.\n //\n // Its basis is half the strip, which is what decides when the controls\n // drop beneath it. A word longer than the line holds breaks inside\n // itself rather than running under the controls, which the least width\n // of 0 allows on the web, where a flex item otherwise keeps the width of\n // its longest word.\n message: {\n flexBasis: '50%',\n flexGrow: 1,\n marginHorizontal: spacing.sm,\n minWidth: 0,\n paddingVertical: MESSAGE_BLOCK_PADDING,\n },\n messageText: {\n color: colors.inverseOnSurface,\n },\n // A strip along the bottom of the overlay layer, with the page's 8dp\n // above it. It passes a touch through wherever no strip is drawn, so\n // the screen under it stays usable.\n region: {\n alignItems: 'center',\n bottom: 0,\n left: 0,\n paddingTop: spacing.sm,\n pointerEvents: 'box-none',\n position: 'absolute',\n right: 0,\n },\n // The container: the page's 8dp either side, and nothing above or\n // below, since what sets its height is the message and the close\n // button. It wraps, so controls too long to leave the message half the\n // strip drop onto a line of their own beneath it, Material Design's\n // two-line snackbar with a longer action.\n strip: {\n alignItems: 'center',\n backgroundColor: colors.inverseSurface,\n borderRadius: radii.xs,\n boxShadow: shadows.elevation3,\n flexDirection: 'row',\n flexWrap: 'wrap',\n minHeight: sizing.controlMd,\n paddingHorizontal: spacing.sm,\n width: '100%',\n },\n }),\n)\n\nconst styles = StyleSheet.create({\n // The action, and the close button after it, kept together after the\n // message so they move beneath it together. The auto margin puts them at\n // the trailing edge: on the message's row the message takes all the room\n // first, and on a row of their own it is all the room there is.\n controls: {\n alignItems: 'center',\n flexDirection: 'row',\n flexShrink: 0,\n marginStart: 'auto',\n },\n wide: {\n maxWidth: MAX_WIDE,\n minWidth: MIN_WIDE,\n },\n})\n\n// A message on screen, with what it was added with.\ntype ShownMessage = {\n readonly action: SnackbarAction | undefined\n readonly key: string\n readonly message: string\n readonly onClose: (() => void) | undefined\n readonly showCloseButton: boolean\n readonly timeout: number\n}\n\ntype SnackbarAction = {\n /** What the action says. The page gives it a single word where it can. */\n readonly label: string\n /** Run when the action is pressed, just before the snackbar closes. */\n readonly onPress: () => void\n}\n\ntype SnackbarOptions = {\n /**\n * A single action shown after the message. Pressing it runs `onPress` and\n * closes the snackbar, which is what the page draws.\n */\n readonly action?: SnackbarAction\n /**\n * Run when the snackbar closes, however it was closed: by its timer, its\n * action or close button, `close`, `clear`, or a newer message added in its\n * place.\n */\n readonly onClose?: () => void\n /**\n * Whether a close button is shown at the end. The page draws one for a\n * message a reader may want out of the way before it expires.\n * @default false\n */\n readonly showCloseButton?: boolean\n /**\n * How long the snackbar is shown, in milliseconds. Defaults to five seconds\n * for a message alone, which Android lengthens from the reader's own\n * accessibility setting. A message with an action defaults to `0` and stays\n * until the action is taken or something closes it, as Material Design asks\n * of an actionable snackbar. The timer is paused while a pointer is over the\n * snackbar or one of its controls has focus, so a message never expires\n * while it is being read.\n *\n * `0` is the page's indefinite length: the snackbar stays until something\n * closes it. Give one of those an action or `showCloseButton`, or there is\n * no way to be rid of it.\n */\n readonly timeout?: number\n}\n\ntype SnackbarProps = Omit<ViewProps, 'children' | 'style'> & {\n /**\n * What a screen reader calls the button that dismisses a snackbar. It sits\n * here rather than on a message's own options because it does not vary by\n * message.\n * @default 'Close'\n */\n readonly closeLabel?: string\n /** The queue the snackbar shows messages from. */\n readonly queue: SnackbarQueue\n readonly ref?: Ref<ComponentRef<typeof View>>\n readonly style?: StyleProp<ViewStyle>\n}\n\n/**\n * The queue a snackbar is shown from. Make one where the app can reach it, a\n * module of its own being the usual place, mount `Snackbar` once with it, and\n * call `add` from anywhere.\n *\n * ```ts\n * const messages = new Snackbar.Queue()\n * messages.add('Label', { action: { label: 'Undo', onPress: undo } })\n * ```\n */\nclass SnackbarQueue {\n #added = 0\n readonly #listeners = new Set<() => void>()\n #shown: null | ShownMessage = null\n\n /**\n * Shows a message in place of the one on screen, and returns the key that\n * closes it. The message it replaces is closed, so its `onClose` runs, and\n * it does not come back.\n */\n add(message: string, options: SnackbarOptions = {}): string {\n const { action, onClose, showCloseButton = false, timeout } = options\n\n this.clear()\n this.#added += 1\n\n const key = `snackbar-${String(this.#added)}`\n\n this.#shown = {\n action,\n key,\n message,\n onClose,\n showCloseButton,\n timeout: timeout ?? (action === undefined ? MESSAGE_MS : UNTIL_CLOSED),\n }\n this.#changed()\n\n return key\n }\n\n /** Closes the snackbar on screen, running its `onClose`. */\n clear() {\n if (this.#shown !== null) {\n this.close(this.#shown.key)\n }\n }\n\n /** Closes one snackbar, by the key `add` returned. */\n close(key: string) {\n const shown = this.#shown\n\n if (shown?.key !== key) {\n return\n }\n\n // Off the screen before `onClose` runs, so one that adds the next message\n // adds it to an empty queue.\n this.#shown = null\n this.#changed()\n shown.onClose?.()\n }\n\n /**\n * Calls `listener` whenever the message on screen changes, and returns what\n * stops it. `Snackbar` reads the queue through this and `visible`, and\n * neither is meant for a call site.\n */\n readonly subscribe = (listener: () => void) => {\n this.#listeners.add(listener)\n\n return () => {\n this.#listeners.delete(listener)\n }\n }\n\n /** The message on screen, or `null`. */\n readonly visible = () => this.#shown\n\n #changed() {\n for (const listener of this.#listeners) {\n listener()\n }\n }\n}\n\n// The handlers the strip hands its views, each built by a call rather than\n// declared in the component, which is what react-perf's\n// jsx-no-new-function-as-prop is after; the React Compiler memoises the result\n// on its inputs.\nfunction actionOf(action: SnackbarAction, close: () => void) {\n return () => {\n action.onPress()\n close()\n }\n}\n\nfunction closeOf(queue: SnackbarQueue, key: string) {\n return () => {\n queue.close(key)\n }\n}\n\nfunction flagOf(set: (value: boolean) => void, value: boolean) {\n return () => {\n set(value)\n }\n}\n\nfunction measureInto(height: SharedValue<number>) {\n return (event: LayoutChangeEvent) => {\n height.set(event.nativeEvent.layout.height)\n }\n}\n\n/**\n * A brief message at the bottom of the screen, with an optional action, with\n * web's props and values. Mount one of these with a `Snackbar.Queue`, and\n * call the queue's `add` to show a message from anywhere.\n *\n * ```tsx\n * const messages = new Snackbar.Queue()\n *\n * <Snackbar queue={messages} />\n * ```\n *\n * It draws in the overlay host of the app's outermost `ThemeScope`, above the\n * screen, and needs one around it. It is one region rather than one per\n * message, so mount it once, near the root, inside the `SafeAreaProvider`\n * whose insets it keeps clear of.\n *\n * `style`, `ref` and `testID` land on that region, a view along the bottom of\n * the screen that holds the message.\n */\nfunction Snackbar({\n closeLabel = 'Close',\n queue,\n style,\n ...props\n}: SnackbarProps) {\n const theme = useTheme()\n const insets = use(SafeAreaInsetsContext) ?? NO_INSETS\n const wide = useWindowSizeClass() !== 'compact'\n const shown = useSyncExternalStore(queue.subscribe, queue.visible)\n // The message up when the snackbar mounted, which was on screen before it\n // rather than arriving, so it is put in place rather than risen to it: on\n // a screen that remounts the snackbar, and on a story seeded with one.\n const [standing] = useState(() => queue.visible()?.key)\n const { spacing } = theme\n\n return (\n <Overlay>\n <View\n aria-live={Platform.OS === 'web' ? 'polite' : undefined}\n {...props}\n style={composeStyles<ViewStyle>(\n stylesOf(theme).region,\n {\n paddingBottom: spacing.sm + insets.bottom,\n paddingLeft: spacing.sm + insets.left,\n paddingRight: spacing.sm + insets.right,\n },\n style,\n )}\n >\n {shown === null ? null : (\n <SnackbarStrip\n arrives={shown.key !== standing}\n closeLabel={closeLabel}\n key={shown.key}\n queue={queue}\n shown={shown}\n wide={wide}\n />\n )}\n </View>\n </Overlay>\n )\n}\n\n/**\n * One of the snackbar's two controls, a pill drawing the state layer, the\n * ripple and the ring in its own colour, over a target brought up to 48dp\n * from the `height` it is drawn at. It reports when it takes and loses focus,\n * which pauses the message's timer.\n */\nfunction SnackbarButton({\n 'aria-label': ariaLabel,\n children,\n color,\n height,\n onFocusChange,\n onPress,\n ring,\n style,\n}: {\n readonly 'aria-label'?: string\n readonly children: ReactNode\n readonly color: string\n readonly height: number\n readonly onFocusChange: (focused: boolean) => void\n readonly onPress: () => void\n readonly ring: ViewStyle\n readonly style: ViewStyle\n}) {\n const theme = useTheme()\n const corners = stylesOf(theme).control\n const feedback = usePressFeedback({\n color,\n corners,\n onBlur: () => {\n onFocusChange(false)\n },\n onFocus: () => {\n onFocusChange(true)\n },\n })\n\n return (\n <Pressable\n {...feedback.handlers}\n aria-label={ariaLabel}\n hitSlop={hitSlop(height)}\n onPress={onPress}\n role=\"button\"\n style={composeStyles<ViewStyle>(\n corners,\n style,\n feedback.ring === undefined ? undefined : ring,\n )}\n >\n {feedback.layer}\n {children}\n </Pressable>\n )\n}\n\n/** One message: the words, then whatever sits after them. */\nfunction SnackbarStrip({\n arrives,\n closeLabel,\n queue,\n shown,\n wide,\n}: {\n /** Whether the message rises into place, or is drawn there at once. */\n readonly arrives: boolean\n readonly closeLabel: string\n readonly queue: SnackbarQueue\n readonly shown: ShownMessage\n readonly wide: boolean\n}) {\n const theme = useTheme()\n const themed = stylesOf(theme)\n const body = useTypeRole('bodyMedium')\n const label = useTypeRole('labelLarge')\n const reduceMotion = useReducedMotion()\n const [focused, setFocused] = useState(false)\n const [hovered, setHovered] = useState(false)\n const { action, key, message, showCloseButton } = shown\n const { colors, motion, sizing } = theme\n\n // It rises its own height from the bottom edge as it fades in, which is\n // what the page draws and what says the message came from the edge of the\n // screen rather than appearing over it. Reduced motion puts it in its\n // settled place at once, as web's zeroed duration does.\n const rises = arrives && !reduceMotion\n const arrived = useSharedValue(rises ? 0 : 1)\n const height = useSharedValue(0)\n const rise = useAnimatedStyle(() => {\n 'worklet'\n const progress = arrived.get()\n\n return {\n opacity: progress,\n transform: [{ translateY: (1 - progress) * height.get() }],\n }\n })\n\n useEffect(() => {\n if (rises) {\n arrived.set(\n withTiming(1, {\n duration: motion.durationMedium1,\n easing: Easing.bezier(...motion.easingEmphasizedDecelerate),\n }),\n )\n }\n }, [arrived, motion, rises])\n\n useEffect(() => {\n if (Platform.OS === 'ios' || Platform.OS === 'android') {\n AccessibilityInfo.announceForAccessibilityWithOptions(message, {\n queue: true,\n })\n }\n }, [message])\n\n const close = closeOf(queue, key)\n\n useExpiry(useShownFor(shown.timeout), focused || hovered, close)\n\n return (\n <Animated.View\n onLayout={measureInto(height)}\n onPointerEnter={flagOf(setHovered, true)}\n onPointerLeave={flagOf(setHovered, false)}\n style={composeStyles<AnimatedStyle<ViewStyle>>(\n themed.strip,\n wide ? styles.wide : undefined,\n rise,\n )}\n >\n <View style={themed.message}>\n <NativeText style={composeStyles<TextStyle>(body, themed.messageText)}>\n {message}\n </NativeText>\n </View>\n {action === undefined && !showCloseButton ? null : (\n <View style={styles.controls}>\n {action === undefined ? null : (\n <SnackbarButton\n color={colors.inversePrimary}\n height={sizing.controlSm}\n onFocusChange={setFocused}\n onPress={actionOf(action, close)}\n ring={themed.actionRing}\n style={themed.action}\n >\n <NativeText\n style={composeStyles<TextStyle>(label, themed.actionLabel)}\n >\n {action.label}\n </NativeText>\n </SnackbarButton>\n )}\n {showCloseButton ? (\n <SnackbarButton\n aria-label={closeLabel}\n color={colors.inverseOnSurface}\n height={sizing.controlMd}\n onFocusChange={setFocused}\n onPress={close}\n ring={themed.closeRing}\n style={themed.close}\n >\n <CloseGlyph color={colors.inverseOnSurface} size={24} />\n </SnackbarButton>\n ) : null}\n </View>\n )}\n </Animated.View>\n )\n}\n\n// Closes a message once it has been shown for `duration` milliseconds,\n// counting only the time it was not paused. Nothing for a `duration` of 0,\n// which is until closed, or of `null`, which is not yet known.\nfunction useExpiry(\n duration: null | number,\n paused: boolean,\n expire: () => void,\n) {\n const left = useRef<null | number>(null)\n\n useEffect(() => {\n if (duration === null || duration === 0 || paused) {\n return undefined\n }\n\n const remaining = left.current ?? duration\n const started = Date.now()\n const timer = setTimeout(expire, remaining)\n\n return () => {\n clearTimeout(timer)\n left.current = remaining - (Date.now() - started)\n }\n }, [duration, expire, paused])\n}\n\n// How long a message is shown: its `timeout`, which Android lengthens from\n// the reader's \"Time to take action\" setting, as its own snackbar does, and\n// is `null` until Android has answered. Nothing is asked for a message shown\n// until closed.\nfunction useShownFor(timeout: number): null | number {\n const [recommended, setRecommended] = useState<null | number>(null)\n const asks = Platform.OS === 'android' && timeout > 0\n\n useEffect(() => {\n if (!asks) {\n return undefined\n }\n\n let current = true\n\n async function ask() {\n const milliseconds =\n await AccessibilityInfo.getRecommendedTimeoutMillis(timeout)\n\n if (current) {\n setRecommended(milliseconds)\n }\n }\n\n void ask()\n\n return () => {\n current = false\n }\n }, [asks, timeout])\n\n return asks ? recommended : timeout\n}\n\nSnackbar.Queue = SnackbarQueue\n\n// The queue is reached as `Snackbar.Queue` rather than exported beside the\n// component, as on web: a module exporting something that is not a component\n// is one fast refresh reloads whole.\nexport { Snackbar }\nexport type { SnackbarAction, SnackbarOptions, SnackbarProps, SnackbarQueue }\n"],"mappings":";;;;;;;;;;;;;;AAoFA,MAAMsC,aAAa;AACnB,MAAMC,eAAe;AAIrB,MAAMC,WAAW;AACjB,MAAMC,WAAW;AAKjB,MAAMC,wBAAwB;AAI9B,MAAMC,aAA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GAAH;EACR;EACA1D,KAAA,CAACmE,MAAM3G,OAAO;EAACqC,EAAA,KAAAsE;EAAAtE,EAAA,KAAArC;EAAAqC,EAAA,KAAAD;EAAAC,EAAA,KAAAG;CAAA,OAAA;EAAAJ,KAAAC,EAAA;EAAAG,KAAAH,EAAA;CAAA;CArBlB1I,UAAUyI,IAqBPI,EAAe;CAAC,OAEZmE,OAAAF,cAAAzG;AAA4B;AAGrCmC,SAAS4E,QAAQvG"}
1
+ {"version":3,"file":"index.js","names":["ComponentRef","ReactNode","Ref","LayoutChangeEvent","StyleProp","TextStyle","ViewProps","ViewStyle","AnimatedStyle","SharedValue","use","useEffect","useRef","useState","useSyncExternalStore","AccessibilityInfo","Text","NativeText","Platform","Pressable","StyleSheet","View","Animated","Easing","useAnimatedStyle","useReducedMotion","useSharedValue","withTiming","SafeAreaInsetsContext","CloseGlyph","useWindowSizeClass","useMessages","Overlay","hitSlop","usePressFeedback","useTheme","composeStyles","themedStyles","useTypeRole","MESSAGE_MS","UNTIL_CLOSED","MIN_WIDE","MAX_WIDE","MESSAGE_BLOCK_PADDING","RING_WIDTH","RING_OFFSET","NO_INSETS","bottom","left","right","top","stylesOf","colors","radii","shadows","sizing","spacing","create","action","alignItems","justifyContent","minHeight","controlSm","paddingHorizontal","md","paddingVertical","sm","actionLabel","color","inversePrimary","actionRing","outlineColor","outlineOffset","outlineStyle","outlineWidth","close","height","controlMd","width","closeRing","inverseOnSurface","control","borderRadius","pill","message","flexBasis","flexGrow","marginHorizontal","minWidth","messageText","region","paddingTop","pointerEvents","position","strip","backgroundColor","inverseSurface","xs","boxShadow","elevation3","flexDirection","flexWrap","styles","controls","flexShrink","marginStart","wide","maxWidth","ShownMessage","SnackbarAction","key","onClose","showCloseButton","timeout","label","onPress","SnackbarOptions","SnackbarProps","Omit","closeLabel","queue","SnackbarQueue","ref","style","added","listeners","Set","shown","add","options","clear","String","undefined","changed","subscribe","listener","delete","visible","#changed","actionOf","closeOf","flagOf","set","value","measureInto","event","nativeEvent","layout","Snackbar","t0","$","_c","ownCloseLabel","props","messages","theme","insets","t1","standing","t2","paddingBottom","paddingLeft","paddingRight","t3","t4","OS","SnackbarButton","ariaLabel","children","onFocusChange","ring","corners","feedback","onBlur","onFocus","T0","handlers","t5","t6","t7","layer","SnackbarStrip","arrives","themed","body","reduceMotion","focused","setFocused","hovered","setHovered","motion","rises","arrived","rise","progress","get","opacity","transform","translateY","duration","durationMedium1","easing","bezier","easingEmphasizedDecelerate","announceForAccessibilityWithOptions","useExpiry","useShownFor","t8","Symbol","for","paused","expire","remaining","current","started","Date","now","timer","setTimeout","clearTimeout","recommended","setRecommended","asks","ask","milliseconds","getRecommendedTimeoutMillis","Queue","_c","NativeText"],"sources":["../../../src/components/snackbar/index.tsx"],"sourcesContent":["import type { ComponentRef, ReactNode, Ref } from 'react'\nimport type {\n LayoutChangeEvent,\n StyleProp,\n TextStyle,\n ViewProps,\n ViewStyle,\n} from 'react-native'\nimport type { AnimatedStyle, SharedValue } from 'react-native-reanimated'\n\nimport { use, useEffect, useRef, useState, useSyncExternalStore } from 'react'\nimport {\n AccessibilityInfo,\n Text as NativeText,\n Platform,\n Pressable,\n StyleSheet,\n View,\n} from 'react-native'\nimport Animated, {\n Easing,\n useAnimatedStyle,\n useReducedMotion,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated'\nimport { SafeAreaInsetsContext } from 'react-native-safe-area-context'\n\nimport { CloseGlyph } from '../../glyphs'\nimport { useWindowSizeClass } from '../../hooks/useWindowSizeClass'\nimport { useMessages } from '../../i18n/provider'\nimport { Overlay } from '../../overlay'\nimport { hitSlop, usePressFeedback } from '../../press'\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles, themedStyles } from '../../theme/styles'\nimport { useTypeRole } from '../../typography/roles'\n\n// The snackbar page's brief message at the bottom of the screen, with an\n// optional action beside it and an optional close button after that, as\n// kanso-ui's Snackbar draws it. The page's container is the inverse surface\n// at a 4dp corner and elevation 3, its supporting text is body-medium in\n// inverse on surface, its action label is inverse primary, and its close icon\n// takes the supporting text's colour. The measurements are the page's too: 8dp\n// of margin from the edges of the screen, 8dp of padding inside the container\n// with another 8dp either side of the message, 14dp above and below on a\n// single line, and between 320 and 576dp wide from the 600dp breakpoint up,\n// the width of the window less its margins below it. The margin is counted\n// from the safe area, so a message clears the home indicator and the gesture\n// bar.\n//\n// One at a time, as on web. The page shows a single snackbar and replaces it\n// rather than stacking, so a message added while another is up closes that\n// one, whose `onClose` runs, and takes its place. Nothing waits behind it, so\n// an Undo never comes back long after the thing it undid.\n//\n// The queue is web's API: `add` a message with its options from anywhere, and\n// mount one `Snackbar` with the queue near the root. It draws in the overlay\n// host of the outermost `ThemeScope`, so it floats above every screen in the\n// theme around it.\n//\n// **A message is read out as it arrives.** On iOS and Android it is\n// announced through `AccessibilityInfo`, after whatever VoiceOver is already\n// saying, which is how CopyField says its confirmation too. Under React Native\n// Web the region it appears in is a polite live region instead, as web's is,\n// and the browser's screen reader reads it as it changes. Android is not given\n// a live region as well, since TalkBack would then read each message twice.\n//\n// **A message is a string, where web takes a node.** The announcement is the\n// message's words, and a node has none to hand VoiceOver.\n//\n// **The action and the close button are drawn here rather than through\n// Button and IconButton**, as on web: the page colours them inverse primary\n// and inverse on surface, which no variant of either carries. They take the\n// state layer, the ripple and the focus ring from src/press, with the ring\n// drawn 2dp inside the control rather than outside it: the close button is\n// 48dp in a strip 48dp tall, so a ring outside it crossed the strip's edges\n// onto the screen, in a colour chosen to read on the strip rather than on\n// the screen around it.\n\n// How long a message is shown when the call site names no `timeout`, web's\n// durations from the snackbar's guidelines and accessibility pages. A message\n// alone leaves after five seconds, which Android lengthens from the reader's\n// own accessibility setting, as its own snackbar does. A message with an\n// action stays until the action is taken or something closes it, since no\n// timer knows how long a reader needs to reach it.\nconst MESSAGE_MS = 5000\nconst UNTIL_CLOSED = 0\n\n// The width from the 600dp breakpoint up, the page's. Literals, as on web:\n// they bound the strip rather than measure anything a theme would resize.\nconst MIN_WIDE = 320\nconst MAX_WIDE = 576\n\n// The page's 14dp above and below the message, which with its 20dp line makes\n// a single-line strip 48dp tall. A literal, as on web, since no spacing step\n// is 14.\nconst MESSAGE_BLOCK_PADDING = 14\n\n// The ring's 2dp, drawn 4dp in from the control's edge so all of it lies\n// inside.\nconst RING_WIDTH = 2\nconst RING_OFFSET = -4\n\n// Outside a SafeAreaProvider the insets are unknown, and the window's own edge\n// is the best bound there is.\nconst NO_INSETS = { bottom: 0, left: 0, right: 0, top: 0 }\n\nconst stylesOf = themedStyles(({ colors, radii, shadows, sizing, spacing }) =>\n StyleSheet.create({\n // Material Design's text button in the page's inverse primary, at the\n // label large the page gives it: 40dp tall, as Button's medium size is,\n // over a 48dp target, which is the strip's own height. A least height\n // rather than a height, so a type scale with a taller line grows the\n // button instead of clipping its label.\n action: {\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: sizing.controlSm,\n paddingHorizontal: spacing.md,\n paddingVertical: spacing.sm,\n },\n actionLabel: {\n color: colors.inversePrimary,\n },\n actionRing: {\n outlineColor: colors.inversePrimary,\n outlineOffset: RING_OFFSET,\n outlineStyle: 'solid',\n outlineWidth: RING_WIDTH,\n },\n // The page's 24dp icon in the supporting text's colour, in a 48dp box,\n // the least press area the icon buttons page allows.\n close: {\n alignItems: 'center',\n height: sizing.controlMd,\n justifyContent: 'center',\n width: sizing.controlMd,\n },\n closeRing: {\n outlineColor: colors.inverseOnSurface,\n outlineOffset: RING_OFFSET,\n outlineStyle: 'solid',\n outlineWidth: RING_WIDTH,\n },\n // Both controls are pills, which the state layer and the ripple clip to.\n control: {\n borderRadius: radii.pill,\n },\n // The message: its 8dp either side inside the strip's own 8dp, and the\n // 14dp above and below. The height is the message's rather than the\n // strip's, which is what lets a 48dp close button sit beside it without\n // making the strip taller than the page draws it.\n //\n // Its basis is half the strip, which is what decides when the controls\n // drop beneath it. A word longer than the line holds breaks inside\n // itself rather than running under the controls, which the least width\n // of 0 allows on the web, where a flex item otherwise keeps the width of\n // its longest word.\n message: {\n flexBasis: '50%',\n flexGrow: 1,\n marginHorizontal: spacing.sm,\n minWidth: 0,\n paddingVertical: MESSAGE_BLOCK_PADDING,\n },\n messageText: {\n color: colors.inverseOnSurface,\n },\n // A strip along the bottom of the overlay layer, with the page's 8dp\n // above it. It passes a touch through wherever no strip is drawn, so\n // the screen under it stays usable.\n region: {\n alignItems: 'center',\n bottom: 0,\n left: 0,\n paddingTop: spacing.sm,\n pointerEvents: 'box-none',\n position: 'absolute',\n right: 0,\n },\n // The container: the page's 8dp either side, and nothing above or\n // below, since what sets its height is the message and the close\n // button. It wraps, so controls too long to leave the message half the\n // strip drop onto a line of their own beneath it, Material Design's\n // two-line snackbar with a longer action.\n strip: {\n alignItems: 'center',\n backgroundColor: colors.inverseSurface,\n borderRadius: radii.xs,\n boxShadow: shadows.elevation3,\n flexDirection: 'row',\n flexWrap: 'wrap',\n minHeight: sizing.controlMd,\n paddingHorizontal: spacing.sm,\n width: '100%',\n },\n }),\n)\n\nconst styles = StyleSheet.create({\n // The action, and the close button after it, kept together after the\n // message so they move beneath it together. The auto margin puts them at\n // the trailing edge: on the message's row the message takes all the room\n // first, and on a row of their own it is all the room there is.\n controls: {\n alignItems: 'center',\n flexDirection: 'row',\n flexShrink: 0,\n marginStart: 'auto',\n },\n wide: {\n maxWidth: MAX_WIDE,\n minWidth: MIN_WIDE,\n },\n})\n\n// A message on screen, with what it was added with.\ntype ShownMessage = {\n readonly action: SnackbarAction | undefined\n readonly key: string\n readonly message: string\n readonly onClose: (() => void) | undefined\n readonly showCloseButton: boolean\n readonly timeout: number\n}\n\ntype SnackbarAction = {\n /** What the action says. The page gives it a single word where it can. */\n readonly label: string\n /** Run when the action is pressed, just before the snackbar closes. */\n readonly onPress: () => void\n}\n\ntype SnackbarOptions = {\n /**\n * A single action shown after the message. Pressing it runs `onPress` and\n * closes the snackbar, which is what the page draws.\n */\n readonly action?: SnackbarAction\n /**\n * Run when the snackbar closes, however it was closed: by its timer, its\n * action or close button, `close`, `clear`, or a newer message added in its\n * place.\n */\n readonly onClose?: () => void\n /**\n * Whether a close button is shown at the end. The page draws one for a\n * message a reader may want out of the way before it expires.\n * @default false\n */\n readonly showCloseButton?: boolean\n /**\n * How long the snackbar is shown, in milliseconds. Defaults to five seconds\n * for a message alone, which Android lengthens from the reader's own\n * accessibility setting. A message with an action defaults to `0` and stays\n * until the action is taken or something closes it, as Material Design asks\n * of an actionable snackbar. The timer is paused while a pointer is over the\n * snackbar or one of its controls has focus, so a message never expires\n * while it is being read.\n *\n * `0` is the page's indefinite length: the snackbar stays until something\n * closes it. Give one of those an action or `showCloseButton`, or there is\n * no way to be rid of it.\n */\n readonly timeout?: number\n}\n\ntype SnackbarProps = Omit<ViewProps, 'children' | 'style'> & {\n /**\n * What a screen reader calls the button that dismisses a snackbar. It sits\n * here rather than on a message's own options because it does not vary by\n * message. Left out, it is the word React Aria gives web's in the\n * `I18nProvider`'s locale, or the device's outside one, \"Close\" in English.\n */\n readonly closeLabel?: string\n /** The queue the snackbar shows messages from. */\n readonly queue: SnackbarQueue\n readonly ref?: Ref<ComponentRef<typeof View>>\n readonly style?: StyleProp<ViewStyle>\n}\n\n/**\n * The queue a snackbar is shown from. Make one where the app can reach it, a\n * module of its own being the usual place, mount `Snackbar` once with it, and\n * call `add` from anywhere.\n *\n * ```ts\n * const messages = new Snackbar.Queue()\n * messages.add('Label', { action: { label: 'Undo', onPress: undo } })\n * ```\n */\nclass SnackbarQueue {\n #added = 0\n readonly #listeners = new Set<() => void>()\n #shown: null | ShownMessage = null\n\n /**\n * Shows a message in place of the one on screen, and returns the key that\n * closes it. The message it replaces is closed, so its `onClose` runs, and\n * it does not come back.\n */\n add(message: string, options: SnackbarOptions = {}): string {\n const { action, onClose, showCloseButton = false, timeout } = options\n\n this.clear()\n this.#added += 1\n\n const key = `snackbar-${String(this.#added)}`\n\n this.#shown = {\n action,\n key,\n message,\n onClose,\n showCloseButton,\n timeout: timeout ?? (action === undefined ? MESSAGE_MS : UNTIL_CLOSED),\n }\n this.#changed()\n\n return key\n }\n\n /** Closes the snackbar on screen, running its `onClose`. */\n clear() {\n if (this.#shown !== null) {\n this.close(this.#shown.key)\n }\n }\n\n /** Closes one snackbar, by the key `add` returned. */\n close(key: string) {\n const shown = this.#shown\n\n if (shown?.key !== key) {\n return\n }\n\n // Off the screen before `onClose` runs, so one that adds the next message\n // adds it to an empty queue.\n this.#shown = null\n this.#changed()\n shown.onClose?.()\n }\n\n /**\n * Calls `listener` whenever the message on screen changes, and returns what\n * stops it. `Snackbar` reads the queue through this and `visible`, and\n * neither is meant for a call site.\n */\n readonly subscribe = (listener: () => void) => {\n this.#listeners.add(listener)\n\n return () => {\n this.#listeners.delete(listener)\n }\n }\n\n /** The message on screen, or `null`. */\n readonly visible = () => this.#shown\n\n #changed() {\n for (const listener of this.#listeners) {\n listener()\n }\n }\n}\n\n// The handlers the strip hands its views, each built by a call rather than\n// declared in the component, which is what react-perf's\n// jsx-no-new-function-as-prop is after; the React Compiler memoises the result\n// on its inputs.\nfunction actionOf(action: SnackbarAction, close: () => void) {\n return () => {\n action.onPress()\n close()\n }\n}\n\nfunction closeOf(queue: SnackbarQueue, key: string) {\n return () => {\n queue.close(key)\n }\n}\n\nfunction flagOf(set: (value: boolean) => void, value: boolean) {\n return () => {\n set(value)\n }\n}\n\nfunction measureInto(height: SharedValue<number>) {\n return (event: LayoutChangeEvent) => {\n height.set(event.nativeEvent.layout.height)\n }\n}\n\n/**\n * A brief message at the bottom of the screen, with an optional action, with\n * web's props and values. Mount one of these with a `Snackbar.Queue`, and\n * call the queue's `add` to show a message from anywhere.\n *\n * ```tsx\n * const messages = new Snackbar.Queue()\n *\n * <Snackbar queue={messages} />\n * ```\n *\n * It draws in the overlay host of the app's outermost `ThemeScope`, above the\n * screen, and needs one around it. It is one region rather than one per\n * message, so mount it once, near the root, inside the `SafeAreaProvider`\n * whose insets it keeps clear of.\n *\n * `style`, `ref` and `testID` land on that region, a view along the bottom of\n * the screen that holds the message.\n */\nfunction Snackbar({\n closeLabel: ownCloseLabel,\n queue,\n style,\n ...props\n}: SnackbarProps) {\n const messages = useMessages()\n const closeLabel = ownCloseLabel ?? messages.close\n const theme = useTheme()\n const insets = use(SafeAreaInsetsContext) ?? NO_INSETS\n const wide = useWindowSizeClass() !== 'compact'\n const shown = useSyncExternalStore(queue.subscribe, queue.visible)\n // The message up when the snackbar mounted, which was on screen before it\n // rather than arriving, so it is put in place rather than risen to it: on\n // a screen that remounts the snackbar, and on a story seeded with one.\n const [standing] = useState(() => queue.visible()?.key)\n const { spacing } = theme\n\n return (\n <Overlay>\n <View\n aria-live={Platform.OS === 'web' ? 'polite' : undefined}\n {...props}\n style={composeStyles<ViewStyle>(\n stylesOf(theme).region,\n {\n paddingBottom: spacing.sm + insets.bottom,\n paddingLeft: spacing.sm + insets.left,\n paddingRight: spacing.sm + insets.right,\n },\n style,\n )}\n >\n {shown === null ? null : (\n <SnackbarStrip\n arrives={shown.key !== standing}\n closeLabel={closeLabel}\n key={shown.key}\n queue={queue}\n shown={shown}\n wide={wide}\n />\n )}\n </View>\n </Overlay>\n )\n}\n\n/**\n * One of the snackbar's two controls, a pill drawing the state layer, the\n * ripple and the ring in its own colour, over a target brought up to 48dp\n * from the `height` it is drawn at. It reports when it takes and loses focus,\n * which pauses the message's timer.\n */\nfunction SnackbarButton({\n 'aria-label': ariaLabel,\n children,\n color,\n height,\n onFocusChange,\n onPress,\n ring,\n style,\n}: {\n readonly 'aria-label'?: string\n readonly children: ReactNode\n readonly color: string\n readonly height: number\n readonly onFocusChange: (focused: boolean) => void\n readonly onPress: () => void\n readonly ring: ViewStyle\n readonly style: ViewStyle\n}) {\n const theme = useTheme()\n const corners = stylesOf(theme).control\n const feedback = usePressFeedback({\n color,\n corners,\n onBlur: () => {\n onFocusChange(false)\n },\n onFocus: () => {\n onFocusChange(true)\n },\n })\n\n return (\n <Pressable\n {...feedback.handlers}\n aria-label={ariaLabel}\n hitSlop={hitSlop(height)}\n onPress={onPress}\n role=\"button\"\n style={composeStyles<ViewStyle>(\n corners,\n style,\n feedback.ring === undefined ? undefined : ring,\n )}\n >\n {feedback.layer}\n {children}\n </Pressable>\n )\n}\n\n/** One message: the words, then whatever sits after them. */\nfunction SnackbarStrip({\n arrives,\n closeLabel,\n queue,\n shown,\n wide,\n}: {\n /** Whether the message rises into place, or is drawn there at once. */\n readonly arrives: boolean\n readonly closeLabel: string\n readonly queue: SnackbarQueue\n readonly shown: ShownMessage\n readonly wide: boolean\n}) {\n const theme = useTheme()\n const themed = stylesOf(theme)\n const body = useTypeRole('bodyMedium')\n const label = useTypeRole('labelLarge')\n const reduceMotion = useReducedMotion()\n const [focused, setFocused] = useState(false)\n const [hovered, setHovered] = useState(false)\n const { action, key, message, showCloseButton } = shown\n const { colors, motion, sizing } = theme\n\n // It rises its own height from the bottom edge as it fades in, which is\n // what the page draws and what says the message came from the edge of the\n // screen rather than appearing over it. Reduced motion puts it in its\n // settled place at once, as web's zeroed duration does.\n const rises = arrives && !reduceMotion\n const arrived = useSharedValue(rises ? 0 : 1)\n const height = useSharedValue(0)\n const rise = useAnimatedStyle(() => {\n 'worklet'\n const progress = arrived.get()\n\n return {\n opacity: progress,\n transform: [{ translateY: (1 - progress) * height.get() }],\n }\n })\n\n useEffect(() => {\n if (rises) {\n arrived.set(\n withTiming(1, {\n duration: motion.durationMedium1,\n easing: Easing.bezier(...motion.easingEmphasizedDecelerate),\n }),\n )\n }\n }, [arrived, motion, rises])\n\n useEffect(() => {\n if (Platform.OS === 'ios' || Platform.OS === 'android') {\n AccessibilityInfo.announceForAccessibilityWithOptions(message, {\n queue: true,\n })\n }\n }, [message])\n\n const close = closeOf(queue, key)\n\n useExpiry(useShownFor(shown.timeout), focused || hovered, close)\n\n return (\n <Animated.View\n onLayout={measureInto(height)}\n onPointerEnter={flagOf(setHovered, true)}\n onPointerLeave={flagOf(setHovered, false)}\n style={composeStyles<AnimatedStyle<ViewStyle>>(\n themed.strip,\n wide ? styles.wide : undefined,\n rise,\n )}\n >\n <View style={themed.message}>\n <NativeText style={composeStyles<TextStyle>(body, themed.messageText)}>\n {message}\n </NativeText>\n </View>\n {action === undefined && !showCloseButton ? null : (\n <View style={styles.controls}>\n {action === undefined ? null : (\n <SnackbarButton\n color={colors.inversePrimary}\n height={sizing.controlSm}\n onFocusChange={setFocused}\n onPress={actionOf(action, close)}\n ring={themed.actionRing}\n style={themed.action}\n >\n <NativeText\n style={composeStyles<TextStyle>(label, themed.actionLabel)}\n >\n {action.label}\n </NativeText>\n </SnackbarButton>\n )}\n {showCloseButton ? (\n <SnackbarButton\n aria-label={closeLabel}\n color={colors.inverseOnSurface}\n height={sizing.controlMd}\n onFocusChange={setFocused}\n onPress={close}\n ring={themed.closeRing}\n style={themed.close}\n >\n <CloseGlyph color={colors.inverseOnSurface} size={24} />\n </SnackbarButton>\n ) : null}\n </View>\n )}\n </Animated.View>\n )\n}\n\n// Closes a message once it has been shown for `duration` milliseconds,\n// counting only the time it was not paused. Nothing for a `duration` of 0,\n// which is until closed, or of `null`, which is not yet known.\nfunction useExpiry(\n duration: null | number,\n paused: boolean,\n expire: () => void,\n) {\n const left = useRef<null | number>(null)\n\n useEffect(() => {\n if (duration === null || duration === 0 || paused) {\n return undefined\n }\n\n const remaining = left.current ?? duration\n const started = Date.now()\n const timer = setTimeout(expire, remaining)\n\n return () => {\n clearTimeout(timer)\n left.current = remaining - (Date.now() - started)\n }\n }, [duration, expire, paused])\n}\n\n// How long a message is shown: its `timeout`, which Android lengthens from\n// the reader's \"Time to take action\" setting, as its own snackbar does, and\n// is `null` until Android has answered. Nothing is asked for a message shown\n// until closed.\nfunction useShownFor(timeout: number): null | number {\n const [recommended, setRecommended] = useState<null | number>(null)\n const asks = Platform.OS === 'android' && timeout > 0\n\n useEffect(() => {\n if (!asks) {\n return undefined\n }\n\n let current = true\n\n async function ask() {\n const milliseconds =\n await AccessibilityInfo.getRecommendedTimeoutMillis(timeout)\n\n if (current) {\n setRecommended(milliseconds)\n }\n }\n\n void ask()\n\n return () => {\n current = false\n }\n }, [asks, timeout])\n\n return asks ? recommended : timeout\n}\n\nSnackbar.Queue = SnackbarQueue\n\n// The queue is reached as `Snackbar.Queue` rather than exported beside the\n// component, as on web: a module exporting something that is not a component\n// is one fast refresh reloads whole.\nexport { Snackbar }\nexport type { SnackbarAction, SnackbarOptions, SnackbarProps, SnackbarQueue }\n"],"mappings":";;;;;;;;;;;;;;;AAqFA,MAAMuC,aAAa;AACnB,MAAMC,eAAe;AAIrB,MAAMC,WAAW;AACjB,MAAMC,WAAW;AAKjB,MAAMC,wBAAwB;AAI9B,MAAMC,aAAa;AACnB,MAAMC,cAAc;AAIpB,MAAMC,YAAY;CAAEC,QAAQ;CAAGC,MAAM;CAAGC,OAAO;CAAGC,KAAK;AAAE;AAEzD,MAAMC,WAAWd,cAAc,EAAEe,QAAQC,OAAOC,SAASC,QAAQC,cAC/DpC,WAAWqC,OAAO;CAMhBC,QAAQ;EACNC,YAAY;EACZC,gBAAgB;EAChBC,WAAWN,OAAOO;EAClBC,mBAAmBP,QAAQQ;EAC3BC,iBAAiBT,QAAQU;CAC3B;CACAC,aAAa,EACXC,OAAOhB,OAAOiB,eAChB;CACAC,YAAY;EACVC,cAAcnB,OAAOiB;EACrBG,eAAe3B;EACf4B,cAAc;EACdC,cAAc9B;CAChB;CAGA+B,OAAO;EACLhB,YAAY;EACZiB,QAAQrB,OAAOsB;EACfjB,gBAAgB;EAChBkB,OAAOvB,OAAOsB;CAChB;CACAE,WAAW;EACTR,cAAcnB,OAAO4B;EACrBR,eAAe3B;EACf4B,cAAc;EACdC,cAAc9B;CAChB;CAEAqC,SAAS,EACPC,cAAc7B,MAAM8B,KACtB;CAWAC,SAAS;EACPC,WAAW;EACXC,UAAU;EACVC,kBAAkB/B,QAAQU;EAC1BsB,UAAU;EACVvB,iBAAiBtB;CACnB;CACA8C,aAAa,EACXrB,OAAOhB,OAAO4B,iBAChB;CAIAU,QAAQ;EACN/B,YAAY;EACZZ,QAAQ;EACRC,MAAM;EACN2C,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E,aAAAC,kBAAsChN,SAAwB,IAAI;CAClE,MAAAiN,OAAa5M,SAAQmJ,OAAQ,aAAapD,UAAU;CAAC,IAAAoC;CAAA,IAAAQ;CAAA,IAAAP,EAAA,OAAAwE,QAAAxE,EAAA,OAAArC,SAAA;EAE3CoC,WAAA;GACR,IAAI,CAACyE,MAAI;GAIT,IAAAT,UAAc;GAWTU,CAAAA,eATLA,MAAA;IACE,MAAAC,eACE,MAAMjN,kBAAiBkN,4BAA6BhH,OAAO;IAE7D,IAAIoG,SACFQ,eAAeG,YAAY;GAC5B,EAAA,CAGM;GAAC,aAEH;IACLX,UAAUA;GAAH;EACR;EACAxD,KAAA,CAACiE,MAAM7G,OAAO;EAACqC,EAAA,KAAAwE;EAAAxE,EAAA,KAAArC;EAAAqC,EAAA,KAAAD;EAAAC,EAAA,KAAAO;CAAA,OAAA;EAAAR,KAAAC,EAAA;EAAAO,KAAAP,EAAA;CAAA;CArBlB3I,UAAU0I,IAqBPQ,EAAe;CAAC,OAEZiE,OAAAF,cAAA3G;AAA4B;AAGrCmC,SAAS8E,QAAQzG"}
@@ -0,0 +1,58 @@
1
+ import { View, ViewProps } from "react-native";
2
+ import { ComponentRef, ReactNode, Ref } from "react";
3
+ //#region src/components/tag/index.d.ts
4
+ type TagProps = ViewProps & {
5
+ /**
6
+ * What the tag says. A string or a number is drawn as its label, and runs
7
+ * of them as one label; anything else, such as an icon, is drawn as given,
8
+ * handed the tag's colour and size through `useIconStyle()`.
9
+ */
10
+ readonly children?: ReactNode;
11
+ readonly ref?: Ref<ComponentRef<typeof View>>;
12
+ /**
13
+ * Which colour role the tag carries. `neutral` states without ranking; the
14
+ * other three read as good, bad, or worth noticing.
15
+ *
16
+ * Each is a container under its own on-colour, legible on the surface
17
+ * family, which is what the library's own tokens and every demo scheme are
18
+ * held to. Over a container of its own the pair is one colour family on top
19
+ * of another and is not guaranteed, so a custom theme placing a tag there
20
+ * has to check that pair itself.
21
+ * @default 'neutral'
22
+ */
23
+ readonly tone?: TagTone;
24
+ /**
25
+ * How much weight the tag pulls. `filled` sits on a container of its own;
26
+ * `outlined` is a rule on the surface, for a tag that should not compete
27
+ * with the thing it labels.
28
+ * @default 'filled'
29
+ */
30
+ readonly variant?: TagVariant;
31
+ };
32
+ type TagTone = 'negative' | 'neutral' | 'positive' | 'primary';
33
+ type TagVariant = 'filled' | 'outlined';
34
+ /**
35
+ * A short, read-only label attached to something else, such as a count or a
36
+ * status beside a row's headline. It takes no press: for a label that can be
37
+ * selected, reach for Chip.
38
+ *
39
+ * ```tsx
40
+ * <ListItem trailing={<Tag tone="positive">Label</Tag>}>Headline</ListItem>
41
+ * ```
42
+ *
43
+ * The label is set in label small with tabular figures, on one line. An icon
44
+ * given beside it is drawn at the label's line height in the label's colour,
45
+ * so a tag with an icon is the same height as one without. A screen reader
46
+ * reads the label where the tag sits; the tag adds no role of its own.
47
+ *
48
+ * Like any view, a tag stretches across a column it sits in on its own, so a
49
+ * call site placing one there sets `alignSelf`. A row slot, such as
50
+ * ListItem's trailing one, already holds it at its own width.
51
+ *
52
+ * `style`, `ref` and `testID` land on the `View`, and a `style` there applies
53
+ * over the tag's own.
54
+ */
55
+ declare function Tag({ children, style, tone, variant, ...props }: TagProps): import("react").JSX.Element;
56
+ //#endregion
57
+ export { Tag, type TagProps, type TagTone, type TagVariant };
58
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,205 @@
1
+ import { IconStyleContext } from "../../glyphs/icon-style.js";
2
+ import { useTheme } from "../../theme/scope.js";
3
+ import { composeStyles, themedStyles } from "../../theme/styles.js";
4
+ import { useTypeRole } from "../../typography/roles.js";
5
+ import { c } from "react/compiler-runtime";
6
+ import { StyleSheet, Text, View } from "react-native";
7
+ import { Children } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ //#region src/components/tag/index.tsx
10
+ const styles = StyleSheet.create({ label: {
11
+ flexShrink: 0,
12
+ fontVariant: ["tabular-nums"]
13
+ } });
14
+ const stylesOf = themedStyles(({ radii, spacing }) => StyleSheet.create({ base: {
15
+ alignItems: "center",
16
+ borderRadius: radii.sm,
17
+ borderWidth: 1,
18
+ flexDirection: "row",
19
+ flexShrink: 0,
20
+ gap: spacing.xs,
21
+ paddingHorizontal: spacing.sm,
22
+ paddingVertical: spacing.xxs
23
+ } }));
24
+ const tonesOf = themedStyles(({ colors }) => ({
25
+ filled: {
26
+ negative: toneOf(colors.negativeContainer, "transparent", colors.onNegativeContainer),
27
+ neutral: toneOf(colors.surfaceContainerHighest, "transparent", colors.onSurfaceVariant),
28
+ positive: toneOf(colors.positiveContainer, "transparent", colors.onPositiveContainer),
29
+ primary: toneOf(colors.primaryContainer, "transparent", colors.onPrimaryContainer)
30
+ },
31
+ outlined: {
32
+ negative: toneOf("transparent", colors.negative, colors.negative),
33
+ neutral: toneOf("transparent", colors.outlineVariant, colors.onSurfaceVariant),
34
+ positive: toneOf("transparent", colors.positive, colors.positive),
35
+ primary: toneOf("transparent", colors.primary, colors.primary)
36
+ }
37
+ }));
38
+ /**
39
+ * The children in order, with each run of strings and numbers drawn as one
40
+ * label, so `{count} items` is one Text rather than three. A React Native
41
+ * string has to sit inside a Text, and anything else is drawn as given. A
42
+ * label is keyed by where it falls among what is drawn, which a render of the
43
+ * same children always repeats.
44
+ */
45
+ function contentOf(children, label) {
46
+ const content = [];
47
+ let text;
48
+ const flush = () => {
49
+ if (text !== void 0) {
50
+ content.push(/* @__PURE__ */ jsx(Text, {
51
+ numberOfLines: 1,
52
+ style: label,
53
+ children: text
54
+ }, `label-${String(content.length)}`));
55
+ text = void 0;
56
+ }
57
+ };
58
+ for (const child of Children.toArray(children)) if (typeof child === "string" || typeof child === "number" || typeof child === "bigint") text = (text ?? "") + String(child);
59
+ else {
60
+ flush();
61
+ content.push(child);
62
+ }
63
+ flush();
64
+ return content;
65
+ }
66
+ /**
67
+ * The colour and size the tag hands an icon beside its label. Built by a call
68
+ * rather than written inline, which is what react-perf's
69
+ * jsx-no-new-object-as-prop is after; the React Compiler memoises the result
70
+ * on its inputs.
71
+ */
72
+ function iconStyleOf(color, size) {
73
+ return {
74
+ color,
75
+ size
76
+ };
77
+ }
78
+ /**
79
+ * A short, read-only label attached to something else, such as a count or a
80
+ * status beside a row's headline. It takes no press: for a label that can be
81
+ * selected, reach for Chip.
82
+ *
83
+ * ```tsx
84
+ * <ListItem trailing={<Tag tone="positive">Label</Tag>}>Headline</ListItem>
85
+ * ```
86
+ *
87
+ * The label is set in label small with tabular figures, on one line. An icon
88
+ * given beside it is drawn at the label's line height in the label's colour,
89
+ * so a tag with an icon is the same height as one without. A screen reader
90
+ * reads the label where the tag sits; the tag adds no role of its own.
91
+ *
92
+ * Like any view, a tag stretches across a column it sits in on its own, so a
93
+ * call site placing one there sets `alignSelf`. A row slot, such as
94
+ * ListItem's trailing one, already holds it at its own width.
95
+ *
96
+ * `style`, `ref` and `testID` land on the `View`, and a `style` there applies
97
+ * over the tag's own.
98
+ */
99
+ function Tag(t0) {
100
+ const $ = c(28);
101
+ let children;
102
+ let props;
103
+ let style;
104
+ let t1;
105
+ let t2;
106
+ if ($[0] !== t0) {
107
+ ({children, style, tone: t1, variant: t2, ...props} = t0);
108
+ $[0] = t0;
109
+ $[1] = children;
110
+ $[2] = props;
111
+ $[3] = style;
112
+ $[4] = t1;
113
+ $[5] = t2;
114
+ } else {
115
+ children = $[1];
116
+ props = $[2];
117
+ style = $[3];
118
+ t1 = $[4];
119
+ t2 = $[5];
120
+ }
121
+ const tone = t1 === void 0 ? "neutral" : t1;
122
+ const variant = t2 === void 0 ? "filled" : t2;
123
+ const theme = useTheme();
124
+ const role = useTypeRole("labelSmall");
125
+ let T0;
126
+ let T1;
127
+ let t3;
128
+ let t4;
129
+ let t5;
130
+ let t6;
131
+ if ($[6] !== children || $[7] !== props || $[8] !== role || $[9] !== style || $[10] !== theme || $[11] !== tone || $[12] !== variant) {
132
+ const toned = tonesOf(theme)[variant][tone];
133
+ T1 = View;
134
+ t5 = props;
135
+ t6 = composeStyles(stylesOf(theme).base, toned.container, style);
136
+ T0 = IconStyleContext;
137
+ t3 = iconStyleOf(toned.content, theme.typography.labelSmallLineHeight);
138
+ t4 = contentOf(children, composeStyles(role, styles.label, toned.label));
139
+ $[6] = children;
140
+ $[7] = props;
141
+ $[8] = role;
142
+ $[9] = style;
143
+ $[10] = theme;
144
+ $[11] = tone;
145
+ $[12] = variant;
146
+ $[13] = T0;
147
+ $[14] = T1;
148
+ $[15] = t3;
149
+ $[16] = t4;
150
+ $[17] = t5;
151
+ $[18] = t6;
152
+ } else {
153
+ T0 = $[13];
154
+ T1 = $[14];
155
+ t3 = $[15];
156
+ t4 = $[16];
157
+ t5 = $[17];
158
+ t6 = $[18];
159
+ }
160
+ let t7;
161
+ if ($[19] !== T0 || $[20] !== t3 || $[21] !== t4) {
162
+ t7 = /* @__PURE__ */ jsx(T0, {
163
+ value: t3,
164
+ children: t4
165
+ });
166
+ $[19] = T0;
167
+ $[20] = t3;
168
+ $[21] = t4;
169
+ $[22] = t7;
170
+ } else t7 = $[22];
171
+ let t8;
172
+ if ($[23] !== T1 || $[24] !== t5 || $[25] !== t6 || $[26] !== t7) {
173
+ t8 = /* @__PURE__ */ jsx(T1, {
174
+ ...t5,
175
+ style: t6,
176
+ children: t7
177
+ });
178
+ $[23] = T1;
179
+ $[24] = t5;
180
+ $[25] = t6;
181
+ $[26] = t7;
182
+ $[27] = t8;
183
+ } else t8 = $[27];
184
+ return t8;
185
+ }
186
+ /**
187
+ * One tone's styles: the container's fill and rule, the label's colour, and
188
+ * that colour on its own for an icon beside the label.
189
+ */
190
+ function toneOf(background, border, content) {
191
+ return {
192
+ content,
193
+ ...StyleSheet.create({
194
+ container: {
195
+ backgroundColor: background,
196
+ borderColor: border
197
+ },
198
+ label: { color: content }
199
+ })
200
+ };
201
+ }
202
+ //#endregion
203
+ export { Tag };
204
+
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["ComponentRef","ReactNode","Ref","StyleProp","TextStyle","ViewProps","ViewStyle","Children","Text","NativeText","StyleSheet","View","IconStyle","IconStyleContext","useTheme","composeStyles","themedStyles","useTypeRole","styles","create","label","flexShrink","fontVariant","stylesOf","radii","spacing","base","alignItems","borderRadius","sm","borderWidth","flexDirection","gap","xs","paddingHorizontal","paddingVertical","xxs","tonesOf","colors","filled","negative","toneOf","negativeContainer","onNegativeContainer","neutral","surfaceContainerHighest","onSurfaceVariant","positive","positiveContainer","onPositiveContainer","primary","primaryContainer","onPrimaryContainer","outlined","outlineVariant","TagProps","children","ref","tone","TagTone","variant","TagVariant","contentOf","content","text","flush","undefined","push","String","length","child","toArray","iconStyleOf","color","size","Tag","t0","$","_c","props","style","t1","t2","theme","role","T0","T1","t3","t4","t5","t6","toned","container","typography","labelSmallLineHeight","t7","t8","background","border","backgroundColor","borderColor","NativeText","_c"],"sources":["../../../src/components/tag/index.tsx"],"sourcesContent":["import type { ComponentRef, ReactNode, Ref } from 'react'\nimport type { StyleProp, TextStyle, ViewProps, ViewStyle } from 'react-native'\n\nimport { Children } from 'react'\nimport { Text as NativeText, StyleSheet, View } from 'react-native'\n\nimport type { IconStyle } from '../../glyphs/icon-style'\n\nimport { IconStyleContext } from '../../glyphs/icon-style'\nimport { useTheme } from '../../theme/scope'\nimport { composeStyles, themedStyles } from '../../theme/styles'\nimport { useTypeRole } from '../../typography/roles'\n\n// A tag states something about what it sits beside, such as a count, a status\n// or a version, and is never itself the thing you press. That is the whole\n// line between this and Chip: a chip is a two-state button, so reaching for\n// one to draw a read-only label puts a control in the accessibility tree that\n// nothing can operate. The view takes no press and no role.\n//\n// Both variants carry a 1dp border, and `filled` makes it transparent rather\n// than dropping it, so a tag is the same size either way. Emphasising one tag\n// in a row otherwise nudges its neighbours by a dp each side.\n//\n// Tabular figures are unconditional, for the same reason Currency sets them:\n// what ends up in a tag is mostly numeric, such as counts, versions and ports,\n// and a stack of them down a list wobbles on proportional digits. Text that\n// carries no digits is unaffected.\n//\n// No Material Design page draws a tag, as on web. The badges page's large\n// badge is the nearest, a label-small count on an 8dp corner, and that is the\n// type and the corner here. A tag stands beside a word rather than on an icon,\n// so it takes the padding and the 1dp rule above in place of the badge's 16dp\n// box, and the container roles in place of the badge's error pair, since it\n// names a state rather than flagging one.\n//\n// A tag labels something else, so it is never what makes a row wrap or\n// shrink: `flexShrink: 0` holds its width, and its label stays on one line.\nconst styles = StyleSheet.create({\n label: {\n flexShrink: 0,\n fontVariant: ['tabular-nums'],\n },\n})\n\nconst stylesOf = themedStyles(({ radii, spacing }) =>\n StyleSheet.create({\n base: {\n alignItems: 'center',\n borderRadius: radii.sm,\n borderWidth: 1,\n flexDirection: 'row',\n flexShrink: 0,\n gap: spacing.xs,\n paddingHorizontal: spacing.sm,\n paddingVertical: spacing.xxs,\n },\n }),\n)\n\n// `neutral` draws from the surface roles rather than a colour of its own,\n// which is what lets it state something without ranking it. The other three\n// name a direction, and are the same three Currency uses, plus primary for the\n// notable-but-not-good-or-bad case.\n//\n// Outlined takes the tone at full strength for both the rule and the text,\n// rather than the on-container pairing filled uses. There is no container\n// there for an on-colour to be legible against, since the surface is the\n// background, so the container roles would read as washed out.\nconst tonesOf = themedStyles(({ colors }) => ({\n filled: {\n negative: toneOf(\n colors.negativeContainer,\n 'transparent',\n colors.onNegativeContainer,\n ),\n neutral: toneOf(\n colors.surfaceContainerHighest,\n 'transparent',\n colors.onSurfaceVariant,\n ),\n positive: toneOf(\n colors.positiveContainer,\n 'transparent',\n colors.onPositiveContainer,\n ),\n primary: toneOf(\n colors.primaryContainer,\n 'transparent',\n colors.onPrimaryContainer,\n ),\n },\n outlined: {\n negative: toneOf('transparent', colors.negative, colors.negative),\n neutral: toneOf(\n 'transparent',\n colors.outlineVariant,\n colors.onSurfaceVariant,\n ),\n positive: toneOf('transparent', colors.positive, colors.positive),\n primary: toneOf('transparent', colors.primary, colors.primary),\n },\n}))\n\ntype TagProps = ViewProps & {\n /**\n * What the tag says. A string or a number is drawn as its label, and runs\n * of them as one label; anything else, such as an icon, is drawn as given,\n * handed the tag's colour and size through `useIconStyle()`.\n */\n readonly children?: ReactNode\n readonly ref?: Ref<ComponentRef<typeof View>>\n /**\n * Which colour role the tag carries. `neutral` states without ranking; the\n * other three read as good, bad, or worth noticing.\n *\n * Each is a container under its own on-colour, legible on the surface\n * family, which is what the library's own tokens and every demo scheme are\n * held to. Over a container of its own the pair is one colour family on top\n * of another and is not guaranteed, so a custom theme placing a tag there\n * has to check that pair itself.\n * @default 'neutral'\n */\n readonly tone?: TagTone\n /**\n * How much weight the tag pulls. `filled` sits on a container of its own;\n * `outlined` is a rule on the surface, for a tag that should not compete\n * with the thing it labels.\n * @default 'filled'\n */\n readonly variant?: TagVariant\n}\n\ntype TagTone = 'negative' | 'neutral' | 'positive' | 'primary'\n\ntype TagVariant = 'filled' | 'outlined'\n\n/**\n * The children in order, with each run of strings and numbers drawn as one\n * label, so `{count} items` is one Text rather than three. A React Native\n * string has to sit inside a Text, and anything else is drawn as given. A\n * label is keyed by where it falls among what is drawn, which a render of the\n * same children always repeats.\n */\nfunction contentOf(\n children: ReactNode,\n label: StyleProp<TextStyle>,\n): ReactNode[] {\n const content: ReactNode[] = []\n let text: string | undefined\n\n const flush = () => {\n if (text !== undefined) {\n content.push(\n <NativeText\n key={`label-${String(content.length)}`}\n numberOfLines={1}\n style={label}\n >\n {text}\n </NativeText>,\n )\n text = undefined\n }\n }\n\n for (const child of Children.toArray(children)) {\n if (\n typeof child === 'string' ||\n typeof child === 'number' ||\n typeof child === 'bigint'\n ) {\n text = (text ?? '') + String(child)\n } else {\n flush()\n content.push(child)\n }\n }\n flush()\n\n return content\n}\n\n/**\n * The colour and size the tag hands an icon beside its label. Built by a call\n * rather than written inline, which is what react-perf's\n * jsx-no-new-object-as-prop is after; the React Compiler memoises the result\n * on its inputs.\n */\nfunction iconStyleOf(color: string, size: number): IconStyle {\n return { color, size }\n}\n\n/**\n * A short, read-only label attached to something else, such as a count or a\n * status beside a row's headline. It takes no press: for a label that can be\n * selected, reach for Chip.\n *\n * ```tsx\n * <ListItem trailing={<Tag tone=\"positive\">Label</Tag>}>Headline</ListItem>\n * ```\n *\n * The label is set in label small with tabular figures, on one line. An icon\n * given beside it is drawn at the label's line height in the label's colour,\n * so a tag with an icon is the same height as one without. A screen reader\n * reads the label where the tag sits; the tag adds no role of its own.\n *\n * Like any view, a tag stretches across a column it sits in on its own, so a\n * call site placing one there sets `alignSelf`. A row slot, such as\n * ListItem's trailing one, already holds it at its own width.\n *\n * `style`, `ref` and `testID` land on the `View`, and a `style` there applies\n * over the tag's own.\n */\nfunction Tag({\n children,\n style,\n tone = 'neutral',\n variant = 'filled',\n ...props\n}: TagProps) {\n const theme = useTheme()\n const role = useTypeRole('labelSmall')\n const toned = tonesOf(theme)[variant][tone]\n\n return (\n <View\n {...props}\n style={composeStyles<ViewStyle>(\n stylesOf(theme).base,\n toned.container,\n style,\n )}\n >\n <IconStyleContext\n value={iconStyleOf(\n toned.content,\n theme.typography.labelSmallLineHeight,\n )}\n >\n {contentOf(\n children,\n composeStyles<TextStyle>(role, styles.label, toned.label),\n )}\n </IconStyleContext>\n </View>\n )\n}\n\n/**\n * One tone's styles: the container's fill and rule, the label's colour, and\n * that colour on its own for an icon beside the label.\n */\nfunction toneOf(background: string, border: string, content: string) {\n return {\n content,\n ...StyleSheet.create({\n container: { backgroundColor: background, borderColor: border },\n label: { color: content },\n }),\n }\n}\n\nexport type { TagProps, TagTone, TagVariant }\n\nexport { Tag }\n"],"mappings":";;;;;;;;;AAqCA,MAAMkB,SAASR,WAAWS,OAAO,EAC/BC,OAAO;CACLC,YAAY;CACZC,aAAa,CAAC,cAAc;AAC9B,EACF,CAAC;AAED,MAAMC,WAAWP,cAAc,EAAEQ,OAAOC,cACtCf,WAAWS,OAAO,EAChBO,MAAM;CACJC,YAAY;CACZC,cAAcJ,MAAMK;CACpBC,aAAa;CACbC,eAAe;CACfV,YAAY;CACZW,KAAKP,QAAQQ;CACbC,mBAAmBT,QAAQI;CAC3BM,iBAAiBV,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' | 'accessibilityL
7
7
  /**
8
8
  * Counts the characters the field holds at the end of the supporting line,
9
9
  * against `maxLength` where there is one, as the text fields page's
10
- * character counter does. The count is written in the device's digits.
10
+ * character counter does. The count is written in the digits of the
11
+ * `I18nProvider`'s locale, or the device's outside one.
11
12
  * @default false
12
13
  */
13
14
  readonly characterCount?: boolean;
@@ -15,8 +16,10 @@ type TextFieldProps = Omit<TextInputProps, 'accessibilityHint' | 'accessibilityL
15
16
  * How the limit is said to a screen reader, where there is a `maxLength`.
16
17
  * Read with the field rather than as the value changes, so it names the
17
18
  * limit and not what is left of it; the visible count is hidden from
18
- * screen readers, which is what this replaces. Left out, it is the English
19
- * sentence, "Up to 20 characters", singular for a limit of one.
19
+ * screen readers, which is what this replaces. Left out, it is the
20
+ * library's sentence in the `I18nProvider`'s locale, or the device's
21
+ * outside one, in the plural form the limit takes there: "Up to 20
22
+ * characters" in English, singular for a limit of one.
20
23
  */
21
24
  readonly characterLimitLabel?: string;
22
25
  /** The value the field opens with, when it keeps its own. */
@@ -1,3 +1,4 @@
1
+ import { useLocaleOf } from "../../i18n/provider.js";
1
2
  import { useFieldValidation } from "../../form/index.js";
2
3
  import { FieldBox, FieldInput, FieldMessage, describedBy, useFieldFocus } from "../../field/index.js";
3
4
  import { c } from "react/compiler-runtime";
@@ -94,6 +95,7 @@ function TextField(t0) {
94
95
  } else t12 = $[14];
95
96
  const focus = useFieldFocus(t12);
96
97
  const shownError = validation.error;
98
+ const locale = useLocaleOf(void 0);
97
99
  let t13;
98
100
  let t14;
99
101
  if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
@@ -117,6 +119,7 @@ function TextField(t0) {
117
119
  characterLimitLabel,
118
120
  description,
119
121
  error: shownError,
122
+ locale,
120
123
  maxLength: props.maxLength
121
124
  });
122
125
  const t20 = !isDisabled && !isReadOnly;