Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jy/XButton, Input, Search Filter 구현 #97

Merged
merged 10 commits into from
Nov 5, 2020
16 changes: 16 additions & 0 deletions client/src/components/atoms/Input/FilterInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { useState } from 'react';
import { text } from '@storybook/addon-knobs';
import FilterInput from './FilterInput';

export default {
component: FilterInput,
title: 'FilterInput',
};
export const Default = () => {
const content = text('content', 'content');
const type = text('type', 'button');
const onClick = () => {
// 버튼 메서드
};
return <FilterInput type={type} content={content} onClick={onClick} />;
};
39 changes: 39 additions & 0 deletions client/src/components/atoms/Input/FilterInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { FunctionComponent } from 'react';
import styled from '@themes/styled';

interface Props {
content: string;
onClick?: () => void;
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
type: string;
}

const StyledInput = styled.input`
font-size: 1rem;
text-decoration: none;
border: none;
background-color: rgba(0, 0, 0, 0);
cursor: pointer;
&:focus {
outline: none;
}
`;

const FilterInput: FunctionComponent<Props> = ({
type,
content,
onClick,
onChange,
}) => {
return (
<StyledInput
type={type}
onClick={onClick}
onChange={onChange}
value={content}
/>
);
};

export default FilterInput;
3 changes: 2 additions & 1 deletion client/src/components/atoms/Input/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './Input';
export { default as Input } from './Input';
export { default as FilterInput } from './FilterInput';
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { useState } from 'react';
import { text } from '@storybook/addon-knobs';
import FilterModal from './FilterModal';

export default {
component: FilterModal,
title: 'FilterModal',
};
export const Default = () => {
const optionHeader = text('optionHeader', 'Filter Issues');
const options = [
'Open issues',
'Your issues',
'Everything assigned to you',
'Everything mentioning to you',
'Closed issues',
];
const type = 'button';
const keys = ['search1', 'search2', 'search3', 'search4', 'search5'];
const onClick = () => {
// modal button 클릭 시
};
return (
<FilterModal
display="block"
optionHeader={optionHeader}
options={options}
onClick={onClick}
type={type}
keys={keys}
/>
);
};

export const Author = () => {
const optionHeader = text('optionHeader', 'Filter by author');
const options = ['user1', 'user2', 'user3', 'user4', 'user5'];
const onClick = () => {
// modal button 클릭 시
};
const type = 'checkbox';
const keys = ['radio1', 'radio2', 'radio3', 'radio4', 'radio5'];
const input = 'Filter users';
return (
<FilterModal
display="block"
optionHeader={optionHeader}
options={options}
onClick={onClick}
type={type}
input={input}
keys={keys}
/>
);
};
75 changes: 75 additions & 0 deletions client/src/components/molecules/FilterModal/FilterModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { FunctionComponent } from 'react';
import styled from '@themes/styled';
import { Input, FilterInput } from '@components/atoms/Input';

interface Props {
optionHeader: string;
options: string[];
onClick?: () => void;
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
input?: string;
type: string;
keys: string[];
display: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display type을 string보다는 좀더 명확하게 (ex 'flex' | 'block') 하는게 좋습니당

}

const StyledUl = styled.ul`
border-radius: 0.3rem;
list-style: none;
border: 1px solid ${({ theme }) => theme.palette.BORDER_COLOR};
max-width: 300px;
margin: 10px 0;
`;

const StyledLi = styled.li`
& > h3 {
font-weight: 600;
}
& > input {
width: 100%;
text-align: left;
}
& > input,
& > h3 {
color: ${({ theme }) => theme.palette.PRIMARY};
font-size: 0.8rem;
padding: 7px 16px;
border-bottom: 1px solid ${({ theme }) => theme.palette.BORDER_COLOR};
}
& > input:hover {
background-color: ${({ theme }) => theme.palette.BG_COLOR02};
}
& > input:focus {
outline: none;
}
`;

const SearchFilter: FunctionComponent<Props> = ({
optionHeader,
options,
onClick,
type,
input,
display,
keys,
}) => {
return (
<StyledUl style={{ display }}>
<StyledLi>
<h3>{optionHeader}</h3>
</StyledLi>
{input ? <Input placeholder={input} type="text" /> : <></>}
{options.map((option: string, i: number) => (
<StyledLi key={keys[i]}>
<FilterInput type={type} content={option} onClick={onClick} />
</StyledLi>
))}
</StyledUl>
);
};

export default SearchFilter;
1 change: 1 addition & 0 deletions client/src/components/molecules/FilterModal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './FilterModal';