From 8574c364dbd2ef95e677ad68fc0d99a2edf19034 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sun, 1 Nov 2026 10:34:57 +0530 Subject: [PATCH] add wrap toggle in code block --- src/app/plugins/react-custom-html-parser.tsx | 69 +++++++++++++++----- src/app/styles/CustomHtml.css.ts | 2 +- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/app/plugins/react-custom-html-parser.tsx b/src/app/plugins/react-custom-html-parser.tsx index 6da8f2516..78a9e6c1c 100644 --- a/src/app/plugins/react-custom-html-parser.tsx +++ b/src/app/plugins/react-custom-html-parser.tsx @@ -15,7 +15,20 @@ import { domToReact, } from 'html-react-parser'; import classNames from 'classnames'; -import { Box, Chip, config, Header, Icon, IconButton, Icons, Scroll, Text, toRem } from 'folds'; +import { + Box, + Chip, + config, + Header, + Icon, + IconButton, + Icons, + Scroll, + Text, + Tooltip, + TooltipProvider, + toRem, +} from 'folds'; import { IntermediateRepresentation, Opts as LinkifyOpts, OptFn } from 'linkifyjs'; import Linkify from 'linkify-react'; import { ErrorBoundary } from 'react-error-boundary'; @@ -243,6 +256,7 @@ export function CodeBlock({ ); const [expanded, setExpand] = useState(false); + const [wrap, setWrap] = useState(false); const [copied, setCopied] = useTimeoutToggle(); const handleCopy = () => { @@ -257,7 +271,21 @@ export function CodeBlock({ return (
- + {largeCodeBlock && ( + + + + + + )} + {customLabel ?? language ?? 'Code'} @@ -272,18 +300,29 @@ export function CodeBlock({ > {copied ? 'Copied' : 'Copy'} - {largeCodeBlock && ( - - - - )} + + Toggle Wrap + + } + > + {(triggerRef) => ( + setWrap(!wrap)} + > + + + )} +
-
+
{domToReact(children, opts)}
diff --git a/src/app/styles/CustomHtml.css.ts b/src/app/styles/CustomHtml.css.ts index acf2c0797..0283d46e3 100644 --- a/src/app/styles/CustomHtml.css.ts +++ b/src/app/styles/CustomHtml.css.ts @@ -96,7 +96,7 @@ export const CodeBlock = style([ export const CodeBlockHeader = style([ ContainerColor({ variant: 'Surface' }), { - padding: `0 ${config.space.S200} 0 ${config.space.S300}`, + padding: `0 ${config.space.S200} 0 ${config.space.S200}`, borderBottomWidth: config.borderWidth.B300, gap: config.space.S200, },