···11# Changelog
2233+## Next
44+- Add `timePrecision` prop for showing a time picker (@nihanmubashshir)
55+36## 2.8.0 - 2023 Sep 29
47- Add date to `select` event detail
58
+4
src/lib/DateInput.svelte
···9494 /** Wait with updating the date until a date is selected */
9595 export let browseWithoutSelecting = false
96969797+ /** Show a time picker with the specified precision */
9898+ export let timePrecision: 'minute' | 'second' | 'millisecond' | null = null
9999+97100 // handle on:focusout for parent element. If the parent element loses
98101 // focus (e.g input element), visible is set to false
99102 function onFocusOut(e: FocusEvent) {
···222225 {max}
223226 {locale}
224227 {browseWithoutSelecting}
228228+ {timePrecision}
225229 />
226230 </div>
227231 {/if}
+13-1
src/lib/DatePicker.svelte
···11<script lang="ts">
22+ import TimePicker from './TimePicker.svelte'
23 import { getMonthLength, getCalendarDays, type CalendarDay } from './date-utils.js'
34 import { getInnerLocale, type Locale } from './locale.js'
45 import { createEventDispatcher } from 'svelte'
···2122 value = cloneDate(browseDate)
2223 }
2324 }
2525+2626+ /** Set the browseDate */
2427 function browse(d: Date) {
2528 browseDate = clamp(d, min, max)
2629 if (!browseWithoutSelecting && value) {
···32353336 /** Default Date to use */
3437 const defaultDate = new Date()
3838+3939+ /** Show a time picker with the specified precision */
4040+ export let timePrecision: 'minute' | 'second' | 'millisecond' | null = null
35413642 /** The earliest year the user can select */
3743 export let min = new Date(defaultDate.getFullYear() - 20, 0, 1)
···177183 }
178184 function keydown(e: KeyboardEvent) {
179185 let shift = e.shiftKey || e.altKey
180180- if ((e.target as HTMLElement)?.tagName === 'SELECT') {
186186+ if (
187187+ (e.target as HTMLElement)?.tagName === 'SELECT' ||
188188+ (e.target as HTMLElement)?.tagName === 'SPAN'
189189+ ) {
190190+ // Ignore date/month <select> & TimePicker <input>
181191 return
182192 }
183193 if (shift) {
···317327 {/each}
318328 </div>
319329 {/each}
330330+331331+ <TimePicker {timePrecision} {browseDate} {browse} />
320332 </div>
321333</div>
322334
···77 // had to import it this way to avoid errors
88 // in `npm run build:site` or `npm run check`:
99 import hy from 'date-fns/locale/hy/index.js'
1010-1110 let value: Date
1211 let min: Date
1312 let max: Date
1413 let locale = localeFromDateFnsLocale(hy)
1514 let browseWithoutSelecting: boolean
1515+ let timePrecision: 'minute' | 'second' | 'millisecond' | null = 'millisecond'
1616</script>
17171818<Split>
1919 <div class="left" slot="left">
2020- <DatePicker bind:value bind:min bind:max {locale} bind:browseWithoutSelecting />
2020+ <DatePicker bind:value bind:min bind:max {locale} bind:browseWithoutSelecting {timePrecision} />
2121 </div>
2222 <div slot="right">
2323 <h3 class="no-top">Props</h3>
···2626 <Prop label="max" bind:value={max} />
2727 <Prop label="locale">date-fns <code>hy</code></Prop>
2828 <Prop label="browseWithoutSelecting" bind:value={browseWithoutSelecting} />
2929+ <Prop
3030+ label="timePrecision"
3131+ bind:value={timePrecision}
3232+ values={[null, 'minute', 'second', 'millisecond']}>{timePrecision}</Prop
3333+ >
2934 </div>
3035</Split>
+23-21
src/routes/docs/+page.md
···29293030### <a id="props" />Props
31313232-| Prop | Type | Description |
3333-| :----------------------- | :----------- | :---------------------------------------------------------- |
3434-| `value` | Date \| null | Date value |
3535-| `min` | Date | The earliest value the user can select |
3636-| `max` | Date | The latest value the user can select |
3737-| `placeholder` | string | Placeholder used when date value is null |
3838-| `valid` | bool | Whether the text is valid |
3939-| `format` | string | Format string |
4040-| `visible` | bool | Whether the date popup is visible |
4141-| `disabled` | bool | Disable the input |
4242-| `closeOnSelection` | bool | Close the date popup when a date is selected |
4343-| `browseWithoutSelecting` | bool | Wait with updating the date until a value is selected |
4444-| `dynamicPositioning` | bool | Dynamicly postions the date popup to best fit on the screen |
4545-| `locale` | Locale | Locale object for internationalization |
3232+| Prop | Type | Description |
3333+| :----------------------- | :-------------------------------------------- | :---------------------------------------------------------- |
3434+| `value` | Date \| null | Date value |
3535+| `min` | Date | The earliest value the user can select |
3636+| `max` | Date | The latest value the user can select |
3737+| `placeholder` | string | Placeholder used when date value is null |
3838+| `timePrecision` | "minute" \| "second" \| "millisecond" \| null | Show a time picker with the specified precision |
3939+| `valid` | bool | Whether the text is valid |
4040+| `format` | string | Format string |
4141+| `visible` | bool | Whether the date popup is visible |
4242+| `disabled` | bool | Disable the input |
4343+| `closeOnSelection` | bool | Close the date popup when a date is selected |
4444+| `browseWithoutSelecting` | bool | Wait with updating the date until a value is selected |
4545+| `dynamicPositioning` | bool | Dynamicly postions the date popup to best fit on the screen |
4646+| `locale` | Locale | Locale object for internationalization |
46474748#### <a id="format-string" />Format string
4849···65666667### <a id="datepicker-props" />Props
67686868-| Prop | Type | Description |
6969-| :----------------------- | :----------- | :--------------------------------------------------- |
7070-| `value` | Date \| null | Date value |
7171-| `min` | Date | The earliest year the user can select |
7272-| `max` | Date | The latest year the user can select |
7373-| `locale` | Locale | Locale object for internationalization |
7474-| `browseWithoutSelecting` | bool | Wait with updating the date until a date is selected |
6969+| Prop | Type | Description |
7070+| :----------------------- | :-------------------------------------------- | :--------------------------------------------------- |
7171+| `value` | Date \| null | Date value |
7272+| `min` | Date | The earliest year the user can select |
7373+| `max` | Date | The latest year the user can select |
7474+| `timePrecision` | "minute" \| "second" \| "millisecond" \| null | Show a time picker with the specified precision |
7575+| `locale` | Locale | Locale object for internationalization |
7676+| `browseWithoutSelecting` | bool | Wait with updating the date until a date is selected |
75777678## <a id="internationalization" />Internationalization
7779