Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/types/MarkdownTextProps.web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ColorValue } from 'react-native';
import type { CSSProperties, HTMLAttributes } from 'react';
import type { MarkdownStyle, Md4cFlags } from './MarkdownStyle';
import type {
Expand Down Expand Up @@ -70,7 +69,7 @@ export interface EnrichedMarkdownTextProps
* Color of the text selection highlight.
* @platform web
*/
selectionColor?: ColorValue;
selectionColor?: string;
/**
* When false (default), removes trailing margin from the last element to
* eliminate bottom spacing.
Expand Down
18 changes: 7 additions & 11 deletions src/web/EnrichedMarkdownText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { ASTNode, RendererCallbacks, RenderCapabilities } from './types';
import { indexTaskItems, markInlineImages } from './utils';
import { loadKaTeX } from './katex';
import type { KaTeXInstance } from './katex';
import { normalizeColor } from '../styleUtils';

export const EnrichedMarkdownText = ({
markdown,
Expand Down Expand Up @@ -103,21 +102,18 @@ export const EnrichedMarkdownText = ({
[lastChildStyle]
);

const wrapperStyle = useMemo<CSSProperties>(() => {
const selectionColorCss = selectionColor
? normalizeColor(String(selectionColor))
: undefined;

return {
const wrapperStyle = useMemo<CSSProperties>(
() => ({
display: 'flex',
flexDirection: 'column',
...(containerStyle as CSSProperties),
...(selectable ? undefined : { userSelect: 'none' }),
...(selectionColorCss != null
? ({ ['--enrm-selection-bg']: selectionColorCss } as CSSProperties)
...(selectionColor
? ({ ['--enrm-selection-bg']: selectionColor } as CSSProperties)
: null),
};
}, [containerStyle, selectable, selectionColor]);
}),
[containerStyle, selectable, selectionColor]
);

const selectionStyle = selectionColor ? (
<style>{`[data-enriched-markdown-text] ::selection {
Expand Down
Loading