Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/happy-trees-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

autofocus token search input when token selector modal opens in `BuyWidget`, `SwapWidget` and `BridgeWidget` components
1 change: 1 addition & 0 deletions packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
transform: "none",
}}
setOpen={(v) => setIsTokenSelectionOpen(v)}
autoFocusCrossIcon={false}

Check warning on line 208 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L208

Added line #L208 was not covered by tests
>
<SelectToken
activeWalletInfo={activeWalletInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
value: string;
onChange: (value: string) => void;
placeholder: string;
autoFocus?: boolean;
}) {
return (
<div
Expand Down Expand Up @@ -41,6 +42,7 @@
paddingLeft: "44px",
}}
onChange={(e) => props.onChange(e.target.value)}
autoFocus={props.autoFocus}

Check warning on line 45 in packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SearchInput.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SearchInput.tsx#L45

Added line #L45 was not covered by tests
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@
value={props.search}
onChange={props.setSearch}
placeholder="Search by token or address"
autoFocus={!props.isMobile}

Check warning on line 499 in packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx#L499

Added line #L499 was not covered by tests
/>
</Container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export function SwapUI(props: SwapUIProps) {
<Container p="md">
<Modal
hide={false}
autoFocusCrossIcon={false}
className="tw-modal__swap-widget"
size={isMobile ? "compact" : "wide"}
title="Select Token"
Expand Down
11 changes: 10 additions & 1 deletion packages/thirdweb/src/react/web/ui/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
title: string;
hide?: boolean;
crossContainerStyles?: React.CSSProperties;
autoFocusCrossIcon?: boolean;
}> = (props) => {
const [open, setOpen] = useState(props.open);
const contentRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -143,7 +144,15 @@
}}
>
<Dialog.Close asChild>
<IconButton aria-label="Close" autoFocus type="button">
<IconButton
aria-label="Close"
autoFocus={
props.autoFocusCrossIcon === undefined
? true
: props.autoFocusCrossIcon

Check warning on line 152 in packages/thirdweb/src/react/web/ui/components/Modal.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/components/Modal.tsx#L152

Added line #L152 was not covered by tests
}
type="button"
>
<Cross2Icon
height={iconSize.md}
style={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import type { Meta } from "@storybook/react";
import { BridgeWidgetScript } from "../../../script-exports/bridge-widget-script.js";
import {
BridgeWidgetScript,
type BridgeWidgetScriptProps,
} from "../../../script-exports/bridge-widget-script.js";
import { storyClient } from "../../utils.js";

const meta: Meta<typeof BridgeWidgetScript> = {
title: "Bridge/BridgeWidgetScript",
parameters: {
layout: "centered",
},
decorators: [
(Story) => {
return (
<div>
<Story />
</div>
);
},
],
};
export default meta;

export function BasicUsage() {
return (
<BridgeWidgetScript
<Variant
clientId={storyClient.clientId}
buy={{ chainId: 8453, amount: "0.1" }}
/>
Expand All @@ -30,7 +21,7 @@ export function BasicUsage() {

export function LightTheme() {
return (
<BridgeWidgetScript
<Variant
clientId={storyClient.clientId}
theme="light"
buy={{ chainId: 8453, amount: "0.1" }}
Expand All @@ -40,7 +31,7 @@ export function LightTheme() {

export function CurrencySet() {
return (
<BridgeWidgetScript
<Variant
clientId={storyClient.clientId}
currency="JPY"
buy={{ chainId: 8453, amount: "0.1" }}
Expand All @@ -50,7 +41,7 @@ export function CurrencySet() {

export function NoThirdwebBranding() {
return (
<BridgeWidgetScript
<Variant
clientId={storyClient.clientId}
theme="light"
buy={{ chainId: 8453, amount: "0.1" }}
Expand All @@ -61,7 +52,7 @@ export function NoThirdwebBranding() {

export function CustomTheme() {
return (
<BridgeWidgetScript
<Variant
clientId={storyClient.clientId}
buy={{ chainId: 8453, amount: "0.1" }}
theme={{
Expand All @@ -77,3 +68,19 @@ export function CustomTheme() {
/>
);
}

function Variant(props: BridgeWidgetScriptProps) {
return (
<div
style={{
display: "flex",
flexDirection: "column",
gap: "40px",
alignItems: "center",
}}
>
<BridgeWidgetScript {...props} theme="dark" />
<BridgeWidgetScript {...props} theme="light" />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { Meta } from "@storybook/react-vite";
import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
import { SwapWidget } from "../../../react/web/ui/Bridge/swap-widget/SwapWidget.js";
import {
SwapWidget,
type SwapWidgetProps,
} from "../../../react/web/ui/Bridge/swap-widget/SwapWidget.js";
import { storyClient } from "../../utils.js";

const meta = {
parameters: {
layout: "centered",
},
title: "Bridge/Swap/SwapWidget/Prefill",
} satisfies Meta<typeof SwapWidget>;
export default meta;

export function Buy_NativeToken() {
return (
<SwapWidget
<Variant
client={storyClient}
prefill={{
buyToken: {
Expand All @@ -26,7 +26,7 @@ export function Buy_NativeToken() {

export function Buy_Base_USDC() {
return (
<SwapWidget
<Variant
client={storyClient}
prefill={{
buyToken: {
Expand All @@ -40,7 +40,7 @@ export function Buy_Base_USDC() {

export function Buy_NativeToken_With_Amount() {
return (
<SwapWidget
<Variant
client={storyClient}
prefill={{
buyToken: {
Expand All @@ -55,7 +55,7 @@ export function Buy_NativeToken_With_Amount() {

export function Sell_NativeToken() {
return (
<SwapWidget
<Variant
client={storyClient}
prefill={{
sellToken: {
Expand All @@ -82,7 +82,7 @@ export function Sell_Base_USDC() {

export function Sell_NativeToken_With_Amount() {
return (
<SwapWidget
<Variant
client={storyClient}
prefill={{
sellToken: {
Expand All @@ -97,7 +97,7 @@ export function Sell_NativeToken_With_Amount() {

export function Buy_And_Sell_NativeToken() {
return (
<SwapWidget
<Variant
client={storyClient}
prefill={{
// base native token
Expand All @@ -114,3 +114,19 @@ export function Buy_And_Sell_NativeToken() {
/>
);
}

function Variant(props: SwapWidgetProps) {
return (
<div
style={{
display: "flex",
flexDirection: "column",
gap: "40px",
alignItems: "center",
}}
>
<SwapWidget {...props} theme="dark" />
<SwapWidget {...props} theme="light" />
</div>
);
}
41 changes: 24 additions & 17 deletions packages/thirdweb/src/stories/Bridge/Swap/SwapWidget.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import type { Meta } from "@storybook/react";
import { lightTheme } from "../../../react/core/design-system/index.js";
import { SwapWidget } from "../../../react/web/ui/Bridge/swap-widget/SwapWidget.js";
import {
SwapWidget,
type SwapWidgetProps,
} from "../../../react/web/ui/Bridge/swap-widget/SwapWidget.js";
import { storyClient } from "../../utils.js";

const meta: Meta<typeof SwapWidget> = {
parameters: {
layout: "centered",
},
title: "Bridge/Swap/SwapWidget",
decorators: [
(Story) => {
return (
<div>
<Story />
</div>
);
},
],
};
export default meta;

Expand All @@ -26,7 +17,7 @@ export function BasicUsage() {

export function CurrencySet() {
return (
<SwapWidget
<Variant
client={storyClient}
currency="JPY"
persistTokenSelections={false}
Expand All @@ -36,7 +27,7 @@ export function CurrencySet() {

export function LightMode() {
return (
<SwapWidget
<Variant
client={storyClient}
currency="JPY"
theme="light"
Expand All @@ -47,7 +38,7 @@ export function LightMode() {

export function NoThirdwebBranding() {
return (
<SwapWidget
<Variant
client={storyClient}
currency="JPY"
showThirdwebBranding={false}
Expand All @@ -58,7 +49,7 @@ export function NoThirdwebBranding() {

export function CustomTheme() {
return (
<SwapWidget
<Variant
client={storyClient}
currency="JPY"
persistTokenSelections={false}
Expand All @@ -74,3 +65,19 @@ export function CustomTheme() {
/>
);
}

function Variant(props: SwapWidgetProps) {
return (
<div
style={{
display: "flex",
flexDirection: "column",
gap: "40px",
alignItems: "center",
}}
>
<SwapWidget {...props} theme="dark" />
<SwapWidget {...props} theme="light" />
</div>
);
}
12 changes: 8 additions & 4 deletions packages/thirdweb/src/stories/BuyWidget.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import {
import { storyClient } from "./utils.js";

const meta = {
parameters: {
layout: "centered",
},
title: "Bridge/Buy/BuyWidget",
} satisfies Meta<typeof BuyWidget>;
export default meta;
Expand Down Expand Up @@ -143,7 +140,14 @@ export function LargeAmount() {

function Variant(props: BuyWidgetProps) {
return (
<div style={{ display: "flex", flexDirection: "column", gap: "40px" }}>
<div
style={{
display: "flex",
flexDirection: "column",
gap: "40px",
alignItems: "center",
}}
>
<BuyWidget {...props} theme="dark" />
<BuyWidget {...props} theme="light" />
</div>
Expand Down
Loading