Skip to content

Commit

Permalink
feat: add custom connect button theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Dec 5, 2024
1 parent 510127a commit 38b990e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const RadixButtonTheme = {
black: 'black',
'white-with-outline': 'white-with-outline',
white: 'white',
custom: 'custom',
} as const

export type RadixButtonTheme = keyof typeof RadixButtonTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
background: #7a7676;
}

.column.custom {
--radix-connect-button-background: red;
--radix-connect-button-text-color: black;
--radix-connect-button-border-color: yellow;
--radix-connect-button-background-hover: green;
}

.row {
margin: 1rem;
white-space: nowrap;
Expand All @@ -14,4 +21,4 @@

radix-button {
margin-right: 0.3rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export const Themes: Story = {
connected: false,
})}
</div>
<div class="column custom">
${createRow({ ...args, theme: 'custom', connected: false })}
</div>
<div class="column dark">
${createRow({ ...args, theme: 'white', connected: false })}
</div>
Expand Down
1 change: 0 additions & 1 deletion packages/connect-button/src/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export class RadixButton extends LitElement {
justify-content: flex-end;
container-type: inline-size;
user-select: none;
--radix-connect-button-text-color: var(--color-light);
}
:host([full-width]) > button {
Expand Down
11 changes: 10 additions & 1 deletion packages/dapp-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,21 @@ Play around with the different configurations using the [√ Connect Button stor
<img src="docs/themes.jpeg" alt="Connect Button Themes">
</div>

There are four themes you can choose from by default: `radix-blue` (default), `black`, `white-with-outline`, `white`. In order to do that, call following function after RDT instantiation
There are four themes you can choose from by default: `radix-blue` (default), `black`, `white-with-outline`, `white` and a special one called `custom`. In order to do that, call following function after RDT instantiation

```typescript
rdt.buttonApi.setTheme('black')
```

Using `custom` theme will let you override additional CSS variables. With that you can completely change the UI for not connected connect button.

```css
body {
--radix-connect-button-background: red;
--radix-connect-button-text-color: black;
--radix-connect-button-border-color: yellow;
--radix-connect-button-background-hover: green;
}
### Modes

<div align="center">
Expand Down
6 changes: 2 additions & 4 deletions packages/dapp-toolkit/src/modules/connect-button/subjects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Account, RequestItem } from 'radix-connect-common'
import type { Account, RadixButtonTheme, RequestItem } from 'radix-connect-common'
import { BehaviorSubject, ReplaySubject, Subject } from 'rxjs'
import { isMobile } from '../../helpers'
import { ConnectButtonStatus } from './types'
Expand All @@ -23,9 +23,7 @@ export const ConnectButtonSubjects = () => ({
fullWidth: new BehaviorSubject<boolean>(false),
activeTab: new BehaviorSubject<'sharing' | 'requests'>('sharing'),
mode: new BehaviorSubject<'light' | 'dark'>('light'),
theme: new BehaviorSubject<
'radix-blue' | 'black' | 'white' | 'white-with-outline'
>('radix-blue'),
theme: new BehaviorSubject<RadixButtonTheme>('radix-blue'),
avatarUrl: new BehaviorSubject<string>(''),
personaLabel: new BehaviorSubject<string>(''),
personaData: new BehaviorSubject<{ value: string; field: string }[]>([]),
Expand Down

0 comments on commit 38b990e

Please sign in to comment.