render react in demo component
This commit is contained in:
@@ -5,4 +5,4 @@ slug: react
|
|||||||
|
|
||||||
This is a basic example of tiptap.
|
This is a basic example of tiptap.
|
||||||
|
|
||||||
<react-wrapper />
|
<demo name="React" mode="react" />
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="demo">
|
<div class="demo">
|
||||||
<div class="demo__preview" v-if="mainFile">
|
<div class="demo__preview" v-if="mainFile">
|
||||||
<component :is="mainFile" />
|
<component :is="mainFile" v-if="mode === 'vue'"/>
|
||||||
|
<react-wrapper :component="mainFile" v-if="mode === 'react'" />
|
||||||
</div>
|
</div>
|
||||||
<div class="demo__source">
|
<div class="demo__source">
|
||||||
<div class="demo__tabs" v-if="showFileNames">
|
<div class="demo__tabs" v-if="showFileNames">
|
||||||
@@ -23,12 +24,22 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ReactWrapper from '~/components/ReactWrapper'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
ReactWrapper,
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'vue',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
@@ -38,6 +49,7 @@ export default {
|
|||||||
currentIndex: 0,
|
currentIndex: 0,
|
||||||
syntax: {
|
syntax: {
|
||||||
js: 'javascript',
|
js: 'javascript',
|
||||||
|
jsx: 'jsx',
|
||||||
vue: 'markup',
|
vue: 'markup',
|
||||||
css: 'css',
|
css: 'css',
|
||||||
},
|
},
|
||||||
@@ -46,7 +58,7 @@ export default {
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
mainFile() {
|
mainFile() {
|
||||||
const file = this.files.find(item => item.path.endsWith('.vue'))
|
const file = this.files.find(item => item.path.endsWith('.vue') || item.path.endsWith('.jsx'))
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return
|
return
|
||||||
@@ -68,7 +80,7 @@ export default {
|
|||||||
this.files = require.context(`~/demos/`, true)
|
this.files = require.context(`~/demos/`, true)
|
||||||
.keys()
|
.keys()
|
||||||
.filter(path => path.startsWith(`./${this.name}`))
|
.filter(path => path.startsWith(`./${this.name}`))
|
||||||
.filter(path => path.endsWith('.vue') || path.endsWith('.js') || path.endsWith('.css'))
|
.filter(path => path.endsWith('.vue') || path.endsWith('.js') || path.endsWith('.css') || path.endsWith('.jsx'))
|
||||||
.map(path => path.replace('./', ''))
|
.map(path => path.replace('./', ''))
|
||||||
.map(path => ({
|
.map(path => ({
|
||||||
path,
|
path,
|
||||||
|
|||||||
@@ -5,15 +5,20 @@
|
|||||||
<script>
|
<script>
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import ReactTestComponent from '~/components/ReactTestComponent/index.jsx'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mounted(){
|
props: {
|
||||||
ReactDOM.render(React.createElement(ReactTestComponent, this.$props), this.$el)
|
component: {
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy(){
|
mounted() {
|
||||||
|
ReactDOM.render(React.createElement(this.component), this.$el)
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
ReactDOM.unmountComponentAtNode(this.$el)
|
ReactDOM.unmountComponentAtNode(this.$el)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -11,7 +11,7 @@ export default class TestComponent extends Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.editor = new Editor({
|
this.editor = new Editor({
|
||||||
element: this.editorNode.current,
|
element: this.editorNode.current,
|
||||||
content: '<p>rendered in <strong>react</strong></p>',
|
content: '<p>rendered in <strong>react</strong>!</p>',
|
||||||
extensions: extensions(),
|
extensions: extensions(),
|
||||||
})
|
})
|
||||||
this.forceUpdate()
|
this.forceUpdate()
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import Prism from 'prismjs'
|
import Prism from 'prismjs'
|
||||||
import 'prismjs/themes/prism-coy.css'
|
import 'prismjs/themes/prism-coy.css'
|
||||||
|
import 'prismjs/components/prism-jsx.js'
|
||||||
import DefaultLayout from '~/layouts/Default.vue'
|
import DefaultLayout from '~/layouts/Default.vue'
|
||||||
import Demo from '~/components/Demo'
|
import Demo from '~/components/Demo'
|
||||||
import Tab from '~/components/Tab'
|
import Tab from '~/components/Tab'
|
||||||
|
|||||||
Reference in New Issue
Block a user