Skip to content

Commit

Permalink
add vue decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
bmartel committed Jun 2, 2018
1 parent 0f07e61 commit 3d8c893
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import 'storybook-addon-figma/register'

Link a Figma design to your story

## With React

```jsx
import React from 'react'
import { storiesOf } from '@storybook/react'
Expand All @@ -38,6 +40,23 @@ storiesOf('Button')
))
```

## With Vue

```jsx
import Vue from 'vue'
import { storiesOf } from '@storybook/vue'
import { WithFigma } from 'storybook-addon-figma/vue'

storiesOf('Button')
.add('With Figma', () => ({
components: { WithFigma },
template: `
<with-figma url="https://www.figma.com/file/LbcvMJxDtshDmYtdyfJfkA72/Button-Primary">
<button>My Button</button>
</with-figma>
`
}))
```


## Embed a different design on each story
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"babel-preset-react-app": "3.0.3",
"react": "16.0.0",
"react-dom": "16.0.0"
},
"peerDependencies": {
"vue": ">= 2.0.0"
}
}
26 changes: 26 additions & 0 deletions src/vue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Vue from "vue";
import addons from "@storybook/addons";
import { EVENT_ID } from "./shared";

export const WithFigma = Vue.component("with-figma", {
props: {
url: { type: String, required: true },
allowFullScreen: { type: Boolean, default: true },
embedHost: { type: String, default: "storybook" }
},
render(el) {
addons.getChannel().emit(EVENT_ID, {
url: this.url,
allowFullScreen: this.allowFullScreen,
embedHost: this.embedHost
});

try {
return this.$slots.default[0];
} catch (e) {
throw new Error("WithFigma can only render one child component.");
}

return null;
}
});
1 change: 1 addition & 0 deletions vue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./dist/vue");

0 comments on commit 3d8c893

Please sign in to comment.