Skip to content

Commit 19b91f4

Browse files
committed
[flowbite] Use Datepicker for date input type
1 parent 23f37ab commit 19b91f4

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

.changeset/strange-buses-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sjsf/flowbite-theme": minor
3+
---
4+
5+
Use `Datepicker` for `date` input type

packages/flowbite-theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
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:",
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
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}

packages/testing/src/demo/widgets.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SvelteMap } from "svelte/reactivity";
2-
32
import 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

6768
export 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

108133
export const errors = new SvelteMap(

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)