Skip to content

Commit

Permalink
[#191] feature: SearchInput storybook 적용
Browse files Browse the repository at this point in the history
SearchInput이 가질 수 있는 상태를 스토리로 구현
  • Loading branch information
Seo0H committed Aug 17, 2023
1 parent 7bb3fb7 commit 4c8b4d8
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions src/components/common/SearchInput/SearchInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/* eslint-disable import/no-extraneous-dependencies */
import { useState } from '@storybook/addons';

import { MagnifyingGlassIcon } from '@/assets/Icons';
import SearchInput from '@/components/common/SearchInput';
import AutoCmpContainer from '@/components/common/SearchInput/AutoCmpContainer';
import * as Style from '@/components/common/SearchInput/style';
import * as Layout from '@/components/common/layout/index';

import type { Meta } from '@storybook/react';

const meta = {
title: 'Common/SearchInput',
component: SearchInput,
tags: ['autodocs'],
decorators: [
Story => (
<Layout.Box width='275px'>
<Story />
</Layout.Box>
),
],
} satisfies Meta<typeof SearchInput>;

export default meta;

export function Default() {
const [search, setSearch] = useState('');
const [isFocus, setIsFocus] = useState(false);

const MockAutocmpList = ['자동완성 예시1', '자동완성 예시2'];
const state = 'success';

return (
<Layout.HStack width='100%' height='60px' justifyContent='space-between' maxWidth='310px'>
<Style.SearchInputBox focus={isFocus} search={search}>
<Style.SearchEnterInput
type='text'
placeholder='살까 말까하는 그 물건...'
value={search}
onFocus={() => setIsFocus(true)}
onBlur={() => setIsFocus(false)}
onChange={e => setSearch(e.target.value)}
aria-label='search-input'
/>
{isFocus && search && (
<AutoCmpContainer autoCmpList={MockAutocmpList} setSearch={setSearch} state={state} />
)}
</Style.SearchInputBox>

<Style.SearchButton type='button'>
<MagnifyingGlassIcon />
</Style.SearchButton>
</Layout.HStack>
);
}

export function onFocus() {
const isFocus = true;
const search = '';

return (
<Layout.HStack width='100%' height='60px' justifyContent='space-between' maxWidth='310px'>
<Style.SearchInputBox focus={isFocus} search={search}>
<Style.SearchEnterInput
type='text'
placeholder='살까 말까하는 그 물건...'
value={search}
aria-label='search-input'
/>
</Style.SearchInputBox>
<Style.SearchButton type='button'>
<MagnifyingGlassIcon />
</Style.SearchButton>
</Layout.HStack>
);
}

export function autoFocus() {
const isFocus = true;
const search = '자동완성';
const MockAutocmpList = ['자동완성 예시1', '자동완성 예시2'];
const state = 'success';

return (
<Layout.HStack width='100%' height='60px' justifyContent='space-between' maxWidth='310px'>
<Style.SearchInputBox focus={isFocus} search={search}>
<Style.SearchEnterInput
type='text'
placeholder='살까 말까하는 그 물건...'
value={search}
aria-label='search-input'
/>
<AutoCmpContainer autoCmpList={MockAutocmpList} setSearch={() => false} state={state} />
</Style.SearchInputBox>
<Style.SearchButton type='button'>
<MagnifyingGlassIcon />
</Style.SearchButton>
</Layout.HStack>
);
}

export function autoFocusLoading() {
const isFocus = true;
const search = '자동완성';
const MockAutocmpList = [''];
const state = 'loading';

return (
<Layout.HStack width='100%' height='60px' justifyContent='space-between' maxWidth='310px'>
<Style.SearchInputBox focus={isFocus} search={search}>
<Style.SearchEnterInput
type='text'
placeholder='살까 말까하는 그 물건...'
value={search}
aria-label='search-input'
/>
<AutoCmpContainer autoCmpList={MockAutocmpList} setSearch={() => false} state={state} />
</Style.SearchInputBox>
<Style.SearchButton type='button'>
<MagnifyingGlassIcon />
</Style.SearchButton>
</Layout.HStack>
);
}

0 comments on commit 4c8b4d8

Please sign in to comment.