import React, { useRef, useState } from "react"; import styled, { createGlobalStyle, css } from "styled-components"; import Interweave from "interweave"; import type { IButtonProps, MaybeElement } from "@blueprintjs/core"; import { Button, Alignment, Position, Classes } from "@blueprintjs/core"; import { Popover2 } from "@blueprintjs/popover2"; import type { IconName } from "@blueprintjs/icons"; import type { ComponentProps } from "widgets/BaseComponent"; import { useScript, ScriptStatus, AddScriptTo } from "utils/hooks/useScript"; import { GOOGLE_RECAPTCHA_KEY_ERROR, GOOGLE_RECAPTCHA_DOMAIN_ERROR, createMessage, } from "@appsmith/constants/messages"; import ReCAPTCHA from "react-google-recaptcha"; import { Colors } from "constants/Colors"; import _ from "lodash"; import type { ButtonPlacement, ButtonVariant, RecaptchaType, } from "components/constants"; import { ButtonVariantTypes, RecaptchaTypes } from "components/constants"; import { getCustomBackgroundColor, getCustomBorderColor, getCustomJustifyContent, getAlignText, getComplementaryGrayscaleColor, } from "widgets/WidgetUtils"; import { DragContainer } from "./DragContainer"; import { buttonHoverActiveStyles } from "./utils"; import type { ThemeProp } from "WidgetProvider/constants"; import { toast } from "design-system"; const RecaptchaWrapper = styled.div` position: relative; .grecaptcha-badge { visibility: hidden; } `; const ToolTipWrapper = styled.div` height: 100%; && .bp3-popover2-target { height: 100%; width: 100%; & > div { height: 100%; } } `; const TooltipStyles = createGlobalStyle` .btnTooltipContainer { .bp3-popover2-content { max-width: 350px; overflow-wrap: anywhere; padding: 10px 12px; border-radius: 0px; } } `; const buttonBaseStyle = css` height: 100%; background-image: none !important; font-weight: ${(props) => props.theme.fontWeights[2]}; outline: none; padding: 0px 10px; gap: 8px; &:hover, &:active, &:focus { ${buttonHoverActiveStyles} } ${({ buttonColor, buttonVariant, theme }) => ` background: ${ getCustomBackgroundColor(buttonVariant, buttonColor) !== "none" ? getCustomBackgroundColor(buttonVariant, buttonColor) : buttonVariant === ButtonVariantTypes.PRIMARY ? theme.colors.button.primary.primary.bgColor : "none" } !important; &:disabled, &.${Classes.DISABLED} { cursor: not-allowed; background-color: ${ buttonVariant !== ButtonVariantTypes.TERTIARY && "var(--wds-color-bg-disabled)" } !important; color: var(--wds-color-text-disabled) !important; box-shadow: none !important; pointer-events: none; border-color: var(--wds-color-border-disabled) !important; > span { color: var(--wds-color-text-disabled) !important; } } border: ${ getCustomBorderColor(buttonVariant, buttonColor) !== "none" ? `1px solid ${getCustomBorderColor(buttonVariant, buttonColor)}` : buttonVariant === ButtonVariantTypes.SECONDARY ? `1px solid ${theme.colors.button.primary.secondary.borderColor}` : "none" } !important; & > * { margin-right: 0; } & > span { display: inline-block; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; line-height: normal; color: ${ buttonVariant === ButtonVariantTypes.PRIMARY ? getComplementaryGrayscaleColor(buttonColor) : getCustomBackgroundColor(ButtonVariantTypes.PRIMARY, buttonColor) } !important; } `} border-radius: ${({ borderRadius }) => borderRadius}; box-shadow: ${({ boxShadow }) => `${boxShadow ?? "none"}`} !important; ${({ placement }) => placement ? ` justify-content: ${getCustomJustifyContent(placement)}; & > span.bp3-button-text { flex: unset !important; } ` : ""} `; export const StyledButton = styled((props) => (