Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-date-range-select

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-date-range-select

A svelte component with a HTML5 date picker attached to input range sliders

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

svelte-date-range-select

Something simple to play around with Svelte, a date range component with range sliders attached for fast range selection.

Demos

Simple demo

Installation

yarn add svelte-date-range-select 
npm i svelte-date-range-select 

Note: Install as a dev dependency (yarn add svelte-date-range-select --dev) if useding Sapper to avoid a SSR error.

Usage

<script>
  import DateRangeSelect from 'svelte-date-range-select';

  const name = 'createdDate'; 

  const heading = 'Created Date';

  // this limits the HTML5 date picker end date - e.g. today is used here 
  const endDateMax = new Date();

  // this limits the HTML5 date picker's start date - e.g. 3 years is select here
  const startDateMin = new Date(
    new Date().setFullYear(endDateMax.getFullYear(), endDateMax.getMonth() - 36)
  );

  // option to override the defaults - change to other language, below are the default values
  const labels = {
    notSet: 'not set',
    greaterThan: 'greater than',
    lessThan: 'less than',
    range: 'range',
    day: 'day',
    days: 'days',
    apply: 'Apply'
  }

  // form post ids
  const startDateId = 'start_date_id' 
  const endDateId = 'end_date_id' 


  <DateRangeSelect
    {startDateMin}
    {endDateMax}
    {name}
    {heading}
    {labels}
    {startDateId}
    {endDateId}
    on:onApplyDateRange={handleApplyDateRange} />

  // executed when the user selects the range by clicking the apply button (with the fa-check icon) 

  function handleApplyDateRange(data){
    console.log(data.detail)
    // e.g. will return an object  
    // {
    //  startDate: 2000-12-01,
    //  endDate: 2020-04-06,
    //  name: createdDate
    // }
  }

TODO

  • Allow svelte:component to be dynamically added for the button
  • Tests
  • Custom date formats

Theming

You can override the following CSS variables to style the component.

  • --applyButtonWidth
  • --applyButtonHeight
  • --applyButtonBackgroundColor
  • --applyButtonColor
  • --applyButtonPadding
  • --sliderEndBackgroundColor
  • --sliderEndHeight
  • --sliderEndWidth
  • --sliderEndMargin
  • --sliderStartBackgroundColor
  • --sliderStartHeight
  • --sliderStartWidth
  • --sliderStartMargin
  • --headingColor
  • --headerFontSize
  • --headerFontWeight
  • --dateSelectColor
  • --dateSelectFontSize
  • --dateSelectFontWeight
  • --dateSelectHeight
  • --dateSelectWidth
  • --dateSelectMarginBottom

License

LIL

Keywords

FAQs

Package last updated on 17 May 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc