Skip to content

Commit

Permalink
Made BreadcrumbButton consistent with Item and Link (microsoft#28672)
Browse files Browse the repository at this point in the history
* Made BreadcrumbButton consistent with Item and Link
  • Loading branch information
ValentinaKozlova authored Aug 3, 2023
1 parent 595d43b commit d445789
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: made BreadcrumbButton consistent with other items",
"packageName": "@fluentui/react-breadcrumb-preview",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const defaultButtonStyles = {
const useStyles = makeStyles({
root: {
...shorthands.padding(tokens.spacingHorizontalNone),
minWidth: 'unset',
textWrap: 'nowrap',
},
small: {
height: '24px',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as React from 'react';
import { Breadcrumb, BreadcrumbItem, BreadcrumbDivider, BreadcrumbProps } from '@fluentui/react-breadcrumb-preview';
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbDivider,
BreadcrumbProps,
BreadcrumbButton,
BreadcrumbLink,
} from '@fluentui/react-breadcrumb-preview';
import { RadioGroup, Radio, Label } from '@fluentui/react-components';

type Item = {
Expand Down Expand Up @@ -34,6 +41,31 @@ function renderItem(item: Item, size: BreadcrumbProps['size']) {
</React.Fragment>
);
}

function renderButton(item: Item) {
const isLastItem = items.length - 1 === item.key;
return (
<React.Fragment key={`button-item-${item.key}`}>
<BreadcrumbItem current={isLastItem}>
<BreadcrumbButton>{item.value}</BreadcrumbButton>
</BreadcrumbItem>
{!isLastItem && <BreadcrumbDivider />}
</React.Fragment>
);
}

function renderLink(item: Item) {
const isLastItem = items.length - 1 === item.key;
return (
<React.Fragment key={`link-item-${item.key}`}>
<BreadcrumbItem current={isLastItem}>
<BreadcrumbLink>{item.value}</BreadcrumbLink>
</BreadcrumbItem>
{!isLastItem && <BreadcrumbDivider />}
</React.Fragment>
);
}

export const BreadcrumbSize = () => {
const [dividerType, setDividerType] = React.useState('chevron' as BreadcrumbProps['dividerType']);
return (
Expand All @@ -52,12 +84,30 @@ export const BreadcrumbSize = () => {
<Breadcrumb aria-label="Small breadcrumb example with slashes" size="small" dividerType={dividerType}>
{items.map(item => renderItem(item, 'small'))}
</Breadcrumb>
<Breadcrumb aria-label="Small breadcrumb example with buttons" size="small">
{items.map(item => renderButton(item))}
</Breadcrumb>
<Breadcrumb aria-label="Small breadcrumb example with links" size="small">
{items.map(item => renderLink(item))}
</Breadcrumb>
<h2>Medium</h2>
<Breadcrumb aria-label="Default breadcrumb">{items.map(item => renderItem(item, 'medium'))}</Breadcrumb>
<Breadcrumb aria-label="Medium breadcrumb example with buttons" size="medium">
{items.map(item => renderButton(item))}
</Breadcrumb>
<Breadcrumb aria-label="Medium breadcrumb example with links" size="medium">
{items.map(item => renderLink(item))}
</Breadcrumb>
<h2>Large</h2>
<Breadcrumb aria-label="Large breadcrumb" size="large">
{items.map(item => renderItem(item, 'large'))}
</Breadcrumb>
<Breadcrumb aria-label="Large breadcrumb example with buttons" size="large">
{items.map(item => renderButton(item))}
</Breadcrumb>
<Breadcrumb aria-label="Large breadcrumb example with links" size="large">
{items.map(item => renderLink(item))}
</Breadcrumb>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const BreadcrumbControlledOverflowExample = () => {

return (
<div className={mergeClasses(styles.example, styles.horizontal)}>
<Overflow>
<Overflow padding={40}>
<Breadcrumb>
{startDisplayedItems.map((item: ButtonItem) => renderButton(item, false))}
<ControlledOverflowMenu
Expand Down

0 comments on commit d445789

Please sign in to comment.