mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-22 05:15:32 +01:00
migrate 3
This commit is contained in:
1 parent
de8b3959b3
commit
5285d081e4
29 files changed
+740
-83
No files matched your search
@@ -0,0 +1,88 @@
|
||||
.text-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
|
||||
gap: var(--space-3);
|
||||
|
||||
cursor: text;
|
||||
|
||||
font: inherit;
|
||||
color: var(--gray-11);
|
||||
|
||||
&[data-variant="bubble"] {
|
||||
border-radius: var(--max-size);
|
||||
|
||||
background-color: var(--gray-1);
|
||||
outline: var(--outline-interactive);
|
||||
|
||||
input {
|
||||
padding: var(--space-3) var(--space-4);
|
||||
}
|
||||
}
|
||||
|
||||
&[data-variant="form"] {
|
||||
border-bottom: var(--space-1) solid var(--gray-6);
|
||||
|
||||
input {
|
||||
padding: var(--space-2);
|
||||
}
|
||||
}
|
||||
|
||||
&[data-has-icon="true"] {
|
||||
padding-left: var(--space-3);
|
||||
|
||||
input {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-within {
|
||||
outline: var(--outline-focus);
|
||||
box-shadow: var(--shadow-focus);
|
||||
}
|
||||
|
||||
&[data-disabled="true"] {
|
||||
cursor: not-allowed;
|
||||
background-color: var(--gray-3);
|
||||
|
||||
color: var(--gray-9);
|
||||
|
||||
input::placeholder {
|
||||
color: var(--gray-6);
|
||||
}
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
input {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: inherit;
|
||||
|
||||
font: inherit;
|
||||
|
||||
color: var(--gray-12);
|
||||
|
||||
&::placeholder {
|
||||
color: var(--gray-9);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
&[data-align="center"] {
|
||||
text-align: center;
|
||||
}
|
||||
&[data-align="right"] {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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"> {
|
||||
children?: ReactNode;
|
||||
align?: "left" | "center" | "right";
|
||||
autoWidth?: boolean;
|
||||
variant?: "bubble" | "form";
|
||||
}
|
||||
|
||||
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
||||
(
|
||||
{
|
||||
children,
|
||||
className,
|
||||
autoWidth,
|
||||
placeholder,
|
||||
align,
|
||||
disabled,
|
||||
value,
|
||||
onChange,
|
||||
variant = "bubble",
|
||||
...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 (
|
||||
<div
|
||||
{...props}
|
||||
className={classNames(styles["text-field"], className)}
|
||||
data-has-icon={children !== undefined}
|
||||
data-disabled={disabled}
|
||||
data-variant={variant}
|
||||
>
|
||||
{children}
|
||||
|
||||
<input
|
||||
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`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user