Giter Site home page Giter Site logo

hamedfaryabi / vue-headless-dp Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 279 KB

No UI Vue.js date picker composable.

License: Other

JavaScript 0.22% HTML 1.60% TypeScript 93.92% Vue 4.27%
datepicker headless-datepicker vue-datepicker vue3 vuejs3

vue-headless-dp's Introduction

Vue Headless Date Picker

Vue Headless Date Picker is a flexible and customizable date picker composable for Vue 3 that allows you to easily add date selection functionality to your Vue.js applications.

Features

  • Supports single-date, multi-date, and range-date selection modes.
  • Equal-weeks option for consistent week display.
  • Date range limiting with minDate and maxDate options.
  • Easily disable specific dates.
  • No UI, giving you complete control over the user interface.

Installation

To get started, install the vue-headless-date-picker package from npm:

npm install @hamedfaryabi/vue-headless-date-picker
# or
yarn add @hamedfaryabi/vue-headless-date-picker

Usage

import { useHeadlessDatePicker } from "@hamedfaryabi/vue-headless-date-picker";

// Import a `@date-io` adapter, in this case, DateFnsAdapter
import DateFnsAdapter from "@date-io/date-fns";

// Create a new instance of the DateFnsAdapter
const adapter = new DateFnsAdapter();

const dp = useHeadlessDatePicker(adapter, {
  selectType: "single",
  equalWeeks: false,
  minDate: new Date(),
});

dp.selected.value = new Date(2022-01-12);
console.log(dp.currentYear.value); // 2022

Documentation

useHeadlessDatePicker(adapter, options)

This function initializes the Vue Headless Datepicker and returns an object containing various properties and methods to manage the date picker's state and behavior.

Parameters:

  • adapter (required): An instance of a date adapter that implements @date-io adapters. This adapter is used for date-related operations.
  • options (optional): An object containing configuration options for the date picker. See Options for available options.

Returns:

An object with the following properties and methods:

Property/Method Description Type
state An object that holds the internal state of the date picker, including selected dates, current month, and more. Object
getMonthOfDate(date: Date) A function that takes a Date object and returns a DPMonth object representing the month containing the provided date. Function
isDateSelected(date: Date) A function that checks if a given date is selected according to the date picker's selection mode. Function
isDateDisabled(date: Date) A function that checks if a given date is disabled based on the provided disabled dates. Function
currentMonth A computed property that gets or sets the current month of the date picker. It returns a DPMonth object. Computed Property
currentYear A computed property that gets or sets the current year of the date picker. Computed Property
selected A computed property that gets or sets the selected date(s) based on the date picker's selection mode. Computed Property
disabled A computed property that gets or sets the disabled date(s). Computed Property
minDate A computed property that gets or sets the minimum selectable date. Computed Property
maxDate A computed property that gets or sets the maximum selectable date. Computed Property

Note: All computed properties have getters and setters. for example:

    datePicker.minDate.value = new Date(); // set the min date
    const min = datePicker.minDate; // returns the min date

Options

Basic configuration options for the date picker

Property Description Type
initialMonth Value to initialize the month of the date picker. If not provided, displays the current month. number
initialYear Value to initialize the year of the date picker. If not provided, displays the current year. number
equalWeeks If true, returns days of the previous month in the first week and days of the next month in the last week. boolean
selectType Defines the selection type for the date picker (single, multiple, or range). string
disabled An array of disabled dates. Date[]
minDate The minimum valid date of the date picker. Date
maxDate The maximum valid date of the date picker. Date

License

This project is licensed under the MIT License - see the LICENSE file for details.

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.