Skip to content

Commit

Permalink
fix(vue/Field): create specific stories for controlled components
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerAPfledderer committed Sep 13, 2024
1 parent a1c5ed3 commit 02f94e6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 16 deletions.
16 changes: 16 additions & 0 deletions packages/vue/src/components/field/examples/input-controlled.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Field } from '../'
const model = ref('Input is controlled')
</script>

<template>
<span>Input text: {{ model }}</span>
<Field.Root>
<Field.Label>Label</Field.Label>
<Field.Input v-model="model" />
<Field.HelperText>Some additional Info</Field.HelperText>
<Field.ErrorText>Error Info</Field.ErrorText>
</Field.Root>
</template>
4 changes: 1 addition & 3 deletions packages/vue/src/components/field/examples/input.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script setup lang="ts">
import { Field } from '../'
const model = defineModel()
</script>

<template>
<Field.Root>
<Field.Label>Label</Field.Label>
<Field.Input v-model="model" />
<Field.Input />
<Field.HelperText>Some additional Info</Field.HelperText>
<Field.ErrorText>Error Info</Field.ErrorText>
</Field.Root>
Expand Down
20 changes: 20 additions & 0 deletions packages/vue/src/components/field/examples/select-controlled.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Field } from '../'
const model = ref('3')
</script>

<template>
<span>Selected: Option {{ model }}</span>
<Field.Root>
<Field.Label>Label</Field.Label>
<Field.Select v-model="model">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</Field.Select>
<Field.HelperText>Some additional Info</Field.HelperText>
<Field.ErrorText>Error Info</Field.ErrorText>
</Field.Root>
</template>
4 changes: 1 addition & 3 deletions packages/vue/src/components/field/examples/select.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script setup lang="ts">
import { Field } from '../'
const model = defineModel()
</script>

<template>
<Field.Root>
<Field.Label>Label</Field.Label>
<Field.Select v-model="model">
<Field.Select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
Expand Down
16 changes: 16 additions & 0 deletions packages/vue/src/components/field/examples/textarea-controlled.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Field } from '../'
const model = ref(['This is some text', 'then more text'])
</script>

<template>
<span>Textarea value: {{ model }}</span>
<Field.Root>
<Field.Label>Label</Field.Label>
<Field.Textarea v-model="model" />
<Field.HelperText>Some additional Info</Field.HelperText>
<Field.ErrorText>Error Info</Field.ErrorText>
</Field.Root>
</template>
16 changes: 6 additions & 10 deletions packages/vue/src/components/field/field.stories.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
<script setup lang="ts">
import { ref } from 'vue'
import InputControlled from './examples/input-controlled.vue'
import Input from './examples/input.vue'
import SelectControlled from './examples/select-controlled.vue'
import Select from './examples/select.vue'
import TextareaControlled from './examples/textarea-controlled.vue'
import Textarea from './examples/textarea.vue'
const inputModel = ref('This input is controlled')
const selectModel = ref(3)
const textareaModel = ref(['This is some text', 'then more text'])
</script>
<template>
<Story title="Field">
<Variant title="Input">
<Input />
</Variant>
<Variant title="Input Controlled">
<span>Input value: {{ inputModel }}</span>
<Input v-model="inputModel" />
<InputControlled />
</Variant>
<Variant title="Select">
<Select />
</Variant>
<Variant title="Select Controlled">
<span>Selected: Option {{ selectModel }}</span>
<Select v-model="selectModel" />
<SelectControlled />
</Variant>
<Variant title="Textarea">
<Textarea />
</Variant>
<Variant title="Textarea Controlled">
<span>Textarea value: {{ textareaModel }}</span>
<Textarea v-model="textareaModel" />
<TextareaControlled />
</Variant>
</Story>
</template>

0 comments on commit 02f94e6

Please sign in to comment.