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 all 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: 5 additions & 0 deletions packages/volto/locales/ca/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,11 @@ msgstr "Redueix la barra lateral"
msgid "Shrink toolbar"
msgstr "Redueix la barra d'eines"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/de/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,11 @@ msgstr "Sidebar verkleinern"
msgid "Shrink toolbar"
msgstr "Toolbar verkleinern"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,11 @@ msgstr ""
msgid "Shrink toolbar"
msgstr ""

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/es/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,11 @@ msgstr "Contraer barra lateral"
msgid "Shrink toolbar"
msgstr "Contraer barra de herramientas"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/eu/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,11 @@ msgstr "Txikitu alboko barra"
msgid "Shrink toolbar"
msgstr "Txikitu tresna-barra"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/fi/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,11 @@ msgstr "Kutista sivupalkki"
msgid "Shrink toolbar"
msgstr "Kutista työkalupalkki"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/fr/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,11 @@ msgstr "Rétrécir la barre latérale"
msgid "Shrink toolbar"
msgstr "Réduire la barre d'outils"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/hi/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,11 @@ msgstr "साइडबार को छोटा करें"
msgid "Shrink toolbar"
msgstr "टूलबार को छोटा करें"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/it/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,11 @@ msgstr "Riduci la sidebar"
msgid "Shrink toolbar"
msgstr "Riduci la toolbar"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ja/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,11 @@ msgstr "サイドバーを閉じる"
msgid "Shrink toolbar"
msgstr "ツールバーを閉じる"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/nl/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3402,6 +3402,11 @@ msgstr ""
msgid "Shrink toolbar"
msgstr ""

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/pt/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,11 @@ msgstr "Encolher barra lateral"
msgid "Shrink toolbar"
msgstr ""

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/pt_BR/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,11 @@ msgstr "Recolher barra lateral"
msgid "Shrink toolbar"
msgstr "Recolher barra de ferramentas"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ro/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,11 @@ msgstr "Reduceți bara laterală"
msgid "Shrink toolbar"
msgstr "Reduceti bara de instrumente"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/volto.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3400,6 +3400,11 @@ msgstr ""
msgid "Shrink toolbar"
msgstr ""

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/zh_CN/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,11 @@ msgstr "缩小侧边栏"
msgid "Shrink toolbar"
msgstr "缩小工具栏"

#. Default: "Sidebar expanded"
#: components/manage/Form/SidebarToggleButton
msgid "Sidebar expanded"
msgstr ""

#. Default: "Sign in to start session"
#: components/theme/Login/Login
msgid "Sign in to start session"
Expand Down
2 changes: 2 additions & 0 deletions packages/volto/news/3912.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added a button to the toolbar to make it easier to show and hide the sidebar.
@JeffersonBledsoe
1 change: 1 addition & 0 deletions packages/volto/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export {
export { getQuerystring } from '@plone/volto/actions/querystring/querystring';
export { getQueryStringResults } from '@plone/volto/actions/querystringsearch/querystringsearch';
export {
setSidebarExpanded,
setMetadataFieldsets,
setMetadataFocus,
resetMetadataFocus,
Expand Down
8 changes: 8 additions & 0 deletions packages/volto/src/actions/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SET_METADATA_FIELDSETS,
SET_METADATA_FOCUS,
RESET_METADATA_FOCUS,
SET_SIDEBAR_EXPANDED,
SET_SIDEBAR_TAB,
} from '@plone/volto/constants/ActionTypes';

Expand Down Expand Up @@ -61,3 +62,10 @@ export function setSidebarTab(index) {
index,
};
}

