mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 19:53:59 -05:00
Set background or alternative colors for diagrams (#667)
This commit is contained in:
parent
d5ee2f6d54
commit
8a8c043081
5 changed files with 17 additions and 5 deletions
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
& > img {
|
& > img {
|
||||||
width: unset;
|
width: unset;
|
||||||
background-color: unset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a.heading-anchor {
|
a.heading-anchor {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import React, { useEffect, useRef, useState } from 'react'
|
import React, { useEffect, useRef, useState } from 'react'
|
||||||
import { Alert } from 'react-bootstrap'
|
import { Alert } from 'react-bootstrap'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
|
import { ApplicationState } from '../../../../../redux'
|
||||||
|
|
||||||
export interface FlowChartProps {
|
export interface FlowChartProps {
|
||||||
code: string
|
code: string
|
||||||
|
@ -10,6 +12,8 @@ export const FlowChart: React.FC<FlowChartProps> = ({ code }) => {
|
||||||
const diagramRef = useRef<HTMLDivElement>(null)
|
const diagramRef = useRef<HTMLDivElement>(null)
|
||||||
const [error, setError] = useState(false)
|
const [error, setError] = useState(false)
|
||||||
|
|
||||||
|
const darkModeActivated = useSelector((state: ApplicationState) => state.darkMode.darkMode)
|
||||||
|
|
||||||
useTranslation()
|
useTranslation()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -24,6 +28,8 @@ export const FlowChart: React.FC<FlowChartProps> = ({ code }) => {
|
||||||
'line-width': 2,
|
'line-width': 2,
|
||||||
fill: 'none',
|
fill: 'none',
|
||||||
'font-size': '16px',
|
'font-size': '16px',
|
||||||
|
'line-color': darkModeActivated ? '#ffffff' : '#000000',
|
||||||
|
'element-color': darkModeActivated ? '#ffffff' : '#000000',
|
||||||
'font-family': 'Source Code Pro, "Twemoji Mozilla", monospace'
|
'font-family': 'Source Code Pro, "Twemoji Mozilla", monospace'
|
||||||
})
|
})
|
||||||
setError(false)
|
setError(false)
|
||||||
|
@ -35,7 +41,7 @@ export const FlowChart: React.FC<FlowChartProps> = ({ code }) => {
|
||||||
return () => {
|
return () => {
|
||||||
Array.from(currentDiagramRef.children).forEach(value => value.remove())
|
Array.from(currentDiagramRef.children).forEach(value => value.remove())
|
||||||
}
|
}
|
||||||
}, [code])
|
}, [code, darkModeActivated])
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -3,6 +3,7 @@ import React, { Fragment, useCallback, useEffect, useRef, useState } from 'react
|
||||||
import { Alert } from 'react-bootstrap'
|
import { Alert } from 'react-bootstrap'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { ShowIf } from '../../../common/show-if/show-if'
|
import { ShowIf } from '../../../common/show-if/show-if'
|
||||||
|
import './mermaid.scss'
|
||||||
|
|
||||||
export interface MermaidChartProps {
|
export interface MermaidChartProps {
|
||||||
code: string
|
code: string
|
||||||
|
@ -55,6 +56,6 @@ export const MermaidChart: React.FC<MermaidChartProps> = ({ code }) => {
|
||||||
<ShowIf condition={!!error}>
|
<ShowIf condition={!!error}>
|
||||||
<Alert variant={'warning'}>{error}</Alert>
|
<Alert variant={'warning'}>{error}</Alert>
|
||||||
</ShowIf>
|
</ShowIf>
|
||||||
<div className={'text-center mermaid'} ref={diagramContainer}/>
|
<div className={'text-center mermaid text-black'} ref={diagramContainer}/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
.mermaid>svg {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
7
src/external-types/flowchart.js/index.d.ts
vendored
7
src/external-types/flowchart.js/index.d.ts
vendored
|
@ -3,11 +3,14 @@ declare module 'flowchart.js' {
|
||||||
'line-width': number,
|
'line-width': number,
|
||||||
'fill': string,
|
'fill': string,
|
||||||
'font-size': string,
|
'font-size': string,
|
||||||
'font-family': string
|
'font-family': string,
|
||||||
|
'font-color': string,
|
||||||
|
'line-color': string,
|
||||||
|
'element-color': string
|
||||||
}
|
}
|
||||||
export interface ParseOutput {
|
export interface ParseOutput {
|
||||||
clean: () => void,
|
clean: () => void,
|
||||||
drawSVG: (container: HTMLElement, options: Options) => void,
|
drawSVG: (container: HTMLElement, options: Partial<Options>) => void,
|
||||||
}
|
}
|
||||||
export function parse(code: string): ParseOutput
|
export function parse(code: string): ParseOutput
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue