@hanzo/ui 8.4.4 → 8.4.6

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/dist/box.cjs CHANGED
@@ -21,6 +21,20 @@ const jsx_runtime_1 = require("react/jsx-runtime");
21
21
  * 77 of 225 elements on one page into flex containers that were never asked to
22
22
  * be: an inline run became a column, a heading's width collapsed to its text,
23
23
  * and a page grew 8% taller.
24
+ *
25
+ * `tag` renders the element Box is standing in for, and it is what makes the
26
+ * migration reach past `<div>`. Divs are about a third of what carries a
27
+ * className in these apps; the rest are `p`, `span`, `li`, `h2`, `section`, `a`.
28
+ * Converting those to a div-only Box would read as a rename and would in fact
29
+ * strip the document of its headings, lists and paragraphs — every one of them a
30
+ * thing a screen reader navigates by.
31
+ *
32
+ * It goes through `asChild` because gui does NOT honour a `tag` prop: asked for
33
+ * one it renders its own element anyway AND passes `tag` through to the DOM,
34
+ * where it is an invalid attribute. `asChild` is the supported way to say "style
35
+ * this element instead of yours", so the semantics come from the element and the
36
+ * styling still comes from gui — one substrate, not a second styling path for
37
+ * everything that is not a div.
24
38
  */
25
39
  const react_1 = require("react");
26
40
  const gui_1 = require("@hanzo/gui");
@@ -28,14 +42,24 @@ const tw_1 = require("./tw.cjs");
28
42
  /** Properties a frame ignores and a DOM element passes to its children. */
