let's get IT with DAVINA ๐Ÿ’ป

react-datepicker ๋ณธ๋ฌธ

DEV_IN/CSS

react-datepicker

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 2. 8. 03:05

  • Calender/style.jsx
import styled from "styled-components";

export const DatePickerContainer = styled.div`
  display: flex;
  input {
    cursor: pointer;
    background-color: transparent;
    width: 100%;
    height: 65px;
    border: none;
    padding: 40px 20px 13px 20px;
    &:hover {
      border-radius: 8px;
      border: 2px solid ${(props) => props.theme.darkBlack};
    }
  }
  .react-datepicker__day--keyboard-selected,
  .react-datepicker__month-text--keyboard-selected,
  .react-datepicker__quarter-text--keyboard-selected,
  .react-datepicker__year-text--keyboard-selected {
    border-radius: 50%;
    background-color: ${(props) => props.theme.pointColor};
  }
  .react-datepicker__day--selected,
  .react-datepicker__day--range-end,
  .react-datepicker__day--in-selecting-range,
  .react-datepicker__day--in-range,
  .react-datepicker__day--selecting-range-end {
    border-radius: 50%;
    background-color: ${(props) => props.theme.pointColor};
  }
  .react-datepicker__day:hover,
  .react-datepicker__month-text:hover,
  .react-datepicker__quarter-text:hover,
  .react-datepicker__year-text:hover {
    border-radius: 50%;
  }
`;

export const InOutBox = styled.div`
  position: relative;
  width: 50%;
  border-right: ${({ first }) => (first ? "1px" : "0px")} solid #b0b0b0;
  border-bottom: 1px solid #b0b0b0;
`;

export const FixedText = styled.div`
  position: absolute;
  z-index: 1;
  left: 11%;
  top: 23%;
  font-size: 14px;
  font-weight: bold;
`;
  • Calender/Calender.jsx
import React from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import { ko } from "date-fns/esm/locale";
import { DatePickerContainer, FixedText, InOutBox } from "./style";

export default function Calender({
    startDate,
    endDate,
    setStartDate,
    setEndDate,
}) {
    return (
        <>
            <DatePickerContainer>
                <InOutBox first>
                    <FixedText>์ฒดํฌ์ธ</FixedText>
                    <DatePicker
                        dateFormat={"yyyy.MM.dd"}
                        locale={ko}
                        minDate={new Date()}
                        selected={startDate}
                        onChange={(date) => setStartDate(date)}
                        selectsStart
                        startDate={startDate}
                        endDate={endDate}
                        monthsShown={2}
                        withPortal
                        placeholderText="๋‚ ์งœ ์„ ํƒ"
                    />
                </InOutBox>
                <InOutBox>
                    <FixedText>์ฒดํฌ์•„์›ƒ</FixedText>
                    <DatePicker
                        dateFormat={"yyyy.MM.dd"}
                        locale={ko}
                        minDate={new Date()}
                        selected={endDate}
                        onChange={(date) => setEndDate(date)}
                        selectsEnd
                        startDate={startDate}
                        endDate={endDate}
                        monthsShown={2}
                        withPortal
                        placeholderText="๋‚ ์งœ ์„ ํƒ"
                    />
                </InOutBox>
            </DatePickerContainer>
        </>
    );
}

TRY-1. ๋‘๋ฒˆ์งธ DatePicker์— minDate={startDate}๋กœ ์†์„ฑ์„ ๋„ฃ์–ด์„œ ์ฒดํฌ์•„์›ƒ ์ผ์ž๋Š” ์‹œ์ž‘๋‚ ์งœ ์ดํ›„๋งŒ ์„ ํƒ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋ ค ํ–ˆ์œผ๋‚˜, ์ฒดํฌ์•„์›ƒ ๋‹ฌ๋ ฅ์„ ๋จผ์ € ์„ ํƒํ•  ๊ฒฝ์šฐ ์‹œ์ž‘๋‚ ์งœ๊ฐ€ ์„ ํƒ๋˜์–ด์žˆ์ง€ ์•Š์•„ ์ด์ „ ๋‚ ์งœ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์—ˆ์Œ..๊ผฌ์ž„..

TRY-2. startDate๋ฅผ new Date()๋กœ ํ•ด์„œ ์˜ค๋Š˜๋‚ ์งœ๋ถ€ํ„ฐ ์‹œ์ž‘ํ–ˆ์œผ๋‹ˆ endDate์—๋„ ๋™์ผํ•˜๊ฒŒ minDate์„ new Date()๋กœ ์ค˜์„œ ์˜ค๋Š˜ ๋‚ ์งœ ์ดํ›„๋งŒ ์„ ํƒ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•จ์œผ๋กœ์จ ํ•ด๊ฒฐ..

 

'DEV_IN > CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

div์— img ๋„ฃ๊ธฐ (props)  (0) 2023.02.09
๊ธ€์ž ์ˆ˜ ์ดˆ๊ณผ์‹œ?  (0) 2023.02.09
Position  (0) 2023.02.09
GMT/UTC time ํ˜•์‹ โ€œ2023-02-02โ€ format์œผ๋กœ change  (0) 2023.02.08
React-Styled Components  (0) 2023.02.08
Comments