Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 8895318

Browse files
committed
feat: create breadcrumb component
1 parent 5364346 commit 8895318

File tree

7 files changed

+70
-22
lines changed

7 files changed

+70
-22
lines changed

components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* This is a generated file. Do not edit it's contents.
88
*
9-
* This file was generated on 2021-07-27T08:11:47.550Z
9+
* This file was generated on 2021-07-27T09:42:08.546Z
1010
*/
1111

1212
import { ChakraProps } from '@chakra-ui/vue-system'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as SimpleBreadcrumb from './simple-breadcrumb.vue'

packages/c-breadcrumb/src/c-breadcrumb.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2
99
*/
1010

11-
import { h, defineComponent, PropType, ConcreteComponent, Component, computed, cloneVNode, VNode, VNodeProps, mergeProps } from 'vue'
11+
import { defineComponent, PropType, computed, cloneVNode, VNode, h } from 'vue'
1212
import {
1313
chakra,
1414
HTMLChakraProps,
@@ -17,22 +17,23 @@ import {
1717
StylesProvider,
1818
useMultiStyleConfig,
1919
useStyles,
20-
SystemStyleObject
20+
SystemStyleObject,
21+
ChakraProps
2122
} from '@chakra-ui/vue-system'
2223
import { filterUndefined } from '@chakra-ui/utils'
2324
import { getValidChildren, SNA, SNAO } from '@chakra-ui/vue-utils'
25+
import { DOMElements } from '@chakra-ui/vue-system'
2426

2527
/**
2628
* CBreadcrumb (root)
2729
*/
2830

29-
3031
export interface BreadcrumbOptions {
3132
/**
3233
* The visual separator between each breadcrumb item
3334
* @type string | ConcreteComponent | Component
3435
*/
35-
separator?: string | ConcreteComponent | Component
36+
separator?: string | object
3637
/**
3738
* The left and right margin applied to the separator
3839
* @type SystemProps["mx"]
@@ -41,7 +42,7 @@ export interface BreadcrumbOptions {
4142
}
4243

4344
export interface BreadcrumbProps
44-
extends HTMLChakraProps<'nav'>,
45+
extends ChakraProps,
4546
BreadcrumbOptions,
4647
ThemingProps<'Breadcrumb'> {}
4748

@@ -81,11 +82,12 @@ export const CBreadcrumb = defineComponent(
8182
return (
8283
<chakra.nav
8384
as={props.as}
85+
__label="breadcrumb"
8486
aria-label="breadcrumb"
8587
__css={styles.value.container}
8688
{...attrs}
8789
>
88-
<chakra.ol __label="chakra-breadcrumb__list">
90+
<chakra.ol __label="breadcrumb__list">
8991
{() => children}
9092
</chakra.ol>
9193
</chakra.nav>
@@ -106,7 +108,7 @@ CBreadcrumb.props = {
106108
default: '0.5rem'
107109
},
108110
as: {
109-
type: [String, Object] as PropType<DOMElements | Component | string>,
111+
type: [String, Object] as PropType<DOMElements | object | string>,
110112
default: 'nav',
111113
},
112114
}
@@ -138,7 +140,7 @@ export const CBreadcrumbSeparator = defineComponent((props: BreadcrumbSeparatorP
138140
return () => (
139141
<chakra.span
140142
role="presentation"
141-
__label="chakra-breadcrumb__separator"
143+
__label="breadcrumb__separator"
142144
{...attrs}
143145
__css={separatorStyles.value}
144146
>
@@ -167,7 +169,7 @@ interface BreadcrumbItemOptions extends BreadcrumbOptions {
167169

168170
export interface BreadcrumbItemProps
169171
extends BreadcrumbItemOptions,
170-
HTMLChakraProps<"li"> {}
172+
ChakraProps {}
171173

172174
export const CBreadcrumbItem = defineComponent((props: BreadcrumbItemProps, { attrs, slots }) => {
173175
const styles = useStyles()
@@ -199,7 +201,7 @@ export const CBreadcrumbItem = defineComponent((props: BreadcrumbItemProps, { at
199201
})
200202

201203
return (
202-
<chakra.li __label="chakra-breadcrumb__list-it" __css={itemStyles.value}>
204+
<chakra.li __label="breadcrumb__list-item" __css={itemStyles.value}>
203205
{children}
204206
{!props.isLastChild && (
205207
// @ts-expect-error
@@ -224,8 +226,9 @@ CBreadcrumbItem.props = {
224226
* CBreadcrumbLink
225227
*/
226228

227-
export interface BreadcrumbLinkProps extends HTMLChakraProps<"a"> {
228-
isCurrentPage?: boolean
229+
export interface BreadcrumbLinkProps extends ChakraProps {
230+
isCurrentPage?: boolean,
231+
href?: string
229232
}
230233

231234
/**
@@ -240,14 +243,14 @@ export const CBreadcrumbLink = defineComponent((props: BreadcrumbLinkProps, { at
240243
return () => {
241244
if (props.isCurrentPage) {
242245
return (
243-
<chakra.span __label="chakra-breadcrumb__link" aria-current="page" __css={styles.value.link} as={props.as} {...attrs}>
246+
<chakra.span __label="breadcrumb__link" aria-current="page" __css={styles.value.link} as={props.as} {...attrs}>
244247
{slots}
245248
</chakra.span>
246249
)
247250
}
248251

249252
return (
250-
<chakra.a __label="chakra-breadcrumb__link" as={props.as} __css={styles.value.link} {...attrs}>
253+
<chakra.a __label="breadcrumb__link" as={props.as} __css={styles.value.link} {...attrs}>
251254
{slots}
252255
</chakra.a>
253256
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as Examples from '../examples'
2+
import { h } from 'vue'
3+
// import { cy } from 'local-cypress'
4+
import { CBreadcrumb, CBreadcrumbItem, CBreadcrumbLink } from '../src'
5+
6+
describe('Breadcrumb Examples', () => {
7+
Object.entries(Examples).map(([name, example]: any) => {
8+
it(`renders ${name} successfully`, () => {
9+
cy.mount(h(() => <example.default></example.default>)).checkA11y()
10+
})
11+
})
12+
})
13+
14+
const render = (props: any = {}) => {
15+
return cy.mount(
16+
h(() => (
17+
<CBreadcrumb data-testid="breadcrumb" separator="-" {...props}>
18+
<CBreadcrumbItem>
19+
<CBreadcrumbLink href="/">Home</CBreadcrumbLink>
20+
</CBreadcrumbItem>
21+
22+
<CBreadcrumbItem>
23+
<CBreadcrumbLink href="/about">About</CBreadcrumbLink>
24+
</CBreadcrumbItem>
25+
26+
<CBreadcrumbItem data-testid="current-page" isCurrentPage>
27+
<CBreadcrumbLink href="/contact">Contact</CBreadcrumbLink>
28+
</CBreadcrumbItem>
29+
</CBreadcrumb>
30+
))
31+
)
32+
}
33+
34+
it('contains the correct role', () => {
35+
cy.mount(Examples.SimpleBreadcrumb.default).get('[aria-label=breadcrumb]').should('exist')
36+
})
37+
38+
it('renders its children', () => {
39+
render()
40+
.get('[data-testid=breadcrumb]')
41+
.should('contain', 'Home')
42+
.should('contain', 'About')
43+
.should('contain', 'Contact')
44+
})
45+
46+
it('current page should have `aria-current="page"` attribute', () => {
47+
render()
48+
.get('[data-testid=current-page] > span')
49+
.should('have.attr', 'aria-current', 'page')
50+
})

packages/c-breadcrumb/tests/c-breadcrumb.test.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference types="cypress" />
2+
/// <reference types="local-cypress" />
23
/// <reference types="cypress-plugin-tab" />
34

45
import { ChakraProps, HTMLChakraProps } from '@chakra-ui/vue-system'

0 commit comments

Comments
 (0)