2.3 KB77 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 * as stylex from '@stylexjs/stylex';
9import React from 'react';
10import {colors} from './theme/tokens.stylex';
11
12const styles = stylex.create({
13 group: {
14 display: 'flex',
15 flexWrap: 'nowrap',
16 // StyleX Hack to target Button children of the ButtonGroup
17 ':not(#__unused__) > button:not(:first-child):not(:last-child)': {
18 borderRadius: 0,
19 borderLeft: '1px solid var(--button-secondary-foreground)',
20 },
21 // button may either be a direct child of the group, or one level deeper (e.g. wrapped in tooltip)
22 ':not(#__unused__) > *:not(:first-child):not(:last-child) > button': {
23 borderRadius: 0,
24 borderLeft: '1px solid var(--button-secondary-foreground)',
25 },
26 ':not(#__unused__) > *:first-child > button': {
27 borderTopRightRadius: 0,
28 borderBottomRightRadius: 0,
29 },
30 ':not(#__unused__) > button:first-child': {
31 borderTopRightRadius: 0,
32 borderBottomRightRadius: 0,
33 },
34 ':not(#__unused__) > *:last-child > button': {
35 borderTopLeftRadius: 0,
36 borderBottomLeftRadius: 0,
37 borderLeft: '1px solid var(--button-secondary-foreground)',
38 },
39 ':not(#__unused__) > button:last-child': {
40 borderTopLeftRadius: 0,
41 borderBottomLeftRadius: 0,
42 borderLeft: '1px solid var(--button-secondary-foreground)',
43 },
44 },
45 icon: {
46 ':not(#__unused__) > button:not(:first-child):not(:last-child)': {
47 borderLeftColor: colors.hoverDarken,
48 },
49 ':not(#__unused__) > *:not(:first-child):not(:last-child) > button': {
50 borderLeftColor: colors.hoverDarken,
51 },
52 ':not(#__unused__) > button:last-child': {
53 borderLeftColor: colors.hoverDarken,
54 },
55 ':not(#__unused__) > *:last-child > button': {
56 borderLeftColor: colors.hoverDarken,
57 },
58 },
59});
60
61export function ButtonGroup({
62 children,
63 icon,
64 ...rest
65}: {
66 children: React.ReactNode;
67 /** If true, the border between buttons will be colored to match <Button icon> style buttons */
68 icon?: boolean;
69 'data-testId'?: string;
70}) {
71 return (
72 <div {...stylex.props(styles.group, icon && styles.icon)} {...rest}>
73 {children}
74 </div>
75 );
76}
77