Skip to content

Commit a2275c4

Browse files
authored
Adds unstyled option to TransactionButton (#3103)
1 parent ccdd121 commit a2275c4

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

.changeset/curly-dodos-give.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Adds `unstyled` prop to `TransactionButton` to remove default styles
6+
7+
```tsx
8+
<TransactionButton
9+
transaction={() => {}}
10+
onSuccess={handleSuccess}
11+
onError={handleError}
12+
unstyled
13+
className="bg-white text-black rounded-md p-4 flex items-center justify-center"
14+
>
15+
Confirm Transaction
16+
</TransactionButton>
17+
```

packages/thirdweb/src/react/web/ui/TransactionButton/index.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export type TransactionButtonProps = {
5757
* The style to apply to the button element for custom styling
5858
*/
5959
style?: React.CSSProperties;
60+
/**
61+
* Remove all default styling from the button
62+
*/
63+
unstyled?: boolean;
6064
/**
6165
* The `React.ReactNode` to be rendered inside the button
6266
*/
@@ -111,6 +115,18 @@ export type TransactionButtonProps = {
111115
* Confirm Transaction
112116
* </TransactionButton>
113117
* ```
118+
* Customize the styling by passing the `unstyled` prop and your inline styles and/or classes:
119+
* ```tsx
120+
* <TransactionButton
121+
* transaction={() => {}}
122+
* onSuccess={handleSuccess}
123+
* onError={handleError}
124+
* unstyled
125+
* className="bg-white text-black rounded-md p-4 flex items-center justify-center"
126+
* >
127+
* Confirm Transaction
128+
* </TransactionButton>
129+
* ```
114130
* @component
115131
*/
116132
export function TransactionButton(props: TransactionButtonProps) {
@@ -124,6 +140,7 @@ export function TransactionButton(props: TransactionButtonProps) {
124140
gasless,
125141
payModal,
126142
disabled,
143+
unstyled,
127144
...buttonProps
128145
} = props;
129146
const account = useActiveAccount();
@@ -139,6 +156,7 @@ export function TransactionButton(props: TransactionButtonProps) {
139156
gap="xs"
140157
disabled={!account || disabled || isPending}
141158
variant={"primary"}
159+
unstyled={unstyled}
142160
data-is-loading={isPending}
143161
onClick={async (e) => {
144162
if (onClick) {
@@ -170,12 +188,19 @@ export function TransactionButton(props: TransactionButtonProps) {
170188
}
171189
}}
172190
{...buttonProps}
173-
style={{
174-
opacity: !account || disabled ? 0.5 : 1,
175-
minWidth: "150px",
176-
position: "relative",
177-
...buttonProps.style,
178-
}}
191+
style={
192+
!unstyled
193+
? {
194+
opacity: !account || disabled ? 0.5 : 1,
195+
minWidth: "150px",
196+
position: "relative",
197+
...buttonProps.style,
198+
}
199+
: {
200+
position: "relative",
201+
...buttonProps.style,
202+
}
203+
}
179204
>
180205
<span style={{ visibility: isPending ? "hidden" : "visible" }}>
181206
{children}

packages/thirdweb/src/react/web/ui/components/buttons.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import {
1111
export type ButtonProps = {
1212
variant: "primary" | "secondary" | "link" | "accent" | "outline" | "ghost";
1313
theme?: Theme;
14+
unstyled?: boolean;
1415
fullWidth?: boolean;
1516
gap?: keyof typeof spacing;
1617
};
1718

1819
export const Button = /* @__PURE__ */ StyledButton((props: ButtonProps) => {
1920
const theme = useCustomTheme();
21+
if (props.unstyled) {
22+
return {};
23+
}
2024
return {
2125
all: "unset",
2226
cursor: "pointer",

0 commit comments

Comments
 (0)