export function setSidebarExpanded(isExpanded) {
return {
type: SET_SIDEBAR_EXPANDED,
isExpanded,
};
}
5 changes: 5 additions & 0 deletions packages/volto/src/components/manage/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Icon, Toast } from '@plone/volto/components';
import { Field, BlocksForm } from '@plone/volto/components/manage/Form';
import BlocksToolbar from '@plone/volto/components/manage/Form/BlocksToolbar';
import { SidebarToggleButton } from '@plone/volto/components/manage/Form/SidebarToggleButton';
import UndoToolbar from '@plone/volto/components/manage/Form/UndoToolbar';
import {
difference,
Expand Down Expand Up @@ -758,6 +759,10 @@ class Form extends Component {
}
onSelectBlock={this.onSelectBlock}
/>
{config.experimental.sidebarToggleButton?.position ===
'toolbar' ? (
<SidebarToggleButton />
) : null}
<UndoToolbar
state={{
formData,
Expand Down
54 changes: 54 additions & 0 deletions packages/volto/src/components/manage/Form/SidebarToggleButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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({
sidebarExpanded: {
id: 'Sidebar expanded',
defaultMessage: 'Sidebar expanded',
},
});

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]}
order={-1}
>
<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={intl.formatMessage(messages.sidebarExpanded)}
aria-expanded={sidebarExpanded}
aria-controls="sidebar"
onClick={() => {
dispatch(setSidebarExpanded(!sidebarExpanded));
}}
>
<div aria-hidden="true" focusable="false">
<Icon name={configSVG} />
</div>
</Button>
</Plug>
);
};

export default SidebarToggleButton;
66 changes: 41 additions & 25 deletions packages/volto/src/components/manage/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { useState, Fragment, useCallback } from 'react';
import { setSidebarExpanded, setSidebarTab } from '@plone/volto/actions';
import { Icon } from '@plone/volto/components';
import { BodyClass, getCookieOptions } from '@plone/volto/helpers';
import config from '@plone/volto/registry';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { Button, Tab } from 'semantic-ui-react';
import { useDispatch, useSelector } from 'react-redux';
import { compose } from 'redux';
import { Fragment, useCallback, useState } from 'react';
import { withCookies } from 'react-cookie';
import { defineMessages, useIntl } from 'react-intl';
import cx from 'classnames';
import { BodyClass, getCookieOptions } from '@plone/volto/helpers';
import { Icon } from '@plone/volto/components';
import { useDispatch, useSelector } from 'react-redux';
import { compose } from 'redux';
import { Button, Tab } from 'semantic-ui-react';

import clearSVG from '@plone/volto/icons/clear.svg';
import forbiddenSVG from '@plone/volto/icons/forbidden.svg';
import { setSidebarTab } from '@plone/volto/actions';
import expandSVG from '@plone/volto/icons/left-key.svg';
import collapseSVG from '@plone/volto/icons/right-key.svg';

Expand Down Expand Up @@ -51,9 +54,8 @@ const Sidebar = (props) => {
settingsTab,
orderTab = true,
} = props;
const [expanded, setExpanded] = useState(
cookies.get('sidebar_expanded') !== 'false',
);
const expanded = useSelector((state) => state.sidebar.expanded ?? true);

const [size] = useState(0);
const [showFull, setshowFull] = useState(true);

Expand All @@ -63,7 +65,7 @@ const Sidebar = (props) => {

const onToggleExpanded = () => {
cookies.set('sidebar_expanded', !expanded, getCookieOptions());
setExpanded(!expanded);
dispatch(setSidebarExpanded(!expanded));
resetFullSizeSidebar();
};

Expand Down Expand Up @@ -111,19 +113,23 @@ const Sidebar = (props) => {
className={cx('sidebar-container', { collapsed: !expanded })}
style={size > 0 ? { width: size } : null}
>
<Button
aria-label={
expanded
? intl.formatMessage(messages.shrinkSidebar)
: intl.formatMessage(messages.expandSidebar)
}
className={
content && content.review_state
? `${content.review_state} trigger`
: 'trigger'
}
onClick={onToggleExpanded}
/>
{['toolbar', 'floating'].includes(
config.experimental.sidebarToggleButton?.position,
) ? null : (
<Button
aria-label={
expanded
? intl.formatMessage(messages.shrinkSidebar)
: intl.formatMessage(messages.expandSidebar)
}
className={
content && content.review_state
? `${content.review_state} trigger`
: 'trigger'
}
onClick={onToggleExpanded}
/>
)}
<Button
className="full-size-sidenav-btn"
onClick={onToggleFullSize}
Expand All @@ -134,6 +140,16 @@ const Sidebar = (props) => {
name={showFull ? expandSVG : collapseSVG}
/>
</Button>
{config.experimental.sidebarCloseButton ||
config.experimental.sidebarToggleButton?.position ? (
<Button
className="close-sidenav-btn"
aria-label={intl.formatMessage(messages.shrinkSidebar)}
onClick={onToggleExpanded}
>
<Icon name={clearSVG} size="26px" />
</Button>
) : null}
<Tab
menu={{
secondary: true,
Expand Down
Loading
Loading