diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/contexts/tabular-context.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/contexts/tabular-context.tsx index 60baceab42..fb54fbfdfd 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/contexts/tabular-context.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/contexts/tabular-context.tsx @@ -1,13 +1,30 @@ -import { FC, RefObject, createContext, useContext, useRef } from 'react' +import { + FC, + RefObject, + createContext, + useCallback, + useContext, + useRef, + useState, +} from 'react' const TabularContext = createContext< - { ref: RefObject } | undefined + | { + ref: RefObject + showHelp: () => void + hideHelp: () => void + helpShown: boolean + } + | undefined >(undefined) export const TabularProvider: FC = ({ children }) => { const ref = useRef(null) + const [helpShown, setHelpShown] = useState(false) + const showHelp = useCallback(() => setHelpShown(true), []) + const hideHelp = useCallback(() => setHelpShown(false), []) return ( - + {children} ) diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/help-modal.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/help-modal.tsx new file mode 100644 index 0000000000..20869ba258 --- /dev/null +++ b/services/web/frontend/js/features/source-editor/components/table-generator/help-modal.tsx @@ -0,0 +1,86 @@ +import { Button, Modal } from 'react-bootstrap' +import AccessibleModal from '../../../../shared/components/accessible-modal' +import { useTabularContext } from './contexts/tabular-context' + +export const TableGeneratorHelpModal = () => { + const { helpShown, hideHelp } = useTabularContext() + if (!helpShown) return null + + return ( + + + Help + + +

+ This tool helps you insert simple tables into your project without + writing LaTeX code. This tool is new, so please{' '} + + give us feedback + {' '} + and look out for additional functionality coming soon. +

+ How it works +

+ You’ll get the best results from using this tool in the{' '} + Visual Editor, although you can still use it to insert tables + in the Code Editor. Once you’ve selected the number of rows and + columns you need, the table will appear in your document and you can + double click in a cell to add contents to it. +

+ Customizing tables +

+ If you need to customize your table further, you can. Using LaTeX + code, you can change anything from table styles and border styles to + colors and column widths.{' '} + + Read our guide + {' '} + to using tables in LaTeX to help you get started. +

+ Changing the position of your table +

+ LaTeX places tables according to a special algorithm. You can use + “placement parameters” to influence the position of the table.{' '} + + This article + {' '} + explains how to do this. +

+ Understanding labels +

+ Labels help you to reference your tables throughout your document + easily. To reference a table within the text, reference the label + using the \ref{...} command. This makes it easy + to reference tables without manually remembering the table numbering.{' '} + + Read about labels and cross-references. + +

+
+ + + +
+ ) +} diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/tabular.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/tabular.tsx index 0b5085f3f5..1365218069 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/tabular.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/tabular.tsx @@ -20,6 +20,8 @@ import { TableProvider } from './contexts/table-context' import { TabularProvider, useTabularContext } from './contexts/tabular-context' import Icon from '../../../../shared/components/icon' import { BorderTheme } from './toolbar/commands' +import { TableGeneratorHelpModal } from './help-modal' +import { SplitTestProvider } from '../../../../shared/context/split-test-context' export type ColumnDefinition = { alignment: 'left' | 'center' | 'right' | 'paragraph' @@ -190,22 +192,25 @@ export const Tabular: FC<{ )} > - - - - - - - - - - - + + + + + + + + + + + + + + ) } @@ -216,7 +221,10 @@ const TabularWrapper: FC = () => { const { ref } = useTabularContext() useEffect(() => { const listener: (event: MouseEvent) => void = event => { - if (!ref.current?.contains(event.target as Node)) { + if ( + !ref.current?.contains(event.target as Node) && + !(event.target as HTMLElement).closest('.table-generator-help-modal') + ) { if (selection) { setSelection(null) } diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx index 661d3d89ec..bdeded5dbd 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx @@ -19,6 +19,8 @@ import { } from './commands' import { useCodeMirrorViewContext } from '../../codemirror-editor' import { useTableContext } from '../contexts/table-context' +import { useTabularContext } from '../contexts/tabular-context' +import SplitTestBadge from '../../../../../shared/components/split-test-badge' const borderThemeLabel = (theme: BorderTheme | null) => { switch (theme) { @@ -36,6 +38,7 @@ export const Toolbar = memo(function Toolbar() { const view = useCodeMirrorViewContext() const { positions, rowSeparators, cellSeparators, tableEnvironment, table } = useTableContext() + const { showHelp } = useTabularContext() const borderDropdownLabel = useMemo( () => borderThemeLabel(table.getBorderTheme()), @@ -319,6 +322,18 @@ export const Toolbar = memo(function Toolbar() { view.focus() }} /> + +
+ +
) diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts b/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts index b5ff305364..56b8a4e741 100644 --- a/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts +++ b/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts @@ -252,6 +252,10 @@ export const tableGeneratorTheme = EditorView.baseTheme({ }, }, + '.toolbar-beta-badge': { + padding: '0 4px 2px 12px', + }, + '.table-generator-button-group': { display: 'inline-flex', 'align-items': 'center',