Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push companion window styles up to settings #3834

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 19 additions & 73 deletions src/components/CompanionWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,14 @@ import { Rnd } from 'react-rnd';
import MiradorMenuButton from '../containers/MiradorMenuButton';
import ns from '../config/css-ns';

const StyledRnd = styled(Rnd)({
flexDirection: 'column',
minHeight: 0,
});

const StyledPositionButton = styled(MiradorMenuButton)({
marginLeft: -16,
order: -100,
width: 24,
});

const StyledCloseButton = styled(MiradorMenuButton)({
order: 4,
});

const StyledTitleControls = styled('div')({
alignItems: 'center',
display: 'flex',
flexFlow: 'row wrap',
minHeight: 48,
order: 3,
});
const Root = styled(Paper, { name: 'CompanionWindow', slot: 'root' })({});
const StyledToolbar = styled(Toolbar, { name: 'CompanionWindow', slot: 'toolbar' })({});
const StyledTitle = styled(Typography, { name: 'CompanionWindow', slot: 'title' })({});
const StyledTitleControls = styled('div', { name: 'CompanionWindow', slot: 'controls' })({});
const Contents = styled(Paper, { name: 'CompanionWindow', slot: 'contents' })({});
const StyledRnd = styled(Rnd, { name: 'CompanionWindow', slot: 'resize' })({});
const StyledPositionButton = styled(MiradorMenuButton, { name: 'CompanionWindow', slot: 'positionButton' })({});
const StyledCloseButton = styled(MiradorMenuButton, { name: 'CompanionWindow', slot: 'closeButton' })({});

/**
* CompanionWindow
Expand Down Expand Up @@ -111,27 +97,9 @@ export class CompanionWindow extends Component {
});

return (
<Paper
<Root
ownerState={this.props}
ref={innerRef}
sx={{
boxShadow: 'none',
boxSizing: 'border-box',
display: 'flex',
flexDirection: 'column',
minHeight: 0,
...(position === 'right' && {
borderLeft: '0.5px solid',
borderLeftColor: 'divider',
}),
...(position === 'left' && {
borderRight: '0.5px solid',
borderRightColor: 'divider',
}),
...(position === 'bottom' && {
borderTop: '0.5px solid',
borderTopColor: 'divider',
}),
}}
style={{
display: isDisplayed ? null : 'none',
order: position === 'left' ? -1 : null,
Expand All @@ -142,7 +110,8 @@ export class CompanionWindow extends Component {
aria-label={ariaLabel || title}
>
<StyledRnd
style={{ display: 'flex', position: 'relative' }}
style={{ display: 'inherit', position: 'inherit' }}
ownerState={this.props}
default={{
height: isBottom ? defaultSidebarPanelHeight : '100%',
width: isBottom ? 'auto' : defaultSidebarPanelWidth,
Expand All @@ -153,30 +122,12 @@ export class CompanionWindow extends Component {
minWidth={position === 'left' ? 235 : 100}
>

<Toolbar
sx={{
alignItems: 'flex-start',
bgcolor: 'shades.light',
flexWrap: 'wrap',
justifyContent: 'space-between',
minHeight: 'max-content',
paddingLeft: 2,
}}
<StyledToolbar
variant="dense"
className={[ns('companion-window-header'), size.width < 370 ? classes.small : null].join(' ')}
disableGutters
>
<Typography
variant="h3"
sx={{
alignSelf: 'center',
flexGrow: 1,
typography: 'subtitle1',
width: 160,
}}
>
{title}
</Typography>
<StyledTitle variant="h3">{title}</StyledTitle>
{
position === 'left'
? updateCompanionWindow
Expand Down Expand Up @@ -217,9 +168,8 @@ export class CompanionWindow extends Component {
{
titleControls && (
<StyledTitleControls
ownerState={{ position }}
sx={{
flexGrow: 1,
justifyContent: isBottom ? 'flex-end' : 'flex-start',
order: isBottom || size.width < 370 ? 'unset' : 1000,
}}
className={ns('companion-window-title-controls')}
Expand All @@ -228,19 +178,15 @@ export class CompanionWindow extends Component {
</StyledTitleControls>
)
}
</Toolbar>
<Paper
sx={{
overflowY: 'auto',
wordBreak: 'break-word',
}}
</StyledToolbar>
<Contents
className={ns('scrollto-scrollable')}
elevation={0}
>
{childrenWithAdditionalProps}
</Paper>
</Contents>
</StyledRnd>
</Paper>
</Root>
);
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,68 @@ export default {
},
]
},
CompanionWindow: {
styleOverrides: {
closeButton: {
order: 4,
},
contents: {
overflowY: 'auto',
wordBreak: 'break-word',
},
controls: ({ ownerState }) => ({
alignItems: 'center',
display: 'flex',
flexFlow: 'row wrap',
flexGrow: 1,
justifyContent: (ownerState?.position === 'bottom' || ownerState?.position === 'far-bottom') ? 'flex-end' : 'flex-start',
minHeight: 48,
order: 3
}),
positionButton: {
marginLeft: -16,
order: -100,
width: 24,
},
resize: ({ ownerState }) => ({
display: 'flex',
flexDirection: 'column',
minHeight: 50,
minWidth: (ownerState?.position === 'left') ? 235 : 100,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the minWidth here if it has been relocated?

minWidth={position === 'left' ? 235 : 100}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so? the react-rnd library wants to know that information too 🤷‍♂️

position: 'relative',
}),
root: ({ ownerState }) => ({
boxShadow: 'none',
boxSizing: 'border-box',
display: 'flex',
flexDirection: 'column',
minHeight: 0,
...(ownerState?.position === 'right' && {
borderLeft: '0.5px solid rgba(0, 0, 0, 0.125)'
}),
...(ownerState?.position === 'left' && {
borderRight: '0.5px solid rgba(0, 0, 0, 0.125)'
}),
...(ownerState?.position === 'bottom' && {
borderTop: '0.5px solid rgba(0, 0, 0, 0.125)'
}),
}),
title: ({ theme }) => ({
...theme.typography.subtitle1,
alignSelf: 'center',
flexGrow: 1,
width: 160
}),
toolbar: ({ theme }) => ({
alignItems: 'flex-start',
backgroundColor: theme.palette.shades.light,
flexWrap: 'wrap',
justifyContent: 'space-between',
minHeight: 'max-content',
paddingInlineStart: '1rem',
}),
},
},
CompanionWindowSection: {
styleOverrides: {
root: {
Expand Down