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
94 changes: 94 additions & 0 deletions docs-nextra/app/_components/api-reference.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { FC } from 'react'
import styles from './controller-docs.module.css'

export type Locale = 'en' | 'zh'
export type LocalizedText = Readonly<Record<Locale, string>>

export type ApiRow = Readonly<{
name: string
type: string
defaultValue: string
description: LocalizedText
required?: boolean
}>

export type ApiSection = Readonly<{
name: string
inherited: LocalizedText
rows: readonly ApiRow[]
}>

export const localizedText = (en: string, zh: string): LocalizedText => ({ en, zh })

const labels = {
en: {
defaultValue: 'Default',
description: 'Description',
name: 'Prop',
required: 'required',
type: 'Type',
},
zh: {
defaultValue: '默认值',
description: '说明',
name: '属性',
required: '必填',
type: '类型',
},
} as const

type ApiTableProps = Readonly<{
lang: Locale
section: ApiSection
}>

export const ApiTable: FC<ApiTableProps> = ({ lang, section }) => {
const localeLabels = labels[lang]

return (
<section className={styles.apiSection} aria-labelledby={`${section.name}-api`}>
<h3 className={styles.apiHeading} id={`${section.name}-api`}>
{section.name}
</h3>
<p className={styles.apiInherited}>{section.inherited[lang]}</p>
{section.rows.length > 0 && (
<div className={styles.tableWrap}>
<table className={styles.apiTable}>
<caption className={styles.visuallyHidden}>
{section.name} {lang === 'zh' ? '公开属性' : 'public props'}
</caption>
<thead>
<tr>
<th scope="col">{localeLabels.name}</th>
<th scope="col">{localeLabels.type}</th>
<th scope="col">{localeLabels.defaultValue}</th>
<th scope="col">{localeLabels.description}</th>
</tr>
</thead>
<tbody>
{section.rows.map((row) => (
<tr key={row.name}>
<td className={styles.propName} data-label={localeLabels.name}>
<code>{row.name}</code>
{row.required && (
<span className={styles.required} title={localeLabels.required}>
*
</span>
)}
</td>
<td data-label={localeLabels.type}>
<code>{row.type}</code>
</td>
<td data-label={localeLabels.defaultValue}>
<code>{row.defaultValue}</code>
</td>
<td data-label={localeLabels.description}>{row.description[lang]}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</section>
)
}
92 changes: 1 addition & 91 deletions docs-nextra/app/_components/controller-api.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
import type { FC } from 'react'
import styles from './controller-docs.module.css'
import { ApiTable, localizedText as text, type ApiSection, type Locale } from './api-reference'

export type ControllerName =
'button' | 'checkbox' | 'envelope' | 'input' | 'knob' | 'radio' | 'slider' | 'switch'

type Locale = 'en' | 'zh'
type LocalizedText = Readonly<Record<Locale, string>>

type ApiRow = Readonly<{
name: string
type: string
defaultValue: string
description: LocalizedText
required?: boolean
}>

type ApiSection = Readonly<{
name: string
inherited: LocalizedText
rows: readonly ApiRow[]
}>

type ControllerApiDefinition = Readonly<{
main: ApiSection
group?: ApiSection
}>

const text = (en: string, zh: string): LocalizedText => ({ en, zh })

const definitions: Record<ControllerName, ControllerApiDefinition> = {
button: {
main: {
Expand Down Expand Up @@ -966,77 +947,6 @@ const definitions: Record<ControllerName, ControllerApiDefinition> = {
},
}

const labels = {
en: {
defaultValue: 'Default',
description: 'Description',
name: 'Prop',
required: 'required',
type: 'Type',
},
zh: {
defaultValue: '默认值',
description: '说明',
name: '属性',
required: '必填',
type: '类型',
},
} as const

type ApiTableProps = Readonly<{
lang: Locale
section: ApiSection
}>

const ApiTable: FC<ApiTableProps> = ({ lang, section }) => {
const localeLabels = labels[lang]

return (
<section className={styles.apiSection} aria-labelledby={`${section.name}-api`}>
<h3 className={styles.apiHeading} id={`${section.name}-api`}>
{section.name}
</h3>
<p className={styles.apiInherited}>{section.inherited[lang]}</p>
<div className={styles.tableWrap}>
<table className={styles.apiTable}>
<caption className={styles.visuallyHidden}>
{section.name} {lang === 'zh' ? '公开属性' : 'public props'}
</caption>
<thead>
<tr>
<th scope="col">{localeLabels.name}</th>
<th scope="col">{localeLabels.type}</th>
<th scope="col">{localeLabels.defaultValue}</th>
<th scope="col">{localeLabels.description}</th>
</tr>
</thead>
<tbody>
{section.rows.map((row) => (
<tr key={row.name}>
<td className={styles.propName} data-label={localeLabels.name}>
<code>{row.name}</code>
{row.required && (
<span className={styles.required} title={localeLabels.required}>
*
</span>
)}
</td>
<td data-label={localeLabels.type}>
<code>{row.type}</code>
</td>
<td data-label={localeLabels.defaultValue}>
<code>{row.defaultValue}</code>
</td>
<td data-label={localeLabels.description}>{row.description[lang]}</td>
</tr>
))}
</tbody>
</table>
</div>
</section>
)
}

type ControllerApiProps = Readonly<{
controller: ControllerName
lang: Locale
Expand Down
Loading