Skip to content

Commit

Permalink
refactor: refactor breadcrumb to fix misc. bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhojang6 committed Feb 17, 2023
1 parent be028db commit 5a3928f
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ export const breadcrumbClasses = {

open: 'lsd-breadcrumb--open',
disabled: 'lsd-breadcrumb--disabled',
small: `lsd-breadcrumb--small`,
medium: `lsd-breadcrumb--medium`,
large: `lsd-breadcrumb--large`,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { Breadcrumb, BreadcrumbProps } from './Breadcrumb'
export default {
title: 'Breadcrumb',
component: Breadcrumb,
argTypes: {
size: {
type: {
name: 'enum',
value: ['small', 'medium', 'large'],
},
},
},
} as Meta

export const Root: Story<BreadcrumbProps> = (args) => (
Expand All @@ -21,7 +13,6 @@ export const Root: Story<BreadcrumbProps> = (args) => (
)

Root.args = {
size: 'large',
disabled: false,
onChange: undefined,
options: new Array(6).fill(null).map((value, index) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const BreadcrumbStyles = css`
.${breadcrumbClasses.list} {
display: flex;
flex-direction: row;
align-items: flex-start;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
Expand Down Expand Up @@ -43,6 +43,7 @@ export const BreadcrumbStyles = css`
&:hover,
&:focus {
text-decoration: underline;
text-decoration-color: rgb(var(--lsd-border-primary));
}
}
`
10 changes: 2 additions & 8 deletions packages/lsd-react/src/components/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export type BreadcrumbProps = Omit<
disabled?: boolean
ellipsis?: boolean
maxItems?: number
size?: 'small' | 'medium' | 'large'
options?: BreadcrumbOption[]
value?: string | string[]
onChange?: (value: string | string[]) => void
Expand All @@ -31,7 +30,6 @@ export type BreadcrumbProps = Omit<
export const Breadcrumb: React.FC<BreadcrumbProps> & {
classes: typeof breadcrumbClasses
} = ({
size = 'large',
disabled = false,
ellipsis = false,
maxItems,
Expand All @@ -44,7 +42,7 @@ export const Breadcrumb: React.FC<BreadcrumbProps> & {
const ellipsisRef = useRef<HTMLLIElement>(null)
const [open, setOpen] = useState<boolean>(false)

maxItems = Math.max(1, Math.min(maxItems || 1, options.length))
maxItems = Math.max(2, Math.min(maxItems || 2, options.length))

const [root, ...rest] = options
const [collapsed, visible] = !ellipsis
Expand All @@ -58,9 +56,8 @@ export const Breadcrumb: React.FC<BreadcrumbProps> & {
items.map((item, idx) => (
<BreadcrumbItem
key={idx}
current={idx === visible.length - 1}
current={idx === visible.length - 1 && item !== root}
label={item.value}
size={size}
link={item.link}
linkComponent={item?.linkComponent}
/>
Expand All @@ -80,7 +77,6 @@ export const Breadcrumb: React.FC<BreadcrumbProps> & {
className={clsx(
props.className,
breadcrumbClasses.root,
breadcrumbClasses[size],
disabled && breadcrumbClasses.disabled,
open && breadcrumbClasses.open,
)}
Expand All @@ -90,7 +86,6 @@ export const Breadcrumb: React.FC<BreadcrumbProps> & {
{collapsed.length > 0 && (
<BreadcrumbItem
ellipsisRef={ellipsisRef}
size={size}
label={'...'}
onClick={onTrigger}
/>
Expand All @@ -109,7 +104,6 @@ export const Breadcrumb: React.FC<BreadcrumbProps> & {
<BreadcrumbItem
key={idx}
label={opt.value}
size={size}
link={opt.link}
className={breadcrumbItemClasses.itemLink}
linkComponent={opt?.linkComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ export const breadcrumbItemClasses = {

itemCurrentPage: `lsd-breadcrumb-item--current-page`,
itemLink: `lsd-breadcrumb-item-link`,

small: `lsd-breadcrumb-item--small`,
medium: `lsd-breadcrumb-item--medium`,
large: `lsd-breadcrumb-item--large`,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { BreadcrumbItem, BreadcrumbItemProps } from './BreadcrumbItem'
export default {
title: 'BreadcrumbItem',
component: BreadcrumbItem,
argTypes: {
size: {
type: {
name: 'enum',
value: ['small', 'medium', 'large'],
},
},
},
} as Meta

export const Root: Story<BreadcrumbItemProps> = (args) => (
Expand All @@ -22,6 +14,5 @@ export const Root: Story<BreadcrumbItemProps> = (args) => (

Root.args = {
label: 'label',
size: 'large',
current: true,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { breadcrumbItemClasses } from './BreadcrumbItem.classes'
export const BreadcrumbItemStyles = css`
.${breadcrumbItemClasses.root} {
list-style-type: none;
display: flex;
align-items: center;
}
.${breadcrumbClasses.list} li + li::before {
Expand Down Expand Up @@ -32,16 +34,4 @@ export const BreadcrumbItemStyles = css`
}
}
}
.${breadcrumbItemClasses.small} {
padding: 6px 10px;
}
.${breadcrumbItemClasses.medium} {
padding: 6px 12px;
}
.${breadcrumbItemClasses.large} {
padding: 10px 14px;
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react'
import { Typography } from '../Typography'
import { breadcrumbItemClasses } from './BreadcrumbItem.classes'
export type BreadcrumbItemProps = React.LiHTMLAttributes<HTMLLIElement> & {
size: 'small' | 'medium' | 'large'
label: string
link?: string
linkComponent?: React.ComponentType<
Expand All @@ -22,20 +21,20 @@ export const BreadcrumbItem: React.FC<BreadcrumbItemProps> & {
label,
link,
linkComponent: LinkComponent = (props) => <a {...props}>{props.children}</a>,
size = 'large',
current,
selected,
ellipsisRef,
onClick,
className,
...props
}) => {
return (
<li
{...props}
className={clsx(breadcrumbItemClasses.root)}
className={clsx(breadcrumbItemClasses.root, className)}
aria-selected={selected ? 'true' : 'false'}
onClick={onClick}
ref={ellipsisRef}
{...props}
>
<LinkComponent
href={link}
Expand All @@ -44,11 +43,7 @@ export const BreadcrumbItem: React.FC<BreadcrumbItemProps> & {
current && breadcrumbItemClasses.itemCurrentPage,
)}
>
<Typography
color="primary"
component="span"
variant={size === 'large' ? 'label1' : 'label2'}
>
<Typography color="primary" component="span" variant={'label1'}>
{label}
</Typography>
</LinkComponent>
Expand Down

0 comments on commit 5a3928f

Please sign in to comment.