antagonist controls

This commit is contained in:
tresabhi committed 2026-11-10 14:54:22 -06:00
1 parent f74b66dd5f
commit f071a77fc0
18 files changed
+316 -259

No files matched your search

@@ -29,6 +29,24 @@
}
}
&[data-size="minor"] {
gap: var(--space-1);
font-size: var(--font-size-minor);
&[data-variant="bubble"] input {
padding: var(--space-2) var(--space-3);
}
&[data-variant="form"] input {
padding: var(--space-1);
}
/* the icon's gap already separates it from the input */
&[data-has-icon="true"] input {
padding-left: 0;
}
}
&[data-has-icon="true"] {
padding-left: var(--space-3);
@@ -37,6 +55,10 @@
}
}
&[data-has-suffix="true"] {
padding-right: var(--space-3);
}
&:focus-within {
outline: var(--outline-focus);
box-shadow: var(--shadow-focus);
@@ -60,6 +82,7 @@
input {
min-width: 0;
width: auto;
flex: 1;
background: none;
@@ -84,5 +107,9 @@
&[data-align="right"] {
text-align: right;
}
&[data-auto-width="true"] {
field-sizing: content;
}
}
}
@@ -1,20 +1,20 @@
import {
forwardRef,
useCallback,
useImperativeHandle,
useRef,
type ChangeEvent,
type ComponentProps,
type ReactNode,
} from "react";
import { classNames } from "../../ui/classNames";
import styles from "./index.module.css";
export interface TextFieldProps extends ComponentProps<"input"> {
export interface TextFieldProps extends Omit<ComponentProps<"input">, "size"> {
children?: ReactNode;
align?: "left" | "center" | "right";
autoWidth?: boolean;
variant?: "bubble" | "form";
size?: "regular" | "minor";
childrenAsSuffix?: boolean;
}
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
@@ -27,25 +27,15 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
align,
disabled,
value,
onChange,
variant = "bubble",
size = "regular",
childrenAsSuffix,
...props
},
ref,
) => {
const input = useRef<HTMLInputElement>(null);
const handleChange = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
if (autoWidth && input.current) {
input.current.style.width = `${event.target.value.length || event.target.placeholder.length}ch`;
}
onChange?.(event);
},
[onChange],
);
useImperativeHandle(ref, () => input.current!, []);
return (
@@ -55,20 +45,21 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
data-has-icon={children !== undefined}
data-disabled={disabled}
data-variant={variant}
data-size={size}
data-has-suffix={childrenAsSuffix}
>
{children}
{!childrenAsSuffix && children}
<input
data-auto-width={autoWidth}
data-align={align === "left" ? undefined : align}
disabled={disabled}
ref={input}
onChange={handleChange}
placeholder={placeholder}
value={value}
style={{
width: `${value?.toString().length || placeholder?.length || 0}ch`,
}}
/>
{childrenAsSuffix && children}
</div>
);
},