addons/components/ButtonGroup.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 * as stylex from '@stylexjs/stylex';
b69ab319import React from 'react';
b69ab3110import {colors} from './theme/tokens.stylex';
b69ab3111
b69ab3112const styles = stylex.create({
b69ab3113 group: {
b69ab3114 display: 'flex',
b69ab3115 flexWrap: 'nowrap',
b69ab3116 // StyleX Hack to target Button children of the ButtonGroup
b69ab3117 ':not(#__unused__) > button:not(:first-child):not(:last-child)': {
b69ab3118 borderRadius: 0,
b69ab3119 borderLeft: '1px solid var(--button-secondary-foreground)',
b69ab3120 },
b69ab3121 // button may either be a direct child of the group, or one level deeper (e.g. wrapped in tooltip)
b69ab3122 ':not(#__unused__) > *:not(:first-child):not(:last-child) > button': {
b69ab3123 borderRadius: 0,
b69ab3124 borderLeft: '1px solid var(--button-secondary-foreground)',
b69ab3125 },
b69ab3126 ':not(#__unused__) > *:first-child > button': {
b69ab3127 borderTopRightRadius: 0,
b69ab3128 borderBottomRightRadius: 0,
b69ab3129 },
b69ab3130 ':not(#__unused__) > button:first-child': {
b69ab3131 borderTopRightRadius: 0,
b69ab3132 borderBottomRightRadius: 0,
b69ab3133 },
b69ab3134 ':not(#__unused__) > *:last-child > button': {
b69ab3135 borderTopLeftRadius: 0,
b69ab3136 borderBottomLeftRadius: 0,
b69ab3137 borderLeft: '1px solid var(--button-secondary-foreground)',
b69ab3138 },
b69ab3139 ':not(#__unused__) > button:last-child': {
b69ab3140 borderTopLeftRadius: 0,
b69ab3141 borderBottomLeftRadius: 0,
b69ab3142 borderLeft: '1px solid var(--button-secondary-foreground)',
b69ab3143 },
b69ab3144 },
b69ab3145 icon: {
b69ab3146 ':not(#__unused__) > button:not(:first-child):not(:last-child)': {
b69ab3147 borderLeftColor: colors.hoverDarken,
b69ab3148 },
b69ab3149 ':not(#__unused__) > *:not(:first-child):not(:last-child) > button': {
b69ab3150 borderLeftColor: colors.hoverDarken,
b69ab3151 },
b69ab3152 ':not(#__unused__) > button:last-child': {
b69ab3153 borderLeftColor: colors.hoverDarken,
b69ab3154 },
b69ab3155 ':not(#__unused__) > *:last-child > button': {
b69ab3156 borderLeftColor: colors.hoverDarken,
b69ab3157 },
b69ab3158 },
b69ab3159});
b69ab3160
b69ab3161export function ButtonGroup({
b69ab3162 children,
b69ab3163 icon,
b69ab3164 ...rest
b69ab3165}: {
b69ab3166 children: React.ReactNode;
b69ab3167 /** If true, the border between buttons will be colored to match <Button icon> style buttons */
b69ab3168 icon?: boolean;
b69ab3169 'data-testId'?: string;
b69ab3170}) {
b69ab3171 return (
b69ab3172 <div {...stylex.props(styles.group, icon && styles.icon)} {...rest}>
b69ab3173 {children}
b69ab3174 </div>
b69ab3175 );
b69ab3176}