import { ComponentProps, ReactElement } from 'react'; import classnames from 'classnames'; import styles from './BannerCallout.css'; import VRBannerCallout from './BannerCallout/VRBannerCallout'; import Box from './Box'; import Button from './Button'; import ButtonLink from './ButtonLink'; import { useDefaultLabelContext } from './contexts/DefaultLabelProvider'; import Icon from './Icon'; import IconButton from './IconButton'; import MESSAGING_TYPE_ATTRIBUTES from './MESSAGING_TYPE_ATTRIBUTES'; import Text from './Text'; import useResponsiveMinWidth from './useResponsiveMinWidth'; import useExperimentalTheme from './utils/useExperimentalTheme'; export type ActionDataType = | { accessibilityLabel: string; disabled?: boolean; href: string; label: string; onClick?: ComponentProps['onClick']; rel?: 'none' | 'nofollow'; role: 'link'; target?: null | 'self' | 'blank'; } | { accessibilityLabel: string; disabled?: boolean; label: string; onClick?: ComponentProps['onClick']; role?: 'button'; }; type Props = { /** * Adds a dismiss button to BannerCallout. See the [Dismissible variant](https://gestalt.pinterest.systems/web/bannercallout#Dismissible) for more info. * The `accessibilityLabel` should follow the [Accessibility guidelines](https://gestalt.pinterest.systems/web/bannercallout#Accessibility). */ dismissButton?: { accessibilityLabel?: string; onDismiss: () => void; }; /** * Label to describe the icon’s purpose. See the [Accessibility guidelines](https://gestalt.pinterest.systems/web/bannercallout#Accessibility) for details on proper usage. */ iconAccessibilityLabel?: string; /** * Main content of BannerCallout. Content should be [localized](https://gestalt.pinterest.systems/web/bannercallout#Localization). * * See the [message variant](https://gestalt.pinterest.systems/web/bannercallout#Message) to learn more. Refer to the [Best Practices](https://gestalt.pinterest.systems/web/bannercallout#Best-practices) for content guidelines. */ message: string | ReactElement; /** * Main action for users to take on BannerCallout. If `href` is supplied, the action will serve as a link. See [GlobalEventsHandlerProvider](https://gestalt.pinterest.systems/web/utilities/globaleventshandlerprovider#Link-handlers) to learn more about link navigation. * If no `href` is supplied, the action will be a button. * The `accessibilityLabel` should follow the [Accessibility guidelines](https://gestalt.pinterest.systems/web/bannercallout#Accessibility). */ primaryAction?: | { role: 'link'; accessibilityLabel: string; disabled?: boolean; href: string; label: string; onClick?: ComponentProps['onClick']; rel?: 'none' | 'nofollow'; target?: null | 'self' | 'blank'; } | { role?: 'button'; accessibilityLabel: string; disabled?: boolean; label: string; onClick?: ComponentProps['onClick']; }; /** * Secondary action for users to take on BannerCallout. If role='link', the action will serve as a link. See [GlobalEventsHandlerProvider](https://gestalt.pinterest.systems/web/utilities/globaleventshandlerprovider#Link-handlers) to learn more about link navigation. * If role='button' (or undefined), the action will be a button. * The `accessibilityLabel` should follow the [Accessibility guidelines](https://gestalt.pinterest.systems/web/bannercallout#Accessibility). */ secondaryAction?: | { role: 'link'; accessibilityLabel: string; disabled?: boolean; href: string; label: string; onClick?: ComponentProps['onClick']; rel?: 'none' | 'nofollow'; target?: null | 'self' | 'blank'; } | { role?: 'button'; accessibilityLabel: string; disabled?: boolean; label: string; onClick?: ComponentProps['onClick']; }; /** * The category of BannerCallout. See [Variants](https://gestalt.pinterest.systems/web/bannercallout#Variants) to learn more. */ type: 'default' | 'error' | 'info' | 'recommendation' | 'success' | 'warning'; /** * Brief title summarizing BannerCallout. Content should be [localized](https://gestalt.pinterest.systems/web/bannercallout#Localization). */ title?: string; }; function BannerCalloutAction({ data, stacked, level, type, }: { data: ActionDataType; stacked?: boolean; level: string; type: 'default' | 'error' | 'info' | 'recommendation' | 'success' | 'warning'; }) { const primaryColor: ComponentProps['color'] = 'white'; let secondaryColor: 'white' | 'transparent' | 'gray' = 'transparent'; if (type === 'default') { secondaryColor = 'gray'; } const color: ComponentProps['color'] = level === 'primary' ? primaryColor : secondaryColor; const { accessibilityLabel, disabled, label } = data; return ( {data.role === 'link' ? ( ) : (