All Projects → mskocik → svelty-picker

mskocik / svelty-picker

Licence: other
Simple date & time picker in svelte

Programming Languages

Svelte
593 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to svelty-picker

vue3-date-time-picker
Datepicker component for Vue 3
Stars: ✭ 157 (+313.16%)
Mutual labels:  datetime, timepicker, datepicker, datetimepicker
Angular Bootstrap Datetimepicker
Native Angular date/time picker component styled by Twitter Bootstrap
Stars: ✭ 1,289 (+3292.11%)
Mutual labels:  datetime, timepicker, datepicker, datetimepicker
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (+2342.11%)
Mutual labels:  datetime, timepicker, datepicker, datetimepicker
Zebra datepicker
A super-lightweight, highly configurable, cross-browser date / time picker jQuery plugin
Stars: ✭ 367 (+865.79%)
Mutual labels:  datetime, timepicker, datepicker
nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (-31.58%)
Mutual labels:  timepicker, datepicker, datetimepicker
Material Ui Pickers
Date & Time pickers, built with ❤️ for @material-ui/core
Stars: ✭ 2,291 (+5928.95%)
Mutual labels:  timepicker, datepicker, datetimepicker
Datetimepicker
📅 Date and Time Picker
Stars: ✭ 90 (+136.84%)
Mutual labels:  timepicker, datepicker, datetimepicker
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (+1310.53%)
Mutual labels:  datetime, timepicker, datepicker
Jedate
jeDate V6.5.0 是一款原生JS开发的 不依赖任何第三方库 大众化的日期控件,她身兼多职,虽不是万能的,但是她却是功能强大多样的美少女,她除了包含 单双面板、区域选择、 多语言、日历固定、有效无效日期、日期时间戳转换、日期加减、限制时分秒、初始化日期加减N、日期标注点、设定年月(YYYY-MM)、日期范围限制、开始日期设定、自定义日期格式、当天的前后若干天返回、时分秒选择、智能响应、自动纠错、节日识别,操作等常规功能外,根据不同的日期格式,显示不同内容,还拥有更多趋近完美的解决方案。更多的是需要你与她的亲密接触与呵护!
Stars: ✭ 433 (+1039.47%)
Mutual labels:  datetime, datepicker, datetimepicker
NodaTimePicker
A Date/Time picker component library for Blazor using NodaTime
Stars: ✭ 49 (+28.95%)
Mutual labels:  timepicker, datepicker, datetimepicker
popoPicker
popoPicker是一个移动端3D滚轮日期时间和单项的选择器,支持无限循环滚动,不依赖第三方库
Stars: ✭ 26 (-31.58%)
Mutual labels:  timepicker, datepicker, datetimepicker
Flatpickr
lightweight, powerful javascript datetimepicker with no dependencies
Stars: ✭ 14,575 (+38255.26%)
Mutual labels:  datetime, timepicker, datepicker
Ng2 Datetime
Datetime picker plugins wrapper for Angular2+
Stars: ✭ 165 (+334.21%)
Mutual labels:  timepicker, datepicker, datetimepicker
react-calendar-datetime-picker
A simple and fast date and time picker component for React
Stars: ✭ 58 (+52.63%)
Mutual labels:  datetime, timepicker, datepicker
Materialdaterangepicker
A material Date Range Picker based on wdullaers MaterialDateTimePicker
Stars: ✭ 1,315 (+3360.53%)
Mutual labels:  timepicker, datepicker, datetimepicker
Tempus Dominus
A powerful Date/time picker widget.
Stars: ✭ 6,900 (+18057.89%)
Mutual labels:  datetime, datepicker, datetimepicker
Circularpicker
CircularPicker is helpful for creating a controller aimed to manage any calculated parameter.
Stars: ✭ 73 (+92.11%)
Mutual labels:  datetime, timepicker, datepicker
Datetimepicker
⭐️🎉一个简约、漂亮的日期时间选择器,支持全方位自定义UI
Stars: ✭ 378 (+894.74%)
Mutual labels:  timepicker, datepicker, datetimepicker
Datetimepicker
This is a custom android holo datepicker timepicker
Stars: ✭ 56 (+47.37%)
Mutual labels:  timepicker, datepicker, datetimepicker
Rc Datetime Picker
React component for datetime picker by Moment.js
Stars: ✭ 85 (+123.68%)
Mutual labels:  datetime, datepicker, datetimepicker

📆 Svelty Picker NPM version

Simple date & time picker implemented in svelte.

Features:

  • datepicker
  • timepicker (with meridian support)
  • various formatting options
  • keyboard navigation
  • includes <input> element
  • easily themable
  • restriction by start and end date
  • validator action for <input> using svelte-use-forms (optional)
  • custom element

screenshot

⚙️ Install

npm install svelty-picker

👀 Example

<script>
  import SveltyPicker from 'svelty-picker'
  
  let myDate = '2021-11-11';
</script>

<SveltyPicker inputClasses="form-control" format="yyyy-mm-dd hh:ii" bind:value={myDate}></SveltyPicker>

Try yourself in REPL.

📓 Options

