-
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.
feat: implement
UsaCollectionHeading
component
ISSUES CLOSED: #20
- Loading branch information
1 parent
19a3c2a
commit 3c9df87
Showing
4 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/components/UsaCollectionHeading/UsaCollectionHeading.stories.js
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,98 @@ | ||
import UsaCollectionHeading from './UsaCollectionHeading.vue' | ||
|
||
const defaultProps = { | ||
heading: 'Collection Item Heading', | ||
headingTag: 'h2', | ||
href: '/test-page', | ||
to: '', | ||
routerComponentName: '', | ||
customClasses: { | ||
link: [], | ||
}, | ||
} | ||
|
||
export default { | ||
component: UsaCollectionHeading, | ||
title: 'Components/UsaCollectionHeading', | ||
argTypes: { | ||
heading: { | ||
control: { type: 'text' }, | ||
}, | ||
headingTag: { | ||
options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], | ||
control: { | ||
type: 'select', | ||
}, | ||
}, | ||
href: { | ||
control: { type: 'text' }, | ||
}, | ||
to: { | ||
control: { type: 'text' }, | ||
}, | ||
routerComponentName: { | ||
control: { type: 'text' }, | ||
}, | ||
customClasses: { | ||
control: { type: 'object' }, | ||
}, | ||
defaultSlot: { | ||
control: { type: 'text' }, | ||
}, | ||
}, | ||
args: { | ||
heading: defaultProps.heading, | ||
headingTag: defaultProps.headingTag, | ||
href: defaultProps.href, | ||
to: defaultProps.to, | ||
routerComponentName: defaultProps.routerComponentName, | ||
customClasses: defaultProps.customClasses, | ||
defaultSlot: '', | ||
}, | ||
} | ||
|
||
const DefaultTemplate = (args, { argTypes }) => ({ | ||
components: { UsaCollectionHeading }, | ||
props: Object.keys(argTypes), | ||
setup() { | ||
return { ...args } | ||
}, | ||
template: `<UsaCollectionHeading | ||
:heading="heading" | ||
:heading-tag="headingTag" | ||
:href="href" | ||
:to="to" | ||
:router-component-name="routerComponentName" | ||
:custom-classes="customClasses" | ||
>${args.defaultSlot}</UsaCollectionHeading>`, | ||
}) | ||
|
||
export const DefaultCollectionItemHeading = DefaultTemplate.bind({}) | ||
DefaultCollectionItemHeading.args = { | ||
...defaultProps, | ||
} | ||
DefaultCollectionItemHeading.storyName = 'Default' | ||
|
||
export const CustomHeadingCollectionItemHeading = DefaultTemplate.bind({}) | ||
CustomHeadingCollectionItemHeading.args = { | ||
...defaultProps, | ||
headingTag: 'h4', | ||
heading: 'Custom heading tag', | ||
} | ||
CustomHeadingCollectionItemHeading.storyName = 'Custom Heading Tag' | ||
|
||
export const HeadingSlotCollectionItemHeading = DefaultTemplate.bind({}) | ||
HeadingSlotCollectionItemHeading.args = { | ||
...defaultProps, | ||
defaultSlot: 'Custom header slot', | ||
} | ||
HeadingSlotCollectionItemHeading.storyName = 'Header Slot' | ||
|
||
export const CustomClassesCollectionItemHeading = DefaultTemplate.bind({}) | ||
CustomClassesCollectionItemHeading.args = { | ||
...defaultProps, | ||
customClasses: { | ||
link: ['test-link-class'], | ||
}, | ||
} | ||
CustomClassesCollectionItemHeading.storyName = 'Custom Classes' |
71 changes: 71 additions & 0 deletions
71
src/components/UsaCollectionHeading/UsaCollectionHeading.test.js
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,71 @@ | ||
import '@module/uswds/dist/css/uswds.min.css' | ||
import { mount } from '@cypress/vue' | ||
import UsaCollectionHeading from './UsaCollectionHeading.vue' | ||
|
||
describe('UsaCollectionHeading', () => { | ||
it('renders the component', () => { | ||
mount(UsaCollectionHeading, { | ||
props: { | ||
header: 'Test header text', | ||
href: '/test-page', | ||
}, | ||
}) | ||
|
||
cy.get('h2.usa-collection__heading a') | ||
.should('have.class', 'usa-link') | ||
.and('have.attr', 'href') | ||
.and('contain', '/test-page') | ||
}) | ||
|
||
it('uses the `heading` slot content', () => { | ||
mount(UsaCollectionHeading, { | ||
props: { | ||
header: 'Test header text', | ||
}, | ||
slots: { | ||
default: () => 'Custom slot heading text', | ||
}, | ||
}) | ||
|
||
cy.get('.usa-collection__heading').should( | ||
'contain', | ||
'Custom slot heading text' | ||
) | ||
}) | ||
|
||
it('renders custom heading tag', () => { | ||
mount(UsaCollectionHeading, { | ||
props: { | ||
header: 'Test header text', | ||
headingTag: 'h4', | ||
}, | ||
}) | ||
|
||
cy.get('h4.usa-collection__heading').should('exist') | ||
}) | ||
|
||
it('renders the custom router link tag and props', () => { | ||
mount(UsaCollectionHeading, { | ||
props: { | ||
heading: 'Test header text', | ||
to: '/test-page', | ||
routerComponentName: 'router-link', | ||
}, | ||
}) | ||
|
||
cy.get('router-link').should('have.attr', 'to').and('contain', '/test-page') | ||
}) | ||
|
||
it('adds custom CSS classes', () => { | ||
mount(UsaCollectionHeading, { | ||
props: { | ||
header: 'Test header text', | ||
customClasses: { | ||
link: ['test-link-class'], | ||
}, | ||
}, | ||
}) | ||
|
||
cy.get('a.test-link-class').should('exist') | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
src/components/UsaCollectionHeading/UsaCollectionHeading.vue
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,48 @@ | ||
<script setup> | ||
import BaseHeading from '@/components/BaseHeading' | ||
import BaseLink from '@/components/BaseLink' | ||
defineProps({ | ||
heading: { | ||
type: String, | ||
default: '', | ||
}, | ||
headingTag: { | ||
type: String, | ||
default: 'h2', | ||
}, | ||
href: { | ||
type: String, | ||
default: '', | ||
}, | ||
to: { | ||
type: [String, Object], | ||
default: '', | ||
}, | ||
routerComponentName: { | ||
type: String, | ||
default: '', | ||
}, | ||
customClasses: { | ||
type: Object, | ||
default: () => { | ||
return { | ||
link: [], | ||
} | ||
}, | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<BaseHeading :tag="headingTag" class="usa-collection__heading" | ||
><BaseLink | ||
:href="href" | ||
:to="to" | ||
:router-component-name="routerComponentName" | ||
class="usa-link" | ||
:class="customClasses?.link" | ||
><slot>{{ heading }}</slot></BaseLink | ||
></BaseHeading | ||
> | ||
</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 UsaCollectionHeading from './UsaCollectionHeading.vue' | ||
|
||
export { UsaCollectionHeading } | ||
export default UsaCollectionHeading |