@tangle-network/ui 11.22.3 → 11.23.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tangle-network/ui
2
2
 
3
+ ## 11.23.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 57f4e3d: `Tag` takes `wrap` to break a long label across lines instead of truncating it, for text that must be read in full without a hover (model-written part names on a phone or on paper).
8
+
3
9
  ## 11.22.3
4
10
 
5
11
  ### Patch Changes
@@ -30,6 +30,12 @@ export interface TagProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, "c
30
30
  * the label is a string; pass it when the label is not plain text.
31
31
  */
32
32
  removeLabel?: string;
33
+ /**
34
+ * Wraps a long label onto more lines instead of truncating it. Use it where
35
+ * the full text matters and no hover is available to read a `title`, such
36
+ * as model-written part names read on a phone or on paper.
37
+ */
38
+ wrap?: boolean;
33
39
  }
34
40
  declare const Tag: React.ForwardRefExoticComponent<TagProps & React.RefAttributes<HTMLSpanElement>>;
35
41
  //#endregion
@@ -6,23 +6,38 @@ import { jsx, jsxs } from "react/jsx-runtime";
6
6
  import { X } from "lucide-react";
7
7
  //#region src/primitives/tag.tsx
8
8
  const SIZE = {
9
- sm: "h-6 gap-1 px-2 text-xs [&_svg]:size-3",
10
- md: "h-7 gap-1.5 px-2.5 text-sm [&_svg]:size-3.5"
9
+ sm: "gap-1 px-2 text-xs [&_svg]:size-3",
10
+ md: "gap-1.5 px-2.5 text-sm [&_svg]:size-3.5"
11
11
  };
