Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divider: Improve default behavior when in vertical orientation #39316

Merged
merged 8 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Enhancements

- `BaseControl`: Add `__nextHasNoMarginBottom` prop for opting into the new margin-free styles ([#39325](https://github.com/WordPress/gutenberg/pull/39325)).
- `Divider`: Make the divider visible by default (`display: inline`) in flow layout containers when the divider orientation is vertical ([#39316](https://github.com/WordPress/gutenberg/pull/39316)).

## 19.6.0 (2022-03-11)

### Enhancements
Expand All @@ -10,7 +15,6 @@
- `InputControl`: Allow `onBlur` for empty values to commit the change when `isPressEnterToChange` is true, and move reset behavior to the ESCAPE key. ([#39109](https://github.com/WordPress/gutenberg/pull/39109)).
- `TreeGrid`: Add tests for Home/End keyboard navigation. Add `onFocusRow` callback for Home/End keyboard navigation, this was missed in the implementation PR. Modify test for expanding/collapsing a row as row 1 implements this now. Update README with latest changes. ([#39302](https://github.com/WordPress/gutenberg/pull/39302))
- `ToggleGroupControlOption`: Calculate width from button content and remove `LabelPlaceholderView` ([#39345](https://github.com/WordPress/gutenberg/pull/39345))
- `BaseControl`: Add `__nextHasNoMarginBottom` prop for opting into the new margin-free styles ([#39325](https://github.com/WordPress/gutenberg/pull/39325)).

### Bug Fix

Expand Down
49 changes: 26 additions & 23 deletions packages/components/src/divider/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ComponentMeta, ComponentStory } from '@storybook/react';
*/
import { Text } from '../../text';
import { Divider } from '..';
import { Flex } from '../../flex';

const meta: ComponentMeta< typeof Divider > = {
component: Divider,
Expand All @@ -30,41 +31,43 @@ const meta: ComponentMeta< typeof Divider > = {
};
export default meta;

const HorizontalTemplate: ComponentStory< typeof Divider > = ( args ) => (
const Template: ComponentStory< typeof Divider > = ( args ) => (
<div>
<Text>Some text before the divider</Text>
<Divider { ...args } />
<Text>Some text after the divider</Text>
</div>
);

const VerticalTemplate: ComponentStory< typeof Divider > = ( args ) => {
const styles = {
display: 'flex',
alignItems: 'stretch',
justifyContent: 'start',
};

return (
<div style={ styles }>
<Text>Some text before the divider</Text>
<Divider { ...args } />
<Text>Some text after the divider</Text>
</div>
);
};

export const Horizontal: ComponentStory<
typeof Divider
> = HorizontalTemplate.bind( {} );
export const Horizontal: ComponentStory< typeof Divider > = Template.bind( {} );
Horizontal.args = {
margin: 2,
};

export const Vertical: ComponentStory< typeof Divider > = VerticalTemplate.bind(
{}
);
export const Vertical: ComponentStory< typeof Divider > = Template.bind( {} );
Vertical.args = {
...Horizontal.args,
orientation: 'vertical',
};

// Inside a `flex` container, the divider will need to be `stretch` aligned in order to be visible.
export const InFlexContainer: ComponentStory< typeof Divider > = ( args ) => {
return (
<Flex align="stretch">
<Text>
Some text before the divider Some text before the divider Some
text before the divider Some text before the divider Some text
before the divider Some text before the divider Some text before
the divider
</Text>
<Divider { ...args } />
<Text>
Some text after the divider Some text after the divider Some
text after the divider
</Text>
</Flex>
);
};
InFlexContainer.args = {
...Vertical.args,
};
9 changes: 9 additions & 0 deletions packages/components/src/divider/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ const renderMargin = ( {
} )()
);

const renderDisplay = ( {
'aria-orientation': orientation = 'horizontal',
}: Props ) => {
return orientation === 'vertical'
? css( { display: 'inline' } )
: undefined;
};

const renderBorder = ( {
'aria-orientation': orientation = 'horizontal',
}: Props ) => {
Expand All @@ -67,6 +75,7 @@ export const DividerView = styled.hr< Props >`
border: 0;
margin: 0;

${ renderDisplay }
${ renderBorder }
${ renderSize }
${ renderMargin }
Expand Down
12 changes: 11 additions & 1 deletion packages/components/src/divider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ export interface OwnProps {
* Adjusts the inline-end margin.
*/
marginEnd?: SpaceInput;
/**
* Divider's orientation. When using inside a flex container, you may need to make sure the divider is `stretch` aligned
* in order for it to be visible.
*
* @default 'horizontal'
*/
orientation?: SeparatorProps[ 'orientation' ];
}

export interface Props
extends Omit< SeparatorProps, 'children' | 'unstable_system' >,
extends Omit<
SeparatorProps,
'children' | 'unstable_system' | 'orientation'
>,
OwnProps {}