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