File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,11 +12,12 @@ export const Breadcrumb: React.FC<BreadcrumbProps> = props => {
1212
1313 const { splitter = < IconChevronRight size = { 16 } /> , children, ...rest } = props
1414
15- const count = React . Children . count ( children )
15+ const validChildren = React . Children . toArray ( children ) . filter ( child => child != null )
16+ const count = validChildren . length
1617
1718 return (
1819 < div { ...mergeComponentProps ( `breadcrumb` , rest ) } >
19- { React . Children . map ( children , ( child , index ) => (
20+ { validChildren . map ( ( child , index ) => (
2021 < React . Fragment key = { index } >
2122 { child }
2223 { index < count - 1 ? (
Original file line number Diff line number Diff line change @@ -4,20 +4,31 @@ import "./ButtonGroup.style.scss"
44import { Component , Color , mergeComponentProps } from "../../utils" ;
55
66export interface ButtonGroupType extends Component < HTMLDivElement > {
7- children : ReactElement < ButtonProps > [ ]
7+ children : ReactElement < ButtonProps > | ReactElement < ButtonProps > [ ]
88 color ?: Color
99}
1010
1111export const ButtonGroup : React . FC < ButtonGroupType > = ( props ) => {
1212
1313 const { children, color = "secondary" , ...args } = props
1414
15+ const validChildren = React . Children . toArray ( children ) . filter ( child => child != null )
16+ const count = validChildren . length
17+
1518 return < div { ...mergeComponentProps ( `button-group button-group--${ color } ` , args ) } >
1619
17- { children . map ( ( child , i ) => {
20+ { validChildren . map ( ( child , i ) => {
21+
22+ let className = "button-group__item"
23+ if ( i === count - 1 ) {
24+ className = "button-group__last"
25+ } else if ( i === 0 ) {
26+ className = "button-group__first"
27+ }
28+
1829 return < div
19- key = { child . key ?? `button-group-${ i } ` }
20- className = { ` ${ i == 0 || i == children . length - 1 ? i == 0 ? "button-group__first" : "button-group__last" : "button-group__item" } ` } >
30+ key = { `button-group-${ i } ` }
31+ className = { className } >
2132 { child }
2233 </ div >
2334 } ) }
You can’t perform that action at this time.
0 commit comments