Property Type Default Description
name string date html attribute for underlying <input> element
disabled bool false html attribute for underlying <input> element
placeholder string null html attribute for underlying <input> element
required bool false html attribute for underlying <input> element
value string null string representation of selected value
initialDate Date null initial date object, if you prefer that to value
startDate `string Date` null
endDate `string Date` null
pickerOnly bool false Picker is always visible and input field is then hidden, but still present
theme string sdt-calendar-colors css class defining css variables
mode string auto restrict picker's mode. Possible values: `auto
format string yyyy-mm-dd Format of entered date/time. See format settings for available options
weekStart number 1 number in range 0-6 to select first day of the week. Sunday is 0
inputId string `` id attribute for input element
inputClasses string `` input css class string
todayBtnClasses string sdt-action-btn sdt-today-btn today button css classes
clearBtnClasses string sdt-action-btn sdt-clear-btn clear button css classes
todayBtn bool true Show today button
clearBtn bool true Show clear button
clearToggle bool true Allows to clear selected date when clicking on the same date when in mode='date' or mode='auto' resolving to 'date'
autoclose bool true Hides picker after selection is done. If mode includes time picker, it closes automatically only after minute selection
i18n object en localization object, english is by default
positionFn function internal function used to position picker. Used as action. Acceps following object: { inputEl, visible}, where visible is visible parameter & inputEl is underlying <input> element
validatorAction array null Bind validator action for inner <input> element. Designed to be used with svelte-use-form.

Note: Properties starting by theme to i18n are configurable globally by overriding it in globally available config

import { config } from 'svelty-picker';

// set new locale 
config.i18n = {
  // my localization object
}
// default for all pickers in the app
config.todayBtn = false;

Format settings

Date format can be defined under formatType property. It has two options: standard and php, where standard is the default.

standard format settings:

Format Description Example
d day of the month without leading zeros 1 to 31
dd day of the month, 2 digits with leading zeros 01 to 31
D short textual representation of a weekday (i18n.daysShort) Mon through Sun
DD long textual representation of a weekday (i18n.days) Sunday through Saturday
S English ordinal suffix for the day of the month, (i18n.suffix) st, nd, rd or th. Works well with d
m numeric representation of month without leading zeros 1 to 12
mm numeric representation of the month, 2 digits with leading zeros 01 to 12
M short textual representation of a month, three letters (i18n.monthsShort) Jan through Dec
MM full textual representation of a month, such as January or March (i18n.months) January through December
yy two digit representation of a year 99 or 03
yyyy full numeric representation of a year, 4 digits 1999, 2003
h hour without leading zeros - 24-hour format 0 - 23
hh hour, 2 digits with leading zeros - 24-hour format 00 - 23
H hour without leading zeros - 12-hour format 1 - 12
HH hour, 2 digits with leading zeros - 12-hour format 01 - 12
i minutes, 2 digits with leading zeros 00 - 59
ii alias for i 00 - 59
s seconds, 2 digits with leading zeros 00
ss alias for s 00
p meridian in lower case ('am' or 'pm') - according to locale file (i18n.meridiem) am or pm
P meridian in upper case ('AM' or 'PM') - according to locale file (i18n.meridiem) AM or PM
t timestamp in milliseconds (although milliseconds are always 0). For timestamp in seconds use php format

php format settings:

Format Description Example
d Day of the month, 2 digits with leading zeros 01 to 31
D A textual representation of a day, three letters Mon through Sun
j Day of the month without leading zeros 1 to 31
l A full textual representation of the day of the week Sunday through Saturday
N ISO 8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
F A full textual representation of a month, such as January or March January through December
m Numeric representation of a month, with leading zeros 01 through 12
M A short textual representation of a month, three letters Jan through Dec
n Numeric representation of a month, without leading zeros 1 through 12
Y A full numeric representation of a year, at least 4 digits 0787, 1999, 2003
y A two digit representation of a year 99 or 03
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
g 12-hour format of an hour without leading zeros 1 through 12
G 24-hour format of an hour without leading zeros 0 through 23
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros 00 through 23
i Minutes with leading zeros 00 to 59
s Seconds with leading zeros 00
U timestamp in seconds. For timestamp with miliseconds use standard format

CSS variables

/** defaults */
.sdt-calendar-colors {
  --sdt-primary: #286090;
  --sdt-color: #000;
  --sdt-bg-main: #fff;
  --sdt-bg-today: var(--sdt-primary);
  --sdt-bg-clear: #dc3545;
  --sdt-today-bg: #1e486d;
  --sdt-clear-color: #dc3545;
  --sdt-btn-bg-hover: #eee;
  --sdt-btn-header-bg-hover: #dfdfdf;
  --sdt-clock-bg: #eeeded;
  --sdt-clock-bg-minute: rgb(238, 237, 237, 0.25);
  --sdt-clock-bg-shadow: 0 0 128px 2px #ddd inset;
  --sdt-shadow: #ccc;
}

🗯️ Events

Component emits input, change and blur events.

  • input is dispatched on <input> element therefore you can get current value like from every native event:
  • change event is using Svelte's eventDispatcher, therefore triggered event contains detail property
<script>
function onInput(event) {
  console.log(event.target.value) // logs currently selected date or empty string
}

function onChange(event) {
  console.log(event.detail) // logs currently selected date or null
}
</script>

<SveltyPicker on:input={onInput} on:change={onChange}></SveltyPicker>

🌐 Localization

Localization file has following structure.

export const en = {
  days:        ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
  daysShort:   ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  daysMin:     ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'],
  months:      ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  meridiem:    ['am', 'pm'],
  suffix:      ['st', 'nd', 'rd', 'th'],
  todayBtn:    'Today',
  clearBtn:    'Clear',
  timeView:    'Show time view',
  backToDate:  'Back to calendar view'
}

PRs for extending built-in localization are welcome 🥳

🏆 Thanks to:

Licence:

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].