### Install Svelty Picker
Source: https://svelty-picker.vercel.app/
Install the latest version of svelty-picker using npm. This is the standard installation command.
```bash
npm install svelty-picker
```
--------------------------------
### SveltyPicker Date Binding Example
Source: https://svelty-picker.vercel.app/working-with-dates
This example demonstrates how to bind the `value` property of SveltyPicker using function binding to format and parse dates. It ensures that the internal `date` variable is kept in sync with the picker's selected value.
```svelte
Selected date: {date}
{
return formatDate(date, 'yyyy/mm/dd', en, 'standard');
},
(v) => {
date = v ? parseDate(v, 'yyyy/mm/dd', en, 'standard') : null;
}
}
/>
```
```svelte
Selected date: {date}
{
return formatDate(date, 'yyyy/mm/dd', en, 'standard');
},
(v) => {
date = v ? parseDate(v, 'yyyy/mm/dd', en, 'standard') : null;
}
}
/>
```
--------------------------------
### Install Svelty Picker for Svelte 4
Source: https://svelty-picker.vercel.app/
Install a specific version of svelty-picker compatible with Svelte 4. Use this if you are working with an older Svelte version.
```bash
npm install svelty-picker@5.2.11
```
--------------------------------
### Applying Global and Local Svelty Picker Configurations
Source: https://svelty-picker.vercel.app/global-config
Demonstrates how to set global configuration options for Svelty Picker, such as language and week start day, and how to override these settings for individual picker instances.
```svelte
My german picker (global)
Japanese override
```
```svelte
My german picker (global)
Japanese override
```
--------------------------------
### Svelty Picker Component Examples
Source: https://svelty-picker.vercel.app/modes-and-formats
Demonstrates different configurations of the SveltyPicker component, including matching and differing format/displayFormat properties, and a time-only format.
```svelte
Format === displayFormat Internal value: {valueDefault}
Format !== displayFormat Internal value: {valueDifferent}
Time only format: Internal value: {valueTimeOnly}
```
--------------------------------
### Configure Svelty Picker with German Locale and Saturday Week Start
Source: https://svelty-picker.vercel.app/localization
This snippet demonstrates how to globally configure the Svelty Picker to use the German locale and set the week to start on Saturday. This configuration affects all Svelty Picker instances on the page unless overridden.
```javascript
import SveltyPicker, { config } from 'svelty-picker';
import { de, jp } from 'svelty-picker/i18n';
// all pickers set to german and to start week on saturday
config.i18n = de;
config.weekStart = 6;
```
--------------------------------
### Migrating Events to Callback Properties
Source: https://svelty-picker.vercel.app/migration-guide
Event dispatchers have been replaced by event callback properties. For example, `on:change` is now `onChange`.
```svelte
// [!code --]
// [!code ++]
```
--------------------------------
### Svelty Picker Config Type Definition
Source: https://svelty-picker.vercel.app/global-config
Defines the structure of the global configuration object for Svelty Picker. This includes settings for theme, date formatting, minute increments, week start day, CSS classes, and internationalization.
```typescript
type Config = {
theme: string;
format: string;
formatType: string;
displayFormat: string?;
displayFormatType: string?;
minuteIncrement: number;
weekStart: number;
inputClasses: string;
todayBtnClasses: string;
clearBtnClasses: string;
hourOnly: boolean;
todayBtn: boolean;
clearBtn: boolean;
autocommit: boolean;
i18n: i18nType;
}
```
```typescript
type Config = {
theme: string;
format: string;
formatType: string;
displayFormat: string?;
displayFormatType: string?;
minuteIncrement: number;
weekStart: number;
inputClasses: string;
todayBtnClasses: string;
clearBtnClasses: string;
hourOnly: boolean;
todayBtn: boolean;
clearBtn: boolean;
autocommit: boolean;
i18n: i18nType;
}
```
--------------------------------
### Svelty Picker Default Configuration
Source: https://svelty-picker.vercel.app/global-config
Provides the default values for the Svelty Picker configuration. These settings are applied if no custom configuration is specified.
```javascript
export default {
theme: 'sdt-calendar-colors',
format: 'yyyy-mm-dd',
formatType: 'standard',
displayFormat: null,
displayFormatType: null,
minuteIncrement: 1,
weekStart: 1,
inputClasses: '',
todayBtnClasses: 'sdt-action-btn sdt-today-btn',
clearBtnClasses: 'sdt-action-btn sdt-clear-btn',
hourOnly: false,
todayBtn: true,
clearBtn: true,
autocommit: true,
i18n: en
}
```
```javascript
export default {
theme: 'sdt-calendar-colors',
format: 'yyyy-mm-dd',
formatType: 'standard',
displayFormat: null,
displayFormatType: null,
minuteIncrement: 1,
weekStart: 1,
inputClasses: '',
todayBtnClasses: 'sdt-action-btn sdt-today-btn',
clearBtnClasses: 'sdt-action-btn sdt-clear-btn',
hourOnly: false,
todayBtn: true,
clearBtn: true,
autocommit: true,
i18n: en
}
```
--------------------------------
### Default Action Row Implementation
Source: https://svelty-picker.vercel.app/snippets
Provides the default Svelte implementation for the 'actionRow' snippet, rendering 'Today', 'Clear', 'Ok', and 'Cancel' buttons based on configuration.
```svelte
{#snippet action_row({
autocloseSupported,
todayBtnClasses,
clearBtnClasses,
onCancel,
onConfirm,
onClear,
onToday,
isTodayDisabled,
i18n,
currentMode
})}
{#if !autocloseSupported || true}
{/if}
{/snippet}
```
--------------------------------
### Light Theme CSS Variables for Svelty Picker
Source: https://svelty-picker.vercel.app/theme
Defines CSS variables for the light theme, providing a clean and standard appearance. Customizes elements like the clock, table, and buttons for a light interface.
```css
```
--------------------------------
### Migrating initialDate Property
Source: https://svelty-picker.vercel.app/migration-guide
The `initialDate` property is deprecated in favor of Svelte 5's function bindings. Use `bind:value` directly for more powerful date handling.
```svelte
// [!code --]
// [!code ++]
```
--------------------------------
### Date Helper Functions
Source: https://svelty-picker.vercel.app/working-with-dates
These functions are used for converting between Date objects and strings. They are essential for managing date values, especially when the library expects string inputs.
```javascript
/**
* String -> date
*
* @param {Date|string} date
* @param {string} format
* @param {i18nType} i18n
* @param {string} type
* @returns {Date}
*/
export function parseDate(date, format, i18n, type) { /* ... */}
/**
* Date -> string
*
* @param {Date} date
* @param {string} format
* @param {i18nType} i18n
* @param {string} type
* @returns {string}
*/
export function formatDate(date, format, i18n, type) { /* ... */}
```
```javascript
/**
* String -> date
*
* @param {Date|string} date
* @param {string} format
* @param {i18nType} i18n
* @param {string} type
* @returns {Date}
*/
export function parseDate(date, format, i18n, type) { /* ... */}
/**
* Date -> string
*
* @param {Date} date
* @param {string} format
* @param {i18nType} i18n
* @param {string} type
* @returns {string}
*/
export function formatDate(date, format, i18n, type) { /* ... */}
```
--------------------------------
### Dark Theme CSS Variables for Svelty Picker
Source: https://svelty-picker.vercel.app/theme
Defines CSS variables for the dark theme, including background, shadow, and text colors. Customizes elements like the clock, table, and buttons for a dark interface.
```css
```
--------------------------------
### Add Custom Icon with Children Snippet
Source: https://svelty-picker.vercel.app/snippets
Use the 'children' snippet to add custom icons, such as an SVG, to the date picker. Ensure proper positioning of the icon using CSS.
```svelte
```
```svelte
```
--------------------------------
### Disabling Dates with startDate and endDate
Source: https://svelty-picker.vercel.app/disabling-dates
Use `startDate` and `endDate` to define an inclusive range of selectable dates. It's recommended to use string formats that match the picker's `format` property.
```javascript
```
--------------------------------
### Svelty Picker CSS Variables
Source: https://svelty-picker.vercel.app/theme
This snippet shows the default CSS variables for customizing the Svelty Picker component. Use these variables to modify colors, shadows, and other visual properties.
```css
:root {
/* general */
--sdt-bg-main: #fff; /** wrap background color */
--sdt-shadow-color: #ccc; /** wrap shadow color */
--sdt-wrap-shadow: 0 1px 6px var(--sdt-shadow-color); /** wrap shadow settings */
--sdt-radius: 4px; /** wrap radius */
--sdt-color: #000; /** data to select(e.g date/time) text color (except header & buttons) */
--sdt-color-selected: #fff; /** selected data(e.g date/time) text color */
--sdt-header-color: #000; /** header items color (e.g. text & buttons) */
--sdt-header-btn-bg-hover: #dfdfdf; /** header items hover background color */
--sdt-bg-selected: #286090; /** selected data(e.g date/time) background color */
/* action buttons */
--sdt-today-bg: #1e486d; /** date picker today button hover background color */
--sdt-today-color: var(--sdt-bg-main); /** date picker today button text & border color */
--sdt-clear-color: #dc3545; /** clear button text & border color */
--sdt-clear-bg: transparent; /** clear button background color */
--sdt-clear-hover-color: var(--sdt-bg-main); /** clear button hover text color */
--sdt-clear-hover-bg: #dc3545; /** clear button hover background color */
/* time picker */
--sdt-clock-selected-bg: var(--sdt-bg-selected); /** selected time background color */
--sdt-clock-bg: #eeeded; /** time picker inner circle background color */
--sdt-clock-color: var(--sdt-color); /** time picker text color (watch "--sdt-color") */
--sdt-clock-color-hover: var(--sdt-color); /** time picker hover text color (watch "--sdt-color") */
--sdt-clock-time-bg: transparent; /** time picker time background color */
--sdt-clock-time-bg-hover: transparent; /** time picker time selection hover background color */
--sdt-clock-disabled-time: #b22222; /** disabled time picker time text color */
--sdt-clock-disabled-time-bg: #eee; /** disabled time picker time background color */
/* date picker */
--sdt-table-selected-bg: var(--sdt-bg-selected); /** selected date background color */
--sdt-table-disabled-date: #b22222; /** disabled dates text color */
--sdt-table-disabled-date-bg: #eee; /** disabled dates background color */
--sdt-table-bg: transparent; /** date picker inner table background color */
--sdt-table-data-bg-hover: #eee; /** table selection data hover background color */
--sdt-table-today-indicator: #ccc; /** date picker current day marker color */
}
```
--------------------------------
### Define Action Row Snippet Type
Source: https://svelty-picker.vercel.app/snippets
Defines the type for the 'actionRow' snippet, outlining the available properties for customizing the button row below the picker.
```typescript
Snippet<[ prop: {
autocloseSupported: boolean,
todayBtnClasses: string,
clearBtnClasses: string,
onCancel: function,
onConfirm: function,
onClear: function,
onToday: function,
isTodayDisabled: boolean,
i18n: import('svelty-picker/i18n').i18nType,
currentMode: string
}]>
```
```typescript
Snippet<[ prop: {
autocloseSupported: boolean,
todayBtnClasses: string,
clearBtnClasses: string,
onCancel: function,
onConfirm: function,
onClear: function,
onToday: function,
isTodayDisabled: boolean,
i18n: import('svelty-picker/i18n').i18nType,
currentMode: string
}]>
```
--------------------------------
### onChange Callback Type Definition
Source: https://svelty-picker.vercel.app/properties
Defines the structure of the object passed to the `onChange` event callback. It includes the selected value in various formats and the type of event that triggered the change.
```typescript
type onChangeProperty = {
value: string|string[],
dateValue: Date|Date[],
displayValue: string,
valueFormat: string,
displayFormat: string,
event: 'date'|'hour'|'minute'|'datetime' // which event triggered the callback
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.