12
- const Tag = React.forwardRef(({ className, children, tone = "neutral", emphasis = "soft", size = "sm", icon, onRemove, removeLabel, ...props }, ref) => {
12
+ const WRAP = {
13
+ sm: {
14
+ box: "items-start",
15
+ label: "py-[3px]",
16
+ icon: "h-[22px] items-center"
17
+ },
18
+ md: {
19
+ box: "items-start",
20
+ label: "py-[3px]",
21
+ icon: "h-[26px] items-center"
22
+ }
23
+ };
24
+ const Tag = React.forwardRef(({ className, children, tone = "neutral", emphasis = "soft", size = "sm", icon, onRemove, removeLabel, wrap = false, ...props }, ref) => {
13
25
  const classes = TONE_CLASSES[tone];
14
26
  const label = removeLabel ?? (typeof children === "string" ? `Remove ${children}` : "Remove");
15
27
  return /* @__PURE__ */ jsxs("span", {
16
28
  ref,
17
- className: cn("inline-flex min-w-0 max-w-full shrink-0 items-center rounded-md border font-medium", SIZE[size], emphasis === "outline" ? classes.outline : classes.surface, onRemove && (size === "sm" ? "pr-0.5" : "pr-1"), className),
29
+ className: cn("inline-flex min-w-0 max-w-full shrink-0 rounded-md border font-medium", SIZE[size], wrap ? WRAP[size].box : ["items-center", size === "sm" ? "h-6" : "h-7"], emphasis === "outline" ? classes.outline : classes.surface, onRemove && (size === "sm" ? "pr-0.5" : "pr-1"), className),
18
30
  ...props,
19
31
  children: [
20
32
  icon ? /* @__PURE__ */ jsx("span", {
21
33
  "aria-hidden": "true",
22
- className: cn("inline-flex shrink-0", classes.icon),
34
+ className: cn("inline-flex shrink-0", wrap && WRAP[size].icon, classes.icon),
23
35
  children: icon
24
36
  }) : null,
25
- /* @__PURE__ */ jsx("span", {
37
+ wrap ? /* @__PURE__ */ jsx("span", {
38
+ className: cn("min-w-0 [overflow-wrap:anywhere]", WRAP[size].label),
39
+ children
40
+ }) : /* @__PURE__ */ jsx("span", {
26
41
  className: "min-w-0 truncate",
27
42
  title: typeof children === "string" ? children : void 0,
28
43
  children
@@ -31,7 +46,7 @@ const Tag = React.forwardRef(({ className, children, tone = "neutral", emphasis
31
46
  type: "button",
32
47
  "aria-label": label,
33
48
  onClick: onRemove,
34
- className: cn("relative inline-flex shrink-0 items-center justify-center rounded-sm opacity-70 transition-[opacity,background-color] duration-150 ease-out hover:bg-[color-mix(in_srgb,currentColor_14%,transparent)] hover:opacity-100 before:absolute before:-inset-1.5 before:content-['']", size === "sm" ? "size-5" : "size-6", focusRing),
49
+ className: cn("relative inline-flex shrink-0 items-center justify-center rounded-sm opacity-70 transition-[opacity,background-color] duration-150 ease-out hover:bg-[color-mix(in_srgb,currentColor_14%,transparent)] hover:opacity-100 before:absolute before:-inset-1.5 before:content-['']", size === "sm" ? "size-5" : "size-6", wrap && "mt-px", focusRing),
35
50
  children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true" })
36
51
  }) : null
37
52
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/ui",
3
- "version": "11.22.3",
3
+ "version": "11.23.0",
4
4
  "description": "Generic React UI components for Tangle products — primitives, chat, run, files, editor, markdown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -124,6 +124,28 @@ describe("Tag", () => {
124
124
  });
125
125
  });
126
126
 
127
+ describe("Tag wrap", () => {
128
+ const LONG = "Adafruit-BME680-Temperature-Humidity-Pressure-Gas-Sensor-Breakout";
129
+
130
+ it("truncates a long label by default and names it in a title", () => {
131
+ render(<Tag>{LONG}</Tag>);
132
+ const label = screen.getByText(LONG);
133
+ expect(label.className).toContain("truncate");
134
+ expect(label.getAttribute("title")).toBe(LONG);
135
+ expect(label.parentElement?.className).toContain("h-6");
136
+ });
137
+
138
+ it("wraps a long label across lines when asked, aligned to its first line", () => {
139
+ render(<Tag wrap size="md">{LONG}</Tag>);
140
+ const label = screen.getByText(LONG);
141
+ expect(label.className).not.toContain("truncate");
142
+ expect(label.className).toContain("[overflow-wrap:anywhere]");
143
+ expect(label.className).toContain("py-[3px]");
144
+ expect(label.parentElement?.className).toContain("items-start");
145
+ expect(label.parentElement?.className).not.toMatch(/(^|\s)h-7(\s|$)/);
146
+ });
147
+ });
148
+
127
149
  describe("IconTile", () => {
128
150
  it("falls back from a broken image to the glyph, then to initials", () => {
129
151
  const { container, rerender } = render(<IconTile src="https://example.invalid/logo.png" name="Acme Robotics" />);
@@ -224,3 +224,27 @@ export const WorstCase: Story = {
224
224
  </BothThemes>
225
225
  ),
226
226
  };
227
+
228
+ const PART = "Adafruit-BME680-Temperature-Humidity-Pressure-Gas-Sensor-Breakout";
229
+
230
+ /** `wrap` keeps the whole label readable: one line matches a fixed tag's height; more lines grow it, with the icon and remove button on the first line. */
231
+ export const Wrap: Story = {
232
+ render: () => (
233
+ <BothThemes>
234
+ <div className="flex w-full max-w-[220px] flex-col items-start gap-2" data-testid="wrap-column">
235
+ {(["sm", "md"] as const).map((size) => (
236
+ <div key={size} className="flex flex-col items-start gap-2">
237
+ <div className="flex items-start gap-2">
238
+ <Tag size={size} data-probe={`fixed-${size}`}>Short</Tag>
239
+ <Tag size={size} wrap data-probe={`wrap-one-${size}`}>Short</Tag>
240
+ <Tag size={size} wrap onRemove={() => {}} data-probe={`wrap-remove-${size}`}>Short</Tag>
241
+ </div>
242
+ <Tag size={size} wrap tone="teal" icon={<FileText />} onRemove={() => {}} data-probe={`wrap-long-${size}`}>
243
+ {PART}
244
+ </Tag>
245
+ </div>
246
+ ))}
247
+ </div>
248
+ </BothThemes>
249
+ ),
250
+ };
@@ -33,16 +33,31 @@ export interface TagProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, "c
33
33
  * the label is a string; pass it when the label is not plain text.
34
34
  */
35
35
  removeLabel?: string;
36
+ /**
37
+ * Wraps a long label onto more lines instead of truncating it. Use it where
38
+ * the full text matters and no hover is available to read a `title`, such
39
+ * as model-written part names read on a phone or on paper.
40
+ */
41
+ wrap?: boolean;
36
42
  }
37
43
 
38
44
  const SIZE = {
39
- sm: "h-6 gap-1 px-2 text-xs [&_svg]:size-3",
40
- md: "h-7 gap-1.5 px-2.5 text-sm [&_svg]:size-3.5",
45
+ sm: "gap-1 px-2 text-xs [&_svg]:size-3",
46
+ md: "gap-1.5 px-2.5 text-sm [&_svg]:size-3.5",
47
+ } as const;
48
+
49
+ // A truncating tag has one fixed height. A wrapping tag carries its vertical
50
+ // padding on the label instead, sized so one line is exactly that height
51
+ // (sm: 16px line + 6 + 2px border = 24; md: 20 + 6 + 2 = 28), and aligns the
52
+ // icon and remove button to the first line rather than the middle.
53
+ const WRAP = {
54
+ sm: { box: "items-start", label: "py-[3px]", icon: "h-[22px] items-center" },
55
+ md: { box: "items-start", label: "py-[3px]", icon: "h-[26px] items-center" },
41
56
  } as const;
42
57
 
43
58
  const Tag = React.forwardRef<HTMLSpanElement, TagProps>(
44
59
  (
45
- { className, children, tone = "neutral", emphasis = "soft", size = "sm", icon, onRemove, removeLabel, ...props },
60
+ { className, children, tone = "neutral", emphasis = "soft", size = "sm", icon, onRemove, removeLabel, wrap = false, ...props },
46
61
  ref,
47
62
  ) => {
48
63
  const classes = TONE_CLASSES[tone];
@@ -51,8 +66,9 @@ const Tag = React.forwardRef<HTMLSpanElement, TagProps>(
51
66
  <span
52
67
  ref={ref}
53
68
  className={cn(
54
- "inline-flex min-w-0 max-w-full shrink-0 items-center rounded-md border font-medium",
69
+ "inline-flex min-w-0 max-w-full shrink-0 rounded-md border font-medium",
55
70
  SIZE[size],
71
+ wrap ? WRAP[size].box : ["items-center", size === "sm" ? "h-6" : "h-7"],
56
72
  emphasis === "outline" ? classes.outline : classes.surface,
57
73
  onRemove && (size === "sm" ? "pr-0.5" : "pr-1"),
58
74
  className,
@@ -60,15 +76,20 @@ const Tag = React.forwardRef<HTMLSpanElement, TagProps>(
60
76
  {...props}
61
77
  >
62
78
  {icon ? (
63
- <span aria-hidden="true" className={cn("inline-flex shrink-0", classes.icon)}>
79
+ <span aria-hidden="true" className={cn("inline-flex shrink-0", wrap && WRAP[size].icon, classes.icon)}>
64
80
  {icon}
65
81
  </span>
66
82
  ) : null}
67
- {/* A long label truncates here rather than pushing the remove button
68
- out; the title gives its full text on hover. */}
69
- <span className="min-w-0 truncate" title={typeof children === "string" ? children : undefined}>
70
- {children}
71
- </span>
83
+ {/* By default a long label truncates here rather than pushing the
84
+ remove button out, and the title gives its full text on hover.
85
+ `wrap` breaks it across lines instead, even inside one long token. */}
86
+ {wrap ? (
87
+ <span className={cn("min-w-0 [overflow-wrap:anywhere]", WRAP[size].label)}>{children}</span>
88
+ ) : (
89
+ <span className="min-w-0 truncate" title={typeof children === "string" ? children : undefined}>
90
+ {children}
91
+ </span>
92
+ )}
72
93
  {onRemove ? (
73
94
  <button
74
95
  type="button"
@@ -79,6 +100,8 @@ const Tag = React.forwardRef<HTMLSpanElement, TagProps>(
79
100
  // the hit area without moving the tag's layout.
80
101
  "relative inline-flex shrink-0 items-center justify-center rounded-sm opacity-70 transition-[opacity,background-color] duration-150 ease-out hover:bg-[color-mix(in_srgb,currentColor_14%,transparent)] hover:opacity-100 before:absolute before:-inset-1.5 before:content-['']",
81
102
  size === "sm" ? "size-5" : "size-6",
103
+ // Centred on the first line box (22px sm, 26px md) when wrapping.
104
+ wrap && "mt-px",
82
105
  focusRing,
83
106
  )}
84
107
  >