MCPcopy
hub / github.com/untitleduico/react / ButtonGroupItem

Function ButtonGroupItem

components/base/button-group/button-group.tsx:54–87  ·  view source on GitHub ↗
({
    iconLeading: IconLeading,
    iconTrailing: IconTrailing,
    children,
    className,
    ...otherProps
}: PropsWithChildren<ButtonGroupItemProps>)

Source from the content-addressed store, hash-verified

52}
53
54export 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
89interface ButtonGroupProps extends Omit<ToggleButtonGroupProps, "orientation">, RefAttributes<HTMLDivElement> {
90 size?: ButtonSize;

Callers

nothing calls this directly

Calls 1

isReactComponentFunction · 0.90

Tested by

no test coverage detected