Skip to content

Commit 03db769

Browse files
committed
feat(docs): documented as prop implementation
1 parent e74c8b1 commit 03db769

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Remember to register `ThemeProvider` locally.
171171

172172
Add your `ThemeProvider` component:
173173

174-
```JSX
174+
```vue
175175
<theme-provider :theme="{
176176
primary: 'palevioletred'
177177
}">
@@ -240,6 +240,26 @@ const Button = styled.button`
240240
const Link = Button.withComponent('a')
241241
```
242242

243+
### Polymorphic `as` prop
244+
If you want to keep all the styling you've applied to a component but just switch out what's being ultimately rendered (be it a different HTML tag or a different custom component), you can use the "as" prop to do this at runtime. Another powerful feature of the `as` prop is that it preserves styles if the lowest-wrapped component is a `StyledComponent`.
245+
246+
**Example**
247+
In `Component.js`
248+
```js
249+
// Renders a div element by default.
250+
const Component = styled('div', {})``
251+
```
252+
Using the `as` prop in another template/component would be as shown below.
253+
```vue
254+
<template>
255+
<!-- Component will render a button instead of a div -->
256+
<Component as="button" color="red">
257+
Button
258+
</Component>
259+
</template>
260+
```
261+
This sort of thing is very useful in use cases like a navigation bar where some of the items should be links and some just buttons, but all be styled the same way.
262+
243263
### injectGlobal
244264

245265
A helper method to write global CSS. Does not return a component, adds the styles to the stylesheet directly.

0 commit comments

Comments
 (0)