Skip to content
Closed
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
38 changes: 38 additions & 0 deletions packages/components/src/separator/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';

/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../ui/context';
// eslint-disable-next-line no-duplicate-imports
import type { ViewOwnProps } from '../ui/context';
import { Divider } from '../divider';
// eslint-disable-next-line no-duplicate-imports
import type { DividerProps } from '../divider';

export interface SeparatorProps extends DividerProps {}

function Separator(
props: ViewOwnProps< SeparatorProps, 'hr' >,
forwardedRef: Ref< any >
) {
const { marginBottom = 3, marginTop = 3, ...otherProps } = useContextSystem(
props,
'Separator'
);

return (
<Divider
{ ...otherProps }
marginBottom={ marginBottom }
marginTop={ marginTop }
ref={ forwardedRef }
/>
);
}

export default contextConnect( Separator, 'Separator' );
2 changes: 2 additions & 0 deletions packages/components/src/separator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Separator } from './component';
export type { SeparatorProps } from './component';
29 changes: 29 additions & 0 deletions packages/components/src/separator/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* External dependencies
*/
import { number } from '@storybook/addon-knobs';

/**
* Internal dependencies
*/
import { Separator } from '..';
import { Text } from '../../text';

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

export const _default = () => {
const separatorProps = {
marginTop: number( 'marginTop', undefined ),
marginBottom: number( 'marginBottom', undefined ),
};
return (
<>
<Text>WordPress.org</Text>
<Separator { ...separatorProps } />
<Text>Code is Poetry</Text>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`props should render correctly 1`] = `
.emotion-0 {
border-color: rgba(0,0,0,0.1);
border-width: 0 0 1px 0;
height: 0;
margin: 0;
width: auto;
margin-bottom: calc(4px * 3);
margin-top: calc(4px * 3);
}

<hr
aria-orientation="horizontal"
class="components-divider components-separator emotion-0"
data-wp-c16t="true"
data-wp-component="Separator"
role="separator"
/>
`;

exports[`props should render margin 1`] = `
Snapshot Diff:
- Received styles
+ Base styles

@@ -2,10 +2,10 @@
Object {
"border-color": "rgba(0,0,0,0.1)",
"border-width": "0 0 1px 0",
"height": "0",
"margin": "0",
- "margin-bottom": "calc(4px * 7)",
- "margin-top": "calc(4px * 7)",
+ "margin-bottom": "calc(4px * 3)",
+ "margin-top": "calc(4px * 3)",
"width": "auto",
},
]
`;

exports[`props should render marginBottom 1`] = `
Snapshot Diff:
- Received styles
+ Base styles

@@ -2,10 +2,10 @@
Object {
"border-color": "rgba(0,0,0,0.1)",
"border-width": "0 0 1px 0",
"height": "0",
"margin": "0",
- "margin-bottom": "calc(4px * 5)",
+ "margin-bottom": "calc(4px * 3)",
"margin-top": "calc(4px * 3)",
"width": "auto",
},
]
`;

exports[`props should render marginTop 1`] = `
Snapshot Diff:
- Received styles
+ Base styles

@@ -3,9 +3,9 @@
"border-color": "rgba(0,0,0,0.1)",
"border-width": "0 0 1px 0",
"height": "0",
"margin": "0",
"margin-bottom": "calc(4px * 3)",
- "margin-top": "calc(4px * 5)",
+ "margin-top": "calc(4px * 3)",
"width": "auto",
},
]
`;
42 changes: 42 additions & 0 deletions packages/components/src/separator/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* External dependencies
*/
import { render } from '@testing-library/react';

/**
* Internal dependencies
*/
import { Separator } from '../index';

describe( 'props', () => {
let base;

beforeEach( () => {
base = render( <Separator /> ).container;
} );

test( 'should render correctly', () => {
expect( base.firstChild ).toMatchSnapshot();
} );

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

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

test( 'should render margin', () => {
const { container } = render( <Separator margin={ 7 } /> );
expect( container.firstChild ).toMatchStyleDiffSnapshot(
base.firstChild
);
} );
} );
2 changes: 1 addition & 1 deletion packages/components/src/ui/card/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Grid } from '../../../grid';
import { Text } from '../../../text';
import { VStack } from '../../../v-stack';
import { Card, CardBody, CardFooter } from '../index';
import { Divider } from '../../divider';
import { Divider } from '../../../divider';
import { Heading } from '../../../heading';
import Button from '../../../button';

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ui/elevation/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Elevation } from '../index';
import { Grid } from '../../../grid';
import { View } from '../../../view';
import { HStack } from '../../../h-stack';
import { Divider } from '../../divider';
import { Divider } from '../../../divider';
import {
ExampleGrid,
ExampleGridItem,
Expand Down