Skip to content

Commit

Permalink
✨ feat(core): enable / disable animation with local storage for e2e t…
Browse files Browse the repository at this point in the history
…esting (#1551)

* Create PR for #1550

* feat(core): disable animation by set local storage key baloise-animated to false

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Gery Hirschfeld <[email protected]>
  • Loading branch information
github-actions[bot] and hirsch88 authored Dec 11, 2024
1 parent a625175 commit ad41e5c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-cows-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': minor
---

**core**: disable animation by set local storage key baloise-animated to false
4 changes: 3 additions & 1 deletion packages/core/src/components/bal-app/bal-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class App implements Loggable {
@Prop({ reflect: true, mutable: true }) ready = false

connectedCallback() {
updateBalAnimated(this.animated)
if (this.animated === false) {
updateBalAnimated(this.animated)
}

if (balBrowser.hasWindow) {
window.addEventListener('resize', this.debouncedNotify)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/config/config.const.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const BALOISE_SESSION_KEY = 'baloise-persist-config'
export const BALOISE_ANIMATION_KEY = 'baloise-animated'
18 changes: 17 additions & 1 deletion packages/core/src/utils/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { balBrowser } from '../browser'
import { BalLogger } from '../log'
import { BALOISE_SESSION_KEY } from './config.const'
import { BALOISE_ANIMATION_KEY, BALOISE_SESSION_KEY } from './config.const'
import { BalConfig, BalConfigState, BalIcons, BalLanguage, BalRegion } from './config.types'
import { BalConfigObserver } from './observable/observer'
import { defaultConfig } from './config.default'
Expand Down Expand Up @@ -179,6 +179,22 @@ export const configFromSession = (win: Window): any => {
}
}

export const configFromLocalStorage = (win: Window): any => {
try {
const animated = JSON.parse(win.localStorage.getItem(BALOISE_ANIMATION_KEY))

if (animated !== null) {
return {
animated,
}
}

return {}
} catch (e) {
return {}
}
}

export const saveConfig = (win: Window, c: any) => {
try {
win.sessionStorage.setItem(BALOISE_SESSION_KEY, JSON.stringify(c))
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/config/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { balBrowser } from '../browser'
import { config, configFromSession } from './config'
import { config, configFromLocalStorage, configFromSession } from './config'

import { BalConfig } from './config.types'

Expand All @@ -12,6 +12,7 @@ export const setupConfig = (userConfig: BalConfig = {}, win = {} as any) => {

config.reset({
...configFromSession(win),
...configFromLocalStorage(win),
...userConfig,
icons: {
...configFromSession(win).icons,
Expand Down

0 comments on commit ad41e5c

Please sign in to comment.