generated from arvinxx/monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
249 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# @arvinxu/layout-kit | ||
|
||
[![NPM version][version-image]][version-url] [![NPM downloads][download-image]][download-url] | ||
|
||
## License | ||
|
||
[MIT](../../LICENSE) ® Arvin Xu | ||
|
||
<!-- npm url --> | ||
|
||
[version-image]: http://img.shields.io/npm/v/@arvinxu/layout-kit.svg?color=deepgreen&label=latest | ||
[version-url]: http://npmjs.org/package/@arvinxu/layout-kit | ||
[download-image]: https://img.shields.io/npm/dm/@arvinxu/layout-kit.svg | ||
[download-url]: https://npmjs.org/package/@arvinxu/layout-kit |
4 changes: 2 additions & 2 deletions
4
packages/layout-toolkit/jest.config.js → packages/layout-kit/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
packages/layout-toolkit/package.json → packages/layout-kit/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { DetailedHTMLProps, FC, HTMLAttributes } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { calcValue, getFlexDirection } from './utils'; | ||
import type { | ||
ContentDistribution, | ||
ContentPosition, | ||
FlexDirection, | ||
} from './type'; | ||
|
||
type CommonSpaceNumber = 2 | 4 | 8 | 12 | 16 | 24; | ||
|
||
interface IFlexbox { | ||
direction?: FlexDirection; | ||
distribution?: ContentDistribution; | ||
align?: ContentPosition; | ||
gap?: CommonSpaceNumber | number; | ||
width?: number | string; | ||
height?: number | string; | ||
padding?: string | number | CommonSpaceNumber; | ||
} | ||
export type FlexboxProps = IFlexbox & | ||
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>; | ||
|
||
export const Flexbox: FC<FlexboxProps> = styled.div.attrs(() => ({ | ||
className: 'layoutkit-flexbox', | ||
}))<IFlexbox>` | ||
display: flex; | ||
flex-direction: ${(props) => { | ||
return getFlexDirection(props.direction); | ||
}}; | ||
justify-content: ${(props) => props.distribution}; | ||
align-items: ${(props) => props.align}; | ||
width: ${(props) => calcValue(props.width)}; | ||
height: ${(props) => calcValue(props.height)}; | ||
padding: ${(props) => calcValue(props.padding)}; | ||
> *:not(:last-child) { | ||
margin-right: ${(props) => | ||
getFlexDirection(props.direction) === 'row' && calcValue(props.gap)}; | ||
margin-bottom: ${(props) => | ||
getFlexDirection(props.direction) === 'column' && calcValue(props.gap)}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export type ContentPosition = | ||
| 'center' | ||
| 'end' | ||
| 'flex-end' | ||
| 'flex-start' | ||
| 'start' | ||
| 'stretch'; | ||
|
||
export type ContentDistribution = | ||
| 'center' | ||
| 'space-around' | ||
| 'space-between' | ||
| 'space-evenly' | ||
| 'stretch'; | ||
|
||
export type FlexDirection = | ||
| 'vertical' | ||
| 'vertical-reverse' | ||
| 'horizontal' | ||
| 'horizontal-reverse'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { FlexDirection } from './type'; | ||
|
||
export const getFlexDirection = (direction: FlexDirection) => { | ||
switch (direction) { | ||
case 'horizontal': | ||
return 'row'; | ||
case 'horizontal-reverse': | ||
return 'row-reverse'; | ||
case 'vertical': | ||
default: | ||
return 'column'; | ||
case 'vertical-reverse': | ||
return 'column-reverse'; | ||
} | ||
}; | ||
|
||
export const calcValue = (value: string | number) => | ||
typeof value === 'number' ? `${value}px` : value; |
16 changes: 16 additions & 0 deletions
16
packages/layout-kit/tests/__snapshots__/index.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Flexbox gap 1`] = ` | ||
<div> | ||
<div | ||
class="sc-bdvvtL ezjxOX" | ||
> | ||
<div> | ||
1 | ||
</div> | ||
<div> | ||
2 | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { Flexbox } from '@arvinxu/layout-kit'; | ||
|
||
describe('Flexbox', () => { | ||
it('gap', () => { | ||
const { container } = render( | ||
<Flexbox gap={2}> | ||
<div>1</div> | ||
<div>2</div> | ||
</Flexbox>, | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
packages/layout-toolkit/tests/__snapshots__/index.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.