Skip to content

Commit

Permalink
Merge pull request #16 from broadlume/feat/breadcrumb
Browse files Browse the repository at this point in the history
Component: Breadcrumb
  • Loading branch information
isrodela authored Oct 24, 2024
2 parents b0131b4 + 20eb62e commit 383fe0d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/components/breadcrumb/breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Meta, StoryObj } from '@storybook/react';
import { BreadCrumb, BreadCrumbItem } from './breadcrumb';
import { FaChevronCircleRight } from 'react-icons/fa';

// Let's put a description here because Storybook is buggy
/** A vertically stacked set of interactive headings that each reveal a section of content. */
const meta: Meta<typeof BreadCrumb> = {
component: BreadCrumb,
title: 'Components/BreadCrumb',
};

export default meta;
type Story = StoryObj<typeof BreadCrumbItem>;

/** A basic BreadCrumb. */
export const Simple: Story = {
args: {
classNames: {
wrapper: [],
label: [''],
},
onClick: (e) => alert('clicked=' + e.target.id),
},
render: (args) => (
<BreadCrumb>
<BreadCrumbItem id='item1' label='Item 1' {...args} />
<BreadCrumbItem id='item2' label='Item 2' {...args} />
<BreadCrumbItem id='item3' label='Item 3' isLast={true} {...args} />
</BreadCrumb>
),
};

export const Custom: Story = {
args: {
classNames: {
wrapper: [''],
label: ['~text-4xl ~text-junglegreen'],
},
customIcon: () => (
<FaChevronCircleRight className='~mx-3 ~text-lg ~text-ash-light' />
),
onClick: (e) => alert('clicked=' + e.target.id),
},
render: (args) => (
<BreadCrumb>
<BreadCrumbItem {...args} id='item1' label='Item 1' />
<BreadCrumbItem {...args} id='item2' label='Item 2' />
<BreadCrumbItem {...args} id='item3' label='Item 3' isLast={true} />
</BreadCrumb>
),
};
85 changes: 85 additions & 0 deletions src/components/breadcrumb/breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import clsx from 'clsx';
import React from 'react';
import { FaChevronRight } from 'react-icons/fa';

/**
* Functional component for rendering a breadcrumb.
*
* @param className - Additional CSS classes to be applied to the breadcrumb container.
* @param children - The breadcrumb items to be rendered.
* @param props - Additional HTML attributes to be spread on the breadcrumb container.
* @returns JSX element representing the breadcrumb.
*/
const BreadCrumb = ({
className = '',
children,
...props
}: React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>) => {
return (
<div className={clsx(`~my-4 ~flex ~flex-row`, className)} {...props}>
{children}
</div>
);
};

type BreadCrumbItemProps = {
label: string;
isLast?: boolean;
customIcon?: () => JSX.Element;
classNames?: { wrapper?: string[]; label?: string[] };
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'classesName'>;

/**
* Functional component for rendering a single breadcrumb item.
*
* @param label - The label text for the breadcrumb item.
* @param classNames - Additional CSS classes to be applied to the breadcrumb item.
* @param id - The unique identifier for the breadcrumb item.
* @param isLast - Indicates whether this breadcrumb item is the last one.
* @param onClick - The function to be called when the breadcrumb item is clicked.
* @param customIcon - A custom icon component to be displayed instead of the default chevron icon.
* @param props - Additional HTML attributes to be spread on the breadcrumb item container.
* @returns JSX element representing the breadcrumb item.
*/
const BreadCrumbItem = ({
label,
classNames = { wrapper: [], label: [] },
id,
isLast = false,
onClick,
customIcon: CustomIcon,
...props
}: React.PropsWithChildren<BreadCrumbItemProps>) => {
return (
<div
id={id + 'wrapper'}
className={clsx(
`~flex ~flex-row ~items-center ~justify-between`,
classNames.wrapper
)}
{...props}
>
<span
id={id}
onClick={onClick}
className={clsx(
`~font-sans ~text-xs`,
onClick ? '~underline hover:~cursor-pointer' : '',
!isLast ? '~text-gold' : '',
classNames.label
)}
>
{label}
</span>
{!isLast ? (
CustomIcon ? (
<CustomIcon />
) : (
<FaChevronRight className='~mx-1.5 ~text-xs ~text-ash-light' />
)
) : null}
</div>
);
};

export { BreadCrumb, BreadCrumbItem };
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export * from '@components/truncated-text/truncated-text';
export * from '@src/reports/summary-tile/summary-tile';

export * from '@src/misc/custom-data-table/custom-data-table';
export * from '@components/breadcrumb/breadcrumb';

0 comments on commit 383fe0d

Please sign in to comment.