@colixsystems/widget-sdk 0.303.0 → 0.305.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
90
90
 
91
91
  ## Status
92
92
 
93
- `v0.303.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
93
+ `v0.305.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
94
+
95
+ ### What's new in 0.305.0 (contract 1.249.0)
96
+
97
+ **A `<Button>` follows its parent's alignment.** A button forced `alignSelf: "flex-start"` on itself, so it sat at the left of a column with `alignItems: "center"` (an empty state's call to action) and at the top of a row with `alignItems: "center"` (an Edit button beside a name and a price). It now hugs its label inside a box its parent places: centred in a centring column, vertically centred in a centring row, at the end of a `flex-end` column, and at the start of a plain column, content-width as before. A `style` with `alignSelf`, `flex`, `flexGrow`, `flexBasis` or a percentage `width`, `minWidth`, `height` or `minHeight` makes it an ordinary flex item the parent places like any other, so a `flex: 1` button in a row takes the row's cross-axis alignment. The button's margins, `maxWidth`, `maxHeight`, `flexShrink`, `position` and offsets go on that box. `<IconButton>` drops its own `alignSelf` too: a fixed square never stretches. Visible change: a button that sat at the start of a centring parent moves to where that parent puts its children.
98
+
99
+ ### What's new in 0.304.0 (contract 1.248.0)
100
+
101
+ **A horizontal `ScrollView` shows mouse users that it scrolls.** A card carousel or chip row in `<ScrollView horizontal showsHorizontalScrollIndicator={false}>` is fine on a phone, where you swipe, but on a computer nothing showed that it scrolls and a mouse had no easy way to scroll it, so the last card looked cut off. On the web, a horizontal `ScrollView` whose content overflows now fades the edge that has more content, and hovering it with a mouse shows previous / next arrow buttons that scroll smoothly by about one view width (instantly when the visitor prefers reduced motion). The arrows are 36px round buttons in the theme's surface, border and `onSurface` colours; they stay out of the tab order, because the row itself is focusable and scrolls with the arrow keys, and shift-wheel and trackpad scrolling work as before. A row that fits shows nothing, and the edges update as the row scrolls or its content or width changes. Touch screens on the web and the exported app are unchanged: a swipe is their affordance. It is on by default, so published widgets get it with no code change; pass `showsScrollAffordance={false}` to a widget that draws its own arrows. Vertical scrollers are unchanged. A short set of chips on a wide layout reads better wrapped in a `<ChipGroup>` than scrolled.
94
102
 
95
103
  ### What's new in 0.303.0 (contract 1.247.0)
96
104
 
@@ -130,6 +130,43 @@ function triggerProps(props) {
130
130
  };
131
131
  }
132
132
 
133
+ // Where a hugging button sits among its siblings: its box takes these.
134
+ const BOX_STYLE_KEYS = new Set([
135
+ "margin", "marginTop", "marginRight", "marginBottom", "marginLeft",
136
+ "marginHorizontal", "marginVertical", "marginStart", "marginEnd",
137
+ "marginBlock", "marginBlockStart", "marginBlockEnd",
138
+ "marginInline", "marginInlineStart", "marginInlineEnd",
139
+ "flexShrink", "maxWidth", "maxHeight",
140
+ "position", "top", "right", "bottom", "left", "start", "end", "zIndex", "display",
141
+ ]);
142
+ const SELF_PLACING_KEYS = ["alignSelf", "flex", "flexGrow", "flexBasis"];
143
+ const SIZE_KEYS = ["width", "minWidth", "height", "minHeight"];
144
+
145
+ /**
146
+ * How a button's `style` splits between the box its parent places and the
147
+ * button that hugs its label inside it, or null when the style places the
148
+ * button itself (an `alignSelf`, a flex grow or basis, a percentage size).
149
+ *
150
+ * Flexbox has no "do not stretch" that leaves the parent's other alignments
151
+ * alone: `alignSelf: "flex-start"` overrode a centring parent, and Yoga
152
+ * stretches a `width: "fit-content"` child. So the box follows the parent and
153
+ * the button hugs at its start, which differs only where the parent stretches.
154
+ *
155
+ * @param {object|Array|null|undefined|false} style
156
+ * @returns {{ box: object, button: object } | null}
157
+ */
158
+ function hugStyle(style) {
159
+ const flat = flattenStyle(style);
160
+ const selfPlaced =
161
+ SELF_PLACING_KEYS.some((key) => flat[key] !== undefined) ||
162
+ SIZE_KEYS.some((key) => flat[key] !== undefined && typeof flat[key] !== "number");
163
+ if (selfPlaced) return null;
164
+ const box = {};
165
+ const button = {};
166
+ for (const [key, value] of Object.entries(flat)) (BOX_STYLE_KEYS.has(key) ? box : button)[key] = value;
167
+ return { box, button };
168
+ }
169
+
133
170
  function pressable(props) {
134
171
  return typeof props.onPress === "function" || typeof props.onLongPress === "function";
135
172
  }
