Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Adds new tokens to Breadcrumb #146

Merged
merged 6 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Applies new local tokens to `Breadcrumb` ([#146](https://github.com/vtex-sites/gatsby.store/pull/146))
- Adds [MSW Addon](https://storybook.js.org/addons/msw-storybook-addon) ([#143](https://github.com/vtex-sites/gatsby.store/pull/143))
- Global tokens doc page on storybook ([#140](https://github.com/vtex-sites/gatsby.store/pull/140))
- Uses new cross selling API on PDP ([#137](https://github.com/vtex-sites/gatsby.store/pull/137))
Expand Down
197 changes: 197 additions & 0 deletions src/components/ui/Breadcrumb/Breadcrumb.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { Meta, Canvas, Story, ArgsTable } from '@storybook/addon-docs'
import Breadcrumb from '.'

import {
TokenTable,
TokenRow,
TokenDivider,
} from 'src/../.storybook/components'

<Meta component={Breadcrumb} title="Molecules/Breadcrumb" />

export const breadcrumbList = [
{ item: 'technology', name: 'Technology', position: 1 },
{
item: 'technology/electronics',
name: 'Electronics',
position: 2,
},
{
item: 'technology/electronics/audio-and-video',
name: 'Audio & Video',
position: 3,
},
{
item: 'technology/electronics/audio-and-video/headphones',
name: 'Headphones',
position: 4,
},
]

export const Template = (args) => <Breadcrumb {...args} />

<header>

# Breadcrumb

Breadcrumbs indicate the user's location in a website hierarchy, facilitating the navigation to previous page levels.

</header>

## Overview

The `Breadcrumb` component uses [FastStore UI Breadcrumb](https://www.faststore.dev/reference/ui/molecules/Breadcrumb) as base.

<Canvas isColumn>
<Story name="overview" args={{ breadcrumbList }}>
{Template.bind({})}
</Story>
<Story
name="overview-with-dropdown"
args={{
breadcrumbList: [
...breadcrumbList,
{
item: 'technology/electronics/audio-and-video/headphones/headphonesaedle-vk1-headphone',
name: 'Aedle VK-1 L Headphone',
position: 5,
},
],
}}
>
{Template.bind({})}
</Story>
</Canvas>

---

## Usage

`import Breadcrumb from 'src/components/ui/Breadcrumb'`

<Canvas>
<Story name="default" args={{ breadcrumbList }}>
{Template.bind({})}
</Story>
</Canvas>

<ArgsTable story="default" />

<TokenTable>
<TokenRow
token="--fs-breadcrumb-margin-left"
value="calc(-1 * var(--fs-spacing-1))"
/>
</TokenTable>

---

## Nested Elements

### List Item

<TokenTable>
<TokenRow
token="--fs-breadcrumb-list-item-padding"
value="var(--fs-spacing-0)"
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-list-item-last-text-color"
value="var(--fs-color-text-light)"
isColor
/>
<TokenDivider />
<TokenRow token="--fs-breadcrumb-list-item-max-width-mobile" value="30%" />
</TokenTable>

### Link

<TokenTable>
<TokenRow
token="--fs-breadcrumb-link-color-visited"
value="var(--fs-color-link)"
isColor
/>
</TokenTable>

### Link Home

<TokenTable>
<TokenRow
token="--fs-breadcrumb-link-home-padding"
value="var(--fs-spacing-1)"
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-link-home-border-radius"
value="var(--fs-border-radius-circle)"
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-link-home-hover-bkg-color"
value="var(--fs-color-primary-bkg-light)"
isColor
/>
<TokenRow
token="--fs-breadcrumb-link-home-color"
value="var(--fs-color-text)"
isColor
/>
</TokenTable>

### Divider

<TokenTable>
<TokenRow
token="--fs-breadcrumb-divider-height"
value="var(--fs-spacing-3)"
/>
<TokenRow
token="--fs-breadcrumb-divider-margin"
value="var(--fs-spacing-1)"
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-divider-border-left-width"
value="var(--fs-border-width)"
/>
<TokenRow
token="--fs-breadcrumb-divider-border-left-color"
value="var(--fs-border-color-light)"
isColor
/>
</TokenTable>

### Dropdown Button

<TokenTable>
<TokenRow
token="--fs-breadcrumb-dropdown-button-margin-left"
value="var(--fs-breadcrumb-margin-left)"
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-dropdown-button-color"
value="var(--fs-color-link)"
isColor
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-dropdown-button-border-radius"
value="var(--fs-spacing-0)"
/>
<TokenDivider />
<TokenRow
token="--fs-breadcrumb-dropdown-button-transition-property"
value="var(--fs-transition-property)"
/>
<TokenRow
token="--fs-breadcrumb-dropdown-button-transition-timing"
value="var(--fs-transition-timing)"
/>
<TokenRow
token="--fs-breadcrumb-dropdown-button-transition-function"
value="var(--fs-transition-function)"
/>
</TokenTable>
49 changes: 0 additions & 49 deletions src/components/ui/Breadcrumb/Breadcrumb.stories.tsx

This file was deleted.

36 changes: 25 additions & 11 deletions src/components/ui/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { navigate } from 'gatsby'
import { memo } from 'react'
import type { BreadcrumbProps as UIBreadcrumbProps } from '@faststore/ui'
import { Breadcrumb as UIBreadcrumb } from '@faststore/ui'
import { navigate } from 'gatsby'
import { memo } from 'react'
import Dropdown, {
DropdownButton,
DropdownItem,
Expand All @@ -10,12 +10,17 @@ import Dropdown, {
import Icon from 'src/components/ui/Icon'
import Link from 'src/components/ui/Link'

import styles from './breadcrumb.module.scss'

type ItemElement = {
item: string
name: string
position: number
}
export interface BreadcrumbProps extends UIBreadcrumbProps {
/**
* Array of ItemElement that represents each breadcrumb item.
*/
breadcrumbList: ItemElement[]
}

Expand All @@ -39,9 +44,16 @@ function BaseBreadcrumb({
return (
<UIBreadcrumb
divider=""
className={isDesktop ? 'hidden-mobile' : 'display-mobile'}
className={`${styles.fsBreadcrumb} ${
isDesktop ? 'hidden-mobile' : 'display-mobile'
}`}
>
<Link aria-label="Go to homepage" href="/">
<Link
data-fs-breadcrumb-link
data-fs-breadcrumb-link-home
aria-label="Go to homepage"
href="/"
>
<Icon name="House" width={18} height={18} weight="bold" />
</Link>

Expand All @@ -50,25 +62,27 @@ function BaseBreadcrumb({
return breadcrumbList.length === index + 1 ? (
<span key={String(index)}>{name}</span>
) : (
<Link href={item} key={String(index)}>
<Link data-fs-breadcrumb-link href={item} key={String(index)}>
{name}
</Link>
)
})}

{collapseBreadcrumb && firstItem && (
<Link href={firstItem.item}>{firstItem.name}</Link>
<Link data-fs-breadcrumb-link href={firstItem.item}>
{firstItem.name}
</Link>
)}

{collapseBreadcrumb && (
<Dropdown>
<DropdownButton>
<span>...</span>
<DropdownButton data-fs-breadcrumb-dropdown-button>
<Icon name="DotsThree" width={24} height={24} />
</DropdownButton>
<DropdownMenu>
<DropdownMenu data-fs-breadcrumb-dropdown-menu>
{mediumItems.map(({ item, name }, index) => (
<DropdownItem
data-breadcrumb-dropdown-item
data-fs-breadcrumb-dropdown-item
icon={
<Icon name="ArrowElbowDownRight" width={24} height={24} />
}
Expand All @@ -87,7 +101,7 @@ function BaseBreadcrumb({
return lastItems.length === index + 1 ? (
<span key={String(index)}>{name}</span>
) : (
<Link href={item} key={String(index)}>
<Link data-fs-breadcrumb-link href={item} key={String(index)}>
{name}
</Link>
)
Expand Down
Loading