Skip to content

Commit

Permalink
✨ feat: 新增 horizontal props
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 2, 2022
1 parent 9f68cb8 commit 1f38438
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/layout-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"registry": "https://registry.npmjs.org",
"access": "public"
},
"peerDependencies": {
"styled-components": ">5"
"dependencies": {
"styled-components": "^5.3.3"
},
"devDependencies": {
"styled-components": "^5.3.3",
Expand Down
9 changes: 6 additions & 3 deletions packages/layout-kit/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
export type CommonSpaceNumber = 2 | 4 | 8 | 12 | 16 | 24;

export interface IFlexbox {
horizontal?: boolean;
direction?: FlexDirection;
distribution?: ContentDistribution;
align?: ContentPosition;
Expand All @@ -28,7 +29,7 @@ export const Flexbox: FC<FlexboxProps> = styled.div.attrs(() => ({
}))<IFlexbox>`
display: flex;
flex-direction: ${(props) => {
return getFlexDirection(props.direction);
return getFlexDirection(props.direction, props.horizontal);
}};
justify-content: ${(props) => props.distribution};
align-items: ${(props) => props.align};
Expand All @@ -40,8 +41,10 @@ export const Flexbox: FC<FlexboxProps> = styled.div.attrs(() => ({
> *:not(:last-child) {
margin-right: ${(props) =>
getFlexDirection(props.direction) === 'row' && calcValue(props.gap)};
getFlexDirection(props.direction, props.horizontal) === 'row' &&
calcValue(props.gap)};
margin-bottom: ${(props) =>
getFlexDirection(props.direction) === 'column' && calcValue(props.gap)};
getFlexDirection(props.direction, props.horizontal) === 'column' &&
calcValue(props.gap)};
}
`;
3 changes: 2 additions & 1 deletion packages/layout-kit/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export type ContentPosition =
| 'flex-end'
| 'flex-start'
| 'start'
| 'stretch';
| 'stretch'
| 'baseline';

export type ContentDistribution =
| 'center'
Expand Down
7 changes: 6 additions & 1 deletion packages/layout-kit/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { FlexDirection } from './type';

export const getFlexDirection = (direction: FlexDirection) => {
export const getFlexDirection = (
direction: FlexDirection,
isHorizontal: boolean,
) => {
if (isHorizontal) return 'row';

switch (direction) {
case 'horizontal':
return 'row';
Expand Down

0 comments on commit 1f38438

Please sign in to comment.