Skip to content

Commit

Permalink
Add sandbox with included React component
Browse files Browse the repository at this point in the history
  • Loading branch information
EricTendian committed Aug 9, 2024
1 parent 7d64f10 commit dc83541
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 57 deletions.
1 change: 1 addition & 0 deletions app/components/sandbox.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div {{react this.theReactComponent message=this.message onClick=this.toggle}} />
18 changes: 18 additions & 0 deletions app/components/sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HelloWorld } from 'react-frontend/hello-world.jsx';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class SandboxComponent extends Component {
theReactComponent = HelloWorld;

@tracked message = 'hello';

@action toggle() {
if (this.message === 'hello') {
this.message = 'goodbye';
} else {
this.message = 'hello';
}
}
}
14 changes: 14 additions & 0 deletions app/modifiers/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Modifier from 'ember-modifier';
import { createRoot } from 'react-dom/client';
import { createElement } from 'react';
import { registerDestructor } from '@ember/destroyable';

export default class ReactModifier extends Modifier {
modify(element, [reactComponent], props) {
if (!this.root) {
this.root = createRoot(element);
registerDestructor(this, () => this.root.unmount());
}
this.root.render(createElement(reactComponent, { ...props }));
}
}
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Router.map(function () {
});
this.route('settings');
this.route('airshow');
this.route('sandbox');
});
3 changes: 3 additions & 0 deletions app/routes/sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Route from '@ember/routing/route';

export default class SandboxRoute extends Route {}
4 changes: 4 additions & 0 deletions app/templates/sandbox.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{page-title "Sandbox"}}
<div class="container">
<Sandbox />
</div>
18 changes: 18 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ const Funnel = require('broccoli-funnel');

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
autoImport: {
webpack: {
module: {
rules: [
{
test: /react-frontend\/.*\.jsx/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-react', { runtime: 'automatic' }]],
},
},
},
],
},
},
},

babel: {
plugins: [
// ... any other plugins
Expand Down
Loading

0 comments on commit dc83541

Please sign in to comment.