@oxy.so/bloom 4.20.0 → 4.21.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 (47) hide show
  1. package/docs/adoption-matrix.mdx +3 -3
  2. package/docs/button.mdx +1 -1
  3. package/docs/design-tokens.mdx +22 -0
  4. package/docs/dialog.mdx +5 -0
  5. package/lib/commonjs/accordion/Accordion.js +7 -3
  6. package/lib/commonjs/accordion/Accordion.js.map +1 -1
  7. package/lib/commonjs/button/Button.js +37 -1
  8. package/lib/commonjs/button/Button.js.map +1 -1
  9. package/lib/commonjs/design-tokens/theme-css.js +24 -2
  10. package/lib/commonjs/design-tokens/theme-css.js.map +1 -1
  11. package/lib/commonjs/design-tokens/theme.css +8 -8
  12. package/lib/commonjs/dialog/DialogBottomSheet.js +19 -3
  13. package/lib/commonjs/dialog/DialogBottomSheet.js.map +1 -1
  14. package/lib/commonjs/dialog/DialogHeader.js +78 -6
  15. package/lib/commonjs/dialog/DialogHeader.js.map +1 -1
  16. package/lib/module/accordion/Accordion.js +7 -3
  17. package/lib/module/accordion/Accordion.js.map +1 -1
  18. package/lib/module/button/Button.js +38 -2
  19. package/lib/module/button/Button.js.map +1 -1
  20. package/lib/module/design-tokens/theme-css.js +23 -2
  21. package/lib/module/design-tokens/theme-css.js.map +1 -1
  22. package/lib/module/design-tokens/theme.css +8 -8
  23. package/lib/module/dialog/DialogBottomSheet.js +19 -3
  24. package/lib/module/dialog/DialogBottomSheet.js.map +1 -1
  25. package/lib/module/dialog/DialogHeader.js +76 -5
  26. package/lib/module/dialog/DialogHeader.js.map +1 -1
  27. package/lib/typescript/commonjs/accordion/Accordion.d.ts.map +1 -1
  28. package/lib/typescript/commonjs/button/Button.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/design-tokens/theme-css.d.ts +9 -1
  30. package/lib/typescript/commonjs/design-tokens/theme-css.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/dialog/DialogBottomSheet.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/dialog/DialogHeader.d.ts +24 -0
  33. package/lib/typescript/commonjs/dialog/DialogHeader.d.ts.map +1 -1
  34. package/lib/typescript/module/accordion/Accordion.d.ts.map +1 -1
  35. package/lib/typescript/module/button/Button.d.ts.map +1 -1
  36. package/lib/typescript/module/design-tokens/theme-css.d.ts +9 -1
  37. package/lib/typescript/module/design-tokens/theme-css.d.ts.map +1 -1
  38. package/lib/typescript/module/dialog/DialogBottomSheet.d.ts.map +1 -1
  39. package/lib/typescript/module/dialog/DialogHeader.d.ts +24 -0
  40. package/lib/typescript/module/dialog/DialogHeader.d.ts.map +1 -1
  41. package/package.json +5 -2
  42. package/src/accordion/Accordion.tsx +9 -1
  43. package/src/button/Button.tsx +41 -3
  44. package/src/design-tokens/theme-css.ts +23 -2
  45. package/src/design-tokens/theme.css +8 -8
  46. package/src/dialog/DialogBottomSheet.tsx +21 -0
  47. package/src/dialog/DialogHeader.tsx +94 -11
@@ -4,6 +4,7 @@ import { resolveIconSlot } from '../icons/render-icon';
4
4
  import {
5
5
  ActivityIndicator,
6
6
  Linking,
7
+ Platform,
7
8
  Pressable,
8
9
  StyleSheet,
9
10
  View,
@@ -80,6 +81,42 @@ const SQUARE_HIT_SLOP = {
80
81
  lg: { top: 0, bottom: 0, left: 0, right: 0 },
81
82
  } as const satisfies Record<ButtonResolvedSize, NonNullable<ButtonProps['hitSlop']>>;
82
83
 
84
+ type HitSlop = { top: number; bottom: number; left: number; right: number };
85
+
86
+ /**
87
+ * Android's floor is 48dp (Material), 4dp above the 44 the tables above reach —
88
+ * so on Android every target grows 2dp at its top and bottom: `lg` (44dp tall,
89
+ * no slack) reaches 48, and every smaller size clears 48 the same way. Squares
90
+ * also grow 2dp at the sides, since they already take all-round slack; row
91
+ * buttons and links do not, because side slack steals presses from a
92
+ * neighbour. Two stacked buttons keep 4dp of every 8dp gap between them.
93
+ */
94
+ const ANDROID_TARGET_EXTRA = 2;
95
+
96
+ function growVertical(slop: HitSlop): HitSlop {
97
+ return { ...slop, top: slop.top + ANDROID_TARGET_EXTRA, bottom: slop.bottom + ANDROID_TARGET_EXTRA };
98
+ }
99
+
100
+ function growAllRound(slop: HitSlop): HitSlop {
101
+ return {
102
+ top: slop.top + ANDROID_TARGET_EXTRA,
103
+ bottom: slop.bottom + ANDROID_TARGET_EXTRA,
104
+ left: slop.left + ANDROID_TARGET_EXTRA,
105
+ right: slop.right + ANDROID_TARGET_EXTRA,
106
+ };
107
+ }
108
+
109
+ function mapSizes(
110
+ table: Record<ButtonResolvedSize, HitSlop>,
111
+ grow: (slop: HitSlop) => HitSlop,
112
+ ): Record<ButtonResolvedSize, HitSlop> {
113
+ return { xs: grow(table.xs), sm: grow(table.sm), md: grow(table.md), lg: grow(table.lg) };
114
+ }
115
+
116
+ const ANDROID_SIZE_HIT_SLOP = mapSizes(SIZE_HIT_SLOP, growVertical);
117
+ const ANDROID_SQUARE_HIT_SLOP = mapSizes(SQUARE_HIT_SLOP, growAllRound);
118
+ const ANDROID_LINK_HIT_SLOP = growVertical(LINK_HIT_SLOP);
119
+
83
120
  // ---------------------------------------------------------------------------
84
121
  // The button renders ONE node — the same shape the web fork renders (one
85
122
  // `<button>`), so a caller's layout `className` lands on the box its parent
@@ -286,11 +323,12 @@ const ButtonComponent: React.FC<ButtonProps> = ({
286
323
  [geometry, paint.foreground, isLink, underlineMode, hovered, disabled],
287
324
  );
288
325
 
326
+ const android = Platform.OS === 'android';
289
327
  const defaultHitSlop = isSquare
290
- ? SQUARE_HIT_SLOP[size]
328
+ ? (android ? ANDROID_SQUARE_HIT_SLOP : SQUARE_HIT_SLOP)[size]
291
329
  : isLink
292
- ? LINK_HIT_SLOP
293
- : SIZE_HIT_SLOP[size];
330
+ ? (android ? ANDROID_LINK_HIT_SLOP : LINK_HIT_SLOP)
331
+ : (android ? ANDROID_SIZE_HIT_SLOP : SIZE_HIT_SLOP)[size];
294
332
 
295
333
  const IconFromProp = icon != null && isIconComponent(icon) ? icon : null;
296
334
  const iconNode = IconFromProp ? (
@@ -35,6 +35,17 @@ import {
35
35
  } from './scales';
36
36
  import { SHADOW_BOX } from './shadows';
37
37
 
38
+ /**
39
+ * A px line-height as the unitless ratio of its font-size, spelled the way
40
+ * Tailwind spells its own type scale: `lineHeightRatio(22, 15)` → `calc(22 / 15)`.
41
+ * Exact on both platforms (no rounded decimal), and the only form
42
+ * react-native-css resolves correctly through `var()` — it multiplies any
43
+ * number by the font-size.
44
+ */
45
+ export function lineHeightRatio(lineHeightPx: number, fontSizePx: number): string {
46
+ return `calc(${lineHeightPx} / ${fontSizePx})`;
47
+ }
48
+
38
49
  /**
39
50
  * Produce the BODY of a Tailwind v4 `@theme` block (no surrounding braces) that
40
51
  * registers the full Bloom semantic vocabulary.
@@ -42,7 +53,7 @@ import { SHADOW_BOX } from './shadows';
42
53
  * - Colors → `--color-<role>: var(--canonical);`
43
54
  * - Spacing → `--spacing-<key>: <px>;`
44
55
  * - Radius → `--radius-<key>: <px>;`
45
- * - Type → `--text-<role>: <size>; --text-<role>--line-height: <lh>;`
56
+ * - Type → `--text-<role>: <size>; --text-<role>--line-height: calc(<lh> / <size>);`
46
57
  * `--font-<role>: var(--bloom-font-*);` (+ weight via utility doc)
47
58
  * - Shadow → `--shadow-<s|m>: <box-shadow>;`
48
59
  */
@@ -94,10 +105,20 @@ export function bloomThemeCss(): string {
94
105
  }
95
106
 
96
107
  // Typography: size + line-height + family per role.
108
+ //
109
+ // The line-height is a UNITLESS ratio (`calc(22 / 15)`), the form Tailwind's
110
+ // own `--text-sm--line-height: calc(1.25 / 0.875)` takes — never px. On the
111
+ // web the two are identical (a unitless line-height is a multiple of the
112
+ // font-size: 15px × 22/15 = 22px). On native they are not: Tailwind v4 emits
113
+ // `line-height: var(--tw-leading, var(--text-body--line-height))`,
114
+ // react-native-css compiles that to `lineHeight(var(…, 22))`, and its runtime
115
+ // `lineHeight` resolver treats EVERY number as an em multiplier — so a px
116
+ // token rendered `text-body` at 22 × 15 = 330dp line-height on Android and
117
+ // iOS. See `lineHeightRatio` and `docs/typography.mdx`.
97
118
  for (const name of Object.keys(TYPOGRAPHY) as TypeRoleName[]) {
98
119
  const role = TYPOGRAPHY[name];
99
120
  lines.push(` --text-${name}: ${role.size}px;`);
100
- lines.push(` --text-${name}--line-height: ${role.lineHeight}px;`);
121
+ lines.push(` --text-${name}--line-height: ${lineHeightRatio(role.lineHeight, role.size)};`);
101
122
  lines.push(` --text-${name}--font-weight: ${role.weight};`);
102
123
  lines.push(` --font-${name}: ${FONT_FAMILY_VARS[role.family]};`);
103
124
  }
@@ -124,35 +124,35 @@
124
124
  --radius-radius-max: 9999px;
125
125
  --border-width-hairline: 0.5px;
126
126
  --text-caption: 11px;
127
- --text-caption--line-height: 14px;
127
+ --text-caption--line-height: calc(14 / 11);
128
128
  --text-caption--font-weight: 400;
129
129
  --font-caption: var(--bloom-font-sans);
130
130
  --text-bodySmall: 13px;
131
- --text-bodySmall--line-height: 18px;
131
+ --text-bodySmall--line-height: calc(18 / 13);
132
132
  --text-bodySmall--font-weight: 400;
133
133
  --font-bodySmall: var(--bloom-font-sans);
134
134
  --text-bodyTitleSmall: 13px;
135
- --text-bodyTitleSmall--line-height: 18px;
135
+ --text-bodyTitleSmall--line-height: calc(18 / 13);
136
136
  --text-bodyTitleSmall--font-weight: 600;
137
137
  --font-bodyTitleSmall: var(--bloom-font-sans);
138
138
  --text-body: 15px;
139
- --text-body--line-height: 22px;
139
+ --text-body--line-height: calc(22 / 15);
140
140
  --text-body--font-weight: 400;
141
141
  --font-body: var(--bloom-font-sans);
142
142
  --text-subtitle: 17px;
143
- --text-subtitle--line-height: 24px;
143
+ --text-subtitle--line-height: calc(24 / 17);
144
144
  --text-subtitle--font-weight: 500;
145
145
  --font-subtitle: var(--bloom-font-sans);
146
146
  --text-sectionTitle: 20px;
147
- --text-sectionTitle--line-height: 26px;
147
+ --text-sectionTitle--line-height: calc(26 / 20);
148
148
  --text-sectionTitle--font-weight: 600;
149
149
  --font-sectionTitle: var(--bloom-font-sans);
150
150
  --text-headerBold: 28px;
151
- --text-headerBold--line-height: 34px;
151
+ --text-headerBold--line-height: calc(34 / 28);
152
152
  --text-headerBold--font-weight: 700;
153
153
  --font-headerBold: var(--bloom-font-display);
154
154
  --text-buttonLarge: 17px;
155
- --text-buttonLarge--line-height: 22px;
155
+ --text-buttonLarge--line-height: calc(22 / 17);
156
156
  --text-buttonLarge--font-weight: 600;
157
157
  --font-buttonLarge: var(--bloom-font-sans);
158
158
  --font-bloom-sans: var(--bloom-font-sans);
@@ -13,6 +13,7 @@ import {
13
13
  type ViewStyle,
14
14
  } from 'react-native';
15
15
  import { type AnimatedStyle } from 'react-native-reanimated';
16
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
16
17
 
17
18
  import { BottomSheet, type BottomSheetRef } from '../bottom-sheet';
18
19
  import { useTheme } from '../theme/use-theme';
@@ -86,6 +87,11 @@ export function DialogBottomSheet({
86
87
  const titleId = useId();
87
88
  const descriptionId = useId();
88
89
  const headerController = useDialogHeaderController();
90
+ // The sheet is flush with the bottom of the window (a `<Modal>` drawn
91
+ // edge-to-edge on Android, and under the home indicator on iOS), and
92
+ // `BottomSheet` deliberately leaves the safe area to its content. This Dialog
93
+ // IS the content's chrome, so it owns the inset (the spacer after the body).
94
+ const { bottom: bottomInset } = useSafeAreaInsets();
89
95
 
90
96
  // Read the latest controlled flag / `onClose` inside stable callbacks without
91
97
  // re-binding them (the context + imperative handle depend on `close` staying
@@ -325,12 +331,27 @@ export function DialogBottomSheet({
325
331
  <DialogMorphContent morph={morphState} style={scrollableResolved ? undefined : FILL_BOUNDED}>
326
332
  {header ? headerBody : dialogBody}
327
333
  </DialogMorphContent>
334
+ {/* The bottom safe area, INSIDE the scroll content. Without it the
335
+ last row of every bottom-placement Dialog was painted under the
336
+ Android gesture bar / iOS home indicator (a 2400px Pixel put a
337
+ "Having trouble?" link at 2297–2356px), and a body that outgrew
338
+ the sheet could not scroll its last rows out from under the bar —
339
+ the scroll range ended exactly where the bar began. A spacer
340
+ rather than a padding: the content box keeps the caller's
341
+ `padding`/`contentPadding` untouched on both platforms, and the
342
+ morph layer above still measures the content alone. */}
343
+ {bottomInset > 0 ? (
344
+ <View testID={SAFE_AREA_SPACER_TESTID} style={{ height: bottomInset }} />
345
+ ) : null}
328
346
  </StyledView>
329
347
  </Context.Provider>
330
348
  </BottomSheet>
331
349
  );
332
350
  }
333
351
 
352
+ /** Test handle for the bottom safe-area spacer. */
353
+ const SAFE_AREA_SPACER_TESTID = 'dialog-sheet-safe-area';
354
+
334
355
  /** Passes a bounded height down to a `scrollable={false}` body. */
335
356
  const FILL_BOUNDED = { flex: 1, minHeight: 0 } as const;
336
357
 
@@ -83,6 +83,52 @@ const HEADER_H_PADDING = 20;
83
83
  /** Circular icon-button diameter for the default back / close affordances. */
84
84
  const NAV_BUTTON_SIZE = 36;
85
85
 
86
+ /** The large title's line box (px) — `styles.largeTitle.lineHeight`. */
87
+ const LARGE_TITLE_LINE_HEIGHT = 38;
88
+
89
+ /**
90
+ * Content top inset (px) for an INLINE-CLOSE header (see {@link isInlineCloseHeader}):
91
+ * the large title's first line is centred on the nav row, level with the ✕,
92
+ * instead of starting below the whole bar.
93
+ */
94
+ export const DIALOG_HEADER_INLINE_CONTENT_TOP = (DIALOG_NAV_BAR_HEIGHT - LARGE_TITLE_LINE_HEIGHT) / 2;
95
+
96
+ /**
97
+ * Space (px) the large title's first line keeps clear at its trailing edge for
98
+ * the ✕ it shares a row with: the nav row's gutter + the button + an 8px gap,
99
+ * less the title block's own gutter.
100
+ */
101
+ const INLINE_CLOSE_TITLE_RESERVE = HEADER_H_PADDING - 4 + NAV_BUTTON_SIZE + 8 - HEADER_H_PADDING;
102
+
103
+ /** Scroll distance (px) over which the bar's scrim fades in on an inline-close header. */
104
+ const INLINE_SCRIM_FADE_DISTANCE = 16;
105
+
106
+ /**
107
+ * Whether a large-title header puts its title IN the nav row, beside the ✕,
108
+ * rather than in a band below the bar.
109
+ *
110
+ * The nav row exists for its controls. When it would hold nothing but the
111
+ * default close — no back, no leading slot, no trailing actions, no custom
112
+ * trailing node — a full 72px row above the title is an empty band on every
113
+ * entry view of a flow (an account dialog's first screen, a one-page sheet).
114
+ * The title then starts level with the ✕ and wraps before it; the bar's scrim
115
+ * and the small collapsed title still arrive once the title scrolls under it.
116
+ *
117
+ * Anything that gives the row content of its own keeps the stacked layout: a
118
+ * back button (the title would sit between two buttons), rich trailing actions
119
+ * or a custom `right` (unknown width), a branded `titleContent` (no large title
120
+ * at all), and `tone: 'onImage'` (the scrim is what makes the chrome legible
121
+ * over media, so it cannot start hidden).
122
+ */
123
+ export function isInlineCloseHeader(config: DialogHeaderConfig): boolean {
124
+ const hasLargeTitle = !config.titleContent && (config.largeTitle ?? true) && !!config.title;
125
+ if (!hasLargeTitle) return false;
126
+ if (config.tone === 'onImage') return false;
127
+ if (config.left || config.onBack || config.right) return false;
128
+ if (config.actions?.length || config.primaryAction) return false;
129
+ return true;
130
+ }
131
+
86
132
  /**
87
133
  * Trailing icon `actions` shown inline before they collapse into a "more"
88
134
  * overflow menu (Material overflow pattern). Kept small so the nav row never
@@ -473,6 +519,17 @@ export const DialogNavHeader = memo(function DialogNavHeader({
473
519
  // so there is nothing to collapse and no large in-content title to collapse under.
474
520
  const hasLargeTitle =
475
521
  collapse && !config.titleContent && (config.largeTitle ?? true) && !!config.title;
522
+ // The large title shares the nav row with the ✕ at rest (`isInlineCloseHeader`),
523
+ // so the scrim — opaque at the top — must not paint over it until content
524
+ // actually scrolls under the bar. Only a collapsing bar has an in-content title.
525
+ const inlineClose = collapse && isInlineCloseHeader(config);
526
+
527
+ const scrimStyle = useAnimatedStyle(() => {
528
+ if (!inlineClose) return { opacity: 1 };
529
+ return {
530
+ opacity: interpolate(scrollY.value, [0, INLINE_SCRIM_FADE_DISTANCE], [0, 1], Extrapolation.CLAMP),
531
+ };
532
+ }, [scrollY, inlineClose]);
476
533
 
477
534
  const titleStyle = useAnimatedStyle(() => {
478
535
  // When there is no large title to collapse under, the bar title is always
@@ -548,14 +605,23 @@ export const DialogNavHeader = memo(function DialogNavHeader({
548
605
  {/* Opaque (surface bg) at the top → transparent at the bottom, so scrolled
549
606
  content fades out under the bar. `onImage` swaps to a dark scrim so the
550
607
  chrome reads over media. Pure NativeWind — no SVG dependency. */}
551
- <View
552
- className={
553
- onImage
554
- ? 'bg-gradient-to-b from-black/60 to-transparent'
555
- : 'bg-gradient-to-b from-bg to-transparent'
556
- }
557
- style={[StyleSheet.absoluteFill, { height: DIALOG_HEADER_OVERLAY_HEIGHT, pointerEvents: 'none' }]}
558
- />
608
+ <Animated.View
609
+ testID="dialog-nav-scrim"
610
+ style={[
611
+ StyleSheet.absoluteFill,
612
+ { height: DIALOG_HEADER_OVERLAY_HEIGHT, pointerEvents: 'none' },
613
+ scrimStyle,
614
+ ]}
615
+ >
616
+ <View
617
+ className={
618
+ onImage
619
+ ? 'bg-gradient-to-b from-black/60 to-transparent'
620
+ : 'bg-gradient-to-b from-bg to-transparent'
621
+ }
622
+ style={StyleSheet.absoluteFill}
623
+ />
624
+ </Animated.View>
559
625
  <View pointerEvents="box-none" style={styles.navRow}>
560
626
  <View style={styles.side}>{left}</View>
561
627
  <Animated.View
@@ -625,14 +691,31 @@ export const DialogLargeTitle = memo(function DialogLargeTitle({
625
691
  return onImage ? null : <View style={{ height: DIALOG_NAV_BAR_HEIGHT }} />;
626
692
  }
627
693
 
694
+ // Title level with the ✕ when the nav row would hold nothing else.
695
+ const inlineClose = isInlineCloseHeader(config);
696
+
628
697
  return (
629
698
  <>
630
- {/* Clear the whole gradient overlay so the block starts below the bar. */}
631
- <View style={{ height: DIALOG_HEADER_CONTENT_TOP }} />
699
+ {/* Clear the whole gradient overlay so the block starts below the bar —
700
+ or, inline with the ✕, just centre the first line on the nav row. */}
701
+ <View
702
+ testID="dialog-large-title-inset"
703
+ style={{ height: inlineClose ? DIALOG_HEADER_INLINE_CONTENT_TOP : DIALOG_HEADER_CONTENT_TOP }}
704
+ />
632
705
  <View onLayout={onLayout} testID="dialog-large-title" style={styles.largeTitleBlock}>
633
706
  {hasLargeTitle ? (
634
707
  <>
635
- <H1 style={[styles.largeTitle, { color: onImage ? ON_IMAGE_TEXT : theme.colors.text }]}>
708
+ <H1
709
+ style={[
710
+ styles.largeTitle,
711
+ { color: onImage ? ON_IMAGE_TEXT : theme.colors.text },
712
+ // Wrap before the ✕ it shares the row with. A logical inset, so
713
+ // it follows the ✕ to the left edge in a right-to-left layout.
714
+ inlineClose && config.showClose !== false
715
+ ? { marginInlineEnd: INLINE_CLOSE_TITLE_RESERVE }
716
+ : null,
717
+ ]}
718
+ >
636
719
  {config.title}
637
720
  </H1>
638
721
  {config.subtitle ? (