Skip to content

Commit

Permalink
Merge branch 'main' into fix/disabled-in-button-host
Browse files Browse the repository at this point in the history
  • Loading branch information
igorwessel authored Jul 19, 2023
2 parents f012d46 + 051b52e commit 3ce5476
Show file tree
Hide file tree
Showing 55 changed files with 457 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ packages/tokens/index.ts
packages/core/react
packages/core/vue
packages/core/core.css
packages/core/src/icons.d.ts
storybook-static
dist
tmp
Expand Down
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.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
"utils/*"
],
"scripts": {
"core:build": "npx nx build @juntossomosmais/atomium && npm run react:build",
"core:build": "npm run icons:generate-types && npx nx build @juntossomosmais/atomium && npm run react:build",
"docs:build": "npx nx build @atomium/docs && npx nx build @atomium/docs-react",
"docs-react:start": "npx nx run @atomium/docs-react:start",
"lint:pre-commit": "eslint --resolve-plugins-relative-to . -c ./.eslintrc.json $(git diff --cached --name-only --diff-filter=AM | grep -E \"(.js$|.ts$)\") --cache --cache-location node_modules/.cache/eslint",
"lint:styles": "stylelint '**/*.scss'",
"icons:build": "npx nx build @juntossomosmais/atomium-icons",
"postinstall": "npx husky install & npx nx build @juntossomosmais/atomium:prebuild && npm run icons:build && npm run core:build && npm run tokens:build",
"icons:generate-types": "cd packages/icons && npm run generate:types",
"postinstall": "npx nx build @juntossomosmais/atomium:prebuild && npm run icons:build && npm run core:build && npm run tokens:build",
"pre-commit": "lint-staged",
"prepare": "husky install",
"react:build": "cd packages/react && npm run build",
Expand Down
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
4 changes: 3 additions & 1 deletion packages/core/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, Event, EventEmitter, Host, Prop, h } from '@stencil/core'

import { IconProps } from '../../icons'

@Component({
tag: 'atom-alert',
styleUrl: 'alert.scss',
Expand All @@ -8,7 +10,7 @@ import { Component, Event, EventEmitter, Host, Prop, h } from '@stencil/core'
export class AtomAlert {
@Prop() color?: 'info' | 'success' | 'warning' | 'danger' | 'neutral' =
'neutral'
@Prop() icon?: string
@Prop() icon?: IconProps
@Prop() messageTitle?: string
@Prop() messageText?: string
@Prop() actionText?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Info: StoryObj = {
args: {
...AlertComponentArgs,
color: 'info',
icon: 'people',
icon: 'account-multiple',
},
}

Expand All @@ -53,7 +53,7 @@ export const Warning: StoryObj = {
args: {
...AlertComponentArgs,
color: 'warning',
icon: 'warning',
icon: 'alert',
},
}

Expand All @@ -62,6 +62,6 @@ export const Danger: StoryObj = {
args: {
...AlertComponentArgs,
color: 'danger',
icon: 'people',
icon: 'account-multiple',
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Info: StoryObj = {
args: {
...AlertComponentArgs,
color: 'info',
icon: 'people',
icon: 'account-multiple',
},
}

Expand All @@ -53,7 +53,7 @@ export const Warning: StoryObj = {
args: {
...AlertComponentArgs,
color: 'warning',
icon: 'warning',
icon: 'alert',
},
}

Expand All @@ -62,6 +62,6 @@ export const Danger: StoryObj = {
args: {
...AlertComponentArgs,
color: 'danger',
icon: 'people',
icon: 'account-multiple',
},
}
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) {
&::part(native) {
cursor: pointer;

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

.atom-breadcrumb__text {
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}

&::part(native) {
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="west" size="small"></atom-icon>
Voltar para Intermediary level
</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="arrow-right" 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="arrow-right" 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="arrow-right" 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="arrow-right" slot="separator"></atom-icon>
</ion-breadcrumb>
</ion-breadcrumbs>
</mock:shadow-root>
</atom-breadcrumb>
`)
})
})
50 changes: 50 additions & 0 deletions packages/core/src/components/breadcrumb/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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() {
const prevItem = this.items[this.items.length - 2]

return (
<Host>
{this.items.length > 1 && (
<button
class="atom-button__back"
type="button"
onClick={prevItem.redirect}
>
<atom-icon icon="west" size="small" />
Voltar para {prevItem.text}
</button>
)}

<ion-breadcrumbs class="atom-breadcrumbs">
{this.items.map((item) => (
<ion-breadcrumb
class="atom-breadcrumb"
onClick={item.redirect}
key={item.text}
>
<span class="atom-breadcrumb__text" title={item.title}>
{item.text}
</span>
<atom-icon icon="arrow-right" 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,45 @@
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 breadcrumbsElements = document.querySelectorAll('atom-breadcrumb')
breadcrumbsElements.forEach((atomBreadcrumb) => {
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(),
}
Loading

0 comments on commit 3ce5476

Please sign in to comment.