🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

tailwind-basic-datepicker

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tailwind-basic-datepicker

A tailwindcss datepicker component built as a react component with types

Source
npmnpm
Version
1.5.7
Version published
Weekly downloads
101
2425%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version NPM Minified Size GitHub deployments

Tailwind-datepicker-react

A Tailwindcss datepicker component built as a React component with types based on the original datepicker from Flowbite. This component can also be used as a plugin using the Flowbite React library.

Date logic from VanillaJS-datepicker.

Demo

thumbnail

Installation

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

};

  • 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,
	clearBtnText: "Clear",
	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: {
		// () => ReactElement | JSX.Element
		prev: () => <span>Previous</span>,
		next: () => <span>Next</span>,
	},
	datepickerClassNames: "top-12",
	defaultDate: new Date("2022-01-01"),
	language: "en",
	disabledDates: [],
	weekDays: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
	inputNameProp: "date",
	inputIdProp: "date",
	inputPlaceholderProp: "Select Date",
	inputDateFormatProp: {
		day: "numeric",
		month: "long",
		year: "numeric"
	}
}

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,
	clearBtnText: "Clear",
	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: {
		// () => ReactElement | JSX.Element
		prev: () => <span>Previous</span>,
		next: () => <span>Next</span>,
	},
	datepickerClassNames: "top-12",
	defaultDate: new Date("2022-01-01"),
	language: "en",
	disabledDates: [],
	weekDays: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
	inputNameProp: "date",
	inputIdProp: "date",
	inputPlaceholderProp: "Select Date",
	inputDateFormatProp: {
		day: "numeric",
		month: "long",
		year: "numeric"
	}
}

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?: ReactElement
  • value?: Date
  • 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
  • todayBtnText?: string - Default: Today
  • clearBtn?: boolean - Default: true
  • clearBtnText?: string - Default: Clear
  • 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?: false|Date - Default: new Date()
  • language?: string - Default: en
  • disabledDates?: Date[] - Default: []
  • weekDays?: string[] - Default: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"] - Start at Monday even with another language
  • inputNameProp?: string - Default: date
  • inputIdProp?: string - Default: Same as "inputNameProp"
  • inputPlaceholderProp?: string - Default: Select Date
  • inputDateFormatProp?: Intl.DateTimeFormatOptions - Default: {day: "numeric", month: "long", year: "numeric"}

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

License

This project is open-source under the MIT License.

Contributing

After clone, you can run (separated):

  • yarn run dev to start building with Nodemon.
  • cd demo-app/ && npm run dev to start Demo App.

Keywords

tailwind

FAQs

Package last updated on 07 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts