@stackone/malachite 2.130.0 → 2.130.1
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 +1 -1
- package/dist/components/Breadcrumbs.js +51 -45
- package/dist/components/Breadcrumbs.js.map +1 -1
- package/dist/components/CodeBlock.js +95 -91
- package/dist/components/CodeBlock.js.map +1 -1
- package/dist/components/CopyOverlayButton.js +21 -17
- package/dist/components/CopyOverlayButton.js.map +1 -1
- package/dist/components/Input/Input.js +66 -65
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Modal.js +12 -12
- package/dist/components/Modal.js.map +1 -1
- package/dist/components/Search.js +36 -36
- package/dist/components/Search.js.map +1 -1
- package/dist/components/Table/Table.js +2 -2
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tag.js +80 -70
- package/dist/components/Tag.js.map +1 -1
- package/dist/components/TextArea/TextArea.js +68 -67
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/focusRing.js +8 -6
- package/dist/components/focusRing.js.map +1 -1
- package/dist/components/visuallyHiddenStyle.js +6 -3
- package/dist/components/visuallyHiddenStyle.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","sources":["../../../src/components/TextArea/TextArea.tsx"],"sourcesContent":["import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';\nimport type { Control, FieldPath, FieldValues } from 'react-hook-form';\nimport BaseFormComponent, { type RequiredIndicator, useFormFieldIds } from '../BaseFormComponent';\nimport { Button } from '../Button';\nimport CopyIcon from '../CustomIcons/CopyIcon';\nimport InfoIcon from '../CustomIcons/InfoIcon';\nimport FieldMessage from '../FieldMessage';\nimport { paintedFieldValue } from '../devWarning';\nimport type { ButtonDefinition, TextAreaSize } from './types';\n\n/**\n * `assistant` is the chrome for a field sitting in an AI context (e.g. `Chat.Composer`'s\n * policy-assistant tone): the field's own focus border recolours to the assistant violet\n * instead of the default accent — same indicator, different colour, not an extra one. Same\n * naming precedent as `PillButton`'s own `tone`.\n */\ntype TextAreaTone = 'default' | 'assistant';\n\ninterface TextAreaProps {\n label?: string;\n hint?: string;\n /** Decorative icon drawn before `hint`, such as a glyph for the value's type. Shown only with a `hint`. */\n hintIcon?: React.ReactNode;\n tooltip?: string;\n placeholder?: string;\n icon?: React.ReactNode;\n readOnly?: boolean;\n name: FieldPath<FieldValues> | string;\n description?: string;\n size?: TextAreaSize;\n required?: boolean;\n requiredIndicator?: RequiredIndicator;\n error?: boolean;\n loading?: boolean;\n defaultValue?: string;\n disabled?: boolean;\n prefixValue?: string;\n prefixSecondaryValue?: string;\n ellipsis?: boolean;\n formControl?: Control<FieldValues, unknown>;\n buttons?: ButtonDefinition[];\n onCopyClick?: () => void;\n onChange?: (value: string) => void;\n value?: string;\n onBlur?: () => void;\n /** Key handling the control cannot own, e.g. Enter-to-submit in a chat composer. */\n onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n /**\n * A control that belongs inside the field, pinned bottom-right — a chat composer's send.\n * The field reserves room for it, so text cannot run underneath.\n */\n inFieldAction?: React.ReactNode;\n /** See `TextAreaTone`. Defaults to `'default'`, so no existing field changes. */\n tone?: TextAreaTone;\n helperText?: React.ReactNode;\n rows?: number;\n /**\n * Grows the field from `rows` up to this many lines as content is typed, then scrolls\n * internally rather than growing further. Omitted keeps the field at a fixed `rows`\n * height, the pre-existing behaviour.\n */\n maxRows?: number;\n maxLength?: number;\n resize?: 'none' | 'vertical' | 'horizontal' | 'both';\n /**\n * When false, lines are not soft-wrapped — long content scrolls horizontally\n * instead of wrapping (native `wrap=\"off\"`). Useful for one-value-per-line\n * content like URLs. Defaults to true.\n */\n wrap?: boolean;\n id?: string;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n}\n\nconst getSizeClasses = (size: TextAreaSize): string => {\n switch (size) {\n case 'small':\n return 'text-sm';\n case 'medium':\n return 'text-[length:var(--malachite-font-size-15,15px)] leading-[1.4]';\n case 'large':\n return 'text-base';\n default:\n return 'text-[length:var(--malachite-font-size-15,15px)] leading-[1.4]';\n }\n};\n\n/**\n * A rejection always wins the border colour, regardless of `tone`: a field the caller has\n * flagged invalid stays destructive-red on focus even inside an assistant surface.\n *\n * Each branch spells its two classes out in full rather than interpolating a shared colour\n * variable into them. Tailwind extracts candidates by scanning source text, so a class built\n * at runtime is one Tailwind never sees — and the CSS is simply absent, with no build error.\n * The assistant pair was surviving only because the same literal appears in a spec's\n * assertion, which the content glob also scans: rewording that assertion would have silently\n * dropped the violet focus border.\n */\nconst focusBorderClasses = (isError: boolean, tone: TextAreaTone): string => {\n if (isError) {\n return 'focus-within:border-[var(--malachite-destructive-border-hover)] hover:border-[var(--malachite-destructive-border-hover)]';\n }\n\n if (tone === 'assistant') {\n return 'focus-within:border-[var(--malachite-assistant-foreground)] hover:border-[var(--malachite-assistant-foreground)]';\n }\n\n return 'focus-within:border-[var(--malachite-control-border-hover)] hover:border-[var(--malachite-control-border-hover)]';\n};\n\n// Shared by the static min-height and the auto-grow ceiling, so a field's grown height\n// lines up with the same row metrics its resting height already used.\nconst rowHeightPx = (size: TextAreaSize, rows: number): number => {\n const baseHeight = {\n small: 20,\n medium: 22,\n large: 24,\n }[size];\n\n // Every size renders `py-[12px]`, so the vertical padding is 24 regardless of size.\n const padding = 24;\n\n return baseHeight * rows + padding;\n};\n\nconst getMinHeight = (size: TextAreaSize, rows: number): string => `${rowHeightPx(size, rows)}px`;\n\nconst TextArea: React.FC<TextAreaProps> = ({\n label,\n hint,\n hintIcon,\n tooltip,\n placeholder,\n icon,\n name,\n required,\n requiredIndicator,\n error,\n description,\n loading = false,\n readOnly = false,\n size = 'medium',\n defaultValue,\n disabled,\n prefixValue,\n prefixSecondaryValue,\n // ellipsis = false,\n formControl,\n buttons,\n onCopyClick,\n onChange,\n onKeyDown,\n inFieldAction,\n tone = 'default',\n value,\n onBlur,\n helperText,\n rows = 4,\n maxRows,\n maxLength,\n resize = 'vertical',\n wrap = true,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const { controlId, labelId, descriptionId, hintId, helperTextId } = useFormFieldIds({\n id,\n label,\n description,\n hint,\n helperText: true,\n });\n const [internalValue, setInternalValue] = useState(defaultValue || '');\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n\n // Reset-then-measure rather than growing incrementally: `scrollHeight` on a field already\n // taller than its content stays stuck at that height, so the reset is what lets a paste\n // followed by a delete shrink the field back down, not just grow it. Mutates the DOM\n // directly instead of round-tripping through React state, so typing a character never\n // re-renders this component just to change its own height.\n const resizeToFit = useCallback(() => {\n const el = textareaRef.current;\n if (!el || maxRows === undefined) {\n return;\n }\n\n const maxHeight = rowHeightPx(size, maxRows);\n el.style.height = 'auto';\n const nextHeight = Math.min(el.scrollHeight, maxHeight);\n el.style.height = `${nextHeight}px`;\n el.style.overflowY = el.scrollHeight > maxHeight ? 'auto' : 'hidden';\n }, [maxRows, size]);\n\n // Catches every change `onChange` on the element itself would miss: the initial mount,\n // and a value the parent sets from outside (e.g. clearing the composer after send).\n // biome-ignore lint/correctness/useExhaustiveDependencies: `value` is not read in the body, but a controlled `value` changing from outside is exactly the case `onChange` cannot see, so the effect has to re-run on it anyway.\n useLayoutEffect(() => {\n resizeToFit();\n }, [resizeToFit, value]);\n\n const isControlled = value !== undefined;\n const paintedValue = (formValue: unknown): string =>\n paintedFieldValue({\n component: 'TextArea',\n name,\n value,\n formValue,\n defaultValue,\n bound: !!formControl,\n uncontrolledValue: internalValue,\n });\n\n const handleChange =\n (reportToForm?: (value: unknown) => void) =>\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n const newValue = e.target.value;\n if (!isControlled) {\n setInternalValue(newValue);\n }\n // The browser has already applied the keystroke to the element by the time this\n // fires, so `scrollHeight` already reflects it — no need to wait for a re-render.\n resizeToFit();\n onChange?.(newValue);\n reportToForm?.(newValue);\n };\n\n const hasPrefix = icon || prefixValue || prefixSecondaryValue;\n\n const errorMessageId = `${helperTextId}-error`;\n\n const renderTextArea = (\n isError: boolean,\n resolvedHelperText?: React.ReactNode,\n onFieldChange?: (value: unknown) => void,\n onFieldBlur?: () => void,\n errorMessage?: string,\n formValue?: unknown,\n ) => {\n const textAreaValue = paintedValue(formValue);\n // The icon is the only signal a consumer-forced `error` has; beside a message it is\n // duplication, and it crowds the suffix next to a reveal or copy control.\n const showErrorIcon = isError && !errorMessage;\n const hasSuffix =\n showErrorIcon || (onCopyClick && disabled && textAreaValue) || buttons?.length;\n const describedBy =\n [\n descriptionId,\n hintId,\n resolvedHelperText ? helperTextId : undefined,\n errorMessage ? errorMessageId : undefined,\n ]\n .filter(Boolean)\n .join(' ') || undefined;\n const wrapperClasses = [\n 'relative',\n 'flex',\n 'w-full',\n 'rounded-xl',\n 'border border-solid',\n disabled\n ? 'bg-[var(--malachite-card-dimmed-background)]'\n : 'bg-[var(--malachite-card-background)]',\n 'transition-colors duration-200 ease-in-out',\n isError ? 'shadow-error' : 'shadow-default',\n isError\n ? 'border-[var(--malachite-destructive-border)]'\n : 'border-[var(--malachite-card-border)]',\n // One border-hover colour, not two overlapping utilities for the same states: a\n // duplicate pair used to sit above this one, fixed at the default accent — since\n // it targeted the identical `focus-within`/`hover` selectors, a `tone` swap here\n // would otherwise leave a second, conflicting colour in the class list.\n //\n // No separate ring on top of it: the recoloured border IS this field's focus\n // indicator, the same as the default tone's. Adding a ring here drew a second,\n // concentric outline around the first on `assistant` — the field already has one,\n // it only needed to change colour.\n disabled ? '' : focusBorderClasses(isError, tone),\n ]\n .filter(Boolean)\n .join(' ');\n\n const textAreaClasses = [\n 'flex-1',\n 'bg-transparent',\n 'border-none',\n 'outline-none',\n 'text-[var(--malachite-text-primary)]',\n 'placeholder:text-[var(--malachite-text-placeholder)]',\n 'disabled:text-[var(--malachite-text-dimmed)]',\n 'disabled:cursor-not-allowed',\n getSizeClasses(size),\n // Emitted as one side each when an action sits in the field: `px` and `pr` are\n // the same specificity, so which wins would rest on Tailwind's output order.\n inFieldAction ? 'pl-[16px] pr-[52px]' : 'px-[16px]',\n 'py-[12px]',\n resize === 'none'\n ? 'resize-none'\n : resize === 'vertical'\n ? 'resize-y'\n : resize === 'horizontal'\n ? 'resize-x'\n : 'resize',\n wrap ? '' : 'whitespace-pre overflow-x-auto min-w-0',\n ]\n .filter(Boolean)\n .join(' ');\n\n const textAreaElement = (\n <textarea\n ref={textareaRef}\n id={controlId}\n placeholder={placeholder}\n value={textAreaValue}\n onChange={handleChange(onFieldChange)}\n onBlur={() => {\n onBlur?.();\n onFieldBlur?.();\n }}\n onKeyDown={onKeyDown}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-invalid={isError || undefined}\n aria-required={required || undefined}\n aria-describedby={describedBy}\n disabled={disabled || !!prefixValue || !!prefixSecondaryValue || readOnly}\n readOnly={readOnly}\n wrap={wrap ? undefined : 'off'}\n rows={rows}\n maxLength={maxLength}\n style={{ minHeight: getMinHeight(size, rows) }}\n className={textAreaClasses}\n name={name}\n />\n );\n\n return (\n <div className={wrapperClasses}>\n {hasPrefix && (\n <div className=\"flex pt-3 pl-3 pr-1 flex-shrink-0 pointer-events-none\">\n <CompositeIcon\n prefixValue={prefixValue}\n prefixSecondaryValue={prefixSecondaryValue}\n icon={icon}\n />\n </div>\n )}\n\n {textAreaElement}\n\n {inFieldAction && (\n <div className=\"absolute bottom-2 right-2 flex items-center\">\n {inFieldAction}\n </div>\n )}\n\n {hasSuffix && (\n <div className=\"flex pt-3 pl-1 pr-3 flex-shrink-0\">\n <Suffix\n error={showErrorIcon}\n disabled={disabled}\n defaultValue={textAreaValue}\n onCopyClick={onCopyClick}\n />\n <TextAreaButtons buttons={buttons} />\n </div>\n )}\n </div>\n );\n };\n\n const renderHelperText = () =>\n helperText ? (\n <div\n id={helperTextId}\n className=\"mt-1 text-[length:var(--malachite-font-size-small,13px)] text-left pl-2 text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n >\n {helperText}\n </div>\n ) : null;\n\n const renderErrorMessage = (errorMessage?: string) => (\n <FieldMessage id={errorMessageId} message={errorMessage} spaced />\n );\n\n return (\n <BaseFormComponent\n label={label}\n hint={hint}\n hintIcon={hintIcon}\n tooltip={tooltip}\n name={name}\n required={required}\n requiredIndicator={requiredIndicator}\n loading={loading}\n formControl={formControl}\n description={description}\n controlId={controlId}\n labelId={labelId}\n descriptionId={descriptionId}\n hintId={hintId}\n loadingComponent={<LoadingTextArea size={size} rows={rows} />}\n >\n {({ error: fieldError, message, onFieldChange, onFieldBlur, value: formValue }) => {\n const isError = error ?? fieldError;\n // `error={false}` opts out of the resolver entirely, message included: a\n // screen that has dealt with the rejection its own way would otherwise keep\n // reporting it in destructive text and through `aria-describedby`.\n\n // The message is its own line rather than a replacement for the helper text:\n // a field that explains what it wants still has to say why what was typed was\n // rejected, and dropping one for the other left the field marked red with\n // nothing anywhere saying what was wrong.\n const errorMessage = error === false ? undefined : message;\n\n return (\n <>\n {renderTextArea(\n isError,\n helperText,\n onFieldChange,\n onFieldBlur,\n errorMessage,\n formValue,\n )}\n {renderHelperText()}\n {renderErrorMessage(errorMessage)}\n </>\n );\n }}\n </BaseFormComponent>\n );\n};\n\nconst LoadingTextArea: React.FC<{ size?: TextAreaSize; rows?: number }> = ({\n size = 'medium',\n rows = 4,\n}) => {\n return (\n // Decorative height placeholder — kept out of the a11y tree so it is not announced\n // as an unlabelled box (same as Skeleton and LoadingInput).\n <div\n aria-busy=\"true\"\n aria-hidden=\"true\"\n 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)]\"\n style={{ minHeight: getMinHeight(size, rows) }}\n />\n );\n};\n\nconst CompositeIcon: React.FC<{\n prefixValue?: string;\n prefixSecondaryValue?: string;\n icon?: React.ReactNode;\n}> = ({ prefixValue, prefixSecondaryValue, icon }) => {\n return (\n <div className=\"flex items-start gap-1\">\n {icon && (\n <span className=\"flex items-center justify-center text-[var(--malachite-text-dimmed)] w-4 h-4 flex-shrink-0 mt-1\">\n {icon}\n </span>\n )}\n {prefixValue && (\n <span className=\"text-[length:var(--malachite-font-size-15,15px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap\">\n {prefixValue}\n </span>\n )}\n {prefixSecondaryValue && (\n <span className=\"text-[length:var(--malachite-font-size-15,15px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap\">\n {prefixSecondaryValue}\n </span>\n )}\n </div>\n );\n};\n\nconst Suffix: React.FC<{\n error?: boolean;\n disabled?: boolean;\n defaultValue?: string;\n onCopyClick?: () => void;\n}> = ({ error, disabled, defaultValue, onCopyClick }) => {\n return (\n <div className=\"flex items-start gap-1\">\n {error && (\n // Decorative: the rejection is carried by the message beneath the field.\n <div\n aria-hidden=\"true\"\n className=\"flex items-center justify-center w-5 h-5 flex-shrink-0 mt-1\"\n >\n <InfoIcon\n size={16}\n className=\"text-[var(--malachite-destructive-foreground,rgb(196,62,62))]\"\n />\n </div>\n )}\n {onCopyClick && disabled && defaultValue && (\n <button\n onClick={() => {\n navigator.clipboard.writeText(defaultValue);\n onCopyClick();\n }}\n type=\"button\"\n aria-label=\"Copy to clipboard\"\n className=\"flex items-center justify-center w-5 h-5 hover:bg-[var(--malachite-primary-border)] rounded transition-colors flex-shrink-0 mt-1\"\n >\n <CopyIcon size={16} />\n </button>\n )}\n </div>\n );\n};\n\nconst TextAreaButtons: React.FC<{\n buttons?: ButtonDefinition[];\n}> = ({ buttons }) => {\n if (!buttons?.length) {\n return null;\n }\n\n return (\n <div className=\"flex flex-col gap-1 mt-1\">\n {buttons.map((button) => (\n <Button\n key={button.label}\n variant={button.danger ? 'destructive' : 'outline'}\n size=\"small\"\n disabled={button.disabled}\n icon={button.icon}\n tooltip={button.tooltip}\n onClick={button.onClick}\n >\n {button.label}\n </Button>\n ))}\n </div>\n );\n};\n\nexport default TextArea;\n"],"names":["getSizeClasses","size","focusBorderClasses","isError","tone","rowHeightPx","rows","getMinHeight","TextArea","label","hint","hintIcon","tooltip","placeholder","icon","name","required","requiredIndicator","error","description","loading","readOnly","defaultValue","disabled","prefixValue","prefixSecondaryValue","formControl","buttons","onCopyClick","onChange","onKeyDown","inFieldAction","value","onBlur","helperText","maxRows","maxLength","resize","wrap","id","ariaLabel","ariaLabelledBy","controlId","labelId","descriptionId","hintId","helperTextId","useFormFieldIds","internalValue","setInternalValue","useState","textareaRef","useRef","resizeToFit","useCallback","el","maxHeight","nextHeight","useLayoutEffect","isControlled","paintedValue","formValue","paintedFieldValue","handleChange","reportToForm","e","newValue","hasPrefix","errorMessageId","renderTextArea","resolvedHelperText","onFieldChange","onFieldBlur","errorMessage","textAreaValue","showErrorIcon","hasSuffix","describedBy","wrapperClasses","textAreaClasses","textAreaElement","jsx","jsxs","CompositeIcon","Suffix","TextAreaButtons","renderHelperText","renderErrorMessage","FieldMessage","BaseFormComponent","LoadingTextArea","fieldError","message","Fragment","InfoIcon","CopyIcon","button","Button"],"mappings":";;;;;;;;AA2EA,MAAMA,KAAiB,CAACC,MAA+B;AACnD,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAaMC,KAAqB,CAACC,GAAkBC,MACtCD,IACO,6HAGPC,MAAS,cACF,qHAGJ,oHAKLC,IAAc,CAACJ,GAAoBK,OAClB;AAAA,EACf,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,GACTL,CAAI,IAKcK,IAFJ,IAKdC,IAAe,CAACN,GAAoBK,MAAyB,GAAGD,EAAYJ,GAAMK,CAAI,CAAC,MAEvFE,KAAoC,CAAC;AAAA,EACvC,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,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A,EAAA;AAAA,EAGPlE,KAAeL,KAAYD,KACxB,gBAAA2D;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,SAAS,MAAM;AACX,kBAAU,UAAU,UAAU3D,CAAY,GAC1CM,EAAA;AAAA,MACJ;AAAA,MACA,MAAK;AAAA,MACL,cAAW;AAAA,MACX,WAAU;AAAA,MAEV,UAAA,gBAAAqD,EAACc,IAAA,EAAS,MAAM,GAAA,CAAI;AAAA,IAAA;AAAA,EAAA;AACxB,GAER,GAIFV,KAED,CAAC,EAAE,SAAA1D,QACCA,KAAA,QAAAA,EAAS,2BAKT,OAAA,EAAI,WAAU,4BACV,UAAAA,EAAQ,IAAI,CAACqE,MACV,gBAAAf;AAAA,EAACgB;AAAA,EAAA;AAAA,IAEG,SAASD,EAAO,SAAS,gBAAgB;AAAA,IACzC,MAAK;AAAA,IACL,UAAUA,EAAO;AAAA,IACjB,MAAMA,EAAO;AAAA,IACb,SAASA,EAAO;AAAA,IAChB,SAASA,EAAO;AAAA,IAEf,UAAAA,EAAO;AAAA,EAAA;AAAA,EARHA,EAAO;AAAA,CAUnB,GACL,IAlBO;"}
|
|
1
|
+
{"version":3,"file":"TextArea.js","sources":["../../../src/components/TextArea/TextArea.tsx"],"sourcesContent":["import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';\nimport type { Control, FieldPath, FieldValues } from 'react-hook-form';\nimport BaseFormComponent, { type RequiredIndicator, useFormFieldIds } from '../BaseFormComponent';\nimport { Button } from '../Button';\nimport CopyIcon from '../CustomIcons/CopyIcon';\nimport InfoIcon from '../CustomIcons/InfoIcon';\nimport FieldMessage from '../FieldMessage';\nimport { paintedFieldValue } from '../devWarning';\nimport { FOCUS_BORDER } from '../focusRing';\nimport type { ButtonDefinition, TextAreaSize } from './types';\n\n/**\n * `assistant` is the chrome for a field sitting in an AI context (e.g. `Chat.Composer`'s\n * policy-assistant tone): the field's own focus border recolours to the assistant violet\n * instead of the default accent — same indicator, different colour, not an extra one. Same\n * naming precedent as `PillButton`'s own `tone`.\n */\ntype TextAreaTone = 'default' | 'assistant';\n\ninterface TextAreaProps {\n label?: string;\n hint?: string;\n /** Decorative icon drawn before `hint`, such as a glyph for the value's type. Shown only with a `hint`. */\n hintIcon?: React.ReactNode;\n tooltip?: string;\n placeholder?: string;\n icon?: React.ReactNode;\n readOnly?: boolean;\n name: FieldPath<FieldValues> | string;\n description?: string;\n size?: TextAreaSize;\n required?: boolean;\n requiredIndicator?: RequiredIndicator;\n error?: boolean;\n loading?: boolean;\n defaultValue?: string;\n disabled?: boolean;\n prefixValue?: string;\n prefixSecondaryValue?: string;\n ellipsis?: boolean;\n formControl?: Control<FieldValues, unknown>;\n buttons?: ButtonDefinition[];\n onCopyClick?: () => void;\n onChange?: (value: string) => void;\n value?: string;\n onBlur?: () => void;\n /** Key handling the control cannot own, e.g. Enter-to-submit in a chat composer. */\n onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n /**\n * A control that belongs inside the field, pinned bottom-right — a chat composer's send.\n * The field reserves room for it, so text cannot run underneath.\n */\n inFieldAction?: React.ReactNode;\n /** See `TextAreaTone`. Defaults to `'default'`, so no existing field changes. */\n tone?: TextAreaTone;\n helperText?: React.ReactNode;\n rows?: number;\n /**\n * Grows the field from `rows` up to this many lines as content is typed, then scrolls\n * internally rather than growing further. Omitted keeps the field at a fixed `rows`\n * height, the pre-existing behaviour.\n */\n maxRows?: number;\n maxLength?: number;\n resize?: 'none' | 'vertical' | 'horizontal' | 'both';\n /**\n * When false, lines are not soft-wrapped — long content scrolls horizontally\n * instead of wrapping (native `wrap=\"off\"`). Useful for one-value-per-line\n * content like URLs. Defaults to true.\n */\n wrap?: boolean;\n id?: string;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n}\n\nconst getSizeClasses = (size: TextAreaSize): string => {\n switch (size) {\n case 'small':\n return 'text-sm';\n case 'medium':\n return 'text-[length:var(--malachite-font-size-15,15px)] leading-[1.4]';\n case 'large':\n return 'text-base';\n default:\n return 'text-[length:var(--malachite-font-size-15,15px)] leading-[1.4]';\n }\n};\n\n/**\n * A rejection always wins the border colour, regardless of `tone`: a field the caller has\n * flagged invalid stays destructive-red on focus even inside an assistant surface.\n *\n * Every class is a complete literal, here or in `focusRing.ts` for the shared focus border,\n * never a shared colour interpolated into one. Tailwind extracts candidates by scanning source\n * text, so a class built at runtime is one Tailwind never sees — and the CSS is simply absent,\n * with no build error.\n * The assistant pair was surviving only because the same literal appears in a spec's\n * assertion, which the content glob also scans: rewording that assertion would have silently\n * dropped the violet focus border.\n */\nconst focusBorderClasses = (isError: boolean, tone: TextAreaTone): string => {\n if (isError) {\n return 'focus-within:border-[var(--malachite-destructive-border-hover)] hover:border-[var(--malachite-destructive-border-hover)]';\n }\n\n if (tone === 'assistant') {\n return 'focus-within:border-[var(--malachite-assistant-foreground)] hover:border-[var(--malachite-assistant-foreground)]';\n }\n\n return `${FOCUS_BORDER} hover:not-focus-within:border-[var(--malachite-control-border-hover)]`;\n};\n\n// Shared by the static min-height and the auto-grow ceiling, so a field's grown height\n// lines up with the same row metrics its resting height already used.\nconst rowHeightPx = (size: TextAreaSize, rows: number): number => {\n const baseHeight = {\n small: 20,\n medium: 22,\n large: 24,\n }[size];\n\n // Every size renders `py-[12px]`, so the vertical padding is 24 regardless of size.\n const padding = 24;\n\n return baseHeight * rows + padding;\n};\n\nconst getMinHeight = (size: TextAreaSize, rows: number): string => `${rowHeightPx(size, rows)}px`;\n\nconst TextArea: React.FC<TextAreaProps> = ({\n label,\n hint,\n hintIcon,\n tooltip,\n placeholder,\n icon,\n name,\n required,\n requiredIndicator,\n error,\n description,\n loading = false,\n readOnly = false,\n size = 'medium',\n defaultValue,\n disabled,\n prefixValue,\n prefixSecondaryValue,\n // ellipsis = false,\n formControl,\n buttons,\n onCopyClick,\n onChange,\n onKeyDown,\n inFieldAction,\n tone = 'default',\n value,\n onBlur,\n helperText,\n rows = 4,\n maxRows,\n maxLength,\n resize = 'vertical',\n wrap = true,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const { controlId, labelId, descriptionId, hintId, helperTextId } = useFormFieldIds({\n id,\n label,\n description,\n hint,\n helperText: true,\n });\n const [internalValue, setInternalValue] = useState(defaultValue || '');\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n\n // Reset-then-measure rather than growing incrementally: `scrollHeight` on a field already\n // taller than its content stays stuck at that height, so the reset is what lets a paste\n // followed by a delete shrink the field back down, not just grow it. Mutates the DOM\n // directly instead of round-tripping through React state, so typing a character never\n // re-renders this component just to change its own height.\n const resizeToFit = useCallback(() => {\n const el = textareaRef.current;\n if (!el || maxRows === undefined) {\n return;\n }\n\n const maxHeight = rowHeightPx(size, maxRows);\n el.style.height = 'auto';\n const nextHeight = Math.min(el.scrollHeight, maxHeight);\n el.style.height = `${nextHeight}px`;\n el.style.overflowY = el.scrollHeight > maxHeight ? 'auto' : 'hidden';\n }, [maxRows, size]);\n\n // Catches every change `onChange` on the element itself would miss: the initial mount,\n // and a value the parent sets from outside (e.g. clearing the composer after send).\n // biome-ignore lint/correctness/useExhaustiveDependencies: `value` is not read in the body, but a controlled `value` changing from outside is exactly the case `onChange` cannot see, so the effect has to re-run on it anyway.\n useLayoutEffect(() => {\n resizeToFit();\n }, [resizeToFit, value]);\n\n const isControlled = value !== undefined;\n const paintedValue = (formValue: unknown): string =>\n paintedFieldValue({\n component: 'TextArea',\n name,\n value,\n formValue,\n defaultValue,\n bound: !!formControl,\n uncontrolledValue: internalValue,\n });\n\n const handleChange =\n (reportToForm?: (value: unknown) => void) =>\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n const newValue = e.target.value;\n if (!isControlled) {\n setInternalValue(newValue);\n }\n // The browser has already applied the keystroke to the element by the time this\n // fires, so `scrollHeight` already reflects it — no need to wait for a re-render.\n resizeToFit();\n onChange?.(newValue);\n reportToForm?.(newValue);\n };\n\n const hasPrefix = icon || prefixValue || prefixSecondaryValue;\n\n const errorMessageId = `${helperTextId}-error`;\n\n const renderTextArea = (\n isError: boolean,\n resolvedHelperText?: React.ReactNode,\n onFieldChange?: (value: unknown) => void,\n onFieldBlur?: () => void,\n errorMessage?: string,\n formValue?: unknown,\n ) => {\n const textAreaValue = paintedValue(formValue);\n // The icon is the only signal a consumer-forced `error` has; beside a message it is\n // duplication, and it crowds the suffix next to a reveal or copy control.\n const showErrorIcon = isError && !errorMessage;\n const hasSuffix =\n showErrorIcon || (onCopyClick && disabled && textAreaValue) || buttons?.length;\n const describedBy =\n [\n descriptionId,\n hintId,\n resolvedHelperText ? helperTextId : undefined,\n errorMessage ? errorMessageId : undefined,\n ]\n .filter(Boolean)\n .join(' ') || undefined;\n const wrapperClasses = [\n 'relative',\n 'flex',\n 'w-full',\n 'rounded-xl',\n 'border border-solid',\n disabled\n ? 'bg-[var(--malachite-card-dimmed-background)]'\n : 'bg-[var(--malachite-card-background)]',\n 'transition-colors duration-200 ease-in-out',\n isError ? 'shadow-error' : 'shadow-default',\n isError\n ? 'border-[var(--malachite-destructive-border)]'\n : 'border-[var(--malachite-card-border)]',\n // One border-hover colour, not two overlapping utilities for the same states: a\n // duplicate pair used to sit above this one, fixed at the default accent — since\n // it targeted the identical `focus-within`/`hover` selectors, a `tone` swap here\n // would otherwise leave a second, conflicting colour in the class list.\n //\n // No separate ring on top of it: the recoloured border IS this field's focus\n // indicator, the same as the default tone's. Adding a ring here drew a second,\n // concentric outline around the first on `assistant` — the field already has one,\n // it only needed to change colour.\n disabled ? '' : focusBorderClasses(isError, tone),\n ]\n .filter(Boolean)\n .join(' ');\n\n const textAreaClasses = [\n 'flex-1',\n 'bg-transparent',\n 'border-none',\n 'outline-none',\n 'text-[var(--malachite-text-primary)]',\n 'placeholder:text-[var(--malachite-text-placeholder)]',\n 'disabled:text-[var(--malachite-text-dimmed)]',\n 'disabled:cursor-not-allowed',\n getSizeClasses(size),\n // Emitted as one side each when an action sits in the field: `px` and `pr` are\n // the same specificity, so which wins would rest on Tailwind's output order.\n inFieldAction ? 'pl-[16px] pr-[52px]' : 'px-[16px]',\n 'py-[12px]',\n resize === 'none'\n ? 'resize-none'\n : resize === 'vertical'\n ? 'resize-y'\n : resize === 'horizontal'\n ? 'resize-x'\n : 'resize',\n wrap ? '' : 'whitespace-pre overflow-x-auto min-w-0',\n ]\n .filter(Boolean)\n .join(' ');\n\n const textAreaElement = (\n <textarea\n ref={textareaRef}\n id={controlId}\n placeholder={placeholder}\n value={textAreaValue}\n onChange={handleChange(onFieldChange)}\n onBlur={() => {\n onBlur?.();\n onFieldBlur?.();\n }}\n onKeyDown={onKeyDown}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-invalid={isError || undefined}\n aria-required={required || undefined}\n aria-describedby={describedBy}\n disabled={disabled || !!prefixValue || !!prefixSecondaryValue || readOnly}\n readOnly={readOnly}\n wrap={wrap ? undefined : 'off'}\n rows={rows}\n maxLength={maxLength}\n style={{ minHeight: getMinHeight(size, rows) }}\n className={textAreaClasses}\n name={name}\n />\n );\n\n return (\n <div className={wrapperClasses}>\n {hasPrefix && (\n <div className=\"flex pt-3 pl-3 pr-1 flex-shrink-0 pointer-events-none\">\n <CompositeIcon\n prefixValue={prefixValue}\n prefixSecondaryValue={prefixSecondaryValue}\n icon={icon}\n />\n </div>\n )}\n\n {textAreaElement}\n\n {inFieldAction && (\n <div className=\"absolute bottom-2 right-2 flex items-center\">\n {inFieldAction}\n </div>\n )}\n\n {hasSuffix && (\n <div className=\"flex pt-3 pl-1 pr-3 flex-shrink-0\">\n <Suffix\n error={showErrorIcon}\n disabled={disabled}\n defaultValue={textAreaValue}\n onCopyClick={onCopyClick}\n />\n <TextAreaButtons buttons={buttons} />\n </div>\n )}\n </div>\n );\n };\n\n const renderHelperText = () =>\n helperText ? (\n <div\n id={helperTextId}\n className=\"mt-1 text-[length:var(--malachite-font-size-small,13px)] text-left pl-2 text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n >\n {helperText}\n </div>\n ) : null;\n\n const renderErrorMessage = (errorMessage?: string) => (\n <FieldMessage id={errorMessageId} message={errorMessage} spaced />\n );\n\n return (\n <BaseFormComponent\n label={label}\n hint={hint}\n hintIcon={hintIcon}\n tooltip={tooltip}\n name={name}\n required={required}\n requiredIndicator={requiredIndicator}\n loading={loading}\n formControl={formControl}\n description={description}\n controlId={controlId}\n labelId={labelId}\n descriptionId={descriptionId}\n hintId={hintId}\n loadingComponent={<LoadingTextArea size={size} rows={rows} />}\n >\n {({ error: fieldError, message, onFieldChange, onFieldBlur, value: formValue }) => {\n const isError = error ?? fieldError;\n // `error={false}` opts out of the resolver entirely, message included: a\n // screen that has dealt with the rejection its own way would otherwise keep\n // reporting it in destructive text and through `aria-describedby`.\n\n // The message is its own line rather than a replacement for the helper text:\n // a field that explains what it wants still has to say why what was typed was\n // rejected, and dropping one for the other left the field marked red with\n // nothing anywhere saying what was wrong.\n const errorMessage = error === false ? undefined : message;\n\n return (\n <>\n {renderTextArea(\n isError,\n helperText,\n onFieldChange,\n onFieldBlur,\n errorMessage,\n formValue,\n )}\n {renderHelperText()}\n {renderErrorMessage(errorMessage)}\n </>\n );\n }}\n </BaseFormComponent>\n );\n};\n\nconst LoadingTextArea: React.FC<{ size?: TextAreaSize; rows?: number }> = ({\n size = 'medium',\n rows = 4,\n}) => {\n return (\n // Decorative height placeholder — kept out of the a11y tree so it is not announced\n // as an unlabelled box (same as Skeleton and LoadingInput).\n <div\n aria-busy=\"true\"\n aria-hidden=\"true\"\n 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)]\"\n style={{ minHeight: getMinHeight(size, rows) }}\n />\n );\n};\n\nconst CompositeIcon: React.FC<{\n prefixValue?: string;\n prefixSecondaryValue?: string;\n icon?: React.ReactNode;\n}> = ({ prefixValue, prefixSecondaryValue, icon }) => {\n return (\n <div className=\"flex items-start gap-1\">\n {icon && (\n <span className=\"flex items-center justify-center text-[var(--malachite-text-dimmed)] w-4 h-4 flex-shrink-0 mt-1\">\n {icon}\n </span>\n )}\n {prefixValue && (\n <span className=\"text-[length:var(--malachite-font-size-15,15px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap\">\n {prefixValue}\n </span>\n )}\n {prefixSecondaryValue && (\n <span className=\"text-[length:var(--malachite-font-size-15,15px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap\">\n {prefixSecondaryValue}\n </span>\n )}\n </div>\n );\n};\n\nconst Suffix: React.FC<{\n error?: boolean;\n disabled?: boolean;\n defaultValue?: string;\n onCopyClick?: () => void;\n}> = ({ error, disabled, defaultValue, onCopyClick }) => {\n return (\n <div className=\"flex items-start gap-1\">\n {error && (\n // Decorative: the rejection is carried by the message beneath the field.\n <div\n aria-hidden=\"true\"\n className=\"flex items-center justify-center w-5 h-5 flex-shrink-0 mt-1\"\n >\n <InfoIcon\n size={16}\n className=\"text-[var(--malachite-destructive-foreground,rgb(196,62,62))]\"\n />\n </div>\n )}\n {onCopyClick && disabled && defaultValue && (\n <button\n onClick={() => {\n navigator.clipboard.writeText(defaultValue);\n onCopyClick();\n }}\n type=\"button\"\n aria-label=\"Copy to clipboard\"\n className=\"flex items-center justify-center w-5 h-5 hover:bg-[var(--malachite-primary-border)] rounded transition-colors flex-shrink-0 mt-1\"\n >\n <CopyIcon size={16} />\n </button>\n )}\n </div>\n );\n};\n\nconst TextAreaButtons: React.FC<{\n buttons?: ButtonDefinition[];\n}> = ({ buttons }) => {\n if (!buttons?.length) {\n return null;\n }\n\n return (\n <div className=\"flex flex-col gap-1 mt-1\">\n {buttons.map((button) => (\n <Button\n key={button.label}\n variant={button.danger ? 'destructive' : 'outline'}\n size=\"small\"\n disabled={button.disabled}\n icon={button.icon}\n tooltip={button.tooltip}\n onClick={button.onClick}\n >\n {button.label}\n </Button>\n ))}\n </div>\n );\n};\n\nexport default TextArea;\n"],"names":["getSizeClasses","size","focusBorderClasses","isError","tone","FOCUS_BORDER","rowHeightPx","rows","getMinHeight","TextArea","label","hint","hintIcon","tooltip","placeholder","icon","name","required","requiredIndicator","error","description","loading","readOnly","defaultValue","disabled","prefixValue","prefixSecondaryValue","formControl","buttons","onCopyClick","onChange","onKeyDown","inFieldAction","value","onBlur","helperText","maxRows","maxLength","resize","wrap","id","ariaLabel","ariaLabelledBy","controlId","labelId","descriptionId","hintId","helperTextId","useFormFieldIds","internalValue","setInternalValue","useState","textareaRef","useRef","resizeToFit","useCallback","el","maxHeight","nextHeight","useLayoutEffect","isControlled","paintedValue","formValue","paintedFieldValue","handleChange","reportToForm","e","newValue","hasPrefix","errorMessageId","renderTextArea","resolvedHelperText","onFieldChange","onFieldBlur","errorMessage","textAreaValue","showErrorIcon","hasSuffix","describedBy","wrapperClasses","textAreaClasses","textAreaElement","jsx","jsxs","CompositeIcon","Suffix","TextAreaButtons","renderHelperText","renderErrorMessage","FieldMessage","BaseFormComponent","LoadingTextArea","fieldError","message","Fragment","InfoIcon","CopyIcon","button","Button"],"mappings":";;;;;;;;;AA4EA,MAAMA,KAAiB,CAACC,MAA+B;AACnD,UAAQA,GAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB,GAcMC,KAAqB,CAACC,GAAkBC,MACtCD,IACO,6HAGPC,MAAS,cACF,qHAGJ,GAAGC,EAAY,0EAKpBC,IAAc,CAACL,GAAoBM,OAClB;AAAA,EACf,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,GACTN,CAAI,IAKcM,IAFJ,IAKdC,IAAe,CAACP,GAAoBM,MAAyB,GAAGD,EAAYL,GAAMM,CAAI,CAAC,MAEvFE,KAAoC,CAAC;AAAA,EACvC,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA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AAA2D;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,SAAS,MAAM;AACX,kBAAU,UAAU,UAAU3D,CAAY,GAC1CM,EAAA;AAAA,MACJ;AAAA,MACA,MAAK;AAAA,MACL,cAAW;AAAA,MACX,WAAU;AAAA,MAEV,UAAA,gBAAAqD,EAACc,IAAA,EAAS,MAAM,GAAA,CAAI;AAAA,IAAA;AAAA,EAAA;AACxB,GAER,GAIFV,KAED,CAAC,EAAE,SAAA1D,QACCA,KAAA,QAAAA,EAAS,2BAKT,OAAA,EAAI,WAAU,4BACV,UAAAA,EAAQ,IAAI,CAACqE,MACV,gBAAAf;AAAA,EAACgB;AAAA,EAAA;AAAA,IAEG,SAASD,EAAO,SAAS,gBAAgB;AAAA,IACzC,MAAK;AAAA,IACL,UAAUA,EAAO;AAAA,IACjB,MAAMA,EAAO;AAAA,IACb,SAASA,EAAO;AAAA,IAChB,SAASA,EAAO;AAAA,IAEf,UAAAA,EAAO;AAAA,EAAA;AAAA,EARHA,EAAO;AAAA,CAUnB,GACL,IAlBO;"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
const t = "outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-text-primary)]", s = "outline-none focus-visible:[outline:2px_solid_var(--malachite-text-primary)] focus-visible:[outline-offset:-2px]", i = "pointer-events-none absolute inset-0 hidden [outline:2px_solid_var(--malachite-text-primary)] [outline-offset:-2px]", n = `${i} z-[2] group-focus-visible:block`, l = "outline-none has-[[role=radio]:focus-visible]:outline-offset-2 has-[[role=radio]:focus-visible]:[outline:2px_solid_var(--malachite-text-primary)]",
|
|
1
|
+
const t = "outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-text-primary)]", s = "outline-none focus-visible:[outline:2px_solid_var(--malachite-text-primary)] focus-visible:[outline-offset:-2px]", i = "pointer-events-none absolute inset-0 hidden [outline:2px_solid_var(--malachite-text-primary)] [outline-offset:-2px]", n = `${i} z-[2] group-focus-visible:block`, l = "outline-none has-[[role=radio]:focus-visible]:outline-offset-2 has-[[role=radio]:focus-visible]:[outline:2px_solid_var(--malachite-text-primary)]", r = "outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-selection-bar-foreground)]", c = "outline-none focus-visible:[outline:2px_solid_var(--malachite-inline-confirm-foreground)] focus-visible:[outline-offset:-2px]", u = "outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-close-button-inverse-hover-foreground,rgb(255,255,255))]", a = (o, e = !0) => {
|
|
2
2
|
try {
|
|
3
3
|
return o.matches(":focus-visible");
|
|
4
4
|
} catch {
|
|
5
5
|
return e;
|
|
6
6
|
}
|
|
7
|
-
};
|
|
7
|
+
}, _ = "var(--malachite-accent-foreground, rgb(2, 122, 66))", f = "focus-within:border-[var(--malachite-accent-foreground,rgb(2,122,66))]";
|
|
8
8
|
export {
|
|
9
|
+
f as FOCUS_BORDER,
|
|
10
|
+
_ as FOCUS_BORDER_COLOR,
|
|
9
11
|
t as FOCUS_RING,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
u as FOCUS_RING_CLOSE_BUTTON_INVERSE,
|
|
13
|
+
c as FOCUS_RING_INLINE_CONFIRM_INSET,
|
|
12
14
|
s as FOCUS_RING_INSET,
|
|
13
15
|
n as FOCUS_RING_INSET_OVERLAY,
|
|
14
16
|
i as FOCUS_RING_INSET_OVERLAY_HIDDEN,
|
|
15
|
-
|
|
17
|
+
r as FOCUS_RING_SELECTION_BAR,
|
|
16
18
|
l as FOCUS_RING_WITHIN_RADIO,
|
|
17
|
-
|
|
19
|
+
a as isFocusVisible
|
|
18
20
|
};
|
|
19
21
|
//# sourceMappingURL=focusRing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focusRing.js","sources":["../../src/components/focusRing.ts"],"sourcesContent":["// Shared keyboard focus indicator for interactive components.\n\n/** Standard focus ring — sits 2px outside the control. */\nexport const FOCUS_RING =\n 'outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-text-primary)]';\n\n/**\n * Inset focus ring — drawn 2px inside the element edge. Use for full-bleed elements\n * inside an `overflow-hidden` container (e.g. Surface.Row) where an outset outline\n * would be clipped.\n */\nexport const FOCUS_RING_INSET =\n 'outline-none focus-visible:[outline:2px_solid_var(--malachite-text-primary)] focus-visible:[outline-offset:-2px]';\n\nexport const FOCUS_RING_INSET_OVERLAY_HIDDEN =\n 'pointer-events-none absolute inset-0 hidden [outline:2px_solid_var(--malachite-text-primary)] [outline-offset:-2px]';\n\n/** `FOCUS_RING_INSET` drawn by an overlay while its `group` ancestor has keyboard focus. */\nexport const FOCUS_RING_INSET_OVERLAY = `${FOCUS_RING_INSET_OVERLAY_HIDDEN} z-[2] group-focus-visible:block`;\n\n/** Ring drawn on a wrapper when a control *inside* it takes focus. */\nexport const FOCUS_RING_WITHIN =\n 'outline-none has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:[outline:2px_solid_var(--malachite-text-primary)]';\n\n/**\n * As `FOCUS_RING_WITHIN`, for a card whose control is a `role=\"radio\"` beside its links:\n * `:has(:focus-visible)` would also match a focused link and draw a second ring.\n */\nexport const FOCUS_RING_WITHIN_RADIO =\n 'outline-none has-[[role=radio]:focus-visible]:outline-offset-2 has-[[role=radio]:focus-visible]:[outline:2px_solid_var(--malachite-text-primary)]';\n\n/** Ring for a control on the SelectionBar, where `FOCUS_RING` would be invisible. */\nexport const FOCUS_RING_SELECTION_BAR =\n 'outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-selection-bar-foreground)]';\n\n/** Inset ring for a control on the InlineConfirm chip. */\nexport const FOCUS_RING_INLINE_CONFIRM_INSET =\n 'outline-none focus-visible:[outline:2px_solid_var(--malachite-inline-confirm-foreground)] focus-visible:[outline-offset:-2px]';\n\n/** Ring for `CloseButton surface=\"inverse\"`, where `FOCUS_RING` would be invisible on the dark panel. */\nexport const FOCUS_RING_CLOSE_BUTTON_INVERSE =\n 'outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-close-button-inverse-hover-foreground,rgb(255,255,255))]';\n\n/** `fallback` is the answer where the browser can't match `:focus-visible`. */\nexport const isFocusVisible = (element: Element, fallback = true): boolean => {\n try {\n return element.matches(':focus-visible');\n } catch {\n return fallback;\n }\n};\n"],"names":["FOCUS_RING","FOCUS_RING_INSET","FOCUS_RING_INSET_OVERLAY_HIDDEN","FOCUS_RING_INSET_OVERLAY","FOCUS_RING_WITHIN_RADIO","FOCUS_RING_SELECTION_BAR","FOCUS_RING_INLINE_CONFIRM_INSET","FOCUS_RING_CLOSE_BUTTON_INVERSE","isFocusVisible","element","fallback"],"mappings":"AAGO,MAAMA,IACT,+GAOSC,IACT,oHAESC,IACT,uHAGSC,IAA2B,GAAGD,CAA+B,oCAU7DE,IACT,qJAGSC,IACT,2HAGSC,IACT,iIAGSC,IACT,yJAGSC,IAAiB,CAACC,GAAkBC,IAAW,OAAkB;AAC1E,MAAI;AACA,WAAOD,EAAQ,QAAQ,gBAAgB;AAAA,EAC3C,QAAQ;AACJ,WAAOC;AAAA,EACX;AACJ;"}
|
|
1
|
+
{"version":3,"file":"focusRing.js","sources":["../../src/components/focusRing.ts"],"sourcesContent":["// Shared keyboard focus indicator for interactive components.\n\n/** Standard focus ring — sits 2px outside the control. */\nexport const FOCUS_RING =\n 'outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-text-primary)]';\n\n/**\n * Inset focus ring — drawn 2px inside the element edge. Use for full-bleed elements\n * inside an `overflow-hidden` container (e.g. Surface.Row) where an outset outline\n * would be clipped.\n */\nexport const FOCUS_RING_INSET =\n 'outline-none focus-visible:[outline:2px_solid_var(--malachite-text-primary)] focus-visible:[outline-offset:-2px]';\n\nexport const FOCUS_RING_INSET_OVERLAY_HIDDEN =\n 'pointer-events-none absolute inset-0 hidden [outline:2px_solid_var(--malachite-text-primary)] [outline-offset:-2px]';\n\n/** `FOCUS_RING_INSET` drawn by an overlay while its `group` ancestor has keyboard focus. */\nexport const FOCUS_RING_INSET_OVERLAY = `${FOCUS_RING_INSET_OVERLAY_HIDDEN} z-[2] group-focus-visible:block`;\n\n/** Ring drawn on a wrapper when a control *inside* it takes focus. */\nexport const FOCUS_RING_WITHIN =\n 'outline-none has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:[outline:2px_solid_var(--malachite-text-primary)]';\n\n/**\n * As `FOCUS_RING_WITHIN`, for a card whose control is a `role=\"radio\"` beside its links:\n * `:has(:focus-visible)` would also match a focused link and draw a second ring.\n */\nexport const FOCUS_RING_WITHIN_RADIO =\n 'outline-none has-[[role=radio]:focus-visible]:outline-offset-2 has-[[role=radio]:focus-visible]:[outline:2px_solid_var(--malachite-text-primary)]';\n\n/** Ring for a control on the SelectionBar, where `FOCUS_RING` would be invisible. */\nexport const FOCUS_RING_SELECTION_BAR =\n 'outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-selection-bar-foreground)]';\n\n/** Inset ring for a control on the InlineConfirm chip. */\nexport const FOCUS_RING_INLINE_CONFIRM_INSET =\n 'outline-none focus-visible:[outline:2px_solid_var(--malachite-inline-confirm-foreground)] focus-visible:[outline-offset:-2px]';\n\n/** Ring for `CloseButton surface=\"inverse\"`, where `FOCUS_RING` would be invisible on the dark panel. */\nexport const FOCUS_RING_CLOSE_BUTTON_INVERSE =\n 'outline-none focus-visible:outline-offset-2 focus-visible:[outline:2px_solid_var(--malachite-close-button-inverse-hover-foreground,rgb(255,255,255))]';\n\n/** `fallback` is the answer where the browser can't match `:focus-visible`. */\nexport const isFocusVisible = (element: Element, fallback = true): boolean => {\n try {\n return element.matches(':focus-visible');\n } catch {\n return fallback;\n }\n};\n\n/**\n * A field's border while it holds focus, which is its focus indicator: the accent, dark enough\n * to read at 3:1 against the field in both themes. `control.borderHover`, the hover colour, is\n * too faint for that (1.5:1 on white).\n */\nexport const FOCUS_BORDER_COLOR = 'var(--malachite-accent-foreground, rgb(2, 122, 66))';\n\n/** `FOCUS_BORDER_COLOR` as the class a field's bordered wrapper takes. */\nexport const FOCUS_BORDER =\n 'focus-within:border-[var(--malachite-accent-foreground,rgb(2,122,66))]';\n"],"names":["FOCUS_RING","FOCUS_RING_INSET","FOCUS_RING_INSET_OVERLAY_HIDDEN","FOCUS_RING_INSET_OVERLAY","FOCUS_RING_WITHIN_RADIO","FOCUS_RING_SELECTION_BAR","FOCUS_RING_INLINE_CONFIRM_INSET","FOCUS_RING_CLOSE_BUTTON_INVERSE","isFocusVisible","element","fallback","FOCUS_BORDER_COLOR","FOCUS_BORDER"],"mappings":"AAGO,MAAMA,IACT,+GAOSC,IACT,oHAESC,IACT,uHAGSC,IAA2B,GAAGD,CAA+B,oCAU7DE,IACT,qJAGSC,IACT,2HAGSC,IACT,iIAGSC,IACT,yJAGSC,IAAiB,CAACC,GAAkBC,IAAW,OAAkB;AAC1E,MAAI;AACA,WAAOD,EAAQ,QAAQ,gBAAgB;AAAA,EAC3C,QAAQ;AACJ,WAAOC;AAAA,EACX;AACJ,GAOaC,IAAqB,uDAGrBC,IACT;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const e = {
|
|
2
2
|
position: "absolute",
|
|
3
3
|
width: 1,
|
|
4
4
|
height: 1,
|
|
@@ -8,9 +8,12 @@ const i = {
|
|
|
8
8
|
overflow: "hidden",
|
|
9
9
|
clip: "rect(0, 0, 0, 0)",
|
|
10
10
|
clipPath: "inset(50%)",
|
|
11
|
-
whiteSpace: "nowrap"
|
|
11
|
+
whiteSpace: "nowrap",
|
|
12
|
+
// Read as written, not in a container's casing: Chrome puts `text-transform` into the
|
|
13
|
+
// accessible name, so hidden text inside an uppercase Tag was announced in capitals.
|
|
14
|
+
textTransform: "none"
|
|
12
15
|
};
|
|
13
16
|
export {
|
|
14
|
-
|
|
17
|
+
e as VISUALLY_HIDDEN_STYLE
|
|
15
18
|
};
|
|
16
19
|
//# sourceMappingURL=visuallyHiddenStyle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visuallyHiddenStyle.js","sources":["../../src/components/visuallyHiddenStyle.ts"],"sourcesContent":["import type React from 'react';\n\n// Inline rather than Tailwind's `sr-only`, which exists only inside malachite's shadow roots.\nexport const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n margin: -1,\n padding: 0,\n border: 0,\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n clipPath: 'inset(50%)',\n whiteSpace: 'nowrap',\n};\n"],"names":["VISUALLY_HIDDEN_STYLE"],"mappings":"AAGO,MAAMA,IAA6C;AAAA,EACtD,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AAAA,EACV,YAAY;
|
|
1
|
+
{"version":3,"file":"visuallyHiddenStyle.js","sources":["../../src/components/visuallyHiddenStyle.ts"],"sourcesContent":["import type React from 'react';\n\n// Inline rather than Tailwind's `sr-only`, which exists only inside malachite's shadow roots.\nexport const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {\n position: 'absolute',\n width: 1,\n height: 1,\n margin: -1,\n padding: 0,\n border: 0,\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n clipPath: 'inset(50%)',\n whiteSpace: 'nowrap',\n // Read as written, not in a container's casing: Chrome puts `text-transform` into the\n // accessible name, so hidden text inside an uppercase Tag was announced in capitals.\n textTransform: 'none',\n};\n"],"names":["VISUALLY_HIDDEN_STYLE"],"mappings":"AAGO,MAAMA,IAA6C;AAAA,EACtD,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AAAA,EACV,YAAY;AAAA;AAAA;AAAA,EAGZ,eAAe;AACnB;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1293,9 +1293,9 @@ declare interface CodeBlockProps {
|
|
|
1293
1293
|
*/
|
|
1294
1294
|
origin?: 'assistant';
|
|
1295
1295
|
};
|
|
1296
|
-
/** Names the scrollable region. Defaults to "Code". */
|
|
1296
|
+
/** Names the scrollable region, and the copy button as "Copy" and this. Defaults to "Code". */
|
|
1297
1297
|
'aria-label'?: string;
|
|
1298
|
-
/** Names the scrollable region by a visible label instead of `aria-label`. */
|
|
1298
|
+
/** Names the scrollable region and the copy button by a visible label instead of `aria-label`. */
|
|
1299
1299
|
'aria-labelledby'?: string;
|
|
1300
1300
|
}
|
|
1301
1301
|
|
|
@@ -4384,7 +4384,10 @@ export declare interface ModalProps {
|
|
|
4384
4384
|
};
|
|
4385
4385
|
/** Divider under the header. Default: false. */
|
|
4386
4386
|
headerDivider?: boolean;
|
|
4387
|
-
/**
|
|
4387
|
+
/**
|
|
4388
|
+
* Pinned action row below the scrolling body. Its actions sit at the end, the primary last,
|
|
4389
|
+
* whatever they're wrapped in: a bare button, a `FormActions`, or a row that doesn't fill it.
|
|
4390
|
+
*/
|
|
4388
4391
|
footer?: default_2.ReactNode;
|
|
4389
4392
|
size?: ModalSize;
|
|
4390
4393
|
/**
|
|
@@ -6521,6 +6524,12 @@ export declare interface TagProps {
|
|
|
6521
6524
|
/** False when something else already reads `tooltip` to assistive tech, such as a card's
|
|
6522
6525
|
* description, so it is not announced twice. */
|
|
6523
6526
|
tooltipDescribesTag?: boolean;
|
|
6527
|
+
/**
|
|
6528
|
+
* What assistive tech reads in place of the visible value, such as "Severity: high" for a
|
|
6529
|
+
* tag showing "High". Rendered as visually hidden text, since `aria-label` on a plain span is
|
|
6530
|
+
* not honoured. Also names the remove button.
|
|
6531
|
+
*/
|
|
6532
|
+
'aria-label'?: string;
|
|
6524
6533
|
className?: string;
|
|
6525
6534
|
}
|
|
6526
6535
|
|