From 3dd672a5260d9511481b9d31a0ac7a856cdbbc14 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Sat, 3 Aug 2024 18:39:25 -0700 Subject: [PATCH] Blocks: Extract the Toggle button --- src/modules/blocks/AutoBlocksRenderer.tsx | 61 +++++++++++++---------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/modules/blocks/AutoBlocksRenderer.tsx b/src/modules/blocks/AutoBlocksRenderer.tsx index c303c3010..8bf5fa38b 100644 --- a/src/modules/blocks/AutoBlocksRenderer.tsx +++ b/src/modules/blocks/AutoBlocksRenderer.tsx @@ -1,6 +1,8 @@ import * as React from 'react'; import type { Diff as TextDiff } from '@sanity/diff-match-patch'; -import { Button, Typography } from '@mui/joy'; + +import type { SxProps } from '@mui/joy/styles/types'; +import { Button, ColorPaletteProp } from '@mui/joy'; import ExpandLessIcon from '@mui/icons-material/ExpandLess'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; @@ -8,7 +10,7 @@ import type { DMessageRole } from '~/common/stores/chat/chat.message'; import { ContentScaling } from '~/common/app.theme'; import type { Block, CodeBlock, HtmlBlock, ImageBlock, TextBlock } from './blocks.types'; -import { BlocksContainer } from './BlocksContainer'; +import { BlocksContainer } from './BlocksContainers'; import { RenderMarkdown, RenderMarkdownMemo } from './markdown/RenderMarkdown'; import { RenderPlainChatText } from './plaintext/RenderPlainChatText'; import { RenderTextDiff } from './textdiff/RenderTextDiff'; @@ -149,6 +151,29 @@ type BlocksRendererProps = { }; +function ToggleExpansionButton(props: { + color?: ColorPaletteProp; + isCollapsed: boolean; + onToggle: () => void; + sx: SxProps; +}) { + return ( +
+ +
+ ); +} + + /** * Features: collpase/expand, auto-detects HTML, SVG, Code, etc.. * Used by (and more): @@ -180,12 +205,8 @@ export const AutoBlocksRenderer = React.forwardRef { - setForceUserExpanded(false); - }, []); - - const handleTextUncollapse = React.useCallback(() => { - setForceUserExpanded(true); + const handleToggleExpansion = React.useCallback(() => { + setForceUserExpanded(on => !on); }, []); @@ -256,26 +277,14 @@ export const AutoBlocksRenderer = React.forwardRef - - + )} - {/* import VisibilityIcon from '@mui/icons-material/Visibility'; */} - {/*
*/} - {/*}>*/} - {/* BlockAction*/} - {/**/} - ); });