File tree Expand file tree Collapse file tree 5 files changed +67
-9
lines changed
Expand file tree Collapse file tree 5 files changed +67
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @sjsf/flowbite-theme " : minor
3+ ---
4+
5+ Use ` Datepicker ` for ` date ` input type
Original file line number Diff line number Diff line change 6868 "eslint-config-prettier" : " catalog:" ,
6969 "eslint-plugin-svelte" : " catalog:" ,
7070 "flowbite" : " ^2.5.2" ,
71- "flowbite-svelte" : " ^0.47.1 " ,
71+ "flowbite-svelte" : " ^0.47.3 " ,
7272 "globals" : " catalog:" ,
7373 "postcss" : " catalog:" ,
7474 "prettier" : " catalog:" ,
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import { type WidgetProps } from ' @sjsf/form' ;
33 import Input , { type InputProps } from ' flowbite-svelte/Input.svelte' ;
4+ import Datepicker , { type DatepickerProps } from ' flowbite-svelte/Datepicker.svelte' ;
45
56 let { value = $bindable (), attributes }: WidgetProps <' text' > = $props ();
7+
8+ const date = {
9+ get value() {
10+ return value ? new Date (value ) : null ;
11+ },
12+ set value(v ) {
13+ if (attributes .readonly ) {
14+ return ;
15+ }
16+ if (! v ) {
17+ value = undefined ;
18+ return ;
19+ }
20+ value = v .toLocaleDateString (' en-CA' );
21+ }
22+ };
623 </script >
724
8- <Input type ="text" bind:value {...attributes as InputProps } />
25+ {#if attributes .type === ' date' }
26+ <div class =" w-full" >
27+ <Datepicker
28+ bind:value ={date .value }
29+ showActionButtons
30+ autohide ={false }
31+ {...attributes as DatepickerProps }
32+ />
33+ </div >
34+ {:else }
35+ <Input type ="text" bind:value {...attributes as InputProps } />
36+ {/if }
Original file line number Diff line number Diff line change 11import { SvelteMap } from "svelte/reactivity" ;
2-
32import type {
43 Schema ,
54 UiSchema ,
@@ -11,6 +10,7 @@ export const states = (schema: Schema): Schema => ({
1110 type : "object" ,
1211 properties : {
1312 default : schema ,
13+ readonly : schema ,
1414 disabled : schema ,
1515 error : schema ,
1616 } ,
@@ -61,11 +61,29 @@ export const schema: Schema = {
6161 multiSelect : states ( uniqueArray ) ,
6262 text : states ( text ) ,
6363 textarea : states ( text ) ,
64+ date : states ( text )
6465 } ,
6566} ;
6667
6768export const uiStates = ( uiSchema : UiSchema ) : UiSchema => ( {
68- default : uiSchema ,
69+ default : {
70+ ...uiSchema ,
71+ "ui:options" : {
72+ ...uiSchema [ "ui:options" ] ,
73+ input : {
74+ placeholder : "placeholder" ,
75+ } ,
76+ }
77+ } ,
78+ readonly : {
79+ ...uiSchema ,
80+ "ui:options" : {
81+ input : {
82+ ...uiSchema [ "ui:options" ] ?. input ,
83+ readonly : true ,
84+ }
85+ }
86+ } ,
6987 disabled : {
7088 ...uiSchema ,
7189 "ui:options" : {
@@ -103,6 +121,13 @@ export const uiSchema: UiSchemaRoot = {
103121 textarea : uiStates ( {
104122 "ui:widget" : "textarea" ,
105123 } ) ,
124+ date : uiStates ( {
125+ "ui:options" : {
126+ input : {
127+ type : "date" ,
128+ }
129+ }
130+ } )
106131} ;
107132
108133export const errors = new SvelteMap (
You can’t perform that action at this time.
0 commit comments