Framework/React

[React] react-datepicker 라이브러리 css/style 적용 μ•ˆλ˜λŠ” μ—λŸ¬

yuri lee 2023. 1. 3. 22:13
λ°˜μ‘ν˜•

Intro

react-datepicker 라이브러리λ₯Ό μ‚¬μš©ν•˜λ˜ 도쀑 CSS κ°€ 적용 μ•ˆλ˜λŠ” μ—λŸ¬κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. 참고둜 μ €λŠ” νƒ€μž…μŠ€ν¬λ¦½νŠΈλ„ μ μš©ν•΄μ•Ό ν–ˆκΈ° λ•Œλ¬Έμ— 라이브러리 μ„€μΉ˜λŠ” μ•„λž˜μ™€ 같이 μ§„ν–‰ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

yarn add react-datepicker
yarn add @types/react-datepicker

 

react-datepicker 곡식 ν™ˆνŽ˜μ΄μ§€μ— μžˆλŠ” Default 예제λ₯Ό μ½”λ“œμ— λ„£μ–΄ μ‹€ν–‰ν•˜μž, cssκ°€ μ „ν˜€ μ μš©λ˜μ§€ μ•ŠλŠ” μƒνƒœλ‘œ 화면에 λœ¨λ”κ΅°μš”.

() => {
  const [startDate, setStartDate] = useState(new Date());
  return (
    <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
  );
};

 

Why?

λ°”λ‘œ ꡬ글링을 ν•΄λ΄€μŠ΅λ‹ˆλ‹€. 저와 λΉ„μŠ·ν•œ μ—λŸ¬λ₯Ό κ²ͺμœΌμ‹  뢄듀이 λ§Žμ•˜μŠ΅λ‹ˆλ‹€. 

 

https://github.com/Hacker0x01/react-datepicker/issues/879

 

λ”± 이 글을 μ“°μ‹  λΆ„κ³Ό 제 상황이 μœ μ‚¬ν•˜λ‹€κ³  보면 λ©λ‹ˆλ‹€. 닡변도 ꡉμž₯히 많이 λ‹¬λ Έλ„€μš”. 이후 μ €λŠ” react-datepicker 곡식 νŽ˜μ΄μ§€λ„ μ‚΄νŽ΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€. 

 

You’ll need to install React and PropTypes separately since those dependencies aren’t included in the package. If you need to use a locale other than the default en-US, you'll also need to import that into your project from date-fns (see Localization section below). Below is a simple example of how to use the Datepicker in a React view. You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).

import React, { useState } from "react";
import DatePicker from "react-datepicker";

import "react-datepicker/dist/react-datepicker.css";

// CSS Modules, react-datepicker-cssmodules.css
// import 'react-datepicker/dist/react-datepicker-cssmodules.css';

const Example = () => {
  const [startDate, setStartDate] = useState(new Date());
  return (
    <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
  );
};

직접 cssλ₯Ό λͺ…μ‹œν•΄μ•Ό, css νŒŒμΌμ„ μ‚¬μš©ν•  수 μžˆμ—ˆκ΅°μš”..

 

How to solve the problem

date-pickerλ₯Ό μ‚¬μš©ν•˜λŠ” νŒŒμΌμ— λ‹€μŒκ³Ό 같이 cssλ₯Ό λͺ…μ‹œν•˜μ—¬ import ν•΄μ£Όμ—ˆμŠ΅λ‹ˆλ‹€. λ‹€ν–‰νžˆ cssκ°€ 적용이 λ˜λ„€μš”. 

import "react-datepicker/dist/react-datepicker.css"

+) cssκ°€ 적용되긴 ν•˜λŠ”λ°..

살짝 μ°Œκ·ΈλŸ¬μ Έμ„œ 적용이 λ˜λ”λΌκ³ μš”? 🀫 이 λ¬Έμ œλŠ” μ €λ§Œ κ·ΈλŸ°κ±΄μ§€.. λ‹€μ‹œ ν•œλ²ˆ 연ꡬ해 봐야 될 것 κ°™μŠ΅λ‹ˆλ‹€.


https://reactdatepicker.com/

https://github.com/Hacker0x01/react-datepicker

https://github.com/Hacker0x01/react-datepicker/issues/879

λ°˜μ‘ν˜•