1.8 KB80 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import type {ForwardedRef, ReactNode} from 'react';
9import type {ReactProps} from './utils';
10
11import * as stylex from '@stylexjs/stylex';
12import {forwardRef, useId} from 'react';
13import {Column} from './Flex';
14
15export const textFieldStyles = stylex.create({
16 root: {
17 gap: 0,
18 },
19 label: {
20 marginBlock: '1px',
21 },
22 input: {
23 boxSizing: 'border-box',
24 height: '26px',
25 padding: '0 9px',
26 marginBlock: 0,
27 minWidth: '100px',
28 width: '100%',
29 background: 'var(--input-background)',
30 color: 'var(--input-foreground)',
31 border: '1px solid var(--dropdown-border)',
32 outline: {
33 default: 'none',
34 ':focus-visible': '1px solid var(--focus-border)',
35 },
36 outlineOffset: '-1px',
37 },
38});
39
40export const TextField = forwardRef(
41 (
42 {
43 children,
44 xstyle,
45 containerXstyle,
46 value,
47 width,
48 ...rest
49 }: {
50 children?: ReactNode;
51 xstyle?: stylex.StyleXStyles;
52 containerXstyle?: stylex.StyleXStyles;
53 value?: string;
54 width?: string;
55 placeholder?: string;
56 readOnly?: boolean;
57 } & ReactProps<HTMLInputElement>,
58 ref: ForwardedRef<HTMLInputElement>,
59 ) => {
60 const id = useId();
61 return (
62 <Column xstyle={[textFieldStyles.root, containerXstyle ?? null]} style={{width}} alignStart>
63 {children && (
64 <label htmlFor={id} {...stylex.props(textFieldStyles.label)}>
65 {children}
66 </label>
67 )}
68 <input
69 {...stylex.props(textFieldStyles.input, xstyle)}
70 type="text"
71 id={id}
72 value={value}
73 {...rest}
74 ref={ref}
75 />
76 </Column>
77 );
78 },
79);
80