Skip to content

Commit 25bcc7c

Browse files
committed
feat(divider): convert to TypeScript and export types
1 parent c419365 commit 25bcc7c

File tree

7 files changed

+43
-55
lines changed

7 files changed

+43
-55
lines changed

src/ColorInput/ColorInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styled, { css } from 'styled-components';
55
import useControlledOrUncontrolled from '../common/hooks/useControlledOrUncontrolled';
66
import { focusOutline } from '../common';
77
import { StyledButton } from '../Button/Button';
8-
import Divider from '../Divider/Divider';
8+
import { Divider } from '../Divider/Divider';
99

1010
const Trigger = styled(StyledButton)`
1111
padding-left: 8px;

src/Divider/Divider.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Divider/Divider.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name: Divider
44
menu: Components
5-
---import Divider from './Divider'
5+
import { Divider } from './Divider'
66
import List from '../List/List'
77
import ListItem from '../ListItem/ListItem'
88

src/Divider/Divider.spec.js renamed to src/Divider/Divider.spec.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import React from 'react';
2-
31
import { renderWithTheme } from '../../test/utils';
42

5-
import Divider from './Divider';
3+
import { Divider } from './Divider';
64

75
describe('<Divider />', () => {
86
it('should render Divider', () => {
97
const { container } = renderWithTheme(<Divider />);
10-
const divider = container.firstChild;
8+
const divider = container.firstElementChild;
119

1210
expect(divider).toBeInTheDocument();
1311
});
1412

1513
describe('prop: size', () => {
1614
it('defaults to 100%', () => {
1715
const { container } = renderWithTheme(<Divider />);
18-
const divider = container.firstChild;
16+
const divider = container.firstElementChild;
1917
expect(divider).toHaveStyleRule('width', '100%');
2018
});
2119
it('sets size passed correctly', () => {
2220
const size = '53px';
2321
const { container } = renderWithTheme(<Divider size={size} />);
24-
const divider = container.firstChild;
22+
const divider = container.firstElementChild;
2523

2624
expect(divider).toHaveStyleRule('width', size);
2725
});
@@ -31,7 +29,7 @@ describe('<Divider />', () => {
3129
it('renders horizontal line by default', () => {
3230
const size = '53px';
3331
const { container } = renderWithTheme(<Divider size={size} />);
34-
const divider = container.firstChild;
32+
const divider = container.firstElementChild;
3533

3634
expect(divider).toHaveStyleRule('width', size);
3735
});
@@ -41,22 +39,22 @@ describe('<Divider />', () => {
4139
const { container } = renderWithTheme(
4240
<Divider orientation='vertical' size={size} />
4341
);
44-
const divider = container.firstChild;
42+
const divider = container.firstElementChild;
4543

4644
expect(divider).toHaveStyleRule('height', size);
4745
});
4846
});
4947
describe('prop: size', () => {
5048
it('should set proper size', () => {
5149
const { container } = renderWithTheme(<Divider size='85%' />);
52-
const avatarEl = container.firstChild;
50+
const avatarEl = container.firstElementChild;
5351

5452
expect(avatarEl).toHaveStyleRule('width', '85%');
5553
});
5654

5755
it('when passed a number, sets size in px', () => {
5856
const { container } = renderWithTheme(<Divider size={25} />);
59-
const avatarEl = container.firstChild;
57+
const avatarEl = container.firstElementChild;
6058

6159
expect(avatarEl).toHaveStyleRule('width', '25px');
6260
});
@@ -65,7 +63,7 @@ describe('<Divider />', () => {
6563
const { container } = renderWithTheme(
6664
<Divider size={25} orientation='vertical' />
6765
);
68-
const avatarEl = container.firstChild;
66+
const avatarEl = container.firstElementChild;
6967

7068
expect(avatarEl).toHaveStyleRule('height', '25px');
7169
});

src/Divider/Divider.stories.js renamed to src/Divider/Divider.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { ComponentMeta } from '@storybook/react';
22
import styled from 'styled-components';
33

44
import { Divider, List, ListItem } from 'react95';
@@ -12,7 +12,7 @@ export default {
1212
title: 'Divider',
1313
component: Divider,
1414
decorators: [story => <Wrapper>{story()}</Wrapper>]
15-
};
15+
} as ComponentMeta<typeof Divider>;
1616

1717
export function Default() {
1818
return (

src/Divider/Divider.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import styled from 'styled-components';
2+
import { Orientation } from '../types';
3+
4+
function getSize(value: string | number) {
5+
return typeof value === 'number' ? `${value}px` : value;
6+
}
7+
interface DividerProps {
8+
size?: string | number;
9+
orientation?: Orientation;
10+
}
11+
const Divider = styled.div<DividerProps>`
12+
${({ orientation, theme, size = '100%' }) =>
13+
orientation === 'vertical'
14+
? `
15+
height: ${getSize(size)};
16+
border-left: 2px solid ${theme.borderDark};
17+
border-right: 2px solid ${theme.borderLightest};
18+
margin: 0;
19+
`
20+
: `
21+
width: ${getSize(size)};
22+
border-bottom: 2px solid ${theme.borderLightest};
23+
border-top: 2px solid ${theme.borderDark};
24+
margin: 0;
25+
`}
26+
`;
27+
28+
export { Divider, DividerProps };

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export { createScrollbars } from './common/index';
66
export * from './Anchor/Anchor';
77
export { default as AppBar } from './AppBar/AppBar';
88
export { default as Avatar } from './Avatar/Avatar';
9-
export { default as Bar } from './Bar/Bar';
9+
export * from './Bar/Bar';
1010
export { default as Button } from './Button/Button';
1111
export { default as Checkbox } from './Checkbox/Checkbox';
1212
export { default as ColorInput } from './ColorInput/ColorInput';
1313
export { default as Counter } from './Counter/Counter';
1414
export { default as Cutout } from './Cutout/Cutout';
1515
export { default as Desktop } from './Desktop/Desktop';
16-
export { default as Divider } from './Divider/Divider';
16+
export * from './Divider/Divider';
1717
export { default as Fieldset } from './Fieldset/Fieldset';
1818
export { default as Hourglass } from './Hourglass/Hourglass';
1919
export { default as List } from './List/List';

0 commit comments

Comments
 (0)