Skip to content

Commit

Permalink
chore: Add base components and stories
Browse files Browse the repository at this point in the history
Also adds tests for applicable items
  • Loading branch information
novellac committed Mar 7, 2023
1 parent 3e18d9c commit 8a40076
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 11 deletions.
17 changes: 17 additions & 0 deletions src/components/BaseButton.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import BaseButton from './BaseButton.vue'

export default {
title: 'Base button',
component: BaseButton,
}

const Template = (args) => ({
components: { BaseButton },
setup() {
return { args }
},
template: `<BaseButton>What a nice label!</BaseButton>`,
})

export const Primary = Template.bind({})
Primary.args = {}
5 changes: 5 additions & 0 deletions src/components/BaseButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<button class="p-2 border border-slate-300">
<slot />
</button>
</template>
17 changes: 17 additions & 0 deletions src/components/BaseLabel.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import BaseLabel from './BaseLabel.vue'

export default {
title: 'Base label',
component: BaseLabel,
}

const Template = (args) => ({
components: { BaseLabel },
setup() {
return { args }
},
template: `<BaseLabel>What a nice label!</BaseLabel>`,
})

export const Primary = Template.bind({})
Primary.args = {}
5 changes: 5 additions & 0 deletions src/components/BaseLabel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<label>
<slot />
</label>
</template>
19 changes: 19 additions & 0 deletions src/components/BaseTextArea.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import BaseTextArea from './BaseTextArea.vue'

export default {
title: 'Base text area',
component: BaseTextArea,
}

const Template = (args) => ({
components: { BaseTextArea },
setup() {
return { args }
},
template: `<BaseTextArea v-bind="args" />`,
})

export const Primary = Template.bind({})
Primary.args = {
modelValue: 'Cool text',
}
13 changes: 13 additions & 0 deletions src/components/BaseTextArea.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<textarea
class="m-4 border"
rows="4"
:value="modelValue"
@input="$emit('update:modelValue', $event.target.value)"
/>
</template>

<script setup>
defineProps(['modelValue'])
defineEmits(['update:modelValue'])
</script>
29 changes: 29 additions & 0 deletions src/components/StepInput.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, it, expect } from 'vitest'

import { shallowMount } from '@vue/test-utils'

import StepInput from './StepInput.vue'
import BaseTextArea from './BaseTextArea.vue'
import BaseLabel from './BaseLabel.vue'

describe('StepInput', () => {
it('passes a formatted id to the BaseTextArea', () => {
const wrapper = shallowMount(StepInput, {
props: {
stepNumber: 99,
},
})

expect(wrapper.findComponent(BaseTextArea).attributes('id')).toContain(99)
})

it('passes a formated for attr to the BaseLabel', () => {
const wrapper = shallowMount(StepInput, {
props: {
stepNumber: 99,
},
})

expect(wrapper.findComponent(BaseLabel).attributes('for')).toContain(99)
})
})
20 changes: 20 additions & 0 deletions src/components/StepInput.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import StepInput from './StepInput.vue'

export default {
title: 'Step input',
component: StepInput,
}

const Template = (args) => ({
components: { StepInput },
setup() {
return { args }
},
template: `<StepInput v-bind="args" />`,
})

export const Primary = Template.bind({})
Primary.args = {
stepLabel: 'First step is best',
stepNumber: 99,
}
37 changes: 37 additions & 0 deletions src/components/StepInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import BaseLabel from './BaseLabel.vue';

<template>
<div class="flex flex-col border">
<BaseLabel :for="stepId">{{ stepLabel }}</BaseLabel>

<BaseTextArea
:id="stepId"
:modelValue="stepText"
@input="$emit('update:stepText', $event.target.value)"
/>
</div>
</template>

<script setup>
import BaseLabel from './BaseLabel.vue'
import BaseTextArea from './BaseTextArea.vue'
const props = defineProps({
stepNumber: {
type: Number,
required: true,
},
stepLabel: {
type: String,
default: '',
},
stepText: {
type: String,
default: '',
},
})
defineEmits(['update:stepText'])
const stepId = `step-input-${props.stepNumber}`
</script>
11 changes: 0 additions & 11 deletions src/components/__tests__/HelloWorld.spec.js

This file was deleted.

0 comments on commit 8a40076

Please sign in to comment.