Skip to content

Commit

Permalink
2.4.3 (#53)
Browse files Browse the repository at this point in the history
* Notivue - Move `isMouse` util to /Notivue

* Pkg - Edit tests workflow

* Core - Deprecate `syncTransitionStyles` add add `transitionStyles` config

* Core - Set transition config prop as whole

* Core - Remove deprecated transitions test

* Pkg - Bump 2.4.3
  • Loading branch information
smastrom authored Apr 15, 2024
1 parent 6b29277 commit 4a41739
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Tests

on:
pull_request:
branches:
- main
push:
branches:
- '*'
- main
tags-ignore:
- '*'
workflow_call:
Expand Down
2 changes: 1 addition & 1 deletion packages/notivue/Notivue/composables/useMouseEvents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computed } from 'vue'

import { isMouse } from '@/core/utils'
import { isMouse } from '@/Notivue/utils'
import { useStore } from '@/core/useStore'

export function useMouseEvents() {
Expand Down
2 changes: 1 addition & 1 deletion packages/notivue/Notivue/composables/useTouchEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, onBeforeUnmount } from 'vue'

import { useStore } from '@/core/useStore'
import { isMouse } from '@/core/utils'
import { isMouse } from '@/Notivue/utils'

/**
* The logic follows this pattern:
Expand Down
2 changes: 2 additions & 0 deletions packages/notivue/Notivue/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { NotivueItem } from 'notivue'

export const isMouse = (e: PointerEvent) => e.pointerType === 'mouse'

export function getAriaLabel(item: NotivueItem) {
return `${item.title ? `${item.title}: ` : ''}${item.message}`
}
2 changes: 1 addition & 1 deletion packages/notivue/NotivueSwipe/NotivueSwipe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'vue'
import { useStore } from '@/core/useStore'
import { isMouse } from '@/core/utils'
import { isMouse } from '@/Notivue/utils'
import { NotificationTypeKeys as NType } from '@/core/constants'
import { DEFAULT_PROPS, DEBOUNCE, RETURN_DUR } from './constants'
Expand Down
1 change: 1 addition & 0 deletions packages/notivue/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const DEFAULT_CONFIG: NotivueConfigRequired = {
notifications: DEFAULT_NOTIFICATION_OPTIONS,
limit: Infinity,
avoidDuplicates: false,
transition: 'transform 0.35s cubic-bezier(0.5, 1, 0.25, 1)',
animations: {
enter: CLASS_PREFIX + 'enter',
leave: CLASS_PREFIX + 'leave',
Expand Down
1 change: 0 additions & 1 deletion packages/notivue/core/createNotivue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function createInstance(startOnCreation: boolean) {
store.items.clear()
store.queue.clear()
store.items.clearLifecycleEvents()
store.animations.resetTransitionStyles()

setPush(createPushMock())
unwatchStore.forEach((unwatch) => unwatch())
Expand Down
42 changes: 1 addition & 41 deletions packages/notivue/core/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,37 +167,11 @@ export function createAnimations(
queue: QueueSlice,
elements: ElementsSlice
) {
let tStyles = ['0.35s', 'cubic-bezier(0.5, 1, 0.25, 1)']

return {
isReducedMotion: ref(false),
transitionStyles: null as null | Pick<CSSProperties, 'transitionDuration' | 'transitionTimingFunction'>, // prettier-ignore
setReducedMotion(newVal: boolean) {
this.isReducedMotion.value = newVal
},
resetTransitionStyles() {
this.transitionStyles = null
},
syncTransitionStyles() {
const { enter } = config.animations.value

if (!enter) {
tStyles = ['0s', 'ease']
} else {
const animEl = elements.root.value?.querySelector(`.${enter}`)
if (animEl) {
console.log('Syncing transition styles')

const style = window.getComputedStyle(animEl)
tStyles = [style.animationDuration, style.animationTimingFunction]
}
}

this.transitionStyles = {
transitionDuration: tStyles[0],
transitionTimingFunction: tStyles[1],
}
},
playLeave(id: string, { isDestroy = false, isUserTriggered = false } = {}) {
const { leave = '' } = config.animations.value
const item = items.get(id)
Expand Down Expand Up @@ -247,19 +221,6 @@ export function createAnimations(
})
},
updatePositions({ isImmediate = false } = {}) {
if (!this.transitionStyles) {
// Runs the first time a notification is rendered
window.requestAnimationFrame(() => {
this.syncTransitionStyles()
window.requestAnimationFrame(() => {
this.updatePositionsImpl(isImmediate)
})
})
} else {
this.updatePositionsImpl(isImmediate)
}
},
updatePositionsImpl(isImmediate: boolean) {
console.log('Updating positions')

const isReduced = this.isReducedMotion.value || isImmediate
Expand All @@ -276,9 +237,8 @@ export function createAnimations(

items.update(id, {
positionStyles: {
willChange: 'transform',
transform: `translate3d(0, ${accPrevHeights}px, 0)`,
...(isReduced ? { transition: 'none' } : this.transitionStyles),
transition: isReduced ? 'none' : config.transition.value,
},
})

Expand Down
9 changes: 0 additions & 9 deletions packages/notivue/core/createStoreWatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,5 @@ export function createStoreWatchers(store: NotivueStore) {
},
{ flush: 'post' }
),

watch(
() => store.config.animations.value.enter,
(newEnter, prevEnter) => {
if (newEnter !== prevEnter) {
store.animations.resetTransitionStyles()
}
}
),
]
}
11 changes: 11 additions & 0 deletions packages/notivue/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ export interface NotivueConfig {
notifications?: Partial<NotificationTypesOptions>
/** Animation classes for `enter`, `leave` and `clearAll`. */
animations?: NotivueAnimations
/** Transition property applied when repositioning notifications. Must match the following pattern:
*
* `transform <duration> <timing-function>`
*
* @example
*
* ```ts
* transition: 'transform 0.35s cubic-bezier(0.5, 1, 0.25, 1)'
* ```
*/
transition?: string
/** Tag or element to which the stream will be teleported. */
teleportTo?: string | HTMLElement | false
/** Notifications limit. Defaults to `Infinity`. */
Expand Down
3 changes: 1 addition & 2 deletions packages/notivue/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import type {

export const isSSR = typeof window === 'undefined'

export const isMouse = (e: PointerEvent) => e.pointerType === 'mouse'

export function mergeDeep<T extends Obj>(target: T, source: Record<string, any>): T {
const merged: T = { ...target }

Expand Down Expand Up @@ -96,6 +94,7 @@ export const internalKeys: (keyof InternalKeys)[] = [
'timeout',
'resumedAt',
'remaining',
// Maybe in future releases these could be exposed
'animationAttrs',
'positionStyles',
]
Expand Down
2 changes: 1 addition & 1 deletion packages/notivue/nuxt/module.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "notivue/nuxt",
"configKey": "notivue",
"version": "2.4.2"
"version": "2.4.3"
}
2 changes: 1 addition & 1 deletion packages/notivue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notivue",
"version": "2.4.2",
"version": "2.4.3",
"private": false,
"description": "Powerful toast notification system for Vue and Nuxt",
"keywords": [
Expand Down
21 changes: 0 additions & 21 deletions tests/Notivue/transitions-properties.cy.ts

This file was deleted.

File renamed without changes.
4 changes: 1 addition & 3 deletions tests/cypress/support/commands-notivue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,5 @@ Cypress.Commands.add('checkTransitions', (element: HTMLElement, height: number)
.wrap(element)
.should('have.attr', 'style')
.and('include', `transform: translate3d(0px, ${height}px, 0px)`)
.and('include', 'transition-duration: 0.35s')
.and('include', 'transition-property: transform')
.and('include', 'transition-timing-function: cubic-bezier(0.5, 1, 0.25, 1)')
.and('include', 'transition: transform 0.35s cubic-bezier(0.5, 1, 0.25, 1)')
)

0 comments on commit 4a41739

Please sign in to comment.