Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Josanghyeon authored and Josanghyeon committed Dec 21, 2022
2 parents 4ec7d5b + eb3af30 commit d36672e
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 16 deletions.
14 changes: 14 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [1.2.1](https://github.com/team-aliens/design-system/compare/v1.2.0...v1.2.1) (2022-12-21)


### Bug Fixes

* checkBox export as 제거 ([4a383fb](https://github.com/team-aliens/design-system/commit/4a383fbd4635e954404aebfa07029bc7ae1fb7f8))

# [1.2.0](https://github.com/team-aliens/design-system/compare/v1.1.4...v1.2.0) (2022-12-21)


### Features

* 세그멘트 버튼 추가 및 여러 버그수정 ([#20](https://github.com/team-aliens/design-system/issues/20)) ([7670d58](https://github.com/team-aliens/design-system/commit/7670d589f80c9976691bb690c17bb90d09f096ef)), closes [#12](https://github.com/team-aliens/design-system/issues/12) [#11](https://github.com/team-aliens/design-system/issues/11) [#11](https://github.com/team-aliens/design-system/issues/11) [#14](https://github.com/team-aliens/design-system/issues/14) [#15](https://github.com/team-aliens/design-system/issues/15) [#19](https://github.com/team-aliens/design-system/issues/19)

## [1.1.4](https://github.com/team-aliens/design-system/compare/v1.1.3...v1.1.4) (2022-12-20)


Expand Down
4 changes: 3 additions & 1 deletion src/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const _Input = styled.input<{ errorMsg: string }>`
border-radius: 4px;
border: 1px solid
${({ theme, errorMsg }) =>
typeof errorMsg === 'undefined' ? theme.color.gray5 : theme.color.error};
typeof errorMsg === 'undefined' || errorMsg === ''
? theme.color.gray5
: theme.color.error};
:focus {
border: 2px solid ${({ theme }) => theme.color.primary};
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const _Wrapper = styled.label<wrapperPropsType>`
align-items: center;
width: 241px;
height: 40px;
margin: ${({ margin }) => marginToCss({ margin })};
${({ margin }) => marginToCss({ margin })};
background: ${({ theme }) => theme.color.gray1};
box-shadow: 0 1px 20px rgba(204, 204, 204, 0.24);
border-radius: 30px;
Expand Down
27 changes: 27 additions & 0 deletions src/components/segmentedBtn/SegmentBtn.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { useState } from 'react';
import { SegmentedBtn } from '.';

export default {
title: 'component/segmentedBtn',
component: SegmentedBtn,
} as ComponentMeta<typeof SegmentedBtn>;

const selectedArr = ['A', 'B', 'C'];

const Template: ComponentStory<typeof SegmentedBtn> = (args) => {
const [state, setState] = useState<string | number>(selectedArr[0]);
const onChange = (selected: string | number) => {
setState(selected);
};
return (
<SegmentedBtn
onChange={onChange}
selectedArr={selectedArr}
cur={state}
{...args}
/>
);
};

export const segmentedBtn = Template.bind({});
71 changes: 71 additions & 0 deletions src/components/segmentedBtn/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import styled, { css } from 'styled-components';
import { marginCssType, marginToCss } from '../../utils/distance';
import { Text } from '../styleGuide/text/Text';

interface PropsType<T> extends marginCssType {
selectedArr: T[];
cur: T;
onChange: (selected: T) => void;
}

export const SegmentedBtn = <T extends string | number>({
selectedArr,
cur,
onChange,
margin,
}: PropsType<T>) => {
return (
<_Wrapper margin={margin}>
{selectedArr.map((selected) => (
<_SelectedItem
onClick={() => onChange(selected)}
display="inline-block"
key={selected}
>
<_SelectedInner cur={selected === cur}>{selected}</_SelectedInner>
</_SelectedItem>
))}
</_Wrapper>
);
};

const _Wrapper = styled.div<marginCssType>`
${({ margin }) => marginToCss({ margin })};
display: inline-block;
height: 48px;
border: 1px solid ${({ theme }) => theme.color.primaryLighten1};
cursor: pointer;
border-radius: 4px;
> div {
:first-of-type {
left: -1px;
}
:last-of-type {
right: -1px;
}
}
`;

const _SelectedItem = styled(Text)`
color: ${({ theme }) => theme.color.gray4};
width: 110px;
height: 48px;
transition: 0.15s;
position: relative;
top: -1px;
`;

const _SelectedInner = styled.div<{ cur: boolean }>`
display: flex;
justify-content: center;
align-items: center;
height: 100%;
transition: 0.15s;
${({ theme, cur }) =>
cur &&
css`
background-color: ${theme.color.primary};
border-radius: 4px;
color ${theme.color.gray1}
`};
`;
2 changes: 1 addition & 1 deletion src/components/styleGuide/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const _Text = styled.div<PropsType>`
display: ${({ display }) => display};
color: ${({ color, theme }) => theme.color[color]};
${({ size, theme }) => theme.font[size]};
margin: ${({ margin }) => marginToCss({ margin })};
${({ margin }) => marginToCss({ margin })};
cursor: ${({ cursor }) => cursor};
text-align: ${({ align }) => align};
`;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './components/search';
export * from './components/styleGuide/icon';
export * from './components/modal';
export * from './components/breadCrumb/BreadCrumb';
export * from './components/segmentedBtn';
47 changes: 34 additions & 13 deletions src/utils/distance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,53 @@ import styled from 'styled-components';
/** 이거 배열말고 그냥 매개변수로 받아야 타이핑이 줄어들음 */
type marginType =
| [number, number, number, number]
| [number | directionType, number]
| [number | directionType, number | 'auto']
| [number];

export interface marginCssType {
margin?: marginType;
margin?: marginType[] | marginType;
}

export const marginToCss = ({ margin }: marginCssType) => {
if (!margin) return;
const mgReturn = (mg: marginType) => {
if (mg[0] === 0 && mg[1] === 'auto') {
return `margin: 0 auto;`;
}

switch (margin[0]) {
const unitTransform = (m: 'auto' | number) => (m === 'auto' ? m : m + 'px');

switch (mg[0]) {
case 'top':
return `${margin[1]}px 0 0 0`;
return `margin-top: ${unitTransform(mg[1])};`;
case 'bottom':
return `0 0 ${margin[1]}px 0`;
return `margin-bottom: ${unitTransform(mg[1])};`;
case 'left':
return `0 0 0 ${margin[1]}px`;
return `margin-left: ${unitTransform(mg[1])};`;
case 'right':
return `0 ${margin[1]}px 0 0`;
return `margin-right: ${unitTransform(mg[1])};`;
default:
let css = '';
for (let i = 0; i < margin.length; i++) css += margin[i] + 'px ';
return css;
let css = 'margin: ';
for (let j = 0; j < mg.length; j++) css += mg[j] + 'px ';
return css + ';';
}
};

export const marginToCss = ({ margin }: marginCssType) => {
if (!margin) return;
let mgCss = '';

if (Array.isArray(margin[0])) {
for (let i = 0; i < margin.length; i++) {
// @ts-expect-error
mgCss += mgReturn(margin[i]);
}
} else {
// @ts-expect-error
mgCss = mgReturn(margin);
}

return mgCss;
};

export const _Wrapper = styled.div<marginCssType>`
margin: ${({ margin }) => marginToCss({ margin })};
${({ margin }) => marginToCss({ margin })};
`;

0 comments on commit d36672e

Please sign in to comment.