Skip to content

Commit

Permalink
Add a sidebar for docs drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Dec 6, 2023
1 parent d9d70ae commit 0df5493
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 4 deletions.
9 changes: 6 additions & 3 deletions dapp/src/DApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LedgerWalletAPIProvider,
StakingFlowProvider,
WalletContextProvider,
DocsDrawerContextProvider,
} from "./contexts"
import Header from "./components/Header"
import Overview from "./components/Overview"
Expand All @@ -28,9 +29,11 @@ function DAppProviders() {
<LedgerWalletAPIProvider>
<WalletContextProvider>
<StakingFlowProvider>
<ChakraProvider theme={theme}>
<DApp />
</ChakraProvider>
<DocsDrawerContextProvider>
<ChakraProvider theme={theme}>
<DApp />
</ChakraProvider>
</DocsDrawerContextProvider>
</StakingFlowProvider>
</WalletContextProvider>
</LedgerWalletAPIProvider>
Expand Down
27 changes: 27 additions & 0 deletions dapp/src/components/DocsDrawer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react"
import {
Drawer,
DrawerBody,
DrawerContent,
Text,
DrawerOverlay,
useColorModeValue,
} from "@chakra-ui/react"
import { useDocsDrawerContext } from "../../hooks"

export default function DocsDrawer() {
const { isOpen, onClose } = useDocsDrawerContext()

return (
<Drawer size="lg" placement="right" isOpen={isOpen} onClose={onClose}>
<DrawerOverlay />
{/* TODO: Set the correct background color */}
<DrawerContent bg={useColorModeValue("grey.100", "grey.100")}>
<DrawerBody>
{/* TODO: Add a documentation */}
<Text>Documentation</Text>
</DrawerBody>
</DrawerContent>
</Drawer>
)
}
31 changes: 31 additions & 0 deletions dapp/src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react"
import { Box, Button, useColorModeValue } from "@chakra-ui/react"
import { useDocsDrawerContext, useStakingFlowContext } from "../../hooks"
import DocsDrawer from "../DocsDrawer"

export default function Sidebar({ marginTop }: { marginTop?: number }) {
const { modalType } = useStakingFlowContext()
const { onOpen } = useDocsDrawerContext()

return (
<>
<Box
top={0}
right={0}
h="100vh"
position="fixed"
width={modalType ? 80 : 0}
height="100vh"
transition="width 0.3s"
zIndex="sidebar"
// TODO: Set the correct background color
bg={useColorModeValue("white", "white")}
mt={marginTop}
>
{/* TODO: Add a correct content for the sidebar */}
<Button onClick={onOpen}>Open a documentation</Button>
</Box>
<DocsDrawer />
</>
)
}
2 changes: 2 additions & 0 deletions dapp/src/components/Staking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import StakingOverviewModal from "../Modals/StakingOverviewModal"
import { useStakingFlowContext, useWalletContext } from "../../hooks"
import ModalOverlay from "../ModalOverlay"
import { HEADER_HEIGHT } from "../Header"
import Sidebar from "../Sidebar"

function Modal() {
const { modalType } = useStakingFlowContext()
Expand All @@ -23,6 +24,7 @@ export default function Staking() {
{/* The user has several modals in a flow.
Let's use our own modal overlay to prevent the background flickering effect. */}
<ModalOverlay marginTop={HEADER_HEIGHT} />
<Sidebar marginTop={HEADER_HEIGHT} />
</>
)
}
44 changes: 44 additions & 0 deletions dapp/src/contexts/DocsDrawerContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { createContext, useCallback, useMemo, useState } from "react"

type DocsDrawerContextValue = {
isOpen: boolean
onOpen: () => void
onClose: () => void
}

export const DocsDrawerContext = createContext<DocsDrawerContextValue>({
isOpen: false,
onOpen: () => {},
onClose: () => {},
})

export function DocsDrawerContextProvider({
children,
}: {
children: React.ReactNode
}): React.ReactElement {
const [isOpen, setIsOpen] = useState(false)

const onOpen = useCallback(() => {
setIsOpen(true)
}, [])

const onClose = useCallback(() => {
setIsOpen(false)
}, [])

const contextValue: DocsDrawerContextValue = useMemo<DocsDrawerContextValue>(
() => ({
isOpen,
onOpen,
onClose,
}),
[isOpen, onClose, onOpen],
)

return (
<DocsDrawerContext.Provider value={contextValue}>
{children}
</DocsDrawerContext.Provider>
)
}
1 change: 1 addition & 0 deletions dapp/src/contexts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./WalletContext"
export * from "./LedgerWalletAPIProvider"
export * from "./StakingFlowContext"
export * from "./DocsDrawerContext"
1 change: 1 addition & 0 deletions dapp/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./useRequestBitcoinAccount"
export * from "./useRequestEthereumAccount"
export * from "./useWalletContext"
export * from "./useStakingFlowContext"
export * from "./useDocsDrawerContext"
14 changes: 14 additions & 0 deletions dapp/src/hooks/useDocsDrawerContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useContext } from "react"
import { DocsDrawerContext } from "../contexts"

export function useDocsDrawerContext() {
const context = useContext(DocsDrawerContext)

if (!context) {
throw new Error(
"DocsDrawerContext used outside of DocsDrawerContext component",
)
}

return context
}
11 changes: 11 additions & 0 deletions dapp/src/theme/Drawer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ComponentSingleStyleConfig } from "@chakra-ui/react"

const Drawer: ComponentSingleStyleConfig = {
baseStyle: {
dialogContainer: {
zIndex: "drawer",
},
},
}

export default Drawer
5 changes: 4 additions & 1 deletion dapp/src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { StyleFunctionProps, Tooltip, extendTheme } from "@chakra-ui/react"
import { mode } from "@chakra-ui/theme-tools"
import Button from "./Button"
import Switch from "./Switch"
import { colors } from "./utils"
import { colors, zIndices } from "./utils"
import Drawer from "./Drawer"

// Currently, there is no possibility to set all tooltips with hasArrow by defaultProps.
// Let's override the defaultProps as follows.
Tooltip.defaultProps = { ...Tooltip.defaultProps, hasArrow: true }

const defaultTheme = {
colors,
zIndices,
styles: {
global: (props: StyleFunctionProps) => ({
body: {
Expand All @@ -21,6 +23,7 @@ const defaultTheme = {
components: {
Button,
Switch,
Drawer,
},
}

Expand Down
1 change: 1 addition & 0 deletions dapp/src/theme/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./colors"
export * from "./zIndices"
17 changes: 17 additions & 0 deletions dapp/src/theme/utils/zIndices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const zIndices = {
hide: -1,
auto: "auto",
base: 0,
docked: 10,
dropdown: 1000,
sticky: 1100,
banner: 1200,
overlay: 1300,
modal: 1400,
sidebar: 1450,
drawer: 1470,
popover: 1500,
skipLink: 1600,
toast: 1700,
tooltip: 1800,
}

0 comments on commit 0df5493

Please sign in to comment.