improve time input AM/PM selector, partial text implementation
This commit is contained in:
@@ -3,19 +3,24 @@
|
||||
import Label from './Label.svelte';
|
||||
import StyledRawInput from './StyledRawInput.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import moment from 'moment';
|
||||
|
||||
let {
|
||||
name,
|
||||
label,
|
||||
value = $bindable(''),
|
||||
formattedValue = $bindable(''),
|
||||
required,
|
||||
invalidMessage = 'Please select a time'
|
||||
invalidMessage = 'Please select a time',
|
||||
showText = false
|
||||
}: {
|
||||
name: string;
|
||||
label?: string;
|
||||
value?: string;
|
||||
formattedValue?: string;
|
||||
required?: boolean;
|
||||
invalidMessage?: string;
|
||||
showText?: boolean;
|
||||
} = $props();
|
||||
|
||||
let ampm: 'AM' | 'PM' = $state('AM');
|
||||
@@ -155,6 +160,8 @@
|
||||
|
||||
value = `${prefixZero((hourValue + (ampmLocal === 'PM' ? 12 : 0)).toString())}:${prefixZero(minuteValue.toString())}`;
|
||||
updateHiddenInput();
|
||||
|
||||
// update formatted value
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -298,8 +305,11 @@
|
||||
<div class="flex flex-col">
|
||||
<!-- AM Button -->
|
||||
<button
|
||||
class={['ampm rounded-t-sm border', ampm === 'AM' && 'selected']}
|
||||
onclick={() => (ampm = 'AM')}
|
||||
class={['ampm rounded-t-sm border', ampm === 'AM' && 'selected ring-1 ring-blue-300']}
|
||||
onclick={() => {
|
||||
ampm = 'AM';
|
||||
updateValue();
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') minuteInput?.focus();
|
||||
else if (e.key === 'ArrowDown' || e.key === 'ArrowRight') pmButton.focus();
|
||||
@@ -311,8 +321,14 @@
|
||||
|
||||
<!-- PM Button -->
|
||||
<button
|
||||
class={['ampm rounded-b-sm border-r border-b border-l', ampm === 'PM' && 'selected']}
|
||||
onclick={() => (ampm = 'PM')}
|
||||
class={[
|
||||
'ampm rounded-b-sm border-r border-b border-l',
|
||||
ampm === 'PM' && 'selected ring-1 ring-blue-300'
|
||||
]}
|
||||
onclick={() => {
|
||||
ampm = 'PM';
|
||||
updateValue();
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') amButton?.focus();
|
||||
}}
|
||||
@@ -351,7 +367,7 @@
|
||||
@apply border-accent dark:border-accent/50 cursor-pointer px-3 py-1 font-medium;
|
||||
|
||||
&.selected {
|
||||
@apply bg-accent text-background dark:bg-accent/30 dark:text-background/90;
|
||||
@apply bg-accent text-background dark:bg-accent/30 dark:text-background/90 ring-1 ring-blue-600 dark:ring-blue-300;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user