Skip to content

Commit

Permalink
Merge pull request #19 from stoplightio/SL-148/break-component
Browse files Browse the repository at this point in the history
SL-148/break-component
  • Loading branch information
casserni authored Nov 19, 2018
2 parents a1eb871 + a253f23 commit b9a482c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ TODO
- [Extending a styled component](./docs/components.md#extending-a-component)
- Component List
- Box
- Break
- Button
- Flex
- Text
- Heading
- List
- Button
- Portal
- Text
- Table

## Helpful Links
Expand Down
4 changes: 4 additions & 0 deletions src/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
borderColor,
borderRadius,
borders,
borderStyle,
bottom,
boxShadow,
css,
Expand All @@ -29,6 +30,7 @@ import {
zIndex,
} from './utils';

import { BorderStyleProperty } from 'csstype';
import { BorderRadius, BorderWidth, BoxDimension, BoxShadow, FontSize, FontWeight, FullSpace } from './types';

export interface IBoxProps {
Expand Down Expand Up @@ -70,6 +72,7 @@ export interface IBoxProps {
borderRight?: BorderWidth;
borderBottom?: BorderWidth;
borderColor?: string;
borderStyle?: BorderStyleProperty;
radius?: BorderRadius | string;

cursor?:
Expand Down Expand Up @@ -140,6 +143,7 @@ export interface IBoxProps {
export const Box = styled<IBoxProps, 'div'>('div')(
borderRadius,
borderColor,
borderStyle,
bgColor,
borders,
bottom,
Expand Down
22 changes: 22 additions & 0 deletions src/Break.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { style } from 'styled-system';
import { Box, IBoxProps } from './Box';
import { getBorder, styled } from './utils';

export const thickness = style({
prop: 'thickness',
cssProperty: 'borderTop',
transformValue: getBorder,
});

export interface IBreakProps extends IBoxProps {
thickness?: number;
}

export const Break = styled<IBreakProps, 'hr'>(Box as any)(thickness);

Break.defaultProps = {
as: 'hr',
thickness: 1,
m: 'none',
borderColor: 'break.border',
};
14 changes: 14 additions & 0 deletions src/__tests__/Break.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @jest-environment jsdom
*/
import { shallow } from 'enzyme';
import 'jest-enzyme';
import * as React from 'react';
import { Break } from '../';

describe('Break', () => {
// just a smoke test
it('does not require any props', () => {
expect(() => shallow(<Break />)).not.toThrow();
});
});
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

export * from './Box';
export * from './Break';
export * from './Button';
export * from './Flex';
export * from './Heading';
Expand Down
6 changes: 5 additions & 1 deletion src/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const zIndex = style({
});

// @ts-ignore FIXME
const getBorder = n => (num(n) && n > 0 ? n + 'px solid' : n);
export const getBorder = n => (num(n) && n > 0 ? n + 'px solid' : n);

export const border = style({
prop: 'border',
Expand Down Expand Up @@ -152,6 +152,10 @@ export const borderColor = styleColor({
prop: 'borderColor',
});

export const borderStyle = style({
prop: 'borderStyle',
});

export const borders = compose(
border,
borderTop,
Expand Down
21 changes: 21 additions & 0 deletions stories/Break.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';

import { NumberOptions, withKnobs } from '@storybook/addon-knobs';
import { number } from '@storybook/addon-knobs/react';
import { storiesOf } from '@storybook/react';
import { omitBy } from 'lodash';

import { Break } from '../src/Break';

export const breakKnobs = (tabName = 'Break'): any => {
return omitBy(
{
thickness: number('thickness', 10, { min: 0, max: Infinity } as NumberOptions, tabName),
},
val => !val
);
};

storiesOf('Break', module)
.addDecorator(withKnobs)
.add('with defaults', () => <Break {...breakKnobs()} />);
1 change: 1 addition & 0 deletions stories/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './Box';
import './Break';
import './Button';
import './Checkbox';
import './Flex';
Expand Down

0 comments on commit b9a482c

Please sign in to comment.