input list

This commit is contained in:
Ari Sosnovsky committed 2021-11-16 21:46:07 -05:00
1 parent 1dd11eae18
commit 25f21fcc93
2 files changed
+41 -5

No files matched your search

@@ -0,0 +1,29 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { useState } from "react";
import { usePageTheme } from "~/styles/page";
import InputList from "./InputList";
export default {
title: 'Inputs/InputList',
component: InputList,
parameters: { actions: { argTypesRegex: '^on.*' } },
} as ComponentMeta<typeof InputList>;
const Template: ComponentStory<typeof InputList> = args => {
const {classes} = usePageTheme({});
const [value, setValue] = useState('')
return <div className={classes.page}>
<InputList {...args} current={value} onChange={setValue}/>
</div>
}
export const SimpleText = Template.bind({})
SimpleText.args = {
label: "Entity ID",
options: [
'Bob',
'Martin',
"Toots"
]
}
+12 -5
View File
@@ -1,4 +1,6 @@
import { useState } from "react";
import InputWrapper from "./InputWrapper";
import { useInputTextStyles } from "./styles";
export interface Props<T extends string> {
@@ -13,11 +15,16 @@ export default function InputList<T extends string>({
current, options, onChange, label,
...selattr
}: Props<T>) {
return <InputWrapper label={label}>
<select {...selattr} value={current} onChange={e => {
e.preventDefault();
onChange(e.currentTarget.value);
}}>
const {classes} = useInputTextStyles({});
return <InputWrapper label={label} labelSize={'small'}>
<select
className={classes.input}
{...selattr} value={current}
onChange={e => {
e.preventDefault();
onChange(e.currentTarget.value);
}}
>
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
</select>
</InputWrapper>