-
Notifications
You must be signed in to change notification settings - Fork 19
Refactor datepicker to move calendar out #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MrWook
wants to merge
7
commits into
master
Choose a base branch
from
feat/append-to-body
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4993c40
refactor(calendar): move calendar in own component
MrWook 51b9790
feat(calendar): add props to add calendar to body
MrWook 651bd2c
chore(popup): set fixed position for relativ position
MrWook 847ddb1
chore(project): small fine tuning
MrWook 139b71a
feat(position): make fixedPosition workable again
MrWook 9dfa77b
fix(position): resolve position on right sided inputs
MrWook ea9bc22
docs(project): adjust docs for fixedPosition prop
MrWook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,10 @@ | |
| <h1>Datepicker Examples</h1> | ||
| <div class="example"> | ||
| <h3>Default datepicker...</h3> | ||
| <Datepicker placeholder="Select Date" /> | ||
| <Datepicker | ||
| placeholder="Select Date" | ||
| :append-to-body="true" | ||
| /> | ||
| <code> | ||
| <datepicker placeholder="Select Date"></datepicker> | ||
| </code> | ||
|
|
@@ -37,6 +40,7 @@ | |
| <Datepicker | ||
| v-model="vModelExample" | ||
| placeholder="Select Date" | ||
| :append-to-body="true" | ||
| /> | ||
| <code> | ||
| <datepicker placeholder="Select Date" v-model="vmodelexample"></datepicker> | ||
|
|
@@ -45,6 +49,18 @@ | |
| <p>{{ vModelExample }}</p> | ||
| </div> | ||
|
|
||
| <div class="example overflow-scroll"> | ||
| <h3>Append datepicker to body</h3> | ||
| <Datepicker | ||
| :append-to-body="true" | ||
| /> | ||
| <h3>Don't append datepicker to body</h3> | ||
| <Datepicker /> | ||
| <code> | ||
| <datepicker :append-to-body="true"></datepicker> | ||
| </code> | ||
| </div> | ||
|
|
||
| <div class="example"> | ||
| <h3>Format datepicker</h3> | ||
| <Datepicker :format="format" /> | ||
|
|
@@ -499,4 +515,7 @@ h5 { | |
| font-size: 80%; | ||
| display: block; | ||
| } | ||
| .overflow-scroll{ | ||
MrWook marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| overflow:scroll | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting: |
||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,312 @@ | ||
| <template> | ||
| <div | ||
| ref="datepicker" | ||
| :class="[calendarClass, 'vdp-datepicker__calendar']" | ||
| :style="calendarStyle" | ||
| @mousedown.prevent | ||
| > | ||
| <slot name="beforeCalendarHeader" /> | ||
| <component | ||
| :is="currentPicker" | ||
| :page-date="pageDate" | ||
| :selected-date="selectedDate" | ||
| :allowed-to-show-view="allowedToShowView" | ||
| :translation="translation" | ||
| :page-timestamp="pageTimestamp" | ||
|
|
||
| :is-rtl="isRtl" | ||
| :use-utc="useUtc" | ||
| :show-header="showHeader" | ||
| :full-month-name="fullMonthName" | ||
| :monday-first="mondayFirst" | ||
| :day-cell-content="dayCellContent" | ||
| :highlighted="highlighted" | ||
| :disabled-dates="disabledDates" | ||
|
|
||
| @select-date="selectDate" | ||
| @changed-month="handleChangedMonthFromDayPicker" | ||
| @selected-disabled="selectDisabledDate" | ||
|
|
||
| @select-month="selectMonth" | ||
| @changed-year="setPageDate" | ||
| @show-month-calendar="showSpecificCalendar('Month')" | ||
|
|
||
| @select-year="selectYear" | ||
| @changed-decade="setPageDate" | ||
| @show-year-calendar="showSpecificCalendar('Year')" | ||
| > | ||
| <template | ||
| v-for="slotKey of calendarSlots" | ||
| > | ||
| <slot | ||
| :name="`${slotKey}`" | ||
| :item="slotKey" | ||
| /> | ||
| </template> | ||
| </component> | ||
| <slot name="calendarFooter" /> | ||
| </div> | ||
| </template> | ||
| <script> | ||
| import { makeDateUtils } from '~/utils/DateUtils' | ||
| import PickerDay from '~/components/PickerDay' | ||
| import PickerMonth from '~/components/PickerMonth' | ||
| import PickerYear from '~/components/PickerYear' | ||
| import calendarProps from '~/mixins/calendarProps' | ||
| import sharedProps from '~/mixins/sharedProps' | ||
| import calendarSlots from '~/utils/calendarSlots' | ||
|
|
||
| export default { | ||
| name: 'Calendar', | ||
| components: { | ||
| PickerDay, | ||
| PickerMonth, | ||
| PickerYear, | ||
| }, | ||
| mixins: [ | ||
| calendarProps, | ||
| sharedProps, | ||
| ], | ||
| props: { | ||
| translation: { | ||
| type: Object, | ||
| default() { | ||
| return {} | ||
| }, | ||
| }, | ||
| open: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| value: { | ||
| type: Date, | ||
| default: null, | ||
| }, | ||
| }, | ||
| data() { | ||
| const constructedDateUtils = makeDateUtils(this.useUtc) | ||
| const startDate = constructedDateUtils.getNewDateObject(this.openDate) | ||
| const pageTimestamp = constructedDateUtils.setDate(startDate, 1) | ||
| return { | ||
| /* | ||
| * Vue cannot observe changes to a Date Object so date must be stored as a timestamp | ||
| * This represents the first day of the current viewing month | ||
| * {Number} | ||
| */ | ||
| pageTimestamp, | ||
| /* | ||
| * Selected Date | ||
| * {Date} | ||
| */ | ||
| selectedDate: null, | ||
| calendarSlots, | ||
| currentPicker: '', | ||
| utils: constructedDateUtils, | ||
| } | ||
| }, | ||
| computed: { | ||
| pageDate() { | ||
| return new Date(this.pageTimestamp) | ||
| }, | ||
|
|
||
| calendarStyle() { | ||
| return { | ||
| position: this.isInline ? 'static' : undefined, | ||
| } | ||
| }, | ||
| isInline() { | ||
| return !!this.inline | ||
| }, | ||
|
|
||
| computedInitialView() { | ||
| if (!this.initialView) { | ||
| return this.minimumView | ||
| } | ||
|
|
||
| return this.initialView | ||
| }, | ||
| }, | ||
| watch: { | ||
| initialView() { | ||
| this.setInitialView() | ||
| }, | ||
| openDate() { | ||
| this.setPageDate() | ||
| }, | ||
| value: { | ||
| handler(newValue) { | ||
| this.setValue(newValue) | ||
| }, | ||
| immediate: true, | ||
| }, | ||
| }, | ||
| mounted() { | ||
| this.init() | ||
| }, | ||
| methods: { | ||
| /** | ||
| * Initiate the component | ||
| */ | ||
| init() { | ||
| this.setInitialView() | ||
| }, | ||
| /** | ||
| * @param {Object} date | ||
| */ | ||
| selectDate(date) { | ||
| this.setDate(date.timestamp) | ||
| if (!this.isInline) { | ||
| this.close(true) | ||
| } | ||
| this.$emit('reset-typed-date', this.utils.getNewDateObject()) | ||
| }, | ||
| /** | ||
| * @param {Object} date | ||
| */ | ||
| selectDisabledDate(date) { | ||
| this.$emit('selected-disabled', date) | ||
| }, | ||
| /** | ||
| * @param {Object} month | ||
| */ | ||
| selectMonth(month) { | ||
| const date = new Date(month.timestamp) | ||
| if (this.allowedToShowView('day')) { | ||
| this.setPageDate(date) | ||
| this.$emit('changed-month', month) | ||
| this.showSpecificCalendar('Day') | ||
| } else { | ||
| this.selectDate(month) | ||
| } | ||
| }, | ||
| /** | ||
| * @param {Object} year | ||
| */ | ||
| selectYear(year) { | ||
| const date = new Date(year.timestamp) | ||
| if (this.allowedToShowView('month')) { | ||
| this.setPageDate(date) | ||
| this.$emit('changed-year', year) | ||
| this.showSpecificCalendar('Month') | ||
| } else { | ||
| this.selectDate(year) | ||
| } | ||
| }, | ||
| /** | ||
| * Handles a month change from the day picker | ||
| */ | ||
| handleChangedMonthFromDayPicker(date) { | ||
| this.setPageDate(date) | ||
| this.$emit('changed-month', date) | ||
| }, | ||
|
|
||
| /** | ||
| * Show a specific picker | ||
| * @return {Boolean} | ||
| */ | ||
| showSpecificCalendar(type) { | ||
| if (type) { | ||
| if (!this.allowedToShowView(type.toLowerCase())) { | ||
| return false | ||
| } | ||
| this.currentPicker = `Picker${type}` | ||
| return true | ||
| } | ||
| this.currentPicker = '' | ||
| return false | ||
| }, | ||
|
|
||
| /** | ||
| * Sets the initial picker page view: day, month or year | ||
| */ | ||
| setInitialView() { | ||
| const initialView = this.computedInitialView | ||
| if (!this.allowedToShowView(initialView)) { | ||
| throw new Error(`initialView '${this.initialView}' cannot be rendered based on minimum '${this.minimumView}' and maximum '${this.maximumView}'`) | ||
| } | ||
| switch (initialView) { | ||
| case 'year': | ||
| this.showSpecificCalendar('Year') | ||
| break | ||
| case 'month': | ||
| this.showSpecificCalendar('Month') | ||
| break | ||
| default: | ||
| this.showSpecificCalendar('Day') | ||
| break | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Are we allowed to show a specific picker view? | ||
| * @param {String} view | ||
| * @return {Boolean} | ||
| */ | ||
| allowedToShowView(view) { | ||
| const views = [ | ||
| 'day', | ||
| 'month', | ||
| 'year', | ||
| ] | ||
| const minimumViewIndex = views.indexOf(this.minimumView) | ||
| const maximumViewIndex = views.indexOf(this.maximumView) | ||
| const viewIndex = views.indexOf(view) | ||
|
|
||
| return viewIndex >= minimumViewIndex && viewIndex <= maximumViewIndex | ||
| }, | ||
|
|
||
| /** | ||
| * Sets the date that the calendar should open on | ||
| */ | ||
| setPageDate(date) { | ||
| let dateTemp = date | ||
| if (!dateTemp) { | ||
| if (this.openDate) { | ||
| dateTemp = new Date(this.openDate) | ||
| } else { | ||
| dateTemp = new Date() | ||
| } | ||
| dateTemp = this.utils.resetDateTime(dateTemp) | ||
| } | ||
| this.pageTimestamp = this.utils.setDate(new Date(dateTemp), 1) | ||
| }, | ||
| /** | ||
| * Set the selected date | ||
| * @param {Number} timestamp | ||
| */ | ||
| setDate(timestamp) { | ||
| const date = new Date(timestamp) | ||
| this.selectedDate = date | ||
| this.setPageDate(date) | ||
| this.$emit('selected', date) | ||
| this.$emit('input', date) | ||
| }, | ||
|
|
||
| /** | ||
| * Set the datepicker value | ||
| * @param {Date|String|Number|null} date | ||
| */ | ||
| setValue(date) { | ||
| let dateTemp = date | ||
| if (typeof dateTemp === 'string' || typeof dateTemp === 'number') { | ||
| const parsed = new Date(dateTemp) | ||
| dateTemp = Number.isNaN(parsed.valueOf()) ? null : parsed | ||
| } | ||
| if (!dateTemp) { | ||
| this.setPageDate() | ||
| this.selectedDate = null | ||
| return | ||
| } | ||
| this.selectedDate = dateTemp | ||
| this.setPageDate(dateTemp) | ||
| }, | ||
| close() { | ||
| this.$emit('close') | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
| <style lang="scss"> | ||
| @import '../styles/calendar.scss'; | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.