| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import type {ReactNode} from 'react'; |
| 9 | |
| 10 | import * as stylex from '@stylexjs/stylex'; |
| 11 | import {Tooltip} from './Tooltip'; |
| 12 | |
| 13 | import './Banner.css'; |
| 14 | |
| 15 | export enum BannerKind { |
| 16 | default = 'default', |
| 17 | warning = 'warning', |
| 18 | error = 'error', |
| 19 | green = 'green', |
| 20 | } |
| 21 | |
| 22 | export function Banner({ |
| 23 | kind, |
| 24 | children, |
| 25 | icon, |
| 26 | buttons, |
| 27 | alwaysShowButtons, |
| 28 | xstyle, |
| 29 | }: { |
| 30 | kind?: BannerKind; |
| 31 | children: ReactNode; |
| 32 | icon?: ReactNode; |
| 33 | buttons?: ReactNode; |
| 34 | alwaysShowButtons?: boolean; |
| 35 | xstyle?: stylex.StyleXStyles; |
| 36 | }) { |
| 37 | const {className: stylexClassName, ...otherStylex} = stylex.props(xstyle); |
| 38 | return ( |
| 39 | <div className={`${stylexClassName} banner banner-${kind ?? 'default'}`} {...otherStylex}> |
| 40 | <div className="banner-content"> |
| 41 | {icon ?? null} {children} |
| 42 | </div> |
| 43 | {buttons && ( |
| 44 | <div className={'banner-buttons' + (alwaysShowButtons ? ' banner-buttons-visible' : '')}> |
| 45 | {buttons} |
| 46 | </div> |
| 47 | )} |
| 48 | </div> |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | export function BannerTooltip({tooltip, children}: {tooltip: string; children: ReactNode}) { |
| 53 | return ( |
| 54 | <Tooltip trigger="hover" placement="bottom" title={tooltip}> |
| 55 | {children} |
| 56 | </Tooltip> |
| 57 | ); |
| 58 | } |
| 59 | |