@@ -22,85 +22,79 @@ export interface ButtonGroupProps extends ButtonProps, FlexProps {
2222 inline ?: boolean ;
2323}
2424
25- export default class ButtonGroup extends Component < ButtonGroupProps > {
26- static defaultProps : ButtonGroupProps = {
27- bordered : true ,
28- inline : false ,
29- } ;
30- render ( ) {
31- const {
32- children,
33- gutter,
34- inline,
35- size,
36- rounded, // Button Props
37- color,
38- type,
39- bordered,
40- disabled,
41- textStyle, // Button Props
42- direction,
43- justify,
44- align,
45- wrap, // Flex Props
46- ...otherProps
47- } = this . props ;
48- const porps = { color, type, bordered, disabled, textStyle } ;
49- const flexProps = { direction, justify, align, wrap } ;
50- const childs = React . Children . toArray ( children ) ;
25+ export default function ButtonGroup ( props : ButtonGroupProps ) {
26+ const {
27+ children,
28+ gutter,
29+ inline = false ,
30+ size,
31+ rounded, // Button Props
32+ color,
33+ type,
34+ bordered = true ,
35+ disabled,
36+ textStyle, // Button Props
37+ direction,
38+ justify,
39+ align,
40+ wrap, // Flex Props
41+ ...otherProps
42+ } = props ;
43+ const porps = { color, type, bordered, disabled, textStyle } ;
44+ const flexProps = { direction, justify, align, wrap } ;
45+ const childs = React . Children . toArray ( children ) ;
5146
52- if ( inline ) {
53- flexProps . direction = 'row' ;
54- flexProps . wrap = 'wrap' ;
55- }
47+ if ( inline ) {
48+ flexProps . direction = 'row' ;
49+ flexProps . wrap = 'wrap' ;
50+ }
5651
57- return (
58- < Flex testID = "RNE__ButtonGroup__wrap" style = { styles . default } { ...flexProps } { ...otherProps } >
59- { childs . map ( ( child : React . ReactNode , idx : number ) => {
60- if ( ! React . isValidElement ( child ) ) {
61- return null ;
62- }
63- const childStyle : ButtonProps [ 'style' ] = {
64- flex : inline ? 0 : 1 ,
65- } ;
66- if ( inline && gutter ) {
67- childStyle . marginVertical = gutter / 2 ;
52+ return (
53+ < Flex testID = "RNE__ButtonGroup__wrap" style = { styles . default } { ...flexProps } { ...otherProps } >
54+ { childs . map ( ( child : React . ReactNode , idx : number ) => {
55+ if ( ! React . isValidElement ( child ) ) {
56+ return null ;
57+ }
58+ const childStyle : ButtonProps [ 'style' ] = {
59+ flex : inline ? 0 : 1 ,
60+ } ;
61+ if ( inline && gutter ) {
62+ childStyle . marginVertical = gutter / 2 ;
63+ }
64+ if ( ! gutter ) {
65+ if ( childs . length !== 1 && ( idx === 0 || idx < childs . length - 1 ) ) {
66+ childStyle . borderTopRightRadius = 0 ;
67+ childStyle . borderBottomRightRadius = 0 ;
6868 }
69- if ( ! gutter ) {
70- if ( childs . length !== 1 && ( idx === 0 || idx < childs . length - 1 ) ) {
71- childStyle . borderTopRightRadius = 0 ;
72- childStyle . borderBottomRightRadius = 0 ;
73- }
74- if ( childs . length > 0 && idx !== 0 ) {
75- childStyle . borderTopLeftRadius = 0 ;
76- childStyle . borderBottomLeftRadius = 0 ;
77- }
69+ if ( childs . length > 0 && idx !== 0 ) {
70+ childStyle . borderTopLeftRadius = 0 ;
71+ childStyle . borderBottomLeftRadius = 0 ;
7872 }
79- if ( ! bordered ) {
80- childStyle . borderWidth = 0 ;
73+ }
74+ if ( ! bordered ) {
75+ childStyle . borderWidth = 0 ;
76+ }
77+ if ( bordered && ! gutter ) {
78+ if ( ( idx > 0 && idx < ( children as ButtonProps [ ] ) . length - 1 ) || idx === 0 ) {
79+ childStyle . borderRightWidth = StyleSheet . hairlineWidth ;
8180 }
82- if ( bordered && ! gutter ) {
83- if ( ( idx > 0 && idx < ( children as ButtonProps [ ] ) . length - 1 ) || idx === 0 ) {
84- childStyle . borderRightWidth = StyleSheet . hairlineWidth ;
85- }
86- if ( idx > 0 && idx < ( children as ButtonProps [ ] ) . length ) {
87- childStyle . borderLeftWidth = StyleSheet . hairlineWidth ;
88- }
81+ if ( idx > 0 && idx < ( children as ButtonProps [ ] ) . length ) {
82+ childStyle . borderLeftWidth = StyleSheet . hairlineWidth ;
8983 }
90- if ( gutter && inline ) {
91- childStyle . marginHorizontal = gutter / 2 ;
92- } else if ( gutter && idx !== 0 ) {
93- childStyle . marginLeft = gutter / 2 ;
94- }
95- return React . cloneElement ( child , {
96- ... porps ,
97- ...child . props ,
98- size ,
99- rounded ,
100- style : [ childStyle , child . props . style ] ,
101- } ) ;
102- } ) }
103- </ Flex >
104- ) ;
105- }
84+ }
85+ if ( gutter && inline ) {
86+ childStyle . marginHorizontal = gutter / 2 ;
87+ } else if ( gutter && idx !== 0 ) {
88+ childStyle . marginLeft = gutter / 2 ;
89+ }
90+ return React . cloneElement ( child , {
91+ ...porps ,
92+ ... child . props ,
93+ size ,
94+ rounded ,
95+ style : [ childStyle , child . props . style ] ,
96+ } ) ;
97+ } ) }
98+ </ Flex >
99+ ) ;
106100}
0 commit comments