From 41befb07a9a5aaa67e08c892bddb566cb8915c39 Mon Sep 17 00:00:00 2001 From: JinJu Date: Thu, 13 Jun 2024 11:46:45 +0900 Subject: [PATCH] Setting prettier, eslint --- .eslintrc.json | 39 +-- .prettierrc | 10 + package.json | 7 +- src/constants/color.ts | 50 +-- src/constants/index.ts | 90 ++--- src/constants/theme.ts | 34 +- src/constants/typography.ts | 46 +-- .../BottomSheet/BottomSheet.stories.tsx | 46 ++- src/core/components/BottomSheet/index.tsx | 87 ++--- .../components/BottomSheet/types/index.ts | 10 +- .../Button/Button/Button.stories.tsx | 88 ++--- src/core/components/Button/Button/index.tsx | 47 +-- .../components/Button/Button/types/index.ts | 6 +- .../Button/ButtonBase/constants/index.ts | 66 ++-- .../components/Button/ButtonBase/index.tsx | 108 +++--- .../Button/ButtonBase/types/index.ts | 25 +- .../Button/IconButton/IconButton.stories.tsx | 68 ++-- .../Button/IconButton/constants/index.ts | 22 +- .../components/Button/IconButton/index.tsx | 43 +-- .../Button/IconButton/types/index.ts | 5 +- .../BasicCalendar/BasicCalendar.stories.tsx | 16 +- .../Calendar/BasicCalendar/index.tsx | 82 +++-- .../DatePickerCalendar.stories.tsx | 49 ++- .../DatePickerCalendar/constants/index.ts | 4 +- .../Calendar/DatePickerCalendar/index.tsx | 314 +++++++++++------- .../subs/CalendarComponentDaySubText.tsx | 42 +-- .../subs/CalendarComponentDayText.tsx | 67 ++-- .../types/DatePickerCalendarProps.ts | 16 +- .../ScheduleCalendar.stories.tsx | 82 ++--- .../Calendar/ScheduleCalendar/index.tsx | 52 +-- .../subs/CalendarDayComponent.tsx | 188 ++++++----- .../types/CalendarComponentProps.ts | 7 +- .../Calendar/common/constants/index.ts | 8 +- .../Calendar/common/hooks/useCalendar.ts | 20 +- .../common/hooks/useMonthChangeEffect.tsx | 40 ++- .../Calendar/common/subs/CalendarHeader.tsx | 57 ++-- .../common/subs/CalendarWeekdayComponent.tsx | 40 ++- .../Calendar/common/types/CalendarDateDto.ts | 2 +- .../Calendar/common/types/CalendarHeader.ts | 7 +- .../common/types/UseCalendarResponse.ts | 8 +- .../components/Checkbox/Checkbox.stories.tsx | 28 +- .../components/Checkbox/constants/index.ts | 10 +- src/core/components/Checkbox/index.tsx | 74 +++-- src/core/components/Checkbox/types/index.ts | 7 +- .../components/Divider/Divider.stories.tsx | 12 +- src/core/components/Divider/index.tsx | 9 +- src/core/components/Drawer/Drawer.stories.tsx | 62 ++-- src/core/components/Drawer/index.tsx | 97 +++--- src/core/components/Drawer/types/index.ts | 16 +- .../DropdownBase/Dropdown.stories.tsx | 50 ++- .../Dropdown/DropdownBase/DropdownItem.tsx | 64 ++-- .../Dropdown/DropdownBase/DropdownItems.tsx | 44 +-- .../Dropdown/DropdownBase/DropdownTrigger.tsx | 78 +++-- .../Dropdown/DropdownBase/index.tsx | 46 ++- .../Dropdown/DropdownBase/types/index.ts | 24 +- .../DropdownFilter/DropdownFilter.stories.tsx | 26 +- .../DropdownFilter/DropdownFilterItem.tsx | 44 +-- .../DropdownFilter/DropdownFilterItems.tsx | 37 ++- .../DropdownFilter/DropdownFilterTrigger.tsx | 52 +-- .../Dropdown/DropdownFilter/index.tsx | 18 +- .../Dropdown/DropdownFilter/types/index.ts | 21 +- .../DropdownSelect/DropdownSelect.stories.tsx | 27 +- .../DropdownSelect/DropdownSelectItem.tsx | 44 +-- .../DropdownSelect/DropdownSelectItems.tsx | 37 ++- .../DropdownSelect/DropdownSelectTrigger.tsx | 76 +++-- .../Dropdown/DropdownSelect/index.tsx | 18 +- .../Dropdown/DropdownSelect/types/index.ts | 21 +- .../FormLabel/FormLabel.stories.tsx | 38 ++- src/core/components/FormLabel/index.tsx | 43 ++- src/core/components/FormLabel/types/index.ts | 6 +- .../Input/InputBase/InputBase.stories.tsx | 99 +++--- src/core/components/Input/InputBase/index.tsx | 87 +++-- .../components/Input/InputBase/types/index.ts | 16 +- .../Input/InputDatePicker/DatePicker.tsx | 144 ++++---- .../InputDatePicker.stories.tsx | 78 +++-- .../Input/InputDatePicker/index.tsx | 132 ++++---- .../Input/InputDatePicker/types/index.ts | 59 +++- .../InputPassword/InputPassword.stories.tsx | 27 +- .../components/Input/InputPassword/index.tsx | 143 ++++---- .../Input/InputPassword/types/index.ts | 22 +- .../Input/InputSearch/InputSearch.stories.tsx | 39 +-- .../Input/InputSearch/constants/index.ts | 18 +- .../components/Input/InputSearch/index.tsx | 120 +++---- .../Input/InputSearch/types/index.ts | 28 +- .../Input/InputSelect/InputSelect.stories.tsx | 42 +-- .../components/Input/InputSelect/index.tsx | 99 +++--- .../Input/InputSelect/types/index.ts | 14 +- .../InputTextArea/InputTextArea.stories.tsx | 53 +-- .../Input/InputTextArea/constants/index.ts | 14 +- .../components/Input/InputTextArea/index.tsx | 135 ++++---- .../Input/InputTextArea/types/index.ts | 33 +- .../InputTextField/InputTextField.stories.tsx | 53 +-- .../components/Input/InputTextField/index.tsx | 133 ++++---- .../Input/InputTextField/types/index.ts | 23 +- .../hooks/effects/useValueChangeEffect.ts | 10 +- src/core/components/Input/hooks/useInput.ts | 41 ++- src/core/components/Label/Label.stories.tsx | 68 ++-- src/core/components/Label/constants/index.ts | 14 +- src/core/components/Label/index.tsx | 26 +- src/core/components/Label/types/index.ts | 8 +- .../Modal/ModalBase/ModalBase.stories.tsx | 65 ++-- .../Modal/ModalBase/constants/index.ts | 27 +- src/core/components/Modal/ModalBase/index.tsx | 67 ++-- .../components/Modal/ModalBase/types/index.ts | 12 +- .../Modal/ModalPopUp/ModalPopUp.stories.tsx | 63 ++-- .../components/Modal/ModalPopUp/index.tsx | 60 ++-- .../Modal/ModalPopUp/types/index.ts | 11 +- .../components/Modal/ModalPortal/index.tsx | 10 +- src/core/components/Radio/Radio.stories.tsx | 23 +- src/core/components/Radio/index.tsx | 64 ++-- src/core/components/Radio/types/index.ts | 7 +- .../components/Section/Section.stories.tsx | 26 +- .../components/Section/constants/index.ts | 22 +- src/core/components/Section/index.tsx | 49 ++- src/core/components/Section/types/index.ts | 7 +- .../GeneralTab/GeneralTab.stories.tsx | 32 +- .../Tab/GeneralTab/GeneralTab/index.tsx | 42 ++- .../Tab/GeneralTab/GeneralTab/types/index.ts | 7 +- .../GeneralTabItem/GeneralTabItem.stories.tsx | 16 +- .../Tab/GeneralTab/GeneralTabItem/index.tsx | 68 ++-- .../GeneralTab/GeneralTabItem/types/index.ts | 5 +- .../TableTab/TableTab/TableTab.stories.tsx | 30 +- .../Tab/TableTab/TableTab/index.tsx | 41 ++- .../Tab/TableTab/TableTab/types/index.ts | 4 +- .../TableTabItem/TableTabItem.stories.tsx | 14 +- .../Tab/TableTab/TableTabItem/index.tsx | 59 ++-- .../Tab/TableTab/TableTabItem/types/index.ts | 3 +- src/core/components/Table/Table.stories.tsx | 121 +++---- src/core/components/Table/Table.tsx | 38 +-- src/core/components/Table/TableBody.tsx | 36 +- src/core/components/Table/TableCell.tsx | 23 +- src/core/components/Table/TableContainer.tsx | 48 ++- src/core/components/Table/TableHead.tsx | 36 +- src/core/components/Table/TableRow.tsx | 47 ++- src/core/components/Table/constants/index.ts | 21 +- src/core/components/Table/types/index.ts | 11 +- .../TextEditor/TextEditor.stories.tsx | 36 +- src/core/components/TextEditor/index.tsx | 44 +-- src/core/components/Toggle/Toggle.stories.tsx | 58 ++-- src/core/components/Toggle/constants/index.ts | 24 +- src/core/components/Toggle/index.tsx | 52 +-- src/core/components/Toggle/types/index.ts | 13 +- .../components/Tooltip/Tooltip.stories.tsx | 184 +++++----- src/core/components/Tooltip/index.tsx | 16 +- .../Typography/Typography.stories.tsx | 36 +- src/core/components/Typography/index.tsx | 25 +- src/core/components/Typography/types/index.ts | 4 +- src/hooks/effects/useBlockScrollingEffect.ts | 8 +- src/hooks/effects/useClickOutSideEffect.ts | 11 +- src/hooks/useClickOutSide.ts | 4 +- src/index.ts | 99 +++--- src/styles/bbodek-theme.css | 39 ++- src/types/index.ts | 62 +++- src/utilities/utils.ts | 4 +- vite.config.ts | 23 +- yarn.lock | 53 +++ 156 files changed, 3793 insertions(+), 3122 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc.json b/.eslintrc.json index 5508e60..db85065 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,42 +5,19 @@ "node": true, "jest": true }, - "extends": [ - "plugin:@typescript-eslint/recommended" - ], "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" }, "parser": "@typescript-eslint/parser", - "plugins": [ - "@stylistic", - "react" - ], + "plugins": ["prettier", "react"], "rules": { - "@stylistic/jsx-indent": ["error", 2], - "@stylistic/quotes": ["error", "double"], - "@stylistic/object-curly-spacing": ["error", "always"], - "@stylistic/comma-dangle": ["error", "always-multiline"], - "@stylistic/eol-last": ["error", "always"], - "@stylistic/no-trailing-spaces": "error", - "@stylistic/no-multi-spaces": "error", - "@stylistic/comma-spacing": ["error", { "before": false, "after": true }], - "@stylistic/key-spacing": ["error", { "afterColon": true, "beforeColon": false }], - "@stylistic/semi": ["error", "always"], - "@stylistic/space-in-parens": ["error", "never"], - "@stylistic/arrow-spacing": "error", - "@stylistic/no-extra-semi": "error", - "@stylistic/array-bracket-spacing": ["error","always",{"singleValue": false}], - "@stylistic/comma-style": ["error","last"], - "@stylistic/array-element-newline" : ["error","consistent"], - "@stylistic/arrow-parens": ["error", "as-needed"], - "@stylistic/block-spacing": "error", - "@stylistic/brace-style": "error", - "@stylistic/jsx-equals-spacing": [2, "always"], - "@stylistic/function-call-argument-newline": ["error", "consistent"], - "@stylistic/no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }], "react/jsx-first-prop-new-line": ["error", "multiline"], - "@typescript-eslint/no-inferrable-types": "off" - } + "@typescript-eslint/no-inferrable-types": "off", + "semi": [2, "always"] + }, + "extends": [ + "plugin:prettier/recommended", + "prettier" + ] } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b61dfd2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "semi": true, + "useTabs": false, + "tabWidth": 2, + "singleQuote": true, + "jsxSingleQuote": true, + "trailingComma": "all", + "plugins": ["prettier-plugin-tailwindcss"], + "tailwindFunctions": ["clsx"] +} diff --git a/package.json b/package.json index 7874b8b..43c2576 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --fix", "preview": "vite preview", "storybook": "storybook dev -p 6006", - "storybook:build": "storybook build" + "storybook:build": "storybook build", + "format": "prettier --write \"src/**/*.{ts,tsx,css}\"" }, "peerDependencies": { "@types/react": "18.2.0", @@ -71,13 +72,17 @@ "@typescript-eslint/parser": "6.11.0", "@vitejs/plugin-react": "4.0.3", "eslint": "8.54.0", + "eslint-config-prettier": "9.1.0", "eslint-config-standard-with-typescript": "39.1.1", "eslint-plugin-import": "2.29.0", "eslint-plugin-n": "16.3.1", + "eslint-plugin-prettier": "5.1.3", "eslint-plugin-promise": "6.1.1", "eslint-plugin-react": "7.33.2", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-storybook": "0.6.15", + "prettier": "3.1.1", + "prettier-plugin-tailwindcss": "0.5.11", "storybook": "7.5.3", "tailwind-merge": "2.0.0", "tsc-alias": "1.8.8", diff --git a/src/constants/color.ts b/src/constants/color.ts index 19ece57..efbdce2 100644 --- a/src/constants/color.ts +++ b/src/constants/color.ts @@ -1,27 +1,29 @@ export const THEME_COLOR = { - WHITE: "white", - BLACK: "black", - GRAY_09: "gray-09", - GRAY_08: "gray-08", - GRAY_07: "gray-07", - GRAY_06: "gray-06", - GRAY_05: "gray-05", - GRAY_04: "gray-04", - GRAY_03: "gray-03", - GRAY_02: "gray-02", - GRAY_01: "gray-01", - GRAY_00: "gray-00", - PRIMARY_06: "primary-06", - PRIMARY_05: "primary-05", - PRIMARY_04: "primary-04", - PRIMARY_03: "primary-03", - PRIMARY_02: "primary-02", - PRIMARY_01: "primary-01", - PRIMARY_00: "primary-00", - ERROR: "error", - WARNING: "warning", - SUCCESS: "success", - TRANSPARENT: "transparent", + WHITE: 'white', + BLACK: 'black', + GRAY_09: 'gray-09', + GRAY_08: 'gray-08', + GRAY_07: 'gray-07', + GRAY_06: 'gray-06', + GRAY_05: 'gray-05', + GRAY_04: 'gray-04', + GRAY_03: 'gray-03', + GRAY_02: 'gray-02', + GRAY_01: 'gray-01', + GRAY_00: 'gray-00', + PRIMARY_06: 'primary-06', + PRIMARY_05: 'primary-05', + PRIMARY_04: 'primary-04', + PRIMARY_03: 'primary-03', + PRIMARY_02: 'primary-02', + PRIMARY_01: 'primary-01', + PRIMARY_00: 'primary-00', + ERROR: 'error', + WARNING: 'warning', + SUCCESS: 'success', + TRANSPARENT: 'transparent', }; -export const ColorOptions = Object.keys(THEME_COLOR).map(color => THEME_COLOR[color as keyof typeof THEME_COLOR]); +export const ColorOptions = Object.keys(THEME_COLOR).map( + (color) => THEME_COLOR[color as keyof typeof THEME_COLOR], +); diff --git a/src/constants/index.ts b/src/constants/index.ts index 679ca25..6aae128 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,51 +1,51 @@ export const ColorOptions = [ - "white", - "black", - "gray-09", - "gray-08", - "gray-07", - "gray-06", - "gray-05", - "gray-04", - "gray-03", - "gray-02", - "gray-01", - "gray-00", - "primary-06", - "primary-05", - "primary-04", - "primary-03", - "primary-02", - "primary-01", - "primary-00", - "error", - "warning", - "success", - "transparent", + 'white', + 'black', + 'gray-09', + 'gray-08', + 'gray-07', + 'gray-06', + 'gray-05', + 'gray-04', + 'gray-03', + 'gray-02', + 'gray-01', + 'gray-00', + 'primary-06', + 'primary-05', + 'primary-04', + 'primary-03', + 'primary-02', + 'primary-01', + 'primary-00', + 'error', + 'warning', + 'success', + 'transparent', ]; export const TypographyOptions = [ - "head-01-regular", - "head-01-medium", - "head-01-bold", - "head-02-regular", - "head-02-medium", - "head-02-bold", - "subhead-01-regular", - "subhead-01-medium", - "subhead-01-bold", - "subhead-02-regular", - "subhead-02-medium", - "subhead-02-bold", - "body-01-regular", - "body-01-medium", - "body-01-bold", - "body-02-regular", - "body-02-medium", - "body-02-bold", - "body-03-regular", - "body-03-medium", - "body-03-bold", + 'head-01-regular', + 'head-01-medium', + 'head-01-bold', + 'head-02-regular', + 'head-02-medium', + 'head-02-bold', + 'subhead-01-regular', + 'subhead-01-medium', + 'subhead-01-bold', + 'subhead-02-regular', + 'subhead-02-medium', + 'subhead-02-bold', + 'body-01-regular', + 'body-01-medium', + 'body-01-bold', + 'body-02-regular', + 'body-02-medium', + 'body-02-bold', + 'body-03-regular', + 'body-03-medium', + 'body-03-bold', ]; export const Weekdays = { @@ -58,4 +58,4 @@ export const Weekdays = { SATURDAY: 6, }; -export const HOLIDAYS = [ Weekdays["SUNDAY"], Weekdays["SATURDAY"] ]; +export const HOLIDAYS = [Weekdays['SUNDAY'], Weekdays['SATURDAY']]; diff --git a/src/constants/theme.ts b/src/constants/theme.ts index 6c803f8..c353976 100644 --- a/src/constants/theme.ts +++ b/src/constants/theme.ts @@ -1,23 +1,25 @@ -import { ColorThemeType } from "@/types"; +import { ColorThemeType } from '@/types'; export const COLOR_THEME = { - PRIMARY: "primary", - ERROR: "error", - WARNING: "warning", - SUCCESS: "success", - SECONDARY: "secondary", - GRAY: "gray", - WHITE: "white", + PRIMARY: 'primary', + ERROR: 'error', + WARNING: 'warning', + SUCCESS: 'success', + SECONDARY: 'secondary', + GRAY: 'gray', + WHITE: 'white', } as const; export const COLOR_THEME_STYLES: Record = { - [COLOR_THEME["PRIMARY"]]: "bg-primary-03 text-white", - [COLOR_THEME["SECONDARY"]]: "text-primary-03 bg-primary-00", - [COLOR_THEME["ERROR"]]: "text-rose-600 bg-rose-300/20", - [COLOR_THEME["WARNING"]]: "text-amber-600 bg-amber-300/20", - [COLOR_THEME["SUCCESS"]]: "text-green-600 bg-green-300/20", - [COLOR_THEME["GRAY"]]: "text-gray-07 bg-gray-02", - [COLOR_THEME["WHITE"]]: "text-gray-06 bg-white border border-gray-03", + [COLOR_THEME['PRIMARY']]: 'bg-primary-03 text-white', + [COLOR_THEME['SECONDARY']]: 'text-primary-03 bg-primary-00', + [COLOR_THEME['ERROR']]: 'text-rose-600 bg-rose-300/20', + [COLOR_THEME['WARNING']]: 'text-amber-600 bg-amber-300/20', + [COLOR_THEME['SUCCESS']]: 'text-green-600 bg-green-300/20', + [COLOR_THEME['GRAY']]: 'text-gray-07 bg-gray-02', + [COLOR_THEME['WHITE']]: 'text-gray-06 bg-white border border-gray-03', }; -export const colorThemeOptions = Object.values(COLOR_THEME).map(theme => theme); +export const colorThemeOptions = Object.values(COLOR_THEME).map( + (theme) => theme, +); diff --git a/src/constants/typography.ts b/src/constants/typography.ts index 3a0cdb4..45364f8 100644 --- a/src/constants/typography.ts +++ b/src/constants/typography.ts @@ -1,25 +1,27 @@ export const THEME_TYPOGRAPHY = { - HEAD_01_REGULAR: "head-01-regular", - HEAD_01_MEDIUM: "head-01-medium", - HEAD_01_BOLD: "head-01-bold", - HEAD_02_REGULAR: "head-02-regular", - HEAD_02_MEDIUM: "head-02-medium", - HEAD_02_BOLD: "head-02-bold", - SUBHEAD_01_REGULAR: "subhead-01-regular", - SUBHEAD_01_MEDIUM: "subhead-01-medium", - SUBHEAD_01_BOLD: "subhead-01-bold", - SUBHEAD_02_REGULAR: "subhead-02-regular", - SUBHEAD_02_MEDIUM: "subhead-02-medium", - SUBHEAD_02_BOLD: "subhead-02-bold", - BODY_01_REGULAR: "body-01-regular", - BODY_01_MEDIUM: "body-01-medium", - BODY_01_BOLD: "body-01-bold", - BODY_02_REGULAR: "body-02-regular", - BODY_02_MEDIUM: "body-02-medium", - BODY_02_BOLD: "body-02-bold", - BODY_03_REGULAR: "body-03-regular", - BODY_03_MEDIUM: "body-03-medium", - BODY_03_BOLD: "body-03-bold", + HEAD_01_REGULAR: 'head-01-regular', + HEAD_01_MEDIUM: 'head-01-medium', + HEAD_01_BOLD: 'head-01-bold', + HEAD_02_REGULAR: 'head-02-regular', + HEAD_02_MEDIUM: 'head-02-medium', + HEAD_02_BOLD: 'head-02-bold', + SUBHEAD_01_REGULAR: 'subhead-01-regular', + SUBHEAD_01_MEDIUM: 'subhead-01-medium', + SUBHEAD_01_BOLD: 'subhead-01-bold', + SUBHEAD_02_REGULAR: 'subhead-02-regular', + SUBHEAD_02_MEDIUM: 'subhead-02-medium', + SUBHEAD_02_BOLD: 'subhead-02-bold', + BODY_01_REGULAR: 'body-01-regular', + BODY_01_MEDIUM: 'body-01-medium', + BODY_01_BOLD: 'body-01-bold', + BODY_02_REGULAR: 'body-02-regular', + BODY_02_MEDIUM: 'body-02-medium', + BODY_02_BOLD: 'body-02-bold', + BODY_03_REGULAR: 'body-03-regular', + BODY_03_MEDIUM: 'body-03-medium', + BODY_03_BOLD: 'body-03-bold', }; -export const TypographyOptions = Object.keys(THEME_TYPOGRAPHY).map(color => THEME_TYPOGRAPHY[color as keyof typeof THEME_TYPOGRAPHY]); +export const TypographyOptions = Object.keys(THEME_TYPOGRAPHY).map( + (color) => THEME_TYPOGRAPHY[color as keyof typeof THEME_TYPOGRAPHY], +); diff --git a/src/core/components/BottomSheet/BottomSheet.stories.tsx b/src/core/components/BottomSheet/BottomSheet.stories.tsx index 48fa7bb..90c9e92 100644 --- a/src/core/components/BottomSheet/BottomSheet.stories.tsx +++ b/src/core/components/BottomSheet/BottomSheet.stories.tsx @@ -1,29 +1,29 @@ -import { Meta } from "@storybook/react"; -import { useState } from "react"; +import { Meta } from '@storybook/react'; +import { useState } from 'react'; -import { default as BottomSheet } from "./index"; -import { BottomSheetProps } from "./types"; +import { default as BottomSheet } from './index'; +import { BottomSheetProps } from './types'; const meta = { - title: "core/BottomSheet", + title: 'core/BottomSheet', component: BottomSheet, parameters: { - layout: "fullscreen", + layout: 'fullscreen', }, argTypes: { target: { - control: "text", - defaultValue: "modal", - description: "BottomSheet Render Position Element id", + control: 'text', + defaultValue: 'modal', + description: 'BottomSheet Render Position Element id', }, isOpen: { - control: "boolean", + control: 'boolean', defaultValue: false, - description: "Open Modal", + description: 'Open Modal', }, onClose: { - action: "clicked", - description: "BottomSheet Close Function", + action: 'clicked', + description: 'BottomSheet Close Function', }, }, } satisfies Meta; @@ -31,25 +31,23 @@ const meta = { export default meta; export const Default = (props: BottomSheetProps) => { - const [ isOpen, setIsOpen ] = useState(false); + const [isOpen, setIsOpen] = useState(false); - const onToggle = () => setIsOpen(v => !v); + const onToggle = () => setIsOpen((v) => !v); return ( <> -
-
-
+
+
+
BottomSheet - +
diff --git a/src/core/components/BottomSheet/index.tsx b/src/core/components/BottomSheet/index.tsx index dd98f6c..5740816 100644 --- a/src/core/components/BottomSheet/index.tsx +++ b/src/core/components/BottomSheet/index.tsx @@ -1,53 +1,62 @@ -import { X } from "@phosphor-icons/react"; -import clsx from "clsx"; -import { PropsWithChildren, forwardRef } from "react"; +import { X } from '@phosphor-icons/react'; +import clsx from 'clsx'; +import { PropsWithChildren, forwardRef } from 'react'; -import { useBlockScrollingEffect } from "@/hooks/effects/useBlockScrollingEffect"; -import ModalBase from "../Modal/ModalBase"; -import { VARIANTS } from "../Modal/ModalBase/constants"; -import Section from "../Section"; -import { BottomSheetProps } from "./types"; +import { useBlockScrollingEffect } from '@/hooks/effects/useBlockScrollingEffect'; +import ModalBase from '../Modal/ModalBase'; +import { VARIANTS } from '../Modal/ModalBase/constants'; +import Section from '../Section'; +import { BottomSheetProps } from './types'; -const BottomSheet = forwardRef(( +const BottomSheet = forwardRef( + ( { onClose, children, isOpen, useCloseBtn = false, ...props - }: PropsWithChildren, - ref: React.Ref, + }: PropsWithChildren, + ref: React.Ref, ) => { - const { target, className, ...rest } = props; - const CloseIcon = ; + const { target, className, ...rest } = props; + const CloseIcon = ; - useBlockScrollingEffect(isOpen); + useBlockScrollingEffect(isOpen); - return ( - -
- {useCloseBtn ? ( -
- -
- ) : null} - {children} -
-
- ); -}); +
+ {useCloseBtn ? ( +
+ +
+ ) : null} + {children} +
+ + ); + }, +); export default BottomSheet; diff --git a/src/core/components/BottomSheet/types/index.ts b/src/core/components/BottomSheet/types/index.ts index 4d40c90..8fda8fb 100644 --- a/src/core/components/BottomSheet/types/index.ts +++ b/src/core/components/BottomSheet/types/index.ts @@ -1,8 +1,10 @@ -import { HTMLAttributes } from "react"; +import { HTMLAttributes } from 'react'; -import { ModalBaseProps } from "../../Modal/ModalBase/types"; +import { ModalBaseProps } from '../../Modal/ModalBase/types'; -export interface BottomSheetProps extends Pick, Omit, "title"> { +export interface BottomSheetProps + extends Pick, + Omit, 'title'> { useCloseBtn?: boolean; - onClose: ModalBaseProps["onClose"]; + onClose: ModalBaseProps['onClose']; } diff --git a/src/core/components/Button/Button/Button.stories.tsx b/src/core/components/Button/Button/Button.stories.tsx index b518700..de5b032 100644 --- a/src/core/components/Button/Button/Button.stories.tsx +++ b/src/core/components/Button/Button/Button.stories.tsx @@ -1,70 +1,72 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import { TypographyOptions } from "@/constants"; -import { ColorOptions } from "@/constants/color"; -import { GAP, ROUNDED, SIZE } from "../ButtonBase/constants"; -import Button from "./index"; -import { ButtonProps } from "./types"; +import { TypographyOptions } from '@/constants'; +import { ColorOptions } from '@/constants/color'; +import { GAP, ROUNDED, SIZE } from '../ButtonBase/constants'; +import Button from './index'; +import { ButtonProps } from './types'; const meta = { - title: "core/Button", + title: 'core/Button', component: Button, argTypes: { theme: { - control: "select", + control: 'select', options: TypographyOptions, - description: "Button Typography Theme", + description: 'Button Typography Theme', }, color: { - control: "select", + control: 'select', options: ColorOptions, - description: "Button Typography Color", + description: 'Button Typography Color', }, backgroundColor: { - control: "select", + control: 'select', options: ColorOptions, - defaultValue: "gray-08", - description: "Button Background Color", + defaultValue: 'gray-08', + description: 'Button Background Color', }, size: { - control: "select", - options: Object.keys(SIZE).map(size => SIZE[size as keyof typeof SIZE]), - description: "Button Size", + control: 'select', + options: Object.keys(SIZE).map((size) => SIZE[size as keyof typeof SIZE]), + description: 'Button Size', }, gap: { - control: "select", - options: Object.keys(GAP).map(gap => GAP[gap as keyof typeof GAP]), - description: "Button Size", + control: 'select', + options: Object.keys(GAP).map((gap) => GAP[gap as keyof typeof GAP]), + description: 'Button Size', }, rounded: { - control: "select", - options: Object.keys(ROUNDED).map(rounded => ROUNDED[rounded as keyof typeof ROUNDED]), - description: "Button Size", + control: 'select', + options: Object.keys(ROUNDED).map( + (rounded) => ROUNDED[rounded as keyof typeof ROUNDED], + ), + description: 'Button Size', }, borderColor: { - control: "select", - options: [ "gray-04", "gray-03", "gray-02", "gray-01" ], - description: "Button Size", + control: 'select', + options: ['gray-04', 'gray-03', 'gray-02', 'gray-01'], + description: 'Button Size', }, leftIcon: { - control: "text", - description: "Button Left Size", + control: 'text', + description: 'Button Left Size', }, content: { - control: "text", - description: "Button Text", + control: 'text', + description: 'Button Text', }, rightIcon: { - control: "text", - description: "Button Right Size", + control: 'text', + description: 'Button Right Size', }, hasUnderline: { - control: "boolean", - description: "Button With Underline", + control: 'boolean', + description: 'Button With Underline', }, disabled: { - control: "boolean", - description: "Button With disabled", + control: 'boolean', + description: 'Button With disabled', }, }, } satisfies Meta; @@ -76,13 +78,13 @@ export const Default = (props: ButtonProps) => { return ( - ); -}); + return ( + + ); + }, +); export default ButtonBase; diff --git a/src/core/components/Button/ButtonBase/types/index.ts b/src/core/components/Button/ButtonBase/types/index.ts index 2dab228..b7ee33e 100644 --- a/src/core/components/Button/ButtonBase/types/index.ts +++ b/src/core/components/Button/ButtonBase/types/index.ts @@ -1,19 +1,26 @@ -import { ButtonHTMLAttributes } from "react"; +import { ButtonHTMLAttributes } from 'react'; -import { ColorThemeType, ThemeColors, ThemeTypography } from "@/types"; -import { GAP, ROUNDED, SIZE } from "../constants"; +import { ColorThemeType, ThemeColors, ThemeTypography } from '@/types'; +import { GAP, ROUNDED, SIZE } from '../constants'; -export type ThemeType = Extract; +export type ThemeType = Extract< + ThemeTypography, + 'body-01-bold' | 'body-02-bold' | 'body-02-bold' +>; -export type SizeType = typeof SIZE[keyof typeof SIZE]; +export type SizeType = (typeof SIZE)[keyof typeof SIZE]; -export type RoundedType = typeof ROUNDED[keyof typeof ROUNDED]; +export type RoundedType = (typeof ROUNDED)[keyof typeof ROUNDED]; -export type BorderColorType = Extract; +export type BorderColorType = Extract< + ThemeColors, + 'gray-04' | 'gray-03' | 'gray-02' | 'gray-01' +>; -export type GapType = typeof GAP[keyof typeof GAP]; +export type GapType = (typeof GAP)[keyof typeof GAP]; -export interface ButtonBaseProps extends ButtonHTMLAttributes { +export interface ButtonBaseProps + extends ButtonHTMLAttributes { colorTheme?: ColorThemeType; theme?: ThemeType; color?: ThemeColors; diff --git a/src/core/components/Button/IconButton/IconButton.stories.tsx b/src/core/components/Button/IconButton/IconButton.stories.tsx index ae4b9e4..d0bea93 100644 --- a/src/core/components/Button/IconButton/IconButton.stories.tsx +++ b/src/core/components/Button/IconButton/IconButton.stories.tsx @@ -1,54 +1,56 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import { TypographyOptions } from "@/constants"; -import { ColorOptions } from "@/constants/color"; -import { ROUNDED, SIZE } from "../ButtonBase/constants"; -import { default as IconButton } from "./index"; -import { IconButtonProps } from "./types"; +import { TypographyOptions } from '@/constants'; +import { ColorOptions } from '@/constants/color'; +import { ROUNDED, SIZE } from '../ButtonBase/constants'; +import { default as IconButton } from './index'; +import { IconButtonProps } from './types'; const meta = { - title: "core/Button/IconButton", + title: 'core/Button/IconButton', component: IconButton, argTypes: { theme: { - control: "select", + control: 'select', options: TypographyOptions, - description: "Button Typography Theme", + description: 'Button Typography Theme', }, color: { - control: "select", + control: 'select', options: ColorOptions, - description: "Button Typography Color", + description: 'Button Typography Color', }, backgroundColor: { - control: "select", + control: 'select', options: ColorOptions, - defaultValue: "gray-08", - description: "Button Background Color", + defaultValue: 'gray-08', + description: 'Button Background Color', }, size: { - control: "select", - options: Object.keys(SIZE).map(size => SIZE[size as keyof typeof SIZE]), - description: "Button Size", + control: 'select', + options: Object.keys(SIZE).map((size) => SIZE[size as keyof typeof SIZE]), + description: 'Button Size', }, rounded: { - control: "select", - options: Object.keys(ROUNDED).map(rounded => ROUNDED[rounded as keyof typeof ROUNDED]), - description: "Button Size", + control: 'select', + options: Object.keys(ROUNDED).map( + (rounded) => ROUNDED[rounded as keyof typeof ROUNDED], + ), + description: 'Button Size', }, borderColor: { - control: "select", - options: [ "gray-04", "gray-03", "gray-02", "gray-01" ], - description: "Button Size", + control: 'select', + options: ['gray-04', 'gray-03', 'gray-02', 'gray-01'], + description: 'Button Size', }, content: { - control: "text", - description: "Button Text", + control: 'text', + description: 'Button Text', }, disabled: { - control: "boolean", - description: "Button With disabled", + control: 'boolean', + description: 'Button With disabled', }, }, } satisfies Meta; @@ -60,12 +62,12 @@ export const Default = (props: IconButtonProps) => { return ( ); }; diff --git a/src/core/components/Button/IconButton/constants/index.ts b/src/core/components/Button/IconButton/constants/index.ts index ecfd313..d68d59e 100644 --- a/src/core/components/Button/IconButton/constants/index.ts +++ b/src/core/components/Button/IconButton/constants/index.ts @@ -1,14 +1,14 @@ -import { SIZE } from "../../ButtonBase/constants"; -import { SizeType } from "../../ButtonBase/types"; +import { SIZE } from '../../ButtonBase/constants'; +import { SizeType } from '../../ButtonBase/types'; export const BUTTON_SIZE: Record = { - [SIZE.SIZE_60]: "w-[3.75rem]", - [SIZE.SIZE_56]: "w-14", - [SIZE.SIZE_52]: "w-[3.25rem]", - [SIZE.SIZE_49]: "w-[3.0625rem]", - [SIZE.SIZE_48]: "w-12", - [SIZE.SIZE_40]: "w-10", - [SIZE.SIZE_29]: "w-[1.8125rem]", - [SIZE.SIZE_24]: "w-6", - [SIZE.SIZE_20]: "w-5", + [SIZE.SIZE_60]: 'w-[3.75rem]', + [SIZE.SIZE_56]: 'w-14', + [SIZE.SIZE_52]: 'w-[3.25rem]', + [SIZE.SIZE_49]: 'w-[3.0625rem]', + [SIZE.SIZE_48]: 'w-12', + [SIZE.SIZE_40]: 'w-10', + [SIZE.SIZE_29]: 'w-[1.8125rem]', + [SIZE.SIZE_24]: 'w-6', + [SIZE.SIZE_20]: 'w-5', }; diff --git a/src/core/components/Button/IconButton/index.tsx b/src/core/components/Button/IconButton/index.tsx index 0864b95..7d85572 100644 --- a/src/core/components/Button/IconButton/index.tsx +++ b/src/core/components/Button/IconButton/index.tsx @@ -1,24 +1,29 @@ -import clsx from "clsx"; -import { forwardRef } from "react"; -import ButtonBase from "../ButtonBase"; -import { ROUNDED } from "../ButtonBase/constants"; -import { BUTTON_SIZE } from "./constants"; -import { IconButtonProps } from "./types"; +import clsx from 'clsx'; +import { forwardRef } from 'react'; +import ButtonBase from '../ButtonBase'; +import { ROUNDED } from '../ButtonBase/constants'; +import { BUTTON_SIZE } from './constants'; +import { IconButtonProps } from './types'; -const IconButton = forwardRef(({ - icon, - isCircle = false, - ...props - }: IconButtonProps, - ref: React.Ref, +const IconButton = forwardRef( + ( + { icon, isCircle = false, ...props }: IconButtonProps, + ref: React.Ref, ) => { - const { rounded, size, className, ...rest } = props; + const { rounded, size, className, ...rest } = props; - return ( - - {icon} - - ); -}); + return ( + + {icon} + + ); + }, +); export default IconButton; diff --git a/src/core/components/Button/IconButton/types/index.ts b/src/core/components/Button/IconButton/types/index.ts index 07ec5ce..23a1995 100644 --- a/src/core/components/Button/IconButton/types/index.ts +++ b/src/core/components/Button/IconButton/types/index.ts @@ -1,6 +1,7 @@ -import { ButtonBaseProps } from "../../ButtonBase/types"; +import { ButtonBaseProps } from '../../ButtonBase/types'; -export interface IconButtonProps extends Omit { +export interface IconButtonProps + extends Omit { icon: React.ReactNode; isCircle?: boolean; } diff --git a/src/core/components/Calendar/BasicCalendar/BasicCalendar.stories.tsx b/src/core/components/Calendar/BasicCalendar/BasicCalendar.stories.tsx index 332e9f2..63bf6bf 100644 --- a/src/core/components/Calendar/BasicCalendar/BasicCalendar.stories.tsx +++ b/src/core/components/Calendar/BasicCalendar/BasicCalendar.stories.tsx @@ -1,18 +1,16 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import BasicCalendar from "@/core/components/Calendar/BasicCalendar"; +import BasicCalendar from '@/core/components/Calendar/BasicCalendar'; const meta = { - title: "core/Calendar/BasicCalendar", + title: 'core/Calendar/BasicCalendar', component: BasicCalendar, } satisfies Meta; export default meta; -export const DefaultCalendar = () => -
- +export const DefaultCalendar = () => ( +
+
-; +); diff --git a/src/core/components/Calendar/BasicCalendar/index.tsx b/src/core/components/Calendar/BasicCalendar/index.tsx index 7f671ad..30bb3b7 100644 --- a/src/core/components/Calendar/BasicCalendar/index.tsx +++ b/src/core/components/Calendar/BasicCalendar/index.tsx @@ -1,48 +1,58 @@ -import clsx from "clsx"; -import "dayjs/locale/ko"; +import clsx from 'clsx'; +import 'dayjs/locale/ko'; -import { useCalendar } from "@/core/components/Calendar/common/hooks/useCalendar"; -import { CalendarWeekDayComponent } from "@/core/components/Calendar/common/subs/CalendarWeekdayComponent"; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; -import Typography from "@/core/components/Typography"; -import { BasicCalendarProps } from "./types"; +import { useCalendar } from '@/core/components/Calendar/common/hooks/useCalendar'; +import { CalendarWeekDayComponent } from '@/core/components/Calendar/common/subs/CalendarWeekdayComponent'; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; +import Typography from '@/core/components/Typography'; +import { BasicCalendarProps } from './types'; -const BasicCalendar = ({ - dottedDates, -}: BasicCalendarProps) => { +const BasicCalendar = ({ dottedDates }: BasicCalendarProps) => { const { models: commonModels } = useCalendar(); - return( -
+ return ( +
-
- { commonModels.calendarDates.map((calendarWeekDates: CalendarDateDto[], index) => ( -
- { calendarWeekDates.map((calendarDate: CalendarDateDto, index: number) => ( -
-
-
- +
+ {commonModels.calendarDates.map( + (calendarWeekDates: CalendarDateDto[], index) => ( +
+ {calendarWeekDates.map( + (calendarDate: CalendarDateDto, index: number) => ( +
+
+
+ +
+
-
-
- )) - } -
- ))} + ), + )} +
+ ), + )}
); diff --git a/src/core/components/Calendar/DatePickerCalendar/DatePickerCalendar.stories.tsx b/src/core/components/Calendar/DatePickerCalendar/DatePickerCalendar.stories.tsx index 6feb34f..d9a0a5f 100644 --- a/src/core/components/Calendar/DatePickerCalendar/DatePickerCalendar.stories.tsx +++ b/src/core/components/Calendar/DatePickerCalendar/DatePickerCalendar.stories.tsx @@ -1,21 +1,21 @@ -import { Meta } from "@storybook/react"; -import { useState } from "react"; +import { Meta } from '@storybook/react'; +import { useState } from 'react'; -import DatePickerCalendar from "@/core/components/Calendar/DatePickerCalendar"; -import { DATE_PICKER_TYPE } from "./constants"; -import { PeriodDates } from "./types/DatePickerCalendarProps"; +import DatePickerCalendar from '@/core/components/Calendar/DatePickerCalendar'; +import { DATE_PICKER_TYPE } from './constants'; +import { PeriodDates } from './types/DatePickerCalendarProps'; const meta = { - title: "core/Calendar/DatePickerCalendar", + title: 'core/Calendar/DatePickerCalendar', component: DatePickerCalendar, } satisfies Meta; export default meta; export const SingleDatePicker = () => { - const [ periodDates, setPeriodDates ] = useState({ - startDate: "", - endDate: "", + const [periodDates, setPeriodDates] = useState({ + startDate: '', + endDate: '', }); const onDateClick = (date: PeriodDates) => { @@ -23,23 +23,23 @@ export const SingleDatePicker = () => { }; return ( -
+
); }; export const PeriodDatesPicker = () => { - const [ periodDates, setPeriodDates ] = useState({ - startDate: "2024-01-24", - endDate: "2024-01-26", + const [periodDates, setPeriodDates] = useState({ + startDate: '2024-01-24', + endDate: '2024-01-26', }); const onDateClick = (date: PeriodDates) => { @@ -47,14 +47,13 @@ export const PeriodDatesPicker = () => { }; return ( -
+
); }; - diff --git a/src/core/components/Calendar/DatePickerCalendar/constants/index.ts b/src/core/components/Calendar/DatePickerCalendar/constants/index.ts index 0a53cd4..2167d79 100644 --- a/src/core/components/Calendar/DatePickerCalendar/constants/index.ts +++ b/src/core/components/Calendar/DatePickerCalendar/constants/index.ts @@ -1,4 +1,4 @@ export const DATE_PICKER_TYPE = { - SINGLE: "single", - PERIOD: "period", + SINGLE: 'single', + PERIOD: 'period', } as const; diff --git a/src/core/components/Calendar/DatePickerCalendar/index.tsx b/src/core/components/Calendar/DatePickerCalendar/index.tsx index 27b1754..d5ee5fb 100644 --- a/src/core/components/Calendar/DatePickerCalendar/index.tsx +++ b/src/core/components/Calendar/DatePickerCalendar/index.tsx @@ -1,87 +1,110 @@ -import clsx from "clsx"; -import dayjs from "dayjs"; -import { useCallback, useEffect, useState } from "react"; - -import { useCalendar } from "@/core/components/Calendar/common/hooks/useCalendar"; -import { CalendarHeader } from "@/core/components/Calendar/common/subs/CalendarHeader"; -import { CalendarWeekDayComponent } from "@/core/components/Calendar/common/subs/CalendarWeekdayComponent"; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; -import { DATE_PICKER_TYPE } from "./constants"; -import { CalendarComponentDaySubText } from "./subs/CalendarComponentDaySubText"; -import { CalendarComponentDayText } from "./subs/CalendarComponentDayText"; -import { DatePickerCalendarProps, DatePickerType, PeriodDates } from "./types/DatePickerCalendarProps"; +import clsx from 'clsx'; +import dayjs from 'dayjs'; +import { useCallback, useEffect, useState } from 'react'; + +import { useCalendar } from '@/core/components/Calendar/common/hooks/useCalendar'; +import { CalendarHeader } from '@/core/components/Calendar/common/subs/CalendarHeader'; +import { CalendarWeekDayComponent } from '@/core/components/Calendar/common/subs/CalendarWeekdayComponent'; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; +import { DATE_PICKER_TYPE } from './constants'; +import { CalendarComponentDaySubText } from './subs/CalendarComponentDaySubText'; +import { CalendarComponentDayText } from './subs/CalendarComponentDayText'; +import { + DatePickerCalendarProps, + DatePickerType, + PeriodDates, +} from './types/DatePickerCalendarProps'; export interface UseDatePickerCalendarResponse { models: { periodDates: PeriodDates; periodDateArray: string[]; - }, + }; operations: { setCalendarPeriodDates: (periodDates: PeriodDates) => void; setPeriodDates: React.Dispatch>; - onDateClick: (variants: DatePickerType, afterAllDate: boolean, calendarDate: CalendarDateDto) => void; - } + onDateClick: ( + variants: DatePickerType, + afterAllDate: boolean, + calendarDate: CalendarDateDto, + ) => void; + }; } -export const useDatePickerCalendar = ({ isFixStartDate }: Pick): UseDatePickerCalendarResponse => { - const [ periodDates, setPeriodDates ] = useState({ - startDate: "", - endDate: "", +export const useDatePickerCalendar = ({ + isFixStartDate, +}: Pick< + DatePickerCalendarProps, + 'isFixStartDate' +>): UseDatePickerCalendarResponse => { + const [periodDates, setPeriodDates] = useState({ + startDate: '', + endDate: '', }); - const [ periodDateArray, setPeriodDateArray ] = useState([]); + const [periodDateArray, setPeriodDateArray] = useState([]); - const onDateClick = useCallback((variants: DatePickerType, afterAllDate: boolean, calendarDate: CalendarDateDto) => { - const currentDate = calendarDate.dayjs.format("YYYY-MM-DD"); - const newPeriodDates = periodDates; + const onDateClick = useCallback( + ( + variants: DatePickerType, + afterAllDate: boolean, + calendarDate: CalendarDateDto, + ) => { + const currentDate = calendarDate.dayjs.format('YYYY-MM-DD'); + const newPeriodDates = periodDates; - if ((periodDates.startDate && periodDates.endDate) || afterAllDate) { - if(!isFixStartDate) { - newPeriodDates.startDate = currentDate; - newPeriodDates.endDate = ""; + if ((periodDates.startDate && periodDates.endDate) || afterAllDate) { + if (!isFixStartDate) { + newPeriodDates.startDate = currentDate; + newPeriodDates.endDate = ''; - return; - } else { - newPeriodDates.startDate = periodDates["startDate"]; - newPeriodDates.endDate = currentDate; + return; + } else { + newPeriodDates.startDate = periodDates['startDate']; + newPeriodDates.endDate = currentDate; - return; + return; + } } - } - - if (variants === DATE_PICKER_TYPE["PERIOD"] && periodDates.startDate) { - if(isFixStartDate) { - newPeriodDates.endDate = currentDate; - return; - } else { - if (!dayjs(periodDates.startDate).isAfter(calendarDate.dayjs)) { + if (variants === DATE_PICKER_TYPE['PERIOD'] && periodDates.startDate) { + if (isFixStartDate) { newPeriodDates.endDate = currentDate; + + return; } else { - newPeriodDates.startDate = currentDate; - newPeriodDates.endDate = ""; + if (!dayjs(periodDates.startDate).isAfter(calendarDate.dayjs)) { + newPeriodDates.endDate = currentDate; + } else { + newPeriodDates.startDate = currentDate; + newPeriodDates.endDate = ''; + } } + } else { + newPeriodDates.startDate = currentDate; + newPeriodDates.endDate = ''; } - } else { - newPeriodDates.startDate = currentDate; - newPeriodDates.endDate = ""; - } - }, [periodDates]); + }, + [periodDates], + ); - const setCalendarPeriodDates = useCallback((periodDates: PeriodDates) => { - if(!periodDates.endDate || !periodDates.startDate) { - setPeriodDateArray([]); - return; - } - const newPeriodDateArray: string[] = []; - const startDate: dayjs.Dayjs = dayjs(periodDates.startDate); - const endDate: dayjs.Dayjs = dayjs(periodDates.endDate); - const diffDate: number = endDate.diff(startDate, "day"); + const setCalendarPeriodDates = useCallback( + (periodDates: PeriodDates) => { + if (!periodDates.endDate || !periodDates.startDate) { + setPeriodDateArray([]); + return; + } + const newPeriodDateArray: string[] = []; + const startDate: dayjs.Dayjs = dayjs(periodDates.startDate); + const endDate: dayjs.Dayjs = dayjs(periodDates.endDate); + const diffDate: number = endDate.diff(startDate, 'day'); - for (let i = 0; i <= diffDate; i++) { - newPeriodDateArray.push(startDate.add(i, "day").format("YYYY-MM-DD")); - } - setPeriodDateArray(newPeriodDateArray); - }, [ periodDates, setPeriodDateArray ]); + for (let i = 0; i <= diffDate; i++) { + newPeriodDateArray.push(startDate.add(i, 'day').format('YYYY-MM-DD')); + } + setPeriodDateArray(newPeriodDateArray); + }, + [periodDates, setPeriodDateArray], + ); return { models: { @@ -97,8 +120,8 @@ export const useDatePickerCalendar = ({ isFixStartDate }: Pick { - const { date: exceptionDate = "", label: exceptionLabel = "" } = exceptionDay ?? {}; - const { models: commonModels, operations: commonOperations } = useCalendar(initialDate ? dayjs(initialDate): dayjs()); + const { date: exceptionDate = '', label: exceptionLabel = '' } = + exceptionDay ?? {}; + const { models: commonModels, operations: commonOperations } = useCalendar( + initialDate ? dayjs(initialDate) : dayjs(), + ); const { models, operations } = useDatePickerCalendar({ isFixStartDate }); useEffect(() => { @@ -121,11 +147,13 @@ const DatePickerCalendar = ({ return; } - const calenderDatesEndWeek = commonModels.calendarDates[commonModels.calendarDates.length - 1]; - const calenderDatesEndWeekEndDay = calenderDatesEndWeek[calenderDatesEndWeek.length - 1]; + const calenderDatesEndWeek = + commonModels.calendarDates[commonModels.calendarDates.length - 1]; + const calenderDatesEndWeekEndDay = + calenderDatesEndWeek[calenderDatesEndWeek.length - 1]; const renderDates: PeriodDates = { - startDate: commonModels.calendarDates[0][0]?.dayjs.format("YYYY-MM-DD"), - endDate: calenderDatesEndWeekEndDay?.dayjs.format("YYYY-MM-DD"), + startDate: commonModels.calendarDates[0][0]?.dayjs.format('YYYY-MM-DD'), + endDate: calenderDatesEndWeekEndDay?.dayjs.format('YYYY-MM-DD'), }; onRender?.(renderDates); @@ -143,9 +171,9 @@ const DatePickerCalendar = ({ useEffect(() => { if (afterAllDate) { const newPeriodDates = models.periodDates; - newPeriodDates.endDate = ""; + newPeriodDates.endDate = ''; operations.setPeriodDates({ ...newPeriodDates }); - operations.setCalendarPeriodDates({ startDate: "", endDate: "" }); + operations.setCalendarPeriodDates({ startDate: '', endDate: '' }); onDateClick(models.periodDates, true); } }, [afterAllDate]); @@ -155,69 +183,101 @@ const DatePickerCalendar = ({ operations.setCalendarPeriodDates(periodDates); }, [periodDates]); - const isCutoffDateValidation = ({ cutoffDate, cutoffAfterDate, calendarDate }: Pick & { calendarDate: string }) => { - if(!cutoffDate && !cutoffAfterDate) return false; + const isCutoffDateValidation = ({ + cutoffDate, + cutoffAfterDate, + calendarDate, + }: Pick & { + calendarDate: string; + }) => { + if (!cutoffDate && !cutoffAfterDate) return false; - return !!cutoffDate && dayjs(calendarDate).isBefore(cutoffDate) || !!cutoffAfterDate && dayjs(calendarDate).isAfter(cutoffAfterDate); + return ( + (!!cutoffDate && dayjs(calendarDate).isBefore(cutoffDate)) || + (!!cutoffAfterDate && dayjs(calendarDate).isAfter(cutoffAfterDate)) + ); }; return ( -
+
- -
- {commonModels.calendarDates.map((calendarWeekDates: CalendarDateDto[], index: number) => ( -
- {calendarWeekDates.map((calendarDate: CalendarDateDto, index: number) => { - const disabled = (!useHoliday && calendarDate.isHoliday) || !calendarDate.isThisMonth || disabledDates?.includes(calendarDate.dayjs.format("YYYY-MM-DD")) || isCutoffDateValidation({ cutoffDate, cutoffAfterDate, calendarDate: calendarDate.dayjs.format("YYYY-MM-DD") }); - const currentDate = calendarDate.dayjs.format("YYYY-MM-DD"); - const isExceptionDate = exceptionDay ? exceptionDate === currentDate : false; - - return ( -
-
- -
- ); - })} -
- ))} + ); + }, + )} +
+ ), + )}
); diff --git a/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDaySubText.tsx b/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDaySubText.tsx index 0e1af8f..3345682 100644 --- a/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDaySubText.tsx +++ b/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDaySubText.tsx @@ -1,8 +1,9 @@ -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; -import Typography from "@/core/components/Typography"; -import { DatePickerCalendarProps } from "../types/DatePickerCalendarProps"; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; +import Typography from '@/core/components/Typography'; +import { DatePickerCalendarProps } from '../types/DatePickerCalendarProps'; -interface CalendarComponentDaySubTextProps extends Pick { +interface CalendarComponentDaySubTextProps + extends Pick { calendarDate: CalendarDateDto; isExceptionDate: boolean; exceptionDateLabel?: string; @@ -15,39 +16,42 @@ export const CalendarComponentDaySubText = ({ exceptionDateLabel, label, }: CalendarComponentDaySubTextProps) => { - const currentDate = calendarDate.dayjs.format("YYYY-MM-DD"); + const currentDate = calendarDate.dayjs.format('YYYY-MM-DD'); const isPeriod = periodDates.startDate && periodDates.endDate; const isStartDate = isPeriod && periodDates.startDate === currentDate; const isEndDate = isPeriod && periodDates.endDate === currentDate; - const singleSelectedDate = (periodDates.startDate && !periodDates.endDate) && currentDate === periodDates.startDate; + const singleSelectedDate = + periodDates.startDate && + !periodDates.endDate && + currentDate === periodDates.startDate; const isActiveDate = isStartDate || isEndDate || singleSelectedDate; const dayLabel = () => { - if(isExceptionDate) return exceptionDateLabel; + if (isExceptionDate) return exceptionDateLabel; const hasCustomStartLabel = label && label[0]; const hasCustomEndLabel = label && label[1]; - const startLabel = hasCustomStartLabel ? label[0] : "시작일"; - const endLabel = hasCustomEndLabel ? label[1] : "종료일"; + const startLabel = hasCustomStartLabel ? label[0] : '시작일'; + const endLabel = hasCustomEndLabel ? label[1] : '종료일'; - if(isStartDate || singleSelectedDate) return startLabel; + if (isStartDate || singleSelectedDate) return startLabel; - if(isEndDate) return endLabel; + if (isEndDate) return endLabel; - if(calendarDate.isToday) { - const todayLabel = isEndDate ? endLabel : "오늘"; + if (calendarDate.isToday) { + const todayLabel = isEndDate ? endLabel : '오늘'; return todayLabel; } - return ""; -}; + return ''; + }; return ( ); }; diff --git a/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDayText.tsx b/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDayText.tsx index 451c978..8e0f0de 100644 --- a/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDayText.tsx +++ b/src/core/components/Calendar/DatePickerCalendar/subs/CalendarComponentDayText.tsx @@ -1,7 +1,7 @@ -import clsx from "clsx"; +import clsx from 'clsx'; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; -import { PeriodDates } from "../types/DatePickerCalendarProps"; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; +import { PeriodDates } from '../types/DatePickerCalendarProps'; interface CalendarComponentDayTextProps { calendarDate: CalendarDateDto; @@ -20,36 +20,53 @@ export const CalendarComponentDayText = ({ isExceptionDate, disabled, }: CalendarComponentDayTextProps) => { - const currentDate = calendarDate.dayjs.format("YYYY-MM-DD"); + const currentDate = calendarDate.dayjs.format('YYYY-MM-DD'); const isPeriod = periodDates.startDate && periodDates.endDate; - const isStartDate = isPeriod && (periodDates.startDate !== periodDates.endDate) && periodDates.startDate === currentDate; - const isEndDate = isPeriod && (periodDates.startDate !== periodDates.endDate) && periodDates.endDate === currentDate; - const singleSelectedDate = ((periodDates.startDate && !periodDates.endDate) || (periodDates.startDate === periodDates.endDate)) && currentDate === periodDates.startDate; + const isStartDate = + isPeriod && + periodDates.startDate !== periodDates.endDate && + periodDates.startDate === currentDate; + const isEndDate = + isPeriod && + periodDates.startDate !== periodDates.endDate && + periodDates.endDate === currentDate; + const singleSelectedDate = + ((periodDates.startDate && !periodDates.endDate) || + periodDates.startDate === periodDates.endDate) && + currentDate === periodDates.startDate; const isActiveDate = isStartDate || isEndDate || singleSelectedDate; const isMarkedDate = isActiveDate || calendarDate.isToday || isExceptionDate; - const isMarkedPeriod = ((periodDateArray?.slice(1, -1).includes(currentDate)) || (afterAllDate && calendarDate.dayjs.isAfter(periodDates.startDate))); + const isMarkedPeriod = + periodDateArray?.slice(1, -1).includes(currentDate) || + (afterAllDate && calendarDate.dayjs.isAfter(periodDates.startDate)); return (
+ className={clsx('relative flex flex-col items-center justify-between', { + "before:absolute before:z-20 before:block before:h-full before:w-1/2 before:translate-x-1/2 before:bg-primary-00 before:content-['']": + isStartDate || isEndDate || (afterAllDate && singleSelectedDate), + 'before:translate-x-1/2': isStartDate, + 'before:translate-x-[-50%]': isEndDate, + })} + >
{calendarDate.dayjs.date()} diff --git a/src/core/components/Calendar/DatePickerCalendar/types/DatePickerCalendarProps.ts b/src/core/components/Calendar/DatePickerCalendar/types/DatePickerCalendarProps.ts index e6926d1..1643fdc 100644 --- a/src/core/components/Calendar/DatePickerCalendar/types/DatePickerCalendarProps.ts +++ b/src/core/components/Calendar/DatePickerCalendar/types/DatePickerCalendarProps.ts @@ -1,19 +1,21 @@ -import { CalendarHeaderProps } from "../../common/types/CalendarHeader"; -import { DATE_PICKER_TYPE } from "../constants"; +import { CalendarHeaderProps } from '../../common/types/CalendarHeader'; +import { DATE_PICKER_TYPE } from '../constants'; -export type DatePickerType = typeof DATE_PICKER_TYPE[keyof typeof DATE_PICKER_TYPE]; +export type DatePickerType = + (typeof DATE_PICKER_TYPE)[keyof typeof DATE_PICKER_TYPE]; export interface PeriodDates { startDate: string; endDate: string; } -export interface DatePickerCalendarProps extends Pick{ +export interface DatePickerCalendarProps + extends Pick { variants: DatePickerType; exceptionDay?: { - date: string, - label: string, - } + date: string; + label: string; + }; isFixStartDate?: boolean; initialDate?: string; periodDates: PeriodDates; diff --git a/src/core/components/Calendar/ScheduleCalendar/ScheduleCalendar.stories.tsx b/src/core/components/Calendar/ScheduleCalendar/ScheduleCalendar.stories.tsx index 07ad2f8..bab5f56 100644 --- a/src/core/components/Calendar/ScheduleCalendar/ScheduleCalendar.stories.tsx +++ b/src/core/components/Calendar/ScheduleCalendar/ScheduleCalendar.stories.tsx @@ -1,18 +1,18 @@ -import { Meta } from "@storybook/react"; -import { useEffect, useState } from "react"; +import { Meta } from '@storybook/react'; +import { useEffect, useState } from 'react'; -import ScheduleCalendar from "@/core/components/Calendar/ScheduleCalendar"; -import dayjs from "dayjs"; -import { PeriodDates } from "../DatePickerCalendar/types/DatePickerCalendarProps"; +import ScheduleCalendar from '@/core/components/Calendar/ScheduleCalendar'; +import dayjs from 'dayjs'; +import { PeriodDates } from '../DatePickerCalendar/types/DatePickerCalendarProps'; const meta = { - title: "core/Calendar/ScheduleCalendar", + title: 'core/Calendar/ScheduleCalendar', component: ScheduleCalendar, } satisfies Meta; export default meta; export const Default = () => { - const [ selectedDate, setSelectedDate ] = useState(""); + const [selectedDate, setSelectedDate] = useState(''); const onDateClick = (date: string) => { setSelectedDate(date); @@ -27,67 +27,67 @@ export const Default = () => { }, [selectedDate]); return ( -
+
); diff --git a/src/core/components/Calendar/ScheduleCalendar/index.tsx b/src/core/components/Calendar/ScheduleCalendar/index.tsx index 279c192..2d641c0 100644 --- a/src/core/components/Calendar/ScheduleCalendar/index.tsx +++ b/src/core/components/Calendar/ScheduleCalendar/index.tsx @@ -1,12 +1,12 @@ -import dayjs from "dayjs"; -import { useEffect } from "react"; +import dayjs from 'dayjs'; +import { useEffect } from 'react'; -import { CalendarDayComponent } from "@/core/components/Calendar/ScheduleCalendar/subs/CalendarDayComponent"; -import { CalendarComponentProps } from "@/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps"; -import { useCalendar } from "@/core/components/Calendar/common/hooks/useCalendar"; -import { CalendarHeader } from "@/core/components/Calendar/common/subs/CalendarHeader"; -import { CalendarWeekDayComponent } from "@/core/components/Calendar/common/subs/CalendarWeekdayComponent"; -import { PeriodDates } from "../DatePickerCalendar/types/DatePickerCalendarProps"; +import { CalendarDayComponent } from '@/core/components/Calendar/ScheduleCalendar/subs/CalendarDayComponent'; +import { CalendarComponentProps } from '@/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps'; +import { useCalendar } from '@/core/components/Calendar/common/hooks/useCalendar'; +import { CalendarHeader } from '@/core/components/Calendar/common/subs/CalendarHeader'; +import { CalendarWeekDayComponent } from '@/core/components/Calendar/common/subs/CalendarWeekdayComponent'; +import { PeriodDates } from '../DatePickerCalendar/types/DatePickerCalendarProps'; const ScheduleCalendar = ({ initialDate, @@ -16,38 +16,42 @@ const ScheduleCalendar = ({ onRender, monthButtonStatus, }: CalendarComponentProps) => { - const { models, operations } = useCalendar(initialDate ? dayjs(initialDate * 1000) : dayjs()); + const { models, operations } = useCalendar( + initialDate ? dayjs(initialDate * 1000) : dayjs(), + ); useEffect(() => { if (models.calendarDates.length <= 0) { return; } - const calenderDatesEndWeek = models.calendarDates[models.calendarDates.length - 1]; - const calenderDatesEndWeekEndDay = calenderDatesEndWeek[calenderDatesEndWeek.length - 1]; + const calenderDatesEndWeek = + models.calendarDates[models.calendarDates.length - 1]; + const calenderDatesEndWeekEndDay = + calenderDatesEndWeek[calenderDatesEndWeek.length - 1]; const renderDates: PeriodDates = { - startDate: models.calendarDates[0][0]?.dayjs.format("YYYY-MM-DD"), - endDate: calenderDatesEndWeekEndDay?.dayjs.format("YYYY-MM-DD"), + startDate: models.calendarDates[0][0]?.dayjs.format('YYYY-MM-DD'), + endDate: calenderDatesEndWeekEndDay?.dayjs.format('YYYY-MM-DD'), }; onRender?.(renderDates); }, [models.calendarDates]); return ( -
+
- -
+ +
diff --git a/src/core/components/Calendar/ScheduleCalendar/subs/CalendarDayComponent.tsx b/src/core/components/Calendar/ScheduleCalendar/subs/CalendarDayComponent.tsx index c114d03..e2b8d64 100644 --- a/src/core/components/Calendar/ScheduleCalendar/subs/CalendarDayComponent.tsx +++ b/src/core/components/Calendar/ScheduleCalendar/subs/CalendarDayComponent.tsx @@ -1,10 +1,11 @@ -import clsx from "clsx"; +import clsx from 'clsx'; -import { CalendarComponentProps } from "@/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps"; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; -import Typography from "@/core/components/Typography"; +import { CalendarComponentProps } from '@/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps'; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; +import Typography from '@/core/components/Typography'; -interface CalendarDayComponentProps extends Omit { +interface CalendarDayComponentProps + extends Omit { calendarDates: CalendarDateDto[][]; } @@ -14,87 +15,122 @@ export const CalendarDayComponent = ({ calendarDates, onDateClick, }: CalendarDayComponentProps) => { - return( + return ( <> {calendarDates.map((calendarWeekDates: CalendarDateDto[], index) => (
- {calendarWeekDates.map((calendarDate: CalendarDateDto, index: number) => { - const currentDate: string = calendarDate.dayjs.format("YYYY-MM-DD"); - const currentSchedule = schedulesData && Object.keys(schedulesData).find(date => date === currentDate); - let quantity = defaultQuantity; + {calendarWeekDates.map( + (calendarDate: CalendarDateDto, index: number) => { + const currentDate: string = + calendarDate.dayjs.format('YYYY-MM-DD'); + const currentSchedule = + schedulesData && + Object.keys(schedulesData).find((date) => date === currentDate); + let quantity = defaultQuantity; - if(currentSchedule && schedulesData![currentSchedule].quantity) { - quantity = schedulesData![currentSchedule].quantity; - } + if (currentSchedule && schedulesData![currentSchedule].quantity) { + quantity = schedulesData![currentSchedule].quantity; + } - return ( - - ); - })} + {schedulesData && + Object.keys(schedulesData).map( + (markedDate) => + markedDate === + calendarDate.dayjs.format('YYYY-MM-DD') && ( +
+ {schedulesData[markedDate].markedDates + ?.slice(0, 3) + .map((markedDateValue, index) => ( +
+   + +   +
+ ))} + {(schedulesData[markedDate].markedDates?.length ?? + 0) > 3 && ( +
+ +
+ )} +
+ ), + )} + + ); + }, + )}
))} diff --git a/src/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps.ts b/src/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps.ts index 1a55918..3b9ac9c 100644 --- a/src/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps.ts +++ b/src/core/components/Calendar/ScheduleCalendar/types/CalendarComponentProps.ts @@ -1,5 +1,5 @@ -import { PeriodDates } from "../../DatePickerCalendar/types/DatePickerCalendarProps"; -import { CalendarHeaderProps } from "../../common/types/CalendarHeader"; +import { PeriodDates } from '../../DatePickerCalendar/types/DatePickerCalendarProps'; +import { CalendarHeaderProps } from '../../common/types/CalendarHeader'; export interface MarkedDatesProps { markedDates?: string[]; @@ -10,7 +10,8 @@ export interface SchedulesDataProps { [date: string]: MarkedDatesProps; } -export interface CalendarComponentProps extends Pick { +export interface CalendarComponentProps + extends Pick { initialDate?: number; schedulesData?: SchedulesDataProps; defaultQuantity?: number; diff --git a/src/core/components/Calendar/common/constants/index.ts b/src/core/components/Calendar/common/constants/index.ts index d944296..8357f0e 100644 --- a/src/core/components/Calendar/common/constants/index.ts +++ b/src/core/components/Calendar/common/constants/index.ts @@ -1,6 +1,6 @@ export const MONTH_BUTTON_STATUS = { - IDLE: "IDLE", - DISABLE_BOTH: "DISABLE_BOTH", - DISABLE_PREV: "DISABLE_PREV", - DISABLE_NEXT: "DISABLE_NEXT", + IDLE: 'IDLE', + DISABLE_BOTH: 'DISABLE_BOTH', + DISABLE_PREV: 'DISABLE_PREV', + DISABLE_NEXT: 'DISABLE_NEXT', } as const; diff --git a/src/core/components/Calendar/common/hooks/useCalendar.ts b/src/core/components/Calendar/common/hooks/useCalendar.ts index 002d745..4fcd35e 100644 --- a/src/core/components/Calendar/common/hooks/useCalendar.ts +++ b/src/core/components/Calendar/common/hooks/useCalendar.ts @@ -1,21 +1,23 @@ -import dayjs from "dayjs"; -import { useCallback, useState } from "react"; +import dayjs from 'dayjs'; +import { useCallback, useState } from 'react'; -import { useMonthChangeEffect } from "@/core/components/Calendar/common/hooks/useMonthChangeEffect"; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; -import { UseCalendarResponse } from "@/core/components/Calendar/common/types/UseCalendarResponse"; +import { useMonthChangeEffect } from '@/core/components/Calendar/common/hooks/useMonthChangeEffect'; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; +import { UseCalendarResponse } from '@/core/components/Calendar/common/types/UseCalendarResponse'; export const useCalendar = (initialDate?: dayjs.Dayjs): UseCalendarResponse => { - const [ selectedDayjs, setSelectedDayjs ] = useState(initialDate || dayjs()); - const [ calendarDates, setCalendarDates ] = useState([[]]); + const [selectedDayjs, setSelectedDayjs] = useState( + initialDate || dayjs(), + ); + const [calendarDates, setCalendarDates] = useState([[]]); const onPreviousMonthClick = useCallback(() => { - const prevMonth: dayjs.Dayjs = selectedDayjs.subtract(1, "month"); + const prevMonth: dayjs.Dayjs = selectedDayjs.subtract(1, 'month'); setSelectedDayjs(prevMonth); }, [selectedDayjs]); const onNextMonthClick = useCallback(() => { - const nextMonth: dayjs.Dayjs = selectedDayjs.add(1, "month"); + const nextMonth: dayjs.Dayjs = selectedDayjs.add(1, 'month'); setSelectedDayjs(nextMonth); }, [selectedDayjs]); diff --git a/src/core/components/Calendar/common/hooks/useMonthChangeEffect.tsx b/src/core/components/Calendar/common/hooks/useMonthChangeEffect.tsx index e0ecdf9..4d2d687 100644 --- a/src/core/components/Calendar/common/hooks/useMonthChangeEffect.tsx +++ b/src/core/components/Calendar/common/hooks/useMonthChangeEffect.tsx @@ -1,32 +1,38 @@ -import dayjs from "dayjs"; -import { useEffect } from "react"; +import dayjs from 'dayjs'; +import { useEffect } from 'react'; -import { HOLIDAYS, Weekdays } from "@/constants"; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; +import { HOLIDAYS, Weekdays } from '@/constants'; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; export const useMonthChangeEffect = ( - selectedDayjs:dayjs.Dayjs, + selectedDayjs: dayjs.Dayjs, setCalendarDates: React.Dispatch>, ) => { useEffect(() => { - function getNewCalendarDates () { + function getNewCalendarDates() { const newCalendarDates: CalendarDateDto[][] = []; let calendarWeekDates: CalendarDateDto[] = []; let calendarDate: dayjs.Dayjs = - (selectedDayjs.startOf("month").startOf("week").get("d") === Weekdays.SUNDAY) - ? selectedDayjs.startOf("month").startOf("week") - : selectedDayjs.subtract(1, "month").endOf("month").startOf("week"); + selectedDayjs.startOf('month').startOf('week').get('d') === + Weekdays.SUNDAY + ? selectedDayjs.startOf('month').startOf('week') + : selectedDayjs.subtract(1, 'month').endOf('month').startOf('week'); while ( - selectedDayjs.endOf("month").get("d") === Weekdays.SATURDAY - ? calendarDate.isBefore(selectedDayjs.add(1, "month").startOf("month")) - : calendarDate.isBefore(selectedDayjs.add(1, "month").startOf("month").endOf("week")) - ) { + selectedDayjs.endOf('month').get('d') === Weekdays.SATURDAY + ? calendarDate.isBefore( + selectedDayjs.add(1, 'month').startOf('month'), + ) + : calendarDate.isBefore( + selectedDayjs.add(1, 'month').startOf('month').endOf('week'), + ) + ) { calendarWeekDates.push({ dayjs: calendarDate, - isThisMonth: calendarDate.isSame(selectedDayjs, "month"), - isToday: calendarDate.format("YYYY-MM-DD") === dayjs().format("YYYY-MM-DD"), - isHoliday: HOLIDAYS.includes(calendarDate.get("d")), + isThisMonth: calendarDate.isSame(selectedDayjs, 'month'), + isToday: + calendarDate.format('YYYY-MM-DD') === dayjs().format('YYYY-MM-DD'), + isHoliday: HOLIDAYS.includes(calendarDate.get('d')), }); if (calendarWeekDates.length === 7) { @@ -34,7 +40,7 @@ export const useMonthChangeEffect = ( calendarWeekDates = []; } - calendarDate = calendarDate.add(1, "day"); + calendarDate = calendarDate.add(1, 'day'); } return newCalendarDates; diff --git a/src/core/components/Calendar/common/subs/CalendarHeader.tsx b/src/core/components/Calendar/common/subs/CalendarHeader.tsx index 077c429..cf8fde5 100644 --- a/src/core/components/Calendar/common/subs/CalendarHeader.tsx +++ b/src/core/components/Calendar/common/subs/CalendarHeader.tsx @@ -1,39 +1,52 @@ -import { CaretLeft, CaretRight } from "@phosphor-icons/react"; +import { CaretLeft, CaretRight } from '@phosphor-icons/react'; -import Typography from "@/core/components/Typography"; -import { MONTH_BUTTON_STATUS } from "../constants"; -import { CalendarHeaderProps } from "../types/CalendarHeader"; +import Typography from '@/core/components/Typography'; +import { MONTH_BUTTON_STATUS } from '../constants'; +import { CalendarHeaderProps } from '../types/CalendarHeader'; export const CalendarHeader = ({ currentMonth, onPreviousMonthClick, onNextMonthClick, - monthButtonStatus = MONTH_BUTTON_STATUS["IDLE"], + monthButtonStatus = MONTH_BUTTON_STATUS['IDLE'], }: CalendarHeaderProps) => { - const isDisabledMonthBtn = monthButtonStatus === MONTH_BUTTON_STATUS["DISABLE_BOTH"]; - const isDisablePrev = (isDisabledMonthBtn || monthButtonStatus === MONTH_BUTTON_STATUS["DISABLE_PREV"]) ?? false; - const isDisableNext = (isDisabledMonthBtn || monthButtonStatus === MONTH_BUTTON_STATUS["DISABLE_NEXT"]) ?? false; - const buttonClassNames = "group flex justify-center items-center"; - const iconClassNames = "text-gray-05 group-disabled:text-gray-03 group-disabled:cursor-not-allowed text-subhead-01-regular md:text-head-01-regular"; + const isDisabledMonthBtn = + monthButtonStatus === MONTH_BUTTON_STATUS['DISABLE_BOTH']; + const isDisablePrev = + (isDisabledMonthBtn || + monthButtonStatus === MONTH_BUTTON_STATUS['DISABLE_PREV']) ?? + false; + const isDisableNext = + (isDisabledMonthBtn || + monthButtonStatus === MONTH_BUTTON_STATUS['DISABLE_NEXT']) ?? + false; + const buttonClassNames = 'group flex justify-center items-center'; + const iconClassNames = + 'text-gray-05 group-disabled:text-gray-03 group-disabled:cursor-not-allowed text-subhead-01-regular md:text-head-01-regular'; return ( -
+
- +
); diff --git a/src/core/components/Calendar/common/subs/CalendarWeekdayComponent.tsx b/src/core/components/Calendar/common/subs/CalendarWeekdayComponent.tsx index b310ea6..32c094d 100644 --- a/src/core/components/Calendar/common/subs/CalendarWeekdayComponent.tsx +++ b/src/core/components/Calendar/common/subs/CalendarWeekdayComponent.tsx @@ -1,19 +1,39 @@ -import clsx from "clsx"; -import dayjs from "dayjs"; -import "dayjs/locale/ko"; +import clsx from 'clsx'; +import dayjs from 'dayjs'; +import 'dayjs/locale/ko'; -import { Weekdays } from "@/constants"; -import Typography from "@/core/components/Typography"; +import { Weekdays } from '@/constants'; +import Typography from '@/core/components/Typography'; -export const CalendarWeekDayComponent = ({ className }: { className?: string }) => { +export const CalendarWeekDayComponent = ({ + className, +}: { + className?: string; +}) => { const convertWeekdayNumberToString = (weekdayNumber: number) => { - return dayjs().startOf("week").add(weekdayNumber, "day").locale("ko").format("ddd"); + return dayjs() + .startOf('week') + .add(weekdayNumber, 'day') + .locale('ko') + .format('ddd'); }; return ( -
- {Object.values(Weekdays).map(weekdayNumber => ( - +
+ {Object.values(Weekdays).map((weekdayNumber) => ( + ))}
); diff --git a/src/core/components/Calendar/common/types/CalendarDateDto.ts b/src/core/components/Calendar/common/types/CalendarDateDto.ts index da4bcdb..327b0cc 100644 --- a/src/core/components/Calendar/common/types/CalendarDateDto.ts +++ b/src/core/components/Calendar/common/types/CalendarDateDto.ts @@ -1,4 +1,4 @@ -import dayjs from "dayjs"; +import dayjs from 'dayjs'; export interface CalendarDateDto { dayjs: dayjs.Dayjs; diff --git a/src/core/components/Calendar/common/types/CalendarHeader.ts b/src/core/components/Calendar/common/types/CalendarHeader.ts index ce4e8e0..ba9b788 100644 --- a/src/core/components/Calendar/common/types/CalendarHeader.ts +++ b/src/core/components/Calendar/common/types/CalendarHeader.ts @@ -1,10 +1,11 @@ -import { MONTH_BUTTON_STATUS } from "../constants"; +import { MONTH_BUTTON_STATUS } from '../constants'; export interface CalendarHeaderProps { currentMonth: string; onPreviousMonthClick?: () => void; onNextMonthClick?: () => void; - monthButtonStatus?: MonthButtonStatusTypes + monthButtonStatus?: MonthButtonStatusTypes; } -export type MonthButtonStatusTypes = typeof MONTH_BUTTON_STATUS[keyof typeof MONTH_BUTTON_STATUS]; +export type MonthButtonStatusTypes = + (typeof MONTH_BUTTON_STATUS)[keyof typeof MONTH_BUTTON_STATUS]; diff --git a/src/core/components/Calendar/common/types/UseCalendarResponse.ts b/src/core/components/Calendar/common/types/UseCalendarResponse.ts index a49c63b..a23368c 100644 --- a/src/core/components/Calendar/common/types/UseCalendarResponse.ts +++ b/src/core/components/Calendar/common/types/UseCalendarResponse.ts @@ -1,15 +1,15 @@ -import dayjs from "dayjs"; +import dayjs from 'dayjs'; -import { CalendarDateDto } from "@/core/components/Calendar/common/types/CalendarDateDto"; +import { CalendarDateDto } from '@/core/components/Calendar/common/types/CalendarDateDto'; export interface UseCalendarResponse { models: { selectedDayjs: dayjs.Dayjs; calendarDates: CalendarDateDto[][]; - } + }; operations: { onPreviousMonthClick: () => void; onNextMonthClick: () => void; setInitialSelectedDayjs: (selectedDayjs: dayjs.Dayjs) => void; - } + }; } diff --git a/src/core/components/Checkbox/Checkbox.stories.tsx b/src/core/components/Checkbox/Checkbox.stories.tsx index b66ed91..3d409b2 100644 --- a/src/core/components/Checkbox/Checkbox.stories.tsx +++ b/src/core/components/Checkbox/Checkbox.stories.tsx @@ -1,27 +1,25 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import Checkbox from "./index"; -import { CheckboxProps } from "./types"; +import Checkbox from './index'; +import { CheckboxProps } from './types'; const meta = { - title: "core/Checkbox", + title: 'core/Checkbox', component: Checkbox, argTypes: { label: { - control: "text", - description: "Checkbox Label", + control: 'text', + description: 'Checkbox Label', }, svgSize: { - control: "select", - options: [ - "size-24", "size-32", - ], - defaultValue: "size-24", - description: "Checkbox Icon Size", + control: 'select', + options: ['size-24', 'size-32'], + defaultValue: 'size-24', + description: 'Checkbox Icon Size', }, isCircle: { - control: "boolean", - description: "Checkbox Icon Circled", + control: 'boolean', + description: 'Checkbox Icon Circled', }, }, } satisfies Meta; @@ -33,5 +31,5 @@ export const Default = (props: CheckboxProps) => { }; export const Circle = () => { - return ; + return ; }; diff --git a/src/core/components/Checkbox/constants/index.ts b/src/core/components/Checkbox/constants/index.ts index 4c96ff7..5719a25 100644 --- a/src/core/components/Checkbox/constants/index.ts +++ b/src/core/components/Checkbox/constants/index.ts @@ -1,11 +1,11 @@ -import { SvgSizeType } from "../types"; +import { SvgSizeType } from '../types'; export const SVG_SIZE = { - SIZE_32: "size-32", - SIZE_24: "size-24", + SIZE_32: 'size-32', + SIZE_24: 'size-24', } as const; export const CHECKBOX_SVG_SIZE: Record = { - [SVG_SIZE.SIZE_32]: "w-8 h-8", - [SVG_SIZE.SIZE_24]: "w-6 h-6", + [SVG_SIZE.SIZE_32]: 'w-8 h-8', + [SVG_SIZE.SIZE_24]: 'w-6 h-6', }; diff --git a/src/core/components/Checkbox/index.tsx b/src/core/components/Checkbox/index.tsx index a8cdfaa..df0c7c4 100644 --- a/src/core/components/Checkbox/index.tsx +++ b/src/core/components/Checkbox/index.tsx @@ -1,42 +1,58 @@ -import clsx from "clsx"; -import { MouseEvent, forwardRef, useId } from "react"; +import clsx from 'clsx'; +import { MouseEvent, forwardRef, useId } from 'react'; -import { CheckCircle, CheckSquare } from "@phosphor-icons/react"; -import Typography from "../Typography"; -import { CHECKBOX_SVG_SIZE, SVG_SIZE } from "./constants"; -import { CheckboxProps } from "./types"; +import { CheckCircle, CheckSquare } from '@phosphor-icons/react'; +import Typography from '../Typography'; +import { CHECKBOX_SVG_SIZE, SVG_SIZE } from './constants'; +import { CheckboxProps } from './types'; -const Checkbox = forwardRef(( +const Checkbox = forwardRef( + ( { label, - svgSize = SVG_SIZE["SIZE_24"], + svgSize = SVG_SIZE['SIZE_24'], isCircle = false, className, disabled, ...props }: CheckboxProps, - ref: React.ComponentPropsWithRef<"input">["ref"], + ref: React.ComponentPropsWithRef<'input'>['ref'], ) => { - const id = useId(); - const RectangleCheckbox = - ; - const CircleCheckbox = - ; - const svg = !isCircle ? RectangleCheckbox : CircleCheckbox; + const id = useId(); + const RectangleCheckbox = ; + const CircleCheckbox = ; + const svg = !isCircle ? RectangleCheckbox : CircleCheckbox; - return ( - - ); -}); + return ( + + ); + }, +); export default Checkbox; diff --git a/src/core/components/Checkbox/types/index.ts b/src/core/components/Checkbox/types/index.ts index 9f9fc63..076bd47 100644 --- a/src/core/components/Checkbox/types/index.ts +++ b/src/core/components/Checkbox/types/index.ts @@ -1,8 +1,9 @@ -import { SVG_SIZE } from "../constants"; +import { SVG_SIZE } from '../constants'; -export type SvgSizeType = typeof SVG_SIZE[keyof typeof SVG_SIZE]; +export type SvgSizeType = (typeof SVG_SIZE)[keyof typeof SVG_SIZE]; -export interface CheckboxProps extends React.InputHTMLAttributes { +export interface CheckboxProps + extends React.InputHTMLAttributes { label?: string; svgSize?: SvgSizeType; isCircle?: boolean; diff --git a/src/core/components/Divider/Divider.stories.tsx b/src/core/components/Divider/Divider.stories.tsx index 622d705..3ed9490 100644 --- a/src/core/components/Divider/Divider.stories.tsx +++ b/src/core/components/Divider/Divider.stories.tsx @@ -1,19 +1,19 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import Divider from "@/core/components/Divider/index"; +import Divider from '@/core/components/Divider/index'; const meta = { - title: "core/Divider", + title: 'core/Divider', component: Divider, - tags: ["autodocs"], + tags: ['autodocs'], } satisfies Meta; export default meta; export const Primary = () => { return ( -
- +
+
); }; diff --git a/src/core/components/Divider/index.tsx b/src/core/components/Divider/index.tsx index 7154f0d..db68e7e 100644 --- a/src/core/components/Divider/index.tsx +++ b/src/core/components/Divider/index.tsx @@ -1,7 +1,10 @@ -import clsx from "clsx"; +import clsx from 'clsx'; -export default function Divider({ className, ...props }: React.HTMLAttributes) { +export default function Divider({ + className, + ...props +}: React.HTMLAttributes) { return ( -
+
); } diff --git a/src/core/components/Drawer/Drawer.stories.tsx b/src/core/components/Drawer/Drawer.stories.tsx index 7795077..d2d28e1 100644 --- a/src/core/components/Drawer/Drawer.stories.tsx +++ b/src/core/components/Drawer/Drawer.stories.tsx @@ -1,37 +1,37 @@ -import { Meta } from "@storybook/react"; -import { useState } from "react"; +import { Meta } from '@storybook/react'; +import { useState } from 'react'; -import Drawer from "./index"; -import { DrawerProps } from "./types"; +import Drawer from './index'; +import { DrawerProps } from './types'; const meta = { - title: "core/Drawer", + title: 'core/Drawer', component: Drawer, parameters: { - layout: "fullscreen", + layout: 'fullscreen', }, argTypes: { target: { - control: "text", - defaultValue: "modal", - description: "Modal Render Position Element id", + control: 'text', + defaultValue: 'modal', + description: 'Modal Render Position Element id', }, title: { - control: "text", - description: "Drawer Title", + control: 'text', + description: 'Drawer Title', }, titleSub: { - control: "text", - description: "Drawer Title Sub", + control: 'text', + description: 'Drawer Title Sub', }, isOpen: { - control: "boolean", + control: 'boolean', defaultValue: false, - description: "Open Modal", + description: 'Open Modal', }, onClose: { - action: "clicked", - description: "Drawer Close Function", + action: 'clicked', + description: 'Drawer Close Function', }, }, } satisfies Meta; @@ -39,29 +39,27 @@ const meta = { export default meta; export const Default = (props: DrawerProps) => { - const [ isOpen, setIsOpen ] = useState(false); + const [isOpen, setIsOpen] = useState(false); - const onToggle = () => setIsOpen(v => !v); + const onToggle = () => setIsOpen((v) => !v); return ( <> -
Header
-
- -
-
+
Header
+
+ +
+
Drawer - +
diff --git a/src/core/components/Drawer/index.tsx b/src/core/components/Drawer/index.tsx index 5028705..a961cfb 100644 --- a/src/core/components/Drawer/index.tsx +++ b/src/core/components/Drawer/index.tsx @@ -1,14 +1,15 @@ -import { X } from "@phosphor-icons/react"; -import clsx from "clsx"; -import { PropsWithChildren, forwardRef } from "react"; +import { X } from '@phosphor-icons/react'; +import clsx from 'clsx'; +import { PropsWithChildren, forwardRef } from 'react'; -import { useBlockScrollingEffect } from "@/hooks/effects/useBlockScrollingEffect"; -import ModalBase from "../Modal/ModalBase"; -import Section from "../Section"; -import Typography from "../Typography"; -import { DrawerProps } from "./types"; +import { useBlockScrollingEffect } from '@/hooks/effects/useBlockScrollingEffect'; +import ModalBase from '../Modal/ModalBase'; +import Section from '../Section'; +import Typography from '../Typography'; +import { DrawerProps } from './types'; -const Drawer = forwardRef(( +const Drawer = forwardRef( + ( { title, titleSub, @@ -16,43 +17,55 @@ const Drawer = forwardRef(( children, isOpen, ...props - }: PropsWithChildren, - ref: React.Ref, + }: PropsWithChildren, + ref: React.Ref, ) => { - const { target, className, ...rest } = props; - const CloseIcon = ; + const { target, className, ...rest } = props; + const CloseIcon = ; - useBlockScrollingEffect(isOpen); + useBlockScrollingEffect(isOpen); - return ( - -
-
-
-
- - {titleSub && } +
+
+
+
+ + {titleSub && ( + + )} +
+
- -
-
- {children} -
-
- ); -}); + + {children} + + + ); + }, +); export default Drawer; diff --git a/src/core/components/Drawer/types/index.ts b/src/core/components/Drawer/types/index.ts index ae0cff1..bcd316f 100644 --- a/src/core/components/Drawer/types/index.ts +++ b/src/core/components/Drawer/types/index.ts @@ -1,10 +1,12 @@ -import { HTMLAttributes } from "react"; +import { HTMLAttributes } from 'react'; -import { ModalBaseProps } from "../../Modal/ModalBase/types"; -import { TypographyProps } from "../../Typography/types"; +import { ModalBaseProps } from '../../Modal/ModalBase/types'; +import { TypographyProps } from '../../Typography/types'; -export interface DrawerProps extends Pick, Omit, "title"> { - title: TypographyProps<"strong">["text"]; - titleSub?: TypographyProps<"span">["text"]; - onClose: ModalBaseProps["onClose"]; +export interface DrawerProps + extends Pick, + Omit, 'title'> { + title: TypographyProps<'strong'>['text']; + titleSub?: TypographyProps<'span'>['text']; + onClose: ModalBaseProps['onClose']; } diff --git a/src/core/components/Dropdown/DropdownBase/Dropdown.stories.tsx b/src/core/components/Dropdown/DropdownBase/Dropdown.stories.tsx index 90bcbc0..1aeae64 100644 --- a/src/core/components/Dropdown/DropdownBase/Dropdown.stories.tsx +++ b/src/core/components/Dropdown/DropdownBase/Dropdown.stories.tsx @@ -1,11 +1,11 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import { CaretDown } from "@phosphor-icons/react"; -import { useState } from "react"; -import DropdownBase from "./index"; +import { CaretDown } from '@phosphor-icons/react'; +import { useState } from 'react'; +import DropdownBase from './index'; const meta = { - title: "core/Dropdown/DropdownBase", + title: 'core/Dropdown/DropdownBase', component: DropdownBase, argTypes: {}, } satisfies Meta; @@ -13,57 +13,55 @@ const meta = { export default meta; export const Default = () => { - const [ currentValue, setCurrentValue ] = useState(""); + const [currentValue, setCurrentValue] = useState(''); - const data = [ "A반", "B반", "C반", "D반", "E반" ]; + const data = ['A반', 'B반', 'C반', 'D반', 'E반']; - const items = data.map(item => ( - setCurrentValue(item)} - > + const items = data.map((item) => ( + setCurrentValue(item)}> {item} )); return ( - {currentValue || "옵션을 선택해주세요"} + {currentValue || '옵션을 선택해주세요'} } - content = {} + content={} /> ); }; export const DropdownBaseWithIcon = () => { - const [ currentValue, setCurrentValue ] = useState(""); + const [currentValue, setCurrentValue] = useState(''); - const data = [ "A반", "B반", "C반", "D반", "E반" ]; + const data = ['A반', 'B반', 'C반', 'D반', 'E반']; const items = data.map((item, idx) => ( - setCurrentValue(item)} - > + setCurrentValue(item)}> {item} )); return ( {({ isToggle }) => ( -
- {currentValue || "옵션을 선택해주세요"} - +
+ {currentValue || '옵션을 선택해주세요'} +
- )} + )} } - content = {} + content={} /> ); }; diff --git a/src/core/components/Dropdown/DropdownBase/DropdownItem.tsx b/src/core/components/Dropdown/DropdownBase/DropdownItem.tsx index 48d1d4c..46977b8 100644 --- a/src/core/components/Dropdown/DropdownBase/DropdownItem.tsx +++ b/src/core/components/Dropdown/DropdownBase/DropdownItem.tsx @@ -1,38 +1,40 @@ -import { PropsWithChildren, forwardRef, useContext } from "react"; +import { PropsWithChildren, forwardRef, useContext } from 'react'; -import clsx from "clsx"; -import { DropdownContext } from "."; -import { DropdownContextValue, DropdownItemProps } from "./types"; +import clsx from 'clsx'; +import { DropdownContext } from '.'; +import { DropdownContextValue, DropdownItemProps } from './types'; -const DropdownItem = forwardRef(( - { - children, - onClick, - className, - ...props - }: PropsWithChildren, - ref: React.Ref, -) => { - const { setIsToggle } = useContext(DropdownContext) as DropdownContextValue; +const DropdownItem = forwardRef( + ( + { + children, + onClick, + className, + ...props + }: PropsWithChildren, + ref: React.Ref, + ) => { + const { setIsToggle } = useContext(DropdownContext) as DropdownContextValue; - const onClickHandler = (e: React.MouseEvent) => { - setIsToggle(false); - onClick?.(e); - }; + const onClickHandler = (e: React.MouseEvent) => { + setIsToggle(false); + onClick?.(e); + }; - return ( -
  • - {children} -
  • - ); -}); + return ( +
  • + {children} +
  • + ); + }, +); export default DropdownItem; -DropdownItem.displayName = "DropdownItem"; +DropdownItem.displayName = 'DropdownItem'; diff --git a/src/core/components/Dropdown/DropdownBase/DropdownItems.tsx b/src/core/components/Dropdown/DropdownBase/DropdownItems.tsx index f20ebfb..eabc2a2 100644 --- a/src/core/components/Dropdown/DropdownBase/DropdownItems.tsx +++ b/src/core/components/Dropdown/DropdownBase/DropdownItems.tsx @@ -1,29 +1,29 @@ -import clsx from "clsx"; -import { forwardRef } from "react"; +import clsx from 'clsx'; +import { forwardRef } from 'react'; -import { DropdownItemsProps } from "./types"; +import { DropdownItemsProps } from './types'; -const DropdownItems = forwardRef(( - { - className, - items, - ...props - }: DropdownItemsProps, +const DropdownItems = forwardRef( + ( + { className, items, ...props }: DropdownItemsProps, ref: React.Ref, ) => { - - return ( -
      - {items} -
    - ); -}); + return ( +
      + {items} +
    + ); + }, +); export default DropdownItems; -DropdownItems.displayName = "DropdownItems"; +DropdownItems.displayName = 'DropdownItems'; diff --git a/src/core/components/Dropdown/DropdownBase/DropdownTrigger.tsx b/src/core/components/Dropdown/DropdownBase/DropdownTrigger.tsx index e99ae00..aa2dd8c 100644 --- a/src/core/components/Dropdown/DropdownBase/DropdownTrigger.tsx +++ b/src/core/components/Dropdown/DropdownBase/DropdownTrigger.tsx @@ -1,46 +1,52 @@ -import { forwardRef, useContext } from "react"; +import { forwardRef, useContext } from 'react'; -import clsx from "clsx"; -import { DropdownContext } from "./index"; -import { DropdownContextValue, DropdownTriggerProps } from "./types"; +import clsx from 'clsx'; +import { DropdownContext } from './index'; +import { DropdownContextValue, DropdownTriggerProps } from './types'; -const DropdownTrigger = forwardRef(( - { - onClick, - className, - children, - ...props - }: DropdownTriggerProps, +const DropdownTrigger = forwardRef( + ( + { onClick, className, children, ...props }: DropdownTriggerProps, ref: React.Ref, ) => { - const { isToggle, readOnly, disabled, setIsToggle } = useContext(DropdownContext) as DropdownContextValue; - const content = typeof children === "function" ? children({ isToggle, readOnly, disabled }) : children; - const isDisabled = readOnly || disabled; + const { isToggle, readOnly, disabled, setIsToggle } = useContext( + DropdownContext, + ) as DropdownContextValue; + const content = + typeof children === 'function' + ? children({ isToggle, readOnly, disabled }) + : children; + const isDisabled = readOnly || disabled; - const onClickHandler = (e: React.MouseEvent) => { - if(isDisabled) return; + const onClickHandler = (e: React.MouseEvent) => { + if (isDisabled) return; - setIsToggle(v => !v); - onClick?.(e); - }; + setIsToggle((v) => !v); + onClick?.(e); + }; - return ( - - ); -}); + return ( + + ); + }, +); export default DropdownTrigger; -DropdownTrigger.displayName = "DropdownTrigger"; +DropdownTrigger.displayName = 'DropdownTrigger'; diff --git a/src/core/components/Dropdown/DropdownBase/index.tsx b/src/core/components/Dropdown/DropdownBase/index.tsx index b000497..fb9893a 100644 --- a/src/core/components/Dropdown/DropdownBase/index.tsx +++ b/src/core/components/Dropdown/DropdownBase/index.tsx @@ -1,15 +1,17 @@ -import useClickOutside from "@/hooks/useClickOutSide"; -import clsx from "clsx"; -import { createContext, useState } from "react"; +import useClickOutside from '@/hooks/useClickOutSide'; +import clsx from 'clsx'; +import { createContext, useState } from 'react'; -import Typography from "../../Typography"; -import DropdownItem from "./DropdownItem"; -import DropdownItems from "./DropdownItems"; -import DropdownTrigger from "./DropdownTrigger"; -import { DropdownContextValue, DropdownProps, ReturnType } from "./types"; +import Typography from '../../Typography'; +import DropdownItem from './DropdownItem'; +import DropdownItems from './DropdownItems'; +import DropdownTrigger from './DropdownTrigger'; +import { DropdownContextValue, DropdownProps, ReturnType } from './types'; -export const DropdownContext = createContext(undefined); -DropdownContext.displayName = "DropdownContext"; +export const DropdownContext = createContext( + undefined, +); +DropdownContext.displayName = 'DropdownContext'; const DropdownBase = ({ className, @@ -18,26 +20,36 @@ const DropdownBase = ({ trigger, content, feedback, - feedbackColor = "error", + feedbackColor = 'error', }: DropdownProps) => { - const [ isToggle, setIsToggle ] = useState(false); - const { contentRef } = useClickOutside(() => setIsToggle(false)); + const [isToggle, setIsToggle] = useState(false); + const { contentRef } = useClickOutside(() => + setIsToggle(false), + ); const isVisibleContent = !readOnly && !disabled && isToggle; return ( - -
    + +
    {trigger} {isVisibleContent && content}
    - {feedback ? : null} + {feedback ? ( + + ) : null}
    ); }; export default DropdownBase as unknown as ReturnType; -DropdownBase.displayName = "DropdownBase"; +DropdownBase.displayName = 'DropdownBase'; DropdownBase.Trigger = DropdownTrigger; DropdownBase.Items = DropdownItems; DropdownBase.Item = DropdownItem; diff --git a/src/core/components/Dropdown/DropdownBase/types/index.ts b/src/core/components/Dropdown/DropdownBase/types/index.ts index 7648b08..0674b0c 100644 --- a/src/core/components/Dropdown/DropdownBase/types/index.ts +++ b/src/core/components/Dropdown/DropdownBase/types/index.ts @@ -1,8 +1,8 @@ -import { ThemeColors } from "@/types"; -import { Dispatch, HTMLAttributes, SetStateAction } from "react"; -import DropdownItem from "../DropdownItem"; -import DropdownItems from "../DropdownItems"; -import DropdownTrigger from "../DropdownTrigger"; +import { ThemeColors } from '@/types'; +import { Dispatch, HTMLAttributes, SetStateAction } from 'react'; +import DropdownItem from '../DropdownItem'; +import DropdownItems from '../DropdownItems'; +import DropdownTrigger from '../DropdownTrigger'; export interface DropdownProps { className?: string; @@ -14,20 +14,26 @@ export interface DropdownProps { feedbackColor?: ThemeColors; } -export interface DropdownContextValue extends Pick { +export interface DropdownContextValue + extends Pick { isToggle: boolean; setIsToggle: Dispatch>; } export interface DropdownItemProps extends HTMLAttributes {} -export interface DropdownItemsProps extends HTMLAttributes{ +export interface DropdownItemsProps extends HTMLAttributes { items: React.ReactNode[]; } -export interface DropdownTriggerProps extends Omit, "children"> { +export interface DropdownTriggerProps + extends Omit, 'children'> { onClick?: (e: React.MouseEvent) => void; - children: React.ReactNode | ((props: Pick) => React.ReactNode); + children: + | React.ReactNode + | (( + props: Pick, + ) => React.ReactNode); } type Dropdown = (props: DropdownProps) => React.ReactElement; diff --git a/src/core/components/Dropdown/DropdownFilter/DropdownFilter.stories.tsx b/src/core/components/Dropdown/DropdownFilter/DropdownFilter.stories.tsx index 3707a8a..a9b0381 100644 --- a/src/core/components/Dropdown/DropdownFilter/DropdownFilter.stories.tsx +++ b/src/core/components/Dropdown/DropdownFilter/DropdownFilter.stories.tsx @@ -1,10 +1,10 @@ -import { Meta } from "@storybook/react"; -import { useState } from "react"; +import { Meta } from '@storybook/react'; +import { useState } from 'react'; -import DropdownFilter from "../DropdownFilter"; +import DropdownFilter from '../DropdownFilter'; const meta = { - title: "core/Dropdown/DropdownFilter", + title: 'core/Dropdown/DropdownFilter', component: DropdownFilter, argTypes: {}, } satisfies Meta; @@ -12,14 +12,14 @@ const meta = { export default meta; export const Default = () => { - const [ currentValue, setCurrentValue ] = useState(""); - const data = [ "학부모", "교육기관", "둘다" ]; + const [currentValue, setCurrentValue] = useState(''); + const data = ['학부모', '교육기관', '둘다']; const items = data.map((item, idx) => ( setCurrentValue(item)} + key={idx} + checked={item === currentValue} + onClick={() => setCurrentValue(item)} > {item} @@ -27,9 +27,13 @@ export const Default = () => { return ( } - content = { + trigger={ + } + content={} /> ); }; diff --git a/src/core/components/Dropdown/DropdownFilter/DropdownFilterItem.tsx b/src/core/components/Dropdown/DropdownFilter/DropdownFilterItem.tsx index 1d746fc..c158dcf 100644 --- a/src/core/components/Dropdown/DropdownFilter/DropdownFilterItem.tsx +++ b/src/core/components/Dropdown/DropdownFilter/DropdownFilterItem.tsx @@ -1,28 +1,28 @@ -import clsx from "clsx"; -import { forwardRef } from "react"; +import clsx from 'clsx'; +import { forwardRef } from 'react'; -import DropdownBase from "../DropdownBase"; -import { DropdownFilterItemProps } from "./types"; +import DropdownBase from '../DropdownBase'; +import { DropdownFilterItemProps } from './types'; -const DropdownFilterItem = forwardRef(( - { - className, - children, - checked, - ...props - }: DropdownFilterItemProps, +const DropdownFilterItem = forwardRef( + ( + { className, children, checked, ...props }: DropdownFilterItemProps, ref: React.Ref, ) => { - - return ( - - {children} - - ); -}); + return ( + + {children} + + ); + }, +); export default DropdownFilterItem; diff --git a/src/core/components/Dropdown/DropdownFilter/DropdownFilterItems.tsx b/src/core/components/Dropdown/DropdownFilter/DropdownFilterItems.tsx index 483589b..fb3275c 100644 --- a/src/core/components/Dropdown/DropdownFilter/DropdownFilterItems.tsx +++ b/src/core/components/Dropdown/DropdownFilter/DropdownFilterItems.tsx @@ -1,24 +1,25 @@ -import clsx from "clsx"; -import { forwardRef } from "react"; +import clsx from 'clsx'; +import { forwardRef } from 'react'; -import DropdownBase from "../DropdownBase"; -import { DropdownItemsProps } from "../DropdownBase/types"; +import DropdownBase from '../DropdownBase'; +import { DropdownItemsProps } from '../DropdownBase/types'; -const DropdownFilterItems = forwardRef(( - { - className, - ...props - }: DropdownItemsProps, +const DropdownFilterItems = forwardRef( + ( + { className, ...props }: DropdownItemsProps, ref: React.Ref, ) => { - - return ( - - ); -}); + return ( + + ); + }, +); export default DropdownFilterItems; diff --git a/src/core/components/Dropdown/DropdownFilter/DropdownFilterTrigger.tsx b/src/core/components/Dropdown/DropdownFilter/DropdownFilterTrigger.tsx index 7b2b688..e2d5415 100644 --- a/src/core/components/Dropdown/DropdownFilter/DropdownFilterTrigger.tsx +++ b/src/core/components/Dropdown/DropdownFilter/DropdownFilterTrigger.tsx @@ -1,28 +1,36 @@ -import { forwardRef } from "react"; +import { forwardRef } from 'react'; -import { CaretDown } from "@phosphor-icons/react"; -import Typography from "../../Typography"; -import DropdownBase from "../DropdownBase"; -import { DropdownFilterTriggerProps } from "./types"; +import { CaretDown } from '@phosphor-icons/react'; +import Typography from '../../Typography'; +import DropdownBase from '../DropdownBase'; +import { DropdownFilterTriggerProps } from './types'; -const DropdownFilterTrigger = forwardRef(( - { - currentValue, - ...props - }: DropdownFilterTriggerProps, +const DropdownFilterTrigger = forwardRef( + ( + { currentValue, ...props }: DropdownFilterTriggerProps, ref: React.Ref, ) => { - - return ( - - {({ isToggle }) => ( -
    - - -
    - )} -
    - ); -}); + return ( + + {({ isToggle }) => ( +
    + + +
    + )} +
    + ); + }, +); export default DropdownFilterTrigger; diff --git a/src/core/components/Dropdown/DropdownFilter/index.tsx b/src/core/components/Dropdown/DropdownFilter/index.tsx index 0d8de4f..35592f3 100644 --- a/src/core/components/Dropdown/DropdownFilter/index.tsx +++ b/src/core/components/Dropdown/DropdownFilter/index.tsx @@ -1,19 +1,17 @@ -import DropdownBase from "../DropdownBase"; -import { DropdownProps } from "../DropdownBase/types"; -import DropdownFilterItem from "./DropdownFilterItem"; -import DropdownFilterItems from "./DropdownFilterItems"; -import DropdownFilterTrigger from "./DropdownFilterTrigger"; -import { ReturnType } from "./types"; +import DropdownBase from '../DropdownBase'; +import { DropdownProps } from '../DropdownBase/types'; +import DropdownFilterItem from './DropdownFilterItem'; +import DropdownFilterItems from './DropdownFilterItems'; +import DropdownFilterTrigger from './DropdownFilterTrigger'; +import { ReturnType } from './types'; const DropdownFilter = ({ ...props }: DropdownProps) => { - return ( - - ); + return ; }; export default DropdownFilter as unknown as ReturnType; -DropdownFilter.displayName = "DropdownFilter"; +DropdownFilter.displayName = 'DropdownFilter'; DropdownFilter.Trigger = DropdownFilterTrigger; DropdownFilter.Items = DropdownFilterItems; DropdownFilter.Item = DropdownFilterItem; diff --git a/src/core/components/Dropdown/DropdownFilter/types/index.ts b/src/core/components/Dropdown/DropdownFilter/types/index.ts index 242bc16..02e44dd 100644 --- a/src/core/components/Dropdown/DropdownFilter/types/index.ts +++ b/src/core/components/Dropdown/DropdownFilter/types/index.ts @@ -1,15 +1,20 @@ -import { TypographyProps } from "@/core/components/Typography/types"; -import { DropdownItemProps, DropdownProps, DropdownTriggerProps } from "../../DropdownBase/types"; -import DropdownFilterItem from "../DropdownFilterItem"; -import DropdownFilterItems from "../DropdownFilterItems"; -import DropdownFilterTrigger from "../DropdownFilterTrigger"; +import { TypographyProps } from '@/core/components/Typography/types'; +import { + DropdownItemProps, + DropdownProps, + DropdownTriggerProps, +} from '../../DropdownBase/types'; +import DropdownFilterItem from '../DropdownFilterItem'; +import DropdownFilterItems from '../DropdownFilterItems'; +import DropdownFilterTrigger from '../DropdownFilterTrigger'; -export interface DropdownFilterTriggerProps extends Omit { - currentValue: TypographyProps["text"] +export interface DropdownFilterTriggerProps + extends Omit { + currentValue: TypographyProps['text']; } export interface DropdownFilterItemProps extends DropdownItemProps { - checked: boolean + checked: boolean; } type DropdownFilter = (props: DropdownProps) => React.ReactElement; diff --git a/src/core/components/Dropdown/DropdownSelect/DropdownSelect.stories.tsx b/src/core/components/Dropdown/DropdownSelect/DropdownSelect.stories.tsx index 871a87c..44eab5c 100644 --- a/src/core/components/Dropdown/DropdownSelect/DropdownSelect.stories.tsx +++ b/src/core/components/Dropdown/DropdownSelect/DropdownSelect.stories.tsx @@ -1,10 +1,10 @@ -import { Meta } from "@storybook/react"; -import { useState } from "react"; +import { Meta } from '@storybook/react'; +import { useState } from 'react'; -import DropdownSelect from "./index"; +import DropdownSelect from './index'; const meta = { - title: "core/Dropdown/DropdownSelect", + title: 'core/Dropdown/DropdownSelect', component: DropdownSelect, argTypes: {}, } satisfies Meta; @@ -12,14 +12,14 @@ const meta = { export default meta; export const Default = () => { - const [ currentValue, setCurrentValue ] = useState(""); - const data = [ "2023년", "2024년", "2025년" ]; + const [currentValue, setCurrentValue] = useState(''); + const data = ['2023년', '2024년', '2025년']; const items = data.map((item, idx) => ( setCurrentValue(item)} + key={idx} + checked={currentValue === item} + onClick={() => setCurrentValue(item)} > {item} @@ -27,8 +27,13 @@ export const Default = () => { return ( } - content = {} + trigger={ + + } + content={} /> ); }; diff --git a/src/core/components/Dropdown/DropdownSelect/DropdownSelectItem.tsx b/src/core/components/Dropdown/DropdownSelect/DropdownSelectItem.tsx index b05f488..723a084 100644 --- a/src/core/components/Dropdown/DropdownSelect/DropdownSelectItem.tsx +++ b/src/core/components/Dropdown/DropdownSelect/DropdownSelectItem.tsx @@ -1,28 +1,28 @@ -import clsx from "clsx"; -import { forwardRef } from "react"; +import clsx from 'clsx'; +import { forwardRef } from 'react'; -import DropdownBase from "../DropdownBase"; -import { DropdownSelectItemProps } from "./types"; +import DropdownBase from '../DropdownBase'; +import { DropdownSelectItemProps } from './types'; -const DropdownSelectItem = forwardRef(( - { - className, - children, - checked, - ...props - }: DropdownSelectItemProps, +const DropdownSelectItem = forwardRef( + ( + { className, children, checked, ...props }: DropdownSelectItemProps, ref: React.Ref, ) => { - - return ( - - {children} - - ); -}); + return ( + + {children} + + ); + }, +); export default DropdownSelectItem; diff --git a/src/core/components/Dropdown/DropdownSelect/DropdownSelectItems.tsx b/src/core/components/Dropdown/DropdownSelect/DropdownSelectItems.tsx index 9fdc816..a8d548e 100644 --- a/src/core/components/Dropdown/DropdownSelect/DropdownSelectItems.tsx +++ b/src/core/components/Dropdown/DropdownSelect/DropdownSelectItems.tsx @@ -1,24 +1,25 @@ -import clsx from "clsx"; -import { forwardRef } from "react"; +import clsx from 'clsx'; +import { forwardRef } from 'react'; -import DropdownBase from "../DropdownBase"; -import { DropdownItemsProps } from "../DropdownBase/types"; +import DropdownBase from '../DropdownBase'; +import { DropdownItemsProps } from '../DropdownBase/types'; -const DropdownSelectItems = forwardRef(( - { - className, - ...props - }: DropdownItemsProps, +const DropdownSelectItems = forwardRef( + ( + { className, ...props }: DropdownItemsProps, ref: React.Ref, ) => { - - return ( - - ); -}); + return ( + + ); + }, +); export default DropdownSelectItems; diff --git a/src/core/components/Dropdown/DropdownSelect/DropdownSelectTrigger.tsx b/src/core/components/Dropdown/DropdownSelect/DropdownSelectTrigger.tsx index b665b68..a316232 100644 --- a/src/core/components/Dropdown/DropdownSelect/DropdownSelectTrigger.tsx +++ b/src/core/components/Dropdown/DropdownSelect/DropdownSelectTrigger.tsx @@ -1,36 +1,56 @@ -import { CaretDown } from "@phosphor-icons/react"; -import clsx from "clsx"; -import { forwardRef } from "react"; +import { CaretDown } from '@phosphor-icons/react'; +import clsx from 'clsx'; +import { forwardRef } from 'react'; -import Typography from "../../Typography"; -import DropdownBase from "../DropdownBase"; -import { DropdownSelectTriggerProps } from "./types"; +import Typography from '../../Typography'; +import DropdownBase from '../DropdownBase'; +import { DropdownSelectTriggerProps } from './types'; -const DropdownSelectTrigger = forwardRef(( - { - currentValue, - ...props - }: DropdownSelectTriggerProps, +const DropdownSelectTrigger = forwardRef( + ( + { currentValue, ...props }: DropdownSelectTriggerProps, ref: React.Ref, ) => { - const { className, placeholder, ...rest } = props; - const showPlaceholder = placeholder && !currentValue; + const { className, placeholder, ...rest } = props; + const showPlaceholder = placeholder && !currentValue; - return ( - - {({ isToggle, disabled, readOnly }) => { - const isDisabled = readOnly || disabled; - const isVisibleContent = !readOnly && !disabled && isToggle; + return ( + + {({ isToggle, disabled, readOnly }) => { + const isDisabled = readOnly || disabled; + const isVisibleContent = !readOnly && !disabled && isToggle; - return ( - <> - - {!isDisabled ? : null} - - ); - }} - - ); -}); + return ( + <> + + {!isDisabled ? ( + + ) : null} + + ); + }} + + ); + }, +); export default DropdownSelectTrigger; diff --git a/src/core/components/Dropdown/DropdownSelect/index.tsx b/src/core/components/Dropdown/DropdownSelect/index.tsx index dad9ba1..78f513e 100644 --- a/src/core/components/Dropdown/DropdownSelect/index.tsx +++ b/src/core/components/Dropdown/DropdownSelect/index.tsx @@ -1,19 +1,17 @@ -import DropdownBase from "../DropdownBase"; -import { DropdownProps } from "../DropdownBase/types"; -import DropdownSelectItem from "./DropdownSelectItem"; -import DropdownSelectItems from "./DropdownSelectItems"; -import DropdownSelectTrigger from "./DropdownSelectTrigger"; -import { ReturnType } from "./types"; +import DropdownBase from '../DropdownBase'; +import { DropdownProps } from '../DropdownBase/types'; +import DropdownSelectItem from './DropdownSelectItem'; +import DropdownSelectItems from './DropdownSelectItems'; +import DropdownSelectTrigger from './DropdownSelectTrigger'; +import { ReturnType } from './types'; const DropdownSelect = ({ ...props }: DropdownProps) => { - return ( - - ); + return ; }; export default DropdownSelect as unknown as ReturnType; -DropdownSelect.displayName = "DropdownSelect"; +DropdownSelect.displayName = 'DropdownSelect'; DropdownSelect.Trigger = DropdownSelectTrigger; DropdownSelect.Items = DropdownSelectItems; DropdownSelect.Item = DropdownSelectItem; diff --git a/src/core/components/Dropdown/DropdownSelect/types/index.ts b/src/core/components/Dropdown/DropdownSelect/types/index.ts index 17cc9f9..131828b 100644 --- a/src/core/components/Dropdown/DropdownSelect/types/index.ts +++ b/src/core/components/Dropdown/DropdownSelect/types/index.ts @@ -1,15 +1,20 @@ -import { TypographyProps } from "@/core/components/Typography/types"; -import { DropdownItemProps, DropdownProps, DropdownTriggerProps } from "../../DropdownBase/types"; -import DropdownSelectItem from "../DropdownSelectItem"; -import DropdownSelectItems from "../DropdownSelectItems"; -import DropdownSelectTrigger from "../DropdownSelectTrigger"; +import { TypographyProps } from '@/core/components/Typography/types'; +import { + DropdownItemProps, + DropdownProps, + DropdownTriggerProps, +} from '../../DropdownBase/types'; +import DropdownSelectItem from '../DropdownSelectItem'; +import DropdownSelectItems from '../DropdownSelectItems'; +import DropdownSelectTrigger from '../DropdownSelectTrigger'; -export interface DropdownSelectTriggerProps extends Omit { - currentValue: TypographyProps["text"] +export interface DropdownSelectTriggerProps + extends Omit { + currentValue: TypographyProps['text']; } export interface DropdownSelectItemProps extends DropdownItemProps { - checked: boolean + checked: boolean; } type DropdownSelect = (props: DropdownProps) => React.ReactElement; diff --git a/src/core/components/FormLabel/FormLabel.stories.tsx b/src/core/components/FormLabel/FormLabel.stories.tsx index cfa79fa..a62568d 100644 --- a/src/core/components/FormLabel/FormLabel.stories.tsx +++ b/src/core/components/FormLabel/FormLabel.stories.tsx @@ -1,30 +1,30 @@ -import { Meta } from "@storybook/react"; +import { Meta } from '@storybook/react'; -import { ColorOptions } from "@/constants/color"; -import { default as FormLabel } from "./index"; -import { FormLabelProps } from "./types"; +import { ColorOptions } from '@/constants/color'; +import { default as FormLabel } from './index'; +import { FormLabelProps } from './types'; const meta = { - title: "core/FormLabel", + title: 'core/FormLabel', component: FormLabel, argTypes: { label: { - control: "text", - description: "FormLabel test", + control: 'text', + description: 'FormLabel test', }, required: { - control: "boolean", - description: "Form Required", + control: 'boolean', + description: 'Form Required', }, labelColor: { - control: "select", + control: 'select', options: ColorOptions, - defaultValue: "gray-04", - description: "Bbodek DesignSystem Colors", + defaultValue: 'gray-04', + description: 'Bbodek DesignSystem Colors', }, labelSubText: { - control: "text", - description: "Form Feedback", + control: 'text', + description: 'Form Feedback', }, }, } satisfies Meta; @@ -34,10 +34,12 @@ export default meta; export const Default = (props: FormLabelProps) => { return ( ); }; diff --git a/src/core/components/FormLabel/index.tsx b/src/core/components/FormLabel/index.tsx index 2877734..413231d 100644 --- a/src/core/components/FormLabel/index.tsx +++ b/src/core/components/FormLabel/index.tsx @@ -1,28 +1,37 @@ -import { forwardRef } from "react"; +import { forwardRef } from 'react'; -import { THEME_COLOR } from "@/constants/color"; -import { THEME_TYPOGRAPHY } from "@/constants/typography"; -import { ThemeColors, ThemeTypography } from "@/types"; -import Typography from "../Typography"; -import { FormLabelProps } from "./types"; +import { THEME_COLOR } from '@/constants/color'; +import { THEME_TYPOGRAPHY } from '@/constants/typography'; +import { ThemeColors, ThemeTypography } from '@/types'; +import Typography from '../Typography'; +import { FormLabelProps } from './types'; -const FormLabel = forwardRef(( +const FormLabel = forwardRef( + ( { - labelTheme = THEME_TYPOGRAPHY["BODY_02_MEDIUM"] as ThemeTypography, - labelColor = THEME_COLOR["GRAY_06"] as ThemeColors, + labelTheme = THEME_TYPOGRAPHY['BODY_02_MEDIUM'] as ThemeTypography, + labelColor = THEME_COLOR['GRAY_06'] as ThemeColors, label, required, labelSubText, }: FormLabelProps, ref: React.Ref, ) => { - return ( -
    - {label} - {required && *} - {labelSubText && } -
    - ); -}); + return ( +
    + {label} + {required && *} + {labelSubText && ( + + )} +
    + ); + }, +); export default FormLabel; diff --git a/src/core/components/FormLabel/types/index.ts b/src/core/components/FormLabel/types/index.ts index 1771936..7027d9e 100644 --- a/src/core/components/FormLabel/types/index.ts +++ b/src/core/components/FormLabel/types/index.ts @@ -1,10 +1,10 @@ -import { ThemeColors, ThemeTypography } from "@/types"; -import { InputHTMLAttributes } from "react"; +import { ThemeColors, ThemeTypography } from '@/types'; +import { InputHTMLAttributes } from 'react'; export interface FormLabelProps { labelTheme?: ThemeTypography; labelColor?: ThemeColors; label: string; - required?: InputHTMLAttributes["required"]; + required?: InputHTMLAttributes['required']; labelSubText?: string; } diff --git a/src/core/components/Input/InputBase/InputBase.stories.tsx b/src/core/components/Input/InputBase/InputBase.stories.tsx index b36b1fd..5509d17 100644 --- a/src/core/components/Input/InputBase/InputBase.stories.tsx +++ b/src/core/components/Input/InputBase/InputBase.stories.tsx @@ -1,91 +1,94 @@ -import { Meta } from "@storybook/react"; -import { useId, useState } from "react"; +import { Meta } from '@storybook/react'; +import { useId, useState } from 'react'; -import { ColorOptions } from "@/constants/color"; -import InputBase from "./index"; -import { InputBaseProps } from "./types"; +import { ColorOptions } from '@/constants/color'; +import InputBase from './index'; +import { InputBaseProps } from './types'; const meta = { - title: "core/Input/InputBase", + title: 'core/Input/InputBase', component: InputBase, argTypes: { inputId: { - control: "text", - description: "Input & Label Id", + control: 'text', + description: 'Input & Label Id', }, element: { - control: "text", - defaultValue: "div", - description: "HTML Tag", + control: 'text', + defaultValue: 'div', + description: 'HTML Tag', }, rootClassName: { - control: "text", - description: "InputBase Root Element ClassName", + control: 'text', + description: 'InputBase Root Element ClassName', }, inputRootClassName: { - control: "text", - description: "InputBase Input Root Element ClassName", + control: 'text', + description: 'InputBase Input Root Element ClassName', }, label: { - control: "text", - description: "Input Label", + control: 'text', + description: 'Input Label', }, startComponent: { - control: "text", - description: "Input start Component", + control: 'text', + description: 'Input start Component', }, inputComponent: { - control: "text", - description: "Input Component", + control: 'text', + description: 'Input Component', }, endComponent: { - control: "text", - description: "Input end Component", + control: 'text', + description: 'Input end Component', }, required: { - control: "boolean", - description: "Input Required", + control: 'boolean', + description: 'Input Required', }, labelColor: { - control: "select", + control: 'select', options: ColorOptions, - defaultValue: "gray-04", - description: "Bbodek DesignSystem Colors", + defaultValue: 'gray-04', + description: 'Bbodek DesignSystem Colors', }, borderColor: { - control: "select", + control: 'select', options: ColorOptions, - defaultValue: "gray-03", - description: "Bbodek DesignSystem Colors", + defaultValue: 'gray-03', + description: 'Bbodek DesignSystem Colors', }, }, } satisfies Meta; export default meta; -export const Default = (props: InputBaseProps<"div">) => { +export const Default = (props: InputBaseProps<'div'>) => { const { label, inputId, element, inputComponent, ...rest } = props; const id = useId(); - const [ currentValue, setCurrentValue ] = useState(""); - const onChangeHandler = (e: React.ChangeEvent) => setCurrentValue(e.target.value); + const [currentValue, setCurrentValue] = useState(''); + const onChangeHandler = (e: React.ChangeEvent) => + setCurrentValue(e.target.value); return ( -
    +
    : - inputComponent + id={id} + className={'bbodek-field'} + type='text' + onChange={onChangeHandler} + value={currentValue} + required + /> + ) : ( + inputComponent + ) } {...rest} /> diff --git a/src/core/components/Input/InputBase/index.tsx b/src/core/components/Input/InputBase/index.tsx index a9bda83..990edf5 100644 --- a/src/core/components/Input/InputBase/index.tsx +++ b/src/core/components/Input/InputBase/index.tsx @@ -1,10 +1,10 @@ -import clsx from "clsx"; -import React, { forwardRef } from "react"; +import clsx from 'clsx'; +import React, { forwardRef } from 'react'; -import { cn } from "@/utilities/utils"; -import FormLabel from "../../FormLabel"; -import Typography from "../../Typography"; -import { InputBaseProps } from "./types"; +import { cn } from '@/utilities/utils'; +import FormLabel from '../../FormLabel'; +import Typography from '../../Typography'; +import { InputBaseProps } from './types'; const InputBase = forwardRef( ( @@ -19,45 +19,60 @@ const InputBase = forwardRef( endComponent, labelColor, feedback, - borderColor = "gray-03", - feedbackColor = "error", + borderColor = 'gray-03', + feedbackColor = 'error', error = false, disabled = false, readOnly = false, required = false, ...props }: InputBaseProps, - ref: React.ComponentPropsWithRef["ref"], + ref: React.ComponentPropsWithRef['ref'], ) => { - const Component: React.ElementType = Element || "div"; - const isDisabled = readOnly || disabled; - const isVisibleEndComponent = !isDisabled && endComponent; + const Component: React.ElementType = Element || 'div'; + const isDisabled = readOnly || disabled; + const isVisibleEndComponent = !isDisabled && endComponent; - return ( - - {label && - - } -
    - {startComponent && startComponent} - {inputComponent && inputComponent} - {isVisibleEndComponent && endComponent} -
    - {feedback ? : null} -
    - ); -}); + {label && ( + + )} +
    + {startComponent && startComponent} + {inputComponent && inputComponent} + {isVisibleEndComponent && endComponent} +
    + {feedback ? ( + + ) : null} + + ); + }, +); -InputBase.displayName = "InputBase"; +InputBase.displayName = 'InputBase'; export default InputBase; diff --git a/src/core/components/Input/InputBase/types/index.ts b/src/core/components/Input/InputBase/types/index.ts index ce7c07e..52b3479 100644 --- a/src/core/components/Input/InputBase/types/index.ts +++ b/src/core/components/Input/InputBase/types/index.ts @@ -1,11 +1,13 @@ -import { LabelHTMLAttributes } from "react"; +import { LabelHTMLAttributes } from 'react'; -import { FormLabelProps } from "@/core/components/FormLabel/types"; -import { ThemeColors } from "@/types"; +import { FormLabelProps } from '@/core/components/FormLabel/types'; +import { ThemeColors } from '@/types'; -export interface InputBaseProps extends React.HTMLAttributes, Omit { - label?: FormLabelProps["label"]; - inputId: LabelHTMLAttributes["htmlFor"] +export interface InputBaseProps + extends React.HTMLAttributes, + Omit { + label?: FormLabelProps['label']; + inputId: LabelHTMLAttributes['htmlFor']; element?: T; rootClassName?: string; inputRootClassName?: string; @@ -13,7 +15,7 @@ export interface InputBaseProps extends React.HTMLA inputComponent: React.ReactNode; endComponent?: React.ReactNode; borderColor?: ThemeColors; - error?: boolean + error?: boolean; readOnly?: boolean; disabled?: boolean; feedback?: React.ReactNode; diff --git a/src/core/components/Input/InputDatePicker/DatePicker.tsx b/src/core/components/Input/InputDatePicker/DatePicker.tsx index 24064e8..2be8ccf 100644 --- a/src/core/components/Input/InputDatePicker/DatePicker.tsx +++ b/src/core/components/Input/InputDatePicker/DatePicker.tsx @@ -1,18 +1,18 @@ -import { CalendarBlank } from "@phosphor-icons/react"; -import clsx from "clsx"; -import { useEffect, useId, useState } from "react"; +import { CalendarBlank } from '@phosphor-icons/react'; +import clsx from 'clsx'; +import { useEffect, useId, useState } from 'react'; -import Button from "../../Button/Button"; -import DatePickerCalendar from "../../Calendar/DatePickerCalendar"; -import { DATE_PICKER_TYPE } from "../../Calendar/DatePickerCalendar/constants"; -import { PeriodDates } from "../../Calendar/DatePickerCalendar/types/DatePickerCalendarProps"; -import ModalPopUp from "../../Modal/ModalPopUp"; -import GeneralTab from "../../Tab/GeneralTab/GeneralTab"; -import Typography from "../../Typography"; -import { DatePickerProps } from "./types"; +import Button from '../../Button/Button'; +import DatePickerCalendar from '../../Calendar/DatePickerCalendar'; +import { DATE_PICKER_TYPE } from '../../Calendar/DatePickerCalendar/constants'; +import { PeriodDates } from '../../Calendar/DatePickerCalendar/types/DatePickerCalendarProps'; +import ModalPopUp from '../../Modal/ModalPopUp'; +import GeneralTab from '../../Tab/GeneralTab/GeneralTab'; +import Typography from '../../Typography'; +import { DatePickerProps } from './types'; const DatePicker = ({ - variants = DATE_PICKER_TYPE["PERIOD"], + variants = DATE_PICKER_TYPE['PERIOD'], cutoffDate, cutoffAfterDate, isOpen, @@ -24,20 +24,20 @@ const DatePicker = ({ externalDates, useTab = false, useHoliday = false, - closeButtonText = "닫기", + closeButtonText = '닫기', dateLabel, hasDatePickerTitle = true, }: DatePickerProps) => { const id = useId(); - const [ periodDates, setPeriodDates ] = useState({ - startDate: "", - endDate: "", + const [periodDates, setPeriodDates] = useState({ + startDate: '', + endDate: '', }); - const [ tabSelected, setTabSelected ] = useState("selectedDate"); - const [ isAfterAllDate, setIsAfterAllDate ] = useState(false); + const [tabSelected, setTabSelected] = useState('selectedDate'); + const [isAfterAllDate, setIsAfterAllDate] = useState(false); const tabData = [ - { key: "selectedDate", label: "선택한 기간만 적용" }, - { key: "afterAllDate", label: "선택일부터 모든 날짜 적용" }, + { key: 'selectedDate', label: '선택한 기간만 적용' }, + { key: 'afterAllDate', label: '선택일부터 모든 날짜 적용' }, ]; const handleClose = () => { @@ -48,65 +48,89 @@ const DatePicker = ({ externalDates && setPeriodDates(externalDates); }, [externalDates]); - const tabItems = tabData.map(item => ( + const tabItems = tabData.map((item) => ( ) => { + key={item.key} + label={item.label} + name={id} + theme='body-01-bold' + checked={item.key === tabSelected} + value={item.key} + onChange={(e: React.ChangeEvent) => { setTabSelected(e.target.value); }} /> )); const onDateClick = (periodDates: PeriodDates, afterAllDate?: boolean) => { - setPeriodDates(!isFixStartDate ? periodDates! : { startDate: externalDates!["startDate"], endDate: periodDates["endDate"] }); + setPeriodDates( + !isFixStartDate + ? periodDates! + : { + startDate: externalDates!['startDate'], + endDate: periodDates['endDate'], + }, + ); setIsAfterAllDate(afterAllDate !== undefined && afterAllDate); }; return ( - -
    -
    - {hasDatePickerTitle && -
    - - + +
    +
    + {hasDatePickerTitle && ( +
    + +
    - } - {useTab && + )} + {useTab && ( - } + )}
    -
    +
    -
    +
    diff --git a/src/core/components/Input/InputDatePicker/InputDatePicker.stories.tsx b/src/core/components/Input/InputDatePicker/InputDatePicker.stories.tsx index df62d1f..06c748c 100644 --- a/src/core/components/Input/InputDatePicker/InputDatePicker.stories.tsx +++ b/src/core/components/Input/InputDatePicker/InputDatePicker.stories.tsx @@ -1,16 +1,16 @@ -import { Meta } from "@storybook/react"; -import { OverlayProvider, useOverlay } from "@toss/use-overlay"; -import { useState } from "react"; +import { Meta } from '@storybook/react'; +import { OverlayProvider, useOverlay } from '@toss/use-overlay'; +import { useState } from 'react'; -import Button from "../../Button/Button"; -import { PeriodDates } from "../../Calendar/DatePickerCalendar/types/DatePickerCalendarProps"; -import ModalPopUp from "../../Modal/ModalPopUp"; -import InputDatePicker from "./index"; +import Button from '../../Button/Button'; +import { PeriodDates } from '../../Calendar/DatePickerCalendar/types/DatePickerCalendarProps'; +import ModalPopUp from '../../Modal/ModalPopUp'; +import InputDatePicker from './index'; const meta = { - title: "core/Input/InputDatePicker", + title: 'core/Input/InputDatePicker', parameters: { - layout: "fullscreen", + layout: 'fullscreen', }, component: InputDatePicker, } satisfies Meta; @@ -19,26 +19,46 @@ export default meta; const DefaultLayout = () => { const overlay = useOverlay(); - const [ myDates, setMyDates ] = useState({ - startDate: "", - endDate: "", + const [myDates, setMyDates] = useState({ + startDate: '', + endDate: '', }); - const getDate = (periodDates: PeriodDates, isAfterAllDate?: boolean) => console.log(periodDates, isAfterAllDate); + const getDate = (periodDates: PeriodDates, isAfterAllDate?: boolean) => + console.log(periodDates, isAfterAllDate); - const onDatesClick = () => setMyDates({ startDate: "22222", endDate: "1111" }); + const onDatesClick = () => + setMyDates({ startDate: '22222', endDate: '1111' }); return (
    ) => { + className='flex gap-2 p-4' + onSubmit={(e: React.FormEvent) => { e.preventDefault(); - alert("전송"); + alert('전송'); }} > -
    - - - + +
    ); @@ -47,7 +67,7 @@ const DefaultLayout = () => { export const Default = () => { return ( -