Skip to content
Open
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
14 changes: 9 additions & 5 deletions apps/landing/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ for (const entry of res) {
}

await writeFile('public/search.json', JSON.stringify([...search.values()]))
const koreanSearch = new Map(search)
// Korean files replace their English entry. A component page has two
// (index.ko.mdx and Api.ko.mdx), merged into one entry like the English ones.
const koreanEntries = new Map()
for await (const file of glob('src/app/(detail)/**/*.ko.mdx')) {
const content = await readFile(file, 'utf8')
const heading = /^#{1,6} (.+)$/mu.exec(content)
Expand All @@ -57,12 +59,14 @@ for await (const file of glob('src/app/(detail)/**/*.ko.mdx')) {
.replace('src/app/(detail)', '')
.replace('/[component]', '')
.replace(/\/(?:page|index|Api|Description)\.ko\.mdx$/u, '')
koreanSearch.set(url, {
title: heading[1],
text: content.slice(heading.index),
const entry = { title: heading[1], text: content.slice(heading.index), url }
const previous = koreanEntries.get(url)
koreanEntries.set(
url,
})
previous ? { ...previous, text: `${previous.text}\n${entry.text}` } : entry,
)
}
const koreanSearch = new Map([...search, ...koreanEntries])
await writeFile(
'public/search.ko.json',
JSON.stringify([...koreanSearch.values()]),
Expand Down
129 changes: 129 additions & 0 deletions apps/landing/src/app/(detail)/components/ComponentDoc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { Box, Flex, Text, VStack } from '@devup-ui/react'
import type { MDXProps } from 'mdx/types'
import type { Metadata } from 'next'
import { createTranslator, type Locale } from 'next-intl'
import { getTranslations } from 'next-intl/server'
import type { ComponentType } from 'react'

import { CustomCode } from '@/components/mdx/components/CustomCode'
import { CustomH4 } from '@/components/mdx/components/CustomH4'
import { CustomH6 } from '@/components/mdx/components/CustomH6'
import { CustomParagraph } from '@/components/mdx/components/CustomParagraph'
import { CustomPre } from '@/components/mdx/components/CustomPre'
import { CustomStrong } from '@/components/mdx/components/CustomStrong'
import { PropsTable } from '@/components/PropsTable'
import { getLocaleMessages } from '@/i18n/messages'
import { getDemos } from '@/utils/get-demos'

import MdxCard from './MdxCard'

/** `date-picker` -> `Date Picker`; the component name stays English. */
export function getComponentName(component: string) {
return component
.split('-')
.map((item) => item.charAt(0).toUpperCase() + item.slice(1))
.join(' ')
}

export function getComponentMetadata(
component: string,
locale: Locale = 'en',
): Metadata {
const t = createTranslator({
locale,
messages: getLocaleMessages(locale),
namespace: 'ComponentPage',
})
const name = getComponentName(component)
const englishPath = `/components/${component}`
const path = locale === 'en' ? englishPath : `/${locale}${englishPath}`
const title = `Devup UI - ${name}`
const description = t('description', { name })
return {
title,
description,
alternates: {
canonical: path,
languages: {
en: englishPath,
ko: `/ko${englishPath}`,
'x-default': englishPath,
},
},
openGraph: {
title,
description,
url: path,
siteName: 'Devup UI',
images: [`/components-og/${component}.webp`],
},
}
}

interface ComponentDocProps {
component: string
Index: ComponentType<MDXProps>
Api: ComponentType<MDXProps>
locale?: Locale
}

export async function ComponentDoc({
component,
Index,
Api,
locale = 'en',
}: ComponentDocProps) {
const t = await getTranslations({ locale, namespace: 'ComponentPage' })
const c = await getDemos(component)
const m = Math.ceil(c.length / 2)
const componentName = getComponentName(component)

return (
<VStack gap="16px" maxW="100%" overflow="hidden">
<Text as="strong" color="$primary" m="0" typography="captionBold">
{componentName}
</Text>
<Text as="h1" color="$title" m="0" typography="h4">
{componentName}
</Text>
<Index
components={{
h4: CustomH4,
h6: CustomH6,
pre: CustomPre,
strong: CustomStrong,
p: CustomParagraph,
}}
/>
<VStack gap="16px" py="30px">
<Text as="h2" color="$title" m="0" typography="h6">
{t('examples')}
</Text>
<Flex flexWrap="wrap" gap="16px">
<Box flex="1" minW="300px" w="calc(50% - 8px)">
{c.slice(0, m).map(([Demo, src]) => (
<MdxCard key={src} demo={<Demo />} src={src} />
))}
</Box>
<Box flex="1" minW="300px" w="calc(50% - 8px)">
{c.slice(m).map(([Demo, src]) => (
<MdxCard key={src} demo={<Demo />} src={src} />
))}
</Box>
</Flex>
</VStack>
<VStack gap="16px" py="30px">
<Api
components={{
code: CustomCode,
h4: CustomH4,
h6: CustomH6,
pre: CustomPre,
p: CustomParagraph,
PropsTable,
}}
/>
</VStack>
</VStack>
)
}
6 changes: 4 additions & 2 deletions apps/landing/src/app/(detail)/components/MdxCardFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { Box, Center, Flex, Grid, Image, Text, VStack } from '@devup-ui/react'
import { useTranslations } from 'next-intl'
import { useState } from 'react'

import IconCode from '@/components/icons/IconCode'
Expand All @@ -12,6 +13,7 @@ export default function MdxCardFooter({
code: string
children: React.ReactNode
}) {
const t = useTranslations('ComponentPage')
const [isOpen, setIsOpen] = useState(false)
const [copied, setCopied] = useState(false)

Expand Down Expand Up @@ -53,7 +55,7 @@ export default function MdxCardFooter({
w="fit-content"
>
<IconCode open={isOpen} />
<Text>Show Code</Text>
<Text>{t('showCode')}</Text>
</Center>
</Flex>
<Grid
Expand Down Expand Up @@ -92,7 +94,7 @@ export default function MdxCardFooter({
src={copied ? '/icons/copied.svg' : '/icons/copy-code.svg'}
/>
<Text color="$captionBold" typography="caption">
Copy
{t('copy')}
</Text>
</Center>
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ComingSoon } from '@/components/ComingSoon'

<ComingSoon />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`Bottom Sheet` 컴포넌트는 화면 하단에서 위로 올라오는 패널에 콘텐츠를 표시합니다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
ComponentDoc,
getComponentMetadata,
} from '@/app/(detail)/components/ComponentDoc'

import Api from './Api.ko.mdx'
import Index from './index.ko.mdx'

export const metadata = getComponentMetadata('bottom-sheet', 'ko')

export default function Page() {
return (
<ComponentDoc
Api={Api}
component="bottom-sheet"
Index={Index}
locale="ko"
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { PropsTable } from '@/components/PropsTable'

###### API

`Button` props는 button HTML 속성을 확장합니다.

<PropsTable
componentProps={[
{
property: 'variant',
description: '버튼의 variant',
type: "`'primary' | 'default'`",
default: "`'default'`",
},
{
property: 'colors',
description: '버튼의 색상 변수(예: `var(--primary)`)',
type: '```{<br> primary?: string<br> error?: string<br> text?: string<br> border?: string<br> inputBackground?: string<br> primaryFocus?: string<br>}```',
default: '`undefined`',
},
{
property: 'danger',
description:
'주의해서 사용해야 하는 동작임을 나타냅니다. 주로 삭제 버튼이나 오류 상태를 표시할 때 사용합니다.',
type: '`boolean`',
default: '`false`',
},
{
property: 'size',
description: '버튼의 크기',
type: "`'sm' | 'md' | 'lg'`",
default: "`'md'`",
},
{
property: 'icon',
description: 'ReactNode 형태로 전달하는 버튼의 아이콘',
type: '`React.ReactNode`',
default: '`undefined`',
},
{
property: 'ellipsis',
description:
'버튼 텍스트를 말줄임표로 자를지 여부. 텍스트를 자르려면 버튼에 너비가 지정되어 있어야 합니다.',
type: '`boolean`',
default: '`false`',
},
]}
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`Button` 컴포넌트는 사용자 상호작용을 처리하는 데 사용합니다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
ComponentDoc,
getComponentMetadata,
} from '@/app/(detail)/components/ComponentDoc'

import Api from './Api.ko.mdx'
import Index from './index.ko.mdx'

export const metadata = getComponentMetadata('button', 'ko')

export default function Page() {
return <ComponentDoc Api={Api} component="button" Index={Index} locale="ko" />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { PropsTable } from '@/components/PropsTable'

###### API

`Checkbox` props는 input HTML 속성(`type`, `onChange` 제외)을 확장합니다.

<PropsTable
componentProps={[
{
property: 'children',
description: '체크박스의 레이블 내용',
type: '`React.ReactNode`',
default: '-',
},
{
property: 'checked',
description: '체크박스의 선택 여부(제어)',
type: '`boolean`',
default: '`undefined`',
},
{
property: 'defaultChecked',
description: '체크박스의 기본 선택 여부(비제어)',
type: '`boolean`',
default: '`false`',
},
{
property: 'disabled',
description: '체크박스의 비활성화 여부',
type: '`boolean`',
default: '`false`',
},
{
property: 'onChange',
description: '선택 상태가 바뀔 때 호출되는 콜백',
type: '`(checked: boolean) => void`',
default: '`undefined`',
},
{
property: 'colors',
description: '체크박스의 사용자 정의 색상 변수',
type: '```{<br> primary?: string<br> border?: string<br> text?: string<br> inputBg?: string<br> checkIcon?: string<br>}```',
default: '`undefined`',
},
]}
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`Checkbox` 컴포넌트는 사용자가 여러 옵션을 선택할 수 있게 합니다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
ComponentDoc,
getComponentMetadata,
} from '@/app/(detail)/components/ComponentDoc'

import Api from './Api.ko.mdx'
import Index from './index.ko.mdx'

export const metadata = getComponentMetadata('checkbox', 'ko')

export default function Page() {
return (
<ComponentDoc Api={Api} component="checkbox" Index={Index} locale="ko" />
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ComingSoon } from '@/components/ComingSoon'

<ComingSoon />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`Color Picker` 컴포넌트는 사용자가 색상 팔레트에서 색상을 선택할 수 있게 합니다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
ComponentDoc,
getComponentMetadata,
} from '@/app/(detail)/components/ComponentDoc'

import Api from './Api.ko.mdx'
import Index from './index.ko.mdx'

export const metadata = getComponentMetadata('color-picker', 'ko')

export default function Page() {
return (
<ComponentDoc
Api={Api}
component="color-picker"
Index={Index}
locale="ko"
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ComingSoon } from '@/components/ComingSoon'

<ComingSoon />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`Confirm` 컴포넌트는 사용자에게 확인 대화 상자를 표시합니다.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
ComponentDoc,
getComponentMetadata,
} from '@/app/(detail)/components/ComponentDoc'

import Api from './Api.ko.mdx'
import Index from './index.ko.mdx'

export const metadata = getComponentMetadata('confirm', 'ko')

export default function Page() {
return (
<ComponentDoc Api={Api} component="confirm" Index={Index} locale="ko" />
)
}
Loading
Loading