11/* eslint-disable react/require-default-props */
22import { Children , cloneElement , forwardRef } from 'react' ;
3+ import { useSelector } from 'react-redux' ;
34import PropTypes from 'prop-types' ;
45import { styled } from '@mui/material/styles' ;
56import CloseIcon from '@mui/icons-material/CloseSharp' ;
@@ -14,6 +15,8 @@ import { useElementSize } from '@custom-react-hooks/use-element-size';
1415import mergeRefs from 'merge-refs' ;
1516import MiradorMenuButton from '../containers/MiradorMenuButton' ;
1617import ns from '../config/css-ns' ;
18+ import LocaleContext from '../contexts/LocaleContext' ;
19+ import { getCompanionWindowLocale } from '../state/selectors/companionWindows' ;
1720
1821const Root = styled ( Paper , { name : 'CompanionWindow' , slot : 'root' } ) ( { } ) ;
1922const StyledToolbar = styled ( Toolbar , { name : 'CompanionWindow' , slot : 'toolbar' } ) ( { } ) ;
@@ -29,12 +32,13 @@ const StyledCloseButton = styled(MiradorMenuButton, { name: 'CompanionWindow', s
2932 */
3033export const CompanionWindow = forwardRef ( ( props , innerRef ) => {
3134 const {
32- ariaLabel = undefined , classes = { } , direction, paperClassName = '' , onCloseClick = ( ) => { } , updateCompanionWindow = undefined , isDisplayed = false ,
35+ ariaLabel = undefined , classes = { } , direction, id , paperClassName = '' , onCloseClick = ( ) => { } , updateCompanionWindow = undefined , isDisplayed = false ,
3336 position = null , title = null , children = undefined , titleControls = null ,
3437 defaultSidebarPanelWidth = 235 , defaultSidebarPanelHeight = 201 ,
3538 } = props ;
3639 const [ sizeRef , size ] = useElementSize ( ) ;
3740 const { t } = useTranslation ( ) ;
41+ const locale = useSelector ( state => getCompanionWindowLocale ( state , { companionWindowId : id } ) , [ id ] ) ;
3842
3943 /** */
4044 const openInNewStyle = direction === 'rtl' ? { transform : 'scale(-1, 1)' } : { } ;
@@ -105,83 +109,85 @@ export const CompanionWindow = forwardRef((props, innerRef) => {
105109 component = "aside"
106110 aria-label = { ariaLabel || title }
107111 >
108- < StyledRnd
109- style = { { display : 'inherit' , position : 'inherit' } }
110- ownerState = { props }
111- default = { {
112- height : isBottom ? defaultSidebarPanelHeight : '100%' ,
113- width : isBottom ? 'auto' : defaultSidebarPanelWidth ,
114- } }
115- disableDragging
116- enableResizing = { resizeHandles }
117- minHeight = { 50 }
118- minWidth = { position === 'left' ? 235 : 100 }
119- >
120-
121- < StyledToolbar
122- variant = "dense"
123- className = { [ ns ( 'companion-window-header' ) , size . width < 370 ? 'test' : null ] . join ( ' ' ) }
124- disableGutters
112+ < LocaleContext . Provider value = { locale } >
113+ < StyledRnd
114+ style = { { display : 'inherit' , position : 'inherit' } }
115+ ownerState = { props }
116+ default = { {
117+ height : isBottom ? defaultSidebarPanelHeight : '100%' ,
118+ width : isBottom ? 'auto' : defaultSidebarPanelWidth ,
119+ } }
120+ disableDragging
121+ enableResizing = { resizeHandles }
122+ minHeight = { 50 }
123+ minWidth = { position === 'left' ? 235 : 100 }
125124 >
126- < StyledTitle variant = "h3" > { title } </ StyledTitle >
127- {
128- position === 'left'
129- ? updateCompanionWindow
130- && (
131- < MiradorMenuButton
132- aria-label = { t ( 'openInCompanionWindow' ) }
133- onClick = { ( ) => { updateCompanionWindow ( { position : 'right' } ) ; } }
134- >
135- < OpenInNewIcon style = { openInNewStyle } />
136- </ MiradorMenuButton >
137- )
138- : (
139- < >
140- {
141- updateCompanionWindow && (
142- < StyledPositionButton
143- aria-label = { position === 'bottom' ? t ( 'moveCompanionWindowToRight' ) : t ( 'moveCompanionWindowToBottom' ) }
144- onClick = { ( ) => { updateCompanionWindow ( { position : position === 'bottom' ? 'right' : 'bottom' } ) ; } }
145- >
146- < MoveIcon />
147- </ StyledPositionButton >
148- )
149- }
150- < StyledCloseButton
151- sx = { {
152- ...( size . width < 370 && {
153- order : 'unset' ,
154- } ) ,
155- } }
156- aria-label = { t ( 'closeCompanionWindow' ) }
157- onClick = { onCloseClick }
125+
126+ < StyledToolbar
127+ variant = "dense"
128+ className = { [ ns ( 'companion-window-header' ) , size . width < 370 ? 'test' : null ] . join ( ' ' ) }
129+ disableGutters
130+ >
131+ < StyledTitle variant = "h3" > { title } </ StyledTitle >
132+ {
133+ position === 'left'
134+ ? updateCompanionWindow
135+ && (
136+ < MiradorMenuButton
137+ aria-label = { t ( 'openInCompanionWindow' ) }
138+ onClick = { ( ) => { updateCompanionWindow ( { position : 'right' } ) ; } }
158139 >
159- < CloseIcon />
160- </ StyledCloseButton >
161- </ >
140+ < OpenInNewIcon style = { openInNewStyle } />
141+ </ MiradorMenuButton >
142+ )
143+ : (
144+ < >
145+ {
146+ updateCompanionWindow && (
147+ < StyledPositionButton
148+ aria-label = { position === 'bottom' ? t ( 'moveCompanionWindowToRight' ) : t ( 'moveCompanionWindowToBottom' ) }
149+ onClick = { ( ) => { updateCompanionWindow ( { position : position === 'bottom' ? 'right' : 'bottom' } ) ; } }
150+ >
151+ < MoveIcon />
152+ </ StyledPositionButton >
153+ )
154+ }
155+ < StyledCloseButton
156+ sx = { {
157+ ...( size . width < 370 && {
158+ order : 'unset' ,
159+ } ) ,
160+ } }
161+ aria-label = { t ( 'closeCompanionWindow' ) }
162+ onClick = { onCloseClick }
163+ >
164+ < CloseIcon />
165+ </ StyledCloseButton >
166+ </ >
167+ )
168+ }
169+ {
170+ titleControls && (
171+ < StyledTitleControls
172+ ownerState = { { position } }
173+ sx = { {
174+ order : isBottom || size . width < 370 ? 'unset' : 1000 ,
175+ } }
176+ className = { ns ( 'companion-window-title-controls' ) }
177+ >
178+ { titleControls }
179+ </ StyledTitleControls >
162180 )
163- }
164- {
165- titleControls && (
166- < StyledTitleControls
167- ownerState = { { position } }
168- sx = { {
169- order : isBottom || size . width < 370 ? 'unset' : 1000 ,
170- } }
171- className = { ns ( 'companion-window-title-controls' ) }
172- >
173- { titleControls }
174- </ StyledTitleControls >
175- )
176- }
177- </ StyledToolbar >
178- < Contents
179- className = { ns ( 'scrollto-scrollable' ) }
180- elevation = { 0 }
181- >
182- { childrenWithAdditionalProps }
183- </ Contents >
184- </ StyledRnd >
181+ }
182+ </ StyledToolbar >
183+ < Contents
184+ className = { ns ( 'scrollto-scrollable' ) }
185+ elevation = { 0 }
186+ >
187+ { childrenWithAdditionalProps }
188+ </ Contents >
189+ </ StyledRnd >
190+ </ LocaleContext . Provider >
185191 </ Root >
186192 ) ;
187193} ) ;
@@ -193,6 +199,7 @@ CompanionWindow.propTypes = {
193199 defaultSidebarPanelHeight : PropTypes . number ,
194200 defaultSidebarPanelWidth : PropTypes . number ,
195201 direction : PropTypes . string . isRequired ,
202+ id : PropTypes . string . isRequired ,
196203 isDisplayed : PropTypes . bool ,
197204 onCloseClick : PropTypes . func ,
198205 paperClassName : PropTypes . string ,
0 commit comments