Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[major] Add themeing #21

Merged
merged 49 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6c5a931
WIP adding themes, Add styled-components
toddkao Jul 3, 2024
cae6074
Update to styled-components 6 to fix issues with rollupjs
toddkao Jul 3, 2024
4bde2b2
Add theming to more parts of the widget
toddkao Jul 3, 2024
cbd2fe8
Add theme to more components
toddkao Jul 3, 2024
a971e4d
merge main
toddkao Jul 15, 2024
8771bb2
Add seperate page for theme
toddkao Jul 15, 2024
e9e8b2a
Updating Themes
toddkao Jul 15, 2024
0621ee6
Update Tooltips and 3 Buttons
toddkao Jul 16, 2024
d066573
Re-implement WithStyledShadowDom using imperative shadow dom
toddkao Jul 16, 2024
2ad2212
Fix radix ui wheel event WIP fixing Dialogs
toddkao Jul 16, 2024
4cd8f47
Fix WithStyledShadowDom
toddkao Jul 16, 2024
869ab94
Update Themes
toddkao Jul 16, 2024
191bf30
Start adding brandColor to deprecate useSwapWidgetUIStore.getState().…
toddkao Jul 16, 2024
53cd0aa
Refactor
toddkao Jul 16, 2024
273d89a
Refactor
toddkao Jul 16, 2024
0967d10
Add ability to pass arbitrary props in example/nextjs
toddkao Jul 16, 2024
54ba136
Merge branch 'main' into add-themeing
toddkao Jul 16, 2024
7aaae97
Fix after merge
toddkao Jul 16, 2024
b80eaad
Add some default buttons for changing themes
toddkao Jul 16, 2024
ba6fd7d
Remove hover styling on connect wallet back button
toddkao Jul 16, 2024
740f63b
Remove react-shadow-scope, it's no longer used
toddkao Jul 16, 2024
1f25a0b
Add cssReset
toddkao Jul 16, 2024
d990ea4
Remove unnecessary prop
toddkao Jul 16, 2024
87adbf2
test
toddkao Jul 16, 2024
785a7ec
Update naming
toddkao Jul 16, 2024
ce2482c
Update Transaction History, TransactionPreview, Connect wallet theme
toddkao Jul 17, 2024
b79829f
Update styling of set destination address buttons
toddkao Jul 17, 2024
6c5c1b0
Update SetAddressDialog.tsx
toddkao Jul 17, 2024
ad00d4a
Finish removing usages of useSwapWidgetUIStore.getState().colors.primary
toddkao Jul 17, 2024
606d8f6
Update styling
toddkao Jul 17, 2024
98c5851
Fix slippage and gasAmount input styling
toddkao Jul 17, 2024
eff7e20
Refactor Theme interface
toddkao Jul 17, 2024
8f30cf8
Update README, fix build
toddkao Jul 17, 2024
caf7704
Update README, fix build
toddkao Jul 17, 2024
e898054
Add Changeset
toddkao Jul 17, 2024
57c4ac8
Merge branch 'add-themeing' of https://github.com/skip-mev/skip-go in…
toddkao Jul 17, 2024
96ac113
Merge branch 'main' into add-themeing
toddkao Jul 17, 2024
fc3ad16
Fix SetAddressDialog input styling
toddkao Jul 17, 2024
e97ea81
Fix input being slightly clipped off on left side
toddkao Jul 17, 2024
050eb95
Stop passing colors.primary to examples
toddkao Jul 17, 2024
08ec5e7
Update bridgeLogo to just have a backgroundCircle behind it with a st…
toddkao Jul 17, 2024
5aabb45
Remove imports of removed file
toddkao Jul 17, 2024
006726b
Update changeset as major
toddkao Jul 17, 2024
ce004be
Merge branch 'main' into add-themeing
toddkao Jul 18, 2024
0495d5c
Move Toaster from SwapWidgetProvider to Widget.tsx
toddkao Jul 18, 2024
8ef3145
Update borderColors
toddkao Jul 18, 2024
8e93062
update darkTheme
codingki Jul 18, 2024
6c1d1a9
Hard code Create New Swap/Transfer color as text-white
toddkao Jul 18, 2024
45e7225
Merge branch 'add-themeing' of https://github.com/skip-mev/skip-go in…
toddkao Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-crabs-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skip-go/widget': major
---

Add theme prop to enable custom styling
138 changes: 108 additions & 30 deletions examples/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,124 @@
import { NextPage } from 'next';
import React from 'react';
import React, { useState } from 'react';
import { SwapWidget } from '@skip-go/widget';
import crypto from 'crypto';
import { PartialTheme } from '@skip-go/widget/build/ui/theme';

function hashString(inputString: string) {
const hash = crypto.createHash('sha256');
hash.update(inputString);
return hash.digest('hex');
}

function isJsonString(str: string) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}

