|
1 | 1 | <script lang="ts"> |
2 | | - import {getDateRows, getWeekDays, uuid} from './DatePickerInputSvelteHelpers.js'; |
3 | | - import { createEventDispatcher } from "svelte"; |
4 | | - import {moment} from 'obsidian'; |
| 2 | + import {getDateRows, getWeekDays, uuid} from './DatePickerInputSvelteHelpers.js'; |
| 3 | + import {createEventDispatcher} from 'svelte'; |
| 4 | + import {moment} from 'obsidian'; |
5 | 5 |
|
6 | | - const dispatch = createEventDispatcher(); |
| 6 | + const dispatch = createEventDispatcher(); |
7 | 7 |
|
8 | | - // props |
9 | | - export let selectedDate: moment.Moment; |
10 | | - export let month: number; |
11 | | - export let year: number; |
| 8 | + // props |
| 9 | + export let selectedDate: moment.Moment; |
| 10 | + export let month: number; |
| 11 | + export let year: number; |
12 | 12 |
|
13 | | - // local vars to help in render |
14 | | - let cells; |
| 13 | + // local vars to help in render |
| 14 | + let cells; |
15 | 15 |
|
16 | | - // function helpers |
17 | | - function onChange(date: number) { |
18 | | - dispatch("dateChange", moment(new Date(year, month, date))); |
19 | | - } |
| 16 | + // function helpers |
| 17 | + function onChange(date: number) { |
| 18 | + dispatch('dateChange', moment(new Date(year, month, date))); |
| 19 | + } |
20 | 20 |
|
21 | | - $: cells = getDateRows(month, year); |
| 21 | + $: cells = getDateRows(month, year); |
22 | 22 | </script> |
23 | 23 |
|
24 | 24 | <style> |
25 | | - .calendar { |
26 | | - margin-top: 10px; |
27 | | - } |
28 | | -
|
29 | | - .calendar-header { |
30 | | - display: flex; |
31 | | - flex-wrap: wrap; |
32 | | - gap: 2px; |
33 | | - background: var(--background-primary); |
| 25 | + .calendar { |
| 26 | + margin-top: 10px; |
| 27 | + } |
| 28 | +
|
| 29 | + .calendar-header { |
| 30 | + display: flex; |
| 31 | + flex-wrap: wrap; |
| 32 | + gap: 2px; |
| 33 | + background: var(--background-primary); |
34 | 34 | border-radius: var(--meta-bind-plugin-border-radius); |
35 | 35 | margin-bottom: 2px; |
36 | | - } |
| 36 | + } |
37 | 37 |
|
38 | 38 | .calendar-content { |
39 | | - display: grid; |
40 | | - flex-wrap: wrap; |
| 39 | + display: grid; |
| 40 | + flex-wrap: wrap; |
41 | 41 | grid-template-columns: repeat(7, 1fr); |
42 | | - gap: 2px; |
| 42 | + gap: 2px; |
43 | 43 | } |
44 | 44 |
|
45 | | - .cell { |
46 | | - width: 40px; |
47 | | - height: 30px; |
48 | | - padding: 5px; |
49 | | - display: flex; |
| 45 | + .cell { |
| 46 | + width: 40px; |
| 47 | + height: 30px; |
| 48 | + padding: 5px; |
| 49 | + display: flex; |
50 | 50 | justify-content: center; |
51 | | - align-items: center; |
52 | | - border-radius: var(--meta-bind-plugin-border-radius); |
53 | | - } |
| 51 | + align-items: center; |
| 52 | + border-radius: var(--meta-bind-plugin-border-radius); |
| 53 | + } |
54 | 54 |
|
55 | 55 | .content-cell { |
56 | 56 | cursor: pointer; |
57 | 57 | } |
58 | 58 |
|
59 | 59 | .cell-text { |
60 | | - margin: auto; |
| 60 | + margin: auto; |
61 | 61 | text-align: center; |
62 | 62 | } |
63 | 63 |
|
64 | | - .selected { |
65 | | - background: var(--background-modifier-success); |
66 | | - } |
| 64 | + .selected { |
| 65 | + background: var(--background-modifier-success); |
| 66 | + } |
67 | 67 |
|
68 | | - .highlight:hover { |
69 | | - background: var(--interactive-hover); |
70 | | - } |
| 68 | + .highlight:hover { |
| 69 | + background: var(--interactive-hover); |
| 70 | + } |
71 | 71 |
|
72 | | - .selected.highlight:hover { |
73 | | - background: green; |
74 | | - } |
| 72 | + .selected.highlight:hover { |
| 73 | + background: green; |
| 74 | + } |
75 | 75 | </style> |
76 | 76 |
|
77 | 77 | <div class="calendar"> |
78 | | - <div class="calendar-header"> |
79 | | - {#each getWeekDays() as day} |
80 | | - <div class="cell header-cell"> |
| 78 | + <div class="calendar-header"> |
| 79 | + {#each getWeekDays() as day} |
| 80 | + <div class="cell header-cell"> |
81 | 81 | <span class="cell-text">{day}</span> |
82 | 82 | </div> |
83 | | - {/each} |
84 | | - </div> |
85 | | - |
86 | | - <div class="calendar-content"> |
87 | | - {#each cells as value (uuid())} |
88 | | - <div |
89 | | - class="cell" |
90 | | - on:click={value ? () => onChange(value) : () => {}} |
91 | | - class:highlight={value} |
92 | | - class:content-cell={value} |
93 | | - class:selected={selectedDate.year() === year && selectedDate.month() === month && selectedDate.date() === value}> |
94 | | - <span class="cell-text">{value || ''}</span> |
95 | | - </div> |
96 | | - {/each} |
97 | | - </div> |
| 83 | + {/each} |
| 84 | + </div> |
| 85 | + |
| 86 | + <div class="calendar-content"> |
| 87 | + {#each cells as value (uuid())} |
| 88 | + <div |
| 89 | + class="cell" |
| 90 | + on:click={value ? () => onChange(value) : () => {}} |
| 91 | + class:highlight={value} |
| 92 | + class:content-cell={value} |
| 93 | + class:selected={selectedDate.year() === year && selectedDate.month() === month && selectedDate.date() === value}> |
| 94 | + <span class="cell-text">{value || ''}</span> |
| 95 | + </div> |
| 96 | + {/each} |
| 97 | + </div> |
98 | 98 | </div> |
0 commit comments