/* eslint-disable @typescript-eslint/no-explicit-any */
import { MDXProvider } from '@mdx-js/react'
import React, { HTMLProps, useEffect, useRef } from 'react'
import C from '~/code/classes'
type BlockQuoteProps = React.ComponentPropsWithoutRef<'blockquote'> & {
children: React.ReactNode
}
export function A({ children, href, rel, target, ...props }: AProps) {
const list = [
C.textFillPurple,
C.hoverTextFillPurpleLight,
C.visitedTextFillBlue,
C.visitedHoverTextFillBlueLight,
C.transitionFade,
// C.borderBottomDotted,
// C.borderColorPurple,
// C.borderWidth1,
]
if (props.className) {
list.push(...props.className.split(/\s+/))
}
return (
{children}
)
}
type ColumnProps = {
children: React.ReactNode
fixed?: boolean
width?: number | string
}
export function BlockQuote({
children,
className,
...props
}: BlockQuoteProps) {
const list = [
C.backgroundFillBase5,
C.border4,
C.fontNotoSans,
C.fontItalic,
C.lineHeight1P7,
C.marginTop8,
C.marginBottom16,
C.widthMax720,
C.width100P,
C.padding16,
className,
].filter(x => x)
return (
{children}
)
}
type H1Props = {
children: React.ReactNode
}
export function Code({ children, ...props }: CodeProps) {
const list = [
C.backgroundFillBase3,
C.textFillBaseContrast,
C.fontNotoSansMono,
C.paddingLr8,
C.paddingTb2,
]
return (
{children}
)
}
type SupProps = React.ComponentPropsWithoutRef<'sup'> & {
children: React.ReactNode
}
export function Column({
children,
fixed = false,
width,
}: ColumnProps) {
const list = []
if (fixed) {
list.push('fixed-column-cue')
}
if (width) {
list.push(C.displayBlock)
}
return (
{children}
)
}
type H2Props = {
children: React.ReactNode
}
export function H1({ children }: H1Props) {
const list = [
C.textFillBaseContrast,
C.fontNotoSans,
C.font32,
C.lineHeight1P7,
C.marginBottom32,
C.marginTop16,
C.widthMax720,
C.paddingLr16,
C.textCenter,
C.width100P,
]
return {children}
}
type H3Props = {
children: React.ReactNode
}
export function H2({ children }: H2Props) {
const list = [
// C.backgroundFillBase3,
C.textCenter,
C.textFillBaseContrast,
C.fontNotoSans,
C.font24,
C.lineHeight1P7,
C.marginBottom16,
C.marginTop32,
C.widthMax720,
C.paddingBottom8,
C.paddingLr16,
C.paddingTop48,
C.width100P,
C.fontBold,
// C.lowercase,
]
return {children}
}
type EmProps = React.ComponentPropsWithoutRef<'em'> & {
children: React.ReactNode
}
export function Em({ children, ...props }: EmProps) {
const list = [C.fontItalic]
return {children}
}
type OlProps = {
children: React.ReactNode
}
export function H3({ children }: H3Props) {
const list = [
C.backgroundFillBase3,
C.textFillBaseContrast,
C.fontNotoSans,
C.font24,
C.lineHeight1P7,
C.marginBottom16,
C.marginTop8,
C.widthMax720,
C.paddingBottom8,
C.paddingLr16,
C.paddingTop16,
C.width100P,
]
return {children}
}
export function Li({ children }: LiProps) {
const list = [
C.textFillBaseContrast,
C.displayListItem,
C.fontNotoSans,
C.font16,
C.lineHeight1P7,
C.marginBottom4,
C.beforeFontNotoSans,
C.beforeTop8,
C.beforePositionAbsolute,
]
return {children}
}
export function Ol({ children }: OlProps) {
const list = [
C.listStyleDecimal,
C.marginTop4,
C.widthMax670,
C.width100P,
C.listStyleInside,
]
return {children}
}
type CodeProps = React.ComponentPropsWithoutRef<'code'> & {
children: React.ReactNode
}
type StrongProps = React.ComponentPropsWithoutRef<'strong'> & {
children: React.ReactNode
}
export function Strong({ children, ...props }: StrongProps) {
const list = [C.fontBold]
return (
{children}
)
}
export function Overlay({ children }: OverlayProps) {
const list = [
C.flex,
C.alignCenter,
C.column,
C.heightMin100P,
C.widthMin300,
C.clipX,
C.scrollY,
C.paddingBottom80Vh,
C.width100P,
C.zIndex100,
]
return {children}
}
type PreProps = React.ComponentPropsWithoutRef<'pre'> & {
children: React.ReactNode
}
export function P({ children, ...props }: PProps) {
const list = [
C.nestedLineHeight1P7,
C.textFillBaseContrast,
C.fontNotoSans,
C.font16,
C.lineHeight1P7,
C.marginTop8,
C.widthMax720,
C.paddingLeft16,
C.paddingRight16,
C.marginBottom16,
C.width100P,
]
return (
{children}
)
}
type TableProps = {
children: React.ReactNode
}
export type PProps = React.ComponentPropsWithoutRef<'p'> & {
children: React.ReactNode
}
type TRProps = React.ComponentPropsWithoutRef<'tr'> & {
children: React.ReactNode
}
export function Pre({ children, ...props }: PreProps) {
const list = [
C.childBackgroundFillBaseContrast,
C.childTextFillBase2,
C.backgroundFillBaseContrast,
C.border4,
C.textFillBase2,
C.fontNotoSansMono,
C.font16,
C.lineHeight1P7,
C.marginBottom24,
C.marginTop16,
C.widthMax720,
C.padding16,
C.whitespacePre,
C.width100P,
C.scrollX,
]
return (
{children}
)
}
type TDProps = React.ComponentPropsWithoutRef<'td'> & {
children: React.ReactNode
padded?: boolean
}
export function Sup({ children, ...props }: SupProps) {
const list = [C.lineHeight1, C.font12, C.topM6]
return (
{children}
)
}
type THProps = React.ComponentPropsWithoutRef<'th'> & {
children: React.ReactNode
}
export function TD({ padded = true, children, ...props }: TDProps) {
const list = [
C.backgroundFillBase,
C.borderRightWidth4,
C.borderRightSolid,
C.borderColorBase4,
C.fontNotoSans,
C.lineHeight1P7,
C.handleAlignCenter,
C.handleAlignRight,
C.lastBorderRightNone,
C.height100P,
C.textFillBaseContrast,
]
if (padded) {
list.push(C.paddingTb12, C.paddingLr16)
}
return (
{children}
|
)
}
type AProps = {
children: React.ReactNode
href: string
rel?: string
target?: string
} & HTMLProps
export function TH({ children, ...props }: THProps) {
const list = [
C.backgroundFillBase3,
C.borderRightWidth4,
C.borderRightSolid,
C.borderColorBase4,
C.fontNotoSans,
C.fontBold,
C.lineHeight1P7,
C.paddingTop12,
C.paddingBottom12,
C.paddingLr16,
C.textLeft,
C.lastBorderRightNone,
C.textFillBaseContrast,
]
return (
{children}
|
)
}
export function TR({ children, ...props }: TRProps) {
const list = [C.height100P, C.every2NChildBackgroundFillBase5]
return (
{children}
)
}
export function Table({ children }: TableProps) {
const list = [
C.height1,
C.widthMax720,
C.scrollY,
C.width100P,
C.borderSeparate,
C.tableFixedHeader,
C.marginBottom16,
]
const ref = useRef(null)
useEffect(() => {
if (!ref.current) {
return
}
const columnList = ref.current.querySelectorAll('.fixed-column-cue')
for (const column of columnList) {
const th = column.closest('th')
if (th) {
const index = th.cellIndex
const tdList: NodeListOf =
ref.current.querySelectorAll(
`tbody tr td:nth-child(${index + 1})`,
)
const rect = th.getBoundingClientRect()
th.style.width = `${rect.width}px`
th.style.height = `${rect.height}px`
th.classList.add(
'left-0',
'top-auto',
'position-sticky',
'z-index-100',
)
for (const td of tdList) {
const rect = td.getBoundingClientRect()
td.style.width = `${rect.width}px`
td.style.height = `${rect.height}px`
td.classList.add(
'left-0',
'top-auto',
'position-sticky',
'z-index-100',
)
}
}
}
}, [ref])
return (
)
}
export const components = {
a: (props: React.ComponentProps) => {
return
},
blockquote: (props: React.ComponentProps) => {
return
},
code: (props: React.ComponentProps) => {
return
},
h1: (props: React.ComponentProps) => {
return
},
h2: (props: React.ComponentProps) => {
return
},
h3: (props: React.ComponentProps) => {
return
},
li: (props: React.ComponentProps) => {
return
},
ol: (props: React.ComponentProps) => {
return
},
p: (props: React.ComponentProps) => {
return
},
pre: (props: React.ComponentProps) => {
return
},
sup: (props: React.ComponentProps) => {
return
},
strong: (props: React.ComponentProps) => {
return
},
em: (props: React.ComponentProps) => {
return
},
table: (props: React.ComponentProps) => {
return (
)
},
td: (props: React.ComponentProps) => {
return (
|
)
},
th: (props: React.ComponentProps) => {
return |
},
tr: (props: React.ComponentProps) => {
return
},
ul: (props: React.ComponentProps) => {
return
},
}
type UlProps = {
children: React.ReactNode
}
export function TableScroller({
children,
borderless = false,
framed = false,
}: TableScrollerProps) {
const list = [
C.borderNone,
C.border4,
C.marginBottom32,
C.marginTop16,
C.heightMax100Vh,
C.widthMax720,
C.width100P,
C.scrollX,
C.stickyTableHeader,
]
if (!borderless) {
list.push(
C.borderBottomWidth4,
C.borderBottomSolid,
C.borderColorBase4,
)
}
if (framed) {
list.push(C.borderWidth4, C.borderSolid, C.borderColorBase4)
}
return {children}
}
type LiProps = {
children: React.ReactNode
}
export type TableScrollerProps = {
borderless?: boolean
children: React.ReactNode
framed?: boolean
}
type OverlayProps = {
children: React.ReactNode
}
export function Ul({ children }: UlProps) {
const list = [
C.listStyleNone,
C.marginBottom12,
C.marginTop8,
C.widthMax720,
C.width100P,
C.paddingLeft38,
C.beforeContentAsterisk,
C.beforeLeft16,
]
return
}
type PropsType = {
background?: string
children: React.ReactNode
}
export default function Content({ children }: PropsType) {
return (
{children}
)
}