Skip to content

Commit

Permalink
Better async loading behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
NickGerleman committed Oct 20, 2023
1 parent b496008 commit 1acbd2e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 61 deletions.
27 changes: 20 additions & 7 deletions website-next/src/components/Playground/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

.PlaygroundContainer {
.PlaygroundContainer {
display: flex;
flex-direction: row;
flex-grow: 1;
width: 100%;
}

.Playground {
display: flex;
flex-grow: 1;
position: relative;
width: 100%;
overflow: hidden;
.playground-background {
background: linear-gradient(-90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px),
linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
linear-gradient(-90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
Expand All @@ -41,6 +36,15 @@
100px 100px, 100px 100px, 100px 100px;
}

.Playground {
display: flex;
flex-grow: 1;
position: relative;
width: 100%;
overflow: hidden;
animation: playground-content-fade-in-frames 50ms ease-in;
}

.Playground > .YogaNode {
margin: auto;
position: static;
Expand Down Expand Up @@ -72,3 +76,12 @@
.ant-modal-content {
overflow: hidden;
}

@keyframes playground-content-fade-in-frames {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
98 changes: 52 additions & 46 deletions website-next/src/components/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,52 +235,58 @@ export default class Playground extends Component<Props, State> {
: null;

const playground = (
<div
className={`Playground ${this.props.renderSidebar ? '' : 'standalone'}`}
onMouseDown={this.onMouseDown}
style={{height, maxHeight: height}}
ref={ref => {
this._containerRef = ref;
}}>
<YogaNode
layoutDefinition={layoutDefinition}
selectedNodePath={selectedNodePath}
onClick={selectedNodePath => this.setState({selectedNodePath})}
onDoubleClick={this.onAdd}
direction={direction}
showGuides={this.props.showGuides}
/>
{!this.props.renderSidebar && (
<Sidebar>
{this.state.selectedNodePath ? (
<Editor
node={selectedNode}
selectedNodeIsRoot={
selectedNodePath ? selectedNodePath.length === 0 : false
}
onChangeLayout={this.onChangeLayout}
// @ts-ignore
onChangeSetting={(key, value) => this.setState({[key]: value})}
direction={direction}
onRemove={
selectedNodePath && selectedNodePath.length > 0
? this.onRemove
: undefined
}
onAdd={
selectedNodePath &&
selectedNodePath.length < this.props.maxDepth
? this.onAdd
: undefined
}
/>
) : (
<div className="NoContent">
Select a node to edit its properties
</div>
)}
</Sidebar>
)}
<div className="playground-background">
<div
className={`Playground ${
this.props.renderSidebar ? '' : 'standalone'
}`}
onMouseDown={this.onMouseDown}
style={{height, maxHeight: height}}
ref={ref => {
this._containerRef = ref;
}}>
<YogaNode
layoutDefinition={layoutDefinition}
selectedNodePath={selectedNodePath}
onClick={selectedNodePath => this.setState({selectedNodePath})}
onDoubleClick={this.onAdd}
direction={direction}
showGuides={this.props.showGuides}
/>
{!this.props.renderSidebar && (
<Sidebar>
{this.state.selectedNodePath ? (
<Editor
node={selectedNode}
selectedNodeIsRoot={
selectedNodePath ? selectedNodePath.length === 0 : false
}
onChangeLayout={this.onChangeLayout}
// @ts-ignore
onChangeSetting={(key, value) =>
this.setState({[key]: value})
}
direction={direction}
onRemove={
selectedNodePath && selectedNodePath.length > 0
? this.onRemove
: undefined
}
onAdd={
selectedNodePath &&
selectedNodePath.length < this.props.maxDepth
? this.onAdd
: undefined
}
/>
) : (
<div className="NoContent">
Select a node to edit its properties
</div>
)}
</Sidebar>
)}
</div>
</div>
);

Expand Down
18 changes: 10 additions & 8 deletions website-next/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ const LazyPlayground = React.lazy(() => import('../components/Playground'));

function ClientPlayground() {
const fallback = <div className={styles.playgroundFallback} />;
return <BrowserOnly fallback={fallback}>
{() => (
<Suspense fallback={fallback}>
<LazyPlayground />
</Suspense>
)}
</BrowserOnly>;
}

return (
<BrowserOnly fallback={fallback}>
{() => (
<Suspense fallback={fallback}>
<LazyPlayground />
</Suspense>
)}
</BrowserOnly>
);
}

export default function Home(): JSX.Element {
const {siteConfig} = useDocusaurusContext();
Expand Down

0 comments on commit 1acbd2e

Please sign in to comment.