|
1 | | -import { useRef, useState } from 'react'; |
| 1 | +import { useRef, useState, useEffect } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | import { styled } from '@mui/material/styles'; |
4 | 4 | import classNames from 'classnames'; |
@@ -44,6 +44,14 @@ export function WorkspaceAdd({ |
44 | 44 | const { t } = useTranslation(); |
45 | 45 | const [addResourcesOpen, setAddResourcesVisibility] = useState(false); |
46 | 46 | const ref = useRef(); |
| 47 | + const [refWidth, setRefWidth] = useState('100%'); |
| 48 | + |
| 49 | + /** */ |
| 50 | + const updateRefWidth = () => { |
| 51 | + if (ref.current) { |
| 52 | + setRefWidth(ref.current.offsetWidth); |
| 53 | + } |
| 54 | + }; |
47 | 55 |
|
48 | 56 | /** */ |
49 | 57 | const handleDrop = ({ manifestId, manifestJson }, props, monitor) => { |
@@ -84,9 +92,19 @@ export function WorkspaceAdd({ |
84 | 92 | addResource, catalog, setWorkspaceAddVisibility, t, ...rest, |
85 | 93 | }; |
86 | 94 |
|
| 95 | + useEffect(() => { |
| 96 | + window.addEventListener('resize', updateRefWidth); |
| 97 | + |
| 98 | + updateRefWidth(); |
| 99 | + |
| 100 | + return () => { |
| 101 | + window.removeEventListener('resize', updateRefWidth); |
| 102 | + }; |
| 103 | + }, []); |
| 104 | + |
87 | 105 | return ( |
88 | 106 | <IIIFDropTarget onDrop={handleDrop}> |
89 | | - <StyledWorkspaceAdd ref={ref} className={classNames(ns('workspace-add'))}> |
| 107 | + <StyledWorkspaceAdd className={classNames(ns('workspace-add'))} ref={ref}> |
90 | 108 | {catalog.length < 1 ? ( |
91 | 109 | <Grid |
92 | 110 | alignItems="center" |
@@ -138,10 +156,8 @@ export function WorkspaceAdd({ |
138 | 156 | sx={theme => ({ |
139 | 157 | '.MuiDrawer-paper': { |
140 | 158 | borderTop: '0', |
141 | | - left: '0', |
142 | | - [theme.breakpoints.up('sm')]: { |
143 | | - left: '65px', |
144 | | - }, |
| 159 | + left: 'unset', |
| 160 | + width: refWidth, |
145 | 161 | }, |
146 | 162 | ...(!addResourcesOpen && { |
147 | 163 | display: 'none', |
|
0 commit comments