@firstnoodle-ui/bui 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/dist/bui.css +1 -1
- package/dist/components/calendar-view/CalendarView.vue.d.ts +21 -0
- package/dist/components/calendar-view/components/DateButton.vue.d.ts +10 -0
- package/dist/components/calendar-view/components/DecadeView.vue.d.ts +12 -0
- package/dist/components/calendar-view/components/MonthView.vue.d.ts +17 -0
- package/dist/components/calendar-view/components/YearView.vue.d.ts +13 -0
- package/dist/components/calendar-view/composables/useCalendar.d.ts +44 -0
- package/dist/components/calendar-view/index.d.ts +1 -0
- package/dist/components/calendar-view/utils/enums.d.ts +29 -0
- package/dist/components/calendar-view/utils/index.d.ts +23 -0
- package/dist/components/calendar-view/utils/types.d.ts +12 -0
- package/dist/components/calendar-view/utils/utils/calendar.d.ts +22 -0
- package/dist/components/calendar-view/utils/utils/date.d.ts +15 -0
- package/dist/components/calendar-view/utils/utils/format.d.ts +18 -0
- package/dist/components/calendar-view/utils/utils/time.d.ts +35 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/notification-badge/NotificationBadge.vue.d.ts +5 -0
- package/dist/components/notification-badge/index.d.ts +1 -0
- package/dist/components/select-list/components/option-group/OptionGroup.vue.d.ts +1 -0
- package/dist/components/select-list/components/select-list-option/SelectListOption.vue.d.ts +1 -0
- package/dist/components/select-list/types.d.ts +1 -0
- package/dist/components/types.d.ts +1 -1
- package/dist/index.mjs +7056 -6465
- package/dist/utils/capitalizeFirstLetter.d.ts +1 -0
- package/package.json +4 -3
- package/src/components/application-wrapper/ApplicationWrapper.vue +8 -0
- package/src/components/application-wrapper/index.ts +1 -0
- package/src/components/aside-section-label/AsideSectionLabel.vue +16 -0
- package/src/components/aside-section-label/index.ts +1 -0
- package/src/components/button/Button.vue +246 -0
- package/src/components/button/NotificationBadge.vue +15 -0
- package/src/components/button/components/button-label/ButtonLabel.vue +9 -0
- package/src/components/button/components/button-label/index.ts +1 -0
- package/src/components/button/components/index.ts +3 -0
- package/src/components/button/components/left-group/LeftGroup.vue +5 -0
- package/src/components/button/components/left-group/index.ts +1 -0
- package/src/components/button/components/notification-badge/NotificationBadge.vue +17 -0
- package/src/components/button/components/notification-badge/index.ts +1 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/button-group/ButtonGroup.vue +97 -0
- package/src/components/button-group/index.ts +1 -0
- package/src/components/calendar-view/CalendarView.vue +106 -0
- package/src/components/calendar-view/components/DateButton.vue +23 -0
- package/src/components/calendar-view/components/DecadeView.vue +50 -0
- package/src/components/calendar-view/components/MonthView.vue +72 -0
- package/src/components/calendar-view/components/NavButton.vue +16 -0
- package/src/components/calendar-view/components/YearView.vue +52 -0
- package/src/components/calendar-view/composables/useCalendar.ts +138 -0
- package/src/components/calendar-view/index.ts +1 -0
- package/src/components/calendar-view/utils/enums.ts +31 -0
- package/src/components/calendar-view/utils/index.ts +240 -0
- package/src/components/calendar-view/utils/types.ts +13 -0
- package/src/components/calendar-view/utils/utils/calendar.ts +70 -0
- package/src/components/calendar-view/utils/utils/date.ts +130 -0
- package/src/components/calendar-view/utils/utils/format.ts +61 -0
- package/src/components/calendar-view/utils/utils/time.ts +70 -0
- package/src/components/checkbox/Checkbox.vue +51 -0
- package/src/components/checkbox/CircleIndicator.vue +26 -0
- package/src/components/checkbox/DefaultIndicator.vue +19 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/collapse/Collapse.vue +114 -0
- package/src/components/collapse/index.ts +1 -0
- package/src/components/confirm-cancel/ConfirmCancel.vue +66 -0
- package/src/components/confirm-cancel/index.ts +1 -0
- package/src/components/confirm-cancel/types.ts +18 -0
- package/src/components/content-slider/ContentSlider.vue +79 -0
- package/src/components/content-slider/index.ts +1 -0
- package/src/components/data-point/DataPoint.vue +5 -0
- package/src/components/data-point/index.ts +1 -0
- package/src/components/delete-button/DeleteButton.vue +19 -0
- package/src/components/delete-button/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +70 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/fade-in-up/FadeInUp.vue +17 -0
- package/src/components/fade-in-up/index.ts +1 -0
- package/src/components/filter-chip/FilterChip.vue +28 -0
- package/src/components/filter-chip/index.ts +1 -0
- package/src/components/first-paint/FirstPaint.vue +21 -0
- package/src/components/first-paint/index.ts +1 -0
- package/src/components/first-paint/style.scss +23 -0
- package/src/components/flexbox/Flexbox.vue +51 -0
- package/src/components/flexbox/index.ts +1 -0
- package/src/components/horizontal-layout/Aside.vue +114 -0
- package/src/components/horizontal-layout/HorizontalLayout.vue +118 -0
- package/src/components/horizontal-layout/index.ts +2 -0
- package/src/components/icon/Icon.vue +1263 -0
- package/src/components/icon/index.ts +1 -0
- package/src/components/icon/utils/combine-svgs.cjs +55 -0
- package/src/components/icon/utils/combined-svgs.txt +1150 -0
- package/src/components/icon/utils/svgs/admin.svg +16 -0
- package/src/components/icon/utils/svgs/arrow-deviate.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-down-plus.svg +4 -0
- package/src/components/icon/utils/svgs/arrow-down.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-from.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-left.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-move.svg +15 -0
- package/src/components/icon/utils/svgs/arrow-right.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-sub.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-trend.svg +15 -0
- package/src/components/icon/utils/svgs/arrow-up-plus.svg +4 -0
- package/src/components/icon/utils/svgs/arrow-up.svg +3 -0
- package/src/components/icon/utils/svgs/authority.svg +5 -0
- package/src/components/icon/utils/svgs/beams.svg +5 -0
- package/src/components/icon/utils/svgs/bell.svg +15 -0
- package/src/components/icon/utils/svgs/bold.svg +3 -0
- package/src/components/icon/utils/svgs/box.svg +5 -0
- package/src/components/icon/utils/svgs/building.svg +15 -0
- package/src/components/icon/utils/svgs/bullet-list.svg +8 -0
- package/src/components/icon/utils/svgs/calendar.svg +21 -0
- package/src/components/icon/utils/svgs/camera.svg +5 -0
- package/src/components/icon/utils/svgs/categories.svg +3 -0
- package/src/components/icon/utils/svgs/check-circled.svg +16 -0
- package/src/components/icon/utils/svgs/check-outline.svg +15 -0
- package/src/components/icon/utils/svgs/check.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-down.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-left-double.svg +4 -0
- package/src/components/icon/utils/svgs/chevron-left.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-right-double.svg +4 -0
- package/src/components/icon/utils/svgs/chevron-right.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-up.svg +3 -0
- package/src/components/icon/utils/svgs/clock.svg +4 -0
- package/src/components/icon/utils/svgs/close-outline.svg +3 -0
- package/src/components/icon/utils/svgs/close.svg +3 -0
- package/src/components/icon/utils/svgs/columns.svg +3 -0
- package/src/components/icon/utils/svgs/conclusion.svg +17 -0
- package/src/components/icon/utils/svgs/copy.svg +16 -0
- package/src/components/icon/utils/svgs/crosshair.svg +15 -0
- package/src/components/icon/utils/svgs/dash.svg +3 -0
- package/src/components/icon/utils/svgs/dashboard.svg +3 -0
- package/src/components/icon/utils/svgs/delete.svg +4 -0
- package/src/components/icon/utils/svgs/delta.svg +3 -0
- package/src/components/icon/utils/svgs/download.svg +3 -0
- package/src/components/icon/utils/svgs/drag.svg +8 -0
- package/src/components/icon/utils/svgs/drilldown.svg +8 -0
- package/src/components/icon/utils/svgs/edit.svg +16 -0
- package/src/components/icon/utils/svgs/envelope.svg +3 -0
- package/src/components/icon/utils/svgs/error.svg +3 -0
- package/src/components/icon/utils/svgs/export-document.svg +16 -0
- package/src/components/icon/utils/svgs/filter.svg +6 -0
- package/src/components/icon/utils/svgs/filters.svg +4 -0
- package/src/components/icon/utils/svgs/flag.svg +3 -0
- package/src/components/icon/utils/svgs/folder.svg +15 -0
- package/src/components/icon/utils/svgs/frequency.svg +3 -0
- package/src/components/icon/utils/svgs/fullscreen-off.svg +3 -0
- package/src/components/icon/utils/svgs/fullscreen-on.svg +3 -0
- package/src/components/icon/utils/svgs/graduate.svg +3 -0
- package/src/components/icon/utils/svgs/hamburger.svg +5 -0
- package/src/components/icon/utils/svgs/handshake.svg +15 -0
- package/src/components/icon/utils/svgs/heading-1.svg +4 -0
- package/src/components/icon/utils/svgs/heading-2.svg +4 -0
- package/src/components/icon/utils/svgs/heading.svg +3 -0
- package/src/components/icon/utils/svgs/home.svg +3 -0
- package/src/components/icon/utils/svgs/id-card.svg +6 -0
- package/src/components/icon/utils/svgs/id.svg +4 -0
- package/src/components/icon/utils/svgs/indent-left.svg +7 -0
- package/src/components/icon/utils/svgs/indent-right.svg +7 -0
- package/src/components/icon/utils/svgs/information.svg +17 -0
- package/src/components/icon/utils/svgs/italics.svg +3 -0
- package/src/components/icon/utils/svgs/itenary.svg +11 -0
- package/src/components/icon/utils/svgs/keyboard.svg +11 -0
- package/src/components/icon/utils/svgs/lightning.svg +15 -0
- package/src/components/icon/utils/svgs/link.svg +4 -0
- package/src/components/icon/utils/svgs/list-collapse.svg +6 -0
- package/src/components/icon/utils/svgs/list-expand.svg +6 -0
- package/src/components/icon/utils/svgs/location.svg +4 -0
- package/src/components/icon/utils/svgs/lock-locked.svg +4 -0
- package/src/components/icon/utils/svgs/lock-unlocked.svg +4 -0
- package/src/components/icon/utils/svgs/magnifying-glass.svg +15 -0
- package/src/components/icon/utils/svgs/map.svg +3 -0
- package/src/components/icon/utils/svgs/megaphone.svg +3 -0
- package/src/components/icon/utils/svgs/message.svg +15 -0
- package/src/components/icon/utils/svgs/microscope.svg +3 -0
- package/src/components/icon/utils/svgs/moon.svg +3 -0
- package/src/components/icon/utils/svgs/new-document.svg +4 -0
- package/src/components/icon/utils/svgs/news.svg +15 -0
- package/src/components/icon/utils/svgs/numbered-list.svg +7 -0
- package/src/components/icon/utils/svgs/open-link.svg +16 -0
- package/src/components/icon/utils/svgs/options.svg +5 -0
- package/src/components/icon/utils/svgs/page.svg +7 -0
- package/src/components/icon/utils/svgs/paper-plane.svg +15 -0
- package/src/components/icon/utils/svgs/paper.svg +3 -0
- package/src/components/icon/utils/svgs/pen-and-paper.svg +4 -0
- package/src/components/icon/utils/svgs/phase.svg +15 -0
- package/src/components/icon/utils/svgs/photo.svg +4 -0
- package/src/components/icon/utils/svgs/pie-chart.svg +3 -0
- package/src/components/icon/utils/svgs/plus.svg +3 -0
- package/src/components/icon/utils/svgs/point-left.svg +3 -0
- package/src/components/icon/utils/svgs/point-up.svg +3 -0
- package/src/components/icon/utils/svgs/popup.svg +16 -0
- package/src/components/icon/utils/svgs/question.svg +17 -0
- package/src/components/icon/utils/svgs/radio-tower.svg +3 -0
- package/src/components/icon/utils/svgs/recycle.svg +3 -0
- package/src/components/icon/utils/svgs/redo.svg +3 -0
- package/src/components/icon/utils/svgs/refresh.svg +3 -0
- package/src/components/icon/utils/svgs/route.svg +3 -0
- package/src/components/icon/utils/svgs/rows.svg +3 -0
- package/src/components/icon/utils/svgs/scope.svg +7 -0
- package/src/components/icon/utils/svgs/settings.svg +16 -0
- package/src/components/icon/utils/svgs/share.svg +11 -0
- package/src/components/icon/utils/svgs/sign-in.svg +4 -0
- package/src/components/icon/utils/svgs/sign-up.svg +3 -0
- package/src/components/icon/utils/svgs/sort-down.svg +20 -0
- package/src/components/icon/utils/svgs/sort-up.svg +20 -0
- package/src/components/icon/utils/svgs/sort.svg +7 -0
- package/src/components/icon/utils/svgs/square-solid.svg +3 -0
- package/src/components/icon/utils/svgs/star-solid.svg +15 -0
- package/src/components/icon/utils/svgs/star.svg +15 -0
- package/src/components/icon/utils/svgs/stop-watch.svg +5 -0
- package/src/components/icon/utils/svgs/structure.svg +3 -0
- package/src/components/icon/utils/svgs/sun.svg +23 -0
- package/src/components/icon/utils/svgs/table.svg +3 -0
- package/src/components/icon/utils/svgs/tag.svg +15 -0
- package/src/components/icon/utils/svgs/team.svg +15 -0
- package/src/components/icon/utils/svgs/telescope.svg +15 -0
- package/src/components/icon/utils/svgs/trash.svg +6 -0
- package/src/components/icon/utils/svgs/triangle-angle.svg +3 -0
- package/src/components/icon/utils/svgs/triangle-side.svg +3 -0
- package/src/components/icon/utils/svgs/underline.svg +4 -0
- package/src/components/icon/utils/svgs/undo.svg +3 -0
- package/src/components/icon/utils/svgs/user.svg +16 -0
- package/src/components/icon/utils/svgs/venn.svg +3 -0
- package/src/components/icon/utils/svgs/video.svg +3 -0
- package/src/components/icon/utils/svgs/visibility-off-alt.svg +19 -0
- package/src/components/icon/utils/svgs/visibility-off.svg +3 -0
- package/src/components/icon/utils/svgs/visibility-on.svg +16 -0
- package/src/components/icon/utils/svgs/warning.svg +5 -0
- package/src/components/index.ts +45 -0
- package/src/components/input/Input.vue +118 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input-number/InputNumber.vue +112 -0
- package/src/components/input-number/StepButton.vue +23 -0
- package/src/components/input-number/index.ts +1 -0
- package/src/components/load-spinner/LoadSpinner.vue +13 -0
- package/src/components/load-spinner/index.ts +1 -0
- package/src/components/modal/Modal.vue +111 -0
- package/src/components/modal/index.ts +1 -0
- package/src/components/nav-item/NavItem.vue +62 -0
- package/src/components/nav-item/index.ts +1 -0
- package/src/components/notification/Notification.vue +53 -0
- package/src/components/notification/index.ts +1 -0
- package/src/components/notification-badge/NotificationBadge.vue +7 -0
- package/src/components/notification-badge/index.ts +1 -0
- package/src/components/pagination/Pagination.vue +65 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pop-confirm/PopConfirm.vue +90 -0
- package/src/components/pop-confirm/index.ts +1 -0
- package/src/components/pop-select/FooterButton.vue +5 -0
- package/src/components/pop-select/PopSelect.vue +346 -0
- package/src/components/pop-select/ResultFilters.vue +28 -0
- package/src/components/pop-select/enums.ts +7 -0
- package/src/components/pop-select/index.ts +2 -0
- package/src/components/pop-select/option.vue +51 -0
- package/src/components/popper/Popper.vue +239 -0
- package/src/components/popper/PopperContent.vue +5 -0
- package/src/components/popper/index.ts +2 -0
- package/src/components/popper/middleware.ts +19 -0
- package/src/components/screen-overlay/ScreenOverlay.vue +53 -0
- package/src/components/screen-overlay/index.ts +1 -0
- package/src/components/scrollbar/Bar.vue +106 -0
- package/src/components/scrollbar/ScrollBottomLoader.vue +25 -0
- package/src/components/scrollbar/Scrollbar.vue +219 -0
- package/src/components/scrollbar/enums.ts +23 -0
- package/src/components/scrollbar/index.ts +3 -0
- package/src/components/scrollbar/style.scss +77 -0
- package/src/components/scrollbar/types.ts +32 -0
- package/src/components/select-list/SelectList.vue +476 -0
- package/src/components/select-list/components/SelectListFilterChip.vue +34 -0
- package/src/components/select-list/components/index.ts +3 -0
- package/src/components/select-list/components/option-group/OptionGroup.vue +20 -0
- package/src/components/select-list/components/option-group/index.ts +1 -0
- package/src/components/select-list/components/select-list-option/SelectListOption.vue +83 -0
- package/src/components/select-list/components/select-list-option/index.ts +1 -0
- package/src/components/select-list/components/status-cards/error-card/ErrorCard.vue +17 -0
- package/src/components/select-list/components/status-cards/error-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/idle-card/IdleCard.vue +11 -0
- package/src/components/select-list/components/status-cards/idle-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/index.ts +4 -0
- package/src/components/select-list/components/status-cards/loading-card/LoadingCard.vue +10 -0
- package/src/components/select-list/components/status-cards/loading-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/no-match-card/NoMatchCard.vue +15 -0
- package/src/components/select-list/components/status-cards/no-match-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/status-card/StatusCard.vue +25 -0
- package/src/components/select-list/components/status-cards/status-card/index.ts +1 -0
- package/src/components/select-list/index.ts +5 -0
- package/src/components/select-list/types.ts +49 -0
- package/src/components/side-over/SideOver.vue +87 -0
- package/src/components/side-over/index.ts +1 -0
- package/src/components/status-select/StatusIndicator.vue +78 -0
- package/src/components/status-select/StatusSelect.vue +62 -0
- package/src/components/status-select/index.ts +1 -0
- package/src/components/switch/Switch.vue +52 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/tab/Tab.vue +65 -0
- package/src/components/tab/index.ts +1 -0
- package/src/components/tag/Tag.vue +34 -0
- package/src/components/tag/index.ts +1 -0
- package/src/components/text-editor/TextEditor.vue +399 -0
- package/src/components/text-editor/components/Dialog.vue +11 -0
- package/src/components/text-editor/components/FormattingButton.vue +46 -0
- package/src/components/text-editor/components/InsertLinkDialog.vue +81 -0
- package/src/components/text-editor/components/InsertTextDialog.vue +36 -0
- package/src/components/text-editor/components/index.ts +3 -0
- package/src/components/text-editor/index.ts +1 -0
- package/src/components/text-highlight/TextHighlight.vue +113 -0
- package/src/components/text-highlight/index.ts +1 -0
- package/src/components/text-viewer/TextViewer.vue +5 -0
- package/src/components/text-viewer/index.ts +1 -0
- package/src/components/toggle-button/ToggleButton.vue +105 -0
- package/src/components/toggle-button/index.ts +1 -0
- package/src/components/tooltip/Tooltip.vue +54 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/types.ts +232 -0
- package/src/components/vertical-layout/RunningSection.vue +54 -0
- package/src/components/vertical-layout/VerticalLayout.vue +37 -0
- package/src/components/vertical-layout/index.ts +3 -0
- package/src/components/vertical-layout/types.ts +2 -0
- package/src/components/window-frame/WindowFrame.vue +20 -0
- package/src/components/window-frame/index.ts +1 -0
- package/src/composables/index.ts +5 -0
- package/src/composables/useClickOutside.ts +48 -0
- package/src/composables/useEscapeKey.ts +12 -0
- package/src/composables/useMounted.ts +7 -0
- package/src/composables/useNextFrame.ts +10 -0
- package/src/composables/useTrapFocus.ts +61 -0
- package/src/index.ts +5 -0
- package/src/main.css +140 -0
- package/src/utils/array.ts +11 -0
- package/src/utils/capitalizeFirstLetter.ts +4 -0
- package/src/utils/clamp.ts +9 -0
- package/src/utils/debounce.ts +8 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/scrollIntoView.ts +25 -0
- package/src/utils/scrollbarWidth.ts +27 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { CalendarGridItem } from "../utils/types";
|
|
3
|
+
import { capitalizeFirstLetter } from "../../../utils/capitalizeFirstLetter";
|
|
4
|
+
import { BButton } from "../../button";
|
|
5
|
+
import { TimeUnit } from "../utils/utils/time";
|
|
6
|
+
import DateButton from "./DateButton.vue";
|
|
7
|
+
|
|
8
|
+
defineProps<{
|
|
9
|
+
viewData: CalendarGridItem[];
|
|
10
|
+
currentMonth: string;
|
|
11
|
+
currentYear: number;
|
|
12
|
+
weekdays: string[];
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
const emit = defineEmits(["move", "change-view", "select"]);
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<div>
|
|
20
|
+
<nav class="w-56 grid grid-cols-7">
|
|
21
|
+
<BButton
|
|
22
|
+
variant="textSubtle"
|
|
23
|
+
icon="chevron-left-double"
|
|
24
|
+
@click="emit('move', { amount: -1, unit: TimeUnit.YEAR })"
|
|
25
|
+
/>
|
|
26
|
+
<BButton
|
|
27
|
+
variant="textSubtle"
|
|
28
|
+
icon="chevron-left"
|
|
29
|
+
@click="emit('move', { amount: -1, unit: TimeUnit.MONTH })"
|
|
30
|
+
/>
|
|
31
|
+
<div class="col-span-3 h-8 flex items-center justify-center">
|
|
32
|
+
<BButton
|
|
33
|
+
variant="textSubtle"
|
|
34
|
+
:label="capitalizeFirstLetter(currentMonth.slice(0, 3))"
|
|
35
|
+
@click="emit('change-view', TimeUnit.YEAR)"
|
|
36
|
+
/>
|
|
37
|
+
<BButton
|
|
38
|
+
variant="textSubtle"
|
|
39
|
+
:label="currentYear.toString()"
|
|
40
|
+
@click="emit('change-view', TimeUnit.DECADE)"
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
<BButton
|
|
44
|
+
variant="textSubtle"
|
|
45
|
+
icon="chevron-right"
|
|
46
|
+
@click="emit('move', { amount: 1, unit: TimeUnit.MONTH })"
|
|
47
|
+
/>
|
|
48
|
+
<BButton
|
|
49
|
+
variant="textSubtle"
|
|
50
|
+
icon="chevron-right-double"
|
|
51
|
+
@click="emit('move', { amount: 1, unit: TimeUnit.YEAR })"
|
|
52
|
+
/>
|
|
53
|
+
</nav>
|
|
54
|
+
<header class="w-56 grid grid-cols-7 bg-bg-medium rounded my-2">
|
|
55
|
+
<div
|
|
56
|
+
v-for="day in weekdays"
|
|
57
|
+
:key="day"
|
|
58
|
+
class="flex items-center justify-center w-8 h-6 text-muted text-xs select-none"
|
|
59
|
+
>
|
|
60
|
+
{{ day.slice(0, 1).toUpperCase() }}
|
|
61
|
+
</div>
|
|
62
|
+
</header>
|
|
63
|
+
<main class="w-56 grid grid-cols-7">
|
|
64
|
+
<DateButton
|
|
65
|
+
v-for="dateItem in viewData"
|
|
66
|
+
:key="dateItem.date"
|
|
67
|
+
:date="dateItem"
|
|
68
|
+
@click="emit('select', dateItem)"
|
|
69
|
+
/>
|
|
70
|
+
</main>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { TIcon } from "../../types";
|
|
3
|
+
import { BButton } from "../../button";
|
|
4
|
+
|
|
5
|
+
defineProps<{ icon: TIcon }>();
|
|
6
|
+
|
|
7
|
+
const emit = defineEmits(["click"]);
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<BButton
|
|
12
|
+
:icon="icon"
|
|
13
|
+
variant="textSubtle"
|
|
14
|
+
@click="emit('click')"
|
|
15
|
+
/>
|
|
16
|
+
</template>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { CalendarGridItem } from "../utils/types";
|
|
3
|
+
import { capitalizeFirstLetter } from "../../../utils/capitalizeFirstLetter";
|
|
4
|
+
import { BButton } from "../../button";
|
|
5
|
+
import { TimeUnit } from "../utils/utils/time";
|
|
6
|
+
|
|
7
|
+
defineProps<{
|
|
8
|
+
viewData: CalendarGridItem[];
|
|
9
|
+
currentYear: number;
|
|
10
|
+
}>();
|
|
11
|
+
const emit = defineEmits(["move", "select"]);
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<div>
|
|
16
|
+
<nav class="w-56 grid grid-cols-7">
|
|
17
|
+
<BButton
|
|
18
|
+
icon="chevron-left"
|
|
19
|
+
variant="textSubtle"
|
|
20
|
+
@click="emit('move', { amount: -1, unit: 'YEAR' })"
|
|
21
|
+
/>
|
|
22
|
+
<div
|
|
23
|
+
class="col-span-5 text-sm flex justify-center items-center"
|
|
24
|
+
>
|
|
25
|
+
{{ currentYear }}
|
|
26
|
+
</div>
|
|
27
|
+
<BButton
|
|
28
|
+
icon="chevron-right"
|
|
29
|
+
variant="textSubtle"
|
|
30
|
+
@click="emit('move', { amount: 1, unit: 'YEAR' })"
|
|
31
|
+
/>
|
|
32
|
+
</nav>
|
|
33
|
+
<main class="w-56 grid grid-cols-2 py-4">
|
|
34
|
+
<BButton
|
|
35
|
+
v-for="(month, monthIndex) in viewData"
|
|
36
|
+
:key="month.label"
|
|
37
|
+
:variant="month.selected ? 'fill' : (month.current ? 'text' : 'textSubtle')"
|
|
38
|
+
:label="capitalizeFirstLetter(month.label.toString())"
|
|
39
|
+
@click="
|
|
40
|
+
emit(
|
|
41
|
+
'select',
|
|
42
|
+
{
|
|
43
|
+
value: monthIndex,
|
|
44
|
+
unit: TimeUnit.MONTH,
|
|
45
|
+
view: TimeUnit.MONTH,
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
"
|
|
49
|
+
/>
|
|
50
|
+
</main>
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { Direction } from "../utils/enums";
|
|
2
|
+
import type { CalendarGridItem, CalendarOptions } from "../utils/types";
|
|
3
|
+
import { onBeforeMount, ref } from "vue";
|
|
4
|
+
import { Calendar } from "../utils";
|
|
5
|
+
import { TimeUnit } from "../utils/utils/time";
|
|
6
|
+
|
|
7
|
+
export enum ViewType {
|
|
8
|
+
DATE = TimeUnit.DAY,
|
|
9
|
+
WEEK = TimeUnit.WEEK,
|
|
10
|
+
MONTH = TimeUnit.MONTH,
|
|
11
|
+
YEAR = TimeUnit.YEAR,
|
|
12
|
+
DECADE = TimeUnit.DECADE,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useCalendar = (value: string | Date | null = null, options: CalendarOptions) => {
|
|
16
|
+
|
|
17
|
+
const calendar = new Calendar(options, value);
|
|
18
|
+
const viewData = ref<CalendarGridItem[] | []>([]);
|
|
19
|
+
const viewType = ref<ViewType>(ViewType.MONTH);
|
|
20
|
+
const viewMonth = ref<string>("");
|
|
21
|
+
const viewYear = ref<number>(0);
|
|
22
|
+
|
|
23
|
+
const changeView = (type: ViewType): void => {
|
|
24
|
+
if (!Object.keys(ViewType).includes(type)) {
|
|
25
|
+
console.warn(`[changeView] wrong view type: ${type}`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
viewType.value = type;
|
|
30
|
+
|
|
31
|
+
switch (type) {
|
|
32
|
+
case ViewType.DATE:
|
|
33
|
+
// TODO
|
|
34
|
+
break;
|
|
35
|
+
case ViewType.WEEK:
|
|
36
|
+
viewData.value = calendar.getDatesInCurrentWeek();
|
|
37
|
+
break;
|
|
38
|
+
case ViewType.MONTH:
|
|
39
|
+
viewData.value = calendar.getDatesInCurrentMonth();
|
|
40
|
+
break;
|
|
41
|
+
case ViewType.YEAR:
|
|
42
|
+
viewData.value = calendar.getMonthsInCurrentYear();
|
|
43
|
+
break;
|
|
44
|
+
case ViewType.DECADE:
|
|
45
|
+
viewData.value = calendar.getYearsInCurrentDecade();
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const updateView = () => {
|
|
51
|
+
changeView(viewType.value);
|
|
52
|
+
viewMonth.value = calendar.getDateCursorMonthName();
|
|
53
|
+
viewYear.value = calendar.dateCursor!.getUTCFullYear();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const setSelectedDate = (date: string | Date | null): void => {
|
|
57
|
+
calendar.setSelectedDate(date);
|
|
58
|
+
updateView();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
onBeforeMount(() => {
|
|
62
|
+
setSelectedDate(value);
|
|
63
|
+
changeView(viewType.value);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const moveRequest = (direction: Direction, keepCurrentView: boolean = false) => {
|
|
67
|
+
// TODO: create eventListener for calendar
|
|
68
|
+
calendar.moveSelectedDate(direction);
|
|
69
|
+
|
|
70
|
+
// change back to DateView (if on month or year)
|
|
71
|
+
if (!keepCurrentView && viewType.value !== ViewType.MONTH) {
|
|
72
|
+
changeView(ViewType.DATE);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
updateView();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Move viewDate (or parts of viewDate: date, month, year) by specified amount
|
|
81
|
+
*/
|
|
82
|
+
const moveViewDate = ({ amount, unit }: { amount: number; unit: TimeUnit }): void => {
|
|
83
|
+
switch (unit) {
|
|
84
|
+
case TimeUnit.DAY:
|
|
85
|
+
calendar.addDaysToDateCursor(amount);
|
|
86
|
+
break;
|
|
87
|
+
case TimeUnit.WEEK:
|
|
88
|
+
calendar.addWeeksToDateCursor(amount);
|
|
89
|
+
break;
|
|
90
|
+
case TimeUnit.MONTH:
|
|
91
|
+
calendar.addMonthsToDateCursor(amount);
|
|
92
|
+
break;
|
|
93
|
+
case TimeUnit.YEAR:
|
|
94
|
+
calendar.addYearsToDateCursor(amount);
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`[moveViewDate] unknown unit: ${unit}`);
|
|
98
|
+
}
|
|
99
|
+
updateView();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const setViewDate = (value: number, unit: TimeUnit): void => {
|
|
103
|
+
switch (unit) {
|
|
104
|
+
case TimeUnit.DAY:
|
|
105
|
+
calendar.setDateCursorDate(value);
|
|
106
|
+
break;
|
|
107
|
+
case TimeUnit.MONTH:
|
|
108
|
+
calendar.setDateCursorMonth(value);
|
|
109
|
+
break;
|
|
110
|
+
case TimeUnit.YEAR:
|
|
111
|
+
calendar.setDateCursorYear(value);
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
console.error(`[setViewDate] unknown unit: ${unit}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
updateView();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const setViewDateAndChangeView = ({ value, unit, view }: { value: number; unit: TimeUnit; view: ViewType }): void => {
|
|
121
|
+
setViewDate(value, unit);
|
|
122
|
+
changeView(view);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
selectedDate: calendar.selectedDate,
|
|
127
|
+
viewData,
|
|
128
|
+
viewType,
|
|
129
|
+
viewMonth,
|
|
130
|
+
viewYear,
|
|
131
|
+
changeView,
|
|
132
|
+
moveRequest,
|
|
133
|
+
moveViewDate,
|
|
134
|
+
setSelectedDate,
|
|
135
|
+
setViewDate,
|
|
136
|
+
setViewDateAndChangeView,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BCalendarView } from "./CalendarView.vue";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export enum Month {
|
|
2
|
+
JANUARY = "january",
|
|
3
|
+
FEBRUARY = "february",
|
|
4
|
+
MARCH = "march",
|
|
5
|
+
APRIL = "april",
|
|
6
|
+
MAY = "may",
|
|
7
|
+
JUNE = "june",
|
|
8
|
+
JULY = "july",
|
|
9
|
+
AUGUST = "august",
|
|
10
|
+
SEPTEMBER = "september",
|
|
11
|
+
OCTOBER = "october",
|
|
12
|
+
NOVEMBER = "november",
|
|
13
|
+
DECEMBER = "december",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export enum Weekday {
|
|
17
|
+
SUNDAY = "sunday",
|
|
18
|
+
MONDAY = "monday",
|
|
19
|
+
TUESDAY = "tuesday",
|
|
20
|
+
WEDNESDAY = "wednesday",
|
|
21
|
+
THURSDAY = "thursday",
|
|
22
|
+
FRIDAY = "friday",
|
|
23
|
+
SATURDAY = "saturday",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export enum Direction {
|
|
27
|
+
UP = "up",
|
|
28
|
+
DOWN = "down",
|
|
29
|
+
LEFT = "left",
|
|
30
|
+
RIGHT = "right",
|
|
31
|
+
};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { CalendarGridItem, CalendarOptions } from "./types.ts";
|
|
2
|
+
import { loopRange } from "../../../utils/array.ts";
|
|
3
|
+
import { Direction, Month, Weekday } from "./enums.ts";
|
|
4
|
+
import { datesAreEqual, getDecade, moveDate, parseDate } from "./utils/date";
|
|
5
|
+
import { TimeUnit } from "./utils/time";
|
|
6
|
+
|
|
7
|
+
const COLUMN_COUNT: number = 7;
|
|
8
|
+
const ROW_COUNT: number = 6;
|
|
9
|
+
const CELL_COUNT: number = COLUMN_COUNT * ROW_COUNT;
|
|
10
|
+
|
|
11
|
+
export class Calendar {
|
|
12
|
+
options: CalendarOptions;
|
|
13
|
+
today: Date;
|
|
14
|
+
selectedDate: Date | null;
|
|
15
|
+
dateCursor: Date | null;
|
|
16
|
+
|
|
17
|
+
constructor(options: CalendarOptions, date: string | Date | null = null) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
if (!("weekstart" in options)) {
|
|
20
|
+
this.options.weekStart = Object.values(Weekday).indexOf(Weekday.MONDAY);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const d = new Date();
|
|
24
|
+
this.today = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
|
|
25
|
+
this.selectedDate = null;
|
|
26
|
+
this.dateCursor = null;
|
|
27
|
+
// this.dateCursor = this.today
|
|
28
|
+
|
|
29
|
+
if (date) {
|
|
30
|
+
try {
|
|
31
|
+
const parsedDate = parseDate(date);
|
|
32
|
+
this.setSelectedDate(parsedDate);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.setSelectedDate(this.today);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
addDaysToDateCursor(days: number): void {
|
|
44
|
+
this.dateCursor!.setUTCDate(this.dateCursor!.getUTCDate() + days);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
addWeeksToDateCursor(weeks: number): void {
|
|
48
|
+
this.addDaysToDateCursor(weeks * 7);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
addMonthsToDateCursor(months: number): void {
|
|
52
|
+
const currentMonth = this.dateCursor!.getUTCMonth();
|
|
53
|
+
const requestedMonth = loopRange(currentMonth + months, Object.values(Month).length);
|
|
54
|
+
|
|
55
|
+
// TODO: revisit this - it doesn't seem to be the right solution..
|
|
56
|
+
// change year ?
|
|
57
|
+
const deltaMonths = currentMonth - requestedMonth;
|
|
58
|
+
if (Math.abs(deltaMonths) > 1) {
|
|
59
|
+
if (deltaMonths >= 0) {
|
|
60
|
+
this.addYearsToDateCursor(1);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.addYearsToDateCursor(-1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.dateCursor!.setUTCMonth(requestedMonth);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addYearsToDateCursor(years: number): void {
|
|
70
|
+
this.dateCursor!.setFullYear(this.dateCursor!.getUTCFullYear() + years);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getDatesInCurrentMonth(): CalendarGridItem[] {
|
|
74
|
+
const cursor = new Date(
|
|
75
|
+
Date.UTC(
|
|
76
|
+
this.dateCursor!.getUTCFullYear(),
|
|
77
|
+
this.dateCursor!.getUTCMonth(),
|
|
78
|
+
1,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// find and set calendar grid start date
|
|
83
|
+
const startDate = !(cursor.getUTCDay() - this.options.weekStart!)
|
|
84
|
+
? 7
|
|
85
|
+
: loopRange(
|
|
86
|
+
cursor.getUTCDay() - this.options.weekStart!,
|
|
87
|
+
Object.values(Weekday).length,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
cursor.setUTCDate(cursor.getUTCDate() - startDate);
|
|
91
|
+
|
|
92
|
+
const dates: CalendarGridItem[] = [];
|
|
93
|
+
|
|
94
|
+
for (let row = 0; row < CELL_COUNT; row++) {
|
|
95
|
+
dates.push({
|
|
96
|
+
label: cursor.getUTCDate(),
|
|
97
|
+
date: cursor.toUTCString(),
|
|
98
|
+
disabled: this.options.disabledDates
|
|
99
|
+
? this.options.disabledDates.some(fn => fn(cursor))
|
|
100
|
+
: false,
|
|
101
|
+
inactive: cursor.getUTCMonth() !== this.dateCursor!.getUTCMonth(),
|
|
102
|
+
selected: Boolean(this.selectedDate) && datesAreEqual(cursor, this.selectedDate as Date),
|
|
103
|
+
current: datesAreEqual(cursor, this.today),
|
|
104
|
+
});
|
|
105
|
+
cursor.setUTCDate(cursor.getUTCDate() + 1);
|
|
106
|
+
}
|
|
107
|
+
return dates;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getDatesInCurrentWeek(): CalendarGridItem[] {
|
|
111
|
+
// TODO
|
|
112
|
+
let cursor = new Date(
|
|
113
|
+
Date.UTC(
|
|
114
|
+
this.dateCursor!.getUTCFullYear(),
|
|
115
|
+
this.dateCursor!.getUTCMonth(),
|
|
116
|
+
this.dateCursor!.getUTCDate(),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
const offset = loopRange(
|
|
120
|
+
cursor.getUTCDay() - this.options.weekStart!,
|
|
121
|
+
Object.values(Weekday).length,
|
|
122
|
+
);
|
|
123
|
+
cursor = moveDate(cursor, -offset, TimeUnit.DAY);
|
|
124
|
+
|
|
125
|
+
const dates: CalendarGridItem[] = [];
|
|
126
|
+
// populate grid
|
|
127
|
+
for (let i = 0; i < 7; i++) {
|
|
128
|
+
dates.push({
|
|
129
|
+
label: cursor.getUTCDate(),
|
|
130
|
+
date: cursor.toUTCString(),
|
|
131
|
+
disabled: this.options.disabledDates
|
|
132
|
+
? this.options.disabledDates.some(fn => fn(cursor))
|
|
133
|
+
: false,
|
|
134
|
+
inactive:
|
|
135
|
+
cursor.getUTCMonth() !== this.dateCursor!.getUTCMonth(),
|
|
136
|
+
selected: Boolean(this.selectedDate) && datesAreEqual(cursor, this.selectedDate as Date),
|
|
137
|
+
current: datesAreEqual(cursor, this.today),
|
|
138
|
+
});
|
|
139
|
+
cursor.setUTCDate(cursor.getUTCDate() + 1);
|
|
140
|
+
}
|
|
141
|
+
return dates;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
getMonthsInCurrentYear(): CalendarGridItem[] {
|
|
145
|
+
const monthList: CalendarGridItem[] = [];
|
|
146
|
+
|
|
147
|
+
for (const [index, month] of Object.values(Month).entries()) {
|
|
148
|
+
monthList.push({
|
|
149
|
+
label: month,
|
|
150
|
+
current:
|
|
151
|
+
index === this.today.getUTCMonth()
|
|
152
|
+
&& this.dateCursor!.getUTCFullYear()
|
|
153
|
+
=== this.today.getUTCFullYear(),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return monthList;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
getDateCursorMonthName(): string {
|
|
160
|
+
return Object.values(Month)[this.dateCursor!.getUTCMonth()];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getYearsInCurrentDecade(): CalendarGridItem[] {
|
|
164
|
+
const yearGrid: CalendarGridItem[] = [];
|
|
165
|
+
|
|
166
|
+
const decade = getDecade(this.dateCursor as Date);
|
|
167
|
+
|
|
168
|
+
// TODO: use array range
|
|
169
|
+
for (const digit of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) {
|
|
170
|
+
const year = decade + digit;
|
|
171
|
+
yearGrid.push({
|
|
172
|
+
label: year,
|
|
173
|
+
current: this.today.getUTCFullYear() === year,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return yearGrid;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
moveSelectedDate(direction: Direction): void {
|
|
180
|
+
let tempDate = new Date(
|
|
181
|
+
Date.UTC(
|
|
182
|
+
this.selectedDate!.getUTCFullYear(),
|
|
183
|
+
this.selectedDate!.getUTCMonth(),
|
|
184
|
+
this.selectedDate!.getUTCDate(),
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
switch (direction) {
|
|
188
|
+
case Direction.UP:
|
|
189
|
+
tempDate = moveDate(tempDate, -7, TimeUnit.DAY);
|
|
190
|
+
break;
|
|
191
|
+
case Direction.DOWN:
|
|
192
|
+
tempDate = moveDate(tempDate, 7, TimeUnit.DAY);
|
|
193
|
+
break;
|
|
194
|
+
case Direction.LEFT:
|
|
195
|
+
tempDate = moveDate(tempDate, -1, TimeUnit.DAY);
|
|
196
|
+
break;
|
|
197
|
+
case Direction.RIGHT:
|
|
198
|
+
tempDate = moveDate(tempDate, 1, TimeUnit.DAY);
|
|
199
|
+
break;
|
|
200
|
+
default:
|
|
201
|
+
throw new Error(`Direction [${direction}] not accepted`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (this.options.disabledDates && this.options.disabledDates.some(fn => fn(tempDate))) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.setSelectedDate(tempDate);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
setSelectedDate(date: string | Date | null): void {
|
|
212
|
+
if (date) {
|
|
213
|
+
this.selectedDate = parseDate(date);
|
|
214
|
+
this.dateCursor = new Date(
|
|
215
|
+
Date.UTC(
|
|
216
|
+
this.selectedDate!.getUTCFullYear(),
|
|
217
|
+
this.selectedDate!.getUTCMonth(),
|
|
218
|
+
this.selectedDate!.getUTCDate(),
|
|
219
|
+
),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
this.selectedDate = null;
|
|
224
|
+
this.dateCursor = new Date();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
setDateCursorDate(date: number): void {
|
|
230
|
+
this.dateCursor!.setUTCDate(date);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
setDateCursorMonth(month: number): void {
|
|
234
|
+
this.dateCursor!.setUTCMonth(month);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
setDateCursorYear(year: number): void {
|
|
238
|
+
this.dateCursor!.setFullYear(year);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CalendarOptions = {
|
|
2
|
+
weekStart?: number;
|
|
3
|
+
disabledDates?: ((date: Date) => boolean)[] | any[];
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type CalendarGridItem = {
|
|
7
|
+
label: number | string;
|
|
8
|
+
current: boolean;
|
|
9
|
+
date?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
inactive?: boolean;
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { range } from "../../../../utils/array";
|
|
2
|
+
import { Weekday } from "../enums";
|
|
3
|
+
import { parseDate } from "./date";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Premade disable-function to disable weekend (saturday and sunday)
|
|
7
|
+
*/
|
|
8
|
+
export const isWeekend = (date: string | Date): boolean | null => {
|
|
9
|
+
const parsedDate = parseDate(date);
|
|
10
|
+
if (!parsedDate) return null;
|
|
11
|
+
const dayIndex: number = parsedDate.getUTCDay();
|
|
12
|
+
return dayIndex === 0 || dayIndex === 6;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Premade disable-function to disable workdays (monday - friday)
|
|
17
|
+
*/
|
|
18
|
+
export const disableWorkDays = (date: string | Date): boolean | null => {
|
|
19
|
+
const parsedDate = parseDate(date);
|
|
20
|
+
|
|
21
|
+
if (!parsedDate) return null;
|
|
22
|
+
|
|
23
|
+
const dayIndex = parsedDate.getUTCDay();
|
|
24
|
+
const weekDays: number[] = range(1, 5);
|
|
25
|
+
return weekDays.includes(dayIndex);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get index of weekday - fx 3 for 'wednesday'
|
|
30
|
+
*/
|
|
31
|
+
export const getWeekdayIndex = (weekDayString: string): number => {
|
|
32
|
+
const weekdays = Object.values(Weekday) as string[];
|
|
33
|
+
|
|
34
|
+
if (!weekdays.includes(weekDayString.toLowerCase())) {
|
|
35
|
+
throw new Error(`Invalid weekday [${weekDayString}]`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return weekdays.indexOf(weekDayString);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Premade disable-function to disable specific weekDay
|
|
43
|
+
* Accepts both an integer 0-6 or a string fx 'monday'
|
|
44
|
+
*/
|
|
45
|
+
export const disableWeekday = (weekDay: number | string): (date: string | Date) => boolean | null => {
|
|
46
|
+
let dayIndex: number | null;
|
|
47
|
+
|
|
48
|
+
if (typeof weekDay === "string") {
|
|
49
|
+
dayIndex = getWeekdayIndex(weekDay);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
dayIndex = weekDay;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (date: string | Date): boolean | null => {
|
|
56
|
+
const parsedDate = parseDate(date);
|
|
57
|
+
if (!parsedDate) return null;
|
|
58
|
+
return parsedDate.getUTCDay() === dayIndex;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Return the weekday from a date string or object
|
|
64
|
+
* Monday
|
|
65
|
+
*/
|
|
66
|
+
export const getWeekday = (value: string | Date): string => {
|
|
67
|
+
const d = new Date(value);
|
|
68
|
+
const day = new Intl.DateTimeFormat("en-001", { weekday: "long" }).format(d);
|
|
69
|
+
return `${day}`;
|
|
70
|
+
};
|