Skip to content

Commit

Permalink
feat: implement UsaTag component
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #1
  • Loading branch information
patrickcate committed Nov 3, 2021
1 parent 587cf75 commit 77e4d53
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/components/UsaTag/UsaTag.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import UsaTag from './UsaTag.vue'

const defaultProps = {
size: '',
}

export default {
component: UsaTag,
title: 'Components/UsaTag',
argTypes: {
size: {
options: ['', 'big'],
control: {
type: 'radio',
labels: {
'': 'default',
},
},
},
tag: {
control: {
type: 'text',
},
},
content: {
control: { type: 'text' },
},
},
args: {
tag: 'span',
content: 'Test',
},
}

const Template = (args, { argTypes }) => ({
components: { UsaTag },
props: Object.keys(argTypes),
setup() {
return { ...args }
},
template: `<UsaTag :tag="tag" :size="size">{{ content }}</UsaTag>`,
})

export const Default = Template.bind({})
Default.args = {
...defaultProps,
}

export const Big = Template.bind({})
Big.args = {
...defaultProps,
size: 'big',
}

export const CustomTag = Template.bind({})
CustomTag.args = {
...defaultProps,
tag: 'div',
content: 'Test (div)',
}
38 changes: 38 additions & 0 deletions src/components/UsaTag/UsaTag.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import '@module/uswds/dist/css/uswds.min.css'
import { mount } from '@cypress/vue'
import UsaTag from './UsaTag.vue'

describe('UsaTag', () => {
it('renders the component', () => {
mount(UsaTag, {
slots: {
default: () => 'Test',
},
})
cy.get('span.usa-tag').should('exist').contains('Test')
})

it('renders the size class', () => {
mount(UsaTag, {
slots: {
default: () => 'Test',
},
props: {
size: 'big',
},
})
cy.get('.usa-tag--big').should('exist')
})

it('renders as a custom HTML element', () => {
mount(UsaTag, {
slots: {
default: () => 'Test',
},
props: {
tag: 'div',
},
})
cy.get('div.usa-tag').should('exist')
})
})
25 changes: 25 additions & 0 deletions src/components/UsaTag/UsaTag.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script setup>
import { computed } from 'vue'
const props = defineProps({
size: {
type: String,
default: '',
validator(size) {
return size === '' || size === 'big'
},
},
tag: {
type: String,
default: 'span',
},
})
const sizeClass = computed(() => (props.size === 'big' ? 'usa-tag--big' : null))
</script>

<template>
<component :is="tag" class="usa-tag" :class="sizeClass"
><slot></slot
></component>
</template>
4 changes: 4 additions & 0 deletions src/components/UsaTag/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import UsaTag from './UsaTag.vue'

export { UsaTag }
export default UsaTag

0 comments on commit 77e4d53

Please sign in to comment.