-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from 'react'; | ||
|
||
import type {Href, RouterOptions} from '../../types'; | ||
import {filterDOMProps} from '../../utils/filterDOMProps'; | ||
|
||
import type {BreadcrumbsItemProps} from './Breadcrumbs'; | ||
import {b, shouldClientNavigate} from './utils'; | ||
|
||
interface BreadcrumbItemProps extends BreadcrumbsItemProps { | ||
onAction?: () => void; | ||
title?: string; | ||
isCurrent?: boolean; | ||
isMenu?: boolean; | ||
disabled?: boolean; | ||
navigate?: (href: Href, routerOptions: RouterOptions | undefined) => void; | ||
} | ||
export function BreadcrumbItem(props: BreadcrumbItemProps) { | ||
const Element = props.href ? 'a' : 'span'; | ||
const domProps = filterDOMProps(props, {labelable: true}); | ||
|
||
let title = props.title; | ||
if (!title && typeof props.children === 'string') { | ||
title = props.children; | ||
} | ||
|
||
const handleAction = (event: React.MouseEvent | React.KeyboardEvent) => { | ||
if (props.disabled || props.isCurrent) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
|
||
if (typeof props.onAction === 'function') { | ||
props.onAction(); | ||
} | ||
|
||
const target = event.currentTarget; | ||
if (typeof props.navigate === 'function' && target instanceof HTMLAnchorElement) { | ||
if (props.href && !event.isDefaultPrevented() && shouldClientNavigate(target, event)) { | ||
event.preventDefault(); | ||
props.navigate(props.href, props.routerOptions); | ||
} | ||
} | ||
}; | ||
|
||
const isDisabled = props.disabled || props.isCurrent; | ||
let linkProps: React.AllHTMLAttributes<HTMLElement> = { | ||
title, | ||
onClick: handleAction, | ||
'aria-disabled': isDisabled ? true : undefined, | ||
}; | ||
if (Element === 'a') { | ||
linkProps.href = props.href; | ||
linkProps.target = props.target; | ||
linkProps.rel = props.target === '_blank' && !props.rel ? 'noopener noreferrer' : props.rel; | ||
} else { | ||
linkProps.role = 'link'; | ||
linkProps.tabIndex = isDisabled ? undefined : 0; | ||
linkProps.onKeyDown = (event: React.KeyboardEvent) => { | ||
if (event.key === 'Enter') { | ||
handleAction(event); | ||
} | ||
}; | ||
} | ||
|
||
if (props.isCurrent) { | ||
linkProps['aria-current'] = 'page'; | ||
} | ||
|
||
if (props.isMenu) { | ||
linkProps = {}; | ||
} | ||
|
||
return ( | ||
<Element | ||
{...domProps} | ||
{...linkProps} | ||
className={ | ||
props.isMenu | ||
? undefined | ||
: b('link', { | ||
'is-current': props.isCurrent, | ||
'is-disabled': isDisabled && !props.isCurrent, | ||
}) | ||
} | ||
> | ||
{props.children} | ||
</Element> | ||
); | ||
} | ||
|
||
BreadcrumbItem.displayName = 'Breadcrumbs.Item'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
@use '../../variables'; | ||
@use '../../../../styles/mixins'; | ||
|
||
$block: '.#{variables.$ns}breadcrumbs2'; | ||
|
||
#{$block} { | ||
&__list { | ||
display: flex; | ||
flex-wrap: nowrap; | ||
justify-content: flex-start; | ||
|
||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
&__list-item { | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
|
||
height: 24px; | ||
white-space: nowrap; | ||
color: var(--g-color-text-primary); | ||
|
||
&:last-child { | ||
font-weight: var(--g-text-accent-font-weight); | ||
overflow: hidden; | ||
|
||
#{$block}__link { | ||
@include mixins.overflow-ellipsis(); | ||
} | ||
} | ||
|
||
&_calculating:last-child { | ||
overflow: visible; | ||
} | ||
} | ||
|
||
&__link { | ||
cursor: default; | ||
position: relative; | ||
text-decoration: none; | ||
outline: none; | ||
touch-action: manipulation; | ||
-webkit-tap-highlight-color: transparent; | ||
|
||
height: 24px; | ||
line-height: 24px; | ||
vertical-align: middle; | ||
padding: 0 var(--g-spacing-2); | ||
border-radius: var(--g-focus-border-radius); | ||
|
||
color: inherit; | ||
|
||
&_is-disabled { | ||
color: var(--g-color-text-hint); | ||
} | ||
|
||
&:not([aria-disabled]) { | ||
cursor: pointer; | ||
|
||
&:hover { | ||
color: var(--g-color-text-link-hover); | ||
} | ||
} | ||
|
||
&:focus-visible { | ||
outline: 2px solid var(--g-color-line-focus); | ||
outline-offset: -2px; | ||
} | ||
} | ||
|
||
&__divider { | ||
display: flex; | ||
align-items: center; | ||
color: var(--g-color-text-secondary); | ||
} | ||
|
||
&__more-button { | ||
--g-button-border-radius: var(--g-focus-border-radius); | ||
--g-button-focus-outline-offset: -2px; | ||
} | ||
|
||
&__popup_staircase { | ||
$menu: '.#{variables.$ns}menu'; | ||
$staircaseLength: 10; | ||
#{$menu} { | ||
#{$menu}__list-item { | ||
#{$menu}__item[class] { | ||
padding-inline-start: 8px * $staircaseLength; | ||
} | ||
} | ||
|
||
@for $i from 0 through $staircaseLength { | ||
#{$menu}__list-item:nth-child(#{$i}) { | ||
#{$menu}__item[class] { | ||
padding-inline-start: 8px * $i; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.