Skip to content

Commit

Permalink
Divider component (uber#5027)
Browse files Browse the repository at this point in the history
* feat(divider): create divider component

* chore(divider): add docs

* chore(divider): convert to typescript

* chore(divider): more typescript migration changes

* test(vrt): update visual snapshots for 20f5e60 [skip ci] (uber#5029)

Co-authored-by: UberOpenSourceBot <[email protected]>

* chore(divider): use long-hand properties for border styles

* Update src/divider/types.js.flow

Co-authored-by: Chase Starr <[email protected]>

* Apply suggestions from code review

Co-authored-by: Chase Starr <[email protected]>

* chore(divider): fix typescript issue

Co-authored-by: UberOpenSourceBot <[email protected]>
Co-authored-by: UberOpenSourceBot <[email protected]>
Co-authored-by: Chase Starr <[email protected]>
  • Loading branch information
4 people authored Jul 14, 2022
1 parent 58c6a32 commit c6f8e7f
Show file tree
Hide file tree
Showing 24 changed files with 435 additions and 0 deletions.
30 changes: 30 additions & 0 deletions documentation-site/components/yard/config/divider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { StyledDivider, SIZE } from 'baseui/divider';
import { PropTypes } from 'react-view';
import { TConfig } from '../types';

const DividerConfig: TConfig = {
componentName: 'StyledDivider',
imports: {
'baseui/divider': {
named: ['StyledDivider'],
},
},
scope: { StyledDivider, SIZE },
theme: [],
props: {
$size: {
value: 'SIZE.section',
defaultValue: 'SIZE.section',
options: SIZE,
type: PropTypes.Enum,
description: 'Defines the height of the divider.',
imports: {
'baseui/divider': {
named: ['SIZE'],
},
},
},
},
};

export default DividerConfig;
57 changes: 57 additions & 0 deletions documentation-site/examples/divider/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @flow

import * as React from 'react';
import {StyledDivider, SIZE} from 'baseui/divider';

export default function Example() {
return (
<div
style={{
width: '400px',
border: '1px solid #E2E2E2',
borderRadius: '8px',
}}
>
<div
style={{
height: '50px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Cell Divider
</div>

<StyledDivider $size={SIZE.cell} />

<div
style={{
height: '80px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Section Divider
</div>

<StyledDivider $size={SIZE.section} />

<div
style={{
height: '160px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Module Divider
</div>

<StyledDivider $size={SIZE.module} />

<div style={{height: '160px'}}></div>
</div>
);
}
55 changes: 55 additions & 0 deletions documentation-site/examples/divider/basic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from 'react';
import {StyledDivider, SIZE} from 'baseui/divider';

export default function Example() {
return (
<div
style={{
width: '400px',
border: '1px solid #E2E2E2',
borderRadius: '8px',
}}
>
<div
style={{
height: '50px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Cell Divider
</div>

<StyledDivider $size={SIZE.cell} />

<div
style={{
height: '80px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Section Divider
</div>

<StyledDivider $size={SIZE.section} />

<div
style={{
height: '160px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Module Divider
</div>

<StyledDivider $size={SIZE.module} />

<div style={{height: '160px'}}></div>
</div>
);
}
35 changes: 35 additions & 0 deletions documentation-site/pages/components/divider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

import Example from '../../components/example';
import Layout from '../../components/layout';
import Exports from '../../components/exports';

import { StyledDivider } from 'baseui/divider';
import * as DividerExports from 'baseui/divider';
import DividerBasic from 'examples/divider/basic.js';

export default Layout;

# Divider

Dividers are visual indicators used to separate sections of content. Divider is available in
three sizes via the `size` prop:

1. `cell`: 1px thick. Use to divide individual cells in List items.
2. `section`: 2px thick. Use between groups of List items.
3. `module`: 8px thick. Use to group larger clusters of related sections.

## Examples

<Example title="Basic" path="divider/basic.js">
<DividerBasic />
</Example>

## API

<Exports component={DividerExports} title="Divider exports" path="baseui/divider" />
4 changes: 4 additions & 0 deletions documentation-site/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ const routes = [
title: 'Block',
itemId: '/components/block',
},
{
title: 'Divider',
itemId: '/components/divider',
},
{
title: 'FlexGrid',
itemId: '/components/flex-grid',
Expand Down
62 changes: 62 additions & 0 deletions src/divider/__tests__/divider.scenario.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';

import { StyledDivider, SIZE } from '../index';

export function Scenario() {
return (
<div
style={{
width: '400px',
border: '1px solid #E2E2E2',
borderRadius: '8px',
}}
>
<div
style={{
height: '50px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Cell Divider
</div>

<StyledDivider $size={SIZE.cell} />

<div
style={{
height: '80px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Section Divider
</div>

<StyledDivider $size={SIZE.section} />

<div
style={{
height: '160px',
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'center',
}}
>
Module Divider
</div>

<StyledDivider $size={SIZE.module} />

<div style={{ height: '160px' }}></div>
</div>
);
}
10 changes: 10 additions & 0 deletions src/divider/__tests__/divider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import { Scenario as DividerDivider } from './divider.scenario';

export const Divider = () => <DividerDivider />;
12 changes: 12 additions & 0 deletions src/divider/constants.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
export const SIZE = {
cell: 'cell',
section: 'section',
module: 'module',
};
11 changes: 11 additions & 0 deletions src/divider/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
export const SIZE = {
cell: 'cell',
section: 'section',
module: 'module',
} as const;
21 changes: 21 additions & 0 deletions src/divider/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import { withWrapper } from '../styles/index.js';

import { StyledDivider as StyledDividerElement } from './styled-components.js';

export * from './constants.js';

export const StyledDivider = withWrapper(
StyledDividerElement,
(StyledComponent) =>
function StyledDivider(props) {
return <StyledComponent aria-hidden="true" {...props} />;
}
);
20 changes: 20 additions & 0 deletions src/divider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { withWrapper } from '../styles/index';

import { StyledDivider as StyledDividerElement } from './styled-components';

export * from './constants';

export const StyledDivider = withWrapper(
StyledDividerElement,
(StyledComponent) =>
function StyledDivider(props) {
return <StyledComponent aria-hidden="true" {...props} />;
}
);
41 changes: 41 additions & 0 deletions src/divider/styled-components.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import { styled } from '../styles/index.js';
import { SIZE } from './constants.js';
import type { DividerProps } from './types.js';

export const StyledDivider = styled<DividerProps>('hr', ({ $theme, $size = SIZE.section }) => {
const borderResetStyles = {
borderRightWidth: 0,
borderBottomWidth: 0,
borderLeftWidth: 0,
};

if ($size === SIZE.cell) {
return {
...borderResetStyles,
borderTopWidth: '1px',
borderTopColor: $theme.colors.borderOpaque,
borderTopStyle: 'solid',
};
}
if ($size === SIZE.module) {
return {
...borderResetStyles,
borderTopWidth: '8px',
borderTopColor: $theme.colors.backgroundTertiary,
borderTopStyle: 'solid',
};
}
return {
...borderResetStyles,
borderTopWidth: '2px',
borderTopColor: $theme.colors.borderOpaque,
borderTopStyle: 'solid',
};
});
Loading

0 comments on commit c6f8e7f

Please sign in to comment.