| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import {type ForwardedRef, forwardRef, type ReactNode} from 'react'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import * as stylex from '@stylexjs/stylex'; |
| b69ab31 | | | 11 | import {Button} from './Button'; |
| b69ab31 | | | 12 | import {Icon} from './Icon'; |
| b69ab31 | | | 13 | import {colors, spacing} from './theme/tokens.stylex'; |
| b69ab31 | | | 14 | import {Tooltip} from './Tooltip'; |
| b69ab31 | | | 15 | |
| b69ab31 | | | 16 | const styles = stylex.create({ |
| b69ab31 | | | 17 | container: { |
| b69ab31 | | | 18 | display: 'flex', |
| b69ab31 | | | 19 | alignItems: 'stretch', |
| b69ab31 | | | 20 | position: 'relative', |
| b69ab31 | | | 21 | }, |
| b69ab31 | | | 22 | button: { |
| b69ab31 | | | 23 | borderBottomRightRadius: 0, |
| b69ab31 | | | 24 | borderTopRightRadius: 0, |
| b69ab31 | | | 25 | }, |
| b69ab31 | | | 26 | chevron: { |
| b69ab31 | | | 27 | borderBottomLeftRadius: 0, |
| b69ab31 | | | 28 | borderTopLeftRadius: 0, |
| b69ab31 | | | 29 | borderLeft: 'unset', |
| b69ab31 | | | 30 | width: '24px', |
| b69ab31 | | | 31 | height: '24px', |
| b69ab31 | | | 32 | paddingTop: 6, |
| b69ab31 | | | 33 | }, |
| b69ab31 | | | 34 | builtinButtonBorder: { |
| b69ab31 | | | 35 | borderLeft: 'unset', |
| b69ab31 | | | 36 | }, |
| b69ab31 | | | 37 | iconButton: { |
| b69ab31 | | | 38 | borderTopRightRadius: 0, |
| b69ab31 | | | 39 | borderBottomRightRadius: 0, |
| b69ab31 | | | 40 | paddingRight: spacing.half, |
| b69ab31 | | | 41 | }, |
| b69ab31 | | | 42 | iconSelect: { |
| b69ab31 | | | 43 | borderTopLeftRadius: 0, |
| b69ab31 | | | 44 | borderBottomLeftRadius: 0, |
| b69ab31 | | | 45 | borderLeftColor: colors.hoverDarken, |
| b69ab31 | | | 46 | }, |
| b69ab31 | | | 47 | chevronDisabled: { |
| b69ab31 | | | 48 | opacity: 0.5, |
| b69ab31 | | | 49 | }, |
| b69ab31 | | | 50 | }); |
| b69ab31 | | | 51 | |
| b69ab31 | | | 52 | export const ButtonWithDropdownTooltip = forwardRef( |
| b69ab31 | | | 53 | ( |
| b69ab31 | | | 54 | { |
| b69ab31 | | | 55 | label, |
| b69ab31 | | | 56 | kind, |
| b69ab31 | | | 57 | onClick, |
| b69ab31 | | | 58 | disabled, |
| b69ab31 | | | 59 | icon, |
| b69ab31 | | | 60 | tooltip, |
| b69ab31 | | | 61 | ...rest |
| b69ab31 | | | 62 | }: { |
| b69ab31 | | | 63 | label: ReactNode; |
| b69ab31 | | | 64 | kind?: 'primary' | 'icon' | undefined; |
| b69ab31 | | | 65 | onClick: () => unknown; |
| b69ab31 | | | 66 | disabled?: boolean; |
| b69ab31 | | | 67 | icon?: React.ReactNode; |
| b69ab31 | | | 68 | tooltip: React.ReactNode; |
| b69ab31 | | | 69 | 'data-testId'?: string; |
| b69ab31 | | | 70 | }, |
| b69ab31 | | | 71 | ref: ForwardedRef<HTMLButtonElement>, |
| b69ab31 | | | 72 | ) => { |
| b69ab31 | | | 73 | return ( |
| b69ab31 | | | 74 | <div {...stylex.props(styles.container)}> |
| b69ab31 | | | 75 | <Button |
| b69ab31 | | | 76 | kind={kind} |
| b69ab31 | | | 77 | onClick={disabled ? undefined : () => onClick()} |
| b69ab31 | | | 78 | disabled={disabled} |
| b69ab31 | | | 79 | xstyle={[styles.button, kind === 'icon' && styles.iconButton]} |
| b69ab31 | | | 80 | ref={ref} |
| b69ab31 | | | 81 | {...rest}> |
| b69ab31 | | | 82 | {icon ?? null} {label} |
| b69ab31 | | | 83 | </Button> |
| b69ab31 | | | 84 | <Tooltip |
| b69ab31 | | | 85 | trigger="click" |
| b69ab31 | | | 86 | component={_dismiss => <div>{tooltip}</div>} |
| b69ab31 | | | 87 | group="topbar" |
| b69ab31 | | | 88 | placement="bottom"> |
| b69ab31 | | | 89 | <Button |
| b69ab31 | | | 90 | kind={kind} |
| b69ab31 | | | 91 | onClick={undefined} |
| b69ab31 | | | 92 | disabled={disabled} |
| b69ab31 | | | 93 | xstyle={[styles.chevron]} |
| b69ab31 | | | 94 | {...rest}> |
| b69ab31 | | | 95 | <Icon |
| b69ab31 | | | 96 | icon="chevron-down" |
| b69ab31 | | | 97 | {...stylex.props(styles.chevron, disabled && styles.chevronDisabled)} |
| b69ab31 | | | 98 | /> |
| b69ab31 | | | 99 | </Button> |
| b69ab31 | | | 100 | </Tooltip> |
| b69ab31 | | | 101 | </div> |
| b69ab31 | | | 102 | ); |
| b69ab31 | | | 103 | }, |
| b69ab31 | | | 104 | ); |