29
43
  const TEXT_PROPS = ['fontSize', 'lineHeight', 'fontWeight', 'letterSpacing',
30
44
  'textTransform', 'fontFamily', 'fontStyle', 'textAlign', 'color',
31
- 'textDecorationLine', 'whiteSpace'];
32
- exports.Box = (0, react_1.forwardRef)(function Box({ className, children, 'aria-hidden': hidden, ...rest }, ref) {
45
+ 'textDecorationLine', 'whiteSpace',
46
+ // `tabular-nums` is the one class on a checkout that MUST survive: it is what
47
+ // makes a column of figures line up. tw converts it to fontVariantNumeric,
48
+ // which a frame drops like the rest of these, and the loss shows as a money
49
+ // column going ragged — a 25px total measuring 27px, which no test asserting
50
+ // on text would notice.
51
+ 'fontVariantNumeric'];
52
+ exports.Box = (0, react_1.forwardRef)(function Box({ className, children, 'aria-hidden': hidden, tag, ...rest }, ref) {
33
53
  const { props, rest: unread } = (0, tw_1.tw)(className);
34
54
  // A View pins `min-height: 0`; a div's is `auto`, and auto is what gives a
35
55
  // flex or grid child its automatic minimum size. Pinned, a converted child of
36
56
  // a row of indefinite height measured 0px and its content vanished.
37
57
  if (!('minHeight' in props))
38
58
  props.minHeight = 'auto';
59
+ // The same fact on the other axis. A View pins `min-width: 0`, a div's is
60
+ // auto, and auto is what stops a flex child shrinking below its content.
61
+ if (!('minWidth' in props))
62
+ props.minWidth = 'auto';
39
63
  // gui drops a text property set on a frame — `fontSize` is not a frame style
40
64
  // prop, so it silently rendered at the inherited size and a page carrying
41
65
  // `text-xs` on a box came out three pixels larger everywhere. A div DOES pass
@@ -52,15 +76,21 @@ exports.Box = (0, react_1.forwardRef)(function Box({ className, children, 'aria-
52
76
  // class said otherwise, so `leading-relaxed` still wins.
53
77
  if (!('lineHeight' in text))
54
78
  text.lineHeight = 'inherit';
79
+ const style = Object.keys(text).length
80
+ ? { ...text, ...rest.style }
81
+ : rest.style;
55
82
  // Explicit props win: a caller who states a value directly means it, and the
56
83
  // classes are what they are migrating away from.
57
- return ((0, jsx_runtime_1.jsx)(gui_1.YStack, { ref: ref, display: "block",
84
+ const frame = ((0, jsx_runtime_1.jsx)(gui_1.YStack, { ref: tag ? undefined : ref, asChild: tag ? true : undefined, display: "block",
58
85
  // A View does not shrink; a div does. Left at the View's default, every
59
86
  // converted flex child held its full basis and overflowed its row instead
60
87
  // of sharing it — two half-width columns came out 608px each in a 1216px
61
88
  // row with a 32px gap, where the divs they replaced sat at 592.
62
89
  // `shrink`, not `flexShrink`: gui types the shorthand and compiles both to
63
90
  // the same `_shrink-1`, and the DOM spelling is the one it does not carry.
64
- shrink: 1, "aria-hidden": hidden === undefined ? undefined : hidden !== 'false' && hidden !== false, ...props, ...rest, className: unread || undefined, style: Object.keys(text).length ? { ...text, ...rest.style } : rest.style, children: children }));
91
+ shrink: 1, "aria-hidden": hidden === undefined ? undefined : hidden !== 'false' && hidden !== false, ...props, ...rest, className: tag ? undefined : unread || undefined, style: tag ? undefined : style, children: tag
92
+ ? (0, react_1.createElement)(tag, { ref, className: unread || undefined, style }, children)
93
+ : children }));
94
+ return frame;
65
95
  });
66
96
  exports.default = exports.Box;
package/dist/box.d.ts CHANGED
@@ -16,6 +16,20 @@
16
16
  * 77 of 225 elements on one page into flex containers that were never asked to
17
17
  * be: an inline run became a column, a heading's width collapsed to its text,
18
18
  * and a page grew 8% taller.
19
+ *
20
+ * `tag` renders the element Box is standing in for, and it is what makes the
21
+ * migration reach past `<div>`. Divs are about a third of what carries a
22
+ * className in these apps; the rest are `p`, `span`, `li`, `h2`, `section`, `a`.
23
+ * Converting those to a div-only Box would read as a rename and would in fact
24
+ * strip the document of its headings, lists and paragraphs — every one of them a
25
+ * thing a screen reader navigates by.
26
+ *
27
+ * It goes through `asChild` because gui does NOT honour a `tag` prop: asked for
28
+ * one it renders its own element anyway AND passes `tag` through to the DOM,
29
+ * where it is an invalid attribute. `asChild` is the supported way to say "style
30
+ * this element instead of yours", so the semantics come from the element and the
31
+ * styling still comes from gui — one substrate, not a second styling path for
32
+ * everything that is not a div.
19
33
  */
20
34
  import { type ReactNode } from 'react';
21
35
  import { YStack } from '@hanzo/gui';
@@ -23,6 +37,10 @@ import { type ClassValue } from './tw.js';
23
37
  export type BoxProps = Omit<React.ComponentProps<typeof YStack>, 'aria-hidden'> & {
24
38
  className?: ClassValue;
25
39
  children?: ReactNode;
40
+ /**
41
+ * The element to render. Omitted, Box is the `<div>` it has always been.
42
+ */
43
+ tag?: keyof React.JSX.IntrinsicElements;
26
44
  /**
27
45
  * ARIA states are strings in markup and gui types this one as a boolean, so
28
46
  * both spellings are taken and normalised. Rejecting `"true"` would make a
package/dist/box.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.tsx"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+18,45 @@ import { jsx as _jsx } from "react/jsx-runtime";
18
18
  * 77 of 225 elements on one page into flex containers that were never asked to
19
19
  * be: an inline run became a column, a heading's width collapsed to its text,
20
20
  * and a page grew 8% taller.
21
+ *
22
+ * `tag` renders the element Box is standing in for, and it is what makes the
23
+ * migration reach past `<div>`. Divs are about a third of what carries a
24
+ * className in these apps; the rest are `p`, `span`, `li`, `h2`, `section`, `a`.
25
+ * Converting those to a div-only Box would read as a rename and would in fact
26
+ * strip the document of its headings, lists and paragraphs — every one of them a
27
+ * thing a screen reader navigates by.
28
+ *
29
+ * It goes through `asChild` because gui does NOT honour a `tag` prop: asked for
30
+ * one it renders its own element anyway AND passes `tag` through to the DOM,
31
+ * where it is an invalid attribute. `asChild` is the supported way to say "style
32
+ * this element instead of yours", so the semantics come from the element and the
33
+ * styling still comes from gui — one substrate, not a second styling path for
34
+ * everything that is not a div.
21
35
  */
22
- import { forwardRef } from 'react';
36
+ import { createElement, forwardRef } from 'react';
23
37
  import { YStack } from '@hanzo/gui';
24
38
  import { tw } from './tw.js';
25
39
  /** Properties a frame ignores and a DOM element passes to its children. */
26
40
  const TEXT_PROPS = ['fontSize', 'lineHeight', 'fontWeight', 'letterSpacing',
27
41
  'textTransform', 'fontFamily', 'fontStyle', 'textAlign', 'color',
28
- 'textDecorationLine', 'whiteSpace'];
29
- export const Box = forwardRef(function Box({ className, children, 'aria-hidden': hidden, ...rest }, ref) {
42
+ 'textDecorationLine', 'whiteSpace',
43
+ // `tabular-nums` is the one class on a checkout that MUST survive: it is what
44
+ // makes a column of figures line up. tw converts it to fontVariantNumeric,
45
+ // which a frame drops like the rest of these, and the loss shows as a money
46
+ // column going ragged — a 25px total measuring 27px, which no test asserting
47
+ // on text would notice.
48
+ 'fontVariantNumeric'];
49
+ export const Box = forwardRef(function Box({ className, children, 'aria-hidden': hidden, tag, ...rest }, ref) {
30
50
  const { props, rest: unread } = tw(className);
31
51
  // A View pins `min-height: 0`; a div's is `auto`, and auto is what gives a
32
52
  // flex or grid child its automatic minimum size. Pinned, a converted child of
33
53
  // a row of indefinite height measured 0px and its content vanished.
34
54
  if (!('minHeight' in props))
35
55
  props.minHeight = 'auto';
56
+ // The same fact on the other axis. A View pins `min-width: 0`, a div's is
57
+ // auto, and auto is what stops a flex child shrinking below its content.
58
+ if (!('minWidth' in props))
59
+ props.minWidth = 'auto';
36
60
  // gui drops a text property set on a frame — `fontSize` is not a frame style
37
61
  // prop, so it silently rendered at the inherited size and a page carrying
38
62
  // `text-xs` on a box came out three pixels larger everywhere. A div DOES pass
@@ -49,16 +73,22 @@ export const Box = forwardRef(function Box({ className, children, 'aria-hidden':
49
73
  // class said otherwise, so `leading-relaxed` still wins.
50
74
  if (!('lineHeight' in text))
51
75
  text.lineHeight = 'inherit';
76
+ const style = Object.keys(text).length
77
+ ? { ...text, ...rest.style }
78
+ : rest.style;
52
79
  // Explicit props win: a caller who states a value directly means it, and the
53
80
  // classes are what they are migrating away from.
54
- return (_jsx(YStack, { ref: ref, display: "block",
81
+ const frame = (_jsx(YStack, { ref: tag ? undefined : ref, asChild: tag ? true : undefined, display: "block",
55
82
  // A View does not shrink; a div does. Left at the View's default, every
56
83
  // converted flex child held its full basis and overflowed its row instead
57
84
  // of sharing it — two half-width columns came out 608px each in a 1216px
58
85
  // row with a 32px gap, where the divs they replaced sat at 592.
59
86
  // `shrink`, not `flexShrink`: gui types the shorthand and compiles both to
60
87
  // the same `_shrink-1`, and the DOM spelling is the one it does not carry.
61
- shrink: 1, "aria-hidden": hidden === undefined ? undefined : hidden !== 'false' && hidden !== false, ...props, ...rest, className: unread || undefined, style: Object.keys(text).length ? { ...text, ...rest.style } : rest.style, children: children }));
88
+ shrink: 1, "aria-hidden": hidden === undefined ? undefined : hidden !== 'false' && hidden !== false, ...props, ...rest, className: tag ? undefined : unread || undefined, style: tag ? undefined : style, children: tag
89
+ ? createElement(tag, { ref, className: unread || undefined, style }, children)
90
+ : children }));
91
+ return frame;
62
92
  });
63
93
  export default Box;
64
94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