From 60787dd4f8af603307cfb4623b938b8a12dc9b44 Mon Sep 17 00:00:00 2001
From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Date: Fri, 7 May 2021 11:17:37 -0700
Subject: [PATCH] components: Add Separator
---
.../components/src/separator/component.tsx | 38 +++++++++
packages/components/src/separator/index.ts | 2 +
.../components/src/separator/stories/index.js | 29 +++++++
.../test/__snapshots__/index.js.snap | 78 +++++++++++++++++++
.../components/src/separator/test/index.js | 42 ++++++++++
.../components/src/ui/card/stories/index.js | 2 +-
.../src/ui/elevation/stories/index.js | 2 +-
7 files changed, 191 insertions(+), 2 deletions(-)
create mode 100644 packages/components/src/separator/component.tsx
create mode 100644 packages/components/src/separator/index.ts
create mode 100644 packages/components/src/separator/stories/index.js
create mode 100644 packages/components/src/separator/test/__snapshots__/index.js.snap
create mode 100644 packages/components/src/separator/test/index.js
diff --git a/packages/components/src/separator/component.tsx b/packages/components/src/separator/component.tsx
new file mode 100644
index 00000000000000..131211863e1f99
--- /dev/null
+++ b/packages/components/src/separator/component.tsx
@@ -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 (
+
+ );
+}
+
+export default contextConnect( Separator, 'Separator' );
diff --git a/packages/components/src/separator/index.ts b/packages/components/src/separator/index.ts
new file mode 100644
index 00000000000000..4ae1c80f4063ef
--- /dev/null
+++ b/packages/components/src/separator/index.ts
@@ -0,0 +1,2 @@
+export { default as Separator } from './component';
+export type { SeparatorProps } from './component';
diff --git a/packages/components/src/separator/stories/index.js b/packages/components/src/separator/stories/index.js
new file mode 100644
index 00000000000000..30b84730d1dbf3
--- /dev/null
+++ b/packages/components/src/separator/stories/index.js
@@ -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 (
+ <>
+ WordPress.org
+
+ Code is Poetry
+ >
+ );
+};
diff --git a/packages/components/src/separator/test/__snapshots__/index.js.snap b/packages/components/src/separator/test/__snapshots__/index.js.snap
new file mode 100644
index 00000000000000..699c555ddae9f0
--- /dev/null
+++ b/packages/components/src/separator/test/__snapshots__/index.js.snap
@@ -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);
+}
+
+
+`;
+
+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",
+ },
+ ]
+`;
diff --git a/packages/components/src/separator/test/index.js b/packages/components/src/separator/test/index.js
new file mode 100644
index 00000000000000..6e24e94517e965
--- /dev/null
+++ b/packages/components/src/separator/test/index.js
@@ -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( ).container;
+ } );
+
+ test( 'should render correctly', () => {
+ expect( base.firstChild ).toMatchSnapshot();
+ } );
+
+ test( 'should render marginTop', () => {
+ const { container } = render( );
+ expect( container.firstChild ).toMatchStyleDiffSnapshot(
+ base.firstChild
+ );
+ } );
+
+ test( 'should render marginBottom', () => {
+ const { container } = render( );
+ expect( container.firstChild ).toMatchStyleDiffSnapshot(
+ base.firstChild
+ );
+ } );
+
+ test( 'should render margin', () => {
+ const { container } = render( );
+ expect( container.firstChild ).toMatchStyleDiffSnapshot(
+ base.firstChild
+ );
+ } );
+} );
diff --git a/packages/components/src/ui/card/stories/index.js b/packages/components/src/ui/card/stories/index.js
index f9271a6f4c01b1..ae0fce6911301a 100644
--- a/packages/components/src/ui/card/stories/index.js
+++ b/packages/components/src/ui/card/stories/index.js
@@ -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';
diff --git a/packages/components/src/ui/elevation/stories/index.js b/packages/components/src/ui/elevation/stories/index.js
index 52b263504bb052..70b157bf5d0f09 100644
--- a/packages/components/src/ui/elevation/stories/index.js
+++ b/packages/components/src/ui/elevation/stories/index.js
@@ -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,