Skip to content

Commit e3345db

Browse files
committed
Add NativeSelect helper component
1 parent ca02273 commit e3345db

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

website/app/data-converter/pageClient.tsx

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
defaultSystem,
1111
Clipboard,
1212
Input,
13-
NativeSelect,
13+
NativeSelect as ChakraNativeSelect,
1414
Button,
1515
Link,
1616
} from "@chakra-ui/react";
@@ -157,21 +157,18 @@ const ConverterBox = ({
157157
<Box mb="4" />
158158
<Box display="flex" gap="3" alignItems="center">
159159
Type
160-
<NativeSelect.Root>
161-
<NativeSelect.Field
162-
value={inputType}
163-
onChange={(e) =>
164-
onChangeState({ inputType: e.currentTarget.value as any })
165-
}
166-
>
167-
{Object.entries(dataTypes).map(([value, name]) => (
168-
<option key={value} value={value}>
169-
{name}
170-
</option>
171-
))}
172-
</NativeSelect.Field>
173-
<NativeSelect.Indicator />
174-
</NativeSelect.Root>
160+
<NativeSelect
161+
value={inputType}
162+
onChange={(e) =>
163+
onChangeState({ inputType: e.currentTarget.value as any })
164+
}
165+
>
166+
{Object.entries(dataTypes).map(([value, name]) => (
167+
<option key={value} value={value}>
168+
{name}
169+
</option>
170+
))}
171+
</NativeSelect>
175172
</Box>
176173
<Box mb="3" />
177174
<Box>
@@ -202,21 +199,18 @@ const ConverterBox = ({
202199
<Box mb="3" />
203200
<Box display="flex" gap="3" alignItems="center">
204201
Type
205-
<NativeSelect.Root>
206-
<NativeSelect.Field
207-
value={outputType}
208-
onChange={(e) =>
209-
onChangeState({ outputType: e.currentTarget.value as any })
210-
}
211-
>
212-
{Object.entries(dataTypes).map(([value, name]) => (
213-
<option key={value} value={value}>
214-
{name}
215-
</option>
216-
))}
217-
</NativeSelect.Field>
218-
<NativeSelect.Indicator />
219-
</NativeSelect.Root>
202+
<NativeSelect
203+
value={outputType}
204+
onChange={(e) =>
205+
onChangeState({ outputType: e.currentTarget.value as any })
206+
}
207+
>
208+
{Object.entries(dataTypes).map(([value, name]) => (
209+
<option key={value} value={value}>
210+
{name}
211+
</option>
212+
))}
213+
</NativeSelect>
220214
</Box>
221215
<Box mb="3" />
222216
<Box>
@@ -235,6 +229,21 @@ const ConverterBox = ({
235229
);
236230
};
237231

232+
const NativeSelect = ({
233+
value,
234+
onChange,
235+
children,
236+
...props
237+
}: Omit<ChakraNativeSelect.RootProps, "value" | "onChange" | "children"> &
238+
Pick<ChakraNativeSelect.FieldProps, "value" | "onChange" | "children">) => {
239+
return (
240+
<ChakraNativeSelect.Root {...props}>
241+
<ChakraNativeSelect.Field {...{ value, onChange, children }} />
242+
<ChakraNativeSelect.Indicator />
243+
</ChakraNativeSelect.Root>
244+
);
245+
};
246+
238247
const useConverters = () => {
239248
const [states, setStates] = useLocalStorage<ConverterState[]>(
240249
"converterStates",

0 commit comments

Comments
 (0)