Giter Site home page Giter Site logo

Comments (2)

Dave352 avatar Dave352 commented on September 17, 2024

목적

react-datepicker 라이브러리 의존성 제거

작업 스케줄

  • DatePicker 컴포넌트 스타일 구현 시도
  • DatePicker 컴포넌트 기능 구현 시도
  • DateRangePicker 컴포넌트 스타일 구현 시도
  • DateRangePicker 컴포넌트 기능 구현 시도
  • 설계 구상
  • 만들어진 DatePicker 컴포넌트를 이용해서 DateRangePicker 스타일 구현
  • 만들어진 DatePicker 컴포넌트를 이용해서 DateRangePicker 기능 구현
  • DatePicker 컴포넌트에 props를 전달받아 레인지 기능을 사용 할 수 있도록 구현

필요한 정보

  • forwardRef 정의, 인자, 제네릭
  • date-fns
  • Omit

from react-libraries.

Dave352 avatar Dave352 commented on September 17, 2024

📌 예시 코드

기본 타입

image

import { Fragment } from 'react'
import { Controller } from 'react-hook-form'

import { useTheme } from '@emotion/react'
import { useFormSearch } from '@musma/react-utils'
import { DateTime } from 'luxon'

import { DatePicker, SearchForm } from './components'

const Component = () => {
  const theme = useTheme()
  const { control, onSubmit, handleSubmit, getValues } = useFormSearch({
    useFormProps: {
      defaultValues: {
        date: DateTime.now().setZone('Asia/Seoul'),
      },
    },

    fetchAPI() {
      const { date } = getValues()
      console.log('date', date)
    },
  })

  return (
    <Fragment>
      <SearchForm onSubmit={handleSubmit(onSubmit)}>
          {/* DatePicker 기본 타입 */}
          <Controller
            name="date"
            control={control}
            render={({ field }) => {
              return <DatePicker label="기본 타입" {...field} />
            }}
          />
      </SearchForm>
    </Fragment>
  )
}

export default Component

레인지 타입 - default값이 필요한 경우

image

import { Fragment } from 'react'
import { Controller } from 'react-hook-form'

import { useTheme } from '@emotion/react'
import { useFormSearch } from '@musma/react-utils'
import { DateTime } from 'luxon'

import { DatePicker, SearchForm } from './components'

const Component = () => {
  const theme = useTheme()
  const { control, onSubmit, handleSubmit, getValues } = useFormSearch({
    useFormProps: {
      defaultValues: {
        date: [
          DateTime.now().setZone('Asia/Seoul'),
          DateTime.now().setZone('Asia/Seoul'),
        ],
      },
    },

    fetchAPI() {
      const { date } = getValues()
      console.log('date', date)
    },
  })

  return (
    <Fragment>
      <SearchForm onSubmit={handleSubmit(onSubmit)}>
          {/* DatePicker 레인지 타입 (defaultValue O) */}
            <Controller
              name="date"
              control={control}
              render={({ field: { value, ...rest } }) => {
                const [startDate, endDate] = value
                return (
                  <DatePicker
                    label="레인지 타입(디폴트 o)"
                    startDate={startDate}
                    endDate={endDate}
                    selectRange={true}
                    {...rest}
                  />
                )
              }}
            />
      </SearchForm>
    </Fragment>
  )
}

export default Component

레인지 타입 - default값이 필요하지 않은 경우

image

import { Fragment } from 'react'
import { Controller } from 'react-hook-form'

import { useTheme } from '@emotion/react'
import { useFormSearch } from '@musma/react-utils'
import { DateTime } from 'luxon'

import { DatePicker, SearchForm } from './components'

const Component = () => {
  const theme = useTheme()
  const { control, onSubmit, handleSubmit, getValues } = useFormSearch({
    useFormProps: {
      defaultValues: {
        date: [null, null]
      },
    },

    fetchAPI() {
      const { date } = getValues()
      console.log('date', date)
    },
  })

  return (
    <Fragment>
      <SearchForm onSubmit={handleSubmit(onSubmit)}>
          {/* DatePicker 레인지 타입 (defaultValue O) */}
            <Controller
              name="date"
              control={control}
              render={({ field: { value, ...rest } }) => {
                const [startDate, endDate] = value
                return (
                  <DatePicker
                    label="레인지 타입(디폴트 o)"
                    startDate={startDate}
                    endDate={endDate}
                    selectRange={true}
                    {...rest}
                  />
                )
              }}
            />
      </SearchForm>
    </Fragment>
  )
}

export default Component

영문 달력으로 변경

<DatePicker i18n="en" {...rest} />

from react-libraries.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.