-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
c1904b9
commit 5c56228
Showing
6 changed files
with
229 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,39 @@ | ||
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui'; | ||
import type { DividerProps } from '@yuntijs/ui'; | ||
import { Divider } from '@yuntijs/ui'; | ||
|
||
export default () => { | ||
const store = useCreateStore(); | ||
const control: DividerProps | any = useControls( | ||
{ | ||
mode: { | ||
options: ['expanded', 'line', 'default'], | ||
value: 'line', | ||
}, | ||
defaultOpen: false, | ||
content: 'content', | ||
iconPlacement: { | ||
options: ['left', 'right'], | ||
value: 'left', | ||
}, | ||
type: { | ||
options: ['horizontal', 'vertical'], | ||
value: 'horizontal', | ||
}, | ||
orientation: { | ||
options: ['left', 'right', 'center'], | ||
value: 'left', | ||
}, | ||
orientationMargin: 10, | ||
children: '', | ||
dashed: false, | ||
plain: false, | ||
}, | ||
{ store } | ||
); | ||
return ( | ||
<StoryBook levaStore={store}> | ||
<Divider {...control} /> | ||
</StoryBook> | ||
); | ||
}; |
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,49 @@ | ||
import { Divider } from '@yuntijs/ui'; | ||
|
||
export default () => { | ||
return ( | ||
<div style={{ width: '100%' }}> | ||
<div> | ||
<Divider mode="line" type="horizontal" /> | ||
</div> | ||
<div> | ||
分割线左侧 | ||
<Divider mode="line" type="vertical" /> | ||
分割线右侧 | ||
</div> | ||
|
||
<div> | ||
<Divider | ||
content={ | ||
<div> | ||
The YuntiUI components are inspired by LobeUI and developed based on Antd components, | ||
fully compatible with Antd components, and it is recommended to use antd-style as the | ||
default css-in-js styling solution. | ||
</div> | ||
} | ||
dashed={true} | ||
defaultOpen={true} | ||
iconPlacement="left" | ||
mode="expanded" | ||
orientation="left" | ||
orientationMargin={0} | ||
> | ||
YuntiUI | ||
</Divider> | ||
</div> | ||
|
||
<div> | ||
<Divider | ||
dashed={true} | ||
defaultOpen={true} | ||
iconPlacement="left" | ||
mode="default" | ||
orientation="left" | ||
orientationMargin={0} | ||
> | ||
YuntiUI | ||
</Divider> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,48 @@ | ||
--- | ||
nav: Components | ||
group: Layout | ||
title: Divider | ||
description: A divider line separates different content. | ||
--- | ||
|
||
## Usage | ||
|
||
based on antd [Divider](https://ant.design/components/divider-cn/) component. | ||
|
||
### Simple usage | ||
|
||
```jsx | pure | ||
import { Divider } from '@yuntijs/ui'; | ||
|
||
export default () => { | ||
return ( | ||
<Divider | ||
mode="expanded" | ||
defaultOpen={true} | ||
content={ | ||
<div> | ||
The YuntiUI components are inspired by LobeUI and developed based on Antd components, | ||
fully compatible with Antd components, and it is recommended to use antd-style as the | ||
default css-in-js styling solution. | ||
</div> | ||
} | ||
iconPlacement="left" | ||
orientation="left" | ||
orientationMargin={0} | ||
dashed={true} | ||
> | ||
YuntiUI | ||
</Divider> | ||
); | ||
}; | ||
``` | ||
|
||
<code src="./demos/index.tsx" center></code> | ||
|
||
## Playground | ||
|
||
<code src="./demos/Playground.tsx" nopadding></code> | ||
|
||
## APIs | ||
|
||
<API></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,76 @@ | ||
import { MinusSquareOutlined, PlusSquareOutlined } from '@ant-design/icons'; | ||
import { Divider as AntdDivider, type DividerProps as AntdDividerProps, Space } from 'antd'; | ||
import React, { useState } from 'react'; | ||
|
||
import { useStyles } from './style'; | ||
|
||
export interface CustomDividerProps { | ||
/** | ||
* @description type of the divider | ||
* @default 'default' | ||
*/ | ||
mode?: 'expanded' | 'line' | 'default'; | ||
/** | ||
* @description Default whether to expand. This parameter is available only when mode is expanded | ||
* @default 'false' | ||
*/ | ||
defaultOpen?: boolean; | ||
/** | ||
* @description Expand content. This parameter is available only when mode is expanded | ||
* @default '-' | ||
*/ | ||
content?: React.ReactNode; | ||
/** | ||
* @description The position of icon. This parameter is available only when mode is expanded and default | ||
* @default 'left' | ||
*/ | ||
iconPlacement?: 'left' | 'right'; | ||
/** | ||
* @description custom open icon. This parameter is available only when mode is expanded | ||
* @default '-' | ||
*/ | ||
openIcon?: React.ReactNode; | ||
/** | ||
* @description custom close icon. This parameter is available only when mode is expanded | ||
* @default '-' | ||
*/ | ||
closeIcon?: React.ReactNode; | ||
} | ||
export interface DividerProps extends AntdDividerProps, CustomDividerProps {} | ||
|
||
export const Divider: React.FC<DividerProps> = props => { | ||
const { mode, content, defaultOpen, iconPlacement, openIcon, closeIcon, ...otherProps } = props; | ||
|
||
const { styles } = useStyles({}); | ||
|
||
const canExpanded = mode === 'expanded'; | ||
const [open, setOpen] = useState<boolean | undefined>(defaultOpen); | ||
|
||
const closeIconDom = closeIcon ? closeIcon : <MinusSquareOutlined />; | ||
const openIconDom = openIcon ? openIcon : <PlusSquareOutlined />; | ||
const iconDom = canExpanded && <span>{open ? closeIconDom : openIconDom}</span>; | ||
if (mode === 'line') { | ||
return <AntdDivider {...otherProps} />; | ||
} | ||
return ( | ||
<> | ||
<AntdDivider {...otherProps}> | ||
<span | ||
className={canExpanded ? styles.custom : ''} | ||
onClick={() => { | ||
setOpen(!open); | ||
}} | ||
> | ||
<Space size={6}> | ||
{iconPlacement !== 'right' && iconDom} | ||
<span>{props.children}</span> | ||
{iconPlacement === 'right' && iconDom} | ||
</Space> | ||
</span> | ||
</AntdDivider> | ||
{canExpanded && <div style={{ display: open ? 'block' : 'none' }}>{content}</div>} | ||
</> | ||
); | ||
}; | ||
|
||
export default Divider; |
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,16 @@ | ||
import { createStyles } from 'antd-style'; | ||
|
||
export const useStyles = createStyles( | ||
({ css, token }) => { | ||
return { | ||
custom: css` | ||
cursor: pointer; | ||
color: ${token.colorPrimary}; | ||
&:hover { | ||
color: ${token.colorPrimaryHover}; | ||
} | ||
`, | ||
}; | ||
}, | ||
{ hashPriority: 'low' } | ||
); |
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