-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import UsaTag from './UsaTag.vue' | ||
|
||
export { UsaTag } | ||
export default UsaTag |