@colixsystems/widget-sdk 0.304.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 +5 -1
- package/dist/button-view.js +58 -20
- package/dist/contract.cjs +4 -2
- package/dist/contract.js +4 -2
- package/package.json +1 -1
- package/src/contract.js +4 -2
package/README.md
CHANGED
|
@@ -90,7 +90,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
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.
|
|
94
98
|
|
|
95
99
|
### What's new in 0.304.0 (contract 1.248.0)
|
|
96
100
|
|
package/dist/button-view.js
CHANGED
|
@@ -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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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"
|
|
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
|
@@ -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,
|
|
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
|
},
|
|
@@ -6917,7 +6917,9 @@ const CONTRACT = deepFreeze({
|
|
|
6917
6917
|
// the palette. `deriveStatusColors` stays exported, unused by the hosts.
|
|
6918
6918
|
// 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
|
|
6919
6919
|
// the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
|
|
6920
|
-
|
|
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",
|
|
6921
6923
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6922
6924
|
hooks: HOOKS,
|
|
6923
6925
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -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,
|
|
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
|
},
|
|
@@ -6912,7 +6912,9 @@ const CONTRACT = deepFreeze({
|
|
|
6912
6912
|
// the palette. `deriveStatusColors` stays exported, unused by the hosts.
|
|
6913
6913
|
// 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
|
|
6914
6914
|
// the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
|
|
6915
|
-
|
|
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",
|
|
6916
6918
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6917
6919
|
hooks: HOOKS,
|
|
6918
6920
|
primitives: PRIMITIVES,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "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
|
@@ -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,
|
|
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
|
},
|
|
@@ -6912,7 +6912,9 @@ const CONTRACT = deepFreeze({
|
|
|
6912
6912
|
// the palette. `deriveStatusColors` stays exported, unused by the hosts.
|
|
6913
6913
|
// 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
|
|
6914
6914
|
// the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
|
|
6915
|
-
|
|
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",
|
|
6916
6918
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6917
6919
|
hooks: HOOKS,
|
|
6918
6920
|
primitives: PRIMITIVES,
|