Skip to content

Commit

Permalink
Divider orientation feature (#9275)
Browse files Browse the repository at this point in the history
User can align the text to the left or right with "orientation" prop, if not set it will be centered.
  • Loading branch information
jrvboesch authored and afc163 committed Feb 11, 2018
1 parent e8fa1f1 commit 0e591ef
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
24 changes: 24 additions & 0 deletions components/divider/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ exports[`renders ./components/divider/demo/horizontal.md correctly 1`] = `
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
</p>
<div
class="ant-divider ant-divider-horizontal ant-divider-with-text-left"
>
<span
class="ant-divider-inner-text"
>
With Text
</span>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
</p>
<div
class="ant-divider ant-divider-horizontal ant-divider-with-text-right"
>
<span
class="ant-divider-inner-text"
>
With Text
</span>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
</p>
</div>
`;

Expand Down
4 changes: 4 additions & 0 deletions components/divider/demo/horizontal.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ ReactDOM.render(
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.</p>
<Divider dashed />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.</p>
<Divider orientation="left">With Text</Divider>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.</p>
<Divider orientation="right">With Text</Divider>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.</p>
</div>
, mountNode);
````
1 change: 1 addition & 0 deletions components/divider/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ A divider line separates different content.
| -------- | ----------- | ---- | ------- |
| dashed | whether line is dasded | Boolean | false |
| type | direction type of divider | enum: `horizontal` `vertical` | `horizontal` |
| orientation | this is optional, if not set it will have the text in the center | enum: `left` `right` | `center` |
5 changes: 4 additions & 1 deletion components/divider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
export interface DividerProps {
prefixCls?: string;
type?: 'horizontal' | 'vertical';
orientation?: 'left' | 'right';
className?: string;
children?: React.ReactNode;
dashed?: boolean;
Expand All @@ -13,14 +14,16 @@ export interface DividerProps {
export default function Divider({
prefixCls = 'ant',
type = 'horizontal',
orientation = '',
className,
children,
dashed,
...restProps,
}: DividerProps) {
const orientationPrefix = (orientation.length > 0) ? '-' + orientation : orientation;
const classString = classNames(
className, `${prefixCls}-divider`, `${prefixCls}-divider-${type}`, {
[`${prefixCls}-divider-with-text`]: children,
[`${prefixCls}-divider-with-text${orientationPrefix}`]: children,
[`${prefixCls}-divider-dashed`]: !!dashed,
});
return (
Expand Down
68 changes: 66 additions & 2 deletions components/divider/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,81 @@
transform: translateY(50%);
}
}

&-inner-text {
display: inline-block;
padding: 0 24px;
}
&-horizontal&-with-text-left {
display: table;
white-space: nowrap;
text-align: center;
background: transparent;
font-weight: 500;
color: @heading-color;
font-size: @font-size-base;
margin: 16px 0;

&:before {
content: '';
display: table-cell;
position: relative;
top: 50%;
width: 5%;
border-top: 1px solid @border-color-split;
transform: translateY(50%);
}
&:after {
content: '';
display: table-cell;
position: relative;
top: 50%;
width: 95%;
border-top: 1px solid @border-color-split;
transform: translateY(50%);
}
&-inner-text {
display: inline-block;
padding: 0 10px;
}
}

&-horizontal&-with-text-right {
display: table;
white-space: nowrap;
text-align: center;
background: transparent;
font-weight: 500;
color: @heading-color;
font-size: @font-size-base;
margin: 16px 0;

&:before {
content: '';
display: table-cell;
position: relative;
top: 50%;
width: 95%;
border-top: 1px solid @border-color-split;
transform: translateY(50%);
}
&:after {
content: '';
display: table-cell;
position: relative;
top: 50%;
width: 5%;
border-top: 1px solid @border-color-split;
transform: translateY(50%);
}
&-inner-text {
display: inline-block;
padding: 0 10px;
}
}
&-dashed {
background: none;
border-top: 1px dashed @border-color-split;
}

&-horizontal&-with-text&-dashed {
border-top: 0;
&:before,
Expand Down

0 comments on commit 0e591ef

Please sign in to comment.