Skip to content

Commit

Permalink
feat: add flex component (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettdorrans authored Jan 14, 2021
1 parent 70ff8d8 commit a19cc3b
Show file tree
Hide file tree
Showing 9 changed files with 1,990 additions and 1,290 deletions.
2 changes: 2 additions & 0 deletions docs/components/SectionRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Markdown from 'react-styleguidist/lib/client/rsg-components/Markdown/Markdown';
import { Text } from '../../src/components/text';
import { Heading, HeadingSize } from '../../src/components/heading';
Expand Down
3,084 changes: 1,824 additions & 1,260 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,57 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@lapidist/styles": "^3.0.0",
"@lapidist/styles": "^3.2.1",
"lodash.merge": "^4.6.2"
},
"devDependencies": {
"@lapidist/linting": "^2.0.0",
"@lapidist/linting": "^2.52.0",
"@react-mock/state": "^0.1.8",
"@types/jest": "^26.0.13",
"@types/jest": "^26.0.20",
"@types/lodash.merge": "^4.6.6",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-test-renderer": "^17.0.0",
"@types/styled-components": "^5.1.3",
"@types/styled-components": "^5.1.7",
"awesome-typescript-loader": "^5.2.1",
"circular-dependency-plugin": "^5.2.0",
"cross-env": "^7.0.2",
"css-loader": "^5.0.0",
"csstype": "^3.0.3",
"circular-dependency-plugin": "^5.2.2",
"cross-env": "^7.0.3",
"css-loader": "^5.0.1",
"csstype": "^3.0.6",
"fs-extra": "^9.0.1",
"husky": "^4.3.0",
"jest": "^26.4.2",
"husky": "^4.3.7",
"jest": "^26.6.3",
"jest-styled-components": "^7.0.3",
"lint-staged": "^10.3.0",
"react": "^16.13.1",
"react-docgen-typescript": "^1.20.4",
"react-dom": "^16.13.1",
"react-styleguidist": "^11.0.11",
"react-test-renderer": "^16.13.1",
"lint-staged": "^10.5.3",
"react": "^17.0.1",
"react-docgen-typescript": "^1.20.5",
"react-dom": "^17.0.1",
"react-styleguidist": "^11.1.5",
"react-test-renderer": "^17.0.1",
"rimraf": "^3.0.2",
"source-map-loader": "^2.0.0",
"style-loader": "^2.0.0",
"styled-components": "^5.1.0",
"stylelint": "^13.7.0",
"stylelint": "^13.8.0",
"stylelint-config-recommended": "^3.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-no-unsupported-browser-features": "^4.0.0",
"stylelint-no-unsupported-browser-features": "^4.1.4",
"stylelint-processor-styled-components": "^1.10.0",
"ts-jest": "^26.3.0",
"typescript": "^4.0.2",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3",
"typescript-proptypes-generator": "0.0.6",
"webpack": "^5.10.3",
"webpack-bundle-analyzer": "^4.1.0",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^3.11.0"
"webpack": "^4.46.0",
"webpack-bundle-analyzer": "^4.3.0",
"webpack-cli": "^4.3.1",
"webpack-dev-server": "^3.11.2"
},
"peerDependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"styled-components": "^5.x"
},
"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},
"browserslist": [
"> 0.55%",
Expand Down
8 changes: 5 additions & 3 deletions src/components/box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { ThemeProvider, Box, Text } from '@lapidist/components';
backgroundColor: { group: 'primary', shade: 'base' }
}}
>
<Text styles={{
textColor: { group: 'base', shade: 'white' }
}}>
<Text
styles={{
textColor: { group: 'base', shade: 'light' }
}}
>
Hello world!
</Text>
</Box>
Expand Down
37 changes: 37 additions & 0 deletions src/components/flex/Flex.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import renderer from 'react-test-renderer';
import 'jest-styled-components';

import { Flex } from './index';
import { ThemeProvider } from '../theme-provider';

test('it works', () => {
const tree = renderer
.create(
<ThemeProvider>
<Flex>
<p>Hello world!</p>
</Flex>
</ThemeProvider>
)
.toJSON();
expect(tree).toMatchSnapshot();
});

test('it works with styles', () => {
const tree = renderer
.create(
<ThemeProvider>
<Flex
styles={{
flex: '1 1 auto',
padding: '2'
}}
>
<p>Hello world!</p>
</Flex>
</ThemeProvider>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
36 changes: 36 additions & 0 deletions src/components/flex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
The Flex component creates flexbox layouts.

```jsx harmony
import { ThemeProvider, Box, Text, Flex } from '@lapidist/components';

<ThemeProvider>
<Flex>
<Box
styles={{
flex: '1 1 auto'
}}
>
<Text
styles={{
padding: 4,
backgroundColor: { group: 'primary', shade: 'base' },
textColor: { group: 'base', shade: 'light' }
}}
>
Hello world!
</Text>
</Box>
<Box>
<Text
styles={{
padding: 4,
backgroundColor: { group: 'primary', shade: 'light' },
textColor: { group: 'base', shade: 'light' }
}}
>
Hello world!
</Text>
</Box>
</Flex>
</ThemeProvider>
```
39 changes: 39 additions & 0 deletions src/components/flex/__snapshots__/Flex.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`it works 1`] = `
.c0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
<div
className="c0"
>
<p>
Hello world!
</p>
</div>
`;

exports[`it works with styles 1`] = `
.c0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
padding: 0.5rem;
}
<div
className="c0"
>
<p>
Hello world!
</p>
</div>
`;
19 changes: 19 additions & 0 deletions src/components/flex/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import deepMerge from 'lodash.merge';
import { Box, BoxProps } from '../box';

export type FlexPropType = BoxProps & React.HTMLProps<HTMLDivElement>;

export const Flex: React.FC<FlexPropType> = ({
as = 'div',
styles,
...restProps
}) => (
<Box
as={as}
styles={deepMerge({ display: 'flex' }, styles)}
{...restProps}
/>
);

Flex.displayName = 'Flex';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './aspect-ratio';
export * from './box';
export * from './button';
export * from './flex';
export * from './heading';
export * from './image';
export * from './link';
Expand Down

0 comments on commit a19cc3b

Please sign in to comment.