Skip to content
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

[next] feat(NcDateTimePicker): migrate to vue 3 #4631

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = {
'cypress',
],
ignorePatterns: [
'src/components/NcDateTimePicker/*.vue',
'src/components/NcAction*/*.vue',
'src/components/NcAppContent*/*.vue',
'src/components/NcAppNavigation*/*.vue',
Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"unist-builder": "^4.0.0",
"unist-util-visit": "^5.0.0",
"vue": "^3.3.4",
"vue-datepicker-next": "^1.0.3",
"vue-material-design-icons": "^5.1.2",
"vue-select": "^4.0.0-beta.6"
},
Expand Down
34 changes: 17 additions & 17 deletions src/components/NcDateTimePicker/NcDateTimePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->

<docs>
> We're wrapping the awesome datepicker library here https://github.com/mengxiong10/vue2-datepicker
> We're wrapping the awesome datepicker library here https://github.com/mengxiong10/vue-datepicker-next
> Please check there for all the available options.

### Defaults
Expand Down Expand Up @@ -105,7 +105,7 @@ picked time zone, but you will have to convert it yourself when necessary.
v-model="time"
type="datetime"
:show-timezone-select="true"
:timezone-id.sync="tz" /><br>
v-model:timezone-id="tz" /><br>
raimund-schluessler marked this conversation as resolved.
Show resolved Hide resolved
{{ time }} | {{ tz }}
</span>
</template>
Expand Down Expand Up @@ -134,15 +134,13 @@ export default {
:popup-class="{ 'show-week-number': showWeekNumber }"
:show-week-number="showWeekNumber"
:type="type"
:value="value"
v-bind="$attrs"
v-on="$listeners"
:value="modelValue"
@select-year="handleSelectYear"
@select-month="handleSelectMonth"
@update:value="$emit('update:value', value)">
@update:value="$emit('update:modelValue', $event)">
<template #icon-calendar>
<NcPopover v-if="showTimezoneSelect"
:shown.sync="showTimezonePopover"
v-model:shown="showTimezonePopover"
popover-base-class="timezone-select__popper">
<template #trigger>
<button class="datetime-picker-inline-icon"
Expand All @@ -157,13 +155,13 @@ export default {
{{ t('Please select a time zone:') }}
</strong>
</div>
<NcTimezonePicker v-model="tzVal"
<NcTimezonePicker :model-value="tzVal"
class="timezone-popover-wrapper__timezone-select"
@input="$emit('update:timezone-id', arguments[0])" />
@update:model-value="$emit('update:timezone-id', $event)" />
</NcPopover>
<CalendarBlank v-else :size="20" />
</template>
<template v-for="(_, slot) of $scopedSlots" #[slot]="scope">
<template v-for="(_, slot) of $slots" #[slot]="scope">
<slot :name="slot" v-bind="scope" />
</template>
</DatePicker>
Expand All @@ -175,6 +173,7 @@ import { t } from '../../l10n.js'
import NcTimezonePicker from '../NcTimezonePicker/index.js'
import NcPopover from '../NcPopover/index.js'
import l10n from '../../mixins/l10n.js'
import ScopeComponent from '../../utils/ScopeComponent.js'

import CalendarBlank from 'vue-material-design-icons/CalendarBlank.vue'
import Web from 'vue-material-design-icons/Web.vue'
Expand All @@ -188,7 +187,8 @@ import {
getMonthNamesShort,
} from '@nextcloud/l10n'

import DatePicker from 'vue2-datepicker'
import DatePicker from 'vue-datepicker-next'
import './index.scss'

const formatMap = {
date: 'YYYY-MM-DD',
Expand All @@ -199,7 +199,7 @@ const formatMap = {
week: 'w',
}

export default {
export default ScopeComponent({
name: 'NcDateTimePicker',

components: {
Expand All @@ -211,7 +211,6 @@ export default {
},

mixins: [l10n],
inheritAttrs: false,

props: {
clearable: {
Expand Down Expand Up @@ -250,12 +249,12 @@ export default {
* value. You have to translate the time yourself when you want to factor in time zones.
*/
// eslint-disable-next-line
value: {
modelValue: {
default: () => new Date(),
},

/**
* The preselected IANA time zone ID for the time zone picker, only relevant in combination with `:show-timezone-select="true"`. Example: `Europe/Berlin`. The prop supports two-way binding through the .sync modifier.
* The preselected IANA time zone ID for the time zone picker, only relevant in combination with `:show-timezone-select="true"`. Example: `Europe/Berlin`. The prop supports two-way binding through v-model directive.
*/
timezoneId: {
type: String,
Expand Down Expand Up @@ -289,7 +288,7 @@ export default {
},

emits: [
'update:value',
'update:modelValue',
'update:timezone-id',
],

Expand Down Expand Up @@ -394,7 +393,8 @@ export default {
this.showTimezonePopover = !this.showTimezonePopover
},
},
}
})

</script>

<style lang="scss" scoped>
Expand Down
7 changes: 1 addition & 6 deletions src/components/NcDateTimePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import './index.scss'
import NcDateTimePicker from './NcDateTimePicker.vue'
import ScopeComponent from '../../utils/ScopeComponent.js'

ScopeComponent(NcDateTimePicker)

export default NcDateTimePicker
export { default } from './NcDateTimePicker.vue'
2 changes: 1 addition & 1 deletion src/components/NcDateTimePicker/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$cell_height: 32px;

@import 'vue2-datepicker/scss/index';
@import 'vue-datepicker-next/scss/index';

.mx-datepicker[data-v-#{$scope_version}] {
user-select: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ All available types are: 'date', 'datetime-local', 'month', 'time' and 'week', p
</template>

<script>
import ScopeComponent from '../../utils/ScopeComponent.js'

const inputDateTypes = ['date', 'datetime-local', 'month', 'time', 'week']

export default {
export default ScopeComponent({
name: 'NcDateTimePickerNative',
inheritAttrs: false,

Expand Down Expand Up @@ -361,7 +362,7 @@ export default {
}
},
},
}
})
</script>

<style lang="scss" scoped>
Expand Down
7 changes: 1 addition & 6 deletions src/components/NcDateTimePickerNative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,4 @@
*
*/

import NcDateTimePickerNative from './NcDateTimePickerNative.vue'
import ScopeComponent from '../../utils/ScopeComponent.js'

ScopeComponent(NcDateTimePickerNative)

export default NcDateTimePickerNative
export { default } from './NcDateTimePickerNative.vue'
15 changes: 8 additions & 7 deletions src/components/NcTimezonePicker/NcTimezonePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<template>
<span>
<NcTimezonePicker v-model="tz" />
{{ tz }}
</span>
</template>
<script>
Expand All @@ -41,7 +42,7 @@ export default {
</docs>

<template>
<NcSelect :value="selectedTimezone"
<NcSelect :model-value="selectedTimezone"
:options="options"
:multiple="false"
:clearable="false"
Expand Down Expand Up @@ -77,26 +78,26 @@ export default {
/**
* The selected timezone. Use v-model for two-way binding. The default timezone is floating, which means a time independent of timezone. See https://icalendar.org/CalDAV-Access-RFC-4791/7-3-date-and-floating-time.html for details.
*/
value: {
modelValue: {
type: String,
default: 'floating',
},
},
emits: ['input'],
emits: ['update:modelValue'],
computed: {
placeholder() {
return t('Type to search time zone')
},
selectedTimezone() {
for (const additionalTimezone of this.additionalTimezones) {
if (additionalTimezone.timezoneId === this.value) {
if (additionalTimezone.timezoneId === this.modelValue) {
return additionalTimezone
}
}

return {
label: getReadableTimezoneName(this.value),
timezoneId: this.value,
label: getReadableTimezoneName(this.modelValue),
timezoneId: this.modelValue,
}
},
options() {
Expand Down Expand Up @@ -128,7 +129,7 @@ export default {
/**
* Two-way binding of the value prop. Use v-model="selectedTimezone" for two-way binding
*/
this.$emit('input', newValue.timezoneId)
this.$emit('update:modelValue', newValue.timezoneId)
},

/**
Expand Down
4 changes: 2 additions & 2 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export { default as NcCounterBubble } from './NcCounterBubble/index.js'
// export { default as NcDashboardWidget } from './NcDashboardWidget/index.js'
// export { default as NcDashboardWidgetItem } from './NcDashboardWidgetItem/index.js'
export { default as NcDateTime } from './NcDateTime/index.js'
// export { default as NcDateTimePicker } from './NcDateTimePicker/index.js'
export { default as NcDateTimePicker } from './NcDateTimePicker/index.js'
export { default as NcDateTimePickerNative } from './NcDateTimePickerNative/index.js'
// Not exported on purpose
// export { default as NcEllipsisedOption } from './NcEllipsisedOption/index.js'
Expand Down Expand Up @@ -92,5 +92,5 @@ export { default as NcSettingsInputText } from './NcSettingsInputText/index.js'
export { default as NcSettingsSection } from './NcSettingsSection/index.js'
export { default as NcSettingsSelectGroup } from './NcSettingsSelectGroup/index.js'
export { default as NcTextField } from './NcTextField/index.js'
// export { default as NcTimezonePicker } from './NcTimezonePicker/index.js'
export { default as NcTimezonePicker } from './NcTimezonePicker/index.js'
// export { default as NcUserBubble } from './NcUserBubble/index.js'
2 changes: 2 additions & 0 deletions src/utils/ScopeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const ScopeComponent = (Component) => {
Component.mounted.push(function() {
this.$el.setAttribute(`data-v-${SCOPE_VERSION}`, '')
})

return Component
}

export default ScopeComponent
5 changes: 1 addition & 4 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ module.exports = async () => {
{
name: 'NcPickers',
components: [
//'src/components/Nc*Picker*/*.vue',
'src/components/NcColorPicker/*.vue',
'src/components/NcDateTimePickerNative*/*.vue',
'src/components/NcEmojiPicker/*.vue',
'src/components/Nc*Picker*/*.vue',
],
},
// {
Expand Down
Loading