From 989c0086a9f81babebac698fc6e7ccf44c219b8f Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Mon, 22 Jul 2019 17:41:56 +0800 Subject: [PATCH 01/16] feat(clickoutside): lazy click (handler is called when clicked second times) --- demo/components/timePickerDemo/index.vue | 32 +++ .../timePickerDemo/scaffold.demo.vue | 28 +++ demo/demo.vue | 4 + demo/index.js | 4 +- index.js | 2 + packages/common/DatePicker/src/main.vue | 18 +- .../common/DatePicker/src/panel/datetime.vue | 21 +- packages/common/Input/src/main.vue | 5 + packages/common/TimePicker/index.js | 8 + packages/common/TimePicker/src/main.vue | 218 ++++++++++++++++++ packages/directives/clickoutside.js | 24 +- packages/utils/clickoutsideDelegate.js | 6 +- styles/TimePicker.scss | 47 ++++ styles/index.scss | 1 + styles/theme/default.scss | 20 ++ 15 files changed, 405 insertions(+), 33 deletions(-) create mode 100644 demo/components/timePickerDemo/index.vue create mode 100644 demo/components/timePickerDemo/scaffold.demo.vue create mode 100644 packages/common/TimePicker/index.js create mode 100644 packages/common/TimePicker/src/main.vue create mode 100644 styles/TimePicker.scss diff --git a/demo/components/timePickerDemo/index.vue b/demo/components/timePickerDemo/index.vue new file mode 100644 index 000000000..28bc43eec --- /dev/null +++ b/demo/components/timePickerDemo/index.vue @@ -0,0 +1,32 @@ + + + diff --git a/demo/components/timePickerDemo/scaffold.demo.vue b/demo/components/timePickerDemo/scaffold.demo.vue new file mode 100644 index 000000000..4b3830996 --- /dev/null +++ b/demo/components/timePickerDemo/scaffold.demo.vue @@ -0,0 +1,28 @@ + + + diff --git a/demo/demo.vue b/demo/demo.vue index ade4c9167..a96d05a77 100644 --- a/demo/demo.vue +++ b/demo/demo.vue @@ -124,6 +124,10 @@ export default { name: 'Table', path: '/n-table' }, + { + name: 'TimePicker', + path: '/n-time-picker' + }, { name: 'Tooltip', path: '/n-tooltip' diff --git a/demo/index.js b/demo/index.js index e1cbb3dae..11b5e846d 100644 --- a/demo/index.js +++ b/demo/index.js @@ -26,6 +26,7 @@ import datePickerDemo from './components/datePickerDemo' import inputNumberDemo from './components/inputNumberDemo' import nimbusIconDemo from './components/nimbusIconDemo' import radioDemo from './components/radioDemo' +import timePickerDemo from './components/timePickerDemo' import notificationDemo from './components/notificationDemo' import nimbusConfirmCardDemo from './components/nimbusConfirmCardDemo' @@ -71,7 +72,8 @@ const routes = [ { path: '/n-date-picker', component: datePickerDemo }, { path: '/n-input-number', component: inputNumberDemo }, { path: '/n-nimbus-icon', component: nimbusIconDemo }, - { path: '/n-radio', component: radioDemo } + { path: '/n-radio', component: radioDemo }, + { path: '/n-time-picker', component: timePickerDemo } ] }, { diff --git a/index.js b/index.js index 6ee53fb76..870714b79 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,7 @@ import Alert from './packages/common/Alert' import DatePicker from './packages/common/DatePicker' import InputNumber from './packages/common/InputNumber' import Radio from './packages/common/Radio' +import TimePicker from './packages/common/TimePicker' import ServiceCard from './packages/nimbus/ServiceCard' import HomeLayout from './packages/nimbus/HomeLayout' @@ -65,6 +66,7 @@ function install (Vue) { InputNumber.install(Vue) NimbusIcon.install(Vue) Radio.install(Vue) + TimePicker.install(Vue) } export default { diff --git a/packages/common/DatePicker/src/main.vue b/packages/common/DatePicker/src/main.vue index 5b8e2b07e..46a72f081 100644 --- a/packages/common/DatePicker/src/main.vue +++ b/packages/common/DatePicker/src/main.vue @@ -6,14 +6,13 @@ [`n-date-picker--${size}-size`]: true, 'n-date-picker--disabled': disabled }" - @click="handleCalendarClick" > @@ -182,8 +181,8 @@ export default { } }, methods: { - handlePanelValueChange (value) { - this.$emit('change', value) + handlePanelValueChange (value, valueString) { + this.$emit('change', value, valueString) this.refreshSelectedDateTimeString() }, /** @@ -251,15 +250,6 @@ export default { closeTimeSelector () { this.showTimeSelector = false }, - /** - * To close timeSelector - */ - handleCalendarClick (e) { - if (!this.$refs.timeSelector) return - if (!this.$refs.timeSelector.contains(e.target) && this.$refs.timeSelector !== e.target) { - this.closeTimeSelector() - } - }, /** * If not selected, display nothing, * else update datetime related string @@ -296,7 +286,7 @@ export default { /** * Calendar view related methods */ - openCalendar () { + openCalendar (e) { /** * May leak memory here if change disabled from false to true */ diff --git a/packages/common/DatePicker/src/panel/datetime.vue b/packages/common/DatePicker/src/panel/datetime.vue index 7037ff477..b67e01c9b 100644 --- a/packages/common/DatePicker/src/panel/datetime.vue +++ b/packages/common/DatePicker/src/panel/datetime.vue @@ -2,7 +2,7 @@
+
+
+ +
+
+
+ +
+
+
+
+ {{ hour }} +
+
+
+
+ {{ minute }} +
+
+
+
+ {{ second }} +
+
+
+
+ + Cancel + + + Confirm + +
+
+
+
+
+
+ + + diff --git a/packages/directives/clickoutside.js b/packages/directives/clickoutside.js index dbf1ae073..b2d616011 100644 --- a/packages/directives/clickoutside.js +++ b/packages/directives/clickoutside.js @@ -2,25 +2,41 @@ import clickoutsideDelegate from '../utils/clickoutsideDelegate' const ctx = '@@clickoutsideContext' +function lazyHandler (handler) { + let called = false + return function () { + if (called) { + console.debug('[clickoutside] called') + handler() + } else { + console.debug('[clickoutside] lazy called') + called = true + } + } +} + const clickoutside = { + bind (el, bindings) { + console.debug('[clickoutside]: bind', el) + }, inserted (el, bindings) { - console.log('[clickoutside]: inserted') + console.debug('[clickoutside]: inserted') if (typeof bindings.value === 'function') { el[ctx] = { - handler: bindings.value + handler: bindings.modifiers.lazy ? lazyHandler(bindings.value) : bindings.value } clickoutsideDelegate.registerHandler(el, el[ctx].handler, false) } }, update (el, bindings) { if (typeof bindings.value === 'function') { - clickoutsideDelegate.unregisterHandler(el, el[ctx].handler) + clickoutsideDelegate.unregisterHandler(el[ctx].handler) el[ctx].handler = bindings.value clickoutsideDelegate.registerHandler(el, el[ctx].handler, false) } }, unbind (el) { - console.log('[clickoutside]: unbind') + console.debug('[clickoutside]: unbind') clickoutsideDelegate.unregisterHandler(el[ctx].handler) } } diff --git a/packages/utils/clickoutsideDelegate.js b/packages/utils/clickoutsideDelegate.js index 2f8de505f..cc50757dd 100644 --- a/packages/utils/clickoutsideDelegate.js +++ b/packages/utils/clickoutsideDelegate.js @@ -45,7 +45,7 @@ class ClickOutsideDelegate { } if (!this.handlerCount) { console.debug('[ClickOutsideDelegate]: remove handler from window') - window.removeEventListener('click', this.handleClickOutside, true) + window.removeEventListener('click', this.handleClickOutside) this.handlers = new Map() } } @@ -57,11 +57,11 @@ class ClickOutsideDelegate { if (!el) throw new Error('[ClickOutsideDelegate.registerHandler]: make sure `el` is an HTMLElement') } if (this.handlers.get(handler)) { - throw new Error('[ClickOutsideDelegate.registerHandler]: don\'t register duplicate event handler') + throw new Error('[ClickOutsideDelegate.registerHandler]: don\'t register duplicate event handler, if you want to do it, unregister this handler and reregister it.') } if (!this.handlerCount) { console.debug('[ClickOutsideDelegate]: add handler to window') - window.addEventListener('click', this.handleClickOutside, true) + window.addEventListener('click', this.handleClickOutside) } ++this.handlerCount this.handlers.set(handler, { els, once }) diff --git a/styles/TimePicker.scss b/styles/TimePicker.scss new file mode 100644 index 000000000..435bb7548 --- /dev/null +++ b/styles/TimePicker.scss @@ -0,0 +1,47 @@ +@include b(time-picker) { + background-color: rgba(97, 104, 132, 1); + box-shadow:0px 2px 20px 0px rgba(0,0,0,0.16); + font-size: 12px; + border-radius: 6px; + margin-top: 4px; + width: 180px; + @include fade-in-transition(time-picker, center top); + .n-time-picker__selection-wrapper { + + height: 244px; + border-bottom: 1px solid rgba(255, 255, 255, .07); + display: flex; + } + .n-time-picker__hour, .n-time-picker__minute, .n-time-picker__second { + @include scrollbar; + width: 60px; + height: 244px; + flex-direction: column; + overflow-y: scroll; + .n-time-picker__item { + cursor: pointer; + height: 35px; + display: flex; + align-items: center; + justify-content: center; + transition: background-color .2s $default-cubic-bezier, color .2s $default-cubic-bezier; + background: transparent; + &:hover { + background-color: rgba(99,226,183,0.12); + } + &.n-time-picker__item--active { + background-color: rgba(99,226,183,0.12); + color: rgba(99, 226, 183, 1); + } + } + } + .n-time-picker__actions { + // margin will boom! I don't know why + padding: 10px 15px; + display: flex; + justify-content: space-between; + .n-button { + margin: 0; + } + } +} \ No newline at end of file diff --git a/styles/index.scss b/styles/index.scss index 42d45fb34..3f3d456cc 100644 --- a/styles/index.scss +++ b/styles/index.scss @@ -21,6 +21,7 @@ @import './DatePicker.scss'; @import './InputNumber.scss'; @import './Radio.scss'; +@import './TimePicker.scss'; @import "./NimbusServiceLayout.scss"; @import "./Popover.scss"; diff --git a/styles/theme/default.scss b/styles/theme/default.scss index 223c1c480..71277d4f1 100644 --- a/styles/theme/default.scss +++ b/styles/theme/default.scss @@ -182,4 +182,24 @@ $default-font-family: 'Lato'; &.#{$namespace}-#{$block}--transition-leave-to { transition: opacity .2s $slow-out-cubic-bezier, transform .2s $slow-out-cubic-bezier; } +} + +@mixin fade-in-transition($block, $origin: left top) { + &.#{$namespace}-#{$block}--transition-enter-active, + &.#{$namespace}-#{$block}--transition-leave-active { + transform: scale(1); + opacity: 1; + } + &.#{$namespace}-#{$block}--transition-enter-active { + transform-origin: $origin; + transition: opacity .2s $fast-in-cubic-bezier, transform .2s $fast-in-cubic-bezier; + } + &.#{$namespace}-#{$block}--transition-enter, &.#{$namespace}-#{$block}--transition-leave-to { + opacity: 0; + transform-origin: $origin; + transform: scale(.9); + } + &.#{$namespace}-#{$block}--transition-leave-to { + transition: opacity .2s $slow-out-cubic-bezier, transform .2s $slow-out-cubic-bezier; + } } \ No newline at end of file From a69c43615190876b3bd4967c7cb1f6426ebc2fcf Mon Sep 17 00:00:00 2001 From: mangogan <1261639871@qq.com> Date: Mon, 22 Jul 2019 19:14:47 +0800 Subject: [PATCH 02/16] feature: store --- README.md | 2 +- demo/components/formDemo.vue | 184 +++++++++++++++++++++++++ demo/demo.vue | 4 + demo/index.js | 4 +- index.js | 4 + packages/common/Form/index.js | 10 ++ packages/common/Form/src/form-item.vue | 122 ++++++++++++++++ packages/common/Form/src/main.vue | 104 ++++++++++++++ packages/common/Input/src/main.vue | 22 +++ packages/mixins/emitter.js | 33 +++++ styles/Form.scss | 78 +++++++++++ styles/index.scss | 1 + 12 files changed, 566 insertions(+), 2 deletions(-) create mode 100644 demo/components/formDemo.vue create mode 100644 packages/common/Form/index.js create mode 100644 packages/common/Form/src/form-item.vue create mode 100644 packages/common/Form/src/main.vue create mode 100644 packages/mixins/emitter.js create mode 100644 styles/Form.scss diff --git a/README.md b/README.md index 5fea52bf5..6e1c6ce36 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Run `npm run test` to test all components. Run `npm run test-cov` to test all components and see detailed test coverage report. ## Want to see how component works -1. Run `npm run build` +1. Run `npm run dev` 2. Open `http://localhost:8086/` in browser. ## Want to add your own component There is no guideline for now. If you want to know how to do it, you can explore by yourself or ask `lecong.zhang@tusimple.ai`. diff --git a/demo/components/formDemo.vue b/demo/components/formDemo.vue new file mode 100644 index 000000000..c30eca359 --- /dev/null +++ b/demo/components/formDemo.vue @@ -0,0 +1,184 @@ + + \ No newline at end of file diff --git a/demo/demo.vue b/demo/demo.vue index ade4c9167..51004e0e9 100644 --- a/demo/demo.vue +++ b/demo/demo.vue @@ -127,6 +127,10 @@ export default { { name: 'Tooltip', path: '/n-tooltip' + }, + { + name: 'Form', + path: '/n-form' } ] } diff --git a/demo/index.js b/demo/index.js index b07c5d261..3a8e4d5fd 100644 --- a/demo/index.js +++ b/demo/index.js @@ -25,6 +25,7 @@ import datePickerDemo from './components/datePickerDemo' import inputNumberDemo from './components/inputNumberDemo' import nimbusIconDemo from './components/nimbusIconDemo' import radioDemo from './components/radioDemo' +import formDemo from './components/formDemo' import notificationDemo from './components/notificationDemo' import nimbusConfirmCardDemo from './components/nimbusConfirmCardDemo' @@ -68,7 +69,8 @@ const routes = [ { path: '/n-date-picker', component: datePickerDemo }, { path: '/n-input-number', component: inputNumberDemo }, { path: '/n-nimbus-icon', component: nimbusIconDemo }, - { path: '/n-radio', component: radioDemo } + { path: '/n-radio', component: radioDemo }, + { path: '/n-form', component: formDemo } ] }, { diff --git a/index.js b/index.js index 6ee53fb76..9a692a053 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,8 @@ import Alert from './packages/common/Alert' import DatePicker from './packages/common/DatePicker' import InputNumber from './packages/common/InputNumber' import Radio from './packages/common/Radio' +import Form from './packages/common/Form' +// import FormItem from './packages/common/Form/form-item' import ServiceCard from './packages/nimbus/ServiceCard' import HomeLayout from './packages/nimbus/HomeLayout' @@ -65,6 +67,8 @@ function install (Vue) { InputNumber.install(Vue) NimbusIcon.install(Vue) Radio.install(Vue) + Form.install(Vue) + // FormItem.install(Vue) } export default { diff --git a/packages/common/Form/index.js b/packages/common/Form/index.js new file mode 100644 index 000000000..63c617b9e --- /dev/null +++ b/packages/common/Form/index.js @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +import Form from './src/main.vue' +import FormItem from './src/form-item.vue' + +Form.install = function (Vue) { + Vue.component(Form.name, Form) + Vue.component(FormItem.name, FormItem) +} + +export default Form diff --git a/packages/common/Form/src/form-item.vue b/packages/common/Form/src/form-item.vue new file mode 100644 index 000000000..f9b4473bf --- /dev/null +++ b/packages/common/Form/src/form-item.vue @@ -0,0 +1,122 @@ + + diff --git a/packages/common/Form/src/main.vue b/packages/common/Form/src/main.vue new file mode 100644 index 000000000..bbe713c95 --- /dev/null +++ b/packages/common/Form/src/main.vue @@ -0,0 +1,104 @@ + + \ No newline at end of file diff --git a/packages/common/Input/src/main.vue b/packages/common/Input/src/main.vue index d4ca0f82e..cac1826c6 100644 --- a/packages/common/Input/src/main.vue +++ b/packages/common/Input/src/main.vue @@ -64,12 +64,22 @@ + +
-
- Form Item -
+
Form Item
- - - + + + + + + + + + + + + + + + + Definitely Maybe + + Be Here Now + + + Submit + Cancel + + +
+
+ +
+
+
+
Form of Label Position
+
+ + + - - + + - - + + - - + + - - - Definitely Maybe - - - Be Here Now - - - Be Here Now - + + Submit Cancel + + Submit + Cancel + -
- -
+
+
+
-
- Demo Form -
+
Validate Form
- - - + + + - - + + - - Ceshi - resetForm + + + + + + + + Definitely Maybe + Be Here Now + + + Submit + Reset + +
+
+ +
+
+
+
Form of Custom validate rules
+
+ + + + + + + + + + + + Commit + + +
+
+ +
+
+
+
Form of Dynamic
+
+ + + + + + Add item + Delete + + +
+
+
\ No newline at end of file diff --git a/demo/readme.js b/demo/readme.js index a535936c5..acd41378b 100644 --- a/demo/readme.js +++ b/demo/readme.js @@ -22,7 +22,7 @@ You MUST fix all lint warnings and errors before you push your Run npm run test-cov to test all components and see detailed test coverage report.

Want to see how component works

    -
  1. Run npm run build
  2. +
  3. Run npm run dev
  4. Open http://localhost:8086/ in browser.

Want to add your own component

diff --git a/packages/common/Form/src/form-item.vue b/packages/common/Form/src/form-item.vue index f9b4473bf..3a90c892e 100644 --- a/packages/common/Form/src/form-item.vue +++ b/packages/common/Form/src/form-item.vue @@ -12,6 +12,7 @@ @@ -443,7 +453,7 @@ - Add item + Add Delete @@ -584,10 +594,10 @@ export default { } ], validateForm: { - input: "", + input: "input", muti: { deep: { - select: "" + select: "Public" } }, datepicker: "", @@ -722,9 +732,9 @@ export default { }, methods: { formValidate(ref) { - // this.$refs[ref].validate((flag, res) => { - // console.log("validate all result", flag, res); - // }); + this.$refs[ref].validate((flag, res) => { + console.log("validate all result", flag, res); + }); new Promise((resolve, reject) => { this.$refs[ref].validate((valid, filed) => { if (valid) { @@ -741,8 +751,8 @@ export default { console.log("unpass", e); }); }, - resetForm() { - this.$refs["form3"].resetForm(); + formReset (ref) { + this.$refs[ref].resetForm(); }, dynamicAddItem() { let i = Object.keys(this.dynamic.email).length; @@ -758,7 +768,6 @@ export default { let keys = Object.keys(this.dynamic.email) let k = keys.pop() if (k) { - console.log(this.dynamic.email, k) this.$delete(this.dynamic.email, k) } } diff --git a/packages/common/Form/src/form-item.vue b/packages/common/Form/src/form-item.vue index 3a90c892e..b1e8186d8 100644 --- a/packages/common/Form/src/form-item.vue +++ b/packages/common/Form/src/form-item.vue @@ -12,6 +12,7 @@ diff --git a/packages/common/DatePicker/src/panel/datetime.vue b/packages/common/DatePicker/src/panel/datetime.vue index b67e01c9b..9f403c27d 100644 --- a/packages/common/DatePicker/src/panel/datetime.vue +++ b/packages/common/DatePicker/src/panel/datetime.vue @@ -8,100 +8,20 @@
- -
- - -
-
-
-
- {{ hour }} -
-
-
-
- {{ minute }} -
-
-
-
- {{ second }} -
-
-
-
- - Cancel - - - Confirm - -
-
-
-
+ /> +
-
Confirm @@ -205,15 +125,15 @@ import NIcon from '../../../Icon' import clickoutside from '../../../../directives/clickoutside' import NButton from '../../../Button' +import NTimePicker from '../../../TimePicker' +import NInput from '../../../Input' + +const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss' +const DATE_FORMAT = 'YYYY-MM-DD' +const DATE_VALIDATE_FORMAT = ['YYYY-MM-DD', 'YYYY-MM-D', 'YYYY-M-D', 'YYYY-M-DD'] + +const PLACEHOLDER = 'Select date and time' -const DATE_FORMAT = { - date: 'YYYY-MM-DD', - datetime: 'YYYY-MM-DD HH:mm:ss' -} -const PLACEHOLDER = { - date: 'Select date', - datetime: 'Select date and time' -} const TIME_CONST = { weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], hours: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'], @@ -224,74 +144,65 @@ const TIME_CONST = { export default { components: { NButton, - NIcon + NIcon, + NTimePicker, + NInput }, directives: { clickoutside }, - model: { - prop: 'value', - event: 'change' - }, props: { active: { type: Boolean, default: true }, value: { - type: [Number, String], + type: Number, required: false, default: null }, debug: { type: Boolean, default: false + }, + placeholder: { + type: String, + default: PLACEHOLDER + }, + format: { + type: String, + default: DATETIME_FORMAT } }, data () { return { - displayDateTimeString: '', displayDateString: '', - displayTimeString: '', - rightDisplayDateTimeString: '', - rightDisplayDateString: '', - rightDisplayTimeString: '', calendarDateTime: moment(), - rightCalendarDateTime: moment(), currentDateTime: moment(), - showTimeSelector: false, - showRightTimeSelector: false, calendar: [], - rightCalendar: [], ...TIME_CONST } }, computed: { - placeholder () { - return PLACEHOLDER[this.type] - }, - format () { - return DATE_FORMAT[this.type] - }, computedHour () { - if (this.computedSelectedDateTime) return this.computedSelectedDateTime.format('HH') + if (this.valueAsMoment) return this.valueAsMoment.format('HH') else return null }, computedMinute () { - if (this.computedSelectedDateTime) return this.computedSelectedDateTime.format('mm') + if (this.valueAsMoment) return this.valueAsMoment.format('mm') else return null }, computedSecond () { - if (this.computedSelectedDateTime) return this.computedSelectedDateTime.format('ss') + if (this.valueAsMoment) return this.valueAsMoment.format('ss') else return null }, /** * If value is valid return null. * If value is not valid, return moment(value) */ - computedSelectedDateTime () { + valueAsMoment () { if (this.value === null || this.value === undefined) return null - const newSelectedDateTime = moment(Number(this.value)) + const newSelectedDateTime = moment(this.value) if (newSelectedDateTime.isValid()) { return newSelectedDateTime } else { @@ -299,170 +210,113 @@ export default { } } }, + watch: { + valueAsMoment (newValue) { + if (newValue !== null) { + this.displayDateString = newValue.format(DATE_FORMAT) + } else { + this.displayDateString = '' + } + } + }, + created () { + if (this.valueAsMoment !== null) { + this.displayDateString = this.valueAsMoment.format(DATE_FORMAT) + } else { + this.displayDateString = '' + } + }, methods: { + dateArray, handleClickOutside () { this.closeCalendar() - console.log('clickoutside') }, - dateArray, - /** - * If new datetime is null or undefined, emit null to value. - * Else adjust new datetime by props.type and emit it to value. - */ setValue (newSelectedDateTime) { if (newSelectedDateTime === null || newSelectedDateTime === undefined) { - this.$emit('change', null) - return - } - if (newSelectedDateTime.isValid()) { - const adjustedDateTime = this.adjustDateTime(newSelectedDateTime) - if (this.computedSelectedDateTime === null || adjustedDateTime.valueOf() !== this.computedSelectedDateTime.valueOf()) { - this.refreshSelectedDateTimeString(adjustedDateTime) - this.$emit('change', adjustedDateTime.valueOf(), adjustedDateTime.format(this.format)) + this.$emit('input', null) + } else if (newSelectedDateTime.isValid()) { + const adjustedDateTime = this.adjustValue(newSelectedDateTime) + if (this.valueAsMoment === null || adjustedDateTime.valueOf() !== this.valueAsMoment.valueOf()) { + this.refreshDisplayDateString(adjustedDateTime) + this.$emit('input', adjustedDateTime.valueOf()) } } - // this.$nextTick(this.refreshSelectedDateTimeString) }, - adjustDateTime (datetime) { + adjustValue (datetime) { return moment(datetime).startOf('second') }, - justifySelectedDateTimeAfterChangeTimeString () { - if (this.computedSelectedDateTime === null) { - // case here is impossible for now, because you can't clear time for now + handleDateInput (value) { + const date = moment(value, DATE_FORMAT, true) + if (date.isValid()) { + if (!this.valueAsMoment) { + const newValue = moment() + newValue.year(date.year()) + newValue.month(date.month()) + newValue.date(date.date()) + this.$emit('input', this.adjustValue(newValue).valueOf()) + } else { + const newValue = this.valueAsMoment + newValue.year(date.year()) + newValue.month(date.month()) + newValue.date(date.date()) + this.$emit('input', this.adjustValue(newValue).valueOf()) + } } else { - const newDisplayDateTimeString = this.displayDateString + ' ' + this.displayTimeString - const newSelectedDateTime = moment(newDisplayDateTimeString, this.format, true) - this.setValue(newSelectedDateTime) + // do nothing } }, - handleTimeInput (e) { - const newDisplayDateTimeString = this.displayDateString + ' ' + e.target.value - const newSelectedDateTime = moment(newDisplayDateTimeString, this.format, true) - this.setValue(newSelectedDateTime) - }, - handleDateInput (e) { - const newDisplayDateTimeString = e.target.value + ' ' + this.displayTimeString - const newSelectedDateTime = moment(newDisplayDateTimeString, this.format, true) - this.setValue(newSelectedDateTime) - }, - handleTimeInputBlur () { - this.refreshSelectedDateTimeString() - }, handleDateInputBlur () { - this.refreshSelectedDateTimeString() - }, - handleTimeConfirmClick () { - this.justifySelectedDateTimeAfterChangeTimeString() - this.refreshSelectedDateTimeString() - this.closeTimeSelector() - }, - handleTimeCancelClick () { - this.closeTimeSelector() - }, - setHour (hour) { - try { - const timeArray = this.displayTimeString.split(':') - timeArray[0] = hour - this.displayTimeString = timeArray.join(':') - } catch (err) { - - } finally { - this.justifySelectedDateTimeAfterChangeTimeString() + const date = moment(this.displayDateString, DATE_VALIDATE_FORMAT, true) + if (date.isValid()) { + if (!this.valueAsMoment) { + const newValue = moment() + newValue.year(date.year()) + newValue.month(date.month()) + newValue.date(date.date()) + this.$emit('input', this.adjustValue(newValue).valueOf()) + } else { + const newValue = this.valueAsMoment + newValue.year(date.year()) + newValue.month(date.month()) + newValue.date(date.date()) + this.$emit('input', this.adjustValue(newValue).valueOf()) + } + } else { + this.refreshDisplayDateString() } }, - setMinute (minute) { - try { - const timeArray = this.displayTimeString.split(':') - timeArray[1] = minute - this.displayTimeString = timeArray.join(':') - } catch (err) { - - } finally { - this.justifySelectedDateTimeAfterChangeTimeString() - } - }, - setSecond (second) { - try { - const timeArray = this.displayTimeString.split(':') - timeArray[2] = second - this.displayTimeString = timeArray.join(':') - } catch (err) { - - } finally { - this.justifySelectedDateTimeAfterChangeTimeString() - } - }, - openTimeSelector () { - if (this.computedSelectedDateTime === null) { - this.setValue(moment()) - } - this.showTimeSelector = true - }, - closeTimeSelector () { - this.showTimeSelector = false - }, clearSelectedDateTime () { - this.setValue(null) - this.displayDateTimeString = '' + this.$emit('input', null) this.displayDateString = '' - this.displayTimeString = '' }, setSelectedDateTimeToNow () { - this.setValue(moment()) + this.$emit('input', this.adjustValue(moment()).valueOf()) this.calendarDateTime = moment() }, handleDateClick (dateItem) { let newSelectedDateTime = moment() - if (this.computedSelectedDateTime !== null) { - newSelectedDateTime = moment(this.computedSelectedDateTime) + if (this.valueAsMoment !== null) { + newSelectedDateTime = moment(this.valueAsMoment) } newSelectedDateTime = setDate(newSelectedDateTime, dateItem) - this.setValue(newSelectedDateTime) + this.$emit('input', this.adjustValue(newSelectedDateTime).valueOf()) }, /** * If not selected, display nothing, * else update datetime related string */ - refreshSelectedDateTimeString (time) { - if (this.computedSelectedDateTime === null) { - this.displayDateTimeString = '' + refreshDisplayDateString (time) { + if (this.valueAsMoment === null) { + this.displayDateString = '' return } if (time === undefined) { - time = this.computedSelectedDateTime + time = this.valueAsMoment } - this.displayDateTimeString = time.format(this.format) - this.displayDateString = time.format('YYYY-MM-DD') - this.displayTimeString = time.format('HH:mm:ss') + this.displayDateString = time.format(DATE_FORMAT) }, - /** - * If new time is invalid, do nothing. - * If valid, update. - */ - handleDateTimeInputEnter () { - const newSelectedDateTime = moment(this.displayDateTimeString, this.format, true) - this.setValue(newSelectedDateTime) - }, - /** - * If new SelectedDateTime is valid, update `selectedDateTime` and `calendarTime` - * Whatever happened, refresh selectedDateTime - */ - handleDateTimeInputBlur () { - const newSelectedDateTime = moment(this.displayDateTimeString, this.format, true) - this.setValue(newSelectedDateTime) - /** - * If newSelectedDateTime is invalid, display string need to be restored - */ - this.refreshSelectedDateTimeString() - }, - handleDateInputAndTimeInputConfirmClick () { - const newDisplayDateTimeString = `${this.displayDateString.trim()} ${this.displayTimeString.trim()}` - const newSelectedDateTime = moment(newDisplayDateTimeString, this.format, true) - if (this.computedSelectedDateTime === null) { - this.setValue(moment()) - } else { - this.setValue(newSelectedDateTime) - } + handleConfirmClick () { + this.$emit('confirm') this.closeCalendar() }, closeCalendar () { @@ -485,6 +339,9 @@ export default { prevMonth () { this.calendarDateTime.subtract(1, 'month') this.$forceUpdate() + }, + handleTimePickerInput (value) { + this.$emit('input', value) } } } diff --git a/packages/common/Modal/src/ModalContent.vue b/packages/common/Modal/src/ModalContent.vue index 41bf9fa11..a4289bfd7 100644 --- a/packages/common/Modal/src/ModalContent.vue +++ b/packages/common/Modal/src/ModalContent.vue @@ -23,6 +23,11 @@ export default { diff --git a/demo/components/datePickerDemo/Wrapper.vue b/demo/components/datePickerDemo/Wrapper.vue new file mode 100644 index 000000000..974991115 --- /dev/null +++ b/demo/components/datePickerDemo/Wrapper.vue @@ -0,0 +1,10 @@ + + diff --git a/demo/components/datePickerDemo/disabled.demo.vue b/demo/components/datePickerDemo/disabled.demo.vue index a6f48f14e..a4db66362 100644 --- a/demo/components/datePickerDemo/disabled.demo.vue +++ b/demo/components/datePickerDemo/disabled.demo.vue @@ -21,6 +21,7 @@ :disabled="disabled" @change="onDateChange" /> +
+ + diff --git a/demo/demo.vue b/demo/demo.vue index a96d05a77..ee7f63ca9 100644 --- a/demo/demo.vue +++ b/demo/demo.vue @@ -50,7 +50,6 @@ export default { }, { name: 'Common', - path: '/', childItems: [ { name: 'AdvanceTable', @@ -133,6 +132,15 @@ export default { path: '/n-tooltip' } ] + }, + { + name: 'Debug', + childItems: [ + { + name: 'Popover', + path: '/n-popover-debug' + } + ] } ] } diff --git a/demo/index.js b/demo/index.js index 11b5e846d..d92770e7c 100644 --- a/demo/index.js +++ b/demo/index.js @@ -34,6 +34,8 @@ import paginationDemo from './components/paginationDemo' import startPage from './components/startPage' import demo from './demo' +import popoverDebug from './debugComponents/popoverDebug' + Vue.use(NaiveUI) Vue.use(VueRouter) @@ -44,6 +46,10 @@ const routes = [ path: '/home-demo', component: homeDemo }, + { + path: '/n-popover-debug', + component: popoverDebug + }, { path: '/start', component: demo, diff --git a/packages/mixins/placeable.js b/packages/mixins/placeable.js index cbda12fe2..533c3ceab 100644 --- a/packages/mixins/placeable.js +++ b/packages/mixins/placeable.js @@ -87,19 +87,14 @@ export default { resizeDelegate.registerHandler(this.updatePosition) }, registerScrollListeners () { - let currentElement = this.$el + let currentElement = getParentNode(this.$el) while (true) { - console.log('currentElement', currentElement) currentElement = getScrollParent(currentElement) - if (currentElement === document.body || currentElement.nodeName === 'HTML') { - break - } + if (currentElement === null) break this.scrollListeners.push([currentElement, this.updatePosition]) currentElement = getParentNode(currentElement) } - this.scrollListeners.push([document, this.updatePosition]) - this.scrollListeners.push([document.body, this.updatePosition]) - console.log(this.scrollListeners) + // console.log(this.scrollListeners) for (const [el, handler] of this.scrollListeners) { scrollDelegate.registerHandler(el, handler) } diff --git a/packages/utils/dom/getParentNode.js b/packages/utils/dom/getParentNode.js index d2872f7f2..6bd21c01c 100644 --- a/packages/utils/dom/getParentNode.js +++ b/packages/utils/dom/getParentNode.js @@ -1,11 +1,11 @@ /** - * Returns the parentNode or the host of the element + * Returns the parentNode or the host of the element until document * @method * @param {Element} element * @returns {Element} parent */ export default function getParentNode (element) { - if (element.nodeName === 'HTML') { + if (element.nodeName === '#document') { return element } return element.parentNode || element.host diff --git a/packages/utils/dom/getScrollParent.js b/packages/utils/dom/getScrollParent.js index ad0f4146f..feec6f500 100644 --- a/packages/utils/dom/getScrollParent.js +++ b/packages/utils/dom/getScrollParent.js @@ -5,20 +5,20 @@ import getParentNode from './getParentNode' * Returns the scrolling parent of the given element * @method * @param {Element} element - * @returns {Element} scroll parent + * @returns {Element|null} scroll parent */ export default function getScrollParent (element) { // Return body, `getScroll` will take care to get the correct `scrollTop` from it if (!element) { - return document.body + return null } switch (element.nodeName) { case 'HTML': case 'BODY': - return element.ownerDocument.body + return document case '#document': - return element.body + return null } // Firefox want us to check `-x` and `-y` variations as well From 52596b5b67a623dabd04b8b32aaa23bdc8a208d9 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Thu, 25 Jul 2019 10:10:56 +0800 Subject: [PATCH 14/16] release: 0.2.32 --- demo/components/datePickerDemo/Oops.vue | 15 --------------- demo/components/datePickerDemo/Wrapper.vue | 10 ---------- demo/components/datePickerDemo/disabled.demo.vue | 7 ------- package.json | 2 +- 4 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 demo/components/datePickerDemo/Oops.vue delete mode 100644 demo/components/datePickerDemo/Wrapper.vue diff --git a/demo/components/datePickerDemo/Oops.vue b/demo/components/datePickerDemo/Oops.vue deleted file mode 100644 index c0eb2afd4..000000000 --- a/demo/components/datePickerDemo/Oops.vue +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/demo/components/datePickerDemo/Wrapper.vue b/demo/components/datePickerDemo/Wrapper.vue deleted file mode 100644 index 974991115..000000000 --- a/demo/components/datePickerDemo/Wrapper.vue +++ /dev/null @@ -1,10 +0,0 @@ - - diff --git a/demo/components/datePickerDemo/disabled.demo.vue b/demo/components/datePickerDemo/disabled.demo.vue index a4db66362..a6f48f14e 100644 --- a/demo/components/datePickerDemo/disabled.demo.vue +++ b/demo/components/datePickerDemo/disabled.demo.vue @@ -21,7 +21,6 @@ :disabled="disabled" @change="onDateChange" /> -
diff --git a/demo/demo.vue b/demo/demo.vue index 8c6668b6b..18a121569 100644 --- a/demo/demo.vue +++ b/demo/demo.vue @@ -141,8 +141,12 @@ export default { name: 'Debug', childItems: [ { - name: 'Popover', + name: 'PopoverDebug', path: '/n-popover-debug' + }, + { + name: 'RouterDebug', + path: '/n-router-debug' } ] } diff --git a/demo/index.js b/demo/index.js index 34be8e43d..042ca2e5f 100644 --- a/demo/index.js +++ b/demo/index.js @@ -36,6 +36,7 @@ import startPage from './components/startPage' import demo from './demo' import popoverDebug from './debugComponents/popoverDebug' +import routerDebug from './debugComponents/routerDebug' Vue.use(NaiveUI) Vue.use(VueRouter) @@ -81,7 +82,8 @@ const routes = [ { path: '/n-nimbus-icon', component: nimbusIconDemo }, { path: '/n-radio', component: radioDemo }, { path: '/n-form', component: formDemo }, - { path: '/n-time-picker', component: timePickerDemo } + { path: '/n-time-picker', component: timePickerDemo }, + { path: '/n-router-debug', component: routerDebug } ] }, { diff --git a/packages/nimbus/ServiceLayout/src/main.vue b/packages/nimbus/ServiceLayout/src/main.vue index 5d75562b7..d21c407e8 100644 --- a/packages/nimbus/ServiceLayout/src/main.vue +++ b/packages/nimbus/ServiceLayout/src/main.vue @@ -104,10 +104,6 @@ export default { paddingBody: { type: Boolean, default: true - }, - value: { - type: String, - default: '' } }, data () { @@ -121,31 +117,31 @@ export default { } }, watch: { - value () { - this.activeItemName = this.value + $route (to, from) { + this.syncActiveItemWithPath(to.path) } }, mounted () { - this.activeItemName = this.value const path = this.$route.path - for (const item of this.items) { - if (item.path === path) { - this.activeItemName = item.name - this.$emit('input', item.name) - return - } - if (item.childItems) { - for (const childItem of item.childItems) { - if (childItem.path === path) { - this.activeItemName = childItem.name - this.$emit('input', item.name) - return + this.syncActiveItemWithPath(path) + }, + methods: { + syncActiveItemWithPath (path) { + for (const item of this.items) { + if (item.path === path) { + this.activeItemName = item.name + return + } + if (item.childItems) { + for (const childItem of item.childItems) { + if (childItem.path === path) { + this.activeItemName = childItem.name + return + } } } } - } - }, - methods: { + }, toggle () { this.isCollapsed = !this.isCollapsed }, diff --git a/styles/NimbusServiceLayout.scss b/styles/NimbusServiceLayout.scss index ee5e9eb73..807c93e66 100644 --- a/styles/NimbusServiceLayout.scss +++ b/styles/NimbusServiceLayout.scss @@ -123,8 +123,13 @@ transition: opacity 0.3s cubic-bezier(0.4, 0.0, 0.2, 1); opacity: 1; } - &.n-nimbus-service-layout-drawer__item--active span{ - opacity: 1; + &.n-nimbus-service-layout-drawer__item--active { + &:not(.n-nimbus-service-layout-drawer__item--is-group-item) { + color: #63E2B7; + } + span { + opacity: 1; + } } &:hover span { opacity: 1; From f49997ef87586a7a88ef0ecbe100f42f067facf4 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Thu, 25 Jul 2019 10:49:05 +0800 Subject: [PATCH 16/16] release: 0.2.33 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a422e415..c860a52fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "naive-ui", - "version": "0.2.32", + "version": "0.2.33", "description": "", "main": "index.js", "scripts": {