Description
I propose to add support to custom child properties. This expand the options to create and organize the components and can reduce the amount of components in some cases.
Current Behavior
const MyComponent = (props) => {
const { header, body, footer } = props
return (
<div>
<div>{header}</div>
<div>{body}</div>
<div>{footer}</div>
</div>
)
}
const Page = () =>
<MyComponent
header={
<div>
<Brand>My Brand</Brand>
<Menu>
<MenuItem>Item 1</MenuItem>
<MenuItem>Item 2</MenuItem>
<MenuItem>Item 3</MenuItem>
<MenuItem>Item 4</MenuItem>
</Menu>
<UserName>Codeco</UserName>
<SignOutButton />
<div>
}
body={
<div>
<p>My content 1</p>
<p>My content 2</p>
<p>My content 3</p>
<p>My content 4</p>
<p>My content 5</p>
<p>My content 6</p>
<p>My content 7</p>
<p>My content 8</p>
<p>My content 9</p>
</div>
}
footer={
<div>
<b>codeco</b>
<b>proposal</b>
<b>2022</b>
</div>
}
/>
Desired Behavior
const MyComponent = (props) => {
const { header, body, footer } = props
return (
<div>
<div>{header}</div>
<div>{body}</div>
<div>{footer}</div>
</div>
)
}
const Page = () =>
<MyComponent>
<MyComponent.header>
<div>
<Brand>My Brand</Brand>
<Menu>
<MenuItem>Item 1</MenuItem>
<MenuItem>Item 2</MenuItem>
<MenuItem>Item 3</MenuItem>
<MenuItem>Item 4</MenuItem>
</Menu>
<UserName>Codeco</UserName>
<SignOutButton />
<div>
</MyComponent.header>
<MyComponent.body>
<div>
<p>My content 1</p>
<p>My content 2</p>
<p>My content 3</p>
<p>My content 4</p>
<p>My content 5</p>
<p>My content 6</p>
<p>My content 7</p>
<p>My content 8</p>
<p>My content 9</p>
</div>
</MyComponent.body>
<MyComponent.footer>
<div>
<b>codeco</b>
<b>proposal</b>
<b>2022</b>
</div>
</MyComponent.footer>
</MyComponent>
This example above expand the options to create and organize the components.
To use a real case...
Some developers make their codes like this:
<Card variant="outlined">
<CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be{bull}nev{bull}o{bull}lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
... creating two components (CardContent and CardActions) to direct the content...
(this example was copied from https://mui.com/pt/material-ui/react-card/#OutlinedCard.tsx and changed to simplify)
... but imagine doing something like this:
<Card variant="outlined">
<Card.Content>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be{bull}nev{bull}o{bull}lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</Card.Content>
<Card.Actions>
<Button size="small">Learn More</Button>
</Card.Actions>
</Card>
eliminating the need to create more components, reducing the amount of components on the page.
So, adding support to use the components properties, like header; body and footer from MyComponent in my example, as a children make possible this behaviors.
make sense?