mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
chore(form): add stories for Form, FormItem, FormLabel
This commit is contained in:
parent
8398e478e7
commit
f366b7b948
18 changed files with 152 additions and 22 deletions
74
src/components/Form/Form.Story.svelte
Normal file
74
src/components/Form/Form.Story.svelte
Normal file
|
@ -0,0 +1,74 @@
|
|||
<script>
|
||||
import Layout from '../../internal/ui/Layout.svelte';
|
||||
import Checkbox from '../Checkbox';
|
||||
import FormGroup from '../FormGroup';
|
||||
import FileUploader from '../FileUploader';
|
||||
import NumberInput from '../NumberInput';
|
||||
import RadioButton from '../RadioButton';
|
||||
import RadioButtonGroup from '../RadioButtonGroup';
|
||||
import Button from '../Button';
|
||||
import Search from '../Search';
|
||||
import Select, { SelectItem } from '../Select';
|
||||
import TextArea from '../TextArea';
|
||||
import TextInput from '../TextInput';
|
||||
import Toggle from '../Toggle';
|
||||
import Form from './Form.svelte';
|
||||
</script>
|
||||
|
||||
<Layout>
|
||||
<Form
|
||||
on:submit={event => {
|
||||
console.log('on:submit', event);
|
||||
}}>
|
||||
<FormGroup {...$$props}>
|
||||
<Checkbox id="checkbox-0" labelText="Checkbox Label" checked />
|
||||
<Checkbox id="checkbox-1" labelText="Checkbox Label" />
|
||||
<Checkbox id="checkbox-2" labelText="Checkbox Label" disabled />
|
||||
</FormGroup>
|
||||
<NumberInput id="number-input-1" label="Number Input" min={0} max={100} value={50} step={10} />
|
||||
<FormGroup legendText="Toggle heading">
|
||||
<Toggle id="toggle-1" />
|
||||
<Toggle id="toggle-2" disabled />
|
||||
</FormGroup>
|
||||
<FormGroup legendText="File Uploader">
|
||||
<FileUploader id="file-1" buttonLabel="Add files" labelDescription="Choose Files..." />
|
||||
</FormGroup>
|
||||
<FormGroup legendText="Radio Button heading">
|
||||
<RadioButtonGroup name="radio-button-group" defaultSelected="default-selected">
|
||||
<RadioButton id="radio-1" value="standard" labelText="Standard Radio Button" />
|
||||
<RadioButton
|
||||
id="radio-2"
|
||||
value="default-selected"
|
||||
labelText="Default Selected Radio Button" />
|
||||
<RadioButton id="radio-3" value="blue" labelText="Standard Radio Button" />
|
||||
<RadioButton id="radio-4" value="disabled" labelText="Disabled Radio Button" disabled />
|
||||
</RadioButtonGroup>
|
||||
</FormGroup>
|
||||
<FormGroup legendText="Search">
|
||||
<Search id="search-1" labelText="Search" placeholder="Search" />
|
||||
</FormGroup>
|
||||
<Select id="select-1" defaultValue="placeholder-item">
|
||||
<SelectItem disabled hidden value="placeholder-item" text="Choose an option" />
|
||||
<SelectItem value="option-1" text="Option 1" />
|
||||
<SelectItem value="option-2" text="Option 2" />
|
||||
<SelectItem value="option-3" text="Option 3" />
|
||||
</Select>
|
||||
<TextInput id="text-input-1" labelText="Text Input label" placeholder="Placeholder text" />
|
||||
<TextInput id="text-input-2" type="password" labelText="Password" required />
|
||||
<TextInput
|
||||
id="text-input-3"
|
||||
type="password"
|
||||
labelText="Password"
|
||||
invalidText="Your password must be at least 6 characters as well as contain at least one
|
||||
uppercase, one lowercase, and one number."
|
||||
required
|
||||
invalid />
|
||||
<TextArea
|
||||
id="text-area"
|
||||
labelText="Text Area label"
|
||||
placeholder="Placeholder text"
|
||||
rows={4}
|
||||
cols={50} />
|
||||
<Button type="submit">Submit</Button>
|
||||
</Form>
|
||||
</Layout>
|
14
src/components/Form/Form.stories.js
Normal file
14
src/components/Form/Form.stories.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { withKnobs, text, boolean } from '@storybook/addon-knobs';
|
||||
import Component from './Form.Story.svelte';
|
||||
|
||||
export default { title: 'Form', decorators: [withKnobs] };
|
||||
|
||||
export const Default = () => ({
|
||||
Component,
|
||||
props: {
|
||||
legendText: text('Text in <legend> (legendText)', 'Checkbox heading'),
|
||||
message: boolean('Show form requirement (message)', false),
|
||||
messageText: text('Form requirement text (messageText)', ''),
|
||||
invalid: boolean('Mark as invalid (invalid)', false)
|
||||
}
|
||||
});
|
11
src/components/FormItem/FormItem.Story.svelte
Normal file
11
src/components/FormItem/FormItem.Story.svelte
Normal file
|
@ -0,0 +1,11 @@
|
|||
<script>
|
||||
import Layout from '../../internal/ui/Layout.svelte';
|
||||
import NumberInput from '../NumberInput';
|
||||
import FormItem from './FormItem.svelte';
|
||||
</script>
|
||||
|
||||
<Layout>
|
||||
<FormItem>
|
||||
<NumberInput id="number-input-1" />
|
||||
</FormItem>
|
||||
</Layout>
|
6
src/components/FormItem/FormItem.stories.js
Normal file
6
src/components/FormItem/FormItem.stories.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { withKnobs } from '@storybook/addon-knobs';
|
||||
import Component from './FormItem.Story.svelte';
|
||||
|
||||
export default { title: 'FormItem', decorators: [withKnobs] };
|
||||
|
||||
export const Default = () => ({ Component });
|
17
src/components/FormLabel/FormLabel.Story.svelte
Normal file
17
src/components/FormLabel/FormLabel.Story.svelte
Normal file
|
@ -0,0 +1,17 @@
|
|||
<script>
|
||||
export let story = undefined;
|
||||
|
||||
import Layout from '../../internal/ui/Layout.svelte';
|
||||
import Tooltip from '../Tooltip';
|
||||
import FormLabel from './FormLabel.svelte';
|
||||
</script>
|
||||
|
||||
<Layout>
|
||||
{#if story === 'tooltip'}
|
||||
<FormLabel>
|
||||
<Tooltip triggerText="Label">This is the content of the tooltip.</Tooltip>
|
||||
</FormLabel>
|
||||
{:else}
|
||||
<FormLabel>Label</FormLabel>
|
||||
{/if}
|
||||
</Layout>
|
8
src/components/FormLabel/FormLabel.stories.js
Normal file
8
src/components/FormLabel/FormLabel.stories.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { withKnobs } from '@storybook/addon-knobs';
|
||||
import Component from './FormLabel.Story.svelte';
|
||||
|
||||
export default { title: 'FormLabel', decorators: [withKnobs] };
|
||||
|
||||
export const Default = () => ({ Component });
|
||||
|
||||
export const WithTooltip = () => ({ Component, props: { story: 'tooltip' } });
|
Loading…
Add table
Add a link
Reference in a new issue