Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created August 21, 2019 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoisryosuke/5432424faf4923fd20bab70716de9f00 to your computer and use it in GitHub Desktop.
Save whoisryosuke/5432424faf4923fd20bab70716de9f00 to your computer and use it in GitHub Desktop.
Semantic UI React - Example - Hide Sidebar on mobile -- requires simple debounce
import React from "react"
import { Sidebar } from "semantic-ui-react"
import debounce from "../tools/debounce"
import DocSidebar from "./sidebar"
import "./layout.scss"
import "../../../dist/semantic.min.css"
class Layout extends React.Component {
state = { visible: true }
handleHideClick = () => this.setState({ visible: false })
handleShowClick = () => this.setState({ visible: true })
handleSidebarHide = () => this.setState({ visible: false })
componentDidMount() {
window.addEventListener("resize", debounce(this.resize.bind(this), 250))
this.resize()
}
resize() {
let currentHideNav = window.innerWidth <= 760
if (!currentHideNav !== this.state.visible) {
this.setState({ visible: !currentHideNav })
}
}
render() {
const { children, className } = this.props
const { visible } = this.state
return (
<>
<Sidebar.Pushable as="section">
<DocSidebar
visible={visible}
/>
<Sidebar.Pusher as="main" className={className}>
<div className="ui text container">{children}</div>
</Sidebar.Pusher>
</Sidebar.Pushable>
</>
)
}
}
export default Layout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment