Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e24cf6b
feat: add borders to the center of the picker that's visualize select…
rustem-nasyrov May 19, 2022
73f6f86
feat: add selection that's always centered
rustem-nasyrov May 19, 2022
83e95ab
feat: rename function
rustem-nasyrov May 20, 2022
061e0ba
feat: refactor debounced scroll function
rustem-nasyrov May 20, 2022
fa125b7
feat: add component property description
rustem-nasyrov May 20, 2022
7075d26
feat: add props translation
rustem-nasyrov May 20, 2022
59d424e
feat: add translation to framed property
rustem-nasyrov May 20, 2022
5131054
feat: add framed property usage example
rustem-nasyrov May 20, 2022
954b10e
feat: rename VaTimePickerColumn directory
rustem-nasyrov May 20, 2022
dc6e037
feat: update component export/import
rustem-nasyrov May 20, 2022
e0e7f08
fix: fix scroll flickering
rustem-nasyrov May 20, 2022
24a6ff5
feat: remove nested computed properties
rustem-nasyrov May 23, 2022
a6092dc
feat: add column vertical gap variable, remove cell height variable
rustem-nasyrov May 23, 2022
def65a2
feat: add time picker cell height variable
rustem-nasyrov May 23, 2022
f9c06a3
feat: refactoring
rustem-nasyrov May 23, 2022
d461ca8
feat: remove redundant datasets
rustem-nasyrov May 23, 2022
ace6564
feat: move types to the separate file and folder
rustem-nasyrov May 23, 2022
c9015bd
feat: rewrite height constants to the component props
rustem-nasyrov May 23, 2022
236e685
fix: remove v-bind, set variable cell height through css variable in …
rustem-nasyrov May 23, 2022
6a3f689
feat: restore animation
rustem-nasyrov May 23, 2022
a3ee168
feat: refactor styles
rustem-nasyrov May 24, 2022
81eb2f1
feat: move child component to the components folder
rustem-nasyrov May 24, 2022
9e5b9af
feat: refactoring
rustem-nasyrov May 24, 2022
a1b546c
feat: refactor semicolons
rustem-nasyrov May 25, 2022
d02fea0
feat: automatically calculate height of the component
rustem-nasyrov May 25, 2022
549fdbc
feat: add new prop description
rustem-nasyrov May 25, 2022
48b748e
feat: add prop usage example
rustem-nasyrov May 25, 2022
af8770f
feat: add new property usage example to the docs
rustem-nasyrov May 25, 2022
e1b9c31
feat: refactor demo examples
rustem-nasyrov May 25, 2022
fffc8b9
feat: add spacing between exports declarations
rustem-nasyrov May 25, 2022
2e5a8b9
feat: refactoring
rustem-nasyrov May 25, 2022
32c842c
feat: add selected values background
rustem-nasyrov May 27, 2022
0651b79
feat: fix scroll behavior
rustem-nasyrov May 27, 2022
7246898
Merge branch 'develop' into feat/improve-time-picker-behavior
rustem-nasyrov Jun 1, 2022
27d2251
feat: fix scroll
rustem-nasyrov Jun 1, 2022
4238701
Merge branch 'develop' into feat/improve-time-picker-behavior
rustem-nasyrov Jun 8, 2022
9d4899f
Merge branch 'develop' into feat/improve-time-picker-behavior
rustem-nasyrov Jun 13, 2022
671ae70
feat: refactor demo
rustem-nasyrov Jun 15, 2022
d012544
feat: handle filtered values
rustem-nasyrov Jun 15, 2022
abd0237
feat: add passive flag to the listeners
rustem-nasyrov Jun 20, 2022
c742cad
Merge branch 'develop' into feat/improve-time-picker-behavior
rustem-nasyrov Jun 28, 2022
71809fc
feat: refactor
rustem-nasyrov Jun 28, 2022
0d6c655
Merge branch 'epicmaxco:develop' into feat/improve-time-picker-behavior
rustem-nasyrov Jun 30, 2022
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
15 changes: 13 additions & 2 deletions packages/docs/src/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1134,12 +1134,15 @@
},
"VaTimePicker": {
Copy link
Copy Markdown
Member

@Derranion Derranion May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some examples of this:

Clicked on 8 hours, 9 hours are selected as the result.

incorrecetTimeSelection

Copy link
Copy Markdown
Member

@Derranion Derranion Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update:
Now bug shows only when clicking a few times at the bottom.

Copy link
Copy Markdown
Member

@Derranion Derranion Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant - you need to scroll down with am\pm mode active and select 8 hours.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While scrolling TimePicker it may roll back from time to time unpredictably.

scrolledDownRolledBackSelectedTime

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AM \ PM toggle changes selection to invalid time.

amPmToggleSelectsInvalidTime

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant

"props": {
"ampm": "Use 12-hours time format.",
"ampm": "Use 12-hours time format",
"hoursFilter": "Function that allows you to hide some specific hours",
"minutesFilter": "Function that allows you to hide some specific minutes",
"secondsFilter": "Function that allows you to hide some specific seconds",
"view": "View specifying which columns will be shown",
"periodUpdatesModelValue": "If user will change period it will automatically update model value. You can turn off it and am/pm switch will only change view."
"periodUpdatesModelValue": "If user will change period it will automatically update model value. You can turn off it and am/pm switch will only change view.",
"framed": "Adds borders to center of the picker",
"cellHeight": "Height of the time cell",
"visibleCellsCount": "Count of time cells to display"
},
"events": {},
"methods": {},
Expand Down Expand Up @@ -3855,6 +3858,14 @@
"title": "Default",
"text": ""
},
"framed": {
"title": "Framed",
"text": ""
},
"visibleCellsCount": {
"title": "Controlling the count of displayed cells",
"text": "For the better view need to set odd numbers"
},
"readonlyAndDisabled": {
"title": "Readonly and disabled",
"text": ""
Expand Down
20 changes: 19 additions & 1 deletion packages/docs/src/locales/ru/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,17 @@
"slots": {}
},
"VaTimePicker": {
"props": {},
"props": {
"ampm": "12 часовой формат",
"hoursFilter": "Функция, позволяющая скрыть определенные часы",
"minutesFilter": "Функция, позволяющая скрыть определенные минуты",
"secondsFilter": "Функция, позволяющая скрыть определенные секунды",
"view": "Отображение только выбранных колонок",
"periodUpdatesModelValue": "Изменение периода времен автоматически обновит model value при переключении AM/PM",
"framed": "Добавляет рамки по центру компонента для выделения выбранных значений",
"cellHeight": "Высота ячейки времени",
"visibleCellsCount": "Количество ячеек времени для отображения"
},
"events": {},
"methods": {},
"slots": {}
Expand Down Expand Up @@ -3732,6 +3742,14 @@
"title": "Базовое использование",
"text": ""
},
"framed": {
"title": "Рамки",
"text": ""
},
"visibleCellsCount": {
"title": "Контроль количества отображаемых ячеек",
"text": "Для лучшего вида, нужно задавать нечетные числа"
},
"readonlyAndDisabled": {
"title": "Только для чтения и отключение",
"text": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<h6>{{ value.getHours() }}:{{ value.getMinutes() }}:{{ value.getSeconds() }}</h6>

<va-time-picker v-model="value" framed />
</template>

<script>
export default {
data () {
return {
value: new Date(),
}
},
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<h6>{{ value.getHours() }}:{{ value.getMinutes() }}:{{ value.getSeconds() }}</h6>

<div class="d-flex">
<va-time-picker v-model="value" visible-cells-count="3" />
<va-divider vertical />
<va-time-picker v-model="value" visible-cells-count="8" />
<va-divider vertical />
<va-time-picker v-model="value" visible-cells-count="5" />
<va-divider vertical />
<va-time-picker v-model="value" visible-cells-count="9" />
</div>
</template>

<script>
export default {
data () {
return { value: new Date() }
},
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const config: ApiDocsBlock[] = [
'default',
),

...block.exampleBlock(
'timePicker.examples.framed.title',
'timePicker.examples.framed.text',
'framed',
),

...block.exampleBlock(
'timePicker.examples.visibleCellsCount.title',
'timePicker.examples.visibleCellsCount.text',
'visibleCellsCount',
),

...block.exampleBlock(
'timePicker.examples.readonlyAndDisabled.title',
'timePicker.examples.readonlyAndDisabled.text',
Expand Down
71 changes: 58 additions & 13 deletions packages/ui/src/components/va-time-picker/VaTimePicker.demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,43 @@
</VbCard>

<VbCard title="view">
<VaTimePicker v-model="value" :view="'seconds'" />
<br />
<VaTimePicker v-model="value" :view="'hours'" />
<div class="d-flex">
<VaTimePicker v-model="value" :view="'seconds'" />
<va-divider vertical />
<VaTimePicker v-model="value" :view="'hours'" />
</div>
</VbCard>

<VbCard title="ampm">
<VaTimePicker v-model="value" :ampm="ampm" />
<br />
<VaTimePicker v-model="value" :ampm="ampm" />
<div class="d-flex">
<VaTimePicker v-model="value" :ampm="ampm" />
<va-divider vertical />
<VaTimePicker v-model="value" :ampm="ampm" />
</div>
</VbCard>

<VbCard title="value">
23:05:53
<br />
{{ value.getHours() }}:{{ value.getMinutes() }}:{{ value.getSeconds() }}
<div class="d-flex justify--space-around">
<span>23:05:53</span>
<span>{{ selectedTime }}</span>
</div>
<br />
<VaTimePicker v-model="value" :ampm="true" />
<br />
<VaTimePicker v-model="value" :ampm="false" :view="'seconds'" />
<div class="d-flex">
<VaTimePicker v-model="value" :ampm="true" />
<va-divider vertical />
<VaTimePicker v-model="value" :ampm="false" :view="'seconds'" />
</div>
</VbCard>

<VbCard title="filter">
<VaTimePicker v-model="value" :view="'seconds'" :ampm="false" :hoursFilter="(h) => h >= 9 && h <= 19" :minutesFilter="(m) => m % 10 === 0" :secondsFilter="(s) => s % 20 === 0" />
<VaTimePicker
v-model="value"
view="seconds"
:ampm="false"
:hoursFilter="(h) => h >= 9 && h <= 19"
:minutesFilter="(m) => m % 10 === 0"
:secondsFilter="(s) => s % 20 === 0"
/>
</VbCard>

<VbCard title="readonly">
Expand All @@ -45,6 +59,26 @@
<VbCard title="disabled">
<VaTimePicker v-model="value" disabled />
</VbCard>

<VbCard title="Framed">
<VaTimePicker v-model="value" framed />
</VbCard>

<VbCard title="Visible cells count">
<div class="d-flex justify--space-around">
<span>Show 2</span>
<span>Show 5</span>
<span>Show 12</span>
</div>
<br />
<div class="d-flex">
<VaTimePicker v-model="value" visible-cells-count="2" />
<va-divider vertical />
<VaTimePicker v-model="value" visible-cells-count="5" />
<va-divider vertical />
<VaTimePicker v-model="value" visible-cells-count="9" />
</div>
</VbCard>
</VbDemo>
</template>

Expand All @@ -63,5 +97,16 @@ export default {
ampm: false,
}
},

computed: {
selectedTime () {
const formatTime = (time) => time < 10 ? `0${time}` : time
const hours = formatTime(this.value.getHours())
const minutes = formatTime(this.value.getMinutes())
const seconds = formatTime(this.value.getSeconds())

return `${hours}:${minutes}:${seconds}`
},
},
}
</script>
58 changes: 51 additions & 7 deletions packages/ui/src/components/va-time-picker/VaTimePicker.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<template>
<div class="va-time-picker" :class="computedClass">
<div
class="va-time-picker"
:class="computedClass"
:style="computedStyles"
>
<VaTimePickerColumn
v-for="(column, idx) in columns" :key="idx"
:ref="setItemRef"
:items="column.items"
:tabindex="disabled ? -1 : 0"
:cell-height="$props.cellHeight"
v-model:activeItemIndex="column.activeItem.value"
@keydown.right.stop.prevent="focusNext()"
@keydown.tab.exact.stop.prevent="focusNext()"
Expand All @@ -16,11 +21,11 @@
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue'
import { defineComponent, ref, computed, PropType } from 'vue'
import { useTimePicker } from './hooks/useTimePicker'
import VaTimePickerColumn from './components/VaTimePickerColumn.vue'
import VaTimePickerColumn from './components/VaTimePickerColumn'
import { useStateful, useStatefulEmits, useStatefulProps } from '../../composables/useStateful'
import { useFormProps, useForm } from '../../composables/useForm'
import { useForm, useFormProps } from '../../composables/useForm'
import { useArrayRefs } from '../../composables/useArrayRefs'

export default defineComponent({
Expand All @@ -39,6 +44,9 @@ export default defineComponent({
hoursFilter: { type: Function as PropType<(h: number) => boolean> },
minutesFilter: { type: Function as PropType<(h: number) => boolean> },
secondsFilter: { type: Function as PropType<(h: number) => boolean> },
framed: { type: Boolean, default: false },
cellHeight: { type: Number, default: 30 },
visibleCellsCount: { type: Number, default: 7 },
},

emits: useStatefulEmits,
Expand All @@ -59,23 +67,42 @@ export default defineComponent({
idx ? pickers.value[idx]?.blur() : pickers.value.forEach((el) => el?.blur())
}

const { createComputedClass } = useForm(props)

const focusNext = () => {
const nextIndex = (activeColumnIndex?.value || 0) + 1

activeColumnIndex.value = nextIndex % columns.value.length
focus(activeColumnIndex.value)
}

const focusPrev = () => {
const nextIndex = (activeColumnIndex?.value || 0) - 1 + columns.value.length

activeColumnIndex.value = nextIndex % columns.value.length
focus(activeColumnIndex.value)
}

const { createComputedClass } = useForm(props)
const formClasses = createComputedClass('va-time-picker')

const computedClass = computed(() => ({
...formClasses.value,
'va-time-picker--framed': props.framed,
}))

const computedStyles = computed(() => {
const gapHeight = (props.visibleCellsCount - 1) / 2 * props.cellHeight

return {
'--va-time-picker-height': `${props.cellHeight * props.visibleCellsCount}px`,
'--va-time-picker-cell-height': `${props.cellHeight}px`,
'--va-time-picker-column-gap-height': `${gapHeight}px`,
}
})

return {
columns,
computedClass: createComputedClass('va-time-picker'),
computedClass,
computedStyles,
isPM,
pickers,
setItemRef,
Expand Down Expand Up @@ -122,5 +149,22 @@ export default defineComponent({

opacity: var(--va-time-picker-disabled-opacity);
}

&--framed {
position: relative;

&::before {
content: "";
height: var(--va-time-picker-cell-height);
width: 100%;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
border-top: 1px solid var(--va-divider);
border-bottom: 1px solid var(--va-divider);
z-index: 0;
}
}
}
</style>
1 change: 0 additions & 1 deletion packages/ui/src/components/va-time-picker/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.va-time-picker {
--va-time-picker-display: inline-flex;
--va-time-picker-height: 200px;
--va-time-picker-disabled-opacity: 0.4;
}
Loading