Files
gitbook/src/components/DocumentView/Text.tsx
T
Sebastian Graz 1fde857aee Stylepr (#60)
* hint leading

* first attempt at themed ui

* v2 theme ui

* fix feedback

* fix hint css override

* cookie

* more sensible scroll logic

* Add better heading margin

* inline code styling

* fix copy button, list vis, next/prev mobile

* add shortcut to search button

* search button, toc

* add toc style

* fix toc hover

* safari fix

* simplify search, swagger, next/prev

* add mask to page cover

* codeblock fix

* global defaults

* improve mobile cards

* modal changes

* change mask intensity dark mode, fix table progress zindex

* a target

* selection, footer, search icon

* fix card resp

* fix multi col images

* fix aside

* card item pos

* search vis

* reuse same header for mobile

* fix header and search legibility

* format

* Sidebar changes

* remove linear gradient light mode page cover
2023-12-26 14:38:54 +01:00

98 lines
2.5 KiB
TypeScript

import {
DocumentMarkBold,
DocumentMarkCode,
DocumentMarkColor,
DocumentMarkItalic,
DocumentMarkStrikethrough,
DocumentText,
DocumentTextMark,
} from '@gitbook/api';
import React from 'react';
import { tcls } from '@/lib/tailwind';
export function Text(props: { text: DocumentText }) {
const { text } = props;
return (
<>
{text.leaves.map((leaf, index) => {
return (
<React.Fragment key={index}>
{leaf.marks.reduce<React.ReactNode>((children, mark, index) => {
const Mark = MARK_STYLES[mark.type];
if (!Mark) {
return children;
}
// @ts-ignore
return <Mark mark={mark}>{children}</Mark>;
}, leaf.text)}
</React.Fragment>
);
})}
</>
);
}
const MARK_STYLES = {
bold: Bold,
italic: Italic,
code: Code,
strikethrough: Strikethrough,
color: Color,
};
interface MarkedLeafProps<Mark extends DocumentTextMark> {
mark: Mark;
children: React.ReactNode;
}
function Bold(props: MarkedLeafProps<DocumentMarkBold>) {
return <strong className={tcls('font-bold')}>{props.children}</strong>;
}
function Italic(props: MarkedLeafProps<DocumentMarkItalic>) {
return <i className={tcls('font-italic')}>{props.children}</i>;
}
function Strikethrough(props: MarkedLeafProps<DocumentMarkStrikethrough>) {
return <s className={tcls('line-through')}>{props.children}</s>;
}
function Code(props: MarkedLeafProps<DocumentMarkCode>) {
return (
<code
className={tcls(
'font-normal',
'py-[1px]',
'px-1.5',
'min-w-[1.625rem]',
'inline-flex',
'justify-center',
'items-center',
'leading-normal',
'ring-1',
'ring-inset',
'ring-dark/1',
'bg-dark/[0.06]',
'rounded',
'text-sm',
'text-dark/8',
'dark:ring-light/1',
'dark:bg-light/1',
'dark:text-light/7',
'[&>*]:font-normal',
)}
>
{props.children}
</code>
);
}
function Color(props: MarkedLeafProps<DocumentMarkColor>) {
// TODO
return <span>{props.children}</span>;
}