From 76f8680db05684ecb8cc2d5d741ca563e1c83cf2 Mon Sep 17 00:00:00 2001
From: Tim Down <158919+timdown@users.noreply.github.com>
Date: Wed, 16 Oct 2024 11:50:32 +0100
Subject: [PATCH] Merge pull request #21013 from
overleaf/td-bs5-history-document-diff-viewer
Migrate document diff viewer to Bootstrap 5
GitOrigin-RevId: 361e6398a09a5ec5c48aced02f27d9896567b539
---
.../diff-view/document-diff-viewer.tsx | 23 +++++-----
.../features/ui/components/ol/ol-button.tsx | 43 ++++++++++++++++++-
.../bootstrap-5/pages/editor/history.scss | 28 ++++++++++++
3 files changed, 82 insertions(+), 12 deletions(-)
diff --git a/services/web/frontend/js/features/history/components/diff-view/document-diff-viewer.tsx b/services/web/frontend/js/features/history/components/diff-view/document-diff-viewer.tsx
index 5ed5b4bcf7..30b9c9da8d 100644
--- a/services/web/frontend/js/features/history/components/diff-view/document-diff-viewer.tsx
+++ b/services/web/frontend/js/features/history/components/diff-view/document-diff-viewer.tsx
@@ -18,9 +18,10 @@ import {
highlightLocationsField,
scrollToHighlight,
} from '../../extensions/highlight-locations'
-import Icon from '../../../../shared/components/icon'
import { useTranslation } from 'react-i18next'
import { inlineBackground } from '../../../source-editor/extensions/inline-background'
+import OLButton from '@/features/ui/components/ol/ol-button'
+import { bsVersion } from '@/features/utils/bootstrap-5'
function extensions(themeOptions: Options): Extension[] {
return [
@@ -131,24 +132,24 @@ function DocumentDiffViewer({
{before > 0 ? (
-
+
) : null}
{after > 0 ? (
-
+
) : null}
)
diff --git a/services/web/frontend/js/features/ui/components/ol/ol-button.tsx b/services/web/frontend/js/features/ui/components/ol/ol-button.tsx
index 519526adfe..6df9266744 100644
--- a/services/web/frontend/js/features/ui/components/ol/ol-button.tsx
+++ b/services/web/frontend/js/features/ui/components/ol/ol-button.tsx
@@ -7,6 +7,8 @@ import Button from '../bootstrap-5/button'
import classnames from 'classnames'
import { getAriaAndDataProps } from '@/features/utils/bootstrap-5'
import { callFnsInSequence } from '@/utils/functions'
+import Icon from '@/shared/components/icon'
+
export type BS3ButtonSize = 'xsmall' | 'sm' | 'medium' | 'lg'
export type OLButtonProps = ButtonProps & {
@@ -49,6 +51,38 @@ export function bs3ButtonProps(props: ButtonProps) {
return bs3ButtonProps
}
+function BS3ButtonContent({
+ children,
+ leadingIcon,
+ trailingIcon,
+}: {
+ children: React.ReactNode
+ leadingIcon: OLButtonProps['leadingIcon']
+ trailingIcon: OLButtonProps['trailingIcon']
+}) {
+ const leadingIconComponent =
+ leadingIcon && typeof leadingIcon === 'string' ? (
+
+ ) : (
+ leadingIcon
+ )
+
+ const trailingIconComponent =
+ trailingIcon && typeof trailingIcon === 'string' ? (
+
+ ) : (
+ trailingIcon
+ )
+
+ return (
+ <>
+ {leadingIconComponent ? <>{leadingIconComponent} > : null}
+ {children}
+ {trailingIconComponent ? <> {trailingIconComponent}> : null}
+ >
+ )
+}
+
const OLButton = forwardRef(
({ bs3Props = {}, ...rest }, ref) => {
const { className: _, ...restBs3Props } = bs3Props
@@ -78,7 +112,14 @@ const OLButton = forwardRef(
{...bs3FinalProps}
ref={ref as React.LegacyRef | undefined}
>
- {bs3Props?.loading || rest.children}
+ {bs3Props?.loading || (
+
+ {rest.children}
+
+ )}
}
bs5={}
diff --git a/services/web/frontend/stylesheets/bootstrap-5/pages/editor/history.scss b/services/web/frontend/stylesheets/bootstrap-5/pages/editor/history.scss
index bfb986767e..4615f6e9df 100644
--- a/services/web/frontend/stylesheets/bootstrap-5/pages/editor/history.scss
+++ b/services/web/frontend/stylesheets/bootstrap-5/pages/editor/history.scss
@@ -365,6 +365,34 @@ history-root {
}
}
+.document-diff-container {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ position: relative;
+
+ .cm-viewer-container,
+ .cm-editor {
+ height: 100%;
+ }
+
+ .previous-highlight-button,
+ .next-highlight-button {
+ @include shadow-md;
+
+ position: absolute;
+ right: var(--spacing-06);
+ }
+
+ .previous-highlight-button {
+ top: var(--spacing-06);
+ }
+
+ .next-highlight-button {
+ bottom: var(--spacing-06);
+ }
+}
+
.history-dropdown-icon {
color: var(--content-primary);
}