import { forwardRef, useImperativeHandle, useRef } from 'react'; import classnames from 'classnames'; import FacebookIcon from './FacebookIcon'; import GoogleIcon from './GoogleIcon'; import LineIcon from './LineIcon'; import styles from './VRButtonSocial.css'; import Box from '../Box'; import { useColorScheme } from '../contexts/ColorSchemeProvider'; import { useDefaultLabelContext } from '../contexts/DefaultLabelProvider'; import Flex from '../Flex'; import focusStyles from '../Focus.css'; import Icon from '../Icon'; import TextUI from '../TextUI'; import useFocusVisible from '../useFocusVisible'; type ButtonProps = { /** * Available for testing purposes, if needed. Consider [better queries](https://testing-library.com/docs/queries/about/#priority) before using this prop. */ dataTestId?: string; /** * Callback invoked when the user clicks (press and release) on Button with the mouse or keyboard. */ onClick?: (arg1: { event: React.MouseEvent | React.KeyboardEvent; }) => void; /** * Text to render inside the ButtonSocial to convey the function and purpose of the ButtonSocial. */ type: 'login' | 'continue' | 'signup'; /** * Text to render inside the ButtonSocial to convey the function and purpose of the ButtonSocial. */ service: 'apple' | 'facebook' | 'google' | 'email' | 'line'; }; /** * [ButtonLink](https://gestalt.pinterest.systems/buttonlink) should be used only to enable users to sign-up or sign-in to Pinterest using other trusted services. * * ![ButtonLink light mode](https://raw.githubusercontent.com/pinterest/gestalt/master/playwright/visual-test/ButtonLink.spec.ts-snapshots/ButtonLink-chromium-darwin.png) * ![ButtonLink dark mode](https://raw.githubusercontent.com/pinterest/gestalt/master/playwright/visual-test/ButtonLink-dark.spec.ts-snapshots/ButtonLink-dark-chromium-darwin.png) */ const ButtonSocialWithForwardRef = forwardRef(function ButtonLink( { dataTestId, onClick, type, service }, ref, ) { const innerRef = useRef(null); const { isFocusVisible } = useFocusVisible(); // When using both forwardRef and innerRef, React.useimperativehandle() allows a parent component // that renders to call inputRef.current.focus() // @ts-expect-error - TS2322 - Type 'HTMLButtonElement | null' is not assignable to type 'HTMLButtonElement'. useImperativeHandle(ref, () => innerRef.current); let iconService = null; switch (service) { case 'apple': iconService = ; break; case 'facebook': iconService = ; break; case 'google': iconService = ; break; case 'email': iconService = ; break; case 'line': iconService = ; break; default: iconService = ; break; } const { textLoginEmail, textLoginFacebook, textLoginGoogle, textLoginApple, textLoginLine, textContinueEmail, textContinueFacebook, textContinueGoogle, textContinueApple, textContinueLine, textSignupEmail, textSignupFacebook, textSignupGoogle, textSignupApple, textSignupLine, } = useDefaultLabelContext('ButtonSocial'); const message = { apple: { signup: textSignupApple, continue: textContinueApple, login: textLoginApple, }, facebook: { signup: textSignupFacebook, continue: textContinueFacebook, login: textLoginFacebook, }, google: { signup: textSignupGoogle, continue: textContinueGoogle, login: textLoginGoogle, }, email: { signup: textSignupEmail, continue: textContinueEmail, login: textLoginEmail, }, line: { signup: textSignupLine, continue: textContinueLine, login: textLoginLine, }, }; const textWithService = message[service][type]; const { colorSchemeName } = useColorScheme(); const isDarkMode = colorSchemeName === 'darkMode'; const background = isDarkMode ? styles.darkMode : styles.lightMode; const buttonClasses = classnames(styles.social, background, styles.rtl, { [focusStyles.accessibilityOutlineButtonSocialVR]: isFocusVisible, }); return ( ); }); ButtonSocialWithForwardRef.displayName = 'ButtonSocial'; export default ButtonSocialWithForwardRef;