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(breadcrumb): create new component #163

Merged
merged 23 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
128cf03
feat(breadcrumb): init new component
denilsonrp Jun 28, 2023
91322b8
style(alert): fix css properties order
denilsonrp Jun 28, 2023
dc5ab9d
test(breadcrumb): fix breadcrumb render test
denilsonrp Jun 28, 2023
140ff0e
feat(breadcrumb): add key to ion-breadcrumb
denilsonrp Jun 28, 2023
14be410
feat(breadcrumb): change caret-forward icon to sharp
denilsonrp Jun 28, 2023
95ca6f1
Merge branch 'main' of github.com:juntossomosmais/atomium into feat/b…
felipefialho Jun 28, 2023
c69e1be
Merge branch 'main' into feat/breadcrumb
felipefialho Jun 28, 2023
cbd6a8b
Merge branch 'main' into feat/breadcrumb
felipefialho Jun 28, 2023
102ae35
style: add hover state
denilsonrp Jun 30, 2023
89762a4
style: use margin instead margin-inline
denilsonrp Jul 3, 2023
cae5a9a
chore(tokens): add rgb tokens (#181)
lupy100 Jul 12, 2023
2fde126
chore(tokens): remove variable not used to remove sonar bug (#180)
RodrigoRVSN Jul 12, 2023
fa90b1f
feat(breadcrumb): add back button to mobile version
denilsonrp Jul 13, 2023
6325f00
Merge branch 'main' into feat/breadcrumb
denilsonrp Jul 13, 2023
028b736
fix(breadcrumb): use rupture syntax instead media
denilsonrp Jul 13, 2023
4fd5bbb
docs: add new ADR about use onclick in breadcrumb component
denilsonrp Jul 14, 2023
71b1260
Merge branch 'main' into feat/breadcrumb
denilsonrp Jul 14, 2023
53d3dba
Merge branch 'main' into feat/breadcrumb
denilsonrp Jul 18, 2023
89357e2
fix: rename ADR doc
denilsonrp Jul 18, 2023
eaa3a39
fix(breadcrumb): use querySelectorAll to get all breadcrumbs in stories
denilsonrp Jul 18, 2023
893a9c4
feat(breadcrumb): add previous item text to mobile back button
denilsonrp Jul 18, 2023
74556c0
Merge branch 'main' into feat/breadcrumb
denilsonrp Jul 18, 2023
914f54b
feat(breadcrumb): add svg icons
denilsonrp Jul 18, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Meta } from '@storybook/addon-docs'

<Meta title="Docs/Architecture Decision Records/ADR 0009: Why use onClick event on breadcrumb component even undocumented?" />

# Why use `onClick` event on breadcrumb component even undocumented?

🗓️ 2023-07 · ✍️ [@denilsonrp](https://github.com/denilsonrp)

## Context

In the [breadcrumb component's pull request](https://github.com/juntossomosmais/atomium/pull/163) a [doubt arose about the correct functioning of the `onClick` event](https://github.com/juntossomosmais/atomium/pull/163#discussion_r1250986555), as this event isn't documented in [ion-breadcrumb docs](https://ionicframework.com/docs/api/breadcrumb#events).

## Decision

We ran some tests on Atomium's breadcrumb component in order to ensure the correct firing of the event and even though the `onClick` event isn't documented in the events section of the [ion-breadcrumb docs](https://ionicframework.com/docs/api/breadcrumb#events), the tests were successful and the event fired correctly.

Based on these tests, we can assume that, even without event documentation, it's possible to use it. The idea of ​​exposing this decision is to serve as a reference in possible similar scenarios in the future.
2 changes: 1 addition & 1 deletion packages/core/src/components/alert/alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
}

.atom-alert {
border-radius: var(--border-radius);
border: 1px solid transparent;
border-radius: var(--border-radius);
font: var(--text-body-medium);
letter-spacing: var(--text-body-medium-letter);
padding: var(--spacing-base);
Expand Down
60 changes: 60 additions & 0 deletions packages/core/src/components/breadcrumb/breadcrumb.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@import '~@atomium/scss-utils/index';

.atom-breadcrumbs {
display: none;

@include above(medium) {
display: flex;
}
}

.atom-breadcrumb {
--color: var(--color-brand-secondary-regular);
--color-active: var(--color-neutral-regular);
font: var(--text-body-small);
letter-spacing: var(--text-body-small-letter);

&:not(:last-of-type) {
denilsonrp marked this conversation as resolved.
Show resolved Hide resolved
&::part(native) {
schirrel marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer;

&:hover {
text-decoration: underline;
}
}

.atom-breadcrumb__text {
felipefialho marked this conversation as resolved.
Show resolved Hide resolved
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}

&::part(native) {
denilsonrp marked this conversation as resolved.
Show resolved Hide resolved
padding: 0;
}

&::part(separator) {
color: var(--color-neutral-regular);
margin: 0 var(--spacing-xxsmall);
}
}

.atom-button__back {
align-items: center;
background-color: transparent;
border: 0;
color: var(--color-brand-secondary-regular);
cursor: pointer;
display: flex;
font: var(--text-link-small);
gap: var(--spacing-xsmall);
letter-spacing: var(--text-link-small-letter);
padding: 0;
text-decoration: underline;

@include above(medium) {
display: none;
}
}
90 changes: 90 additions & 0 deletions packages/core/src/components/breadcrumb/breadcrumb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { newSpecPage } from '@stencil/core/testing'

import { AtomBreadcrumb } from './breadcrumb'

const breadcrumbItemsMock = [
{
text: 'First level',
title: 'Go to first level',
redirect: () => console.log('/first'),
},
{
text: 'Intermediary level',
title: 'Go to intermediary level',
redirect: () => console.log('/intermediary'),
},
{
text: 'Current level',
title: 'This is the current level',
},
]

describe('atom-breadcrumb', () => {
it('should render breadcrumb items and mobile back button correctly', async () => {
const page = await newSpecPage({
components: [AtomBreadcrumb],
html: `<atom-breadcrumb />`,
})

page.rootInstance.items = breadcrumbItemsMock

await page.waitForChanges()

expect(page.root).toEqualHtml(`
<atom-breadcrumb>
<mock:shadow-root>
<button class="atom-button__back" type="button">
<atom-icon icon="arrow-back-outline" size="small"></atom-icon>
Voltar
</button>
<ion-breadcrumbs class="atom-breadcrumbs">
<ion-breadcrumb class="atom-breadcrumb">
<span class="atom-breadcrumb__text" title="Go to first level">
First level
</span>
<atom-icon icon="caret-forward-sharp" slot="separator"></atom-icon>
</ion-breadcrumb>
<ion-breadcrumb class="atom-breadcrumb">
<span class="atom-breadcrumb__text" title="Go to intermediary level">
Intermediary level
</span>
<atom-icon icon="caret-forward-sharp" slot="separator"></atom-icon>
</ion-breadcrumb>
<ion-breadcrumb class="atom-breadcrumb">
<span class="atom-breadcrumb__text" title="This is the current level">
Current level
</span>
<atom-icon icon="caret-forward-sharp" slot="separator"></atom-icon>
</ion-breadcrumb>
</ion-breadcrumbs>
</mock:shadow-root>
</atom-breadcrumb>
`)
})

it('should not render mobile back button when only one breadcrumb item is sent as prop', async () => {
const page = await newSpecPage({
components: [AtomBreadcrumb],
html: `<atom-breadcrumb />`,
})

page.rootInstance.items = [breadcrumbItemsMock[0]]

await page.waitForChanges()

expect(page.root).toEqualHtml(`
<atom-breadcrumb>
<mock:shadow-root>
<ion-breadcrumbs class="atom-breadcrumbs">
<ion-breadcrumb class="atom-breadcrumb">
<span class="atom-breadcrumb__text" title="Go to first level">
First level
</span>
<atom-icon icon="caret-forward-sharp" slot="separator"></atom-icon>
</ion-breadcrumb>
</ion-breadcrumbs>
</mock:shadow-root>
</atom-breadcrumb>
`)
})
})
48 changes: 48 additions & 0 deletions packages/core/src/components/breadcrumb/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Component, h, Host, Prop } from '@stencil/core'

type BreadcrumbItemProp = {
redirect?: (event: MouseEvent) => void
text: string
title: string
}

@Component({
tag: 'atom-breadcrumb',
styleUrl: 'breadcrumb.scss',
shadow: true,
})
export class AtomBreadcrumb {
@Prop({ mutable: true }) items: BreadcrumbItemProp[] = []

render() {
return (
<Host>
{this.items.length > 1 && (
<button
class="atom-button__back"
type="button"
onClick={this.items[this.items.length - 2].redirect}
>
<atom-icon icon="arrow-back-outline" size="small" />
Voltar
</button>
)}

<ion-breadcrumbs class="atom-breadcrumbs">
{this.items.map((item) => (
<ion-breadcrumb
class="atom-breadcrumb"
onClick={item.redirect}
schirrel marked this conversation as resolved.
Show resolved Hide resolved
key={item.text}
>
<span class="atom-breadcrumb__text" title={item.title}>
{item.text}
</span>
<atom-icon icon="caret-forward-sharp" slot="separator" />
</ion-breadcrumb>
))}
</ion-breadcrumbs>
</Host>
)
}
}
25 changes: 25 additions & 0 deletions packages/core/src/components/breadcrumb/stories/breadcrumb.args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Category } from '@atomium/storybook-utils/enums/table'

export const BreadcrumbStoryArgs = {
decorators: [],
parameters: {
actions: {
handles: [],
},
docs: {
description: {
component:
'Breadcrumbs are navigation items that are used to indicate where a user is on site. Read the [Ionic documentation](https://ionicframework.com/docs/api/breadcrumbs) for more information about this component.',
},
},
},
argTypes: {
items: {
description:
'This is the list of items that will be displayed in the breadcrumb. Items must have `title` and `text` and optionally a `redirect` function when clicking on the item.',
table: {
category: Category.PROPERTIES,
},
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Meta, StoryObj } from '@storybook/web-components'

import { html } from 'lit'

import { BreadcrumbStoryArgs } from './breadcrumb.args'

export default {
title: 'Components/Breadcrumb',
...BreadcrumbStoryArgs,
} as Meta

const createBreadcrumb = () => {
return html`
<atom-breadcrumb />

<script>
;(function () {
const atomBreadcrumb = document.querySelector('atom-breadcrumb')

atomBreadcrumb.items = [
{
text: 'First level',
title: 'Go to first level',
redirect: () => console.log('/first'),
},
{
text: 'Intermediary level',
title: 'Go to intermediary level',
redirect: () => console.log('/intermediary'),
},
{
text: 'Current level',
title: 'This is the current level',
},
]
})()
</script>
`
}

export const Default: StoryObj = {
render: () => createBreadcrumb(),
felipefialho marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Meta, StoryObj } from '@storybook/react'
import React from 'react'

import { AtomBreadcrumb } from '@juntossomosmais/atomium/react'

import { BreadcrumbStoryArgs } from './breadcrumb.args'

export default {
title: 'Components/Breadcrumb',
...BreadcrumbStoryArgs,
} as Meta

const createBreadcrumb = (args) => (
<AtomBreadcrumb items={args.items}></AtomBreadcrumb>
)

export const Default: StoryObj = {
render: (args) => createBreadcrumb(args),
args: {
items: [
{
text: 'First level',
title: 'Go to first level',
redirect: () => console.log('/first'),
},
{
text: 'Intermediary level',
title: 'Go to intermediary level',
redirect: () => console.log('/intermediary'),
},
{
text: 'Current level',
title: 'This is the current level',
},
],
},
}