Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@cautionyourblast/svelte-calendar

6eDesign4MIT1.5.0

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

readme

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.

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.5.0 (2020-03-12)

Features

  • pass formattedSelected to slot (3149c93)

1.4.0 (2020-03-12)

Features

1.3.5 (2020-02-14)

Bug Fixes

  • use |local modifier for transitions so that they don't play out on navigation (#67) (8242299)

1.3.4 (2020-01-26)

1.3.3 (2020-01-26)

Bug Fixes

1.3.2 (2020-01-26)

Bug Fixes

1.3.1 (2020-01-15)

Bug Fixes

  • ignore line for eslint (error suddenly popped up but only in travis [odd]) (17c4be1)

1.3.0 (2020-01-15)

Bug Fixes

Features

  • allow styling of div which wraps the Datepicker component (19d4b07)

1.2.2 (2019-12-19)

Bug Fixes

1.2.1 (2019-11-23)

1.2.0 (2019-11-15)

Features

  • Internationalization (add daysOfWeek and monthsOfYear props) (a290701)
  • Internationalization (add daysOfWeek and monthsOfYear props) (20c6d5a)

1.1.0 (2019-10-19)

Features

  • add basic theming functionality (ce244db)

1.0.11 (2019-10-17)

1.0.10 (2019-09-30)

1.0.9 (2019-09-30)

Bug Fixes

  • linting issues (a24aa7c)
  • Update .popover class to .sc-popover to prevent conflict with bootstrap, fixes issue 41 (#42) (1ccdb62)

1.0.8 (2019-08-09)

Bug Fixes

1.0.7 (2019-08-05)

1.0.6 (2019-08-05)

Bug Fixes

1.0.5 (2019-08-04)

Bug Fixes

  • remove .bind(this) in Popover component which is no longer needed in svelte v3 (29341ea)

1.0.4 (2019-08-04)

Bug Fixes

  • Fix Popover.svelte bug introduced by svelte 3 migration. Note, this introduces async/await which is not transpiled by buble. Also, code style modifications. (aa03bbd)

1.0.3 (2019-07-15)

Bug Fixes

  • update version of timeutils (a39c5d2)

1.0.2 (2019-07-10)

1.0.1 (2019-07-10)

0.4.2 (2019-07-10)

0.4.1 (2019-07-10)

0.4.0 (2019-02-19)

Features

  • lighter color/opacity for disabled days (d139457)

0.3.0 (2019-02-19)

Features

  • emit dateSelected event from <Datepicker />, [beyonk-adventures:feature/onchange-event] (c11fc69)
  • Merge pull request #16 from beyonk-adventures/feature/console-warnings (6ba44f5)

0.2.10 (2019-02-07)

0.2.9 (2019-02-07)

0.2.8 (2019-02-06)

0.2.7 (2019-02-05)

0.2.6 (2019-02-01)

0.2.5 (2019-02-01)

0.2.4 (2019-01-29)

0.2.3 (2019-01-29)

0.2.2 (2019-01-29)

0.2.1 (2019-01-29)

0.1.1 (2019-01-21)

0.1.0 (2019-01-21)

Bug Fixes

  • Add styling to indicate which dates are selectable. Prevent out-of-range months from being selected in month-picker and add appropriate styling. (e61b6b2)
  • Fix for popover positioning when parent changes dimensions (ffaf6f4)
  • light gh-pages work (5bb9739)
  • push minified bundle (a593a2c)
  • Setup test page/bundle for non-svelte usage (cf44ceb)
  • styles (503b8e1)
  • styles (73e7d59)
  • use default cursor instead of not-allowed for disabled days (3d42536)

Features