-
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): apply UI theme provided by consumer (#3182)
- Loading branch information
Showing
7 changed files
with
74 additions
and
3 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,31 @@ | ||
import type { InjectedWidgetPalette } from '@cowprotocol/widget-lib' | ||
|
||
import { css, DefaultTheme } from 'styled-components/macro' | ||
|
||
// Map the provided data from consumer to styled-components theme | ||
export function mapWidgetTheme( | ||
widgetTheme: InjectedWidgetPalette | undefined, | ||
defaultTheme: DefaultTheme | ||
): DefaultTheme { | ||
if (!widgetTheme) return defaultTheme | ||
|
||
return { | ||
...defaultTheme, | ||
bg3: widgetTheme.widgetBackground, | ||
bg4: widgetTheme.widgetBackground, | ||
cardBackground: widgetTheme.widgetBackground, | ||
text1: widgetTheme.textColor, | ||
primary1: widgetTheme.primaryColor, | ||
primary2: widgetTheme.primaryColor, | ||
primary3: widgetTheme.primaryColor, | ||
primary4: widgetTheme.primaryColor, | ||
bg2: widgetTheme.primaryColor, | ||
body: { | ||
...defaultTheme.body, | ||
background: css` | ||
background-color: ${widgetTheme.screenBackground}; | ||
background-image: none; | ||
`, | ||
}, | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { InjectedWidgetPalette } from '@cowprotocol/widget-lib' | ||
|
||
import { useInjectedWidgetParams } from './useInjectedWidgetParams' | ||
|
||
// The theme palette provided by a consumer | ||
export function useInjectedWidgetPalette(): InjectedWidgetPalette | undefined { | ||
const state = useInjectedWidgetParams() | ||
|
||
return state.palette | ||
} |
4 changes: 3 additions & 1 deletion
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { useAtomValue } from 'jotai' | ||
|
||
import type { CowSwapWidgetAppParams } from '@cowprotocol/widget-lib' | ||
|
||
import { injectedWidgetParamsAtom } from '../state/injectedWidgetParamsAtom' | ||
|
||
export function useInjectedWidgetParams() { | ||
export function useInjectedWidgetParams(): CowSwapWidgetAppParams { | ||
return useAtomValue(injectedWidgetParamsAtom) | ||
} |
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,3 +1,4 @@ | ||
export { InjectedWidgetUpdater } from './updaters/InjectedWidgetUpdater' | ||
export { useInjectedWidgetParams } from './hooks/useInjectedWidgetParams' | ||
export { useInjectedWidgetMetaData } from './hooks/useInjectedWidgetMetaData' | ||
export { useInjectedWidgetPalette } from './hooks/useInjectedWidgetPalette' |
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