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

Add a sidebar toggle into the toolbar and close button into sidebar #3912

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8a0d34f
Add a sidebar toggle into the toolbar and close button into sidebar
JeffersonBledsoe Nov 17, 2022
9c4477c
prettier
JeffersonBledsoe Nov 17, 2022
3cb6068
Use aria-label instead of sr-only and add intl
JeffersonBledsoe Nov 17, 2022
82b8653
Remove unused state
JeffersonBledsoe Nov 17, 2022
f5cd2fb
Fix sidebar being closed by default
JeffersonBledsoe Nov 17, 2022
48e614a
Update snapshot
JeffersonBledsoe Nov 17, 2022
705f1a2
Close sidebar button styling
JeffersonBledsoe Nov 17, 2022
786be3a
Fix opening & closing (but the button moves now)
JeffersonBledsoe Nov 17, 2022
bf2b582
Merge branch 'master' into settings-icon-in-toolbar
JeffersonBledsoe Dec 16, 2022
146f4f1
Merge branch 'main' into settings-icon-in-toolbar
JeffersonBledsoe Jul 26, 2024
f34e4ee
Remove unuseds
JeffersonBledsoe Jul 26, 2024
8e17a6c
Restore sidebar logic from bad merge
JeffersonBledsoe Jul 26, 2024
1b5f937
Fix button moving about
JeffersonBledsoe Jul 26, 2024
001a909
i18n
JeffersonBledsoe Jul 26, 2024
2805348
lin
JeffersonBledsoe Jul 26, 2024
9e6325f
changelog
JeffersonBledsoe Jul 26, 2024
ca2a6e1
no message
JeffersonBledsoe Sep 24, 2024
350f281
Improve relationship between button and sidebar
JeffersonBledsoe Sep 24, 2024
eef0603
i18n
JeffersonBledsoe Sep 24, 2024
9971de6
Fix random auto lint
JeffersonBledsoe Sep 24, 2024
f94b0f2
.
JeffersonBledsoe Sep 24, 2024
ac16a6f
Minor adjustments to close button sizing
JeffersonBledsoe Sep 25, 2024
8bfcb66
Move changes behind flags
JeffersonBledsoe Sep 25, 2024
286677b
Merge branch 'main' into settings-icon-in-toolbar
ichim-david Oct 29, 2024
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
5 changes: 4 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ export {
} from '@plone/volto/actions/workflow/workflow';
export { getQuerystring } from '@plone/volto/actions/querystring/querystring';
export { getQueryStringResults } from '@plone/volto/actions/querystringsearch/querystringsearch';
export { setSidebarTab } from '@plone/volto/actions/sidebar/sidebar';
export {
setSidebarExpanded,
setSidebarTab,
} from '@plone/volto/actions/sidebar/sidebar';
export {
deleteLinkTranslation,
getTranslationLocator,
Expand Down
12 changes: 11 additions & 1 deletion src/actions/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* @module actions/sidebar/sidebar
*/

import { SET_SIDEBAR_TAB } from '@plone/volto/constants/ActionTypes';
import {
SET_SIDEBAR_EXPANDED,
SET_SIDEBAR_TAB,
} from '@plone/volto/constants/ActionTypes';

/**
* Set sidebar tab function.
Expand All @@ -17,3 +20,10 @@ export function setSidebarTab(index) {
index,
};
}

export function setSidebarExpanded(isExpanded) {
return {
type: SET_SIDEBAR_EXPANDED,
isExpanded,
};
}
3 changes: 2 additions & 1 deletion src/components/manage/Add/Add.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import qs from 'query-string';
import { toast } from 'react-toastify';

import { createContent, getSchema, changeLanguage } from '@plone/volto/actions';
import { changeLanguage, createContent, getSchema } from '@plone/volto/actions';
import {
Form,
Icon,
Expand All @@ -42,6 +42,7 @@

import saveSVG from '@plone/volto/icons/save.svg';
import clearSVG from '@plone/volto/icons/clear.svg';
import configSVG from '@plone/volto/icons/configuration.svg';

Check warning on line 45 in src/components/manage/Add/Add.jsx

View workflow job for this annotation

GitHub Actions / ESlint (16.x)

'configSVG' is defined but never used

const messages = defineMessages({
add: {
Expand Down
2 changes: 2 additions & 0 deletions src/components/manage/Edit/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import qs from 'query-string';
import { find } from 'lodash';
import { toast } from 'react-toastify';
import cx from 'classnames';

Check warning on line 18 in src/components/manage/Edit/Edit.jsx

View workflow job for this annotation

GitHub Actions / ESlint (16.x)

'cx' is defined but never used

import {
Forbidden,
Expand All @@ -40,6 +41,7 @@

import saveSVG from '@plone/volto/icons/save.svg';
import clearSVG from '@plone/volto/icons/clear.svg';
import configSVG from '@plone/volto/icons/configuration.svg';

Check warning on line 44 in src/components/manage/Edit/Edit.jsx

View workflow job for this annotation

GitHub Actions / ESlint (16.x)

'configSVG' is defined but never used

import config from '@plone/volto/registry';

Expand Down
2 changes: 2 additions & 0 deletions src/components/manage/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import { v4 as uuid } from 'uuid';
import { toast } from 'react-toastify';
import { BlocksToolbar, UndoToolbar } from '@plone/volto/components';
import { SidebarToggleButton } from '@plone/volto/components/manage/Form/SidebarToggleButton';
import { setSidebarTab } from '@plone/volto/actions';
import { compose } from 'redux';
import config from '@plone/volto/registry';
Expand Down Expand Up @@ -560,6 +561,7 @@ class Form extends Component {
}
onSelectBlock={this.onSelectBlock}
/>
<SidebarToggleButton />
<UndoToolbar
state={{
formData: this.state.formData,
Expand Down
59 changes: 59 additions & 0 deletions src/components/manage/Form/SidebarToggleButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import cx from 'classnames';
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useDispatch, useSelector } from 'react-redux';

import { setSidebarExpanded } from '@plone/volto/actions';
import { Icon } from '@plone/volto/components';
import { Plug } from '@plone/volto/components/manage/Pluggable';
import configSVG from '@plone/volto/icons/configuration.svg';
import { Button } from 'semantic-ui-react';

const messages = defineMessages({
shrinkSidebar: {
id: 'Shrink sidebar',
defaultMessage: 'Shrink sidebar',
},
expandSidebar: {
id: 'Expand sidebar',
defaultMessage: 'Expand sidebar',
},
});

export const SidebarToggleButton = () => {
const intl = useIntl();
const dispatch = useDispatch();
const sidebarExpanded = useSelector(
(state) => state.sidebar.expanded ?? true,
);

return (
<Plug
pluggable="main.toolbar.bottom"
id="sidebar-toggle-button"
dependencies={[sidebarExpanded]}
>
<Button
className={cx('settings', {
'sidebar-expanded': sidebarExpanded,
})}
// TODO: The below should set `aria-pressed`, but it doesn't for some reason :(
active={sidebarExpanded}
aria-label={
sidebarExpanded
? intl.formatMessage(messages.shrinkSidebar)
: intl.formatMessage(messages.expandSidebar)
}
onClick={() => {
dispatch(setSidebarExpanded(!sidebarExpanded));
}}
>
<div aria-hidden="true" focusable="false">
<Icon name={configSVG} />
</div>
</Button>
</Plug>
);
};

export default SidebarToggleButton;
38 changes: 26 additions & 12 deletions src/components/manage/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import { BodyClass, getCookieOptions } from '@plone/volto/helpers';
import { Icon } from '@plone/volto/components';
import forbiddenSVG from '@plone/volto/icons/forbidden.svg';
import { setSidebarTab } from '@plone/volto/actions';
import { setSidebarExpanded, setSidebarTab } from '@plone/volto/actions';
import expandSVG from '@plone/volto/icons/left-key.svg';
import clearSVG from '@plone/volto/icons/clear.svg';
import collapseSVG from '@plone/volto/icons/right-key.svg';

const messages = defineMessages({
Expand Down Expand Up @@ -77,30 +78,35 @@
*/
constructor(props) {
super(props);
const { cookies } = props;

Check warning on line 81 in src/components/manage/Sidebar/Sidebar.jsx

View workflow job for this annotation

GitHub Actions / ESlint (16.x)

'cookies' is assigned a value but never used
this.onToggleExpanded = this.onToggleExpanded.bind(this);
this.onToggleFullSize = this.onToggleFullSize.bind(this);
this.onTabChange = this.onTabChange.bind(this);
this.state = {
expanded: cookies.get('sidebar_expanded') !== 'false',
size: 0,
showFull: true,
showFullToolbarExpanded: true,
};
}

componentDidUpdate(prevProps) {
if (this.props.sidebarExpanded !== prevProps.sidebarExpanded) {
const { cookies } = this.props;
cookies.set(
'sidebar_expanded',
this.props.sidebarExpanded,
getCookieOptions(),
);
}
}

/**
* On toggle expanded handler
* also reset sidebar since this has mimized it
* @method onToggleExpanded
* @returns {undefined}
*/
onToggleExpanded() {
const { cookies } = this.props;
cookies.set('sidebar_expanded', !this.state.expanded, getCookieOptions());
this.setState({
expanded: !this.state.expanded,
});
this.props.setSidebarExpanded(!this.props.sidebarExpanded);
this.resetFullSizeSidebar();
}

Expand All @@ -109,7 +115,7 @@
* Reset state
*/
resetFullSizeSidebar() {
if (!this.state.expanded) {
if (!this.props.sidebarExpanded) {
const currentResizer = document.querySelector('#sidebar');
const sidebarContainer = currentResizer.getElementsByClassName(
'sidebar-container',
Expand Down Expand Up @@ -168,7 +174,7 @@
* @returns {string} Markup for the component.
*/
render() {
const { expanded } = this.state;
const expanded = this.props.sidebarExpanded ?? true;

return (
<Fragment>
Expand Down Expand Up @@ -202,6 +208,13 @@
name={this.state.showFull ? expandSVG : collapseSVG}
/>
</Button>
<Button
className="close-sidenav-btn"
aria-label={this.props.intl.formatMessage(messages.shrinkSidebar)}
onClick={this.onToggleExpanded}
>
<Icon name={clearSVG} />
</Button>
<Tab
menu={{
secondary: true,
Expand Down Expand Up @@ -262,7 +275,7 @@
].filter((tab) => tab)}
/>
</div>
<div className={this.state.expanded ? 'pusher expanded' : 'pusher'} />
<div className={expanded ? 'pusher expanded' : 'pusher'} />
</Fragment>
);
}
Expand All @@ -274,9 +287,10 @@
connect(
(state) => ({
tab: state.sidebar.tab,
sidebarExpanded: state.sidebar.expanded,
toolbarExpanded: state.toolbar.expanded,
type: state.schema?.schema?.title,
}),
{ setSidebarTab },
{ setSidebarTab, setSidebarExpanded },
),
)(Sidebar);
24 changes: 24 additions & 0 deletions src/components/manage/Sidebar/__snapshots__/Sidebar.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ Array [
xmlns=""
/>
</button>
<button
aria-label="Shrink sidebar"
className="ui button close-sidenav-btn"
onClick={[Function]}
>
<svg
className="icon"
dangerouslySetInnerHTML={
Object {
"__html": undefined,
}
}
onClick={null}
style={
Object {
"fill": "currentColor",
"height": "36px",
"width": "auto",
}
}
viewBox=""
xmlns=""
/>
</button>
<div
className="tabs-wrapper"
>
Expand Down
1 change: 1 addition & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const RESET_PASSWORD = 'RESET_PASSWORD';
export const REVERT_HISTORY = 'REVERT_HISTORY';
export const REVERT_TRANSACTIONS = 'REVERT_TRANSACTIONS';
export const SEARCH_CONTENT = 'SEARCH_CONTENT';
export const SET_SIDEBAR_EXPANDED = 'SET_SIDEBAR_EXPANDED';
export const SET_SIDEBAR_TAB = 'SET_SIDEBAR_TAB';
export const TRANSITION_WORKFLOW = 'TRANSITION_WORKFLOW';
export const UNINSTALL_ADDON = 'UNINSTALL_ADDON';
Expand Down
10 changes: 9 additions & 1 deletion src/reducers/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* @module reducers/sidebar/sidebar
*/

import { SET_SIDEBAR_TAB } from '@plone/volto/constants/ActionTypes';
import {
SET_SIDEBAR_EXPANDED,
SET_SIDEBAR_TAB,
} from '@plone/volto/constants/ActionTypes';

const initialState = {
tab: 0,
Expand All @@ -23,6 +26,11 @@ export default function sidebar(state = initialState, action = {}) {
...state,
tab: action.index,
};
case SET_SIDEBAR_EXPANDED:
return {
...state,
expanded: action.isExpanded,
};
default:
return state;
}
Expand Down
18 changes: 18 additions & 0 deletions theme/themes/pastanaga/extras/sidebar.less
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@
color: #bac5c7;
}

.ui.button.close-sidenav-btn {
position: absolute;
top: 0;
right: 0;
padding: 12px;
background: transparent;
margin: 0;

& svg {
height: @fullSizeIcon;
// Below attributes needed to stop the excess margin
width: 100% !important;
vertical-align: top !important;
margin: 0 !important;
}
}


.sidebar-container {
position: fixed;
z-index: 150;
Expand Down
Loading