-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathInputGroup.tsx
More file actions
82 lines (76 loc) · 1.83 KB
/
Copy pathInputGroup.tsx
File metadata and controls
82 lines (76 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { forwardRef } from 'react';
import { descriptors, Flex, Input, Text } from '../customizables';
import { common, type PropsOfComponent, type ThemableCssProp } from '../styledSystem';
type InputGroupProps = PropsOfComponent<typeof Input>;
export const InputGroup = forwardRef<
HTMLInputElement,
InputGroupProps & {
groupPrefix?: string;
groupSuffix?: string;
}
>((props, ref) => {
const { sx, groupPrefix, groupSuffix, ...rest } = props;
const inputBorder = groupPrefix
? {
borderStartStartRadius: '0',
borderEndStartRadius: '0',
}
: {
borderStartEndRadius: '0',
borderEndEndRadius: '0',
};
const textProps: ThemableCssProp = t => ({
paddingInline: t.space.$2,
borderStartEndRadius: '0',
borderEndEndRadius: '0',
width: 'fit-content',
display: 'flex',
alignItems: 'center',
});
return (
<Flex
elementDescriptor={descriptors.formInputGroup}
direction='row'
hasError={rest.hasError}
sx={theme => ({
position: 'relative',
zIndex: 1,
...common.borderVariants(theme).normal,
'&:has(:focus-visible),&[data-focus-within="true"]': {
...common.borderVariants(theme, {
focusRing: true,
}).normal['&:focus-visible'],
},
})}
>
{groupPrefix && (
<Text
colorScheme='secondary'
sx={textProps}
>
{groupPrefix}
</Text>
)}
<Input
maxLength={25}
sx={[
{
...inputBorder,
},
sx,
]}
variant='unstyled'
ref={ref}
{...rest}
/>
{groupSuffix && (
<Text
colorScheme='secondary'
sx={textProps}
>
{groupSuffix}
</Text>
)}
</Flex>
);
});