diff --git a/src/components/commons/inputs/PostFormDropdown.module.scss b/src/components/commons/inputs/PostFormDropdown.module.scss new file mode 100644 index 00000000..57a99495 --- /dev/null +++ b/src/components/commons/inputs/PostFormDropdown.module.scss @@ -0,0 +1,139 @@ +.dropdown { + @include column-flexbox(start, start, 0.8rem); + + .label { + @include text-style(14, $white); + } + + .select-group { + position: relative; + width: 100%; + + &-select { + display: none; + } + + &-input-group { + position: relative; + + .input { + @include text-style(16, $gray10); + + cursor: pointer; + + width: 100%; + height: 4.8rem; + padding: 0 5.2rem 0 1.6rem; + + background: $input-background; + border: 0.1rem solid $input-stroke; + border-radius: 0.8rem; + + transition: $base-transition; + + &::placeholder { + @include text-style(16, $gray50); + } + + &.sm { + @include text-style-14; + + height: 4rem; + padding-right: 4.4rem; + } + + &.opened { + border-color: $purple; + } + + &:disabled { + cursor: not-allowed; + background: $gray60; + } + } + + .arrow-btn { + @include pos-center-y; + + right: 1.2rem; + transition: $transition-6s; + + &:disabled { + cursor: not-allowed; + } + + &.rotate { + @include pos-center-y; + + transform: translateY(-62%) rotate(180deg); + transition: $transition-6s; + } + } + } + + &-container { + cursor: pointer; + + position: absolute; + z-index: $dropdown-level; + top: 5.6rem; + + display: none; + + width: 100%; + max-height: 24.8rem; + padding: 0.8rem 0.4rem 0.8rem 0.8rem; + + background: $input-background; + border: 0.1rem solid $input-stroke; + border-radius: 0.6rem; + box-shadow: $dropdown-shadow; + + &.sm { + top: 4.8rem; + } + + &.show { + display: block; + } + + &-list { + @include column-flexbox(start, start, 0.4rem); + @include thin-scrollbar; + + overflow-y: auto; + width: 100%; + max-height: 23rem; + padding-right: 0.4rem; + + .item { + width: 100%; + + .btn { + @include text-style(16, $gray50); + + @include responsive(T) { + color: $gray50; + background: inherit; + border-radius: inherit; + } + + width: 100%; + padding: 0.8rem; + text-align: left; + + &:hover { + color: $gray10; + background: $black50; + border-radius: 0.4rem; + } + + &.sm { + @include text-style(14); + } + } + } + } + } + } +} diff --git a/src/components/commons/inputs/PostFormDropdown.tsx b/src/components/commons/inputs/PostFormDropdown.tsx new file mode 100644 index 00000000..bb6b5207 --- /dev/null +++ b/src/components/commons/inputs/PostFormDropdown.tsx @@ -0,0 +1,104 @@ +import Image from 'next/image'; + +import { useState } from 'react'; + +import classNames from 'classnames/bind'; +import { useFormContext } from 'react-hook-form'; + +import { SVGS } from '@/constants'; + +import useTogglePopup from '@/hooks/useTogglePopup'; + +import styles from './PostFormDropdown.module.scss'; + +const cx = classNames.bind(styles); + +const { url: defaultUrl, alt: defaultAlt } = SVGS.arrow.down.default; +const { url: activeUrl, alt: activeAlt } = SVGS.arrow.down.active; + +type PostFormDropdownProps = { + name: string; + options: { title: string; value: number | string }[]; + label?: string; + isSmall?: boolean; + isDisabled?: boolean; +}; + +export const PostFormDropdown = ({ + name, + label = '', + options, + isSmall = false, + isDisabled = false, +}: PostFormDropdownProps) => { + const { register, setValue } = useFormContext(); + const { isOpen, popupRef, buttonRef, togglePopup } = useTogglePopup(); + const [currentOptionTitle, setCurrentOptionTitle] = useState(options[0].title); + + const handleOptionChange = (title: string, value: number | string) => { + setValue(name, value); + setCurrentOptionTitle(title); + togglePopup(); + }; + + return ( +
+ {label} +
+ + +
+ + +
+ +
+ {isOpen && ( +
    + {options.map((option, index) => ( +
  • + +
  • + ))} +
+ )} +
+
+
+ ); +}; diff --git a/src/components/commons/inputs/index.ts b/src/components/commons/inputs/index.ts index 8fa6bea0..c2fdb9a8 100644 --- a/src/components/commons/inputs/index.ts +++ b/src/components/commons/inputs/index.ts @@ -5,3 +5,4 @@ export * from './FormDropdown'; export * from './SearchBar'; export * from './DateField'; export * from './ImageField'; +export * from './PostFormDropdown'; diff --git a/src/components/createPage/PostForm/index.tsx b/src/components/createPage/PostForm/index.tsx index a39fec54..4d3f56db 100644 --- a/src/components/createPage/PostForm/index.tsx +++ b/src/components/createPage/PostForm/index.tsx @@ -18,7 +18,7 @@ import { import { convertTimeStringToNumber, createHeadcountOptions, joinTitleByDelimiter, navigateBack } from '@/utils'; import { BaseButton } from '@/components/commons/buttons'; -import { FormDropdown, ImageField, InputField, InputRadio, TextField } from '@/components/commons/inputs'; +import { ImageField, InputField, InputRadio, PostFormDropdown, TextField } from '@/components/commons/inputs'; import { ConfirmModal, ModalButton } from '@/components/commons/modals'; import Schedule from '@/components/createPage/Schedule'; import SelectedSchedule from '@/components/createPage/SelectedSchedule'; @@ -186,7 +186,7 @@ const PostForm = ({ type, category }: PostFormProps) => { {recruitmentTypes.isOfflineOrOnline(price) && (
참여 인원 - +
)} diff --git a/src/components/createPage/Schedule/index.tsx b/src/components/createPage/Schedule/index.tsx index c6b87f23..89bea8a9 100644 --- a/src/components/createPage/Schedule/index.tsx +++ b/src/components/createPage/Schedule/index.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames/bind'; import { createTimeRange } from '@/utils'; import { OperationButton } from '@/components/commons/buttons'; -import { DateField, FormDropdown } from '@/components/commons/inputs'; +import { DateField, PostFormDropdown } from '@/components/commons/inputs'; import styles from './Schedule.module.scss'; @@ -28,11 +28,11 @@ const Schedule = ({ isScheduleSelected, onClick }: ScheduleProps) => {
- +
-
- +