Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit c065d09

Browse files
committed
feat: deprecate "component" in favor of "as"
Closes #33
1 parent df506d2 commit c065d09

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

docs/advanced/CustomComponent.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Sometimes you may want to use a component but the resulting HTML tag is not the
1212

1313
You can do it using two approaches.
1414

15-
## Use "component" property
15+
## Use "as" property
1616

17-
Every components accepts a `component` property, it defines the base component used in each component.
17+
Every components accepts a `as` property, it defines the base component used in each component.
1818

1919
An example of an `Alert` that uses `span` as a component.
2020

2121
<Playground>
22-
<Alert component="span" variant="primary">
22+
<Alert as="span" variant="primary">
2323
A span alert
2424
</Alert>
2525
</Playground>

docs/components/Typography.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ HTML component is automatically determined from variant. You can customize it us
5858
}}
5959
</Playground>
6060

61-
### Using `component` property
61+
### Using `as` property
6262

6363
<Playground>
64-
<Typography variant="h4" component="div">
64+
<Typography variant="h4" as="div">
6565
div displayed as h4
6666
</Typography>
6767
</Playground>

src/styled-engine/emotion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const patchStyledAPI = (StyledComponent, BaseComponent) => {
7070
)
7171
StyledComponent.withComponent = component => {
7272
const NewStyledComponent = originalWithComponent(props => (
73-
<BaseComponent component={component} {...props} />
73+
<BaseComponent as={component} {...props} />
7474
))
7575

7676
patchStyledAPI(NewStyledComponent, BaseComponent)

src/styled-engine/styled-components.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export const patchStyledAPI = (StyledComponent, BaseComponent) => {
3030
StyledComponent,
3131
)
3232
StyledComponent.withComponent = component => {
33-
const CustomComponent = props => (
34-
<BaseComponent component={component} {...props} />
35-
)
33+
const CustomComponent = props => <BaseComponent as={component} {...props} />
3634
const NewStyledComponent = originalWithComponent(CustomComponent)
3735
patchStyledAPI(NewStyledComponent, BaseComponent)
3836
return NewStyledComponent

src/utils/createComponent.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,22 @@ function createComponent(getConfig) {
3434
render() {
3535
const {
3636
className,
37-
component: Component = defaultComponent,
37+
as,
38+
component,
3839
theme,
3940
baseRef,
4041
...props
4142
} = this.props
4243

44+
const Component = as || component || defaultComponent
45+
46+
if (component && process.env.NODE_ENV !== 'production') {
47+
// eslint-disable-next-line no-console
48+
console.warn(
49+
'Smooth UI: "component" prop is deprecated and will be removed in v6, please use "as" instead.',
50+
)
51+
}
52+
4353
const renderProps = {
4454
ref: baseRef,
4555
Component,

0 commit comments

Comments
 (0)