const defaultProps = {
defaultRoute: {
srcChainID: 'osmosis-1',
srcAssetDenom:
'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
},
};

const darkTheme = {
backgroundColor: '#191A1C',
textColor: '#E6EAE9',
borderColor: '#363B3F',
brandColor: '#FF4FFF',
highlightColor: '#1F2022',
};

const defaultHash = hashString(JSON.stringify(defaultProps));

const Home: NextPage = () => {
const [props, setProps] = useState(defaultProps);
const [propsHash, setPropsHash] = useState(defaultHash);

const handleOnChange = (event: any) => {
if (isJsonString(event.target.innerText)) {
const newHash = hashString(event.target.innerText);
if (propsHash !== newHash) {
console.log('update props');
setProps({ ...JSON.parse(event.target.innerText) });
setPropsHash(newHash);
}
}
};

const handleUpdateTheme = (theme: PartialTheme) => {
const newProps = { ...props, theme: theme } as any;
const newHash = hashString(JSON.stringify(newProps));
setProps(newProps);
setPropsHash(newHash);
};

return (
<div
style={{
display: 'flex',
flexDirection: 'row',
}}
>
<div style={{ display: 'flex', gap: 50 }}>
<div
style={{
width: '450px',
height: '820px',
flexShrink: 0,
}}
>
<SwapWidget
colors={{
primary: '#FF4FFF',
}}
defaultRoute={{
srcChainID: 'osmosis-1',
srcAssetDenom:
'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
<SwapWidget {...props} key={propsHash} />
</div>
<div>
<div style={{ display: 'flex' }}>
<button
onClick={() => {
if (
window.confirm('Are you sure you want to purge all settings?')
) {
window.localStorage.clear();
window.sessionStorage.clear();
window.location.reload();
}
}}
style={{
height: '40px',
}}
>
Purge Settings
</button>
<button
style={{
height: '40px',
}}
onClick={() => handleUpdateTheme(undefined)}
>
Default Theme
</button>
<button
style={{
height: '40px',
}}
onClick={() => handleUpdateTheme(darkTheme)}
>
Dark Theme
</button>
</div>

<pre
contentEditable="true"
onBlur={handleOnChange}
style={{
border: '1px solid black',
padding: 20,
fontSize: '20px',
color: 'black',
}}
/>
>
{JSON.stringify(props, null, 2)}
</pre>
</div>
<button
onClick={() => {
if (window.confirm('Are you sure you want to purge all settings?')) {
window.localStorage.clear();
window.sessionStorage.clear();
window.location.reload();
}
}}
style={{
height: '40px',
}}
>
Purge Settings
</button>
</div>
);
};
Expand Down
3 changes: 0 additions & 3 deletions examples/nextjs/pages/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const Home: NextPage = () => {
>
<SwapWidgetProvider>
<SwapWidgetWithoutProviders
colors={{
primary: '#FF4FFF',
}}
defaultRoute={{
srcChainID: 'osmosis-1',
srcAssetDenom:
Expand Down
6 changes: 1 addition & 5 deletions examples/nextjs/pages/vue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ const VuePage: NextPage = () => {
const { createApp } = require('vue/dist/vue.esm-bundler.js');
const app = createApp({
setup() {
const colors = JSON.stringify({
primary: '#FF4FFF',
});
const defaultRoute = JSON.stringify({
srcChainID: 'osmosis-1',
srcAssetDenom:
'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
});

return {
colors,
defaultRoute,
};
},
template: `
<div style="width:450px;height:820px;">
<skip-widget :colors="colors" :default-route="defaultRoute"></skip-widget>
<skip-widget :default-route="defaultRoute"></skip-widget>
</div>
`,
});
Expand Down
3 changes: 0 additions & 3 deletions examples/nextjs/pages/web-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const WebComponent: NextPage = () => {
}}
>
<skip-widget
colors={JSON.stringify({
primary: '#FF4FFF',
})}
default-route={JSON.stringify({
srcChainID: 'osmosis-1',
srcAssetDenom:
Expand Down
10 changes: 7 additions & 3 deletions packages/widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ The `SwapWidget` component accepts the following props:

````tsx
interface SwapWidgetProps {
colors?: {
primary?: string; // Custom primary color for the widget. Defaults to `#FF486E`.
};
defaultRoute?: {
// Default route for the widget.
amountIn?: number;
Expand Down Expand Up @@ -129,6 +126,13 @@ interface SwapWidgetProps {
getRestEndpointForChain?: (chainID: string) => Promise<string>;
};
apiURL?: string; // Custom API URL to override Skip API endpoint. Defaults to Skip proxied endpoints. Please reach out to us first if you want to be whitelisted.
theme?: {
backgroundColor: string; // background color
textColor: string; // text color
borderColor: string; // border color
brandColor: string; // color used for confirmation buttons
highlightColor: string; // color used when hovering over buttons, and in select chain/asset dropdown
};
}
````

Expand Down
8 changes: 5 additions & 3 deletions packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@
},
"peerDependencies": {
"react": "17.x || 18.x",
"react-dom": "17.x || 18.x"
"react-dom": "17.x || 18.x",
"styled-components": "^6.0.0",
"stylis": "^4.0.0"
},
"devDependencies": {
"@rollup/plugin-url": "^8.0.2",
"@types/node": "18.7.18",
"@types/qrcode": "^1.4.2",
"@types/react": "^18.0.6",
"@types/react-dom": "^18.0.2",
"@types/styled-components": "^5.1.25",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"postcss-prefixwrap": "^1.49.0",
"rollup-plugin-copy": "^3.5.0",
"styled-components": "^6.0.0",
"stylis": "^4.0.0",
"tailwindcss": "^3.4.3",
"tailwindcss-animate": "^1.0.7",
"typed-query-selector": "^2.11.2",
Expand Down Expand Up @@ -101,7 +104,6 @@
"match-sorter": "^6.3.4",
"react-hot-toast": "^2.4.1",
"react-icons": "^5.2.1",
"react-shadow-scope": "^1.0.5",
"tailwind-merge": "^2.3.0",
"viem": "2.x",
"wagmi": "2.x",
Expand Down
24 changes: 0 additions & 24 deletions packages/widget/src/hooks/use-fix-radix-ui-wheel-event.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/widget/src/hooks/use-swap-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Chain, useChains } from './use-chains';
import { useBalancesByChain } from './use-balances-by-chain';
import { useRoute } from './use-route';
import { getChainFeeAssets, getChainGasPrice } from '../utils/chain';
import { useSkipClient, useSkipConfig } from './use-skip-client';
import { useSkipClient } from './use-skip-client';
import { getAmountWei, parseAmountWei } from '../utils/number';
import { gracefullyConnect } from '../utils/wallet';
import { useSwapWidgetUIStore } from '../store/swap-widget';
Expand Down
9 changes: 1 addition & 8 deletions packages/widget/src/provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
endpointOptions as defaultEndpointOptions,
apiURL as defaultApiURL,
} from '../constants/defaults';
import { useTheme } from 'styled-components';

interface WalletProviderProps {
children: React.ReactNode;
Expand All @@ -24,7 +25,6 @@ export interface WidgetConfig {
}
export interface SwapWidgetProviderProps extends SkipAPIProviderProps {
children: React.ReactNode;
toasterProps?: ToasterProps;
}
export interface SkipAPIProviderProps {
children: React.ReactNode;
Expand Down Expand Up @@ -58,18 +58,11 @@ export const SkipAPIProvider: React.FC<SkipAPIProviderProps> = ({

export const SwapWidgetProvider: React.FC<SwapWidgetProviderProps> = ({
children,
toasterProps,
...skipApiProviderProps
}) => {
return (
<WalletProvider>
<SkipAPIProvider {...skipApiProviderProps}>{children}</SkipAPIProvider>
<Toaster
position={'top-right'}
containerClassName="font-diatype"
toastOptions={{ duration: 1000 * 10 }}
{...toasterProps}
/>
</WalletProvider>
);
};
15 changes: 0 additions & 15 deletions packages/widget/src/store/swap-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import {
} from 'zustand/middleware';

interface SwapWidgetStore {
colors: {
primary?: string;
};
onlyTestnet?: boolean;
defaultRoute?: DefaultRouteConfig;
routeConfig?: RouteConfig;
Expand Down Expand Up @@ -45,9 +42,6 @@ interface SwapWidgetStore {
};
}
export const swapWidgetDefaultValues: SwapWidgetStore = {
colors: {
primary: '#FF486E',
},
onlyTestnet: false,
defaultRoute: undefined,
routeConfig: {
Expand Down Expand Up @@ -78,12 +72,6 @@ export const useSwapWidgetUIStore = create(
);

export interface ConfigureSwapWidgetArgs {
colors?: {
/**
* @default '#FF486E'
*/
primary?: string;
};
settings?: {
/**
* gas amount for validation
Expand Down Expand Up @@ -128,9 +116,6 @@ export interface ConfigureSwapWidgetArgs {

export const configureSwapWidget = (args: ConfigureSwapWidgetArgs) => {
useSwapWidgetUIStore.setState((prev) => ({
colors: {
primary: args.colors?.primary || prev.colors.primary,
},
onlyTestnet: args.onlyTestnet || prev.onlyTestnet,
defaultRoute: args.defaultRoute || prev.defaultRoute,
routeConfig: {
Expand Down
6 changes: 0 additions & 6 deletions packages/widget/src/styles/cssReset.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@
background-color: unset;
word-spacing: unset;
}

div,
p,
span {
color: black;
}
Loading
Loading