Skip to content

Commit 9021816

Browse files
committed
[Month] Add hideControls prop
1 parent 6a71989 commit 9021816

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

.changeset/itchy-wolves-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-ux': patch
3+
---
4+
5+
[Month] Add `hideControls` prop

packages/svelte-ux/src/lib/components/Month.svelte

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
endOfMonth as endOfMonthFunc,
99
format,
1010
addMonths,
11-
subMonths,
1211
isSameDay,
1312
isWithinInterval,
1413
} from 'date-fns';
@@ -33,10 +32,14 @@
3332
startOfMonthFunc(selected.from)) ||
3433
startOfMonthFunc(new Date());
3534
36-
// TODO: Variable shows error if set to `endOfMonth` maybe due to import
37-
$: endOfMonth2 = endOfMonthFunc(startOfMonth);
35+
$: endOfMonth = endOfMonthFunc(startOfMonth);
3836
$: monthDaysByWeek = getMonthDaysByWeek(startOfMonth);
3937
38+
/**
39+
* Hide controls and date. Useful to control externally
40+
*/
41+
export let hideControls = false;
42+
4043
/**
4144
* Show days before and after selected month
4245
*/
@@ -65,35 +68,39 @@
6568
$: isDayHidden = (day: Date) => {
6669
const isCurrentMonth = isWithinInterval(day, {
6770
start: startOfMonth,
68-
end: endOfMonth2,
71+
end: endOfMonth,
6972
});
7073
return !isCurrentMonth && !showOutsideDays;
7174
};
7275
7376
$: isDayFaded = (day: Date) => {
7477
const isCurrentMonth = isWithinInterval(day, {
7578
start: startOfMonth,
76-
end: endOfMonth2,
79+
end: endOfMonth,
7780
});
7881
return !isCurrentMonth && showOutsideDays;
7982
};
8083
</script>
8184

82-
<div class="flex m-2">
83-
<Button
84-
icon={mdiChevronLeft}
85-
class="p-2"
86-
on:click={() => (startOfMonth = subMonths(startOfMonth, 1))}
87-
/>
88-
<div class="flex flex-1 items-center justify-center">
89-
<span>{format(startOfMonth, 'MMMM yyyy')}</span>
85+
{#if !hideControls}
86+
<div class="flex m-2">
87+
<Button
88+
icon={mdiChevronLeft}
89+
class="p-2"
90+
on:click={() => (startOfMonth = addMonths(startOfMonth, -1))}
91+
/>
92+
93+
<div class="flex flex-1 items-center justify-center">
94+
<span>{format(startOfMonth, 'MMMM yyyy')}</span>
95+
</div>
96+
97+
<Button
98+
icon={mdiChevronRight}
99+
class="p-2"
100+
on:click={() => (startOfMonth = addMonths(startOfMonth, 1))}
101+
/>
90102
</div>
91-
<Button
92-
icon={mdiChevronRight}
93-
class="p-2"
94-
on:click={() => (startOfMonth = addMonths(startOfMonth, 1))}
95-
/>
96-
</div>
103+
{/if}
97104

98105
<div class="flex">
99106
{#each monthDaysByWeek[0] ?? [] as day (day.getDate())}

0 commit comments

Comments
 (0)