Skip to content

Commit

Permalink
Feat(#38): Input 기본 스타일 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
KIMSEI1124 committed Nov 9, 2024
1 parent 07bd8f9 commit 436935a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/components/Common/Divider/Divider.styled.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { css } from '@emotion/css';
import { css } from '@emotion/react';

export interface DividerStyling {
$direction: 'vertical' | 'horizontal';
}

// FIXME: 해당 코드가 적용이 되지 않는 현상이 발생하여 추후 수정이 필요합니다.
export const getDirectionStyling = (
direction: Required<DividerStyling>['$direction'],
) => {
Expand Down
10 changes: 2 additions & 8 deletions src/components/Common/Divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentPropsWithRef, ElementType } from 'react';

import { getDirectionStyling } from './Divider.styled';
import Flex from '../Flex/Flex';

import type { DividerStyling } from './Divider.styled';
Expand Down Expand Up @@ -31,14 +32,7 @@ function Divider({ tag = 'div', styles, text, ...attributes }: DividerProps) {
css={{ inset: '0px' }}
aria-hidden="true"
>
<Tag
css={{
width: styles.$direction === 'vertical' ? '1px' : '100%',
height: styles.$direction === 'vertical' ? '100%' : '1px',
backgroundColor: '#d1d5db',
}}
{...attributes}
/>
<Tag css={[getDirectionStyling(styles.$direction)]} {...attributes} />
{text && (
<Flex
styles={{
Expand Down
49 changes: 49 additions & 0 deletions src/components/Common/Input/Input.styled.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
import { css } from '@emotion/react';

export interface InputStyling {
$variant: 'default' | 'title';

$width?: string;
$isValid?: boolean;
$void?: boolean;
$resize?: boolean;
}

export const getVariantStyling = (
variant: Required<InputStyling>['$variant'],
) => {
const style = {
title: css({
fontWeight: 'bold',
backgroundColor: 'transparent',

'&:focus': {
borderColor: '#008080',
},
}),
default: css({
borderRadius: '0.375rem',

'&:focus': {
outline: 'none',
boxShadow: '0 0 0 2px rgba(0, 128, 128, 0.5)',
},
}),
};
return style[variant];
};

export const getInputStyling = () => {
return css({
height: '2rem',
paddingLeft: '0.5rem',
paddingRight: '0.5rem',
transition: 'all 0.2s ease',

'::placeholder': {
color: '#D1D5DB',
},

'&:hover': {
borderColor: '#9CA3AF',
},

'&:focus': {
outline: 'none',
},
});
};
16 changes: 9 additions & 7 deletions src/components/Common/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { ComponentPropsWithRef } from 'react';
import type { ComponentPropsWithRef } from 'react';

import { getInputStyling, getVariantStyling } from './Input.styled';

import type { InputStyling } from './Input.styled';

export interface InputProps extends ComponentPropsWithRef<'input'> {
/** Input 스타일 옵션 */
styles: InputStyling;
}

function Input({ styles }: InputProps) {
const Tag = 'input';

function Input({ styles, ...attributes }: InputProps) {
return (
<div>
<Tag />
</div>
<input
css={[getInputStyling, getVariantStyling(styles.$variant)]}
{...attributes}
/>
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/components/Common/InputText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ type InputTextProps = {
const InputDefault = styled.input<InputTextProps>`
${tw`
h-8
rounded-md
px-2
transition
placeholder:text-gray-300
hover:outline-gray-400
focus:!outline-none
rounded-md
focus:ring
focus:ring-main
`}
Expand All @@ -32,14 +33,15 @@ const InputDefault = styled.input<InputTextProps>`
const InputTitle = styled.input<InputTextProps>`
${tw`
h-8
bg-transparent
font-bold
px-2
transition
placeholder:text-gray-300
hover:border-gray-400
focus:!outline-none
font-bold
bg-transparent
focus:border-main
`}
${(props) => (props.$void ? '' : tw`border-b-2`)}
Expand Down
11 changes: 10 additions & 1 deletion src/stories/Common/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ const meta: Meta<typeof Input> = {
component: Input,
tags: ['autodocs'],
args: {
styles: {},
styles: {
$variant: 'default',
},
},
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {};
export const Title: Story = {
args: {
styles: {
$variant: 'title',
},
},
};

0 comments on commit 436935a

Please sign in to comment.