Skip to content

Commit 3074fff

Browse files
committed
♻️ Extend defaultProps
1 parent c30b682 commit 3074fff

File tree

9 files changed

+23
-13
lines changed

9 files changed

+23
-13
lines changed

src/flex-grid.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ const FlexGridItem = styled(FlexGridItemBase)(
7979

8080
FlexGrid.Item = FlexGridItem
8181
FlexGrid.Item.displayName = 'FlexGrid.Item'
82-
FlexGrid.Item.propTypes = { ...getPropTypes(flexGridItem), ...Box.propTypes }
83-
FlexGrid.Item.defaultProps = { flex: '0 1 auto', minWidth: 0 }
82+
FlexGrid.Item.propTypes = { ...getPropTypes(flexGridItem), ...FlexGridItemBase.propTypes }
83+
FlexGrid.Item.defaultProps = { ...FlexGridItemBase.defaultProps, flex: '0 1 auto', minWidth: 0 }
8484

8585
export {
8686
FlexGrid

src/flex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Flex = styled(Box)(
2525

2626
Flex.displayName = 'Flex'
2727
Flex.propTypes = { ...styles.propTypes, ...Box.propTypes }
28-
Flex.defaultProps = { display: 'flex' }
28+
Flex.defaultProps = { ...Box.defaultProps, display: 'flex' }
2929

3030
export {
3131
Flex

src/grid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Grid = styled(Box)(
3434

3535
Grid.displayName = 'Grid'
3636
Grid.propTypes = { ...getPropTypes(styles), ...Box.propTypes }
37-
Grid.defaultProps = { display: 'grid' }
37+
Grid.defaultProps = { ...Box.defaultProps, display: 'grid' }
3838

3939
const BaseGridItem = base({
4040
use: Box,

src/image.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Image.propTypes = {
1313
}
1414

1515
Image.defaultProps = {
16+
...Box.defaultProps,
1617
as: 'img',
1718
display: 'block',
1819
maxWidth: '100%',

src/layout.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ const LayoutSide = styled(Box)()
1212

1313
LayoutSide.displayName = 'Layout.Side'
1414
LayoutSide.propTypes = { ...Box.propTypes }
15-
LayoutSide.defaultProps = { flex: '0 0 auto', minWidth: 0 }
15+
LayoutSide.defaultProps = { ...Box.defaultProps, flex: '0 0 auto', minWidth: 0 }
1616

1717
const LayoutContent = styled(Box)()
1818

1919
LayoutContent.displayName = 'Layout.Content'
2020
LayoutContent.propTypes = { ...Box.propTypes }
21-
LayoutContent.defaultProps = { flex: '1 1 auto', minWidth: 0 }
21+
LayoutContent.defaultProps = { ...Box.defaultProps, flex: '1 1 auto', minWidth: 0 }
2222

2323
Layout.Side = LayoutSide
2424
Layout.Content = LayoutContent

src/link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Link = styled(Text)(
88

99
Link.displayName = 'Link'
1010
Link.propTypes = { ...Text.propTypes }
11-
Link.defaultProps = { as: 'a' }
11+
Link.defaultProps = { ...Text.defaultProps, as: 'a' }
1212

1313
export {
1414
Link

src/list.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const List = styled(BaseList)(
1717
)
1818

1919
List.displayName = 'List'
20-
List.propTypes = { ...listStyle.propTypes, ...Box.propTypes }
21-
List.defaultProps = { listStyle: 'none', as: 'ul' }
20+
List.propTypes = { ...listStyle.propTypes, ...BaseList.propTypes }
21+
List.defaultProps = { ...BaseList.defaultProps, listStyle: 'none', as: 'ul' }
2222

2323
List.Item = styled(Box)(
2424
listStyle
2525
)
2626

2727
List.Item.displayName = 'List.Item'
2828
List.Item.propTypes = { ...listStyle.propTypes, ...Box.propTypes }
29-
List.Item.defaultProps = { as: 'li' }
29+
List.Item.defaultProps = { ...Box.defaultProps, as: 'li' }
3030

3131
export {
3232
List

src/text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Text.displayName = 'Text'
2424

2525
Text.propTypes = {
2626
...getPropTypes(styles),
27-
...Box.propTypes
27+
...BaseText.propTypes
2828
}
2929

3030
export {

src/utils.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function base ({
2222
const Base = React.forwardRef((props, ref) => {
2323
const {
2424
as: Element = defaultElement,
25-
base: Comp = (BaseComp || Element),
25+
base: Comp = Element,
2626
className,
2727
...rest
2828
} = props
@@ -48,10 +48,19 @@ export function base ({
4848
})
4949

5050
Base.displayName = name ? `Base(${name})` : 'Base'
51+
5152
Base.propTypes = {
5253
className: PropTypes.string,
5354
as: PropTypes.elementType,
54-
base: PropTypes.elementType
55+
...BaseComp !== undefined && {
56+
base: PropTypes.elementType,
57+
...BaseComp.propTypes
58+
}
59+
}
60+
61+
Base.defaultProps = {
62+
as: defaultElement,
63+
base: BaseComp
5564
}
5665

5766
return Base

0 commit comments

Comments
 (0)