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

feat: ListRow 컴포넌트 #55

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/common/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line react-refresh/only-export-components
export * from './selectweek/SelectWeek'
export * from './listRow/ListRow'
export * from './label/Label'
export * from './icon/Icon'
53 changes: 53 additions & 0 deletions src/components/common/listRow/ListRow.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Meta, StoryObj } from '@storybook/react'
import ListRow from '@/components/common/listRow/ListRow'

const meta: Meta<typeof ListRow> = {
component: ListRow,
tags: ['autodocs'],
title: 'components/ListRow',
argTypes: {
hasBorder: {
control: 'boolean'
},
rightElement: {
control: 'text'
},
leftElement: {
control: 'text',
required: true
},
paddingSize: {
control: 'select',
options: ['small', 'medium', 'large']
}
},
render: ({ ...args }) => (
<ListRow
rightElement={<div>{args.rightElement}</div>}
leftElement={<div>{args.leftElement}</div>}
paddingSize={args.paddingSize}
hasBorder={args.hasBorder}
/>
)
}

export default meta
type Story = StoryObj<typeof ListRow>

export const Default: Story = {
args: {
rightElement: <div>{'학원명'}</div>,
leftElement: <div>{'샤론음악학원'}</div>,
paddingSize: 'medium',
hasBorder: false
}
}

export const ListRowBorder: Story = {
args: {
rightElement: <div>{'학원명'}</div>,
leftElement: <div>{'샤론음악학원'}</div>,
paddingSize: 'medium',
hasBorder: true
}
}
31 changes: 31 additions & 0 deletions src/components/common/listRow/ListRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable prettier/prettier */
import { ComponentProps, ReactNode } from 'react'
import { PaddingSizeType, PaddingVariant } from './ListRowType'

/**
* @param leftElement 왼쪽 요소 (필수) ReactNode로 작성해야 함.
* @param rightElement 오른쪽 요소 ReactNode로 작성해야 함
* @param paddingSize 'small [10px] | medium [20px] | large [30px] 가로 사이즈만 조절됨'
* @param hasBorder 'bottom-border 의 존재 여부 설정'
* */

interface ListRowProps extends ComponentProps<'div'> {
rightElement: ReactNode
leftElement?: ReactNode
paddingSize?: PaddingSizeType
hasBorder?: boolean
}

const ListRow = ({ leftElement, rightElement, hasBorder = true, paddingSize = 'medium' }: ListRowProps) => {
return (
<div
className={`flex flex-row justify-between items-center py-[13px] ${hasBorder ? 'border border-b-gray-200' : ''
} ${PaddingVariant[paddingSize]}`}
>
{leftElement}
{rightElement}
</div>
)
}

export default ListRow
6 changes: 6 additions & 0 deletions src/components/common/listRow/ListRowType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type PaddingSizeType = 'small' | 'medium' | 'large'
export const PaddingVariant = {
small: 'px-[10px]',
medium: 'px-[20px]',
large: 'px-[30px]'
}