addons/components/ButtonWithDropdownTooltip.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 ForwardedRef, forwardRef, type ReactNode} from 'react';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111import {Button} from './Button';
b69ab3112import {Icon} from './Icon';
b69ab3113import {colors, spacing} from './theme/tokens.stylex';
b69ab3114import {Tooltip} from './Tooltip';
b69ab3115
b69ab3116const styles = stylex.create({
b69ab3117 container: {
b69ab3118 display: 'flex',
b69ab3119 alignItems: 'stretch',
b69ab3120 position: 'relative',
b69ab3121 },
b69ab3122 button: {
b69ab3123 borderBottomRightRadius: 0,
b69ab3124 borderTopRightRadius: 0,
b69ab3125 },
b69ab3126 chevron: {
b69ab3127 borderBottomLeftRadius: 0,
b69ab3128 borderTopLeftRadius: 0,
b69ab3129 borderLeft: 'unset',
b69ab3130 width: '24px',
b69ab3131 height: '24px',
b69ab3132 paddingTop: 6,
b69ab3133 },
b69ab3134 builtinButtonBorder: {
b69ab3135 borderLeft: 'unset',
b69ab3136 },
b69ab3137 iconButton: {
b69ab3138 borderTopRightRadius: 0,
b69ab3139 borderBottomRightRadius: 0,
b69ab3140 paddingRight: spacing.half,
b69ab3141 },
b69ab3142 iconSelect: {
b69ab3143 borderTopLeftRadius: 0,
b69ab3144 borderBottomLeftRadius: 0,
b69ab3145 borderLeftColor: colors.hoverDarken,
b69ab3146 },
b69ab3147 chevronDisabled: {
b69ab3148 opacity: 0.5,
b69ab3149 },
b69ab3150});
b69ab3151
b69ab3152export const ButtonWithDropdownTooltip = forwardRef(
b69ab3153 (
b69ab3154 {
b69ab3155 label,
b69ab3156 kind,
b69ab3157 onClick,
b69ab3158 disabled,
b69ab3159 icon,
b69ab3160 tooltip,
b69ab3161 ...rest
b69ab3162 }: {
b69ab3163 label: ReactNode;
b69ab3164 kind?: 'primary' | 'icon' | undefined;
b69ab3165 onClick: () => unknown;
b69ab3166 disabled?: boolean;
b69ab3167 icon?: React.ReactNode;
b69ab3168 tooltip: React.ReactNode;
b69ab3169 'data-testId'?: string;
b69ab3170 },
b69ab3171 ref: ForwardedRef<HTMLButtonElement>,
b69ab3172 ) => {
b69ab3173 return (
b69ab3174 <div {...stylex.props(styles.container)}>
b69ab3175 <Button
b69ab3176 kind={kind}
b69ab3177 onClick={disabled ? undefined : () => onClick()}
b69ab3178 disabled={disabled}
b69ab3179 xstyle={[styles.button, kind === 'icon' && styles.iconButton]}
b69ab3180 ref={ref}
b69ab3181 {...rest}>
b69ab3182 {icon ?? null} {label}
b69ab3183 </Button>
b69ab3184 <Tooltip
b69ab3185 trigger="click"
b69ab3186 component={_dismiss => <div>{tooltip}</div>}
b69ab3187 group="topbar"
b69ab3188 placement="bottom">
b69ab3189 <Button
b69ab3190 kind={kind}
b69ab3191 onClick={undefined}
b69ab3192 disabled={disabled}
b69ab3193 xstyle={[styles.chevron]}
b69ab3194 {...rest}>
b69ab3195 <Icon
b69ab3196 icon="chevron-down"
b69ab3197 {...stylex.props(styles.chevron, disabled && styles.chevronDisabled)}
b69ab3198 />
b69ab3199 </Button>
b69ab31100 </Tooltip>
b69ab31101 </div>
b69ab31102 );
b69ab31103 },
b69ab31104);