Skip to content

Commit

Permalink
[Month] Add hideControls prop
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Nov 22, 2023
1 parent 6a71989 commit 9021816
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-wolves-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

[Month] Add `hideControls` prop
45 changes: 26 additions & 19 deletions packages/svelte-ux/src/lib/components/Month.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
endOfMonth as endOfMonthFunc,
format,
addMonths,
subMonths,
isSameDay,
isWithinInterval,
} from 'date-fns';
Expand All @@ -33,10 +32,14 @@
startOfMonthFunc(selected.from)) ||
startOfMonthFunc(new Date());
// TODO: Variable shows error if set to `endOfMonth` maybe due to import
$: endOfMonth2 = endOfMonthFunc(startOfMonth);
$: endOfMonth = endOfMonthFunc(startOfMonth);
$: monthDaysByWeek = getMonthDaysByWeek(startOfMonth);
/**
* Hide controls and date. Useful to control externally
*/
export let hideControls = false;
/**
* Show days before and after selected month
*/
Expand Down Expand Up @@ -65,35 +68,39 @@
$: isDayHidden = (day: Date) => {
const isCurrentMonth = isWithinInterval(day, {
start: startOfMonth,
end: endOfMonth2,
end: endOfMonth,
});
return !isCurrentMonth && !showOutsideDays;
};
$: isDayFaded = (day: Date) => {
const isCurrentMonth = isWithinInterval(day, {
start: startOfMonth,
end: endOfMonth2,
end: endOfMonth,
});
return !isCurrentMonth && showOutsideDays;
};
</script>

<div class="flex m-2">
<Button
icon={mdiChevronLeft}
class="p-2"
on:click={() => (startOfMonth = subMonths(startOfMonth, 1))}
/>
<div class="flex flex-1 items-center justify-center">
<span>{format(startOfMonth, 'MMMM yyyy')}</span>
{#if !hideControls}
<div class="flex m-2">
<Button
icon={mdiChevronLeft}
class="p-2"
on:click={() => (startOfMonth = addMonths(startOfMonth, -1))}
/>

<div class="flex flex-1 items-center justify-center">
<span>{format(startOfMonth, 'MMMM yyyy')}</span>
</div>

<Button
icon={mdiChevronRight}
class="p-2"
on:click={() => (startOfMonth = addMonths(startOfMonth, 1))}
/>
</div>
<Button
icon={mdiChevronRight}
class="p-2"
on:click={() => (startOfMonth = addMonths(startOfMonth, 1))}
/>
</div>
{/if}

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

0 comments on commit 9021816

Please sign in to comment.