Skip to content

Commit 9968e52

Browse files
committed
docs(as prop): added docs for as prop anding
1 parent ca2a745 commit 9968e52

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

example/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ <h1>Basic Example</h1>
150150
secondary: 'papayawhip',
151151
tertiary: 'lavenderblush'
152152
}">
153+
<!--
153154
<wrapper>
154155
<custom-title :visible="true" :animate="animated1"> {{text1}} </custom-title>
155156
<styled-input v-model="text1" />
@@ -160,6 +161,7 @@ <h1>Basic Example</h1>
160161
<styled-input v-model="text2" />
161162
<super-btn visible @click="animated2 = !animated2"> An extension of Styled Button </super-btn>
162163
</w-2>
164+
-->
163165
<w-3
164166
bg="#c6f7e6"
165167
>

src/models/StyledComponent.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import css from '../constructors/css'
22
import normalizeProps from '../utils/normalizeProps'
3+
import isVueComponent from '../utils/isVueComponent'
34

45
export default (ComponentStyle) => {
56
const createStyledComponent = (target, rules, props) => {
@@ -39,7 +40,19 @@ export default (ComponentStyle) => {
3940
}
4041

4142
return createElement(
42-
this.$props.as || target,
43+
/**
44+
* The reason for this check is to test whether the "target" is a Vue / Styled component.
45+
* If the target is a styled component, we render that styled component to preserve the
46+
* styles inherited from the "target" in the new component to be rendered.
47+
*
48+
* The "target" will inherently possess the "as" polymorphic prop. This allows the
49+
* consumer component to render the tag passed inside of it's "as" element it's
50+
* rendering recursively.
51+
*
52+
* Otherwise if the "target" is not a styled component we render the "as" prop element.
53+
* If the "as" prop is not provided, we use the default element.
54+
*/
55+
isVueComponent(target) ? target : this.$props.as || target,
4356
{
4457
class: [this.generatedClassName],
4558
props: this.$props,

0 commit comments

Comments
 (0)