@turnkey/react-wallet-kit
Version:
The easiest and most powerful way to integrate Turnkey's Embedded Wallets into your React applications.
68 lines (64 loc) • 2.58 kB
JavaScript
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var react = require('react');
var Buttons = require('../design/Buttons.js');
var Inputs = require('../design/Inputs.js');
var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
var clsx = require('clsx');
var Hook = require('../../providers/client/Hook.js');
function PhoneNumberInput(props) {
const {
config
} = Hook.useTurnkey();
const {
onContinue
} = props;
const [phone, setPhone] = react.useState("");
const [formattedPhone, setFormattedPhone] = react.useState("");
const [isValid, setIsValid] = react.useState(false);
const [loading, setLoading] = react.useState(false);
const useContinueButton = config?.ui?.preferLargeActionButtons ?? false;
const handleContinue = async () => {
if (isValid && onContinue) {
setLoading(true);
try {
await Promise.resolve(onContinue(phone, formattedPhone));
} finally {
setLoading(false);
}
}
};
const buttonDisabled = !isValid;
const buttonClass = clsx("transition-all duration-300", (isValid || useContinueButton) && "bg-primary-light dark:bg-primary-dark hover:bg-primary-light/90 dark:hover:bg-primary-dark/90 text-primary-text-light dark:text-primary-text-dark");
return jsxRuntime.jsxs("div", {
className: clsx("w-full items-center justify-center space-y-3", useContinueButton ? "flex flex-col" : "flex flex-row"),
children: [jsxRuntime.jsxs("div", {
className: clsx("w-full", !useContinueButton && "relative flex items-center"),
children: [jsxRuntime.jsx(Inputs.PhoneInputBox, {
value: phone,
onChange: (raw, formatted, valid) => {
setPhone(raw);
setFormattedPhone(formatted);
setIsValid(valid);
},
onEnter: handleContinue
}), !useContinueButton && jsxRuntime.jsx(Buttons.IconButton, {
icon: freeSolidSvgIcons.faArrowRight,
onClick: handleContinue,
disabled: buttonDisabled,
loading: loading,
className: clsx("absolute right-2 w-6 h-6", buttonClass),
spinnerClassName: "text-primary-text-light dark:text-primary-text-dark"
})]
}), useContinueButton && jsxRuntime.jsx(Buttons.ActionButton, {
onClick: handleContinue,
disabled: buttonDisabled,
loading: loading,
className: clsx("w-full", buttonClass),
spinnerClassName: "text-primary-text-light dark:text-primary-text-dark",
children: "Continue"
})]
});
}
exports.PhoneNumberInput = PhoneNumberInput;
//# sourceMappingURL=Phone.js.map