Skip to content

Commit dd2e943

Browse files
committed
feat: improve year dropdown visually
1 parent 6ee551c commit dd2e943

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed
Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<template>
2-
<span :class="$style.container">
3-
<span :class="$style.placeholder">{{ value }}</span>
4-
<span ref="textWheelSelect" :class="[$style.textWheelSelect, { [$style.open]: showList }]">
2+
<span ref="container" :class="[$style.container, { [$style.open]: showList }]">
3+
<button :class="$style.currentValue" @click="showList = true">{{ value }}</button>
4+
<span :class="$style.textWheelSelect">
55
<button
66
v-for="v of values"
77
ref="items"
88
:key="v"
99
:data-value="v"
1010
type="button"
11-
:class="$style.value"
11+
:class="[$style.value, { [$style.current]: value === v }]"
1212
@click="select(v)"
1313
>
1414
{{ v }}
@@ -18,7 +18,7 @@
1818
</template>
1919

2020
<script lang="ts" setup generic="T extends string | number">
21-
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue';
21+
import { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue';
2222
import { useOutOfElementClick } from '@composables';
2323
2424
const emit = defineEmits<{
@@ -31,16 +31,16 @@ const props = defineProps<{
3131
}>();
3232
3333
const showList = ref(false);
34-
const textWheelSelect = useTemplateRef('textWheelSelect');
34+
const container = useTemplateRef('container');
3535
const items = useTemplateRef('items');
3636
3737
const visibleItemsWhenOpen = computed(() => Math.min(3, props.values.length));
3838
39-
useOutOfElementClick([textWheelSelect, items], () => (showList.value = false));
39+
useOutOfElementClick([container, items], () => (showList.value = false));
4040
4141
const focusValue = () =>
4242
items.value
43-
.find((el: HTMLButtonElement) => el.dataset.value === String(props.value))
43+
?.find((el: HTMLButtonElement) => el.dataset.value === String(props.value))
4444
?.scrollIntoView({ block: 'start' });
4545
4646
const select = (v: T) => {
@@ -52,58 +52,66 @@ const select = (v: T) => {
5252
}
5353
};
5454
55-
watch(() => props.value, focusValue);
56-
watch(showList, () => nextTick(focusValue));
55+
watch([toRef(props, 'value'), toRef(props, 'values'), items, showList], () => nextTick(focusValue));
5756
</script>
5857

5958
<style lang="scss" module>
6059
.container {
6160
display: flex;
6261
align-items: center;
6362
justify-content: center;
64-
z-index: 1;
63+
background: var(--c-primary);
64+
65+
&.open {
66+
.currentValue {
67+
visibility: hidden;
68+
}
69+
70+
.textWheelSelect {
71+
height: calc(22px * v-bind(visibleItemsWhenOpen));
72+
border-bottom-left-radius: var(--border-radius-l);
73+
border-bottom-right-radius: var(--border-radius-l);
74+
visibility: visible;
75+
76+
.value {
77+
padding: 0 7px;
78+
}
79+
}
80+
}
6581
}
6682
67-
.placeholder {
68-
visibility: hidden;
83+
.value,
84+
.currentValue {
85+
all: unset;
6986
font-size: var(--font-size-xs);
87+
color: var(--c-text-light);
88+
cursor: pointer;
7089
}
7190
7291
.textWheelSelect {
7392
overflow: auto;
7493
height: 22px;
75-
border-radius: var(--border-radius-l);
7694
top: 0;
7795
background: var(--c-primary);
7896
position: absolute;
7997
display: inline-grid;
8098
grid-auto-flow: row;
8199
-ms-overflow-style: none;
82100
scrollbar-width: none;
83-
84-
&.open {
85-
height: calc(22px * v-bind(visibleItemsWhenOpen));
86-
87-
.value {
88-
padding: 0 7px;
89-
}
90-
}
101+
visibility: hidden;
91102
}
92103
93104
.textWheelSelect::-webkit-scrollbar {
94105
display: none;
95106
}
96107
97108
.value {
98-
all: unset;
99-
cursor: pointer;
100109
height: 22px;
101110
padding: 0 3px;
102-
font-size: var(--font-size-xs);
103-
color: var(--c-text-light);
104111
105-
&.transition {
106-
transition: transform var(--transition-s);
112+
&:not(.current) {
113+
background: var(--c-primary-light);
114+
color: var(--c-text);
107115
}
108116
}
109117
</style>

0 commit comments

Comments
 (0)