Skip to content

Commit

Permalink
공용 컴포넌트 - CTABottomButton (#133)
Browse files Browse the repository at this point in the history
* chore: test page ctaBottomBtn 추가

* feat: CTABottomButton 컴포넌트 작성
  • Loading branch information
positiveko committed May 8, 2022
1 parent 5c3b6e1 commit 2955f7c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/components/common/Button/CTABottomButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentProps } from 'react';
import { css, Theme, useTheme } from '@emotion/react';

import { useUserAgent } from '~/hooks/common/useUserAgent';

import { CTAButton } from './CTAButton';

interface CTABottomButtonProps extends ComponentProps<typeof CTAButton> {}

export function CTABottomButton(props: CTABottomButtonProps) {
const { isIos } = useUserAgent();
const theme = useTheme();
const { children, ...rest } = props;

return (
<div css={ctaBottomButtonCss(isIos(), theme)}>
<CTAButton {...rest}>{children}</CTAButton>
</div>
);
}

const ctaBottomButtonCss = (isIos: boolean, theme: Theme) => css`
padding: ${isIos ? `8px 0 0 0` : `8px 0`};
background: ${theme.color.background};
`;
1 change: 1 addition & 0 deletions src/hooks/common/useUserAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const getMobileDetect = (userAgent: string): IUseUserAgent => {
const isMobile = (): boolean => Boolean(isAndroid() || isIos());
const isSSR = (): boolean => Boolean(userAgent.match(/SSR/i));
const isDesktop = (): boolean => Boolean(!isMobile() && !isSSR());

return {
isAndroid,
isIos,
Expand Down
27 changes: 23 additions & 4 deletions src/pages/test/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren } from 'react';
import { PropsWithChildren, useEffect, useState } from 'react';
import { css } from '@emotion/react';

import Button, {
Expand All @@ -7,6 +7,7 @@ import Button, {
GhostButton,
IconButton,
} from '~/components/common/Button';
import { CTABottomButton } from '~/components/common/Button/CTABottomButton';
import CheckList from '~/components/common/CheckList';
import { SearchIcon } from '~/components/common/icons';
import NavigationBar from '~/components/common/NavigationBar';
Expand All @@ -20,6 +21,13 @@ import theme from '~/styles/Theme';
export default function Test() {
const { fireToast } = useToast();
const { isMobile, isIos, isAndroid, isDesktop } = useUserAgent();
const [isSSR, setIsSSR] = useState(true);

useEffect(() => {
setIsSSR(false);
}, []);

if (isSSR) return null;

return (
<div>
Expand All @@ -40,6 +48,8 @@ export default function Test() {
<CTAButton>CTA 버튼</CTAButton>
<CTAButton disabled>CTA 버튼 비활성화</CTAButton>

<CTABottomButton>CTA Bottom 버튼(ios일 때 패딩 변화)</CTABottomButton>

<FilledButton>Filled 버튼</FilledButton>
<FilledButton colorType="light">Filled 버튼 라이트</FilledButton>
</TestItem>
Expand Down Expand Up @@ -96,9 +106,10 @@ export default function Test() {
<Button onClick={() => fireToast({ content: '토스트 메세지' })}>토스트 발사 버튼</Button>

<hr />
<TextField label={'라벨라벨'} placeholder={'플레이스 홀더'} />
<TextField readOnly label={'라벨라벨'} placeholder={'플레이스 홀더'} />
<br />
<TextField
readOnly
label={'라벨라벨'}
placeholder={'플레이스 홀더'}
value={'성공한 상태의 input'}
Expand All @@ -107,6 +118,7 @@ export default function Test() {
/>
<br />
<TextField
readOnly
label={'라벨벨'}
placeholder={'검색'}
feedback={'검색을 만들 땐 이렇게 사용하겠죠?'}
Expand All @@ -123,9 +135,16 @@ export default function Test() {
isSuccess
/>
<br />
<TextField as={'textarea'} rows={10} label={'라벨라벨'} placeholder={'플레이스 홀더'} />
<TextField
readOnly
as={'textarea'}
rows={10}
label={'라벨라벨'}
placeholder={'플레이스 홀더'}
/>
<br />
<TextField
readOnly
as={'textarea'}
rows={10}
label={'라벨라벨'}
Expand All @@ -150,7 +169,7 @@ export default function Test() {
>
체크 리스트
</CheckList>
<SearchBar value={'asdasdasd'} />
<SearchBar readOnly value={'asdasdasd'} />
<MemoText editable wordLimit={150} />
</div>
);
Expand Down

0 comments on commit 2955f7c

Please sign in to comment.