-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): stop using useBrowserStorage hook and use a simpler api…
… usable with postMessage
- Loading branch information
Showing
14 changed files
with
383 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function getLocalStorageItem<T = any>(key: string, defaultValue: T): T { | ||
const item = localStorage.getItem(key) | ||
if (item && item !== 'undefined') { | ||
return JSON.parse(item) | ||
} | ||
|
||
return defaultValue | ||
} | ||
|
||
export function setLocalStorageItem<T = any>(key: string, value: T): void { | ||
localStorage.setItem(key, JSON.stringify(value)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { SLAppComponentProps } from '..' | ||
|
||
export const defaultConfig: SLAppComponentProps = { | ||
title: <> ⚡️ StoryLite</>, | ||
defaultStory: 'index', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
it('passes', () => { | ||
expect(true).toBe(true) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './windowMessaging' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { SLParameters } from '@/types' | ||
|
||
export enum WindowMessageOrigin { | ||
Same = '/', | ||
Any = '*', | ||
} | ||
|
||
export enum CrossDocumentMessageSource { | ||
Root = 'storylite_root', | ||
Iframe = 'storylite_iframe', | ||
} | ||
|
||
export enum CrossDocumentMessageType { | ||
UpdateParameters = 'update_parameters', | ||
} | ||
|
||
export type CrossDocumentMessage = { | ||
source?: CrossDocumentMessageSource | ||
type: string | CrossDocumentMessageType | ||
payload: CrossDocumentMessage['type'] extends CrossDocumentMessageType.UpdateParameters | ||
? SLParameters | ||
: { | ||
[key: string]: any | ||
} | ||
} |
Oops, something went wrong.