({
iconLeading: IconLeading,
iconTrailing: IconTrailing,
children,
className,
...otherProps
}: PropsWithChildren<ButtonGroupItemProps>)
| 52 | } |
| 53 | |
| 54 | export const ButtonGroupItem = ({ |
| 55 | iconLeading: IconLeading, |
| 56 | iconTrailing: IconTrailing, |
| 57 | children, |
| 58 | className, |
| 59 | ...otherProps |
| 60 | }: PropsWithChildren<ButtonGroupItemProps>) => { |
| 61 | const context = useContext(ButtonGroupContext); |
| 62 | |
| 63 | if (!context) { |
| 64 | throw new Error("ButtonGroupItem must be used within a ButtonGroup component"); |
| 65 | } |
| 66 | |
| 67 | const { size } = context; |
| 68 | |
| 69 | const isIcon = (IconLeading || IconTrailing) && !children; |
| 70 | |
| 71 | return ( |
| 72 | <AriaToggleButton |
| 73 | {...otherProps} |
| 74 | data-icon-only={isIcon ? true : undefined} |
| 75 | data-icon-leading={IconLeading ? true : undefined} |
| 76 | className={cx(styles.common.root, styles.sizes[size].root, className)} |
| 77 | > |
| 78 | {isReactComponent(IconLeading) && <IconLeading className={cx(styles.common.icon, styles.sizes[size].icon)} />} |
| 79 | {isValidElement(IconLeading) && IconLeading} |
| 80 | |
| 81 | {children} |
| 82 | |
| 83 | {isReactComponent(IconTrailing) && <IconTrailing className={cx(styles.common.icon, styles.sizes[size].icon)} />} |
| 84 | {isValidElement(IconTrailing) && IconTrailing} |
| 85 | </AriaToggleButton> |
| 86 | ); |
| 87 | }; |
| 88 | |
| 89 | interface ButtonGroupProps extends Omit<ToggleButtonGroupProps, "orientation">, RefAttributes<HTMLDivElement> { |
| 90 | size?: ButtonSize; |
nothing calls this directly
no test coverage detected