Skip to content

Commit

Permalink
remove raf hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Sep 23, 2024
1 parent 0282222 commit 128afda
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/components/SDatePickerBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const format = {
const weekdays = getWeekDays()
const key = computed(() => {
if (props.mode === 'days') {
return `${curr.value.month}-${curr.value.year}`
}
if (props.mode === 'months') {
return `${curr.value.year}`
}
return `${getYearForIndex(1)}-${getYearForIndex(20)}`
})
const isSelectedVisible = computed(() => {
if (props.mode === 'days') {
return curr.value.month === selected.value.month && curr.value.year === selected.value.year
Expand Down Expand Up @@ -239,7 +249,6 @@ function prev(action?: () => void): void {
if (isPrevDisabled.value) {
return
}
el.value?.classList.add('no-transition')
if (props.mode === 'days') {
curr.value.month--
if (curr.value.month === 0) {
Expand All @@ -252,14 +261,12 @@ function prev(action?: () => void): void {
curr.value.year -= 20
}
action?.()
requestAnimationFrame(() => el.value?.classList.remove('no-transition'))
}
function next(action?: () => void): void {
if (isNextDisabled.value) {
return
}
el.value?.classList.add('no-transition')
if (props.mode === 'days') {
curr.value.month++
if (curr.value.month === 13) {
Expand All @@ -272,7 +279,6 @@ function next(action?: () => void): void {
curr.value.year += 20
}
action?.()
requestAnimationFrame(() => el.value?.classList.remove('no-transition'))
}
function isToday(/** 1-indexed */ i: number): boolean {
Expand Down Expand Up @@ -366,10 +372,10 @@ function getFormatter(fmt: Intl.DateTimeFormat, type?: string) {
<div v-for="name in weekdays" :key="name">{{ name }}</div>
</div>
<div class="grid" ref="el">
<div v-for="i in offset" :key="i" />
<div v-for="i in offset" :key="`${key}-${i}`" />
<div
v-for="i in total"
:key="i"
:key="`${key}-${i + offset}`"
:class="{ today: isToday(i), selected: isSelected(i) }"
class="item"
:tabindex="isFocusable(i) ? 0 : -1"
Expand Down Expand Up @@ -408,7 +414,8 @@ function getFormatter(fmt: Intl.DateTimeFormat, type?: string) {
transition: background-color 0.25s;
border-radius: 4px;
&:hover:not(:disabled) {
&:hover:not(:disabled),
&:focus-visible:not(:disabled) {
background-color: var(--c-bg-mute-1);
}
Expand Down Expand Up @@ -464,10 +471,6 @@ function getFormatter(fmt: Intl.DateTimeFormat, type?: string) {
cursor: pointer;
border-radius: 4px;
.no-transition & {
transition: none;
}
&:hover {
background-color: var(--c-bg-info-dimm-a2);
}
Expand Down

0 comments on commit 128afda

Please sign in to comment.