Giter Site home page Giter Site logo

patagoniapy / svelte-calendar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 6edesign/svelte-calendar

0.0 0.0 0.0 1.21 MB

A lightweight datepicker with neat animations and a unique UX.

Home Page: https://6edesign.github.io/svelte-calendar/

License: MIT License

JavaScript 16.18% Svelte 83.82%

svelte-calendar's Introduction

svelte-calendar

A small date picker built with Svelte 3. Demo available here: demo page.

Basic usage

<Datepicker start={minDate} end={maxDate} />

Props

prop name type default
start date new Date(1987, 9, 29)
end date new Date(2020, 9, 29)
selected date today
formattedSelected string today
dateChosen boolean false
selectableCallback function null
format string | function '#{m}/#{d}/#{Y}'
daysOfWeek array En-US Locale (see below)
monthsOfYear array En-US Locale (see below)
style string ""

start and end

These properties set the minimum and maximum dates that will be rendered by this calendar. It is highly recommended that you do not leave these as their defaults and supply values which suit your application's needs.

selected and formattedSelected

Bind to these properties to observe the selected date as either a date or a string. Use selected to set the day which is selected by default.

dateChosen

Bind to this property to observe whether a user has selected a day.

selectableCallback

Provide a function which accepts a date and returns a boolean determining whether a day between start and end is selectable. For example, use this to prevent weekend days from being selected.

format

Date formatting uses timeUtils formatting (MM/DD/YYYY by default). If you would like to use a different formatting library, supply a function which accepts a date and returns a string.

daysOfWeek and monthsOfYear

These two props are used to internationalize the calendar. The default values are:

export let daysOfWeek = [
  ['Sunday', 'Sun'],
  ['Monday', 'Mon'],
  ['Tuesday', 'Tue'],
  ['Wednesday', 'Wed'],
  ['Thursday', 'Thu'],
  ['Friday', 'Fri'],
  ['Saturday', 'Sat']
];
export let monthsOfYear = [
  ['January', 'Jan'],
  ['February', 'Feb'],
  ['March', 'Mar'],
  ['April', 'Apr'],
  ['May', 'May'],
  ['June', 'Jun'],
  ['July', 'Jul'],
  ['August', 'Aug'],
  ['September', 'Sep'],
  ['October', 'Oct'],
  ['November', 'Nov'],
  ['December', 'Dec']
];

style

This prop allows you to style the div which wraps the Datepicker component. This can be useful, for instance, if you'd like to do something like make the component full-width or display: block; (by default the element is inline-block). If you would like to style the button that triggers the opening of the datepicker we recommend you pass a custom element (button/link/etc) to the component via its default slot.

Kitchen Sink Example:

<script>
  const daysOfWeek = [
    [ 'Domingo', 'Dom' ],
    [ 'Lunes', 'Lun' ],
    [ 'Martes', 'Mar' ],
    [ 'Miércoles', 'Mié' ],
    [ 'Jueves', 'Jue' ],
    [ 'Viernes', 'Vie' ],
    [ 'Sábado', 'Sáb' ],
  ];
  const monthsOfYear = [
    [ 'Enero', 'Ene' ],
    [ 'Febrero', 'Feb' ],
    [ 'Marzo', 'Mar' ],
    [ 'Abril', 'Abr' ],
    [ 'Mayo', 'May' ],
    [ 'Junio', 'Jun' ],
    [ 'Julio', 'Jul' ],
    [ 'Agosto', 'Ago' ],
    [ 'Septiembre', 'Sep' ],
    [ 'Octubre', 'Oct' ],
    [ 'Noviembre', 'Nov' ],
    [ 'Diciembre', 'Dic' ],
  ];
</script>

<Datepicker
  bind:formattedSelected={selectedDateFormatted}
  bind:selected={selectedDate}
  bind:dateChosen={userHasChosenDate}
  start={threeDaysInPast}
  end={inThirtyDays}
  selectableCallback={filterWeekends}
  daysOfWeek={daysOfWeek}
  monthsOfYear={monthsOfYear}
  format={date => dayjs(date).format('DD/MM/YYYY')}
/>

Developing/Modifying Svelte-Calendar Guide

Note that you will need to have Node.js installed.

Install the dependencies...

cd svelte-calendar
npm install

...then start Rollup:

npm run dev

Navigate to localhost:5000. You should see your app running. Edit a component file in src, save it, and your browser will reload the page so you can see your changes automatically.

svelte-calendar's People

Contributors

6edesign avatar antony avatar crisfole avatar henrygd avatar pzmarzly avatar rhinodavid avatar rvanderfeer 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.