@@ -230,6 +267,7 @@ export function makeButton(rn) {
230
267
  const fontSize =
231
268
  typeof f.fontSize === "number" && Number.isFinite(f.fontSize) ? f.fontSize : sized.fontSize;
232
269
  const glyph = iconNode(icon, Math.round(fontSize), ink);
270
+ const hug = hugStyle(style);
233
271
 
234
272
  const container = [
235
273
  {
@@ -237,14 +275,14 @@ export function makeButton(rn) {
237
275
  borderRadius: radii.sm,
238
276
  alignItems: "center",
239
277
  justifyContent: "center",
240
- alignSelf: "flex-start",
241
278
  },
279
+ hug ? { alignSelf: "flex-start" } : null,
242
280
  ...layers,
243
281
  glyph ? { flexDirection: "row", gap: spacing.xs } : null,
244
282
  // The gradient IS the fill, so it drops every flat background.
245
283
  gradient ? { backgroundColor: "transparent" } : null,
246
284
  disabled ? { opacity: 0.5 } : null,
247
- style,
285
+ hug ? hug.button : style,
248
286
  ];
249
287
  const label = React.createElement(
250
288
  Text,
@@ -275,23 +313,23 @@ export function makeButton(rn) {
275
313
  busy ? busyMark(look, layers, fontSize) : null,
276
314
  ];
277
315
 
278
- if (!pressable(props)) {
279
- return React.createElement(View, { ref, style: container, testID, accessibilityLabel }, children);
280
- }
281
- return React.createElement(
282
- Pressable,
283
- {
284
- ref,
285
- onPress,
286
- ...trigger.pass,
287
- ...pressableState({ disabled, busy, selected, expanded: trigger.expanded }, web),
288
- accessibilityRole: "button",
289
- accessibilityLabel: accessibilityLabel || (typeof title === "string" ? title : undefined),
290
- testID,
291
- style: pressedStyle(container, disabled || busy),
292
- },
293
- children,
294
- );
316
+ const button = pressable(props)
317
+ ? React.createElement(
318
+ Pressable,
319
+ {
320
+ ref,
321
+ onPress,
322
+ ...trigger.pass,
323
+ ...pressableState({ disabled, busy, selected, expanded: trigger.expanded }, web),
324
+ accessibilityRole: "button",
325
+ accessibilityLabel: accessibilityLabel || (typeof title === "string" ? title : undefined),
326
+ testID,
327
+ style: pressedStyle(container, disabled || busy),
328
+ },
329
+ children,
330
+ )
331
+ : React.createElement(View, { ref, style: container, testID, accessibilityLabel }, children);
332
+ return hug ? React.createElement(View, { style: hug.box }, button) : button;
295
333
  });
296
334
  Button.displayName = "Button";
297
335
 
@@ -335,7 +373,7 @@ export function makeButton(rn) {
335
373
  const { box, glyph } = iconButtonFrame(size);
336
374
 
337
375
  const container = [
338
- { borderRadius: theme.radii.sm, alignItems: "center", justifyContent: "center", alignSelf: "flex-start" },
376
+ { borderRadius: theme.radii.sm, alignItems: "center", justifyContent: "center" },
339
377
  ...layers,
340
378
  // A real square: the web ignores hitSlop, so the box is the target.
341
379
  { width: box, height: box, minWidth: box, minHeight: box, paddingHorizontal: 0, paddingVertical: 0 },
package/dist/contract.cjs CHANGED
@@ -3520,7 +3520,7 @@ const PRIMITIVES = [
3520
3520
  {
3521
3521
  name: "ScrollView",
3522
3522
  description:
3523
- "Scrollable container. Pass `horizontal` to scroll on the x-axis. See https://reactnative.dev/docs/scrollview.",
3523
+ "Scrollable container. Pass `horizontal` to scroll on the x-axis. On the web, a horizontal row whose content overflows shows mouse users that it scrolls: the edge with more content fades, and hovering shows previous / next arrows that scroll about one view width. Touch screens and the exported app swipe as before, and a row that fits shows nothing. Pass `showsScrollAffordance={false}` only when the widget draws its own arrows. A short set of chips is better wrapped in a `<ChipGroup>` than scrolled. See https://reactnative.dev/docs/scrollview.",
3524
3524
  rnComponent: "ScrollView",
3525
3525
  docsUrl: "https://reactnative.dev/docs/scrollview",
3526
3526
  },
@@ -3872,7 +3872,7 @@ const PRIMITIVES = [
3872
3872
  {
3873
3873
  name: "Button",
3874
3874
  description:
3875
- 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style, e.g. `alignSelf`) and `labelStyle`. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3875
+ 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style) and `labelStyle`. It hugs its label and follows its parent\'s alignment: centred in a column with `alignItems: "center"`, vertically centred in such a row, at the start of a plain column. A `style` with `alignSelf`, `flex` or a percentage width makes it an ordinary flex item the parent may stretch. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3876
3876
  rnComponent: null,
3877
3877
  docsUrl: null,
3878
3878
  },
@@ -6915,7 +6915,11 @@ const CONTRACT = deepFreeze({
6915
6915
  // 1.247.0: the four status tokens are fixed again (danger #dc2626, success
6916
6916
  // #059669, warning #d97706, info #0284c7); hosts no longer derive them from
6917
6917
  // the palette. `deriveStatusColors` stays exported, unused by the hosts.
6918
- version: "1.247.0",
6918
+ // 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
6919
+ // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6920
+ // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6921
+ // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6922
+ version: "1.249.0",
6919
6923
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6920
6924
  hooks: HOOKS,
6921
6925
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -3515,7 +3515,7 @@ const PRIMITIVES = [
3515
3515
  {
3516
3516
  name: "ScrollView",
3517
3517
  description:
3518
- "Scrollable container. Pass `horizontal` to scroll on the x-axis. See https://reactnative.dev/docs/scrollview.",
3518
+ "Scrollable container. Pass `horizontal` to scroll on the x-axis. On the web, a horizontal row whose content overflows shows mouse users that it scrolls: the edge with more content fades, and hovering shows previous / next arrows that scroll about one view width. Touch screens and the exported app swipe as before, and a row that fits shows nothing. Pass `showsScrollAffordance={false}` only when the widget draws its own arrows. A short set of chips is better wrapped in a `<ChipGroup>` than scrolled. See https://reactnative.dev/docs/scrollview.",
3519
3519
  rnComponent: "ScrollView",
3520
3520
  docsUrl: "https://reactnative.dev/docs/scrollview",
3521
3521
  },
@@ -3867,7 +3867,7 @@ const PRIMITIVES = [
3867
3867
  {
3868
3868
  name: "Button",
3869
3869
  description:
3870
- 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style, e.g. `alignSelf`) and `labelStyle`. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3870
+ 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style) and `labelStyle`. It hugs its label and follows its parent\'s alignment: centred in a column with `alignItems: "center"`, vertically centred in such a row, at the start of a plain column. A `style` with `alignSelf`, `flex` or a percentage width makes it an ordinary flex item the parent may stretch. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3871
3871
  rnComponent: null,
3872
3872
  docsUrl: null,
3873
3873
  },
@@ -6910,7 +6910,11 @@ const CONTRACT = deepFreeze({
6910
6910
  // 1.247.0: the four status tokens are fixed again (danger #dc2626, success
6911
6911
  // #059669, warning #d97706, info #0284c7); hosts no longer derive them from
6912
6912
  // the palette. `deriveStatusColors` stays exported, unused by the hosts.
6913
- version: "1.247.0",
6913
+ // 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
6914
+ // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6915
+ // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6916
+ // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
+ version: "1.249.0",
6914
6918
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6915
6919
  hooks: HOOKS,
6916
6920
  primitives: PRIMITIVES,
package/dist/index.d.ts CHANGED
@@ -4140,6 +4140,16 @@ export const Text: any;
4140
4140
  export const View: any;
4141
4141
  export const Pressable: any;
4142
4142
  export const Image: any;
4143
+ /**
4144
+ * React Native's ScrollView, with one SDK prop:
4145
+ *
4146
+ * - `showsScrollAffordance` (boolean, default true) — on the web, a
4147
+ * `horizontal` scroller whose content overflows fades the edge with more
4148
+ * content and, on hover with a mouse, shows previous / next arrows that
4149
+ * scroll about one view width. Touch screens and the exported app are
4150
+ * unchanged; keyboard and shift-wheel scrolling keep working. Pass false
4151
+ * only when the widget draws its own arrows.
4152
+ */
4143
4153
  export const ScrollView: any;
4144
4154
  export const TextInput: any;
4145
4155
  export const FlatList: any;
@@ -41,12 +41,14 @@
41
41
  // `react-native` alias path on the web.
42
42
  import { ReactNative } from "./text-scale.js";
43
43
  import { makeTextInput } from "./text-input-view.js";
44
+ import { makeScrollView } from "./scroll-view.js";
44
45
 
45
46
  export const Text = ReactNative.Text;
46
47
  export const View = ReactNative.View;
47
48
  export { Pressable } from "./pressable.js";
48
49
  export const Image = ReactNative.Image;
49
- export const ScrollView = ReactNative.ScrollView;
50
+ // A horizontal row shows mouse users that it scrolls; see ./scroll-view.js.
51
+ export const ScrollView = makeScrollView(ReactNative);
50
52
  export const TextInput = makeTextInput(ReactNative.TextInput);
51
53
  // Additional cross-platform primitives the AI agent + handwritten
52
54
  // widgets commonly reach for. All work in both react-native-web and
@@ -0,0 +1,173 @@
1
+ // The web `<ScrollView>`: react-native-web's, plus an overflow affordance for
2
+ // mouse users on a horizontal row. A mouse has no swipe, so a row whose
3
+ // scrollbar is hidden reads as cut off. Where the content overflows, the edge
4
+ // with more content fades out, and hovering shows previous / next arrows.
5
+ //
6
+ // Native re-exports React Native's ScrollView as is (./primitives.native.js):
7
+ // a swipe is the native affordance. Scrolling is the same capability on both
8
+ // hosts; only the input differs. Touch screens on the web are left unchanged.
9
+
10
+ import React from "react";
11
+ import { useHostSharedText, useHostTheme } from "./hooks.js";
12
+ import { DEFAULT_THEME_TOKENS } from "./_theme-tokens.js";
13
+ import { flattenStyle } from "./flatten-style.js";
14
+ import { Icon } from "./icon.js";
15
+
16
+ const h = React.createElement;
17
+ const FINE_POINTER = "(hover: hover) and (pointer: fine)";
18
+ // The smallest tap target the design findings accept.
19
+ export const SCROLL_ARROW_SIZE = 36;
20
+ export const SCROLL_FADE_PX = 32;
21
+ // Leaves a sliver of the last item in view, so the step reads as continuous.
22
+ const STEP_FRACTION = 0.9;
23
+ // Sub-pixel layouts leave a fraction of a pixel to scroll at either end.
24
+ const EDGE_SLACK_PX = 1;
25
+
26
+ // Placement keys move to the wrapper so the row sits where the author put it.
27
+ const OUTER_STYLE_KEYS = Object.freeze([
28
+ "width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight", "aspectRatio",
29
+ "flex", "flexBasis", "flexGrow", "flexShrink", "alignSelf", "display",
30
+ "position", "top", "right", "bottom", "left", "start", "end", "zIndex",
31
+ "margin", "marginTop", "marginRight", "marginBottom", "marginLeft",
32
+ "marginHorizontal", "marginVertical", "marginStart", "marginEnd",
33
+ ]);
34
+
35
+ function splitStyle(style) {
36
+ const outer = {};
37
+ const inner = {};
38
+ for (const [key, value] of Object.entries(flattenStyle(style))) {
39
+ if (value === undefined) continue;
40
+ (OUTER_STYLE_KEYS.includes(key) ? outer : inner)[key] = value;
41
+ }
42
+ return { outer, inner };
43
+ }
44
+
45
+ function matches(query) {
46
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(query).matches;
47
+ }
48
+
49
+ /** Which edges have more content: "start", "end", "both" or "none". */
50
+ export function overflowEdges({ scrollLeft, scrollWidth, clientWidth }) {
51
+ const x = Math.abs(scrollLeft);
52
+ const start = x > EDGE_SLACK_PX;
53
+ const end = scrollWidth - clientWidth - x > EDGE_SLACK_PX;
54
+ return start && end ? "both" : start ? "start" : end ? "end" : "none";
55
+ }
56
+
57
+ /** A mask that fades the content out toward each edge with more of it. */
58
+ export function fadeMask(edges) {
59
+ if (edges === "none") return null;
60
+ const from = edges === "end" ? "#000" : "transparent";
61
+ const to = edges === "start" ? "#000" : "transparent";
62
+ const mask = `linear-gradient(to right, ${from} 0, #000 ${SCROLL_FADE_PX}px, #000 calc(100% - ${SCROLL_FADE_PX}px), ${to} 100%)`;
63
+ return { maskImage: mask, WebkitMaskImage: mask };
64
+ }
65
+
66
+ function assignRef(ref, node) {
67
+ if (typeof ref === "function") ref(node);
68
+ else if (ref && typeof ref === "object") ref.current = node;
69
+ }
70
+
71
+ function chain(own, theirs) {
72
+ return (...args) => {
73
+ own(...args);
74
+ if (typeof theirs === "function") theirs(...args);
75
+ };
76
+ }
77
+
78
+ /**
79
+ * @param {{ ScrollView: any, View: any, Pressable: any }} rn react-native-web's primitives.
80
+ */
81
+ export function makeScrollView({ ScrollView: BaseScrollView, View, Pressable }) {
82
+ function Arrow({ side, label, onPress, theme }) {
83
+ const { colors, spacing } = theme;
84
+ return h(
85
+ Pressable,
86
+ {
87
+ accessibilityRole: "button",
88
+ accessibilityLabel: label,
89
+ // Keyboard users scroll the focused row itself; the arrows serve the mouse.
90
+ tabIndex: -1,
91
+ onPress,
92
+ testID: `scroll-arrow-${side}`,
93
+ style: {
94
+ position: "absolute",
95
+ top: "50%",
96
+ marginTop: -SCROLL_ARROW_SIZE / 2,
97
+ [side === "previous" ? "left" : "right"]: spacing.xs,
98
+ width: SCROLL_ARROW_SIZE,
99
+ height: SCROLL_ARROW_SIZE,
100
+ borderRadius: SCROLL_ARROW_SIZE / 2,
101
+ alignItems: "center",
102
+ justifyContent: "center",
103
+ backgroundColor: colors.surface,
104
+ borderWidth: 1,
105
+ borderColor: colors.border,
106
+ ...(theme.elevation && theme.elevation.md),
107
+ },
108
+ },
109
+ h(Icon, { name: side === "previous" ? "chevron-left" : "chevron-right", size: 20, color: colors.onSurface }),
110
+ );
111
+ }
112
+
113
+ const ScrollView = React.forwardRef(function ScrollView(props, ref) {
114
+ const { showsScrollAffordance = true, ...rest } = props;
115
+ const theme = useHostTheme() || DEFAULT_THEME_TOKENS;
116
+ const previousLabel = useHostSharedText("previous", "Previous");
117
+ const nextLabel = useHostSharedText("next", "Next");
118
+ const [finePointer] = React.useState(() => matches(FINE_POINTER));
119
+ const [edges, setEdges] = React.useState("none");
120
+ const [hovered, setHovered] = React.useState(false);
121
+ const node = React.useRef(null);
122
+
123
+ const setRef = React.useCallback(
124
+ (value) => {
125
+ node.current = value;
126
+ assignRef(ref, value);
127
+ },
128
+ [ref],
129
+ );
130
+ // The string state bails out of re-rendering while the edges stay put.
131
+ const measure = React.useCallback(() => {
132
+ if (node.current) setEdges(overflowEdges(node.current));
133
+ }, []);
134
+
135
+ if (!rest.horizontal || !showsScrollAffordance || !finePointer) {
136
+ return h(BaseScrollView, { ...rest, ref });
137
+ }
138
+
139
+ const step = (direction) => {
140
+ const el = node.current;
141
+ if (!el) return;
142
+ const behavior = matches("(prefers-reduced-motion: reduce)") ? "auto" : "smooth";
143
+ el.scrollBy({ left: direction * el.clientWidth * STEP_FRACTION, behavior });
144
+ };
145
+ const { outer, inner } = splitStyle(rest.style);
146
+ const showArrows = hovered && edges !== "none";
147
+
148
+ return h(
149
+ View,
150
+ {
151
+ style: { flexGrow: 1, flexShrink: 1, ...outer },
152
+ onMouseEnter: () => setHovered(true),
153
+ onMouseLeave: () => setHovered(false),
154
+ },
155
+ h(BaseScrollView, {
156
+ ...rest,
157
+ ref: setRef,
158
+ style: [inner, fadeMask(edges)],
159
+ onLayout: chain(measure, rest.onLayout),
160
+ onContentSizeChange: chain(measure, rest.onContentSizeChange),
161
+ onScroll: chain(measure, rest.onScroll),
162
+ }),
163
+ showArrows && edges !== "end"
164
+ ? h(Arrow, { side: "previous", label: previousLabel, onPress: () => step(-1), theme })
165
+ : null,
166
+ showArrows && edges !== "start"
167
+ ? h(Arrow, { side: "next", label: nextLabel, onPress: () => step(1), theme })
168
+ : null,
169
+ );
170
+ });
171
+ ScrollView.displayName = "ScrollView";
172
+ return ScrollView;
173
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.303.0",
3
+ "version": "0.305.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "homepage": "https://github.com/Colix-AB/AppStudio",
6
6
  "type": "module",
package/src/contract.js CHANGED
@@ -3515,7 +3515,7 @@ const PRIMITIVES = [
3515
3515
  {
3516
3516
  name: "ScrollView",
3517
3517
  description:
3518
- "Scrollable container. Pass `horizontal` to scroll on the x-axis. See https://reactnative.dev/docs/scrollview.",
3518
+ "Scrollable container. Pass `horizontal` to scroll on the x-axis. On the web, a horizontal row whose content overflows shows mouse users that it scrolls: the edge with more content fades, and hovering shows previous / next arrows that scroll about one view width. Touch screens and the exported app swipe as before, and a row that fits shows nothing. Pass `showsScrollAffordance={false}` only when the widget draws its own arrows. A short set of chips is better wrapped in a `<ChipGroup>` than scrolled. See https://reactnative.dev/docs/scrollview.",
3519
3519
  rnComponent: "ScrollView",
3520
3520
  docsUrl: "https://reactnative.dev/docs/scrollview",
3521
3521
  },
@@ -3867,7 +3867,7 @@ const PRIMITIVES = [
3867
3867
  {
3868
3868
  name: "Button",
3869
3869
  description:
3870
- 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style, e.g. `alignSelf`) and `labelStyle`. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3870
+ 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style) and `labelStyle`. It hugs its label and follows its parent\'s alignment: centred in a column with `alignItems: "center"`, vertically centred in such a row, at the start of a plain column. A `style` with `alignSelf`, `flex` or a percentage width makes it an ordinary flex item the parent may stretch. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3871
3871
  rnComponent: null,
3872
3872
  docsUrl: null,
3873
3873
  },
@@ -6910,7 +6910,11 @@ const CONTRACT = deepFreeze({
6910
6910
  // 1.247.0: the four status tokens are fixed again (danger #dc2626, success
6911
6911
  // #059669, warning #d97706, info #0284c7); hosts no longer derive them from
6912
6912
  // the palette. `deriveStatusColors` stays exported, unused by the hosts.
6913
- version: "1.247.0",
6913
+ // 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
6914
+ // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6915
+ // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6916
+ // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
+ version: "1.249.0",
6914
6918
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6915
6919
  hooks: HOOKS,
6916
6920
  primitives: PRIMITIVES,