diff --git a/packages/app/src/layouts/components/floatingStack/index.jsx b/packages/app/src/layouts/components/floatingStack/index.jsx new file mode 100644 index 00000000..44efedbb --- /dev/null +++ b/packages/app/src/layouts/components/floatingStack/index.jsx @@ -0,0 +1,113 @@ +import React from "react" +import { DOMWindow } from "components/RenderWindow" + +import "./index.less" + +class FloatingStackItem extends React.PureComponent { + state = { + renderError: null + } + + componentDidCatch(error, info) { + console.log(error, info) + + this.setState({ + renderError: error, + }) + } + + render() { + if (this.state.renderError) { + return
+

Render Error

+
+ } + + return
+ + {this.props.children} + +
+ } +} + +export default class FloatingStack extends React.Component { + state = { + renders: [], + } + + public = { + add: (id, render) => { + try { + if (!id) { + console.error(`FloatingStack: id is required`) + return false + } + if (!render) { + console.error(`FloatingStack: render is required`) + return false + } + + if (this.state.renders.find((item) => item.id === id)) { + console.error(`FloatingStack: id ${id} already exists`) + return false + } + + this.setState({ + renders: [ + ...this.state.renders, + { + id, + render: React.createElement(render), + }, + ] + }) + + return render + } catch (error) { + console.log(error) + return null + } + }, + remove: (id) => { + this.setState({ + renders: this.state.renders.filter((item) => { + return item.id !== id + }) + }) + + return true + } + } + + componentDidMount() { + window.app.layout.floatingStack = this.public + } + + componentWillUnmount() { + window.app.layout.floatingStack = null + delete window.app.layout.floatingStack + } + + render() { + return
+ { + this.state.renders.map((item) => { + return + {item.render} + + }) + } +
+ } +} + +export const createWithDom = () => { + const dom = new DOMWindow({ + id: "FloatingStack", + }) + + dom.render() + + return dom +} \ No newline at end of file diff --git a/packages/app/src/layouts/components/floatingStack/index.less b/packages/app/src/layouts/components/floatingStack/index.less new file mode 100644 index 00000000..9e099c0e --- /dev/null +++ b/packages/app/src/layouts/components/floatingStack/index.less @@ -0,0 +1,25 @@ +.floating_stack { + position: absolute; + z-index: 300; + + right: 0; + bottom: 0; + + display: flex; + flex-direction: column; + + align-items: center; + justify-content: center; + + max-width: 270px; + + gap: 20px; + + margin: 20px; + + transition: all 0.3s ease-in-out; +} + +.floating_stack_item { + width: 100%; +} \ No newline at end of file