Skip to content

Commit

Permalink
# Fix
Browse files Browse the repository at this point in the history
- When "maxDate" is not specified, the problem that the time after the current time cannot be selected
- On some devices, the options are cut off in the middle
  • Loading branch information
plusone-masaki committed Jan 31, 2022
1 parent 65055fc commit db52a25
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 35 deletions.
11 changes: 8 additions & 3 deletions src/assets/sass/vue-drumroll-datetime-picker.sass
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
.-selected
color: var(--selected-color)

.vdd-flex
display: flex

.v-drumroll-picker__overlay
height: 100%
left: 0
Expand Down Expand Up @@ -48,19 +45,27 @@
pointer-events: auto
position: relative

& .vue-scroll-picker,
& .vue-scroll-picker-list,
& .vue-scroll-picker-list-rotator
position: relative
width: fit-content

& > .vue-scroll-picker-layer
pointer-events: none

.top, .bottom
background: transparent

& > .vue-scroll-picker-group
display: flex
margin-left: .5em
margin-right: .5em
position: relative

& .vue-scroll-picker-item
text-align: var(--picker-align)
width: auto

.v-drumroll-picker--dialog
.v-drumroll-picker__container
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/useBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { calculatePattern, datestring } from '../modules/format-helper'

export default {
props: {
align: { type: String, default: 'center' },
align: { type: String, default: 'right' },
defaultValue: { type: String, default: undefined },
pattern: { type: Object, default: undefined },
format: { type: [String, Object], default: undefined },
Expand Down
17 changes: 0 additions & 17 deletions src/modules/format-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@ export const guessDateOrder = (baseFormat) => {
.map(item => item.type)
}

export const calculateWidth = str => {
let result = 0
for (let i = 0; i < str.length; i++) {
const chr = str.charCodeAt(i)
if ((chr >= 0x00 && chr < 0x81) ||
(chr === 0xf8f0) ||
(chr >= 0xff61 && chr < 0xffa0) ||
(chr >= 0xf8f1 && chr < 0xf8f4)) {
result += 0.6
} else {
result += 1
}
}

return result
}

/**
* Format date string
*
Expand Down
10 changes: 3 additions & 7 deletions src/pickers/BaseDatePicker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ScrollPickerGroup } from 'vue-scroll-picker'
import * as constants from '../assets/constants'
import dayjs from '../modules/dayjs'
import { calculateWidth, guessDateOrder } from '../modules/format-helper'
import { guessDateOrder } from '../modules/format-helper'
import useSensitivity from '../mixins/useSensitivity'
import DrumDivider from '../components/DrumDivider'
import BasePicker from './BasePicker'
Expand Down Expand Up @@ -151,7 +151,7 @@ export default {

let valueObj = dayjs.unix(value)
if (valueObj.isBefore(this.minDate)) valueObj = dayjs(this.minDate)
if (valueObj.isAfter(this.maxDate)) valueObj = dayjs(this.maxDate)
if (this.maxDate && valueObj.isAfter(this.maxDate)) valueObj = dayjs(this.maxDate)

if (this.value || valueObj.format(this.format) !== this.formatDefaultValue) {
this.$emit('input', valueObj.format(this.format))
Expand All @@ -162,14 +162,12 @@ export default {
render (h) {
const divider = this.separator || this.drumPattern.dividerDate || this.drumPattern['divider-date']
const drumDivider = divider ? h(DrumDivider, { props: { divider } }) : null
const sampleDate = dayjs('1989-12-31')

const drums = {
year: h(BasePicker, {
props: {
items: this.years,
unit: 'year',
width: calculateWidth(sampleDate.format(this.drumPattern.year)) + 'em',
...this.$props,
value: this.value || this.defaultValue,
},
Expand All @@ -181,7 +179,6 @@ export default {
props: {
items: this.months,
unit: 'month',
width: calculateWidth(sampleDate.format(this.drumPattern.month)) + 'em',
...this.$props,
value: this.value || this.defaultValue,
},
Expand All @@ -193,7 +190,6 @@ export default {
props: {
items: this.days,
unit: 'date',
width: calculateWidth(sampleDate.format(this.drumPattern.date)) + 'em',
...this.$props,
value: this.value || this.defaultValue,
},
Expand All @@ -210,6 +206,6 @@ export default {
if (divider && i < dateOrder.length - 1) pickers.push(drumDivider)
}

return h(ScrollPickerGroup, { class: 'vdd-flex' }, pickers)
return h(ScrollPickerGroup, pickers)
},
}
2 changes: 0 additions & 2 deletions src/pickers/BasePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ export default {
height: { type: [String, Number], default: '10em' },
unit: { type: String, required: true },
value: { type: [String, Number], default: undefined },
width: { type: [String, Number], default: '2em' },
},

render (h, { props, listeners }) {
return h(ScrollPicker, {
style: {
'--picker-align': props.align,
height: typeof props.height === 'string' ? props.height : props.height + 'px',
width: typeof props.width === 'string' ? props.width : props.width + 'px',
},
props: {
options: props.items,
Expand Down
6 changes: 1 addition & 5 deletions src/pickers/BaseTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DrumDivider from '../components/DrumDivider'
import BasePicker from './BasePicker'
import * as constants from '../assets/constants'
import useSensitivity from '../mixins/useSensitivity'
import { calculateWidth } from '../modules/format-helper'

export default {
name: 'BaseTimePicker',
Expand Down Expand Up @@ -124,15 +123,13 @@ export default {
render (h) {
const divider = this.separator || this.drumPattern.dividerTime || this.drumPattern['divider-time']
const drumDivider = divider ? h(DrumDivider, { props: { divider } }) : null
const sampleDate = dayjs('1989-12-31 10:10:10')

// 時
const hourPicker = h(BasePicker, {
props: {
...this.$props,
items: this.hours,
unit: 'hour',
width: calculateWidth(sampleDate.format(this.drumPattern.hour)) + 'em',
},
on: {
input: this.onInput,
Expand All @@ -145,14 +142,13 @@ export default {
...this.$props,
items: this.minutes,
unit: 'minute',
width: calculateWidth(sampleDate.format(this.drumPattern.minute)) + 'em',
},
on: {
input: this.onInput,
},
})

return h(ScrollPickerGroup, { class: 'vdd-flex' }, [
return h(ScrollPickerGroup, [
hourPicker,
drumDivider,
minutePicker,
Expand Down

0 comments on commit db52a25

Please sign in to comment.