Skip to content

Commit

Permalink
Merge pull request #966 from takenet/developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
lucasMurtaVI authored Dec 6, 2024
2 parents f85ccc9 + 12a6485 commit c1a0aa5
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ export namespace Components {
}
interface BdsBreadcrumb {
"items": string | Array<{ label: string; href?: string }>;
"maxVisible": number;
}
interface BdsButton {
/**
Expand Down Expand Up @@ -4014,7 +4013,6 @@ declare namespace LocalJSX {
}
interface BdsBreadcrumb {
"items"?: string | Array<{ label: string; href?: string }>;
"maxVisible"?: number;
}
interface BdsButton {
/**
Expand Down
44 changes: 44 additions & 0 deletions src/components/breadcrumb/breadcrumb.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Story,
ArgsTable,
Canvas,
Meta,
Title,
Subtitle,
Description,
Primary,
Controls,
Stories,
Source,
} from '@storybook/blocks';
import * as BreadcrumbStories from './breadcrumb.stories';

# Breadcrumb

[Component Detail](https://design.blip.ai/document/13#/breadcrumb/visao-geral-breadcrumb)
&nbsp;|&nbsp;
[Component Design](https://design.blip.ai/d/UbKsV1JhXTK4/design-1#/breadcrumb/resumo-breadcrumb)
&nbsp;|&nbsp;
[Accessibility](https://design.blip.ai/d/UbKsV1JhXTK4/design-1#/breadcrumb/acessibilidade-breadcrumb)

## Overview

Breadcrumbs provide a navigational aid to help users understand their location within the hierarchy of a website or app and easily move back to higher levels of that hierarchy.

<Canvas of={BreadcrumbStories.Properties}></Canvas>

<Meta isTemplate />

The following properties are available for the Breadcrumb component.

<Controls />

## Events

Some examples of Breadcrumb Events.

<Source of={BreadcrumbStories.Events} />

## Build on React

<Source of={BreadcrumbStories.FrameworkReact} />
98 changes: 98 additions & 0 deletions src/components/breadcrumb/breadcrumb.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { useState } from 'react';
import DocumentationTemplate from './breadcrumb.mdx';
import { BdsBreadcrumb } from '../../../blip-ds-react/dist/components';

export default {
title: 'Components/Breadcrumb',
tags: ['autodocs'],
parameters: {
docs: {
page: DocumentationTemplate,
},
},
};

export const Properties = (args) => {
return (
<bds-breadcrumb
items={args.items}
></bds-breadcrumb>
);
};

Properties.argTypes = {
items: {
table: {
defaultValue: { summary: '' },
},
description: 'Define the labels and hrefs for the breadcrumb items.',
control: { type: 'text' },
},
};

Properties.args = {
items: JSON.stringify([
{ label: 'Home', href: '/' },
{ label: 'About', href: '/about' },
{ label: 'Contact', href: '/contact' },
{ label: 'Current Page' },
]),
};

export const Events = () => {
const [clickedItem, setClickedItem] = useState(null);

const handleBreadcrumbClick = (event) => {
const detail = event.detail;
setClickedItem(detail);
console.log('Breadcrumb item clicked:', detail);
};

return (
<div>
<bds-breadcrumb
items={JSON.stringify([
{ label: 'Home', href: '/' },
{ label: 'Features', href: '/features' },
{ label: 'Pricing', href: '/pricing' },
{ label: 'Documentation' },
])}
onBreadcrumbItemClick={(event) => handleBreadcrumbClick(event)}
></bds-breadcrumb>
{clickedItem && (
<div>
<p>
You clicked on: <strong>{clickedItem.label}</strong>
{clickedItem.href && (
<span>
{' '}
(<a href={clickedItem.href}>{clickedItem.href}</a>)
</span>
)}
</p>
</div>
)}
</div>
);
};

export const FrameworkReact = () => {
const breadcrumbItems = [
{ label: 'Dashboard', href: '/dashboard' },
{ label: 'Settings', href: '/settings' },
{ label: 'Profile', href: '/profile' },
{ label: 'Edit Profile' },
];

const handleBreadcrumbClick = (event) => {
const detail = event.detail;
console.log('React Breadcrumb item clicked:', detail);
};

return (
<BdsBreadcrumb
items={breadcrumbItems}
onBreadcrumbItemClick={(event) => handleBreadcrumbClick(event)}
/>
);
};
53 changes: 33 additions & 20 deletions src/components/breadcrumb/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class Breadcrumb {

@State() parsedItems: Array<{ label: string; href?: string }> = [];

@State() isDropdownOpen: boolean = false;

@Watch('items')
parseItems(newValue: string | Array<{ label: string; href?: string }>) {
if (typeof newValue === 'string') {
Expand All @@ -27,10 +29,6 @@ export class Breadcrumb {
this.parseItems(this.items);
}

@Prop() maxVisible: number = 3;

@State() isDropdownOpen: boolean = false;

toggleDropdown() {
this.isDropdownOpen = !this.isDropdownOpen;
}
Expand All @@ -41,13 +39,13 @@ export class Breadcrumb {
}

const visibleItems =
this.parsedItems.length <= this.maxVisible
this.parsedItems.length <= 3
? this.parsedItems
: [
this.parsedItems[0],
{ label: '...', href: null },
this.parsedItems[this.parsedItems.length - 1],
];
this.parsedItems[0],
{ label: '...', href: null },
this.parsedItems[this.parsedItems.length - 1],
];

return (
<nav aria-label="breadcrumb">
Expand All @@ -63,18 +61,29 @@ export class Breadcrumb {
{item.label === '...' ? (
<bds-dropdown active-mode="click" position="auto">
<bds-grid slot="dropdown-content">
<bds-grid direction='column' padding='1' gap="half">
{this.parsedItems.slice(1, -1).map((subItem, index) => (
<bds-grid>
<bds-grid direction="column" padding="1" gap="half">
{this.parsedItems.slice(1, -1).map((subItem, idx) => (
<bds-grid class={`breadcrumb__button--${idx}`}>
{subItem.href ? (
<a href={subItem.href} class={`breadcrumb__button--${index} breadcrumb__link`}>
<bds-grid align-items='center' gap='half'>
<bds-icon name="reply" theme='outline' class="button--icon" size='x-small'></bds-icon>
<bds-button variant="text" color='content' size='short'>
<a
href={subItem.href}
class={`breadcrumb__link breadcrumb__button--${idx}`}
>
<bds-grid align-items="center" gap="half">
<bds-icon
name="reply"
theme="outline"
class="button--icon"
size="x-small"
></bds-icon>
<bds-button
variant="text"
color="content"
size="short"
>
{subItem.label}
</bds-button>
</bds-grid>

</a>
) : (
<span>{subItem.label}</span>
Expand All @@ -83,19 +92,24 @@ export class Breadcrumb {
))}
</bds-grid>
</bds-grid>
<bds-grid slot="dropdown-activator">
<bds-grid slot="dropdown-activator" align-items="center">
<bds-button
variant="text"
color="content"
size="short"
onClick={() => this.toggleDropdown()}
icon-left="more-options-horizontal"
></bds-button>
<bds-icon name="arrow-right" size="x-small"></bds-icon>
</bds-grid>
</bds-dropdown>
) : item.href ? (
<bds-grid direction="row">
<bds-typo variant="fs-12" margin={false} class="breadcrumb__link--text">
<bds-typo
variant="fs-12"
margin={false}
class="breadcrumb__link--text"
>
<a href={item.href} class="breadcrumb__link">
{item.label}
</a>
Expand All @@ -104,7 +118,6 @@ export class Breadcrumb {
</bds-grid>
) : (
<bds-grid direction="row">
<bds-icon name="arrow-right" size="x-small"></bds-icon>
<bds-typo variant="fs-12" bold="semi-bold" margin={false}>
{item.label}
</bds-typo>
Expand Down
7 changes: 3 additions & 4 deletions src/components/breadcrumb/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------ | ------------- | ----------- | ----------------------------------------------- | ------- |
| `items` | `items` | | `string \| { label: string; href?: string; }[]` | `[]` |
| `maxVisible` | `max-visible` | | `number` | `3` |
| Property | Attribute | Description | Type | Default |
| -------- | --------- | ----------- | ----------------------------------------------- | ------- |
| `items` | `items` | | `string \| { label: string; href?: string; }[]` | `[]` |


## Dependencies
Expand Down

0 comments on commit c1a0aa5

Please sign in to comment.