Skip to content

Commit

Permalink
Merge branch 'main' into acre-points-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska authored Oct 18, 2024
2 parents 1df501b + fb2fbac commit 2be0e39
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
1 change: 0 additions & 1 deletion dapp/src/components/ModalRoot/withBaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function withBaseModal<T extends BaseModalProps>(
<Modal
isOpen
onClose={handleCloseModal}
scrollBehavior="inside"
closeOnOverlayClick={false}
size={MODAL_BASE_SIZE}
closeOnEsc={closeOnEsc}
Expand Down
17 changes: 13 additions & 4 deletions dapp/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ComponentProps } from "react"
import React, { ComponentProps, useEffect } from "react"
import {
Box,
Card,
Expand All @@ -7,7 +7,7 @@ import {
useMultiStyleConfig,
Image,
} from "@chakra-ui/react"
import { useSidebar } from "#/hooks"
import { useScrollbarVisibility, useSidebar } from "#/hooks"
import {
EXTERNAL_HREF,
REWARD_BOOST,
Expand All @@ -18,6 +18,8 @@ import { rewardsBoostArrowImage } from "#/assets/images/benefits"
import ButtonLink from "./shared/ButtonLink"
import { TextSm } from "./shared/Typography"

const CHAKRA_MODAL_CONTAINER_SELECTOR = ".chakra-modal__content-container"

const BUTTONS: Partial<ComponentProps<typeof ButtonLink>>[] = [
{
children: "Docs",
Expand Down Expand Up @@ -52,16 +54,23 @@ const BENEFITS = [

export default function Sidebar() {
const { isOpen } = useSidebar()
// TODO Bring back when dApp embedded docs are ready
// const { onOpen: openDocsDrawer } = useDocsDrawer()
const { isVisible, scrollbarWidth, refreshState } = useScrollbarVisibility(
CHAKRA_MODAL_CONTAINER_SELECTOR,
)
const styles = useMultiStyleConfig("Sidebar")

useEffect(() => {
if (!isOpen) return
refreshState()
}, [isOpen, refreshState])

return (
<Box
as="aside"
mt="header_height"
w={isOpen ? "sidebar_width" : "0"}
__css={styles.sidebarContainer}
mr={isVisible ? scrollbarWidth : 0}
>
<Box __css={styles.sidebar}>
{featureFlags.GAMIFICATION_ENABLED && (
Expand Down
1 change: 1 addition & 0 deletions dapp/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export { default as useReferral } from "./useReferral"
export { default as useMats } from "./useMats"
export { default as useAcrePoints } from "./useAcrePoints"
export { default as useSignMessageAndCreateSession } from "./useSignMessageAndCreateSession"
export { default as useScrollbarVisibility } from "./useScrollbarVisibility"
32 changes: 32 additions & 0 deletions dapp/src/hooks/useScrollbarVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useCallback, useEffect, useState } from "react"

const SCROLLBAR_WIDTH = `${window.innerWidth - document.body.offsetWidth}px`

function isScrollbarVisible(selector: string) {
const element = document.querySelector(selector)

if (!element) return false

return element?.scrollHeight > element?.clientHeight
}

export default function useScrollbarVisibility(selector: string) {
const [isVisible, setIsVisible] = useState(false)

useEffect(() => {
const handleResize = () => {
setIsVisible(isScrollbarVisible(selector))
}
window.addEventListener("resize", handleResize)

return () => {
window.removeEventListener("resize", handleResize)
}
}, [selector])

const refreshState = useCallback(() => {
setIsVisible(isScrollbarVisible(selector))
}, [selector])

return { isVisible, scrollbarWidth: SCROLLBAR_WIDTH, refreshState }
}
7 changes: 2 additions & 5 deletions dapp/src/theme/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import { modalAnatomy as parts } from "@chakra-ui/anatomy"
import { createMultiStyleConfigHelpers, defineStyle } from "@chakra-ui/react"

const baseStyleContainer = defineStyle({
height: "calc(100vh - var(--chakra-space-modal_shift))",
top: "var(--chakra-space-modal_shift)",
overflow: "unset",
px: 8,
})

const baseStyleDialog = defineStyle({
marginTop: "var(--chakra-space-modal_shift)",
marginBottom: 8,
borderWidth: "2px",
boxShadow: "none",
borderColor: "white",
borderRadius: "xl",
bg: "gold.100",
mt: 0,
mb: "auto",
})

const baseCloseButton = defineStyle({
Expand Down

0 comments on commit 2be0e39

Please sign in to comment.