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

components: Promote Divider and use readable prop names #31556

Merged
merged 3 commits into from
May 7, 2021
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: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,12 @@
"markdown_source": "../packages/components/src/disabled/README.md",
"parent": "components"
},
{
"title": "Divider",
"slug": "divider",
"markdown_source": "../packages/components/src/divider/README.md",
"parent": "components"
},
{
"title": "Draggable",
"slug": "draggable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,69 @@ import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../context';
import { contextConnect, useContextSystem } from '../ui/context';
// eslint-disable-next-line no-duplicate-imports
import type { ViewOwnProps } from '../context';
import type { ViewOwnProps } from '../ui/context';
import * as styles from './styles';
import { space } from '../utils/space';
import { space } from '../ui/utils/space';

export interface DividerProps extends SeparatorProps {
/**
* Adjusts all margins.
*/
m?: number;
margin?: number;
/**
* Adjusts top margins.
*/
mt?: number;
marginTop?: number;
/**
* Adjusts bottom margins.
*/
mb?: number;
marginBottom?: number;
}

function Divider(
props: ViewOwnProps< DividerProps, 'hr' >,
forwardedRef: Ref< any >
) {
const { className, m, mb, mt, ...otherProps } = useContextSystem(
props,
'Divider'
);
const {
className,
margin,
marginBottom,
marginTop,
...otherProps
} = useContextSystem( props, 'Divider' );

const classes = useMemo( () => {
const sx: Record< string, string > = {};

if ( typeof m !== 'undefined' ) {
sx.m = css`
margin-bottom: ${ space( m ) };
margin-top: ${ space( m ) };
if ( typeof margin !== 'undefined' ) {
sx.margin = css`
margin-bottom: ${ space( margin ) };
margin-top: ${ space( margin ) };
`;
} else {
if ( typeof mt !== 'undefined' ) {
sx.mt = css`
margin-top: ${ space( mt ) };
if ( typeof marginTop !== 'undefined' ) {
sx.marginTop = css`
margin-top: ${ space( marginTop ) };
`;
}

if ( typeof mb !== 'undefined' ) {
sx.mb = css`
margin-bottom: ${ space( mb ) };
if ( typeof marginBottom !== 'undefined' ) {
sx.marginBottom = css`
margin-bottom: ${ space( marginBottom ) };
`;
}
}

return cx( styles.Divider, sx.mb, sx.mt, sx.m, className );
}, [ className, m, mb, mt ] );
return cx(
styles.Divider,
sx.marginBottom,
sx.marginTop,
sx.margin,
className
);
}, [ className, margin, marginBottom, marginTop ] );

return (
<Separator
Expand All @@ -87,7 +96,10 @@ function Divider(
*
* @example
* ```js
* import { Divider, FormGroup, ListGroup } from `@wordpress/components/ui`;
* import {
* __experimentalDivider as Divider,
* __experimentalText as Text }
* from `@wordpress/components`;
*
* function Example() {
* return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Divider } from '..';

export default {
component: Divider,
title: 'G2 Components (Experimental)/Divider',
title: 'Components (Experimental)/Divider',
};

export const _default = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { css } from 'emotion';
/**
* Internal dependencies
*/
import CONFIG from '../../utils/config-values';
import CONFIG from '../utils/config-values';

export const Divider = css`
border-color: ${ CONFIG.colorDivider };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ describe( 'props', () => {
} );

test( 'should render marginTop', () => {
const { container } = render( <Divider mt={ 5 } /> );
const { container } = render( <Divider marginTop={ 5 } /> );
expect( container.firstChild ).toMatchStyleDiffSnapshot(
base.container.firstChild
);
} );

test( 'should render marginBottom', () => {
const { container } = render( <Divider mb={ 5 } /> );
const { container } = render( <Divider marginBottom={ 5 } /> );
expect( container.firstChild ).toMatchStyleDiffSnapshot(
base.container.firstChild
);
} );

test( 'should render margin', () => {
const { container } = render( <Divider m={ 7 } /> );
const { container } = render( <Divider margin={ 7 } /> );
expect( container.firstChild ).toMatchStyleDiffSnapshot(
base.container.firstChild
);
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export { default as DateTimePicker, DatePicker, TimePicker } from './date-time';
export { default as __experimentalDimensionControl } from './dimension-control';
export { default as Disabled } from './disabled';
export { DisclosureContent as __unstableDisclosureContent } from './disclosure';
export { Divider as __experimentalDivider } from './divider';
export { default as Draggable } from './draggable';
export { default as DropZone } from './drop-zone';
export { default as DropZoneProvider } from './drop-zone/provider';
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ui/__storybook-utils/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { VStack } from '../../v-stack';
import { View } from '../view';
import { Heading } from '../../heading';
import { Divider } from '../divider';
import { Divider } from '../../divider';

function Page( { title = 'Component', children } ) {
return (
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/ui/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './card';
export * from './control-group';
export * from './control-label';
export * from './divider';
export * from './elevation';
export * from './form-group';
export * from './grid';
Expand Down