/* eslint-disable react/no-children-prop */ import { useState } from 'react' import type { Highlight } from '../../lib/networking/fragments/highlightFragment' import { LabelChip } from '../elements/LabelChip' import { Box, VStack, Blockquote, SpanBox, HStack, } from '../elements/LayoutPrimitives' import { styled } from '../tokens/stitches.config' import { HighlightViewNote } from './HighlightNotes' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { highlightColorVar } from '../../lib/themeUpdater' import { ReadableItem } from '../../lib/networking/library_items/useLibraryItems' import { UserBasicData } from '../../lib/networking/queries/useGetViewerQuery' import { autoUpdate, offset, size, useFloating, useHover, useInteractions, } from '@floating-ui/react' import { HighlightHoverActions } from './HighlightHoverActions' type HighlightViewProps = { item: ReadableItem viewer: UserBasicData highlight: Highlight author?: string title?: string updateHighlight: (highlight: Highlight) => void viewInReader: (highlightId: string) => void setLabelsTarget: (target: Highlight) => void setShowConfirmDeleteHighlightId: (set: string) => void } const StyledQuote = styled(Blockquote, { p: '0px', margin: '0px 0px 0px 0px', fontSize: '18px', lineHeight: '27px', borderRadius: '4px', width: '100%', }) export function HighlightView(props: HighlightViewProps): JSX.Element { const [noteMode, setNoteMode] = useState<'preview' | 'edit'>('preview') const [isOpen, setIsOpen] = useState(false) const { refs, floatingStyles, context } = useFloating({ open: isOpen, onOpenChange: setIsOpen, middleware: [ offset({ mainAxis: -25, }), size(), ], placement: 'top-end', whileElementsMounted: autoUpdate, }) const hover = useHover(context) const { getReferenceProps, getFloatingProps } = useInteractions([hover]) const highlightColor = highlightColorVar(props.highlight.color) return ( *': { display: 'inline', padding: '3px', backgroundColor: `rgba(${highlightColor}, var(--colors-highlight_background_alpha))`, boxDecorationBreak: 'clone', borderRadius: '2px', }, '> ul': { display: 'block', boxShadow: 'unset', backgroundColor: 'unset', }, fontSize: '15px', lineHeight: 1.5, color: '$thTextSubtle2', img: { display: 'block', margin: '0.5em auto !important', maxWidth: '100% !important', height: 'auto', }, }} > {props.highlight.labels?.map(({ name, color }, index) => ( ))} ) }