|
11 | 11 | adornment, |
12 | 12 | selectedItem = $bindable(), |
13 | 13 | handleClick, |
14 | | - prefix = "" |
| 14 | + prefix, |
| 15 | + context = "" |
15 | 16 | }: { |
16 | 17 | config: any; |
17 | 18 | item: any; |
|
21 | 22 | selectedItem?: any; |
22 | 23 | handleClick: (value: any) => void; |
23 | 24 | prefix?: string; |
| 25 | + context?: string; |
24 | 26 | } = $props(); |
25 | 27 |
|
26 | 28 | const currYear = new Date().getFullYear(); |
|
41 | 43 | ]; |
42 | 44 | const currMonth = monthNames[currMonthIndex]; |
43 | 45 | const currDate = new Date().getDate(); |
44 | | - const isSelected = $derived(selectedItem == prefix + item); |
| 46 | + const isSelected = $derived(selectedItem == context + item); |
45 | 47 | const state = $derived.by(() => { |
46 | 48 | switch (config.itemType) { |
47 | 49 | case Itemtype.YEAR: |
|
51 | 53 | }; |
52 | 54 | case Itemtype.MONTH: |
53 | 55 | return { |
54 | | - isToday: currYear == Number(prefix) && currMonth == item, |
| 56 | + isToday: currYear == Number(context) && currMonth == item, |
55 | 57 | isPast: |
56 | | - currYear > Number(prefix) || |
57 | | - (currYear == Number(prefix) && |
| 58 | + currYear > Number(context) || |
| 59 | + (currYear == Number(context) && |
58 | 60 | currMonthIndex > monthNames.indexOf(item)) |
59 | 61 | }; |
60 | 62 | case Itemtype.DAY: { |
61 | | - const firstAlphIndex = getFirstAlphabetPosition(prefix); |
| 63 | + const firstAlphIndex = getFirstAlphabetPosition(context); |
62 | 64 | return { |
63 | 65 | isToday: |
64 | | - currYear == Number(prefix.slice(0, firstAlphIndex)) && |
65 | | - currMonth == prefix.slice(-3) && |
| 66 | + currYear == Number(context.slice(0, firstAlphIndex)) && |
| 67 | + currMonth == context.slice(-3) && |
66 | 68 | currDate == Number(item), |
67 | 69 | isPast: |
68 | | - currYear > Number(prefix.slice(0, firstAlphIndex)) || |
69 | | - (currYear == Number(prefix.slice(0, firstAlphIndex)) && |
70 | | - currMonthIndex > monthNames.indexOf(prefix.slice(-3))) || |
71 | | - (currYear == Number(prefix.slice(0, firstAlphIndex)) && |
72 | | - currMonthIndex == monthNames.indexOf(prefix.slice(-3)) && |
| 70 | + currYear > Number(context.slice(0, firstAlphIndex)) || |
| 71 | + (currYear == Number(context.slice(0, firstAlphIndex)) && |
| 72 | + currMonthIndex > monthNames.indexOf(context.slice(-3))) || |
| 73 | + (currYear == Number(context.slice(0, firstAlphIndex)) && |
| 74 | + currMonthIndex == monthNames.indexOf(context.slice(-3)) && |
73 | 75 | currDate > Number(item)) |
74 | 76 | }; |
75 | 77 | } |
|
90 | 92 | )} |
91 | 93 | style="height:{config.itemHeight}px;" |
92 | 94 | {...{ |
93 | | - [`data-${config.itemType}`]: `${prefix}${item}` |
| 95 | + [`data-${config.itemType}`]: `${context}${item}` |
94 | 96 | }} |
95 | 97 | onclick={() => { |
96 | | - handleClick(prefix + item); |
| 98 | + handleClick(context + item); |
97 | 99 | }} |
98 | 100 | onkeydown={(event) => { |
99 | 101 | if (event.key === "Enter") { |
100 | | - handleClick(prefix + item); |
| 102 | + handleClick(context + item); |
101 | 103 | } |
102 | 104 | }} |
103 | 105 | > |
104 | 106 | <span class="flex w-full items-center justify-center"> |
105 | 107 | <span class="relative inline-flex items-center justify-center"> |
106 | | - <span>{label ?? item}</span> |
| 108 | + {#if prefix} |
| 109 | + <span |
| 110 | + class={cn( |
| 111 | + "absolute right-full mr-1 top-1/2 -translate-y-1/2 rounded-md px-1 py-0.5 text-b5 leading-none tabular-nums", |
| 112 | + { "bg-aps3 text-aps1": isSelected }, |
| 113 | + { "bg-bgs3 text-fgs3": !isSelected } |
| 114 | + )} |
| 115 | + > |
| 116 | + {prefix} |
| 117 | + </span> |
| 118 | + {/if} |
| 119 | + <span class="tabular-nums">{label ?? item}</span> |
107 | 120 | {#if suffix} |
108 | 121 | <span |
109 | 122 | class={cn( |
110 | | - "absolute left-full ml-1 top-1/2 -translate-y-1/2 rounded-full px-1.5 py-0.5 text-b5 leading-none", |
| 123 | + "absolute left-full ml-1 top-1/2 -translate-y-1/2 rounded-md px-1 py-0.5 text-b5 leading-none tabular-nums", |
111 | 124 | { "bg-aps3 text-aps1": isSelected }, |
112 | 125 | { "bg-bgs3 text-fgs3": !isSelected } |
113 | 126 | )} |
|
0 commit comments