hamzus-ui 0.0.134 → 0.0.136

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ <script>
2
+ import ScrollArea from '../ScrollArea/ScrollArea.svelte';
3
+ import Button from '../Button/Button.svelte';
4
+ import * as DropdownMenu from '../DropdownMenu';
5
+
6
+ export let name = '';
7
+ export let label = '';
8
+ export let value = '';
9
+ export let variant = '';
10
+ export let onChange = undefined;
11
+ export let required = false;
12
+
13
+ let targetYear = '';
14
+
15
+
16
+ const yearList = getYearList();
17
+
18
+ function getYearList(startYear = 1997) {
19
+ const currentYear = new Date().getFullYear();
20
+ return Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i);
21
+ }
22
+
23
+ function handleSelectYear(newValue) {
24
+ targetYear = newValue;
25
+
26
+ checkIfComplete();
27
+ }
28
+
29
+ function checkIfComplete() {
30
+ if (!targetYear) {
31
+ value = '';
32
+ return;
33
+ }
34
+ value = `${targetYear}`;
35
+
36
+ if (onChange !== undefined) {
37
+ onChange(value);
38
+ }
39
+ }
40
+ </script>
41
+
42
+
43
+ <div class="date-input-container {variant === "collapse" ? "collapse" : ""}">
44
+ {#if label}
45
+ <h5>
46
+ {label}
47
+ {#if required}
48
+ <span style="color:var(--red)">*</span>
49
+ {/if}
50
+ </h5>
51
+ {/if}
52
+ <div class="date-input">
53
+ <DropdownMenu.Root triggerFullWidth direction="bottom-left">
54
+ <DropdownMenu.Trigger slot="trigger">
55
+ <Button style="width:100%;" variant="outline">
56
+ <input class="date-input-value" {required} type="text" style="display: none;" {name} {value} />
57
+ <h4>{targetYear || 'aaaa'}</h4>
58
+ </Button>
59
+ </DropdownMenu.Trigger>
60
+ <DropdownMenu.Content slot="content" width="var(--hamzus-tigger-width)">
61
+ <div class="content">
62
+ <ScrollArea proximity={10} style="max-height:350px;">
63
+ {#each yearList as year}
64
+ <Button
65
+ onClick={() => {
66
+ handleSelectYear(year);
67
+ }}
68
+ style="width:100%;"
69
+ variant="ghost"
70
+ ><h4 style={targetYear == year ? 'color:var(--accent);' : ''}>{year}</h4></Button
71
+ >
72
+ {/each}
73
+ </ScrollArea>
74
+ </div>
75
+ </DropdownMenu.Content>
76
+ </DropdownMenu.Root>
77
+ </div>
78
+ </div>
79
+
80
+ <style>
81
+ .date-input-container.collapse {
82
+ display: flex;
83
+ flex-direction: column;
84
+ padding: var(--pad-s);
85
+ background-color: var(--bg-2);
86
+ border-radius: var(--radius-l);
87
+ }
88
+ .date-input-container.collapse .date-input {
89
+ padding: 0px;
90
+ }
91
+ .date-input {
92
+ display: flex;
93
+ flex-direction: column;
94
+ padding: var(--pad-s);
95
+ background-color: var(--bg-2);
96
+ border-radius: var(--radius-l);
97
+ }
98
+
99
+ .date-input:hover {
100
+ background-color: var(--bg-2);
101
+ }
102
+ .content {
103
+ display: flex;
104
+ max-height: 350px;
105
+ }
106
+
107
+ :global(button:has(.date-input-value:user-invalid)) {
108
+ border: 1px solid var(--red);
109
+ background-color: var(--red-b);
110
+ }
111
+ </style>