-
Notifications
You must be signed in to change notification settings - Fork 42
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
24 changed files
with
227 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
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
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,62 @@ | ||
import type { DId } from '../../utils/global'; | ||
|
||
import React from 'react'; | ||
|
||
import { usePrefixConfig, useComponentConfig } from '../../hooks'; | ||
import { getClassName, registerComponentMate } from '../../utils'; | ||
|
||
export interface DBreadcrumbOption<ID extends DId> { | ||
id: ID; | ||
title: React.ReactNode; | ||
link?: boolean; | ||
separator?: React.ReactNode; | ||
} | ||
|
||
export interface DBreadcrumbProps<ID extends DId, T extends DBreadcrumbOption<ID>> | ||
extends Omit<React.HTMLAttributes<HTMLElement>, 'children'> { | ||
dList: T[]; | ||
dSeparator?: React.ReactNode; | ||
onItemClick?: (id: ID, link: T) => void; | ||
} | ||
|
||
const { COMPONENT_NAME } = registerComponentMate({ COMPONENT_NAME: 'DBreadcrumb' }); | ||
export function DBreadcrumb<ID extends DId, T extends DBreadcrumbOption<ID>>(props: DBreadcrumbProps<ID, T>): JSX.Element | null { | ||
const { | ||
dList, | ||
dSeparator, | ||
onItemClick, | ||
|
||
...restProps | ||
} = useComponentConfig(COMPONENT_NAME, props); | ||
|
||
//#region Context | ||
const dPrefix = usePrefixConfig(); | ||
//#endregion | ||
|
||
return ( | ||
<nav {...restProps} className={getClassName(restProps.className, `${dPrefix}breadcrumb`)}> | ||
<ol className={`${dPrefix}breadcrumb__list`}> | ||
{dList.map((item, index) => ( | ||
<React.Fragment key={item.id}> | ||
<li | ||
className={getClassName(`${dPrefix}breadcrumb__item`, { | ||
[`${dPrefix}breadcrumb__item--link`]: item.link, | ||
[`${dPrefix}breadcrumb__item--last`]: index === dList.length - 1, | ||
})} | ||
onClick={() => { | ||
onItemClick?.(item.id, item); | ||
}} | ||
> | ||
{item.title} | ||
</li> | ||
{index !== dList.length - 1 && ( | ||
<li className={`${dPrefix}breadcrumb__separator`} aria-hidden> | ||
{item.separator ?? dSeparator ?? '/'} | ||
</li> | ||
)} | ||
</React.Fragment> | ||
))} | ||
</ol> | ||
</nav> | ||
); | ||
} |
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,7 @@ | ||
--- | ||
group: Navigation | ||
title: Breadcrumb | ||
aria: breadcrumb | ||
--- | ||
|
||
## API |
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,5 @@ | ||
--- | ||
title: 面包屑 | ||
--- | ||
|
||
## API |
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,45 @@ | ||
--- | ||
title: | ||
en-US: Basic | ||
zh-Hant: 基本 | ||
--- | ||
|
||
# en-US | ||
|
||
The simplest usage. | ||
|
||
# zh-Hant | ||
|
||
最简单的用法。 | ||
|
||
```tsx | ||
import { DBreadcrumb } from '@react-devui/ui'; | ||
import { HomeOutlined } from '@react-devui/ui/icons'; | ||
|
||
export default function Demo() { | ||
return ( | ||
<DBreadcrumb | ||
dList={[ | ||
{ | ||
id: 0, | ||
title: ( | ||
<div style={{ display: 'flex', alignItems: 'center', gap: '0 4px' }}> | ||
<HomeOutlined /> | ||
Home | ||
</div> | ||
), | ||
}, | ||
{ | ||
id: 1, | ||
title: <a>Component</a>, | ||
link: true, | ||
}, | ||
{ | ||
id: 2, | ||
title: 'Breadcrumb', | ||
}, | ||
]} | ||
></DBreadcrumb> | ||
); | ||
} | ||
``` |
47 changes: 47 additions & 0 deletions
47
packages/ui/src/components/breadcrumb/demos/2.Separator.md
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,47 @@ | ||
--- | ||
title: | ||
en-US: Custom separator | ||
zh-Hant: 自定义分隔符 | ||
--- | ||
|
||
# en-US | ||
|
||
Configure the separator globally or configure each item individually. | ||
|
||
# zh-Hant | ||
|
||
全局配置分隔符或者单独配置每一项。 | ||
|
||
```tsx | ||
import { DBreadcrumb } from '@react-devui/ui'; | ||
import { HomeOutlined, RightOutlined } from '@react-devui/ui/icons'; | ||
|
||
export default function Demo() { | ||
return ( | ||
<DBreadcrumb | ||
dList={[ | ||
{ | ||
id: 0, | ||
title: ( | ||
<div style={{ display: 'flex', alignItems: 'center', gap: '0 4px' }}> | ||
<HomeOutlined /> | ||
Home | ||
</div> | ||
), | ||
separator: '-', | ||
}, | ||
{ | ||
id: 1, | ||
title: <a>Component</a>, | ||
link: true, | ||
}, | ||
{ | ||
id: 2, | ||
title: 'Breadcrumb', | ||
}, | ||
]} | ||
dSeparator={<RightOutlined dSize="0.9em" />} | ||
></DBreadcrumb> | ||
); | ||
} | ||
``` |
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 @@ | ||
export * from './Breadcrumb'; |
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
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
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
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
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
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
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
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
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
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
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,32 @@ | ||
@include b(breadcrumb) { | ||
@include e(list) { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 4px 8px; | ||
align-items: center; | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
@include e(item) { | ||
color: var(--#{$variable-prefix}breadcrumb-color); | ||
|
||
@include m(link) { | ||
cursor: pointer; | ||
transition: color var(--#{$variable-prefix}animation-duration-base) linear; | ||
|
||
&:hover { | ||
color: var(--#{$variable-prefix}text-color); | ||
} | ||
} | ||
|
||
@include m(last) { | ||
color: var(--#{$variable-prefix}text-color); | ||
} | ||
} | ||
|
||
@include e(separator) { | ||
color: var(--#{$variable-prefix}breadcrumb-color); | ||
} | ||
} |
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
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
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