-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Divider): add the divider component (#1378)
* feat(stylesheet): add the typography mixin and global z-index variables * fix(stylesheet): fix * docs(divider): add the stories of divider component * feat(Divider): add divider component style(divider): fix style * feat(divider): add data-testid='divider' prop for divider * docs(global): add the stories of typography and z-index
- Loading branch information
Showing
9 changed files
with
226 additions
and
2 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,26 @@ | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import usePrefixCls from '../utils/hooks/use-prefix-cls'; | ||
import WithRef from '../utils/withRef'; | ||
import DividerProps from './interface'; | ||
|
||
const Divider = WithRef<HTMLHRElement, DividerProps>((props, ref) => { | ||
const { orientation = 'horizontal', flexItem = false, className, ...otherProps } = props; | ||
|
||
const prefixCls = usePrefixCls('divider'); | ||
const classes = classNames([prefixCls, className], { | ||
[`${prefixCls}_${orientation}`]: ['horizontal', 'vertical'].includes(orientation), | ||
[`${prefixCls}_flex_item`]: flexItem, | ||
}); | ||
|
||
return <hr ref={ref} className={classes} data-testid="divider" {...otherProps} />; | ||
}); | ||
|
||
Divider.displayName = 'Divider'; | ||
|
||
Divider.defaultProps = { | ||
orientation: 'horizontal', | ||
flexItem: false, | ||
}; | ||
|
||
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,74 @@ | ||
import React from 'react'; | ||
import { Story, Meta } from '@storybook/react/types-6-0'; | ||
import Divider, { DividerProps } from '..'; | ||
import Button from "../../button"; | ||
import '../style'; | ||
import './divider.style.less'; | ||
|
||
export default { | ||
title: 'Upgraded/Divider', | ||
component: Divider, | ||
} as Meta; | ||
|
||
const HorizontalTemplate: Story<DividerProps> = (args) => ( | ||
<> | ||
<h3 className="demo-divider-title">列表分割线</h3> | ||
<ul className="demo-divider-ul"> | ||
<li>Apple</li> | ||
<Divider {...args} /> | ||
<li>Orange</li> | ||
<Divider {...args} /> | ||
<li>Pumpkin</li> | ||
<Divider {...args} /> | ||
<li>Pineapple</li> | ||
</ul> | ||
</> | ||
); | ||
|
||
export const Horizontal = HorizontalTemplate.bind({}); | ||
Horizontal.args = { | ||
orientation: 'horizontal', | ||
flexItem: false, | ||
} as DividerProps; | ||
|
||
const VerticalTemplate: Story<DividerProps> = (args) => ( | ||
<> | ||
<h3 className="demo-divider-title">行内元素的垂直分割线</h3> | ||
<div className="demo-vertical"> | ||
<span>Apple</span> | ||
<Divider {...args} /> | ||
<span>Orange</span> | ||
<Divider {...args} /> | ||
<span>Pumpkin</span> | ||
<Divider {...args} /> | ||
<span>Pineapple</span> | ||
</div> | ||
</> | ||
); | ||
|
||
export const Vertical = VerticalTemplate.bind({}); | ||
Vertical.args = { | ||
orientation: 'vertical', | ||
flexItem: false, | ||
} as DividerProps; | ||
|
||
const FlexItemTemplate: Story<DividerProps> = (args) => ( | ||
<> | ||
<h3 className="demo-divider-title">适应 Flex 容器的垂直分割线</h3> | ||
<div className="demo-flex"> | ||
<Button type="text">Apple</Button> | ||
<Divider {...args} /> | ||
<Button type="text">Orange</Button> | ||
<Divider {...args} /> | ||
<Button type="text">Pumpkin</Button> | ||
<Divider {...args} /> | ||
<Button type="text">Pineapple</Button> | ||
</div> | ||
</> | ||
); | ||
|
||
export const FlexItem = FlexItemTemplate.bind({}); | ||
FlexItem.args = { | ||
orientation: 'vertical', | ||
flexItem: true, | ||
} as DividerProps; |
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,22 @@ | ||
.demo-divider-ul { | ||
width: 400px; | ||
padding: 0; | ||
list-style: none; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
|
||
.demo-divider-ul > li { | ||
width: 100%; | ||
height: 30px; | ||
padding: 10px; | ||
line-height: 30px; | ||
} | ||
|
||
.demo-flex { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: 1px solid #ccc; | ||
border-radius: 6px; | ||
} |
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 @@ | ||
import Divider from './Divider'; | ||
|
||
export type { default as DividerProps } from './interface'; | ||
|
||
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,17 @@ | ||
import React from 'react'; | ||
|
||
interface DividerProps extends React.HTMLAttributes<HTMLHRElement> { | ||
/** | ||
* 分割线的方向 | ||
* @default `horizontal` | ||
*/ | ||
orientation?: 'horizontal' | 'vertical'; | ||
|
||
/** | ||
* 是否处于 flex 容器中。设置为 true,则能正确计算分割线的高度,否则高度为零。 | ||
* @default false | ||
*/ | ||
flexItem?: boolean; | ||
} | ||
|
||
export default DividerProps; |
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,22 @@ | ||
@import '../../stylesheet/variables/index.less'; | ||
|
||
@divider-prefix-cls: ~'@{component-prefix}-divider'; | ||
|
||
.@{divider-prefix-cls} { | ||
margin: 0; | ||
border: 0 solid @gray-2; | ||
border-top-width: thin; | ||
|
||
&_vertical { | ||
display: inline; | ||
padding: 0 8px; | ||
border-top-width: 0; | ||
border-left-width: thin; | ||
} | ||
|
||
&_flex_item { | ||
align-self: stretch; | ||
height: auto; | ||
margin: 0; | ||
} | ||
} |
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 @@ | ||
import './divider.less'; |
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
90598f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: