Skip to content

Commit 92b952d

Browse files
committed
Updates to Ui.Calendar
- Fix spacing of header items to be in center of the rows. - Allow the days to fill their cells. - Comapre selected days with normalization. - Allow showing multiple selected days.
1 parent aa6ead8 commit 92b952d

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

source/Calendar.Cell.mint

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ component Ui.Calendar.Cell {
1515
/* Whether or not the cell is active (selectable). */
1616
property active : Bool = false
1717

18+
/* Whether or not the component is readonly. */
19+
property readonly : Bool = false
20+
1821
/* The day. */
1922
property day : Time
2023

@@ -28,16 +31,18 @@ component Ui.Calendar.Cell {
2831
display: flex;
2932

3033
cursor: pointer;
31-
height: 2em;
32-
width: 2em;
34+
min-height: 2em;
35+
min-width: 2em;
36+
height: 100%;
37+
width: 100%;
3338

3439
if (active) {
3540
opacity: 1;
3641
} else {
3742
opacity: 0.2;
3843
}
3944

40-
if (disabled) {
45+
if (disabled || readonly) {
4146
pointer-events: none;
4247
}
4348

source/Calendar.mint

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ component Ui.Calendar {
66
/* The change event handler. */
77
property onChange : Function(Time, Promise(Never, Void)) = Promise.never1
88

9+
/* The days to highlight as selected. */
10+
property selectedDays : Set(Time) = Set.empty()
11+
912
/* Whether or not to trigger the `onMonthChange` event if clicking on a day in an other month. */
1013
property changeMonthOnSelect : Bool = false
1114

@@ -24,6 +27,9 @@ component Ui.Calendar {
2427
/* Whether or not the component is disabled. */
2528
property disabled : Bool = false
2629

30+
/* Whether or not the component is readonly. */
31+
property readonly : Bool = false
32+
2733
/* Styles for the base. */
2834
style base {
2935
-moz-user-select: none;
@@ -53,6 +59,8 @@ component Ui.Calendar {
5359
/* Style for the table. */
5460
style table {
5561
grid-template-columns: repeat(7, 1fr);
62+
justify-items: center;
63+
align-items: center;
5664
grid-gap: 0.3125em;
5765
display: grid;
5866
width: 100%;
@@ -88,7 +96,7 @@ component Ui.Calendar {
8896

8997
/* Style for the day names. */
9098
style dayNames {
91-
justify-content: space-between;
99+
justify-content: space-around;
92100
white-space: nowrap;
93101
display: flex;
94102
line-height: 1;
@@ -185,11 +193,30 @@ component Ui.Calendar {
185193
}
186194

187195
for (cell of actualDays) {
188-
<Ui.Calendar.Cell
189-
active={Array.any((item : Time) : Bool { cell == item }, range)}
190-
onClick={handleCellClick}
191-
selected={day == cell}
192-
day={cell}/>
196+
try {
197+
normalizedDay =
198+
Time.startOf("day", day)
199+
200+
normalizedCell =
201+
Time.startOf("day", cell)
202+
203+
normalizedDays =
204+
Set.map(Time.startOf("day"), selectedDays)
205+
206+
selected =
207+
if (Set.size(normalizedDays) == 0) {
208+
normalizedDay == normalizedCell
209+
} else {
210+
Set.has(normalizedCell, normalizedDays)
211+
}
212+
213+
<Ui.Calendar.Cell
214+
active={Array.any((item : Time) : Bool { normalizedCell == item }, range)}
215+
onClick={handleCellClick}
216+
day={normalizedCell}
217+
selected={selected}
218+
readonly={readonly}/>
219+
}
193220
}
194221
}
195222
</div>

0 commit comments

Comments
 (0)