Skip to content

Commit

Permalink
feat: Flex 컴포넌트 추가 (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-moon authored Sep 3, 2021
1 parent a778bce commit b33f747
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
30 changes: 30 additions & 0 deletions src/components/Flex/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CSSProperties, ElementType, forwardRef, PropsWithRef, Ref } from 'react';
import { OverridableProps } from 'src/types/OverridableProps';

interface FlexBaseProps {
direction?: CSSProperties['flexDirection'];
align?: CSSProperties['alignItems'];
justify?: CSSProperties['justifyContent'];
}

type Props<T extends ElementType = 'div'> = OverridableProps<T, FlexBaseProps>;
const Flex = <T extends ElementType = 'div'>(
{ direction = 'row', align = 'flex-start', justify = 'flex-start', children }: Props<T>,
ref: Ref<any>
) => {
return (
<div
ref={ref}
css={{
display: 'flex',
flexDirection: direction,
alignItems: align,
justifyContent: justify,
}}
>
{children}
</div>
);
};

export default forwardRef(Flex) as PropsWithRef<typeof Flex>;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export { useOverlay } from './contexts/Overlay';
export { default as TransitionMotion } from './components/TransitionMotion';
export { default as useElementSize } from './hooks/useElementSize';
export { useAnimationFrame } from './hooks/useAnimationFrame';
export { default as Flex } from './components/Flex';
12 changes: 5 additions & 7 deletions src/stories/Components/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CombineElementProps } from '../../../types/utils';
import Text from '../../../components/Text';
import useProgress from '../../../hooks/useProgress';
import { colors } from '../../../constants/colors';
import Flex from '../../../components/Flex';

const noop = (value: number) => value;

Expand Down Expand Up @@ -60,12 +61,9 @@ const ProgressBar = forwardRef<HTMLDivElement, Props>(function ProgressBar(
const ratio = useProgress({ min, value, max, valueMapper });

return (
<div
css={{
display: 'flex',
flexDirection: layoutDirection,
alignItems: layoutDirection === 'row' ? 'center' : undefined,
}}
<Flex
direction={layoutDirection}
align={layoutDirection === 'row' ? 'center' : undefined}
ref={ref}
{...props}
>
Expand Down Expand Up @@ -100,7 +98,7 @@ const ProgressBar = forwardRef<HTMLDivElement, Props>(function ProgressBar(
}}
/>
</div>
</div>
</Flex>
);
});

Expand Down
5 changes: 3 additions & 2 deletions src/stories/Components/Skeleton/index.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Skeleton from '../../../components/Skeleton';
import Spacing from '../../../components/Spacing';
import Flex from '../../../components/Flex';
import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';

<Meta title="components/Skeleton" components={Skeleton} />
Expand All @@ -10,10 +11,10 @@ Skeleton 컴포넌트는

<Canvas>
<Story name="Skeleton">
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Flex direction="column">
<Skeleton width={50} height={50} type="circle" />
<Spacing size={10} />
<Skeleton width={100} height={20} />
</div>
</Flex>
</Story>
</Canvas>
8 changes: 4 additions & 4 deletions src/stories/Styles/Shadows/components.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ComponentProps } from 'react';
import Flex from '../../../components/Flex';

export const Box = ({ children, ...rest }: ComponentProps<'div'>) => {
return (
<div
<Flex
direction="column"
style={{
display: 'flex',
alignItems: 'flex-end',
height: 80,
borderRadius: 8,
backgroundColor: '#fcfcfd',
Expand All @@ -14,6 +14,6 @@ export const Box = ({ children, ...rest }: ComponentProps<'div'>) => {
{...rest}
>
{children}
</div>
</Flex>
);
};
4 changes: 2 additions & 2 deletions src/stories/Styles/Typography/index.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PC와 모바일의 rem 기준 서체 크기는 16px을 사용합니다. 서체

<Story name="Headings">
<ul>
{typographys.map((typography) => (
{Object.keys(typographys).map((typography) => (
<li style={{ listStyle: 'none' }} key={typography}>
<Text typography={typography}>{typographyNames[typography]}</Text>
</li>
Expand All @@ -27,7 +27,7 @@ PC와 모바일의 rem 기준 서체 크기는 16px을 사용합니다. 서체

<Story name="Font Weight">
<ul>
{fontWeights.map((fontWeight) => (
{Object.keys(fontWeights).map((fontWeight) => (
<li style={{ listStyle: 'none' }} key={fontWeight}>
<Text fontWeight={fontWeight}>{fontWeightNames[fontWeight]}</Text>
</li>
Expand Down
7 changes: 2 additions & 5 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { ComponentPropsWithoutRef, ComponentType, ElementType, ReactElement } from 'react';
import { ComponentProps, ComponentType, ElementType, ReactElement } from 'react';

/**
* @description T와 K에서 T의 프로퍼티를 제거한 타입을 병합합니다.
*/
export type Combine<T, K> = T & Omit<K, keyof T>;

export type CombineElementProps<E extends ElementType, P = unknown> = Combine<
P,
ComponentPropsWithoutRef<E>
>;
export type CombineElementProps<E extends ElementType, P = unknown> = Combine<P, ComponentProps<E>>;

export type ComponentElementType<T> = ReactElement<ComponentType<T>>;

0 comments on commit b33f747

Please sign in to comment.