@stll/ui 0.93.0 → 0.93.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.
|
@@ -33,5 +33,5 @@ type TextareaProps = React.ComponentProps<"textarea"> & {
|
|
|
33
33
|
*/
|
|
34
34
|
showCount?: boolean | undefined;
|
|
35
35
|
};
|
|
36
|
-
declare const Textarea: ({ className, id, name, disabled, value, defaultValue, size, appearance, unstyled, inline, fieldSizing, maxRows, showCount, dir, onChange, style, ...props }: TextareaProps) => React.JSX.Element;
|
|
36
|
+
declare const Textarea: ({ className, id, name, disabled, value, defaultValue, size, appearance, unstyled, inline, fieldSizing, maxRows, rows, showCount, dir, onChange, style, ...props }: TextareaProps) => React.JSX.Element;
|
|
37
37
|
export { Textarea, type TextareaProps };
|
|
@@ -9,7 +9,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
9
9
|
import { useState } from "react";
|
|
10
10
|
import { Field } from "@base-ui/react/field";
|
|
11
11
|
// src/components/textarea.tsx
|
|
12
|
-
const Textarea = ({ className, id, name, disabled, value, defaultValue, size = CONTROL_SIZE.default, appearance = "default", unstyled = false, inline = false, fieldSizing = "content", maxRows, showCount = false, dir, onChange, style, ...props }) => {
|
|
12
|
+
const Textarea = ({ className, id, name, disabled, value, defaultValue, size = CONTROL_SIZE.default, appearance = "default", unstyled = false, inline = false, fieldSizing = "content", maxRows, rows, showCount = false, dir, onChange, style, ...props }) => {
|
|
13
13
|
const controlSize = typeof size === "number" ? CONTROL_SIZE.default : size;
|
|
14
14
|
const composer = appearance === "composer";
|
|
15
15
|
const fieldEditorClass = inline ? cn(INLINE_FIELD_CLASS_NAME, "resize-none [--textarea-pb:0px] [--textarea-pt:0px]") : cn("w-full rounded-[inherit] px-[calc(--spacing(3)-1px)] outline-none", TEXTAREA_SIZE_CLASS_NAMES[controlSize], fieldSizing === "content" && TEXTAREA_FLOOR_CLASS_NAMES[controlSize]);
|
|
@@ -49,10 +49,12 @@ const Textarea = ({ className, id, name, disabled, value, defaultValue, size = C
|
|
|
49
49
|
countsUncontrolled,
|
|
50
50
|
trackValue
|
|
51
51
|
]);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const rowLimits = textareaRowLimits({
|
|
53
|
+
fieldSizing,
|
|
54
|
+
maxRows,
|
|
55
|
+
rows,
|
|
56
|
+
style
|
|
57
|
+
});
|
|
56
58
|
return /* @__PURE__ */ jsxs("span", {
|
|
57
59
|
className: cn(composer && "block w-full", !composer && inline && "relative inline-flex w-full", counted && "relative", !composer && !unstyled && !inline && "border-input bg-background text-foreground ring-ring/24 has-focus-visible:border-ring has-aria-invalid:border-destructive/36 has-focus-visible:has-aria-invalid:border-destructive/64 has-focus-visible:has-aria-invalid:ring-destructive/16 dark:bg-input/32 dark:has-aria-invalid:ring-destructive/24 relative inline-flex w-full rounded-lg border text-base shadow-xs/5 not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-has-disabled:has-not-focus-visible:not-has-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] has-focus-visible:ring-[3px] has-disabled:opacity-64 has-[:disabled,:focus-visible,[aria-invalid]]:shadow-none sm:text-sm dark:not-has-disabled:has-not-focus-visible:not-has-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)]", className) || void 0,
|
|
58
60
|
"data-appearance": appearance,
|
|
@@ -66,12 +68,13 @@ const Textarea = ({ className, id, name, disabled, value, defaultValue, size = C
|
|
|
66
68
|
value,
|
|
67
69
|
defaultValue,
|
|
68
70
|
render: /* @__PURE__ */ jsx("textarea", {
|
|
69
|
-
className: cn(editorClass, fieldSizing === "content" ? "field-sizing-content" : "field-sizing-fixed resize-none", "pt-(--textarea-pt) pb-(--textarea-pb)", counted && "[--textarea-pb:--spacing(6)]",
|
|
71
|
+
className: cn(editorClass, fieldSizing === "content" ? "field-sizing-content" : "field-sizing-fixed resize-none", "pt-(--textarea-pt) pb-(--textarea-pb)", counted && "[--textarea-pb:--spacing(6)]", rowLimits.className),
|
|
70
72
|
"data-slot": "textarea",
|
|
73
|
+
rows,
|
|
71
74
|
...props,
|
|
72
75
|
onChange: handleChange,
|
|
73
76
|
dir: contentDir.dir,
|
|
74
|
-
style:
|
|
77
|
+
style: rowLimits.style
|
|
75
78
|
})
|
|
76
79
|
}), counted ? /* @__PURE__ */ jsxs("span", {
|
|
77
80
|
className: "text-muted-foreground pointer-events-none absolute end-3 bottom-1.5 text-xs tabular-nums",
|
|
@@ -95,6 +98,38 @@ const TEXTAREA_FLOOR_CLASS_NAMES = {
|
|
|
95
98
|
[CONTROL_SIZE.default]: "min-h-17.5 max-sm:min-h-20.5",
|
|
96
99
|
[CONTROL_SIZE.lg]: "min-h-18.5 max-sm:min-h-21.5"
|
|
97
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* The height limits `maxRows` sets, as classes and the variables they read.
|
|
103
|
+
* One line is `1lh`; the field's own block padding is added on top so the
|
|
104
|
+
* last allowed line is not cut. The size's floor height gives way, as
|
|
105
|
+
* `min-height` would otherwise win over a smaller cap. A field that grows
|
|
106
|
+
* with its content ignores `rows`, so an empty one would be a single line
|
|
107
|
+
* and a longer placeholder would spill out of it: with a cap, the floor is
|
|
108
|
+
* `rows` lines instead, never more than the cap.
|
|
109
|
+
*/
|
|
110
|
+
function textareaRowLimits({ fieldSizing, maxRows, rows, style }) {
|
|
111
|
+
if (maxRows === void 0) return {
|
|
112
|
+
className: void 0,
|
|
113
|
+
style
|
|
114
|
+
};
|
|
115
|
+
const minRows = rows === void 0 || fieldSizing !== "content" ? void 0 : Math.min(rows, maxRows);
|
|
116
|
+
const cap = "max-h-[calc(var(--textarea-max-rows)*1lh+var(--textarea-pt)+var(--textarea-pb))]";
|
|
117
|
+
if (minRows === void 0) return {
|
|
118
|
+
className: `${cap} min-h-0 max-sm:min-h-0`,
|
|
119
|
+
style: {
|
|
120
|
+
...style,
|
|
121
|
+
"--textarea-max-rows": maxRows
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
className: `${cap} min-h-[calc(var(--textarea-min-rows)*1lh+var(--textarea-pt)+var(--textarea-pb))] max-sm:min-h-[calc(var(--textarea-min-rows)*1lh+var(--textarea-pt)+var(--textarea-pb))]`,
|
|
126
|
+
style: {
|
|
127
|
+
...style,
|
|
128
|
+
"--textarea-max-rows": maxRows,
|
|
129
|
+
"--textarea-min-rows": minRows
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
98
133
|
function textLength(value) {
|
|
99
134
|
if (value === void 0) return 0;
|
|
100
135
|
return String(value).length;
|
package/package.json
CHANGED