Skip to content

Commit

Permalink
Add theming to more parts of the widget
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao committed Jul 3, 2024
1 parent cae6074 commit 4bde2b2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 27 deletions.
27 changes: 26 additions & 1 deletion examples/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '@skip-go/widget/style.css';

const Home: NextPage = () => {
return (
<div>
<div style={{ display: 'flex', gap: 50 }}>
<div
style={{
width: '450px',
Expand All @@ -22,6 +22,31 @@ const Home: NextPage = () => {
}}
/>
</div>

<div
style={{
width: '450px',
height: '820px',
}}
>
<SwapWidget
theme={{
primary: {
backgroundColor: 'black',
textColor: 'white',
},
secondary: {
backgroundColor: 'grey',
textColor: 'white',
},
}}
defaultRoute={{
srcChainID: 'osmosis-1',
srcAssetDenom:
'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
}}
/>
</div>
</div>
);
};
Expand Down
8 changes: 7 additions & 1 deletion packages/widget/src/ui/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { formatPercent, formatUSD } from '../utils/intl';
import { useSwapWidgetUIStore } from '../store/swap-widget';
import { css } from '@emotion/css';
import { styled } from 'styled-components';

interface Props {
amount: string;
Expand Down Expand Up @@ -120,7 +121,7 @@ function AssetInput({
/>
</button>
)}
<input
<AmountInput
data-testid="amount"
className={cn(
'h-10 w-full text-3xl font-medium tabular-nums',
Expand Down Expand Up @@ -258,3 +259,8 @@ function AssetInput({
}

export default AssetInput;

const AmountInput = styled.input`
background-color: ${(props) => props.theme.primary.backgroundColor};
color: ${(props) => props.theme.primary.textColor};
`;
10 changes: 8 additions & 2 deletions packages/widget/src/ui/AssetSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { cn } from '../../utils/ui';
import { Dialog } from '../Dialog/Dialog';
import { DialogTrigger } from '../Dialog/DialogTrigger';
import { DialogContent } from '../Dialog/DialogContent';
import { styled } from 'styled-components';

interface Props {
asset?: Asset;
Expand All @@ -29,7 +30,7 @@ function AssetSelect({
return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger>
<button
<AssetSelectButton
className={cn(
'whitespace-nowrap text-left font-semibold',
'flex w-full items-center gap-2 rounded-md bg-neutral-100 px-4 py-2 transition-colors sm:py-4',
Expand Down Expand Up @@ -59,7 +60,7 @@ function AssetSelect({
<div>
<ChevronDownIcon className="h-4 w-4" />
</div>
</button>
</AssetSelectButton>
</DialogTrigger>
<DialogContent>
<AssetSelectContent
Expand All @@ -76,3 +77,8 @@ function AssetSelect({
}

export default AssetSelect;

const AssetSelectButton = styled.button`
background-color: ${(props) => props.theme.secondary.backgroundColor};
color: ${(props) => props.theme.secondary.textColor};
`;
10 changes: 8 additions & 2 deletions packages/widget/src/ui/ChainSelect/ChainSelectTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChevronDownIcon } from '@heroicons/react/20/solid';
import { forwardRef } from 'react';
import { Chain } from '../../hooks/use-chains';
import { cn } from '../../utils/ui';
import { styled } from 'styled-components';

interface Props {
chain?: Chain;
Expand All @@ -10,7 +11,7 @@ interface Props {
const ChainSelectTrigger = forwardRef<HTMLButtonElement, Props>(
function ChainSelectTrigger({ chain, ...props }, ref) {
return (
<button
<ChainSelectButton
className={cn(
'flex w-full items-center px-4 py-2 sm:py-4',
'whitespace-nowrap rounded-md bg-neutral-100 text-left font-semibold transition-colors',
Expand All @@ -24,10 +25,15 @@ const ChainSelectTrigger = forwardRef<HTMLButtonElement, Props>(
{chain ? chain.prettyName : 'Select Chain'}
</span>
<ChevronDownIcon className="mt-0.5 h-4 w-4" />
</button>
</ChainSelectButton>
);
}
//
);

export default ChainSelectTrigger;

const ChainSelectButton = styled.button`
background-color: ${(props) => props.theme.secondary.backgroundColor};
color: ${(props) => props.theme.secondary.textColor};
`;
11 changes: 8 additions & 3 deletions packages/widget/src/ui/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ import { useSwapWidgetUIStore } from '../store/swap-widget';
import { css } from '@emotion/css';
import { CraftedBySkip } from './CraftedBySkip';
import { ThemeProvider, styled } from 'styled-components';
import { defaultTheme } from './theme';
import { Theme, defaultTheme } from './theme';

type SwapWidgetProps = React.HTMLAttributes<HTMLDivElement> & {
theme?: Theme;
};

export const SwapWidgetUI = ({
className,
theme,
...divProps
}: React.HTMLAttributes<HTMLDivElement>) => {
}: SwapWidgetProps) => {
useEffect(() => void disclosure.rehydrate(), []);

const { openWalletModal } = useWalletModal();
Expand Down Expand Up @@ -91,7 +96,7 @@ export const SwapWidgetUI = ({
const accountStateKey = `${srcAccount?.isWalletConnected ? 'src' : 'no-src'}`;

return (
<ThemeProvider theme={defaultTheme}>
<ThemeProvider theme={theme ?? defaultTheme}>
<UsdDiff.Provider>
<Tooltip.Provider delayDuration={0} disableHoverableContent>
<WidgetContainer
Expand Down
14 changes: 10 additions & 4 deletions packages/widget/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import {
ConfigureSwapWidgetArgs,
} from '../store/swap-widget';
import { SwapWidgetUI } from './Widget';
import { Theme } from './theme';

export interface SwapWidgetProps
extends Pick<React.HTMLAttributes<HTMLDivElement>, 'className' | 'style'>,
ConfigureSwapWidgetArgs {}
export type SwapWidgetProps = Pick<
React.HTMLAttributes<HTMLDivElement>,
'className' | 'style'
> &
ConfigureSwapWidgetArgs & {
theme?: Theme;
};

export const SwapWidget: React.FC<SwapWidgetProps> = ({
colors,
Expand All @@ -18,6 +23,7 @@ export const SwapWidget: React.FC<SwapWidgetProps> = ({
onlyTestnet,
defaultRoute,
routeConfig,
theme,
}) => {
useEffect(() => {
configureSwapWidget({
Expand All @@ -30,5 +36,5 @@ export const SwapWidget: React.FC<SwapWidgetProps> = ({
}, [colors, onlyTestnet, settings, defaultRoute, routeConfig]);

const divProps = { className, style };
return <SwapWidgetUI {...divProps} />;
return <SwapWidgetUI {...divProps} theme={theme} />;
};
30 changes: 16 additions & 14 deletions packages/widget/src/ui/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ import 'styled-components';

export const defaultTheme = {
primary: {
backgroundColor: 'yellow',
textColor: 'blue',
backgroundColor: 'white',
textColor: 'black',
},
secondary: {
backgroundColor: '',
textColor: '',
backgroundColor: 'rgb(245, 245, 245)',
textColor: 'black',
},
};

export type Theme = {
primary: {
backgroundColor: string;
textColor: string;
};
secondary: {
backgroundColor: string;
textColor: string;
};
};

declare module 'styled-components' {
export interface DefaultTheme {
primary: {
backgroundColor: string;
textColor: string;
};
secondary: {
backgroundColor: string;
textColor: string;
};
}
export interface DefaultTheme extends Theme {}
}

0 comments on commit 4bde2b2

Please sign in to comment.