Skip to content

Commit

Permalink
feat(ui): add breadcrumb component
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Jul 25, 2022
1 parent 40c07ca commit ae97c22
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 17 deletions.
Binary file added packages/site/src/assets/imgs/bg-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed packages/site/src/assets/imgs/card-bg.jpg
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/ui/src/components/_virtual-scroll/VirtualScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ function VirtualScroll<T>(props: DVirtualScrollProps<T>, ref: React.ForwardedRef
dEmpty
) : (
<>
<div style={{ [dHorizontal ? 'width' : 'height']: fillSize[0] }} aria-hidden={true}></div>
<div style={{ [dHorizontal ? 'width' : 'height']: fillSize[0] }} aria-hidden></div>
{list}
<div style={{ [dHorizontal ? 'width' : 'height']: fillSize[1] }} aria-hidden={true}></div>
<div style={{ [dHorizontal ? 'width' : 'height']: fillSize[1] }} aria-hidden></div>
</>
)}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/affix/Affix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Affix(props: DAffixProps, ref: React.ForwardedRef<DAffixRef>): JSX.Elem
...referenceStyle,
visibility: 'hidden',
}}
aria-hidden={true}
aria-hidden
></div>
)}
<div
Expand Down
62 changes: 62 additions & 0 deletions packages/ui/src/components/breadcrumb/Breadcrumb.tsx
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>
);
}
7 changes: 7 additions & 0 deletions packages/ui/src/components/breadcrumb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
group: Navigation
title: Breadcrumb
aria: breadcrumb
---

## API
5 changes: 5 additions & 0 deletions packages/ui/src/components/breadcrumb/README.zh-Hant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: 面包屑
---

