Skip to content

Commit

Permalink
refactor: change gap props in Flex component
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-kibong committed Sep 23, 2024
1 parent e0e1cc4 commit 0048f14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/components/common/Flex/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export const Default: Story = {
direction: 'row',
justifyContent: 'center',
alignItems: 'center',
xGap: '10px',
yGap: '10px',
gap: {
x: '10px',
y: '10px',
},
},
render: (args) => (
<Flex {...args}>
Expand Down
24 changes: 10 additions & 14 deletions src/components/common/Flex/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import styled from '@emotion/styled';
import type * as CSS from 'csstype';
import { HTMLAttributes } from 'react';

type FlexGap = {
x: string;
y: string;
};

interface FlexProps {
direction?: 'column' | 'row';
xGap?: string;
yGap?: string;
gap?: FlexGap;
justifyContent?: CSS.Properties['justifyContent'];
alignItems?: CSS.Properties['alignItems'];
}
Expand All @@ -14,22 +18,14 @@ type Props = HTMLAttributes<HTMLDivElement> & FlexProps;

export default function Flex({
direction = 'row',
xGap,
yGap,
gap,
justifyContent = 'start',
alignItems = 'start',
children,
...rest
}: Props) {
return (
<Container
direction={direction}
xGap={xGap}
yGap={yGap}
justifyContent={justifyContent}
alignItems={alignItems}
{...rest}
>
<Container direction={direction} gap={gap} justifyContent={justifyContent} alignItems={alignItems} {...rest}>
{children}
</Container>
);
Expand All @@ -41,6 +37,6 @@ const Container = styled.div<FlexProps>`
flex-direction: ${(p) => p.direction};
justify-content: ${(p) => p.justifyContent};
align-items: ${(p) => p.alignItems};
column-gap: ${(p) => p.xGap};
row-gap: ${(p) => p.yGap};
column-gap: ${(p) => p.gap?.x};
row-gap: ${(p) => p.gap?.y};
`;
5 changes: 2 additions & 3 deletions src/components/common/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { InputHTMLAttributes } from 'react';
import styled from '@emotion/styled';
import Flex from '@components/common/Flex';
import palettes from '@assets/styles/global/pallets';

interface Props extends InputHTMLAttributes<HTMLInputElement> {
Expand All @@ -9,10 +8,10 @@ interface Props extends InputHTMLAttributes<HTMLInputElement> {

export default function Input({ label, ...rest }: Props) {
return (
<Flex xGap="8px" alignItems="center">
<>
{label && <label>{label}</label>}
<InputContainer {...rest} />
</Flex>
</>
);
}

Expand Down

0 comments on commit 0048f14

Please sign in to comment.