diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index 4aee1c15c6..108aa10242 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -2113,7 +2113,6 @@ "toolbar_bold": "", "toolbar_bulleted_list": "", "toolbar_change_editor_mode": "", - "toolbar_choose_section_heading_level": "", "toolbar_code_visual_editor_switch": "", "toolbar_decrease_indent": "", "toolbar_editor": "", @@ -2138,7 +2137,7 @@ "toolbar_numbered_list": "", "toolbar_redo": "", "toolbar_search_file": "", - "toolbar_select_style": "", + "toolbar_section_heading_level": "", "toolbar_selected_projects": "", "toolbar_selected_projects_management_actions": "", "toolbar_selected_projects_remove": "", diff --git a/services/web/frontend/js/features/source-editor/components/toolbar/button-menu.tsx b/services/web/frontend/js/features/source-editor/components/toolbar/button-menu.tsx index 2f6b96151e..12ed780849 100644 --- a/services/web/frontend/js/features/source-editor/components/toolbar/button-menu.tsx +++ b/services/web/frontend/js/features/source-editor/components/toolbar/button-menu.tsx @@ -15,6 +15,7 @@ export const ToolbarButtonMenu: FC< label: string icon: React.ReactNode orientation?: 'vertical' | 'horizontal' + className?: string disabled?: boolean disablePopover?: boolean altCommand?: (view: EditorView) => void @@ -25,6 +26,7 @@ export const ToolbarButtonMenu: FC< id, label, orientation = 'vertical', + className, altCommand, onToggle, disabled, @@ -35,6 +37,18 @@ export const ToolbarButtonMenu: FC< const { open, onToggle: handleToggle, ref } = useDropdown() const view = useCodeMirrorViewContext() + useEffect(() => { + if (!open) return + + const onResize = () => { + handleToggle(false) + } + window.addEventListener('resize', onResize) + return () => { + window.removeEventListener('resize', onResize) + } + }, [open, handleToggle]) + useEffect(() => { if (disablePopover && open) { handleToggle(false) @@ -48,9 +62,12 @@ export const ToolbarButtonMenu: FC< const button = ( - - - {overflowOpen && ( - setOverflowOpen(false)} - transition={false} - container={view.dom} - containerPadding={0} - placement="bottom" - rootClose - target={toggleButtonRef.current} - popperConfig={{ - modifiers: [ - { - name: 'offset', - options: { - offset: [0, 1], - }, - }, - ], + + } + > + {levelsEntries.map(([level, label]) => ( + { + emitToolbarEvent(view, 'section-level-change') + setSectionHeadingLevel(view, level) + view.focus() }} + className={`ol-cm-section-heading-menu-item section-level-${level}`} > - - - - - )} - + {label} + + ))} + ) } diff --git a/services/web/frontend/js/features/source-editor/extensions/toolbar/toolbar-panel.ts b/services/web/frontend/js/features/source-editor/extensions/toolbar/toolbar-panel.ts index 5ee0498f52..fc7511b733 100644 --- a/services/web/frontend/js/features/source-editor/extensions/toolbar/toolbar-panel.ts +++ b/services/web/frontend/js/features/source-editor/extensions/toolbar/toolbar-panel.ts @@ -102,8 +102,29 @@ const toolbarTheme = EditorView.theme({ color: 'var(--toolbar-btn-color)', borderColor: 'var(--editor-toolbar-bg)', background: 'none', + '&.active': { + backgroundColor: 'rgba(125, 125, 125, 0.1)', + color: 'inherit', + }, '&:hover, &:focus': { backgroundColor: 'rgba(125, 125, 125, 0.2)', + color: 'inherit', + }, + '&.ol-cm-section-heading-menu-item': { + border: 'none', + padding: '4px 12px', + height: '40px', + fontSize: '14px', + fontWeight: 'bold', + }, + '&.section-level-section': { + fontSize: '1.44em', + }, + '&.section-level-subsection': { + fontSize: '1.2em', + }, + '&.section-level-text': { + fontWeight: 'normal', }, }, }, @@ -174,6 +195,9 @@ const toolbarTheme = EditorView.theme({ fontWeight: 700, }, }, + '.ol-cm-toolbar-button.ol-cm-toolbar-button-wide': { + width: 'auto', + }, '&.overall-theme-dark .ol-cm-toolbar-button': { opacity: 0.8, '&:hover, &:focus, &:active, &.active': { @@ -198,84 +222,6 @@ const toolbarTheme = EditorView.theme({ display: 'flex', }, }, - '.ol-cm-toolbar-menu-toggle': { - background: 'transparent', - border: 'none', - color: 'inherit', - borderRadius: 'var(--border-radius-base)', - opacity: 0.8, - width: '120px', - fontSize: '13px', - fontWeight: '700', - display: 'flex', - alignItems: 'center', - justifyContent: 'space-between', - padding: '5px 6px', - '&:hover, &:focus, &.active': { - backgroundColor: 'rgba(125, 125, 125, 0.1)', - opacity: '1', - color: 'inherit', - }, - '& .caret': { - marginTop: '0', - }, - }, - '.ol-cm-toolbar-menu-popover': { - border: 'none', - borderRadius: '0', - borderBottomLeftRadius: '4px', - borderBottomRightRadius: '4px', - boxShadow: '0 2px 5px rgb(0 0 0 / 20%)', - backgroundColor: 'var(--editor-toolbar-bg)', - color: 'var(--toolbar-btn-color)', - padding: '0', - '&.bottom': { - marginTop: '1px', - }, - '&.top': { - marginBottom: '1px', - }, - '& .arrow, & .popover-arrow': { - display: 'none', - }, - '& .popover-content, & > .popover-body': { - padding: '0', - color: 'inherit', - }, - '& .ol-cm-toolbar-menu': { - minWidth: '120px', - display: 'flex', - flexDirection: 'column', - boxSizing: 'border-box', - fontSize: '14px', - }, - '& .ol-cm-toolbar-menu-item': { - border: 'none', - background: 'none', - padding: '4px 12px', - height: '40px', - display: 'flex', - alignItems: 'center', - fontWeight: 'bold', - color: 'inherit', - '&.ol-cm-toolbar-menu-item-active': { - backgroundColor: 'rgba(125, 125, 125, 0.1)', - }, - '&:hover': { - backgroundColor: 'rgba(125, 125, 125, 0.2)', - color: 'inherit', - }, - '&.section-level-section': { - fontSize: '1.44em', - }, - '&.section-level-subsection': { - fontSize: '1.2em', - }, - '&.section-level-body': { - fontWeight: 'normal', - }, - }, - }, '&.overall-theme-dark .ol-cm-toolbar-table-grid': { '& td.active': { outlineColor: 'white', diff --git a/services/web/locales/en.json b/services/web/locales/en.json index b1d04fd50a..329e1bbf77 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -2727,7 +2727,6 @@ "toolbar_bold": "Bold", "toolbar_bulleted_list": "Bulleted list", "toolbar_change_editor_mode": "Change editor mode: Code / Visual", - "toolbar_choose_section_heading_level": "Choose section heading level", "toolbar_code_visual_editor_switch": "Code and visual editor switch", "toolbar_decrease_indent": "Decrease indent", "toolbar_editor": "Editor tools", @@ -2752,7 +2751,7 @@ "toolbar_numbered_list": "Numbered list", "toolbar_redo": "Redo", "toolbar_search_file": "Search file", - "toolbar_select_style": "Select style", + "toolbar_section_heading_level": "Section heading level", "toolbar_selected_projects": "Selected projects", "toolbar_selected_projects_management_actions": "Selected projects management actions", "toolbar_selected_projects_remove": "Remove selected projects", diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx index dc81924dcf..63a51c4028 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx @@ -68,14 +68,14 @@ describe(' toolbar in Rich Text mode', function () { mountEditor('hi') cy.get('.cm-content').should('have.text', 'hi') - clickToolbarButton('Choose section heading level') + clickToolbarButton('Section heading level') cy.findByRole('menu').within(() => { cy.findByText('Subsection').click() }) cy.get('.cm-content').should('have.text', 'hi') cy.get('.ol-cm-command-subsection').should('have.length', 1) - clickToolbarButton('Choose section heading level') + clickToolbarButton('Section heading level') cy.findByRole('menu').within(() => { cy.findByText('Normal text').click() })