split hooks

This commit is contained in:
SrGooglo 2023-06-26 23:31:56 +00:00
parent 1819edb154
commit 17850b8b40
4 changed files with 30 additions and 30 deletions

View File

@ -2,32 +2,11 @@ import React from "react"
import classnames from "classnames" import classnames from "classnames"
import { Motion, spring } from "react-motion" import { Motion, spring } from "react-motion"
import useLayoutInterface from "hooks/useLayoutInterface"
import useDefaultVisibility from "hooks/useDefaultVisibility"
import "./index.less" import "./index.less"
const useLayoutInterface = (namespace, ctx) => {
React.useEffect(() => {
if (app.layout["namespace"] === "object") {
throw new Error(`Layout namespace [${namespace}] already exists`)
}
app.layout[namespace] = ctx
}, [])
return app.layout[namespace]
}
const useDefaultVisibility = (defaultValue) => {
const [visible, setVisible] = React.useState(defaultValue ?? false)
React.useEffect(() => {
setTimeout(() => {
setVisible(true)
}, 10)
}, [])
return [visible, setVisible]
}
export const UseTopBar = (props) => { export const UseTopBar = (props) => {
app.layout.top_bar.render( app.layout.top_bar.render(
<React.Fragment> <React.Fragment>
@ -124,8 +103,6 @@ export default (props) => {
const heightValue = visible ? Number(app.cores.style.defaultVar("top-bar-height").replace("px", "")) : 0 const heightValue = visible ? Number(app.cores.style.defaultVar("top-bar-height").replace("px", "")) : 0
console.log(render)
return <Motion style={{ return <Motion style={{
y: spring(visible ? 0 : 300,), y: spring(visible ? 0 : 300,),
height: spring(heightValue,), height: spring(heightValue,),

View File

@ -8,9 +8,6 @@
width: 100%; width: 100%;
height: calc(@top_bar_height + @top_bar_padding * 2); height: calc(@top_bar_height + @top_bar_padding * 2);
min-height: calc(@top_bar_height + @top_bar_padding * 2); min-height: calc(@top_bar_height + @top_bar_padding * 2);
//height: 0;
//min-height: 0;
} }
.top-bar_wrapper { .top-bar_wrapper {
@ -44,7 +41,7 @@
padding: 10px; padding: 10px;
box-shadow: @card-shadow-top; box-shadow: @card-shadow;
transition: all 150ms ease-in-out; transition: all 150ms ease-in-out;

View File

@ -0,0 +1,13 @@
import React from "react"
export default (defaultValue) => {
const [visible, setVisible] = React.useState(defaultValue ?? false)
React.useEffect(() => {
setTimeout(() => {
setVisible(true)
}, 10)
}, [])
return [visible, setVisible]
}

View File

@ -0,0 +1,13 @@
import React from "react"
export default (namespace, ctx) => {
React.useEffect(() => {
if (app.layout["namespace"] === "object") {
throw new Error(`Layout namespace [${namespace}] already exists`)
}
app.layout[namespace] = ctx
}, [])
return app.layout[namespace]
}