addons/components/Banner.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {ReactNode} from 'react';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111import {Tooltip} from './Tooltip';
b69ab3112
b69ab3113import './Banner.css';
b69ab3114
b69ab3115export enum BannerKind {
b69ab3116 default = 'default',
b69ab3117 warning = 'warning',
b69ab3118 error = 'error',
b69ab3119 green = 'green',
b69ab3120}
b69ab3121
b69ab3122export function Banner({
b69ab3123 kind,
b69ab3124 children,
b69ab3125 icon,
b69ab3126 buttons,
b69ab3127 alwaysShowButtons,
b69ab3128 xstyle,
b69ab3129}: {
b69ab3130 kind?: BannerKind;
b69ab3131 children: ReactNode;
b69ab3132 icon?: ReactNode;
b69ab3133 buttons?: ReactNode;
b69ab3134 alwaysShowButtons?: boolean;
b69ab3135 xstyle?: stylex.StyleXStyles;
b69ab3136}) {
b69ab3137 const {className: stylexClassName, ...otherStylex} = stylex.props(xstyle);
b69ab3138 return (
b69ab3139 <div className={`${stylexClassName} banner banner-${kind ?? 'default'}`} {...otherStylex}>
b69ab3140 <div className="banner-content">
b69ab3141 {icon ?? null} {children}
b69ab3142 </div>
b69ab3143 {buttons && (
b69ab3144 <div className={'banner-buttons' + (alwaysShowButtons ? ' banner-buttons-visible' : '')}>
b69ab3145 {buttons}
b69ab3146 </div>
b69ab3147 )}
b69ab3148 </div>
b69ab3149 );
b69ab3150}
b69ab3151
b69ab3152export function BannerTooltip({tooltip, children}: {tooltip: string; children: ReactNode}) {
b69ab3153 return (
b69ab3154 <Tooltip trigger="hover" placement="bottom" title={tooltip}>
b69ab3155 {children}
b69ab3156 </Tooltip>
b69ab3157 );
b69ab3158}