Git Product home page Git Product logo

tailwind-datepicker-react's Introduction

NPM Version NPM Minified Size GitHub deployments

Tailwind-datepicker-react

A Tailwindcss/Flowbite datepicker component built as a React component with types

Date logic from VanillaJS-datepicker

thumbnail

Installation

  1. Install the package
npm install tailwind-datepicker-react
yarn add tailwind-datepicker-react
  1. Add the styles to your tailwind.config.js file
module.exports = {
    ...
    content: [
        ...
        "./node_modules/tailwind-datepicker-react/dist/**/*.js", // <--- Add this line
    ],

};
  1. Import the component and use it
import Datepicker from "tailwind-datepicker-react"

Usage

Basic

const options = {
	title: "Demo Title",
	autoHide: true,
	todayBtn: false,
	clearBtn: true,
	maxDate: new Date("2030-01-01"),
	minDate: new Date("1950-01-01"),
	theme: {
		background: "bg-gray-700 dark:bg-gray-800",
		todayBtn: "",
		clearBtn: "",
		icons: "",
		text: "",
		disabledText: "bg-red-500",
		input: "",
		inputIcon: "",
		selected: "",
	},
	icons: {
		// () => ReactNode | JSX.Element
		prev: () => <span>Previous</span>,
		next: () => <span>Next</span>,
	},
	datepickerClassNames: "top-12",
	defaultDate: new Date("2022-01-01"),
	language: "en",
}

const DemoComponent = () => {
	const [show, setShow] = useState < boolean > false
	const handleChange = (selectedDate: Date) => {
		console.log(selectedDate)
	}
	const handleClose = (state: boolean) => {
		setShow(state)
	}

	return (
		<div>
			<Datepicker options={options} onChange={handleChange} show={show} setShow={handleClose} />
		</div>
	)
}

Advanced - Custom input field

const options = {
    title: "Demo Title",
	autoHide: true,
	todayBtn: false,
	clearBtn: true,
    maxDate: new Date("2030-01-01"),
    minDate: new Date("1950-01-01"),
	theme: {
		background: "bg-gray-700 dark:bg-gray-800",
		todayBtn: "",
		clearBtn: "",
		icons: "",
		text: "",
		disabledText: "bg-red-500",
		input: "",
		inputIcon: "",
		selected: "",
	},
    icons: { // () => ReactNode | JSX.Element
        prev: () => <span>Previous</span>,
        next: () => <span>Next</span>,
    },
	datepickerClassNames: "top-12",
	defaultDate: new Date("2022-01-01"),
	language: "en",
}

const DemoComponent = () => {
    const [show, setShow] = useState<boolean>(false)
    const [selectedDate, setSelectedDate] = useState<Date | null>(null)
	const handleChange = (selectedDate: Date) => {
        setSelectedDate(selectedDate)
		console.log(selectedDate)
	}
    const handleClose = (state: boolean) => {
        setShow(state)
    }

	return (
		<div>
			<Datepicker options={options} onChange={handleChange} show={show} setShow={handleClose} />
                <div className="...">
					<div className="...">
						<CalendarIcon />
					</div>
                    <input
                        type="text"
                        className="..."
                        placeholder="Select Date"
                        value={selectedDate}
                        onFocus={() => setShow(true)}
                        readOnly
                    />
				</div>
            </DatePicker>
		</div>
	)
}

DatePicker Props

  • children?: ReactNode
  • options?: IOptions
  • onChange?: (date: Date) => void
  • show: boolean
  • setShow: (show: boolean) => void
  • classNames?: string

IOptions

  • title?: string - Default: disabled
  • autoHide?: boolean - Default: true
  • todayBtn?: boolean - Default: true
  • clearBtn?: boolean - Default: true
  • maxDate?: Date - Default: disabled
  • minDate?: Date - Default: disabled
  • theme?: ITheme - Default: As seen on demo page
  • icons?: IIcons - Default: As seen on demo page
  • datepickerClassNames?: string - Default: ""
  • defaultDate?: Date - Default: new Date()
  • language?: string - Default: en

ITheme

  • background: string
  • todayBtn: string
  • clearBtn: string
  • icons: string
  • text: string
  • disabledText: string
  • input: string
  • inputIcon: string
  • selected: string

IIcons

  • prev: () => ReactNode | JSX.Element
  • next: () => ReactNode | JSX.Element

tailwind-datepicker-react's People

Contributors

mymth avatar omikkel avatar xdev1 avatar wbt avatar castellinosoftware avatar wrgraff avatar dqve avatar gabrnunes avatar johnkegd avatar petrsiegl avatar

Stargazers

Roman avatar

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.