-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget): use theme colors from URL (#4188)
* feat(widget): use theme colors from URL * fix: dark theme for skeleton * chore: fix useColorMode * chore: rename isCowSwapWidgetPalette * refactor: use json instead of keys * fix: update color palette
- Loading branch information
Showing
21 changed files
with
172 additions
and
92 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
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
25 changes: 17 additions & 8 deletions
25
apps/cowswap-frontend/src/modules/injectedWidget/hooks/useInjectedWidgetPalette.ts
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 |
---|---|---|
@@ -1,14 +1,23 @@ | ||
import type { CowSwapWidgetPalette } from '@cowprotocol/widget-lib' | ||
import { useMemo } from 'react' | ||
|
||
import { useInjectedWidgetParams } from './useInjectedWidgetParams' | ||
import { CowSwapWidgetPaletteParams } from '@cowprotocol/widget-lib' | ||
|
||
import { useLocation } from 'react-router-dom' | ||
|
||
// The theme palette provided by a consumer | ||
export function useInjectedWidgetPalette(): Partial<CowSwapWidgetPalette> | undefined { | ||
const state = useInjectedWidgetParams() | ||
export function useInjectedWidgetPalette(): Partial<CowSwapWidgetPaletteParams> | undefined { | ||
const { search } = useLocation() | ||
|
||
return isCowSwapWidgetPallet(state.theme) ? state.theme : undefined | ||
} | ||
return useMemo(() => { | ||
const searchParams = new URLSearchParams(search) | ||
const palette = searchParams.get('palette') | ||
|
||
if (!palette) return undefined | ||
|
||
function isCowSwapWidgetPallet(palette: any): palette is CowSwapWidgetPalette { | ||
return palette && typeof palette === 'object' | ||
try { | ||
return JSON.parse(decodeURIComponent(palette)) | ||
} catch (e) { | ||
console.error('Failed to parse palette from URL', e) | ||
} | ||
}, [search]) | ||
} |
4 changes: 2 additions & 2 deletions
4
apps/cowswap-frontend/src/modules/injectedWidget/hooks/useInjectedWidgetParams.ts
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
6 changes: 3 additions & 3 deletions
6
apps/cowswap-frontend/src/modules/injectedWidget/state/injectedWidgetParamsAtom.ts
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { atom } from 'jotai' | ||
|
||
import type { CowSwapWidgetParams } from '@cowprotocol/widget-lib' | ||
import { CowSwapWidgetAppParams } from '@cowprotocol/widget-lib' | ||
|
||
export type WidgetParamsErrors = Partial<{ [key in keyof CowSwapWidgetParams]: string[] | undefined }> | ||
export type WidgetParamsErrors = Partial<{ [key in keyof CowSwapWidgetAppParams]: string[] | undefined }> | ||
|
||
export const injectedWidgetParamsAtom = atom<{ params: Partial<CowSwapWidgetParams>; errors: WidgetParamsErrors }>({ | ||
export const injectedWidgetParamsAtom = atom<{ params: Partial<CowSwapWidgetAppParams>; errors: WidgetParamsErrors }>({ | ||
params: {}, | ||
errors: {}, | ||
}) |
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
8 changes: 4 additions & 4 deletions
8
apps/cowswap-frontend/src/modules/injectedWidget/utils/validateWidgetParams.ts
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
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
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
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
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
Oops, something went wrong.