From 43e84678601cdd77dca24294c0815a2a33448e63 Mon Sep 17 00:00:00 2001 From: Antoine Clausse Date: Mon, 28 Oct 2024 13:52:25 +0100 Subject: [PATCH] [web] Wrap Layout MenuItem description on a new line in BS5 (#21206) * [storybook] Rerender when switching BS version * Move comment to related code (bsStyle) * Wrap the Layout MenuItem "subdued" text, using flex-column * Create a Story for `LayoutDropdownButton` * Center `.layout-dropdown .dropdown-item` vertically * Remove unused classname `layout-dropdown-list` * [storybook] Allow `detachable` to be passed as a prop * Migrate `DetachDisabled` to BS5 * [storybook] Set actions for `^handle.*`, rename story GitOrigin-RevId: 18509d259fad02a8aeb52132f1919e216b092b7e --- .../components/layout-dropdown-button.tsx | 103 +++++++++++++----- .../editor/layout-dropdown-button.stories.tsx | 37 +++++++ .../bootstrap-5/pages/editor/toolbar.scss | 4 + 3 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 services/web/frontend/stories/editor/layout-dropdown-button.stories.tsx diff --git a/services/web/frontend/js/features/editor-navigation-toolbar/components/layout-dropdown-button.tsx b/services/web/frontend/js/features/editor-navigation-toolbar/components/layout-dropdown-button.tsx index e9e45763bb..b580fa5cf8 100644 --- a/services/web/frontend/js/features/editor-navigation-toolbar/components/layout-dropdown-button.tsx +++ b/services/web/frontend/js/features/editor-navigation-toolbar/components/layout-dropdown-button.tsx @@ -26,6 +26,7 @@ import useEventListener from '../../../shared/hooks/use-event-listener' import { DetachRole } from '@/shared/context/detach-context' import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher' import MaterialIcon from '@/shared/components/material-icon' +import OLTooltip from '@/features/ui/components/ol/ol-tooltip' function IconPlaceholder() { return @@ -139,7 +140,7 @@ const LayoutDropdownToggleButton = forwardRef< }) LayoutDropdownToggleButton.displayName = 'LayoutDropdownToggleButton' -function DetachDisabled() { +function BS3DetachDisabled() { const { t } = useTranslation() return ( @@ -158,9 +159,25 @@ function DetachDisabled() { ) } -function LayoutDropdownButton() { +function BS5DetachDisabled() { const { t } = useTranslation() + return ( + + + + {t('pdf_in_separate_tab')} + + + + ) +} + +function LayoutDropdownButton() { const { reattach, detach, @@ -199,9 +216,42 @@ function LayoutDropdownButton() { [changeLayout, handleReattach] ) - const processing = !detachIsLinked && detachRole === 'detacher' + return ( + + ) +} - // bsStyle is required for Dropdown.Toggle, but we will override style +type LayoutDropdownButtonUiProps = { + processing: boolean + handleChangeLayout: (newLayout: IdeLayout, newView?: IdeView) => void + handleDetach: () => void + detachIsLinked: boolean + detachRole: DetachRole + pdfLayout: IdeLayout + view: IdeView | null + detachable: boolean +} + +export const LayoutDropdownButtonUi = ({ + processing, + handleChangeLayout, + handleDetach, + detachIsLinked, + detachRole, + view, + pdfLayout, + detachable, +}: LayoutDropdownButtonUiProps) => { + const { t } = useTranslation() return ( <> {processing && ( @@ -219,6 +269,7 @@ function LayoutDropdownButton() { className="toolbar-item layout-dropdown" pullRight > + {/* bsStyle is required for Dropdown.Toggle, but we will override style */} {processing ? : } {t('layout')} @@ -280,7 +331,7 @@ function LayoutDropdownButton() { } /> - {'BroadcastChannel' in window ? ( + {detachable ? ( handleDetach()} checkmark={ @@ -298,7 +349,7 @@ function LayoutDropdownButton() { text={t('pdf_in_separate_tab')} /> ) : ( - + )} @@ -322,7 +373,7 @@ function LayoutDropdownButton() { )} {t('layout')} - + handleChangeLayout('sideBySide')} active={isActiveDropdownItem({ @@ -346,15 +397,14 @@ function LayoutDropdownButton() { })} leadingIcon="code" > - , - ]} - /> +
+ , + ]} + /> +
- , - ]} - /> +
+ , + ]} + /> +
- {'BroadcastChannel' in window ? ( + {detachable ? ( handleDetach()} active={detachRole === 'detacher' && detachIsLinked} @@ -406,7 +455,7 @@ function LayoutDropdownButton() { {t('pdf_in_separate_tab')} ) : ( - + )}
diff --git a/services/web/frontend/stories/editor/layout-dropdown-button.stories.tsx b/services/web/frontend/stories/editor/layout-dropdown-button.stories.tsx new file mode 100644 index 0000000000..cb81b0f5c6 --- /dev/null +++ b/services/web/frontend/stories/editor/layout-dropdown-button.stories.tsx @@ -0,0 +1,37 @@ +import { LayoutDropdownButtonUi } from '@/features/editor-navigation-toolbar/components/layout-dropdown-button' +import { Meta } from '@storybook/react' +import { bsVersionDecorator } from '../../../.storybook/utils/with-bootstrap-switcher' +import { ComponentProps } from 'react' + +export const LayoutDropdown = ( + props: ComponentProps +) => ( +
+
+ +
+
+) + +const meta: Meta = { + title: 'Editor / Toolbar / Layout Dropdown', + component: LayoutDropdownButtonUi, + argTypes: { + view: { + control: 'select', + options: [null, 'editor', 'file', 'pdf', 'history'], + }, + detachRole: { + control: 'select', + options: ['detacher', 'detached'], + }, + pdfLayout: { + control: 'select', + options: ['sideBySide', 'flat'], + }, + ...bsVersionDecorator.argTypes, + }, + parameters: { actions: { argTypesRegex: '^handle.*' } }, +} + +export default meta diff --git a/services/web/frontend/stylesheets/bootstrap-5/pages/editor/toolbar.scss b/services/web/frontend/stylesheets/bootstrap-5/pages/editor/toolbar.scss index 0e13fea449..e38a908c79 100644 --- a/services/web/frontend/stylesheets/bootstrap-5/pages/editor/toolbar.scss +++ b/services/web/frontend/stylesheets/bootstrap-5/pages/editor/toolbar.scss @@ -225,6 +225,10 @@ } } +.layout-dropdown .dropdown-item { + align-items: center; +} + .header-cobranding-logo { display: block; width: auto;