@stackone/malachite 2.130.0 → 2.131.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.
@@ -1,11 +1,12 @@
1
- import { jsx as n, jsxs as W } from "react/jsx-runtime";
2
- import { useRef as C, useState as A, useCallback as B } from "react";
3
- import U from "./CustomIcons/DismissIcon.js";
4
- import { FOCUS_RING as E } from "./focusRing.js";
5
- import { activateOnEnterOrSpace as G } from "./keyboardActivation.js";
1
+ import { jsx as s, jsxs as B } from "react/jsx-runtime";
2
+ import { useRef as N, useState as U, useCallback as E } from "react";
3
+ import G from "./CustomIcons/DismissIcon.js";
6
4
  import P from "./Tooltip.js";
7
5
  import { getTextColor as _ } from "./Typography/textStyles.js";
8
- const q = (e) => {
6
+ import { VisuallyHidden as q } from "./VisuallyHidden.js";
7
+ import { FOCUS_RING as H } from "./focusRing.js";
8
+ import { activateOnEnterOrSpace as K } from "./keyboardActivation.js";
9
+ const V = (e) => {
9
10
  switch (e) {
10
11
  case "xsmall":
11
12
  return "text-[length:var(--malachite-font-size-xsmall)]";
@@ -16,7 +17,7 @@ const q = (e) => {
16
17
  default:
17
18
  return "text-xs";
18
19
  }
19
- }, K = (e) => {
20
+ }, J = (e) => {
20
21
  switch (e) {
21
22
  case "large":
22
23
  return "w-[88px]";
@@ -29,10 +30,10 @@ const q = (e) => {
29
30
  default:
30
31
  return "w-fit";
31
32
  }
32
- }, H = (e) => e === "compact" ? "px-[6px] py-[1px]" : "px-2 py-1", J = (e) => ({
33
+ }, L = (e) => e === "compact" ? "px-[6px] py-[1px]" : "px-2 py-1", M = (e) => ({
33
34
  borderRadius: e === "compact" ? "var(--malachite-radius-md)" : "var(--malachite-radius-lg)"
34
- }), M = (e, c, a) => {
35
- const i = `inline-flex items-center justify-center ${H(c)} ${q(a)} font-medium leading-normal tracking-[0.11px]`, s = {
35
+ }), Q = (e, o, a) => {
36
+ const i = `inline-flex items-center justify-center ${L(o)} ${V(a)} font-medium leading-normal tracking-[0.11px]`, n = {
36
37
  primary: {
37
38
  text: "text-[var(--malachite-tag-primary-foreground)]"
38
39
  },
@@ -61,90 +62,99 @@ const q = (e) => {
61
62
  text: "text-[var(--malachite-tag-assistant-foreground)]"
62
63
  }
63
64
  }[e];
64
- return [i, s.text].filter(Boolean).join(" ");
65
- }, Q = "var(--malachite-ctx-tag-ground, transparent)", V = "var(--malachite-ctx-tag-cursor, default)", X = (e, c, a, i) => {
66
- const r = `var(--malachite-tag-${e}-background)`, s = {
67
- ...J(i),
68
- backgroundColor: Q,
65
+ return [i, n.text].filter(Boolean).join(" ");
66
+ }, X = "var(--malachite-ctx-tag-ground, transparent)", Y = "var(--malachite-ctx-tag-cursor, default)", Z = (e, o, a, i) => {
67
+ const r = `var(--malachite-tag-${e}-background)`, n = {
68
+ ...M(i),
69
+ backgroundColor: X,
69
70
  backgroundImage: `linear-gradient(${r}, ${r})`
70
71
  };
71
- return c && (s.border = `2px solid var(--malachite-tag-${e}-border)`), e === "emphasis" ? s.boxShadow = "0px 0px 10px 0px var(--malachite-tag-emphasis-shadow)" : a && (s.boxShadow = `0 10px 15px -3px var(--malachite-tag-${e}-shadow)`), s;
72
- }, Y = (e, c) => {
73
- const a = new ResizeObserver(c);
72
+ return o && (n.border = `2px solid var(--malachite-tag-${e}-border)`), e === "emphasis" ? n.boxShadow = "0px 0px 10px 0px var(--malachite-tag-emphasis-shadow)" : a && (n.boxShadow = `0 10px 15px -3px var(--malachite-tag-${e}-shadow)`), n;
73
+ }, ee = (e, o) => {
74
+ const a = new ResizeObserver(o);
74
75
  return a.observe(e), a;
75
- }, ce = ({
76
+ }, le = ({
76
77
  value: e,
77
- fontSize: c,
78
+ fontSize: o,
78
79
  type: a = "default",
79
80
  bordered: i = !1,
80
81
  onClick: r,
81
- shadow: s = !1,
82
- textTransform: x = "uppercase",
83
- width: N,
84
- paddingSize: p = "default",
85
- icon: l,
86
- iconPosition: g = "left",
87
- iconColor: h,
88
- pointerType: u,
89
- onRemove: d,
82
+ shadow: n = !1,
83
+ textTransform: p = "uppercase",
84
+ width: z,
85
+ paddingSize: g = "default",
86
+ icon: u,
87
+ iconPosition: h = "left",
88
+ iconColor: b,
89
+ pointerType: d,
90
+ onRemove: f,
90
91
  tooltip: m,
91
- tooltipDescribesTag: z = !0,
92
- className: O = ""
92
+ tooltipDescribesTag: O = !0,
93
+ "aria-label": l,
94
+ className: T = ""
93
95
  }) => {
94
- const b = h ? { color: _(h) } : void 0, f = C(null), o = C(null), [T, j] = A(!1), v = typeof e == "string" || typeof e == "number", I = B((t) => {
95
- var S;
96
- if ((S = f.current) == null || S.disconnect(), f.current = null, o.current !== null && (cancelAnimationFrame(o.current), o.current = null), !t || typeof ResizeObserver > "u")
96
+ const v = b ? { color: _(b) } : void 0, x = N(null), c = N(null), [j, I] = U(!1), y = typeof e == "string" || typeof e == "number", k = E((t) => {
97
+ var R;
98
+ if ((R = x.current) == null || R.disconnect(), x.current = null, c.current !== null && (cancelAnimationFrame(c.current), c.current = null), !t || typeof ResizeObserver > "u")
97
99
  return;
98
- const L = () => {
99
- o.current = null, t.clientWidth !== 0 && j((R) => {
100
- const $ = t.scrollWidth > t.clientWidth;
101
- return R === $ ? R : $;
100
+ const A = () => {
101
+ c.current = null, t.clientWidth !== 0 && I(($) => {
102
+ const C = t.scrollWidth > t.clientWidth;
103
+ return $ === C ? $ : C;
102
104
  });
103
- }, w = () => {
104
- o.current === null && (o.current = requestAnimationFrame(L));
105
+ }, S = () => {
106
+ c.current === null && (c.current = requestAnimationFrame(A));
105
107
  };
106
- w(), f.current = Y(t, w);
107
- }, []), k = (t) => {
108
+ S(), x.current = ee(t, S);
109
+ }, []), D = (t) => {
108
110
  r && (t.stopPropagation(), t.preventDefault(), r());
109
- }, D = [
110
- K(N),
111
- M(a, p, c),
112
- x === "uppercase" ? "uppercase" : "normal-case",
113
- r ? `cursor-pointer ${E}` : u ? `cursor-${u}` : "",
114
- v ? "min-w-0 max-w-full" : "",
115
- O
116
- ].filter(Boolean).join(" "), F = {
117
- ...X(a, i, s, p),
118
- ...!r && !u && { cursor: V }
119
- }, y = /* @__PURE__ */ W(
111
+ }, F = [
112
+ J(z),
113
+ Q(a, g, o),
114
+ p === "uppercase" ? "uppercase" : "normal-case",
115
+ r ? `cursor-pointer ${H}` : d ? `cursor-${d}` : "",
116
+ y ? "min-w-0 max-w-full" : "",
117
+ T
118
+ ].filter(Boolean).join(" "), W = {
119
+ ...Z(a, i, n, g),
120
+ ...!r && !d && { cursor: Y }
121
+ }, w = /* @__PURE__ */ B(
120
122
  "span",
121
123
  {
122
- className: D,
123
- onClick: k,
124
- role: r && !d ? "button" : void 0,
124
+ className: F,
125
+ onClick: D,
126
+ role: r && !f ? "button" : void 0,
125
127
  tabIndex: r ? 0 : void 0,
126
- onKeyDown: r ? (t) => G(t, r) : void 0,
127
- style: F,
128
+ onKeyDown: r ? (t) => K(t, r) : void 0,
129
+ style: W,
128
130
  children: [
129
- l && g === "left" && /* @__PURE__ */ n("span", { className: "mr-1 flex items-center", style: b, children: l }),
130
- v ? /* @__PURE__ */ n("span", { className: "flex items-center min-w-0", children: /* @__PURE__ */ n("span", { ref: I, className: "block min-w-0 truncate", children: e }, String(e)) }) : /* @__PURE__ */ n("span", { className: "flex items-center", children: e }),
131
- l && g === "right" && /* @__PURE__ */ n("span", { className: "ml-1 flex items-center", style: b, children: l }),
132
- d && /* @__PURE__ */ n(
131
+ u && h === "left" && /* @__PURE__ */ s("span", { className: "mr-1 flex items-center", style: v, children: u }),
132
+ y ? /* @__PURE__ */ s(
133
+ "span",
134
+ {
135
+ className: "flex items-center min-w-0",
136
+ "aria-hidden": l ? !0 : void 0,
137
+ children: /* @__PURE__ */ s("span", { ref: k, className: "block min-w-0 truncate", children: e }, String(e))
138
+ }
139
+ ) : /* @__PURE__ */ s("span", { className: "flex items-center", "aria-hidden": l ? !0 : void 0, children: e }),
140
+ l && /* @__PURE__ */ s(q, { children: l }),
141
+ u && h === "right" && /* @__PURE__ */ s("span", { className: "ml-1 flex items-center", style: v, children: u }),
142
+ f && /* @__PURE__ */ s(
133
143
  "button",
134
144
  {
135
145
  type: "button",
136
- "aria-label": `Remove ${typeof e == "string" ? e : ""}`,
146
+ "aria-label": `Remove ${l ?? (typeof e == "string" ? e : "")}`,
137
147
  onClick: (t) => {
138
- t.stopPropagation(), d(t);
148
+ t.stopPropagation(), f(t);
139
149
  },
140
150
  className: "ml-0.5 flex items-center justify-center shrink-0 border-none bg-transparent text-current cursor-pointer p-0 leading-none opacity-70 hover:opacity-100",
141
- children: /* @__PURE__ */ n(U, { size: 9 })
151
+ children: /* @__PURE__ */ s(G, { size: 9 })
142
152
  }
143
153
  )
144
154
  ]
145
155
  }
146
156
  );
147
- return !m && !T ? y : /* @__PURE__ */ n(
157
+ return !m && !j ? w : /* @__PURE__ */ s(
148
158
  P,
149
159
  {
150
160
  text: m ?? e,
@@ -152,14 +162,14 @@ const q = (e) => {
152
162
  wrapChildren: !1,
153
163
  isShrinkable: !0,
154
164
  inline: m !== void 0,
155
- describesTrigger: m === void 0 || z,
165
+ describesTrigger: m === void 0 || O,
156
166
  triggerAs: "span",
157
- children: y
167
+ children: w
158
168
  }
159
169
  );
160
170
  };
161
171
  export {
162
- ce as Tag,
163
- ce as default
172
+ le as Tag,
173
+ le as default
164
174
  };
165
175
  //# sourceMappingURL=Tag.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tag.js","sources":["../../src/components/Tag.tsx"],"sourcesContent":["import React, { useCallback, useRef, useState } from 'react';\nimport DismissIcon from './CustomIcons/DismissIcon';\nimport { FOCUS_RING } from './focusRing';\nimport { activateOnEnterOrSpace } from './keyboardActivation';\nimport Tooltip from './Tooltip';\nimport type { TextColor } from './Typography/Text';\nimport { getTextColor } from './Typography/textStyles';\n\nexport type TagType =\n | 'primary'\n | 'secondary'\n | 'default'\n | 'error'\n | 'warning'\n | 'success'\n | 'emphasis'\n | 'info'\n /** Marks content a machine produced rather than a person — provenance, not severity. */\n | 'assistant';\n\nexport type WidthSize = 'large' | 'medium' | 'small' | 'xsmall';\n\nexport type PaddingSize = 'default' | 'compact';\n\ntype TagFontSize = 'xsmall' | 'small' | 'medium';\n\ninterface TagProps {\n value: string | number | React.ReactNode;\n /** Defaults to 12px. Use `xsmall` for a secondary badge beside a primary one. */\n fontSize?: TagFontSize;\n type?: TagType;\n bordered?: boolean;\n shadow?: boolean;\n textTransform?: 'none' | 'uppercase';\n width?: WidthSize;\n paddingSize?: PaddingSize;\n icon?: React.ReactNode;\n iconPosition?: 'left' | 'right';\n iconColor?: TextColor;\n /** The cursor over a tag that is not clickable. Unset, it is whatever an ancestor sets\n * through `--malachite-ctx-tag-cursor` (a `NavItem` row sets its pointer), else the arrow. */\n pointerType?: 'pointer' | 'default';\n /** Makes it a button, unless `onRemove` is set; keep `value` and `icon` non-interactive. */\n onClick?: () => void;\n onRemove?: (e: React.MouseEvent) => void;\n /** Explains the tag on hover. Takes the place of the truncation tooltip, which only repeats\n * the label. */\n tooltip?: string;\n /** False when something else already reads `tooltip` to assistive tech, such as a card's\n * description, so it is not announced twice. */\n tooltipDescribesTag?: boolean;\n className?: string;\n}\n\nconst getFontSizeClass = (fontSize?: TagFontSize): string => {\n switch (fontSize) {\n case 'xsmall':\n return 'text-[length:var(--malachite-font-size-xsmall)]';\n case 'small':\n return 'text-[length:var(--malachite-font-size-small)]';\n case 'medium':\n return 'text-[length:var(--malachite-font-size-medium)]';\n default:\n return 'text-xs';\n }\n};\n\nconst getWidthClasses = (width?: WidthSize): string => {\n switch (width) {\n case 'large':\n return 'w-[88px]';\n case 'medium':\n return 'w-[44px]';\n case 'small':\n return 'w-[24px]';\n case 'xsmall':\n return 'w-[20px]';\n default:\n return 'w-fit';\n }\n};\n\nconst getPaddingClasses = (paddingSize?: PaddingSize): string => {\n return paddingSize === 'compact' ? 'px-[6px] py-[1px]' : 'px-2 py-1';\n};\n\nconst getBorderRadiusClasses = (paddingSize?: PaddingSize): React.CSSProperties => {\n return {\n borderRadius:\n paddingSize === 'compact' ? 'var(--malachite-radius-md)' : 'var(--malachite-radius-lg)',\n };\n};\n\nconst getTypeClasses = (\n type: TagType,\n paddingSize?: PaddingSize,\n fontSize?: TagFontSize,\n) => {\n const baseClasses = `inline-flex items-center justify-center ${getPaddingClasses(paddingSize)} ${getFontSizeClass(fontSize)} font-medium leading-normal tracking-[0.11px]`;\n\n const typeStyles = {\n primary: {\n text: 'text-[var(--malachite-tag-primary-foreground)]',\n },\n secondary: {\n text: 'text-[var(--malachite-tag-secondary-foreground)]',\n },\n default: {\n text: 'text-[var(--malachite-tag-default-foreground)]',\n },\n error: {\n text: 'text-[var(--malachite-tag-error-foreground)]',\n },\n warning: {\n text: 'text-[var(--malachite-tag-warning-foreground)]',\n },\n success: {\n text: 'text-[var(--malachite-tag-success-foreground)]',\n },\n emphasis: {\n text: 'text-[var(--malachite-tag-emphasis-foreground)]',\n },\n info: {\n text: 'text-[var(--malachite-tag-info-foreground)]',\n },\n assistant: {\n text: 'text-[var(--malachite-tag-assistant-foreground)]',\n },\n };\n\n const style = typeStyles[type];\n const classes = [baseClasses, style.text].filter(Boolean);\n\n return classes.join(' ');\n};\n\n/*\n * Context channels, not theme tokens: no palette value, not settable through `applyTheme`,\n * absent from `getCurrentTheme`. The ground goes under the tint, which is translucent and on\n * its own takes the colour of whatever is behind the tag, a row's hover or current tint included.\n */\nconst GROUND = 'var(--malachite-ctx-tag-ground, transparent)';\nconst IDLE_CURSOR = 'var(--malachite-ctx-tag-cursor, default)';\n\nconst getTypeStyles = (\n type: TagType,\n bordered?: boolean,\n shadow?: boolean,\n paddingSize?: PaddingSize,\n): React.CSSProperties => {\n const tint = `var(--malachite-tag-${type}-background)`;\n const styles: React.CSSProperties = {\n ...getBorderRadiusClasses(paddingSize),\n backgroundColor: GROUND,\n backgroundImage: `linear-gradient(${tint}, ${tint})`,\n };\n\n if (bordered) {\n styles.border = `2px solid var(--malachite-tag-${type}-border)`;\n }\n\n if (type === 'emphasis') {\n styles.boxShadow = '0px 0px 10px 0px var(--malachite-tag-emphasis-shadow)';\n } else if (shadow) {\n styles.boxShadow = `0 10px 15px -3px var(--malachite-tag-${type}-shadow)`;\n }\n\n return styles;\n};\n\nconst observeLabelSize = (el: HTMLSpanElement, onResize: () => void): ResizeObserver => {\n const observer = new ResizeObserver(onResize);\n observer.observe(el);\n return observer;\n};\n\nconst Tag: React.FC<TagProps> = ({\n value,\n fontSize,\n type = 'default',\n bordered = false,\n onClick,\n shadow = false,\n textTransform = 'uppercase',\n width,\n paddingSize = 'default',\n icon,\n iconPosition = 'left',\n iconColor,\n pointerType,\n onRemove,\n tooltip,\n tooltipDescribesTag = true,\n className = '',\n}) => {\n const iconColorStyle = iconColor ? { color: getTextColor(iconColor) } : undefined;\n const observerRef = useRef<ResizeObserver | null>(null);\n const frameRef = useRef<number | null>(null);\n const [isTruncated, setIsTruncated] = useState(false);\n\n // Truncation applies to plain text labels; ReactNode values render untouched.\n const isTextLabel = typeof value === 'string' || typeof value === 'number';\n\n // Memoized so the ref keeps a stable identity. An inline ref callback would be\n // re-invoked (null, then the node) on every render, tearing down and recreating\n // the ResizeObserver each time; this way it only runs on mount/unmount.\n const setLabelRef = useCallback((el: HTMLSpanElement | null) => {\n observerRef.current?.disconnect();\n observerRef.current = null;\n if (frameRef.current !== null) {\n cancelAnimationFrame(frameRef.current);\n frameRef.current = null;\n }\n if (!el || typeof ResizeObserver === 'undefined') {\n return;\n }\n const measure = (): void => {\n frameRef.current = null;\n if (el.clientWidth === 0) {\n return;\n }\n setIsTruncated((prev) => {\n const next = el.scrollWidth > el.clientWidth;\n return prev === next ? prev : next;\n });\n };\n const check = (): void => {\n if (frameRef.current !== null) {\n return;\n }\n frameRef.current = requestAnimationFrame(measure);\n };\n check();\n observerRef.current = observeLabelSize(el, check);\n }, []);\n\n const handleClick = (e: React.MouseEvent) => {\n if (onClick) {\n e.stopPropagation();\n e.preventDefault();\n onClick();\n }\n };\n\n const baseClasses = [\n getWidthClasses(width),\n getTypeClasses(type, paddingSize, fontSize),\n textTransform === 'uppercase' ? 'uppercase' : 'normal-case',\n onClick ? `cursor-pointer ${FOCUS_RING}` : pointerType ? `cursor-${pointerType}` : '',\n isTextLabel ? 'min-w-0 max-w-full' : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const typeStyles = {\n ...getTypeStyles(type, bordered, shadow, paddingSize),\n ...(!onClick && !pointerType && { cursor: IDLE_CURSOR }),\n };\n\n const tag = (\n <span\n className={baseClasses}\n onClick={handleClick}\n // Not with `onRemove`: the role would hide its close button from assistive tech.\n role={onClick && !onRemove ? 'button' : undefined}\n tabIndex={onClick ? 0 : undefined}\n onKeyDown={onClick ? (event) => activateOnEnterOrSpace(event, onClick) : undefined}\n style={typeStyles}\n >\n {icon && iconPosition === 'left' && (\n <span className=\"mr-1 flex items-center\" style={iconColorStyle}>\n {icon}\n </span>\n )}\n {isTextLabel ? (\n <span className=\"flex items-center min-w-0\">\n <span key={String(value)} ref={setLabelRef} className=\"block min-w-0 truncate\">\n {value}\n </span>\n </span>\n ) : (\n <span className=\"flex items-center\">{value}</span>\n )}\n {icon && iconPosition === 'right' && (\n <span className=\"ml-1 flex items-center\" style={iconColorStyle}>\n {icon}\n </span>\n )}\n {onRemove && (\n <button\n type=\"button\"\n aria-label={`Remove ${typeof value === 'string' ? value : ''}`}\n onClick={(e) => {\n e.stopPropagation();\n onRemove(e);\n }}\n className=\"ml-0.5 flex items-center justify-center shrink-0 border-none bg-transparent text-current cursor-pointer p-0 leading-none opacity-70 hover:opacity-100\"\n >\n {/* A bare cross, not `CloseIcon`'s circled one: this sits inside the chip\n it removes, where a second enclosing ring reads as an object of its own\n rather than as part of the label. */}\n <DismissIcon size={9} />\n </button>\n )}\n </span>\n );\n\n if (!tooltip && !isTruncated) {\n return tag;\n }\n\n return (\n <Tooltip\n text={tooltip ?? value}\n placement=\"top\"\n wrapChildren={false}\n isShrinkable\n inline={tooltip !== undefined}\n describesTrigger={tooltip === undefined || tooltipDescribesTag}\n triggerAs=\"span\"\n >\n {tag}\n </Tooltip>\n );\n};\n\nexport default Tag;\nexport { Tag };\nexport type { TagProps };\n"],"names":["getFontSizeClass","fontSize","getWidthClasses","width","getPaddingClasses","paddingSize","getBorderRadiusClasses","getTypeClasses","type","baseClasses","style","GROUND","IDLE_CURSOR","getTypeStyles","bordered","shadow","tint","styles","observeLabelSize","el","onResize","observer","Tag","value","onClick","textTransform","icon","iconPosition","iconColor","pointerType","onRemove","tooltip","tooltipDescribesTag","className","iconColorStyle","getTextColor","observerRef","useRef","frameRef","isTruncated","setIsTruncated","useState","isTextLabel","setLabelRef","useCallback","_a","measure","prev","next","check","handleClick","e","FOCUS_RING","typeStyles","tag","jsxs","event","activateOnEnterOrSpace","jsx","DismissIcon","Tooltip"],"mappings":";;;;;;;AAsDA,MAAMA,IAAmB,CAACC,MAAmC;AACzD,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAkB,CAACC,MAA8B;AACnD,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAoB,CAACC,MAChBA,MAAgB,YAAY,sBAAsB,aAGvDC,IAAyB,CAACD,OACrB;AAAA,EACH,cACIA,MAAgB,YAAY,+BAA+B;AAAA,IAIjEE,IAAiB,CACnBC,GACAH,GACAJ,MACC;AACD,QAAMQ,IAAc,2CAA2CL,EAAkBC,CAAW,CAAC,IAAIL,EAAiBC,CAAQ,CAAC,iDAgCrHS,IA9Ba;AAAA,IACf,SAAS;AAAA,MACL,MAAM;AAAA,IAAA;AAAA,IAEV,WAAW;AAAA,MACP,MAAM;AAAA,IAAA;AAAA,IAEV,SAAS;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AAA,IAAA;AAAA,EAAA;AAKZ,SAAI,CAAC5B,KAAW,CAACQ,IACNe,IAIP,gBAAAI;AAAA,IAACE;AAAA,IAAA;AAAA,MACG,MAAM7B,KAAWR;AAAA,MACjB,WAAU;AAAA,MACV,cAAc;AAAA,MACd,cAAY;AAAA,MACZ,QAAQQ,MAAY;AAAA,MACpB,kBAAkBA,MAAY,UAAaC;AAAA,MAC3C,WAAU;AAAA,MAET,UAAAsB;AAAA,IAAA;AAAA,EAAA;AAGb;"}
1
+ {"version":3,"file":"Tag.js","sources":["../../src/components/Tag.tsx"],"sourcesContent":["import React, { useCallback, useRef, useState } from 'react';\nimport DismissIcon from './CustomIcons/DismissIcon';\nimport Tooltip from './Tooltip';\nimport type { TextColor } from './Typography/Text';\nimport { getTextColor } from './Typography/textStyles';\nimport VisuallyHidden from './VisuallyHidden';\nimport { FOCUS_RING } from './focusRing';\nimport { activateOnEnterOrSpace } from './keyboardActivation';\n\nexport type TagType =\n | 'primary'\n | 'secondary'\n | 'default'\n | 'error'\n | 'warning'\n | 'success'\n | 'emphasis'\n | 'info'\n /** Marks content a machine produced rather than a person — provenance, not severity. */\n | 'assistant';\n\nexport type WidthSize = 'large' | 'medium' | 'small' | 'xsmall';\n\nexport type PaddingSize = 'default' | 'compact';\n\ntype TagFontSize = 'xsmall' | 'small' | 'medium';\n\ninterface TagProps {\n value: string | number | React.ReactNode;\n /** Defaults to 12px. Use `xsmall` for a secondary badge beside a primary one. */\n fontSize?: TagFontSize;\n type?: TagType;\n bordered?: boolean;\n shadow?: boolean;\n textTransform?: 'none' | 'uppercase';\n width?: WidthSize;\n paddingSize?: PaddingSize;\n icon?: React.ReactNode;\n iconPosition?: 'left' | 'right';\n iconColor?: TextColor;\n /** The cursor over a tag that is not clickable. Unset, it is whatever an ancestor sets\n * through `--malachite-ctx-tag-cursor` (a `NavItem` row sets its pointer), else the arrow. */\n pointerType?: 'pointer' | 'default';\n /** Makes it a button, unless `onRemove` is set; keep `value` and `icon` non-interactive. */\n onClick?: () => void;\n onRemove?: (e: React.MouseEvent) => void;\n /** Explains the tag on hover. Takes the place of the truncation tooltip, which only repeats\n * the label. */\n tooltip?: string;\n /** False when something else already reads `tooltip` to assistive tech, such as a card's\n * description, so it is not announced twice. */\n tooltipDescribesTag?: boolean;\n /**\n * What assistive tech reads in place of the visible value, such as \"Severity: high\" for a\n * tag showing \"High\". Rendered as visually hidden text, since `aria-label` on a plain span is\n * not honoured. Also names the remove button.\n */\n 'aria-label'?: string;\n className?: string;\n}\n\nconst getFontSizeClass = (fontSize?: TagFontSize): string => {\n switch (fontSize) {\n case 'xsmall':\n return 'text-[length:var(--malachite-font-size-xsmall)]';\n case 'small':\n return 'text-[length:var(--malachite-font-size-small)]';\n case 'medium':\n return 'text-[length:var(--malachite-font-size-medium)]';\n default:\n return 'text-xs';\n }\n};\n\nconst getWidthClasses = (width?: WidthSize): string => {\n switch (width) {\n case 'large':\n return 'w-[88px]';\n case 'medium':\n return 'w-[44px]';\n case 'small':\n return 'w-[24px]';\n case 'xsmall':\n return 'w-[20px]';\n default:\n return 'w-fit';\n }\n};\n\nconst getPaddingClasses = (paddingSize?: PaddingSize): string => {\n return paddingSize === 'compact' ? 'px-[6px] py-[1px]' : 'px-2 py-1';\n};\n\nconst getBorderRadiusClasses = (paddingSize?: PaddingSize): React.CSSProperties => {\n return {\n borderRadius:\n paddingSize === 'compact' ? 'var(--malachite-radius-md)' : 'var(--malachite-radius-lg)',\n };\n};\n\nconst getTypeClasses = (type: TagType, paddingSize?: PaddingSize, fontSize?: TagFontSize) => {\n const baseClasses = `inline-flex items-center justify-center ${getPaddingClasses(paddingSize)} ${getFontSizeClass(fontSize)} font-medium leading-normal tracking-[0.11px]`;\n\n const typeStyles = {\n primary: {\n text: 'text-[var(--malachite-tag-primary-foreground)]',\n },\n secondary: {\n text: 'text-[var(--malachite-tag-secondary-foreground)]',\n },\n default: {\n text: 'text-[var(--malachite-tag-default-foreground)]',\n },\n error: {\n text: 'text-[var(--malachite-tag-error-foreground)]',\n },\n warning: {\n text: 'text-[var(--malachite-tag-warning-foreground)]',\n },\n success: {\n text: 'text-[var(--malachite-tag-success-foreground)]',\n },\n emphasis: {\n text: 'text-[var(--malachite-tag-emphasis-foreground)]',\n },\n info: {\n text: 'text-[var(--malachite-tag-info-foreground)]',\n },\n assistant: {\n text: 'text-[var(--malachite-tag-assistant-foreground)]',\n },\n };\n\n const style = typeStyles[type];\n const classes = [baseClasses, style.text].filter(Boolean);\n\n return classes.join(' ');\n};\n\n/*\n * Context channels, not theme tokens: no palette value, not settable through `applyTheme`,\n * absent from `getCurrentTheme`. The ground goes under the tint, which is translucent and on\n * its own takes the colour of whatever is behind the tag, a row's hover or current tint included.\n */\nconst GROUND = 'var(--malachite-ctx-tag-ground, transparent)';\nconst IDLE_CURSOR = 'var(--malachite-ctx-tag-cursor, default)';\n\nconst getTypeStyles = (\n type: TagType,\n bordered?: boolean,\n shadow?: boolean,\n paddingSize?: PaddingSize,\n): React.CSSProperties => {\n const tint = `var(--malachite-tag-${type}-background)`;\n const styles: React.CSSProperties = {\n ...getBorderRadiusClasses(paddingSize),\n backgroundColor: GROUND,\n backgroundImage: `linear-gradient(${tint}, ${tint})`,\n };\n\n if (bordered) {\n styles.border = `2px solid var(--malachite-tag-${type}-border)`;\n }\n\n if (type === 'emphasis') {\n styles.boxShadow = '0px 0px 10px 0px var(--malachite-tag-emphasis-shadow)';\n } else if (shadow) {\n styles.boxShadow = `0 10px 15px -3px var(--malachite-tag-${type}-shadow)`;\n }\n\n return styles;\n};\n\nconst observeLabelSize = (el: HTMLSpanElement, onResize: () => void): ResizeObserver => {\n const observer = new ResizeObserver(onResize);\n observer.observe(el);\n return observer;\n};\n\nconst Tag: React.FC<TagProps> = ({\n value,\n fontSize,\n type = 'default',\n bordered = false,\n onClick,\n shadow = false,\n textTransform = 'uppercase',\n width,\n paddingSize = 'default',\n icon,\n iconPosition = 'left',\n iconColor,\n pointerType,\n onRemove,\n tooltip,\n tooltipDescribesTag = true,\n 'aria-label': ariaLabel,\n className = '',\n}) => {\n const iconColorStyle = iconColor ? { color: getTextColor(iconColor) } : undefined;\n const observerRef = useRef<ResizeObserver | null>(null);\n const frameRef = useRef<number | null>(null);\n const [isTruncated, setIsTruncated] = useState(false);\n\n // Truncation applies to plain text labels; ReactNode values render untouched.\n const isTextLabel = typeof value === 'string' || typeof value === 'number';\n\n // Memoized so the ref keeps a stable identity. An inline ref callback would be\n // re-invoked (null, then the node) on every render, tearing down and recreating\n // the ResizeObserver each time; this way it only runs on mount/unmount.\n const setLabelRef = useCallback((el: HTMLSpanElement | null) => {\n observerRef.current?.disconnect();\n observerRef.current = null;\n if (frameRef.current !== null) {\n cancelAnimationFrame(frameRef.current);\n frameRef.current = null;\n }\n if (!el || typeof ResizeObserver === 'undefined') {\n return;\n }\n const measure = (): void => {\n frameRef.current = null;\n if (el.clientWidth === 0) {\n return;\n }\n setIsTruncated((prev) => {\n const next = el.scrollWidth > el.clientWidth;\n return prev === next ? prev : next;\n });\n };\n const check = (): void => {\n if (frameRef.current !== null) {\n return;\n }\n frameRef.current = requestAnimationFrame(measure);\n };\n check();\n observerRef.current = observeLabelSize(el, check);\n }, []);\n\n const handleClick = (e: React.MouseEvent) => {\n if (onClick) {\n e.stopPropagation();\n e.preventDefault();\n onClick();\n }\n };\n\n const baseClasses = [\n getWidthClasses(width),\n getTypeClasses(type, paddingSize, fontSize),\n textTransform === 'uppercase' ? 'uppercase' : 'normal-case',\n onClick ? `cursor-pointer ${FOCUS_RING}` : pointerType ? `cursor-${pointerType}` : '',\n isTextLabel ? 'min-w-0 max-w-full' : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const typeStyles = {\n ...getTypeStyles(type, bordered, shadow, paddingSize),\n ...(!onClick && !pointerType && { cursor: IDLE_CURSOR }),\n };\n\n const tag = (\n <span\n className={baseClasses}\n onClick={handleClick}\n // Not with `onRemove`: the role would hide its close button from assistive tech.\n role={onClick && !onRemove ? 'button' : undefined}\n tabIndex={onClick ? 0 : undefined}\n onKeyDown={onClick ? (event) => activateOnEnterOrSpace(event, onClick) : undefined}\n style={typeStyles}\n >\n {icon && iconPosition === 'left' && (\n <span className=\"mr-1 flex items-center\" style={iconColorStyle}>\n {icon}\n </span>\n )}\n {isTextLabel ? (\n <span\n className=\"flex items-center min-w-0\"\n aria-hidden={ariaLabel ? true : undefined}\n >\n <span key={String(value)} ref={setLabelRef} className=\"block min-w-0 truncate\">\n {value}\n </span>\n </span>\n ) : (\n <span className=\"flex items-center\" aria-hidden={ariaLabel ? true : undefined}>\n {value}\n </span>\n )}\n {ariaLabel && <VisuallyHidden>{ariaLabel}</VisuallyHidden>}\n {icon && iconPosition === 'right' && (\n <span className=\"ml-1 flex items-center\" style={iconColorStyle}>\n {icon}\n </span>\n )}\n {onRemove && (\n <button\n type=\"button\"\n aria-label={`Remove ${ariaLabel ?? (typeof value === 'string' ? value : '')}`}\n onClick={(e) => {\n e.stopPropagation();\n onRemove(e);\n }}\n className=\"ml-0.5 flex items-center justify-center shrink-0 border-none bg-transparent text-current cursor-pointer p-0 leading-none opacity-70 hover:opacity-100\"\n >\n {/* A bare cross, not `CloseIcon`'s circled one: this sits inside the chip\n it removes, where a second enclosing ring reads as an object of its own\n rather than as part of the label. */}\n <DismissIcon size={9} />\n </button>\n )}\n </span>\n );\n\n if (!tooltip && !isTruncated) {\n return tag;\n }\n\n return (\n <Tooltip\n text={tooltip ?? value}\n placement=\"top\"\n wrapChildren={false}\n isShrinkable\n inline={tooltip !== undefined}\n describesTrigger={tooltip === undefined || tooltipDescribesTag}\n triggerAs=\"span\"\n >\n {tag}\n </Tooltip>\n );\n};\n\nexport default Tag;\nexport { Tag };\nexport type { TagProps };\n"],"names":["getFontSizeClass","fontSize","getWidthClasses","width","getPaddingClasses","paddingSize","getBorderRadiusClasses","getTypeClasses","type","baseClasses","style","GROUND","IDLE_CURSOR","getTypeStyles","bordered","shadow","tint","styles","observeLabelSize","el","onResize","observer","Tag","value","onClick","textTransform","icon","iconPosition","iconColor","pointerType","onRemove","tooltip","tooltipDescribesTag","ariaLabel","className","iconColorStyle","getTextColor","observerRef","useRef","frameRef","isTruncated","setIsTruncated","useState","isTextLabel","setLabelRef","useCallback","_a","measure","prev","next","check","handleClick","e","FOCUS_RING","typeStyles","tag","jsxs","event","activateOnEnterOrSpace","jsx","VisuallyHidden","DismissIcon","Tooltip"],"mappings":";;;;;;;;AA6DA,MAAMA,IAAmB,CAACC,MAAmC;AACzD,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAkB,CAACC,MAA8B;AACnD,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAoB,CAACC,MAChBA,MAAgB,YAAY,sBAAsB,aAGvDC,IAAyB,CAACD,OACrB;AAAA,EACH,cACIA,MAAgB,YAAY,+BAA+B;AAAA,IAIjEE,IAAiB,CAACC,GAAeH,GAA2BJ,MAA2B;AACzF,QAAMQ,IAAc,2CAA2CL,EAAkBC,CAAW,CAAC,IAAIL,EAAiBC,CAAQ,CAAC,iDAgCrHS,IA9Ba;AAAA,IACf,SAAS;AAAA,MACL,MAAM;AAAA,IAAA;AAAA,IAEV,WAAW;AAAA,MACP,MAAM;AAAA,IAAA;AAAA,IAEV,SAAS;AAAA,MACL,MAAM;AAAA,IAAA;AAAA,IAEV,OAAO;AAAA,MACH,MAAM;AAAA,IAAA;AAAA,IAEV,SAAS;AAAA,MACL,MAAM;AAAA,IAAA;AAAA,IAEV,SAAS;AAAA,MACL,MAAM;AAAA,IAAA;AAAA,IAEV,UAAU;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,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CAACS,IACNe,IAIP,gBAAAI;AAAA,IAACG;AAAA,IAAA;AAAA,MACG,MAAM/B,KAAWR;AAAA,MACjB,WAAU;AAAA,MACV,cAAc;AAAA,MACd,cAAY;AAAA,MACZ,QAAQQ,MAAY;AAAA,MACpB,kBAAkBA,MAAY,UAAaC;AAAA,MAC3C,WAAU;AAAA,MAET,UAAAuB;AAAA,IAAA;AAAA,EAAA;AAGb;"}
@@ -6,7 +6,8 @@ import He from "../CustomIcons/CopyIcon.js";
6
6
  import je from "../CustomIcons/InfoIcon.js";
7
7
  import { FieldMessage as ke } from "../FieldMessage.js";
8
8
  import { paintedFieldValue as ze } from "../devWarning.js";
9
- const Ce = (t) => {
9
+ import { FOCUS_BORDER as Ce } from "../focusRing.js";
10
+ const Ae = (t) => {
10
11
  switch (t) {
11
12
  case "small":
12
13
  return "text-sm";
@@ -17,60 +18,60 @@ const Ce = (t) => {
17
18
  default:
18
19
  return "text-[length:var(--malachite-font-size-15,15px)] leading-[1.4]";
19
20
  }
20
- }, Ae = (t, e) => t ? "focus-within:border-[var(--malachite-destructive-border-hover)] hover:border-[var(--malachite-destructive-border-hover)]" : e === "assistant" ? "focus-within:border-[var(--malachite-assistant-foreground)] hover:border-[var(--malachite-assistant-foreground)]" : "focus-within:border-[var(--malachite-control-border-hover)] hover:border-[var(--malachite-control-border-hover)]", Q = (t, e) => ({
21
+ }, Me = (t, e) => t ? "focus-within:border-[var(--malachite-destructive-border-hover)] hover:border-[var(--malachite-destructive-border-hover)]" : e === "assistant" ? "focus-within:border-[var(--malachite-assistant-foreground)] hover:border-[var(--malachite-assistant-foreground)]" : `${Ce} hover:not-focus-within:border-[var(--malachite-control-border-hover)]`, q = (t, e) => ({
21
22
  small: 20,
22
23
  medium: 22,
23
24
  large: 24
24
- })[t] * e + 24, R = (t, e) => `${Q(t, e)}px`, Je = ({
25
+ })[t] * e + 24, G = (t, e) => `${q(t, e)}px`, qe = ({
25
26
  label: t,
26
27
  hint: e,
27
28
  hintIcon: l,
28
29
  tooltip: o,
29
- placeholder: U,
30
+ placeholder: J,
30
31
  icon: A,
31
- name: f,
32
+ name: v,
32
33
  required: M,
33
- requiredIndicator: V,
34
+ requiredIndicator: K,
34
35
  error: T,
35
36
  description: $,
36
- loading: W = !1,
37
- readOnly: L = !1,
37
+ loading: Q = !1,
38
+ readOnly: B = !1,
38
39
  size: d = "medium",
39
- defaultValue: P,
40
+ defaultValue: E,
40
41
  disabled: c,
41
42
  prefixValue: u,
42
43
  prefixSecondaryValue: p,
43
44
  // ellipsis = false,
44
- formControl: B,
45
+ formControl: L,
45
46
  buttons: x,
46
- onCopyClick: E,
47
+ onCopyClick: P,
47
48
  onChange: g,
48
- onKeyDown: X,
49
+ onKeyDown: V,
49
50
  inFieldAction: b,
50
- tone: Z = "default",
51
+ tone: W = "default",
51
52
  value: w,
52
53
  onBlur: y,
53
54
  helperText: N,
54
55
  rows: I = 4,
55
56
  maxRows: H,
56
- maxLength: _,
57
+ maxLength: X,
57
58
  resize: j = "vertical",
58
- wrap: S = !0,
59
- id: O,
59
+ wrap: R = !0,
60
+ id: Z,
60
61
  "aria-label": F,
61
62
  "aria-labelledby": ee
62
63
  }) => {
63
- const { controlId: Y, labelId: te, descriptionId: q, hintId: D, helperTextId: k } = Ne({
64
- id: O,
64
+ const { controlId: S, labelId: te, descriptionId: D, hintId: O, helperTextId: k } = Ne({
65
+ id: Z,
65
66
  label: t,
66
67
  description: $,
67
68
  hint: e,
68
69
  helperText: !0
69
- }), [re, ae] = pe(P || ""), G = ge(null), z = be(() => {
70
- const r = G.current;
70
+ }), [re, ae] = pe(E || ""), U = ge(null), z = be(() => {
71
+ const r = U.current;
71
72
  if (!r || H === void 0)
72
73
  return;
73
- const s = Q(d, H);
74
+ const s = q(d, H);
74
75
  r.style.height = "auto";
75
76
  const i = Math.min(r.scrollHeight, s);
76
77
  r.style.height = `${i}px`, r.style.overflowY = r.scrollHeight > s ? "auto" : "hidden";
@@ -80,21 +81,21 @@ const Ce = (t) => {
80
81
  }, [z, w]);
81
82
  const ie = w !== void 0, le = (r) => ze({
82
83
  component: "TextArea",
83
- name: f,
84
+ name: v,
84
85
  value: w,
85
86
  formValue: r,
86
- defaultValue: P,
87
- bound: !!B,
87
+ defaultValue: E,
88
+ bound: !!L,
88
89
  uncontrolledValue: re
89
90
  }), se = (r) => (s) => {
90
91
  const i = s.target.value;
91
92
  ie || ae(i), z(), g == null || g(i), r == null || r(i);
92
- }, ne = A || u || p, J = `${k}-error`, oe = (r, s, i, m, v, C) => {
93
- const n = le(C), K = r && !v, me = K || E && c && n || (x == null ? void 0 : x.length), he = [
94
- q,
93
+ }, ne = A || u || p, Y = `${k}-error`, oe = (r, s, i, m, f, C) => {
94
+ const n = le(C), _ = r && !f, me = _ || P && c && n || (x == null ? void 0 : x.length), he = [
95
95
  D,
96
+ O,
96
97
  s ? k : void 0,
97
- v ? J : void 0
98
+ f ? Y : void 0
98
99
  ].filter(Boolean).join(" ") || void 0, xe = [
99
100
  "relative",
100
101
  "flex",
@@ -114,8 +115,8 @@ const Ce = (t) => {
114
115
  // indicator, the same as the default tone's. Adding a ring here drew a second,
115
116
  // concentric outline around the first on `assistant` — the field already has one,
116
117
  // it only needed to change colour.
117
- c ? "" : Ae(r, Z)
118
- ].filter(Boolean).join(" "), ve = [
118
+ c ? "" : Me(r, W)
119
+ ].filter(Boolean).join(" "), fe = [
119
120
  "flex-1",
120
121
  "bg-transparent",
121
122
  "border-none",
@@ -124,62 +125,62 @@ const Ce = (t) => {
124
125
  "placeholder:text-[var(--malachite-text-placeholder)]",
125
126
  "disabled:text-[var(--malachite-text-dimmed)]",
126
127
  "disabled:cursor-not-allowed",
127
- Ce(d),
128
+ Ae(d),
128
129
  // Emitted as one side each when an action sits in the field: `px` and `pr` are
129
130
  // the same specificity, so which wins would rest on Tailwind's output order.
130
131
  b ? "pl-[16px] pr-[52px]" : "px-[16px]",
131
132
  "py-[12px]",
132
133
  j === "none" ? "resize-none" : j === "vertical" ? "resize-y" : j === "horizontal" ? "resize-x" : "resize",
133
- S ? "" : "whitespace-pre overflow-x-auto min-w-0"
134
- ].filter(Boolean).join(" "), fe = /* @__PURE__ */ a(
134
+ R ? "" : "whitespace-pre overflow-x-auto min-w-0"
135
+ ].filter(Boolean).join(" "), ve = /* @__PURE__ */ a(
135
136
  "textarea",
136
137
  {
137
- ref: G,
138
- id: Y,
139
- placeholder: U,
138
+ ref: U,
139
+ id: S,
140
+ placeholder: J,
140
141
  value: n,
141
142
  onChange: se(i),
142
143
  onBlur: () => {
143
144
  y == null || y(), m == null || m();
144
145
  },
145
- onKeyDown: X,
146
+ onKeyDown: V,
146
147
  "aria-label": F,
147
148
  "aria-labelledby": ee,
148
149
  "aria-invalid": r || void 0,
149
150
  "aria-required": M || void 0,
150
151
  "aria-describedby": he,
151
- disabled: c || !!u || !!p || L,
152
- readOnly: L,
153
- wrap: S ? void 0 : "off",
152
+ disabled: c || !!u || !!p || B,
153
+ readOnly: B,
154
+ wrap: R ? void 0 : "off",
154
155
  rows: I,
155
- maxLength: _,
156
- style: { minHeight: R(d, I) },
157
- className: ve,
158
- name: f
156
+ maxLength: X,
157
+ style: { minHeight: G(d, I) },
158
+ className: fe,
159
+ name: v
159
160
  }
160
161
  );
161
162
  return /* @__PURE__ */ h("div", { className: xe, children: [
162
163
  ne && /* @__PURE__ */ a("div", { className: "flex pt-3 pl-3 pr-1 flex-shrink-0 pointer-events-none", children: /* @__PURE__ */ a(
163
- Te,
164
+ $e,
164
165
  {
165
166
  prefixValue: u,
166
167
  prefixSecondaryValue: p,
167
168
  icon: A
168
169
  }
169
170
  ) }),
170
- fe,
171
+ ve,
171
172
  b && /* @__PURE__ */ a("div", { className: "absolute bottom-2 right-2 flex items-center", children: b }),
172
173
  me && /* @__PURE__ */ h("div", { className: "flex pt-3 pl-1 pr-3 flex-shrink-0", children: [
173
174
  /* @__PURE__ */ a(
174
- $e,
175
+ Be,
175
176
  {
176
- error: K,
177
+ error: _,
177
178
  disabled: c,
178
179
  defaultValue: n,
179
- onCopyClick: E
180
+ onCopyClick: P
180
181
  }
181
182
  ),
182
- /* @__PURE__ */ a(Le, { buttons: x })
183
+ /* @__PURE__ */ a(Ee, { buttons: x })
183
184
  ] })
184
185
  ] });
185
186
  }, de = () => N ? /* @__PURE__ */ a(
@@ -189,7 +190,7 @@ const Ce = (t) => {
189
190
  className: "mt-1 text-[length:var(--malachite-font-size-small,13px)] text-left pl-2 text-[var(--malachite-text-dimmed,rgb(161,161,161))]",
190
191
  children: N
191
192
  }
192
- ) : null, ce = (r) => /* @__PURE__ */ a(ke, { id: J, message: r, spaced: !0 });
193
+ ) : null, ce = (r) => /* @__PURE__ */ a(ke, { id: Y, message: r, spaced: !0 });
193
194
  return /* @__PURE__ */ a(
194
195
  ye,
195
196
  {
@@ -197,18 +198,18 @@ const Ce = (t) => {
197
198
  hint: e,
198
199
  hintIcon: l,
199
200
  tooltip: o,
200
- name: f,
201
+ name: v,
201
202
  required: M,
202
- requiredIndicator: V,
203
- loading: W,
204
- formControl: B,
203
+ requiredIndicator: K,
204
+ loading: Q,
205
+ formControl: L,
205
206
  description: $,
206
- controlId: Y,
207
+ controlId: S,
207
208
  labelId: te,
208
- descriptionId: q,
209
- hintId: D,
210
- loadingComponent: /* @__PURE__ */ a(Me, { size: d, rows: I }),
211
- children: ({ error: r, message: s, onFieldChange: i, onFieldBlur: m, value: v }) => {
209
+ descriptionId: D,
210
+ hintId: O,
211
+ loadingComponent: /* @__PURE__ */ a(Te, { size: d, rows: I }),
212
+ children: ({ error: r, message: s, onFieldChange: i, onFieldBlur: m, value: f }) => {
212
213
  const C = T ?? r, n = T === !1 ? void 0 : s;
213
214
  return /* @__PURE__ */ h(ue, { children: [
214
215
  oe(
@@ -217,7 +218,7 @@ const Ce = (t) => {
217
218
  i,
218
219
  m,
219
220
  n,
220
- v
221
+ f
221
222
  ),
222
223
  de(),
223
224
  ce(n)
@@ -225,7 +226,7 @@ const Ce = (t) => {
225
226
  }
226
227
  }
227
228
  );
228
- }, Me = ({
229
+ }, Te = ({
229
230
  size: t = "medium",
230
231
  rows: e = 4
231
232
  }) => (
@@ -237,14 +238,14 @@ const Ce = (t) => {
237
238
  "aria-busy": "true",
238
239
  "aria-hidden": "true",
239
240
  className: "w-full rounded-xl border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-border)] flex items-center justify-center shadow-[var(--malachite-shadow-default)]",
240
- style: { minHeight: R(t, e) }
241
+ style: { minHeight: G(t, e) }
241
242
  }
242
243
  )
243
- ), Te = ({ prefixValue: t, prefixSecondaryValue: e, icon: l }) => /* @__PURE__ */ h("div", { className: "flex items-start gap-1", children: [
244
+ ), $e = ({ prefixValue: t, prefixSecondaryValue: e, icon: l }) => /* @__PURE__ */ h("div", { className: "flex items-start gap-1", children: [
244
245
  l && /* @__PURE__ */ a("span", { className: "flex items-center justify-center text-[var(--malachite-text-dimmed)] w-4 h-4 flex-shrink-0 mt-1", children: l }),
245
246
  t && /* @__PURE__ */ a("span", { className: "text-[length:var(--malachite-font-size-15,15px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap", children: t }),
246
247
  e && /* @__PURE__ */ a("span", { className: "text-[length:var(--malachite-font-size-15,15px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap", children: e })
247
- ] }), $e = ({ error: t, disabled: e, defaultValue: l, onCopyClick: o }) => /* @__PURE__ */ h("div", { className: "flex items-start gap-1", children: [
248
+ ] }), Be = ({ error: t, disabled: e, defaultValue: l, onCopyClick: o }) => /* @__PURE__ */ h("div", { className: "flex items-start gap-1", children: [
248
249
  t && // Decorative: the rejection is carried by the message beneath the field.
249
250
  /* @__PURE__ */ a(
250
251
  "div",
@@ -272,7 +273,7 @@ const Ce = (t) => {
272
273
  children: /* @__PURE__ */ a(He, { size: 16 })
273
274
  }
274
275
  )
275
- ] }), Le = ({ buttons: t }) => t != null && t.length ? /* @__PURE__ */ a("div", { className: "flex flex-col gap-1 mt-1", children: t.map((e) => /* @__PURE__ */ a(
276
+ ] }), Ee = ({ buttons: t }) => t != null && t.length ? /* @__PURE__ */ a("div", { className: "flex flex-col gap-1 mt-1", children: t.map((e) => /* @__PURE__ */ a(
276
277
  Ie,
277
278
  {
278
279
  variant: e.danger ? "destructive" : "outline",
@@ -286,6 +287,6 @@ const Ce = (t) => {
286
287
  e.label
287
288
  )) }) : null;
288
289
  export {
289
- Je as default
290
+ qe as default
290
291
  };
291
292
  //# sourceMappingURL=TextArea.js.map