1
- import type { ReactElement } from 'react' ;
2
1
import React from 'react' ;
3
2
import styled from 'styled-components' ;
4
3
import type { ButtonGroupProps } from './types' ;
@@ -13,10 +12,9 @@ import type { DotNotationToken } from '~utils/lodashButBetter/get';
13
12
import getIn from '~utils/lodashButBetter/get' ;
14
13
import { getBackgroundColorToken } from '~components/Button/BaseButton/BaseButton' ;
15
14
import type { Theme } from '~components/BladeProvider' ;
16
- import { throwBladeError } from '~utils/logger' ;
17
- import { isValidAllowedChildren } from '~utils/isValidAllowedChildren' ;
18
15
import type { BladeElementRef } from '~utils/types' ;
19
16
import { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute' ;
17
+ import { useVerifyAllowedChildren } from '~utils/useVerifyAllowedChildren' ;
20
18
21
19
const getDividerColorToken = ( {
22
20
color,
@@ -74,6 +72,12 @@ const _ButtonGroup = (
74
72
isFullWidth,
75
73
} ;
76
74
75
+ useVerifyAllowedChildren ( {
76
+ allowedComponents : [ 'Button' , 'Dropdown' , 'Tooltip' , 'Popover' ] ,
77
+ componentName : 'ButtonGroup' ,
78
+ children,
79
+ } ) ;
80
+
77
81
return (
78
82
< ButtonGroupProvider value = { contextValue } >
79
83
< StyledButtonGroup
@@ -88,26 +92,6 @@ const _ButtonGroup = (
88
92
role = "group"
89
93
>
90
94
{ React . Children . map ( children , ( child , index ) => {
91
- if ( __DEV__ ) {
92
- // throw error if child is not a button or dropdown with button trigger
93
- /* eslint-disable no-restricted-properties */
94
- if (
95
- ! isValidAllowedChildren ( child , 'Button' ) &&
96
- ! (
97
- isValidAllowedChildren ( child , 'Dropdown' ) &&
98
- ( child as ReactElement ) . props . children . some ( ( c : ReactElement ) =>
99
- isValidAllowedChildren ( c , 'DropdownButton' ) ,
100
- )
101
- )
102
- ) {
103
- throwBladeError ( {
104
- moduleName : 'ButtonGroup' ,
105
- message : `Only "Button" or "Dropdown" component with Button trigger are allowed as children.` ,
106
- } ) ;
107
- }
108
- /* eslint-enable no-restricted-properties */
109
- }
110
-
111
95
return (
112
96
< >
113
97
{ child }
0 commit comments