Skip to content

Commit c1c337c

Browse files
committed
refactor(lint): remove the lint
1 parent a9af06c commit c1c337c

File tree

8 files changed

+240
-184
lines changed

8 files changed

+240
-184
lines changed

packages/Toast.vue

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
aria-atomic="true"
66
role="status"
77
tabindex="0"
8-
data-sonner-toast=""
8+
data-sonner-toast="true"
99
:class="toastClass"
1010
:data-rich-colors="toast.richColors ?? defaultRichColors"
1111
:data-styled="!Boolean(toast.component || toast?.unstyled || unstyled)"
@@ -30,7 +30,7 @@
3030
'--offset': `${removed ? offsetBeforeRemove : offset}px`,
3131
'--initial-height': expandByDefault ? 'auto' : `${initialHeight}px`,
3232
...style,
33-
...toastStyle,
33+
...toastStyle
3434
}"
3535
@pointerdown="onPointerDown"
3636
@pointerup="onPointerUp"
@@ -40,12 +40,12 @@
4040
<button
4141
:aria-label="closeButtonAriaLabel || 'Close toast'"
4242
:data-disabled="disabled"
43-
data-close-button
43+
data-close-button="true"
4444
:class="cn(classes?.closeButton, toast?.classes?.closeButton)"
4545
@click="handleCloseToast"
4646
>
4747
<template v-if="icons?.close">
48-
<component :is="icons?.close"/>
48+
<component :is="icons?.close" />
4949
</template>
5050
<template v-else>
5151
<slot name="close-icon" />
@@ -99,7 +99,7 @@
9999
descriptionClass,
100100
toastDescriptionClass,
101101
classes?.description,
102-
toast.classes?.description,
102+
toast.classes?.description
103103
)
104104
"
105105
>
@@ -198,22 +198,24 @@ const toastStyle = props.toast.style || {}
198198
// Height index is used to calculate the offset as it gets updated before the toast array, which means we can calculate the new layout faster.
199199
const heightIndex = computed(
200200
() =>
201-
props.heights.findIndex(height => height.toastId === props.toast.id) || 0,
201+
props.heights.findIndex((height) => height.toastId === props.toast.id) || 0
202202
)
203203
const closeButton = computed(() => props.toast.closeButton ?? props.closeButton)
204204
const duration = computed(
205-
() => props.toast.duration || props.duration || TOAST_LIFETIME,
205+
() => props.toast.duration || props.duration || TOAST_LIFETIME
206206
)
207207
208208
const closeTimerStartTimeRef = ref(0)
209209
const offset = ref(0)
210210
const lastCloseTimerStartTimeRef = ref(0)
211-
const pointerStartRef = ref<{ x: number, y: number } | null>(null)
211+
const pointerStartRef = ref<{ x: number; y: number } | null>(null)
212212
const coords = computed(() => props.position.split('-'))
213213
const y = computed(() => coords.value[0])
214214
const x = computed(() => coords.value[1])
215215
const isStringOfTitle = computed(() => typeof props.toast.title !== 'string')
216-
const isStringOfDescription = computed(() => typeof props.toast.description !== 'string')
216+
const isStringOfDescription = computed(
217+
() => typeof props.toast.description !== 'string'
218+
)
217219
218220
const toastsHeightBefore = computed(() => {
219221
return props.heights.reduce((prev, curr, reducerIndex) => {
@@ -230,8 +232,7 @@ const invert = computed(() => props.toast.invert || props.invert)
230232
const disabled = computed(() => toastType.value === 'loading')
231233
232234
onMounted(() => {
233-
if (!mounted.value)
234-
return
235+
if (!mounted.value) return
235236
236237
const toastNode = toastRef.value
237238
const originalHeight = toastNode?.style.height
@@ -243,24 +244,23 @@ onMounted(() => {
243244
244245
let newHeightArr
245246
const alreadyExists = props.heights.find(
246-
height => height.toastId === props.toast.id,
247+
(height) => height.toastId === props.toast.id
247248
)
248249
249250
if (!alreadyExists) {
250251
newHeightArr = [
251252
{
252253
toastId: props.toast.id,
253254
height: newHeight,
254-
position: props.toast.position,
255+
position: props.toast.position
255256
},
256-
...props.heights,
257+
...props.heights
257258
]
258-
}
259-
else {
260-
newHeightArr = props.heights.map(height =>
259+
} else {
260+
newHeightArr = props.heights.map((height) =>
261261
height.toastId === props.toast.id
262262
? { ...height, height: newHeight }
263-
: height,
263+
: height
264264
)
265265
}
266266
@@ -271,7 +271,9 @@ function deleteToast() {
271271
// Save the offset for the exit swipe animation
272272
removed.value = true
273273
offsetBeforeRemove.value = offset.value
274-
const height = props.heights.filter(height => height.toastId !== props.toast.id)
274+
const height = props.heights.filter(
275+
(height) => height.toastId !== props.toast.id
276+
)
275277
emit('update:heights', height)
276278
277279
setTimeout(() => {
@@ -289,27 +291,24 @@ function handleCloseToast() {
289291
}
290292
291293
function onPointerDown(event: PointerEvent) {
292-
if (disabled.value || !dismissible.value)
293-
return
294+
if (disabled.value || !dismissible.value) return
294295
dragStartTime.value = new Date()
295296
offsetBeforeRemove.value = offset.value
296297
// Ensure we maintain correct pointer capture even when going outside of the toast (e.g. when swiping)
297298
;(event.target as HTMLElement).setPointerCapture(event.pointerId)
298-
if ((event.target as HTMLElement).tagName === 'BUTTON')
299-
return
299+
if ((event.target as HTMLElement).tagName === 'BUTTON') return
300300
swiping.value = true
301301
pointerStartRef.value = { x: event.clientX, y: event.clientY }
302302
}
303303
304304
function onPointerUp() {
305-
if (swipeOut.value)
306-
return
305+
if (swipeOut.value) return
307306
pointerStartRef.value = null
308307
309308
const swipeAmount = Number(
310309
toastRef.value?.style
311310
.getPropertyValue('--swipe-amount')
312-
.replace('px', '') || 0,
311+
.replace('px', '') || 0
313312
)
314313
315314
const timeTaken = new Date().getTime() - dragStartTime.value?.getTime()!
@@ -329,8 +328,7 @@ function onPointerUp() {
329328
}
330329
331330
function onPointerMove(event: PointerEvent) {
332-
if (!pointerStartRef.value || !dismissible.value)
333-
return
331+
if (!pointerStartRef.value || !dismissible.value) return
334332
335333
const yPosition = event.clientY - pointerStartRef.value.y
336334
const xPosition = event.clientX - pointerStartRef.value.x
@@ -342,8 +340,7 @@ function onPointerMove(event: PointerEvent) {
342340
343341
if (isAllowedToSwipe) {
344342
toastRef.value?.style.setProperty('--swipe-amount', `${yPosition}px`)
345-
}
346-
else if (Math.abs(xPosition) > swipeStartThreshold) {
343+
} else if (Math.abs(xPosition) > swipeStartThreshold) {
347344
// User is swiping in wrong direction so we disable swipe gesture
348345
// for the current pointer down interaction
349346
pointerStartRef.value = null
@@ -356,9 +353,9 @@ watchEffect(() => {
356353
357354
watchEffect((onInvalidate) => {
358355
if (
359-
(props.toast.promise && toastType.value === 'loading')
360-
|| props.toast.duration === Infinity
361-
|| props.toast.type === 'loading'
356+
(props.toast.promise && toastType.value === 'loading') ||
357+
props.toast.duration === Infinity ||
358+
props.toast.type === 'loading'
362359
) {
363360
return
364361
}
@@ -378,8 +375,7 @@ watchEffect((onInvalidate) => {
378375
}
379376
380377
const startTimer = () => {
381-
if (remainingTime === Infinity)
382-
return
378+
if (remainingTime === Infinity) return
383379
closeTimerStartTimeRef.value = new Date().getTime()
384380
385381
// Let the toast know it has started
@@ -390,13 +386,12 @@ watchEffect((onInvalidate) => {
390386
}
391387
392388
if (
393-
props.expanded
394-
|| props.interacting
395-
|| (props.pauseWhenPageIsHidden && isDocumentHidden)
389+
props.expanded ||
390+
props.interacting ||
391+
(props.pauseWhenPageIsHidden && isDocumentHidden)
396392
) {
397393
pauseTimer()
398-
}
399-
else {
394+
} else {
400395
startTimer()
401396
}
402397
@@ -419,7 +414,7 @@ onMounted(() => {
419414
420415
const newHeights = [
421416
{ toastId: props.toast.id, height, position: props.toast.position! },
422-
...props.heights,
417+
...props.heights
423418
]
424419
emit('update:heights', newHeights)
425420
}
@@ -429,9 +424,9 @@ onMounted(() => {
429424
onUnmounted(() => {
430425
if (toastRef.value) {
431426
const newHeights = props.heights.filter(
432-
height => height.toastId !== props.toast.id,
427+
(height) => height.toastId !== props.toast.id
433428
)
434429
emit('update:heights', newHeights)
435430
}
436431
})
437-
</script>
432+
</script>

0 commit comments

Comments
 (0)