## API
45 changes: 45 additions & 0 deletions packages/ui/src/components/breadcrumb/demos/1.Basic.md
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 packages/ui/src/components/breadcrumb/demos/2.Separator.md
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>
);
}
```
1 change: 1 addition & 0 deletions packages/ui/src/components/breadcrumb/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Breadcrumb';
4 changes: 2 additions & 2 deletions packages/ui/src/components/card/demos/3.Media.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default function Demo() {
<div style={{ margin: '-1px -1px 0 -1px' }}>
<img
style={{ width: '100%', borderRadius: 'var(--d-border-radius) var(--d-border-radius) 0 0' }}
src="/assets/imgs/card-bg.jpg"
alt="card-bg"
src="/assets/imgs/bg-1.png"
alt="bg-1"
/>
</div>
<DCardContent>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/dropdown/DropdownSub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function DDropdownSub(props: DDropdownSubProps): JSX.Element | null {
})}
style={{ paddingLeft: 12 + dLevel * 16 }}
role="menuitem"
aria-haspopup={true}
aria-haspopup
aria-expanded={dPopupVisible}
aria-disabled={dDisabled}
onClick={pOnClick}
Expand Down
16 changes: 11 additions & 5 deletions packages/ui/src/components/image/ImagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
<li className={`${dPrefix}image-preview__toolbar-page`}>
<DInput
className={`${dPrefix}image-preview__toolbar-page-input`}
dModel={(activeIndex + 1).toString()}
dType="number"
dSize="smaller"
dMin={1}
dMax={dList.length}
dInteger={true}
dModel={(activeIndex + 1).toString()}
dInteger
onModelChange={(val) => {
if (val) {
changeActiveIndex(Number(val) - 1);
Expand Down Expand Up @@ -366,12 +366,12 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
<li className={`${dPrefix}image-preview__toolbar-zoom`}>
<DInput
className={`${dPrefix}image-preview__toolbar-zoom-input`}
dModel={Math.round(activeScale * 100).toString()}
dType="number"
dSize="smaller"
dMin={100}
dStep={10}
dInteger={true}
dModel={Math.round(activeScale * 100).toString()}
dInteger
onModelChange={(val) => {
if (val) {
setScale((draft) => {
Expand Down Expand Up @@ -435,6 +435,12 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
onTouchEnd={() => {
setIsDragging(false);
}}
onWheel={(e) => {
setScale((draft) => {
const oldScale = draft.get(activeSrc) ?? 1;
draft.set(activeSrc, e.deltaY < 0 ? oldScale + 0.1 : Math.max(oldScale - 0.1, 1));
});
}}
/>
}
<ul className={`${dPrefix}image-preview__thumbnail-list`}>
Expand Down Expand Up @@ -467,7 +473,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
</ul>
{dMask && (
<DMask
dVisible={true}
dVisible
onClose={() => {
if (dMaskClosable) {
changeVisible(false);
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export { DAvatar } from './avatar';
export type { DBadgeProps } from './badge';
export { DBadge } from './badge';

export type { DBreadcrumbProps } from './breadcrumb';
export { DBreadcrumb } from './breadcrumb';

export type { DButtonProps } from './button';
export { DButton } from './button';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/menu/MenuSub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function DMenuSub(props: DMenuSubProps): JSX.Element | null {
})}
style={{ paddingLeft: dSpace + dLevel * dStep }}
role="menuitem"
aria-haspopup={true}
aria-haspopup
aria-expanded={dMode === 'vertical' ? dExpand : dPopupVisible}
aria-disabled={dDisabled}
onClick={(e) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/popover/demos/3.AutoPlace.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Demo() {
<div className="auto-place-container">
<div className="overflow">
<DPopover
dVisible={true}
dVisible
dContent={
<>
<div>Some contents...</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/tooltip/demos/3.AutoPlace.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Demo() {
return (
<div className="auto-place-container">
<div className="overflow">
<DTooltip dVisible={true} dTitle="Auto Place" dContainer=".auto-place-container">
<DTooltip dVisible dTitle="Auto Place" dContainer=".auto-place-container">
<DButton>Auto Place</DButton>
</DTooltip>
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/hooks/d-config/contex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
DAutoCompleteProps,
DAvatarProps,
DBadgeProps,
DBreadcrumbProps,
DButtonProps,
DCardProps,
DCardHeaderProps,
Expand Down Expand Up @@ -75,6 +76,7 @@ export type DComponentConfig = {
DAutoComplete: DAutoCompleteProps<any>;
DAvatar: DAvatarProps;
DBadge: DBadgeProps;
DBreadcrumb: DBreadcrumbProps<any, any>;
DButton: DButtonProps;
DCard: DCardProps;
DCardHeader: DCardHeaderProps;
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/styles/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import 'components/auto-complete';
@import 'components/avatar';
@import 'components/badge';
@import 'components/breadcrumb';
@import 'components/button';
@import 'components/card';
@import 'components/cascader';
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ $colors: (
/** component **/
--#{$variable-prefix}mask-background-color: rgb(0 0 0 / 20%);
--#{$variable-prefix}avatar-background-color: #bdbdbd;
--#{$variable-prefix}breadcrumb-color: #b1b1b1;
--#{$variable-prefix}slides-navigation-background-color-hover: rgb(245 245 245);
--#{$variable-prefix}switch-background-color: #d4d6d9;
--#{$variable-prefix}tabs-slider-background-color: hsl(0deg 0% 97%);
Expand Down
32 changes: 32 additions & 0 deletions packages/ui/src/styles/components/breadcrumb.scss
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);
}
}
2 changes: 0 additions & 2 deletions packages/ui/src/styles/components/tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@
flex-shrink: 0;
padding: 0;
margin: 0;
color: var(--#{$variable-prefix}color-icon-decorator);
background-color: var(--#{$variable-prefix}background-color);
border: none;
transition: color var(--#{$variable-prefix}animation-duration-base) linear;
Expand Down Expand Up @@ -449,7 +448,6 @@

padding: 0;
margin: 0 0 0 4px;
color: var(--#{$variable-prefix}color-icon-decorator);
background-color: transparent;
border: none;
transition: color var(--#{$variable-prefix}animation-duration-base) linear;
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/styles/components/upload.scss
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@

@include e(picture-button-icon) {
font-size: 1.1em;
color: var(--#{$variable-prefix}color-icon-decorator);
}

@include e(picture-button-text) {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/styles/theme-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ body.dark {
/** component **/
--#{$variable-prefix}mask-background-color: rgb(0 0 0 / 40%);
--#{$variable-prefix}avatar-background-color: #666;
--#{$variable-prefix}breadcrumb-color: #787878;
--#{$variable-prefix}slides-navigation-background-color-hover: rgb(45 45 45);
--#{$variable-prefix}switch-background-color: #5f6164;
--#{$variable-prefix}tabs-slider-background-color: hsl(0deg 0% 26%);
Expand Down

0 comments on commit ae97c22

Please sign in to comment.