@stackone/malachite 2.84.0 → 2.85.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/COMPONENTS.md +2 -2
- package/dist/assets/icons/forbidden.svg.js +173 -3
- package/dist/assets/icons/forbidden.svg.js.map +1 -1
- package/dist/assets/icons/navbar_collapse.svg.js +3 -1
- package/dist/assets/icons/navbar_collapse.svg.js.map +1 -1
- package/dist/assets/icons/navbar_expand.svg.js +3 -1
- package/dist/assets/icons/navbar_expand.svg.js.map +1 -1
- package/dist/assets/icons/not_found.svg.js +143 -3
- package/dist/assets/icons/not_found.svg.js.map +1 -1
- package/dist/assets/icons/required_field_indicator.svg.js +7 -1
- package/dist/assets/icons/required_field_indicator.svg.js.map +1 -1
- package/dist/assets/icons/source.svg.js +4 -2
- package/dist/assets/icons/source.svg.js.map +1 -1
- package/dist/assets/icons/webhook_signing_secret.svg.js +3 -1
- package/dist/assets/icons/webhook_signing_secret.svg.js.map +1 -1
- package/dist/components/Alert.js +31 -31
- package/dist/components/Alert.js.map +1 -1
- package/dist/components/BaseFormComponent.js +63 -59
- package/dist/components/BaseFormComponent.js.map +1 -1
- package/dist/components/DatePickerField.js +131 -129
- package/dist/components/DatePickerField.js.map +1 -1
- package/dist/components/Dropdown.js +444 -434
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/Input/Input.js +126 -124
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/MultiSelect.js +85 -83
- package/dist/components/MultiSelect.js.map +1 -1
- package/dist/components/ShadowEscape.js +49 -78
- package/dist/components/ShadowEscape.js.map +1 -1
- package/dist/components/Sidebar.js +152 -122
- package/dist/components/Sidebar.js.map +1 -1
- package/dist/components/Table/Table.js +345 -345
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/TextArea/TextArea.js +73 -71
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/overlayBehaviour.js +159 -143
- package/dist/components/overlayBehaviour.js.map +1 -1
- package/dist/components/sidebarContext.js +7 -6
- package/dist/components/sidebarContext.js.map +1 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +320 -319
- package/dist/tailwind.css.js +1 -1
- package/dist/theme.js +21 -16
- package/dist/theme.js.map +1 -1
- package/package.json +1 -1
package/dist/components/Alert.js
CHANGED
|
@@ -9,7 +9,7 @@ import q from "./CustomIcons/InfoCircleFilled.js";
|
|
|
9
9
|
import G from "./CustomIcons/SparkleIcon.js";
|
|
10
10
|
import J from "./CustomIcons/WarningCircleFilled.js";
|
|
11
11
|
import E from "./Typography/MarkdownBlock.js";
|
|
12
|
-
import { getTextColor as
|
|
12
|
+
import { getTextColor as k, getFontSize as K } from "./Typography/textStyles.js";
|
|
13
13
|
const g = (r) => {
|
|
14
14
|
switch (r) {
|
|
15
15
|
case "info":
|
|
@@ -55,10 +55,10 @@ const g = (r) => {
|
|
|
55
55
|
), V = ({ text: r, emphasis: l }) => {
|
|
56
56
|
if (!l)
|
|
57
57
|
return [{ text: r, bold: !1, offset: 0 }];
|
|
58
|
-
const t = [],
|
|
59
|
-
n && t.push({ text: n, bold:
|
|
58
|
+
const t = [], o = (n, a, s) => {
|
|
59
|
+
n && t.push({ text: n, bold: a, offset: s });
|
|
60
60
|
}, c = r.split(l);
|
|
61
|
-
return c.reduce((n,
|
|
61
|
+
return c.reduce((n, a, s) => (o(a, !1, n), s < c.length - 1 && o(l, !0, n + a.length), n + a.length + l.length), 0), t;
|
|
62
62
|
}, X = ({ address: r, color: l }) => /* @__PURE__ */ e(
|
|
63
63
|
"code",
|
|
64
64
|
{
|
|
@@ -73,8 +73,8 @@ const g = (r) => {
|
|
|
73
73
|
(t) => t.bold ? /* @__PURE__ */ e("strong", { style: { fontWeight: 600 }, children: t.text }, t.offset) : /* @__PURE__ */ e(M.Fragment, { children: t.text }, t.offset)
|
|
74
74
|
)
|
|
75
75
|
}
|
|
76
|
-
), Z = new RegExp("^\\p{P}", "u"), j = ({ text: r, type: l, lead: t, address:
|
|
77
|
-
const
|
|
76
|
+
), Z = new RegExp("^\\p{P}", "u"), j = ({ text: r, type: l, lead: t, address: o, addressSuffix: c, renderLink: n }) => {
|
|
77
|
+
const a = k(g(l)), s = /* @__PURE__ */ e(
|
|
78
78
|
E,
|
|
79
79
|
{
|
|
80
80
|
text: r,
|
|
@@ -84,17 +84,17 @@ const g = (r) => {
|
|
|
84
84
|
renderLink: n
|
|
85
85
|
}
|
|
86
86
|
);
|
|
87
|
-
return !t && !
|
|
87
|
+
return !t && !o ? s : /* @__PURE__ */ i("div", { className: "alert-lead", children: [
|
|
88
88
|
t ? /* @__PURE__ */ i(u, { children: [
|
|
89
|
-
/* @__PURE__ */ e("strong", { style: { color:
|
|
89
|
+
/* @__PURE__ */ e("strong", { style: { color: a, fontSize: K("small"), fontWeight: 600 }, children: t }),
|
|
90
90
|
" "
|
|
91
91
|
] }) : null,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
s,
|
|
93
|
+
o ? /* @__PURE__ */ i(u, { children: [
|
|
94
94
|
" ",
|
|
95
|
-
/* @__PURE__ */ e(X, { address:
|
|
95
|
+
/* @__PURE__ */ e(X, { address: o, color: a })
|
|
96
96
|
] }) : null,
|
|
97
|
-
|
|
97
|
+
o && c ? /* @__PURE__ */ i(u, { children: [
|
|
98
98
|
Z.test(c) ? "" : " ",
|
|
99
99
|
/* @__PURE__ */ e(
|
|
100
100
|
E,
|
|
@@ -112,23 +112,23 @@ const g = (r) => {
|
|
|
112
112
|
type: r = "info",
|
|
113
113
|
message: l,
|
|
114
114
|
hasMargin: t = !0,
|
|
115
|
-
className:
|
|
115
|
+
className: o,
|
|
116
116
|
children: c,
|
|
117
117
|
isExpanded: n,
|
|
118
|
-
onToggle:
|
|
119
|
-
action:
|
|
118
|
+
onToggle: a,
|
|
119
|
+
action: s,
|
|
120
120
|
icon: N,
|
|
121
|
-
live:
|
|
121
|
+
live: z = !1,
|
|
122
122
|
renderLink: w,
|
|
123
|
-
layout:
|
|
124
|
-
lead:
|
|
125
|
-
address:
|
|
123
|
+
layout: O = "inline",
|
|
124
|
+
lead: b,
|
|
125
|
+
address: C,
|
|
126
126
|
addressSuffix: y,
|
|
127
|
-
align:
|
|
127
|
+
align: W = "start"
|
|
128
128
|
}) => {
|
|
129
|
-
const d = !!c, p =
|
|
129
|
+
const d = !!c, p = O === "banner" && !d, v = p && W === "center", _ = z ? r === "error" || r === "warning" ? "alert" : "status" : void 0, [A, B] = P(!1), f = n !== void 0 ? n : A, T = () => {
|
|
130
130
|
const x = !f;
|
|
131
|
-
n === void 0 && B(x),
|
|
131
|
+
n === void 0 && B(x), a == null || a(x);
|
|
132
132
|
}, I = [
|
|
133
133
|
"alert-base",
|
|
134
134
|
`alert-${r}`,
|
|
@@ -140,7 +140,7 @@ const g = (r) => {
|
|
|
140
140
|
v ? "text-center" : "text-left",
|
|
141
141
|
p ? "" : d ? "rounded-xl !p-0" : "!px-2.5 !py-1.5",
|
|
142
142
|
// Slightly more vertical padding for centering
|
|
143
|
-
|
|
143
|
+
o
|
|
144
144
|
].filter(Boolean).join(" "), R = [
|
|
145
145
|
"flex items-center justify-between w-full",
|
|
146
146
|
d ? "gap-2 px-2.5 py-1" : "gap-2",
|
|
@@ -154,8 +154,8 @@ const g = (r) => {
|
|
|
154
154
|
{
|
|
155
155
|
text: l,
|
|
156
156
|
type: r,
|
|
157
|
-
lead:
|
|
158
|
-
address:
|
|
157
|
+
lead: b,
|
|
158
|
+
address: C,
|
|
159
159
|
addressSuffix: y,
|
|
160
160
|
renderLink: w
|
|
161
161
|
}
|
|
@@ -166,7 +166,7 @@ const g = (r) => {
|
|
|
166
166
|
// Its own group, so an `action` stays at the end while this sits mid-band.
|
|
167
167
|
/* @__PURE__ */ e("div", { className: "alert-centred flex-1 flex items-center justify-center gap-[10px]", children: x })
|
|
168
168
|
) : x,
|
|
169
|
-
|
|
169
|
+
s && /* @__PURE__ */ e("div", { className: "alert-action shrink-0 flex items-center", children: s })
|
|
170
170
|
] });
|
|
171
171
|
}
|
|
172
172
|
return /* @__PURE__ */ i("div", { className: `${I} alert-expandable`, children: [
|
|
@@ -177,8 +177,8 @@ const g = (r) => {
|
|
|
177
177
|
j,
|
|
178
178
|
{
|
|
179
179
|
text: l,
|
|
180
|
-
lead:
|
|
181
|
-
address:
|
|
180
|
+
lead: b,
|
|
181
|
+
address: C,
|
|
182
182
|
addressSuffix: y,
|
|
183
183
|
type: r,
|
|
184
184
|
renderLink: w
|
|
@@ -186,7 +186,7 @@ const g = (r) => {
|
|
|
186
186
|
) }) })
|
|
187
187
|
] }),
|
|
188
188
|
/* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
|
|
189
|
-
|
|
189
|
+
s && /* @__PURE__ */ e("div", { className: "alert-action flex items-center", children: s }),
|
|
190
190
|
/* @__PURE__ */ e(
|
|
191
191
|
U,
|
|
192
192
|
{
|
|
@@ -195,14 +195,14 @@ const g = (r) => {
|
|
|
195
195
|
onClick: T,
|
|
196
196
|
"aria-label": f ? "Collapse" : "Expand",
|
|
197
197
|
style: {
|
|
198
|
-
color:
|
|
198
|
+
color: k(g(r))
|
|
199
199
|
},
|
|
200
200
|
children: f ? /* @__PURE__ */ e($, { style: { minWidth: "13px", minHeight: "13px" } }) : /* @__PURE__ */ e(Y, { style: { minWidth: "13px", minHeight: "13px" } })
|
|
201
201
|
}
|
|
202
202
|
)
|
|
203
203
|
] })
|
|
204
204
|
] }),
|
|
205
|
-
f && /* @__PURE__ */ e(u, { children: /* @__PURE__ */ e("div", { className: H, children: /* @__PURE__ */ e("div", { className: "bg-
|
|
205
|
+
f && /* @__PURE__ */ e(u, { children: /* @__PURE__ */ e("div", { className: H, children: /* @__PURE__ */ e("div", { className: "bg-[var(--malachite-card-background,#fff)] rounded-[var(--malachite-radius-10,10px)] [box-shadow:var(--malachite-shadow-default,0px_1px_0px_0px_rgba(0,0,0,0.15))] border border-[var(--malachite-card-border,#e8e8e8)] border-solid mx-2 mb-2 max-h-[553px] overflow-y-auto", children: c }) }) })
|
|
206
206
|
] });
|
|
207
207
|
};
|
|
208
208
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.js","sources":["../../src/components/Alert.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { Button, ButtonVariant } from './Button';\nimport CaretDownIcon from './CustomIcons/CaretDownIcon';\nimport CaretUpIcon from './CustomIcons/CaretUpIcon';\nimport CheckCircleFilled from './CustomIcons/CheckCircleFilled';\nimport ErrorCircleFilled from './CustomIcons/ErrorCircleFilled';\nimport InfoCircleFilled from './CustomIcons/InfoCircleFilled';\nimport SparkleIcon from './CustomIcons/SparkleIcon';\nimport WarningCircleFilled from './CustomIcons/WarningCircleFilled';\nimport type { RenderLink } from './PageLayout/types';\nimport MarkdownBlock from './Typography/MarkdownBlock';\nimport type { TextColor } from './Typography/Text';\nimport { getFontSize, getTextColor } from './Typography/textStyles';\n\nexport type AlertType = 'info' | 'success' | 'error' | 'warning' | 'assistant';\n\nexport type AlertLayout = 'inline' | 'banner';\n\nexport interface AlertAddress {\n /** The full address, shown whole in mono; it wraps rather than truncates. */\n text: string;\n /** The part to set in bold, such as the registrable domain; every occurrence is bolded. */\n emphasis?: string;\n}\n\ninterface AlertButtonConfig {\n label: string;\n onClick: () => void;\n variant?: ButtonVariant;\n icon?: React.ReactNode;\n}\n\ninterface AlertProps {\n type?: AlertType;\n message: string;\n hasMargin?: boolean;\n className?: string;\n children?: React.ReactNode;\n isExpanded?: boolean;\n onToggle?: (expanded: boolean) => void;\n /** A control at the end of the alert — a link or button that resolves what it reports. */\n action?: React.ReactNode;\n /** Replaces the type's status icon: an svg painting with `currentColor`, such as a CustomIcon,\n * is drawn in the type's colour at the same size. */\n icon?: React.ReactNode;\n /** Makes its message a live region: `role=\"alert\"` for error and warning, `status` otherwise.\n * Screen readers reliably announce an `alert` as it mounts; a `status` is read when its\n * `message` changes, so keep a live info or success alert mounted. Off by default. */\n live?: boolean;\n /** Routes root-relative links in `message` through the app's router; see `MarkdownBlock`. */\n renderLink?: RenderLink;\n /** `banner`: a 48px page-wide band. Applies only without `children`. */\n layout?: AlertLayout;\n /** `center` gathers a banner's icon and text in the middle of the band, for a wide page. */\n align?: 'start' | 'center';\n /** A bold sentence the message runs on from. Plain text, not markdown. */\n lead?: string;\n /** An address the message runs on into, in mono; `emphasis`, an optional substring such as the registrable domain, is bold wherever it occurs. */\n address?: AlertAddress;\n /** Markdown that runs on after the address; it joins without a space when it opens with any punctuation. */\n addressSuffix?: string;\n}\n\n// Distinct from the imported `getTextColor`, which maps a TextColor to a CSS variable.\n// This maps an AlertType to a TextColor token; both are used in this file.\nconst getAlertTextColor = (alertType: AlertType): TextColor => {\n switch (alertType) {\n case 'info':\n return 'primary';\n case 'success':\n return 'success';\n case 'error':\n return 'error';\n case 'warning':\n return 'warning';\n // The violet is on `.alert-assistant` itself; inheriting it keeps one definition\n // rather than a TextColor token that only this alert would ever name.\n case 'assistant':\n return 'inherit';\n default:\n return 'primary';\n }\n};\n\nconst ICON_STYLE = {\n width: '13px',\n height: '13px',\n flexShrink: 0,\n};\n\nconst ICON_COLOR: Record<AlertType, string> = {\n info: 'var(--malachite-alert-info-foreground)',\n success: 'var(--malachite-alert-success-foreground)',\n error: 'var(--malachite-alert-error-foreground)',\n warning: 'var(--malachite-alert-warning-foreground)',\n assistant: 'var(--malachite-alert-assistant-foreground)',\n};\n\nconst AlertIcon = {\n info: <InfoCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.info }} />,\n success: <CheckCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.success }} />,\n error: <ErrorCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.error }} />,\n warning: <WarningCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.warning }} />,\n // The same sparkle the control that produced the message carries, so the two read as\n // one thread rather than two unrelated affordances.\n assistant: <SparkleIcon style={{ ...ICON_STYLE, color: ICON_COLOR.assistant }} />,\n};\n\nconst BANNER_ICON_STYLE = { ...ICON_STYLE, width: '16px', height: '16px' };\n\nconst statusIcon = (type: AlertType, icon: React.ReactNode, banner = false) => {\n if (!icon && !banner) return AlertIcon[type];\n const style = banner ? BANNER_ICON_STYLE : ICON_STYLE;\n return (\n <span\n className=\"alert-status-icon inline-flex shrink-0 [&_svg]:size-full!\"\n style={{ ...style, color: ICON_COLOR[type] }}\n >\n {icon || AlertIcon[type]}\n </span>\n );\n};\n\ninterface AddressSegment {\n text: string;\n bold: boolean;\n offset: number;\n}\n\n// The text cut at every occurrence of the emphasis, each cut remembering where it started.\nconst addressSegments = ({ text, emphasis }: AlertAddress): AddressSegment[] => {\n if (!emphasis) {\n return [{ text, bold: false, offset: 0 }];\n }\n const segments: AddressSegment[] = [];\n const push = (part: string, bold: boolean, offset: number) => {\n if (part) segments.push({ text: part, bold, offset });\n };\n const cuts = text.split(emphasis);\n cuts.reduce((offset, cut, index) => {\n push(cut, false, offset);\n if (index < cuts.length - 1) push(emphasis, true, offset + cut.length);\n return offset + cut.length + emphasis.length;\n }, 0);\n return segments;\n};\n\nconst AddressText: React.FC<{ address: AlertAddress; color: string }> = ({ address, color }) => (\n <code\n className=\"alert-address\"\n style={{\n fontFamily: 'var(--malachite-font-mono, monospace)',\n fontSize: '0.9em',\n color,\n overflowWrap: 'anywhere',\n }}\n >\n {addressSegments(address).map((segment) =>\n segment.bold ? (\n <strong key={segment.offset} style={{ fontWeight: 600 }}>\n {segment.text}\n </strong>\n ) : (\n <React.Fragment key={segment.offset}>{segment.text}</React.Fragment>\n ),\n )}\n </code>\n);\n\nconst OPENS_WITH_PUNCTUATION = /^\\p{P}/u;\n\nconst SimpleTextRenderer: React.FC<{\n text: string;\n type: AlertType;\n lead?: string;\n address?: AlertAddress;\n addressSuffix?: string;\n renderLink?: RenderLink;\n}> = ({ text, type, lead, address, addressSuffix, renderLink }) => {\n const color = getTextColor(getAlertTextColor(type));\n const message = (\n <MarkdownBlock\n text={text}\n color={getAlertTextColor(type)}\n size=\"small\"\n omitMargin\n renderLink={renderLink}\n />\n );\n if (!lead && !address) {\n return message;\n }\n return (\n <div className=\"alert-lead\">\n {lead ? (\n <>\n <strong style={{ color, fontSize: getFontSize('small'), fontWeight: 600 }}>\n {lead}\n </strong>{' '}\n </>\n ) : null}\n {message}\n {address ? (\n <>\n {' '}\n <AddressText address={address} color={color} />\n </>\n ) : null}\n {address && addressSuffix ? (\n <>\n {OPENS_WITH_PUNCTUATION.test(addressSuffix) ? '' : ' '}\n <MarkdownBlock\n text={addressSuffix}\n color={getAlertTextColor(type)}\n size=\"small\"\n omitMargin\n renderLink={renderLink}\n />\n </>\n ) : null}\n </div>\n );\n};\n\nconst Alert: React.FC<AlertProps> = ({\n type = 'info',\n message,\n hasMargin = true,\n className,\n children,\n isExpanded,\n onToggle,\n action,\n icon,\n live = false,\n renderLink,\n layout = 'inline',\n lead,\n address,\n addressSuffix,\n align = 'start',\n}) => {\n const isExpandable = !!children;\n const banner = layout === 'banner' && !isExpandable;\n const centred = banner && align === 'center';\n const urgent = type === 'error' || type === 'warning';\n const liveRole = live ? (urgent ? 'alert' : 'status') : undefined;\n const [internalExpanded, setInternalExpanded] = useState(false);\n\n // Use controlled state if isExpanded is provided, otherwise use internal state\n const expanded = isExpanded !== undefined ? isExpanded : internalExpanded;\n\n const handleToggle = () => {\n const newExpanded = !expanded;\n if (isExpanded === undefined) {\n // Uncontrolled mode\n setInternalExpanded(newExpanded);\n }\n // Call onToggle if provided (for both controlled and uncontrolled)\n onToggle?.(newExpanded);\n };\n\n const alertClasses = [\n 'alert-base',\n `alert-${type}`,\n 'flex',\n 'w-full', // Ensure full width\n banner\n ? 'alert-banner'\n : isExpandable && expanded\n ? 'flex-col'\n : 'gap-2 items-center min-h-[2rem]',\n !hasMargin ? 'alert-no-margin' : '',\n centred ? 'text-center' : 'text-left',\n banner ? '' : isExpandable ? 'rounded-xl !p-0' : '!px-2.5 !py-1.5', // Slightly more vertical padding for centering\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const headerClasses = [\n 'flex items-center justify-between w-full',\n isExpandable ? 'gap-2 px-2.5 py-1' : 'gap-2',\n isExpandable && expanded ? 'rounded-t-xl' : isExpandable ? 'rounded-xl' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const expandableContentClasses = ['w-full', 'overflow-hidden'].filter(Boolean).join(' ');\n\n // Non-expandable alert (original behavior)\n if (!isExpandable) {\n const content = (\n <>\n {statusIcon(type, icon, banner)}\n <div className={centred ? 'flex items-center' : 'flex-1 flex items-center'}>\n <div className=\"[&>div]:mb-0\" role={liveRole}>\n <SimpleTextRenderer\n text={message}\n type={type}\n lead={lead}\n address={address}\n addressSuffix={addressSuffix}\n renderLink={renderLink}\n />\n </div>\n </div>\n </>\n );\n return (\n <div className={alertClasses}>\n {centred ? (\n // Its own group, so an `action` stays at the end while this sits mid-band.\n <div className=\"alert-centred flex-1 flex items-center justify-center gap-[10px]\">\n {content}\n </div>\n ) : (\n content\n )}\n {action && <div className=\"alert-action shrink-0 flex items-center\">{action}</div>}\n </div>\n );\n }\n\n // Expandable alert\n return (\n <div className={`${alertClasses} alert-expandable`}>\n {/* Header section with title and expand/collapse button */}\n <div className={headerClasses}>\n <div className=\"flex-1 flex gap-2 items-center\">\n {statusIcon(type, icon)}\n <div className=\"flex-1 flex items-center\">\n <div className=\"[&>div]:mb-0\" role={liveRole}>\n <SimpleTextRenderer\n text={message}\n lead={lead}\n address={address}\n addressSuffix={addressSuffix}\n type={type}\n renderLink={renderLink}\n />\n </div>\n </div>\n </div>\n\n {/* Right side buttons container */}\n <div className=\"flex items-center gap-2\">\n {action && <div className=\"alert-action flex items-center\">{action}</div>}\n {/* Expand/collapse button */}\n <Button\n variant=\"no-style\"\n size=\"xsmall\"\n onClick={handleToggle}\n aria-label={expanded ? 'Collapse' : 'Expand'}\n style={{\n color: getTextColor(getAlertTextColor(type)),\n }}\n >\n {expanded ? (\n <CaretUpIcon style={{ minWidth: '13px', minHeight: '13px' }} />\n ) : (\n <CaretDownIcon style={{ minWidth: '13px', minHeight: '13px' }} />\n )}\n </Button>\n </div>\n </div>\n\n {/* Expandable content */}\n {expanded && (\n <>\n <div className={expandableContentClasses}>\n <div className=\"bg-white rounded-[var(--malachite-radius-10,10px)] shadow-[0px_1px_0px_0px_rgba(0,0,0,0.15)] border border-[#e8e8e8] border-solid mx-2 mb-2 max-h-[553px] overflow-y-auto\">\n {children}\n </div>\n </div>\n </>\n )}\n </div>\n );\n};\n\nexport default Alert;\nexport { Alert };\nexport type { AlertButtonConfig };\n"],"names":["getAlertTextColor","alertType","ICON_STYLE","ICON_COLOR","AlertIcon","jsx","InfoCircleFilled","CheckCircleFilled","ErrorCircleFilled","WarningCircleFilled","SparkleIcon","BANNER_ICON_STYLE","statusIcon","type","icon","banner","addressSegments","text","emphasis","segments","push","part","bold","offset","cuts","cut","index","AddressText","address","color","segment","React","OPENS_WITH_PUNCTUATION","SimpleTextRenderer","lead","addressSuffix","renderLink","getTextColor","message","MarkdownBlock","jsxs","Fragment","getFontSize","Alert","hasMargin","className","children","isExpanded","onToggle","action","live","layout","align","isExpandable","centred","liveRole","internalExpanded","setInternalExpanded","useState","expanded","handleToggle","newExpanded","alertClasses","headerClasses","expandableContentClasses","content","Button","CaretUpIcon","CaretDownIcon"],"mappings":";;;;;;;;;;;;AAiEA,MAAMA,IAAoB,CAACC,MAAoC;AAC3D,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA;AAAA;AAAA,IAGX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAa;AAAA,EACf,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAChB,GAEMC,IAAwC;AAAA,EAC1C,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AACf,GAEMC,IAAY;AAAA,EACd,MAAM,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OAAA,EAAI,WAAW2D,GACZ,UAAA,gBAAA3D,EAAC,OAAA,EAAI,WAAU,6KACV,UAAAyC,EAAA,CACL,EAAA,CACJ,EAAA,CACJ;AAAA,EAAA,GAER;AAER;"}
|
|
1
|
+
{"version":3,"file":"Alert.js","sources":["../../src/components/Alert.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { Button, ButtonVariant } from './Button';\nimport CaretDownIcon from './CustomIcons/CaretDownIcon';\nimport CaretUpIcon from './CustomIcons/CaretUpIcon';\nimport CheckCircleFilled from './CustomIcons/CheckCircleFilled';\nimport ErrorCircleFilled from './CustomIcons/ErrorCircleFilled';\nimport InfoCircleFilled from './CustomIcons/InfoCircleFilled';\nimport SparkleIcon from './CustomIcons/SparkleIcon';\nimport WarningCircleFilled from './CustomIcons/WarningCircleFilled';\nimport type { RenderLink } from './PageLayout/types';\nimport MarkdownBlock from './Typography/MarkdownBlock';\nimport type { TextColor } from './Typography/Text';\nimport { getFontSize, getTextColor } from './Typography/textStyles';\n\nexport type AlertType = 'info' | 'success' | 'error' | 'warning' | 'assistant';\n\nexport type AlertLayout = 'inline' | 'banner';\n\nexport interface AlertAddress {\n /** The full address, shown whole in mono; it wraps rather than truncates. */\n text: string;\n /** The part to set in bold, such as the registrable domain; every occurrence is bolded. */\n emphasis?: string;\n}\n\ninterface AlertButtonConfig {\n label: string;\n onClick: () => void;\n variant?: ButtonVariant;\n icon?: React.ReactNode;\n}\n\ninterface AlertProps {\n type?: AlertType;\n message: string;\n hasMargin?: boolean;\n className?: string;\n children?: React.ReactNode;\n isExpanded?: boolean;\n onToggle?: (expanded: boolean) => void;\n /** A control at the end of the alert — a link or button that resolves what it reports. */\n action?: React.ReactNode;\n /** Replaces the type's status icon: an svg painting with `currentColor`, such as a CustomIcon,\n * is drawn in the type's colour at the same size. */\n icon?: React.ReactNode;\n /** Makes its message a live region: `role=\"alert\"` for error and warning, `status` otherwise.\n * Screen readers reliably announce an `alert` as it mounts; a `status` is read when its\n * `message` changes, so keep a live info or success alert mounted. Off by default. */\n live?: boolean;\n /** Routes root-relative links in `message` through the app's router; see `MarkdownBlock`. */\n renderLink?: RenderLink;\n /** `banner`: a 48px page-wide band. Applies only without `children`. */\n layout?: AlertLayout;\n /** `center` gathers a banner's icon and text in the middle of the band, for a wide page. */\n align?: 'start' | 'center';\n /** A bold sentence the message runs on from. Plain text, not markdown. */\n lead?: string;\n /** An address the message runs on into, in mono; `emphasis`, an optional substring such as the registrable domain, is bold wherever it occurs. */\n address?: AlertAddress;\n /** Markdown that runs on after the address; it joins without a space when it opens with any punctuation. */\n addressSuffix?: string;\n}\n\n// Distinct from the imported `getTextColor`, which maps a TextColor to a CSS variable.\n// This maps an AlertType to a TextColor token; both are used in this file.\nconst getAlertTextColor = (alertType: AlertType): TextColor => {\n switch (alertType) {\n case 'info':\n return 'primary';\n case 'success':\n return 'success';\n case 'error':\n return 'error';\n case 'warning':\n return 'warning';\n // The violet is on `.alert-assistant` itself; inheriting it keeps one definition\n // rather than a TextColor token that only this alert would ever name.\n case 'assistant':\n return 'inherit';\n default:\n return 'primary';\n }\n};\n\nconst ICON_STYLE = {\n width: '13px',\n height: '13px',\n flexShrink: 0,\n};\n\nconst ICON_COLOR: Record<AlertType, string> = {\n info: 'var(--malachite-alert-info-foreground)',\n success: 'var(--malachite-alert-success-foreground)',\n error: 'var(--malachite-alert-error-foreground)',\n warning: 'var(--malachite-alert-warning-foreground)',\n assistant: 'var(--malachite-alert-assistant-foreground)',\n};\n\nconst AlertIcon = {\n info: <InfoCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.info }} />,\n success: <CheckCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.success }} />,\n error: <ErrorCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.error }} />,\n warning: <WarningCircleFilled style={{ ...ICON_STYLE, color: ICON_COLOR.warning }} />,\n // The same sparkle the control that produced the message carries, so the two read as\n // one thread rather than two unrelated affordances.\n assistant: <SparkleIcon style={{ ...ICON_STYLE, color: ICON_COLOR.assistant }} />,\n};\n\nconst BANNER_ICON_STYLE = { ...ICON_STYLE, width: '16px', height: '16px' };\n\nconst statusIcon = (type: AlertType, icon: React.ReactNode, banner = false) => {\n if (!icon && !banner) return AlertIcon[type];\n const style = banner ? BANNER_ICON_STYLE : ICON_STYLE;\n return (\n <span\n className=\"alert-status-icon inline-flex shrink-0 [&_svg]:size-full!\"\n style={{ ...style, color: ICON_COLOR[type] }}\n >\n {icon || AlertIcon[type]}\n </span>\n );\n};\n\ninterface AddressSegment {\n text: string;\n bold: boolean;\n offset: number;\n}\n\n// The text cut at every occurrence of the emphasis, each cut remembering where it started.\nconst addressSegments = ({ text, emphasis }: AlertAddress): AddressSegment[] => {\n if (!emphasis) {\n return [{ text, bold: false, offset: 0 }];\n }\n const segments: AddressSegment[] = [];\n const push = (part: string, bold: boolean, offset: number) => {\n if (part) segments.push({ text: part, bold, offset });\n };\n const cuts = text.split(emphasis);\n cuts.reduce((offset, cut, index) => {\n push(cut, false, offset);\n if (index < cuts.length - 1) push(emphasis, true, offset + cut.length);\n return offset + cut.length + emphasis.length;\n }, 0);\n return segments;\n};\n\nconst AddressText: React.FC<{ address: AlertAddress; color: string }> = ({ address, color }) => (\n <code\n className=\"alert-address\"\n style={{\n fontFamily: 'var(--malachite-font-mono, monospace)',\n fontSize: '0.9em',\n color,\n overflowWrap: 'anywhere',\n }}\n >\n {addressSegments(address).map((segment) =>\n segment.bold ? (\n <strong key={segment.offset} style={{ fontWeight: 600 }}>\n {segment.text}\n </strong>\n ) : (\n <React.Fragment key={segment.offset}>{segment.text}</React.Fragment>\n ),\n )}\n </code>\n);\n\nconst OPENS_WITH_PUNCTUATION = /^\\p{P}/u;\n\nconst SimpleTextRenderer: React.FC<{\n text: string;\n type: AlertType;\n lead?: string;\n address?: AlertAddress;\n addressSuffix?: string;\n renderLink?: RenderLink;\n}> = ({ text, type, lead, address, addressSuffix, renderLink }) => {\n const color = getTextColor(getAlertTextColor(type));\n const message = (\n <MarkdownBlock\n text={text}\n color={getAlertTextColor(type)}\n size=\"small\"\n omitMargin\n renderLink={renderLink}\n />\n );\n if (!lead && !address) {\n return message;\n }\n return (\n <div className=\"alert-lead\">\n {lead ? (\n <>\n <strong style={{ color, fontSize: getFontSize('small'), fontWeight: 600 }}>\n {lead}\n </strong>{' '}\n </>\n ) : null}\n {message}\n {address ? (\n <>\n {' '}\n <AddressText address={address} color={color} />\n </>\n ) : null}\n {address && addressSuffix ? (\n <>\n {OPENS_WITH_PUNCTUATION.test(addressSuffix) ? '' : ' '}\n <MarkdownBlock\n text={addressSuffix}\n color={getAlertTextColor(type)}\n size=\"small\"\n omitMargin\n renderLink={renderLink}\n />\n </>\n ) : null}\n </div>\n );\n};\n\nconst Alert: React.FC<AlertProps> = ({\n type = 'info',\n message,\n hasMargin = true,\n className,\n children,\n isExpanded,\n onToggle,\n action,\n icon,\n live = false,\n renderLink,\n layout = 'inline',\n lead,\n address,\n addressSuffix,\n align = 'start',\n}) => {\n const isExpandable = !!children;\n const banner = layout === 'banner' && !isExpandable;\n const centred = banner && align === 'center';\n const urgent = type === 'error' || type === 'warning';\n const liveRole = live ? (urgent ? 'alert' : 'status') : undefined;\n const [internalExpanded, setInternalExpanded] = useState(false);\n\n // Use controlled state if isExpanded is provided, otherwise use internal state\n const expanded = isExpanded !== undefined ? isExpanded : internalExpanded;\n\n const handleToggle = () => {\n const newExpanded = !expanded;\n if (isExpanded === undefined) {\n // Uncontrolled mode\n setInternalExpanded(newExpanded);\n }\n // Call onToggle if provided (for both controlled and uncontrolled)\n onToggle?.(newExpanded);\n };\n\n const alertClasses = [\n 'alert-base',\n `alert-${type}`,\n 'flex',\n 'w-full', // Ensure full width\n banner\n ? 'alert-banner'\n : isExpandable && expanded\n ? 'flex-col'\n : 'gap-2 items-center min-h-[2rem]',\n !hasMargin ? 'alert-no-margin' : '',\n centred ? 'text-center' : 'text-left',\n banner ? '' : isExpandable ? 'rounded-xl !p-0' : '!px-2.5 !py-1.5', // Slightly more vertical padding for centering\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const headerClasses = [\n 'flex items-center justify-between w-full',\n isExpandable ? 'gap-2 px-2.5 py-1' : 'gap-2',\n isExpandable && expanded ? 'rounded-t-xl' : isExpandable ? 'rounded-xl' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const expandableContentClasses = ['w-full', 'overflow-hidden'].filter(Boolean).join(' ');\n\n // Non-expandable alert (original behavior)\n if (!isExpandable) {\n const content = (\n <>\n {statusIcon(type, icon, banner)}\n <div className={centred ? 'flex items-center' : 'flex-1 flex items-center'}>\n <div className=\"[&>div]:mb-0\" role={liveRole}>\n <SimpleTextRenderer\n text={message}\n type={type}\n lead={lead}\n address={address}\n addressSuffix={addressSuffix}\n renderLink={renderLink}\n />\n </div>\n </div>\n </>\n );\n return (\n <div className={alertClasses}>\n {centred ? (\n // Its own group, so an `action` stays at the end while this sits mid-band.\n <div className=\"alert-centred flex-1 flex items-center justify-center gap-[10px]\">\n {content}\n </div>\n ) : (\n content\n )}\n {action && <div className=\"alert-action shrink-0 flex items-center\">{action}</div>}\n </div>\n );\n }\n\n // Expandable alert\n return (\n <div className={`${alertClasses} alert-expandable`}>\n {/* Header section with title and expand/collapse button */}\n <div className={headerClasses}>\n <div className=\"flex-1 flex gap-2 items-center\">\n {statusIcon(type, icon)}\n <div className=\"flex-1 flex items-center\">\n <div className=\"[&>div]:mb-0\" role={liveRole}>\n <SimpleTextRenderer\n text={message}\n lead={lead}\n address={address}\n addressSuffix={addressSuffix}\n type={type}\n renderLink={renderLink}\n />\n </div>\n </div>\n </div>\n\n {/* Right side buttons container */}\n <div className=\"flex items-center gap-2\">\n {action && <div className=\"alert-action flex items-center\">{action}</div>}\n {/* Expand/collapse button */}\n <Button\n variant=\"no-style\"\n size=\"xsmall\"\n onClick={handleToggle}\n aria-label={expanded ? 'Collapse' : 'Expand'}\n style={{\n color: getTextColor(getAlertTextColor(type)),\n }}\n >\n {expanded ? (\n <CaretUpIcon style={{ minWidth: '13px', minHeight: '13px' }} />\n ) : (\n <CaretDownIcon style={{ minWidth: '13px', minHeight: '13px' }} />\n )}\n </Button>\n </div>\n </div>\n\n {/* Expandable content */}\n {expanded && (\n <>\n <div className={expandableContentClasses}>\n <div className=\"bg-[var(--malachite-card-background,#fff)] rounded-[var(--malachite-radius-10,10px)] [box-shadow:var(--malachite-shadow-default,0px_1px_0px_0px_rgba(0,0,0,0.15))] border border-[var(--malachite-card-border,#e8e8e8)] border-solid mx-2 mb-2 max-h-[553px] overflow-y-auto\">\n {children}\n </div>\n </div>\n </>\n )}\n </div>\n );\n};\n\nexport default Alert;\nexport { Alert };\nexport type { AlertButtonConfig };\n"],"names":["getAlertTextColor","alertType","ICON_STYLE","ICON_COLOR","AlertIcon","jsx","InfoCircleFilled","CheckCircleFilled","ErrorCircleFilled","WarningCircleFilled","SparkleIcon","BANNER_ICON_STYLE","statusIcon","type","icon","banner","addressSegments","text","emphasis","segments","push","part","bold","offset","cuts","cut","index","AddressText","address","color","segment","React","OPENS_WITH_PUNCTUATION","SimpleTextRenderer","lead","addressSuffix","renderLink","getTextColor","message","MarkdownBlock","jsxs","Fragment","getFontSize","Alert","hasMargin","className","children","isExpanded","onToggle","action","live","layout","align","isExpandable","centred","liveRole","internalExpanded","setInternalExpanded","useState","expanded","handleToggle","newExpanded","alertClasses","headerClasses","expandableContentClasses","content","Button","CaretUpIcon","CaretDownIcon"],"mappings":";;;;;;;;;;;;AAiEA,MAAMA,IAAoB,CAACC,MAAoC;AAC3D,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA;AAAA;AAAA,IAGX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAEMC,IAAa;AAAA,EACf,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAChB,GAEMC,IA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AA;AAAA,QAAA;AAAA,MAEvE,EAAA,CACJ;AAAA,IAAA,GACJ;AAAA,IAGCT,KACG,gBAAAtD,EAAAoC,GAAA,EACI,UAAA,gBAAApC,EAAC,OAAA,EAAI,WAAW2D,GACZ,UAAA,gBAAA3D,EAAC,OAAA,EAAI,WAAU,gRACV,UAAAyC,EAAA,CACL,EAAA,CACJ,EAAA,CACJ;AAAA,EAAA,GAER;AAER;"}
|
|
@@ -1,82 +1,83 @@
|
|
|
1
1
|
import { jsx as e, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import { useId as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { FormItem as
|
|
6
|
-
import { Link as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
2
|
+
import { useId as w } from "react";
|
|
3
|
+
import F from "./CustomIcons/ArrowUpRightIcon.js";
|
|
4
|
+
import $ from "./CustomIcons/InfoFilledIcon.js";
|
|
5
|
+
import { FormItem as y } from "./FormItem.js";
|
|
6
|
+
import { Link as O } from "./Link.js";
|
|
7
|
+
import u from "./Spacer.js";
|
|
8
|
+
import _ from "./Tooltip.js";
|
|
9
|
+
import H from "./Typography/MarkdownBlock.js";
|
|
10
10
|
import h from "./Typography/Text.js";
|
|
11
|
-
import { FOCUS_RING as
|
|
12
|
-
import { renderFormItemChildren as
|
|
13
|
-
import { safeHref as
|
|
14
|
-
const
|
|
11
|
+
import { FOCUS_RING as v } from "./focusRing.js";
|
|
12
|
+
import { renderFormItemChildren as R, NO_FIELD_ERROR as L } from "./formItemState.js";
|
|
13
|
+
import { safeHref as T } from "./safeHref.js";
|
|
14
|
+
const j = 0.5, ee = ({
|
|
15
15
|
id: r,
|
|
16
16
|
label: t,
|
|
17
17
|
description: o,
|
|
18
|
-
hint:
|
|
19
|
-
helperText:
|
|
18
|
+
hint: i,
|
|
19
|
+
helperText: n = !1
|
|
20
20
|
}) => {
|
|
21
|
-
const
|
|
22
|
-
return { controlId:
|
|
23
|
-
},
|
|
21
|
+
const l = `mal-${w().replace(/[^a-zA-Z0-9_-]/g, "")}-`, s = r ?? `${l}control`, p = t ? `${l}label` : void 0, d = o ? `${l}description` : void 0, m = i ? `${l}hint` : void 0, c = n ? `${l}helper` : void 0, f = [d, m, c].filter(Boolean).join(" ") || void 0;
|
|
22
|
+
return { controlId: s, labelId: p, descriptionId: d, hintId: m, helperTextId: c, describedBy: f };
|
|
23
|
+
}, re = ({
|
|
24
24
|
label: r,
|
|
25
25
|
hint: t,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
hintIcon: o,
|
|
27
|
+
rightSideContent: i,
|
|
28
|
+
tooltip: n,
|
|
29
|
+
name: l,
|
|
30
|
+
description: s,
|
|
30
31
|
required: p = !1,
|
|
31
|
-
requiredIndicator:
|
|
32
|
-
loading:
|
|
33
|
-
formControl:
|
|
34
|
-
loadingComponent:
|
|
35
|
-
children:
|
|
36
|
-
controlId:
|
|
37
|
-
labelId:
|
|
38
|
-
descriptionId:
|
|
39
|
-
hintId:
|
|
40
|
-
fullWidth:
|
|
32
|
+
requiredIndicator: d = "optional-suffix",
|
|
33
|
+
loading: m = !1,
|
|
34
|
+
formControl: c,
|
|
35
|
+
loadingComponent: f,
|
|
36
|
+
children: x,
|
|
37
|
+
controlId: b,
|
|
38
|
+
labelId: I,
|
|
39
|
+
descriptionId: N,
|
|
40
|
+
hintId: g,
|
|
41
|
+
fullWidth: z = !1
|
|
41
42
|
}) => {
|
|
42
|
-
const
|
|
43
|
-
return /* @__PURE__ */ a(
|
|
44
|
-
(r || t ||
|
|
43
|
+
const k = c ? /* @__PURE__ */ e(y, { control: c, name: l, children: x }) : R(x, L);
|
|
44
|
+
return /* @__PURE__ */ a(u, { direction: "vertical", size: 6, align: "stretch", fullWidth: z, children: [
|
|
45
|
+
(r || t || s || i) && /* @__PURE__ */ a(u, { direction: "vertical", size: 4, align: "stretch", children: [
|
|
45
46
|
/* @__PURE__ */ a("div", { className: "flex justify-between items-start", children: [
|
|
46
47
|
/* @__PURE__ */ e(
|
|
47
|
-
|
|
48
|
+
A,
|
|
48
49
|
{
|
|
49
50
|
text: r,
|
|
50
51
|
required: p,
|
|
51
|
-
requiredIndicator:
|
|
52
|
-
tooltip:
|
|
53
|
-
id:
|
|
54
|
-
htmlFor:
|
|
52
|
+
requiredIndicator: d,
|
|
53
|
+
tooltip: n,
|
|
54
|
+
id: I,
|
|
55
|
+
htmlFor: m ? void 0 : b
|
|
55
56
|
}
|
|
56
57
|
),
|
|
57
|
-
(t ||
|
|
58
|
-
t && /* @__PURE__ */ e(
|
|
59
|
-
|
|
58
|
+
(t || i) && /* @__PURE__ */ a("div", { className: "flex items-start gap-2", children: [
|
|
59
|
+
t && /* @__PURE__ */ e(D, { text: t, icon: o, id: g }),
|
|
60
|
+
i && /* @__PURE__ */ e(B, { ...i })
|
|
60
61
|
] })
|
|
61
62
|
] }),
|
|
62
|
-
|
|
63
|
+
s && /* @__PURE__ */ e(E, { text: s, id: N })
|
|
63
64
|
] }),
|
|
64
|
-
|
|
65
|
+
m ? f : k
|
|
65
66
|
] });
|
|
66
|
-
},
|
|
67
|
+
}, B = (r) => {
|
|
67
68
|
if (r.type === "button")
|
|
68
69
|
return /* @__PURE__ */ e(
|
|
69
70
|
"button",
|
|
70
71
|
{
|
|
71
72
|
type: "button",
|
|
72
73
|
onClick: r.onClick,
|
|
73
|
-
className: `relative top-[3px] shrink-0 cursor-pointer whitespace-nowrap border-0 bg-transparent p-0 text-[length:var(--malachite-font-size-xsmall)] font-medium text-[var(--malachite-accent-foreground)] hover:underline ${
|
|
74
|
+
className: `relative top-[3px] shrink-0 cursor-pointer whitespace-nowrap border-0 bg-transparent p-0 text-[length:var(--malachite-font-size-xsmall)] font-medium text-[var(--malachite-accent-foreground)] hover:underline ${v}`,
|
|
74
75
|
children: r.text
|
|
75
76
|
}
|
|
76
77
|
);
|
|
77
|
-
const t =
|
|
78
|
+
const t = T(r.href);
|
|
78
79
|
return t ? /* @__PURE__ */ a(
|
|
79
|
-
|
|
80
|
+
O,
|
|
80
81
|
{
|
|
81
82
|
href: t,
|
|
82
83
|
target: "_blank",
|
|
@@ -87,19 +88,22 @@ const T = 0.5, q = ({
|
|
|
87
88
|
className: "shrink-0 whitespace-nowrap inline-flex items-center gap-1 relative top-[3px]",
|
|
88
89
|
children: [
|
|
89
90
|
r.text,
|
|
90
|
-
/* @__PURE__ */ e(
|
|
91
|
+
/* @__PURE__ */ e(F, { size: 13 })
|
|
91
92
|
]
|
|
92
93
|
}
|
|
93
94
|
) : null;
|
|
94
|
-
},
|
|
95
|
+
}, D = ({ text: r, icon: t, id: o }) => /* @__PURE__ */ a("span", { id: o, className: "inline-flex items-center gap-1 relative top-[3px] pr-2", children: [
|
|
96
|
+
t && /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "inline-flex text-[var(--malachite-text-dimmed)]", children: t }),
|
|
97
|
+
/* @__PURE__ */ e(h, { size: "xsmall", color: "dimmed", children: r })
|
|
98
|
+
] }), E = ({ text: r, id: t }) => /* @__PURE__ */ e("div", { className: "pl-2 text-left", id: t, children: /* @__PURE__ */ e(H, { color: "dimmed", size: "small", text: r ?? "", omitMargin: !0 }) }), A = ({
|
|
95
99
|
text: r,
|
|
96
100
|
required: t,
|
|
97
101
|
requiredIndicator: o,
|
|
98
|
-
tooltip:
|
|
99
|
-
id:
|
|
100
|
-
htmlFor:
|
|
102
|
+
tooltip: i,
|
|
103
|
+
id: n,
|
|
104
|
+
htmlFor: l
|
|
101
105
|
}) => r ? /* @__PURE__ */ a("div", { className: "flex items-center", children: [
|
|
102
|
-
/* @__PURE__ */ e("label", { id:
|
|
106
|
+
/* @__PURE__ */ e("label", { id: n, htmlFor: l, children: /* @__PURE__ */ e(h, { size: "xsmall", color: "primary", fontWeight: "semi-bold", className: "pl-2", children: r }) }),
|
|
103
107
|
o === "optional-suffix" && !t && /* @__PURE__ */ e("span", { "aria-hidden": "true", children: /* @__PURE__ */ e(h, { size: "xsmall", color: "dimmed", className: "ml-1", children: "(Optional)" }) }),
|
|
104
108
|
o === "asterisk" && t && /* @__PURE__ */ e(
|
|
105
109
|
"span",
|
|
@@ -109,18 +113,18 @@ const T = 0.5, q = ({
|
|
|
109
113
|
children: "*"
|
|
110
114
|
}
|
|
111
115
|
),
|
|
112
|
-
|
|
116
|
+
i && /* @__PURE__ */ e(_, { text: i, placement: "right", delay: j, children: /* @__PURE__ */ e(
|
|
113
117
|
"button",
|
|
114
118
|
{
|
|
115
119
|
type: "button",
|
|
116
120
|
"aria-label": `More information about ${r}`,
|
|
117
|
-
className: `ml-1 -mt-[2px] inline-flex items-center text-[var(--malachite-text-dimmed)] cursor-help ${
|
|
118
|
-
children: /* @__PURE__ */ e(
|
|
121
|
+
className: `ml-1 -mt-[2px] inline-flex items-center text-[var(--malachite-text-dimmed)] cursor-help ${v}`,
|
|
122
|
+
children: /* @__PURE__ */ e($, { size: 14 })
|
|
119
123
|
}
|
|
120
124
|
) })
|
|
121
125
|
] }) : /* @__PURE__ */ e("div", {});
|
|
122
126
|
export {
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
re as default,
|
|
128
|
+
ee as useFormFieldIds
|
|
125
129
|
};
|
|
126
130
|
//# sourceMappingURL=BaseFormComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseFormComponent.js","sources":["../../src/components/BaseFormComponent.tsx"],"sourcesContent":["import React, { useId } from 'react';\nimport type { Control, FieldPath, FieldValues } from 'react-hook-form';\nimport ArrowUpRightIcon from './CustomIcons/ArrowUpRightIcon';\nimport InfoFilledIcon from './CustomIcons/InfoFilledIcon';\nimport FormItem from './FormItem';\nimport Link from './Link';\nimport Spacer from './Spacer';\nimport Tooltip from './Tooltip';\nimport MarkdownBlock from './Typography/MarkdownBlock';\nimport Text from './Typography/Text';\nimport { FOCUS_RING } from './focusRing';\nimport { type FormItemChildren, NO_FIELD_ERROR, renderFormItemChildren } from './formItemState';\nimport { safeHref } from './safeHref';\n\n/** Tooltip's own default of 1s reads as broken; 0.5 matches the rest of the library. */\nconst TOOLTIP_DELAY_SECONDS = 0.5;\n\n/** The ids that wire a form field's label / description / hint to its control. */\nexport interface FormFieldIds {\n controlId: string;\n labelId?: string;\n descriptionId?: string;\n hintId?: string;\n helperTextId?: string;\n describedBy?: string;\n}\n\ninterface FormFieldIdOptions {\n /** A caller-supplied id always wins, so consumers can label the control themselves. */\n id?: string;\n label?: string;\n description?: string;\n hint?: string;\n helperText?: boolean;\n}\n\n/**\n * Generates the stable ids a form field needs to be announced correctly. Shared by\n * `Input`, `TextArea`, `Dropdown` and `MultiSelect` so all four wire up identically.\n */\nexport const useFormFieldIds = ({\n id,\n label,\n description,\n hint,\n helperText = false,\n}: FormFieldIdOptions): FormFieldIds => {\n // useId() emits \":r0:\", and a colon is invalid in a CSS id selector, so a consumer's\n // querySelector(`#${id}`) throws. Stripping only the delimiters keeps ids unique.\n const generatedId = `mal-${useId().replace(/[^a-zA-Z0-9_-]/g, '')}-`;\n const controlId = id ?? `${generatedId}control`;\n const labelId = label ? `${generatedId}label` : undefined;\n const descriptionId = description ? `${generatedId}description` : undefined;\n const hintId = hint ? `${generatedId}hint` : undefined;\n const helperTextId = helperText ? `${generatedId}helper` : undefined;\n const describedBy =\n [descriptionId, hintId, helperTextId].filter(Boolean).join(' ') || undefined;\n\n return { controlId, labelId, descriptionId, hintId, helperTextId, describedBy };\n};\n\ninterface BaseFormComponentProps {\n label?: string;\n description?: string;\n hint?: string;\n rightSideContent?: RightSideContent;\n tooltip?: string;\n required?: boolean;\n requiredIndicator?: RequiredIndicator;\n name: FieldPath<FieldValues>;\n defaultValue?: string;\n loading?: boolean;\n formControl?: Control<FieldValues, unknown>;\n loadingComponent: React.ReactNode;\n children?: FormItemChildren;\n /** Accessibility wiring, from `useFormFieldIds` — see `FormFieldIds`. */\n controlId?: string;\n labelId?: string;\n descriptionId?: string;\n hintId?: string;\n fullWidth?: boolean;\n}\n\nconst BaseFormComponent: React.FC<BaseFormComponentProps> = ({\n label,\n hint,\n rightSideContent,\n tooltip,\n name,\n description,\n required = false,\n requiredIndicator = 'optional-suffix',\n loading = false,\n formControl,\n loadingComponent,\n children,\n controlId,\n labelId,\n descriptionId,\n hintId,\n fullWidth = false,\n}) => {\n const finalComponent = formControl ? (\n <FormItem control={formControl} name={name}>\n {children}\n </FormItem>\n ) : (\n renderFormItemChildren(children, NO_FIELD_ERROR)\n );\n\n const topHeader = () => (\n <Spacer direction=\"vertical\" size={4} align=\"stretch\">\n <div className=\"flex justify-between items-start\">\n <Label\n text={label}\n required={required}\n requiredIndicator={requiredIndicator}\n tooltip={tooltip}\n id={labelId}\n // No control is rendered while loading, so an htmlFor would be an orphan.\n htmlFor={loading ? undefined : controlId}\n />\n {(hint || rightSideContent) && (\n <div className=\"flex items-start gap-2\">\n {hint && <Hint text={hint} id={hintId} />}\n {rightSideContent && <RightSide {...rightSideContent} />}\n </div>\n )}\n </div>\n {description && <Description text={description} id={descriptionId} />}\n </Spacer>\n );\n\n const showHeader = label || hint || description || rightSideContent;\n\n return (\n <Spacer direction=\"vertical\" size={6} align=\"stretch\" fullWidth={fullWidth}>\n {showHeader && topHeader()}\n {!loading ? finalComponent : loadingComponent}\n </Spacer>\n );\n};\n\n/**\n * What sits at the far end of a field's label row. Data rather than a node, so nothing\n * arbitrary reaches the row; discriminated so a further kind is additive. Plain text is\n * already `hint`.\n */\nexport type RightSideContent =\n | {\n type?: 'link';\n text: string;\n href: string;\n }\n | {\n /** An action on the form itself, such as showing a panel of help beside it. */\n type: 'button';\n text: string;\n onClick: () => void;\n };\n\nconst RightSide = (content: RightSideContent) => {\n if (content.type === 'button') {\n return (\n <button\n type=\"button\"\n onClick={content.onClick}\n className={`relative top-[3px] shrink-0 cursor-pointer whitespace-nowrap border-0 bg-transparent p-0 text-[length:var(--malachite-font-size-xsmall)] font-medium text-[var(--malachite-accent-foreground)] hover:underline ${FOCUS_RING}`}\n >\n {content.text}\n </button>\n );\n }\n\n const safe = safeHref(content.href);\n\n if (!safe) {\n return null;\n }\n\n return (\n <Link\n href={safe}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n color=\"dimmed\"\n size=\"xsmall\"\n underline={false}\n className=\"shrink-0 whitespace-nowrap inline-flex items-center gap-1 relative top-[3px]\"\n >\n {content.text}\n <ArrowUpRightIcon size={13} />\n </Link>\n );\n};\n\nconst Hint = ({ text, id }: { text?: string; id?: string }) => {\n return (\n <span id={id}>\n <Text size=\"xsmall\" color=\"dimmed\" className=\"pr-2 relative top-[3px]\">\n {text}\n </Text>\n </span>\n );\n};\n\nconst Description = ({ text, id }: { text?: string; id?: string }) => {\n return (\n <div className=\"pl-2 text-left\" id={id}>\n <MarkdownBlock color=\"dimmed\" size=\"small\" text={text ?? ''} omitMargin={true} />\n </div>\n );\n};\n\nexport type RequiredIndicator = 'optional-suffix' | 'asterisk' | 'none';\n\nconst Label = ({\n text,\n required,\n requiredIndicator,\n tooltip,\n id,\n htmlFor,\n}: {\n text?: string;\n required: boolean;\n requiredIndicator: RequiredIndicator;\n tooltip?: string;\n id?: string;\n htmlFor?: string;\n}) => {\n return text ? (\n <div className=\"flex items-center\">\n <label id={id} htmlFor={htmlFor}>\n <Text size=\"xsmall\" color=\"primary\" fontWeight=\"semi-bold\" className=\"pl-2\">\n {text}\n </Text>\n </label>\n {/* Sibling of the <label>, not a child: Testing Library's getByLabelText matches\n on textContent, so a marker inside it breaks getByLabelText('<label>'). */}\n {requiredIndicator === 'optional-suffix' && !required && (\n <span aria-hidden=\"true\">\n <Text size=\"xsmall\" color=\"dimmed\" className=\"ml-1\">\n (Optional)\n </Text>\n </span>\n )}\n {requiredIndicator === 'asterisk' && required && (\n <span\n aria-hidden=\"true\"\n className=\"ml-1 text-[var(--malachite-destructive-foreground,rgb(196,62,62))]\"\n >\n *\n </span>\n )}\n {tooltip && (\n <Tooltip text={tooltip} placement=\"right\" delay={TOOLTIP_DELAY_SECONDS}>\n <button\n type=\"button\"\n aria-label={`More information about ${text}`}\n className={`ml-1 -mt-[2px] inline-flex items-center text-[var(--malachite-text-dimmed)] cursor-help ${FOCUS_RING}`}\n >\n <InfoFilledIcon size={14} />\n </button>\n </Tooltip>\n )}\n </div>\n ) : (\n <div />\n );\n};\n\nexport default BaseFormComponent;\n"],"names":["TOOLTIP_DELAY_SECONDS","useFormFieldIds","id","label","description","hint","helperText","generatedId","useId","controlId","labelId","descriptionId","hintId","helperTextId","describedBy","BaseFormComponent","rightSideContent","tooltip","name","required","requiredIndicator","loading","formControl","loadingComponent","children","fullWidth","finalComponent","jsx","FormItem","renderFormItemChildren","NO_FIELD_ERROR","jsxs","Spacer","Label","Hint","RightSide","Description","content","FOCUS_RING","safe","safeHref","Link","ArrowUpRightIcon","text","Text","MarkdownBlock","htmlFor","Tooltip","InfoFilledIcon"],"mappings":";;;;;;;;;;;;;AAeA,MAAMA,IAAwB,KAyBjBC,IAAkB,CAAC;AAAA,EAC5B,IAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC,IAAa;AACjB,MAAwC;AAGpC,QAAMC,IAAc,OAAOC,EAAA,EAAQ,QAAQ,mBAAmB,EAAE,CAAC,KAC3DC,IAAYP,KAAM,GAAGK,CAAW,WAChCG,IAAUP,IAAQ,GAAGI,CAAW,UAAU,QAC1CI,IAAgBP,IAAc,GAAGG,CAAW,gBAAgB,QAC5DK,IAASP,IAAO,GAAGE,CAAW,SAAS,QACvCM,IAAeP,IAAa,GAAGC,CAAW,WAAW,QACrDO,IACF,CAACH,GAAeC,GAAQC,CAAY,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,KAAK;AAEvE,SAAO,EAAE,WAAAJ,GAAW,SAAAC,GAAS,eAAAC,GAAe,QAAAC,GAAQ,cAAAC,GAAc,aAAAC,EAAA;AACtE,GAwBMC,KAAsD,CAAC;AAAA,EACzD,OAAAZ;AAAA,EACA,MAAAE;AAAA,EACA,kBAAAW;AAAA,EACA,SAAAC;AAA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zB,GAAQ,SAAA4C,GACX,UAAA,gBAAAnB,EAACiB,KAAK,MAAK,UAAS,OAAM,WAAU,YAAW,aAAY,WAAU,QAChE,aACL,GACJ;AAAA,EAGCxB,MAAsB,qBAAqB,CAACD,KACzC,gBAAAQ,EAAC,UAAK,eAAY,QACd,UAAA,gBAAAA,EAACiB,GAAA,EAAK,MAAK,UAAS,OAAM,UAAS,WAAU,QAAO,wBAEpD,GACJ;AAAA,EAEHxB,MAAsB,cAAcD,KACjC,gBAAAQ;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,eAAY;AAAA,MACZ,WAAU;AAAA,MACb,UAAA;AAAA,IAAA;AAAA,EAAA;AAAA,EAIJV,uBACI8B,GAAA,EAAQ,MAAM9B,GAAS,WAAU,SAAQ,OAAOjB,GAC7C,UAAA,gBAAA2B;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,cAAY,0BAA0BgB,CAAI;AAAA,MAC1C,WAAW,2FAA2FL,CAAU;AAAA,MAEhH,UAAA,gBAAAX,EAACqB,GAAA,EAAe,MAAM,GAAA,CAAI;AAAA,IAAA;AAAA,EAAA,EAC9B,CACJ;AAAA,EAAA,CAER,sBAEC,OAAA,EAAI;"}
|
|
1
|
+
{"version":3,"file":"BaseFormComponent.js","sources":["../../src/components/BaseFormComponent.tsx"],"sourcesContent":["import React, { useId } from 'react';\nimport type { Control, FieldPath, FieldValues } from 'react-hook-form';\nimport ArrowUpRightIcon from './CustomIcons/ArrowUpRightIcon';\nimport InfoFilledIcon from './CustomIcons/InfoFilledIcon';\nimport FormItem from './FormItem';\nimport Link from './Link';\nimport Spacer from './Spacer';\nimport Tooltip from './Tooltip';\nimport MarkdownBlock from './Typography/MarkdownBlock';\nimport Text from './Typography/Text';\nimport { FOCUS_RING } from './focusRing';\nimport { type FormItemChildren, NO_FIELD_ERROR, renderFormItemChildren } from './formItemState';\nimport { safeHref } from './safeHref';\n\n/** Tooltip's own default of 1s reads as broken; 0.5 matches the rest of the library. */\nconst TOOLTIP_DELAY_SECONDS = 0.5;\n\n/** The ids that wire a form field's label / description / hint to its control. */\nexport interface FormFieldIds {\n controlId: string;\n labelId?: string;\n descriptionId?: string;\n hintId?: string;\n helperTextId?: string;\n describedBy?: string;\n}\n\ninterface FormFieldIdOptions {\n /** A caller-supplied id always wins, so consumers can label the control themselves. */\n id?: string;\n label?: string;\n description?: string;\n hint?: string;\n helperText?: boolean;\n}\n\n/**\n * Generates the stable ids a form field needs to be announced correctly. Shared by\n * `Input`, `TextArea`, `Dropdown` and `MultiSelect` so all four wire up identically.\n */\nexport const useFormFieldIds = ({\n id,\n label,\n description,\n hint,\n helperText = false,\n}: FormFieldIdOptions): FormFieldIds => {\n // useId() emits \":r0:\", and a colon is invalid in a CSS id selector, so a consumer's\n // querySelector(`#${id}`) throws. Stripping only the delimiters keeps ids unique.\n const generatedId = `mal-${useId().replace(/[^a-zA-Z0-9_-]/g, '')}-`;\n const controlId = id ?? `${generatedId}control`;\n const labelId = label ? `${generatedId}label` : undefined;\n const descriptionId = description ? `${generatedId}description` : undefined;\n const hintId = hint ? `${generatedId}hint` : undefined;\n const helperTextId = helperText ? `${generatedId}helper` : undefined;\n const describedBy =\n [descriptionId, hintId, helperTextId].filter(Boolean).join(' ') || undefined;\n\n return { controlId, labelId, descriptionId, hintId, helperTextId, describedBy };\n};\n\ninterface BaseFormComponentProps {\n label?: string;\n description?: string;\n hint?: string;\n /** Decorative, so it stays out of the accessible name; shown only with a `hint`. */\n hintIcon?: React.ReactNode;\n rightSideContent?: RightSideContent;\n tooltip?: string;\n required?: boolean;\n requiredIndicator?: RequiredIndicator;\n name: FieldPath<FieldValues>;\n defaultValue?: string;\n loading?: boolean;\n formControl?: Control<FieldValues, unknown>;\n loadingComponent: React.ReactNode;\n children?: FormItemChildren;\n /** Accessibility wiring, from `useFormFieldIds` — see `FormFieldIds`. */\n controlId?: string;\n labelId?: string;\n descriptionId?: string;\n hintId?: string;\n fullWidth?: boolean;\n}\n\nconst BaseFormComponent: React.FC<BaseFormComponentProps> = ({\n label,\n hint,\n hintIcon,\n rightSideContent,\n tooltip,\n name,\n description,\n required = false,\n requiredIndicator = 'optional-suffix',\n loading = false,\n formControl,\n loadingComponent,\n children,\n controlId,\n labelId,\n descriptionId,\n hintId,\n fullWidth = false,\n}) => {\n const finalComponent = formControl ? (\n <FormItem control={formControl} name={name}>\n {children}\n </FormItem>\n ) : (\n renderFormItemChildren(children, NO_FIELD_ERROR)\n );\n\n const topHeader = () => (\n <Spacer direction=\"vertical\" size={4} align=\"stretch\">\n <div className=\"flex justify-between items-start\">\n <Label\n text={label}\n required={required}\n requiredIndicator={requiredIndicator}\n tooltip={tooltip}\n id={labelId}\n // No control is rendered while loading, so an htmlFor would be an orphan.\n htmlFor={loading ? undefined : controlId}\n />\n {(hint || rightSideContent) && (\n <div className=\"flex items-start gap-2\">\n {hint && <Hint text={hint} icon={hintIcon} id={hintId} />}\n {rightSideContent && <RightSide {...rightSideContent} />}\n </div>\n )}\n </div>\n {description && <Description text={description} id={descriptionId} />}\n </Spacer>\n );\n\n const showHeader = label || hint || description || rightSideContent;\n\n return (\n <Spacer direction=\"vertical\" size={6} align=\"stretch\" fullWidth={fullWidth}>\n {showHeader && topHeader()}\n {!loading ? finalComponent : loadingComponent}\n </Spacer>\n );\n};\n\n/**\n * What sits at the far end of a field's label row. Data rather than a node, so nothing\n * arbitrary reaches the row; discriminated so a further kind is additive. Plain text is\n * already `hint`.\n */\nexport type RightSideContent =\n | {\n type?: 'link';\n text: string;\n href: string;\n }\n | {\n /** An action on the form itself, such as showing a panel of help beside it. */\n type: 'button';\n text: string;\n onClick: () => void;\n };\n\nconst RightSide = (content: RightSideContent) => {\n if (content.type === 'button') {\n return (\n <button\n type=\"button\"\n onClick={content.onClick}\n className={`relative top-[3px] shrink-0 cursor-pointer whitespace-nowrap border-0 bg-transparent p-0 text-[length:var(--malachite-font-size-xsmall)] font-medium text-[var(--malachite-accent-foreground)] hover:underline ${FOCUS_RING}`}\n >\n {content.text}\n </button>\n );\n }\n\n const safe = safeHref(content.href);\n\n if (!safe) {\n return null;\n }\n\n return (\n <Link\n href={safe}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n color=\"dimmed\"\n size=\"xsmall\"\n underline={false}\n className=\"shrink-0 whitespace-nowrap inline-flex items-center gap-1 relative top-[3px]\"\n >\n {content.text}\n <ArrowUpRightIcon size={13} />\n </Link>\n );\n};\n\nconst Hint = ({ text, icon, id }: { text?: string; icon?: React.ReactNode; id?: string }) => {\n return (\n <span id={id} className=\"inline-flex items-center gap-1 relative top-[3px] pr-2\">\n {icon && (\n <span aria-hidden=\"true\" className=\"inline-flex text-[var(--malachite-text-dimmed)]\">\n {icon}\n </span>\n )}\n <Text size=\"xsmall\" color=\"dimmed\">\n {text}\n </Text>\n </span>\n );\n};\n\nconst Description = ({ text, id }: { text?: string; id?: string }) => {\n return (\n <div className=\"pl-2 text-left\" id={id}>\n <MarkdownBlock color=\"dimmed\" size=\"small\" text={text ?? ''} omitMargin={true} />\n </div>\n );\n};\n\nexport type RequiredIndicator = 'optional-suffix' | 'asterisk' | 'none';\n\nconst Label = ({\n text,\n required,\n requiredIndicator,\n tooltip,\n id,\n htmlFor,\n}: {\n text?: string;\n required: boolean;\n requiredIndicator: RequiredIndicator;\n tooltip?: string;\n id?: string;\n htmlFor?: string;\n}) => {\n return text ? (\n <div className=\"flex items-center\">\n <label id={id} htmlFor={htmlFor}>\n <Text size=\"xsmall\" color=\"primary\" fontWeight=\"semi-bold\" className=\"pl-2\">\n {text}\n </Text>\n </label>\n {/* Sibling of the <label>, not a child: Testing Library's getByLabelText matches\n on textContent, so a marker inside it breaks getByLabelText('<label>'). */}\n {requiredIndicator === 'optional-suffix' && !required && (\n <span aria-hidden=\"true\">\n <Text size=\"xsmall\" color=\"dimmed\" className=\"ml-1\">\n (Optional)\n </Text>\n </span>\n )}\n {requiredIndicator === 'asterisk' && required && (\n <span\n aria-hidden=\"true\"\n className=\"ml-1 text-[var(--malachite-destructive-foreground,rgb(196,62,62))]\"\n >\n *\n </span>\n )}\n {tooltip && (\n <Tooltip text={tooltip} placement=\"right\" delay={TOOLTIP_DELAY_SECONDS}>\n <button\n type=\"button\"\n aria-label={`More information about ${text}`}\n className={`ml-1 -mt-[2px] inline-flex items-center text-[var(--malachite-text-dimmed)] cursor-help ${FOCUS_RING}`}\n >\n <InfoFilledIcon size={14} />\n </button>\n </Tooltip>\n )}\n </div>\n ) : (\n <div />\n );\n};\n\nexport default BaseFormComponent;\n"],"names":["TOOLTIP_DELAY_SECONDS","useFormFieldIds","id","label","description","hint","helperText","generatedId","useId","controlId","labelId","descriptionId","hintId","helperTextId","describedBy","BaseFormComponent","hintIcon","rightSideContent","tooltip","name","required","requiredIndicator","loading","formControl","loadingComponent","children","fullWidth","finalComponent","jsx","FormItem","renderFormItemChildren","NO_FIELD_ERROR","jsxs","Spacer","Label","Hint","RightSide","Description","content","FOCUS_RING","safe","safeHref","Link","ArrowUpRightIcon","text","icon","Text","MarkdownBlock","htmlFor","Tooltip","InfoFilledIcon"],"mappings":";;;;;;;;;;;;;AAeA,MAAMA,IAAwB,KAyBjBC,KAAkB,CAAC;AAAA,EAC5B,IAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC,IAAa;AACjB,MAAwC;AAGpC,QAAMC,IAAc,OAAOC,EAAA,EAAQ,QAAQ,mBAAmB,EAAE,CAAC,KAC3DC,IAAYP,KAAM,GAAGK,CAAW,WAChCG,IAAUP,IAAQ,GAAGI,CAAW,UAAU,QAC1CI,IAAgBP,IAAc,GAAGG,CAAW,gBAAgB,QAC5DK,IAASP,IAAO,GAAGE,CAAW,SAAS,QACvCM,IAAeP,IAAa,GAAGC,CAAW,WAAW,QACrDO,IACF,CAACH,GAAeC,GAAQC,CAAY,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,KAAK;AAEvE,SAAO,EAAE,WAAAJ,GAAW,SAAAC,GAAS,e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