Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added traditional Chinese documents #39

Merged
merged 4 commits into from
Dec 15, 2023
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
521 changes: 521 additions & 0 deletions docs/.vitepress/cache/deps/@stackblitz_sdk.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/.vitepress/cache/deps/@stackblitz_sdk.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions docs/.vitepress/cache/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"hash": "b98aed0b",
"browserHash": "3662c0c2",
"optimized": {
"vue": {
"src": "../../../../node_modules/.pnpm/vue@3.2.47/node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "566a3dd0",
"needsInterop": false
},
"@stackblitz/sdk": {
"src": "../../../../node_modules/.pnpm/@stackblitz+sdk@1.9.0/node_modules/@stackblitz/sdk/bundles/sdk.m.js",
"file": "@stackblitz_sdk.js",
"fileHash": "55c10195",
"needsInterop": false
}
},
"chunks": {}
}
3 changes: 3 additions & 0 deletions docs/.vitepress/cache/deps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
9,516 changes: 9,516 additions & 0 deletions docs/.vitepress/cache/deps/vue.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/.vitepress/cache/deps/vue.js.map

Large diffs are not rendered by default.

69 changes: 16 additions & 53 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
import { defineConfig } from 'vitepress'

const guide = [
{
text: 'Get Started',
link: '/guide/',
},
]

const api = [
{
text: 'useForm',
link: '/api/use-form',
},
{
text: 'useField',
link: '/api/use-field',
},
{
text: 'useFieldArray',
link: '/api/use-field-array',
},
{
text: 'useFormContext',
link: '/api/use-form-context',
},
]

const advanced = [
{
text: 'Smart Form Component',
link: '/advanced/smart-form-component',
},
]
import enConfig from './theme/config/en'
import zhTWConfig from './theme/config/zh-tw'

export default defineConfig({
title: 'Vorms',
Expand Down Expand Up @@ -64,38 +33,32 @@ export default defineConfig({
}
},

locales: {
root: {
label: 'English',
lang: 'en',
themeConfig: enConfig
},
'zh-tw': {
label: '็น้ซ”ไธญๆ–‡',
lang: 'zh-tw',
link: '/zh-tw/',
themeConfig: zhTWConfig
}
},

themeConfig: {
logo: '/favicon.svg',

editLink: {
pattern: 'https://github.com/Mini-ghost/vorms/tree/docs/docs/:path'
},

nav: [
{ text: 'Get Started', link: '/guide/', activeMatch: '/guide/' },
{ text: 'API', link: '/api/use-form', activeMatch: '/api/' },
{ text: 'Examples', link: '/examples/', activeMatch: '/examples/' }
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/Mini-ghost/vorms' },
],

sidebar: [
{
text: 'Guide',
items: guide
},
{
text: 'API Reference',
items: api
},
{
text: 'Advanced',
items: advanced
}
],

footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright ยฉ 2022-present Alex Liu'
Expand Down
55 changes: 55 additions & 0 deletions docs/.vitepress/theme/config/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const guide = [
{
text: 'Get Started',
link: '/guide/',
},
]

const api = [
{
text: 'useForm',
link: '/api/use-form',
},
{
text: 'useField',
link: '/api/use-field',
},
{
text: 'useFieldArray',
link: '/api/use-field-array',
},
{
text: 'useFormContext',
link: '/api/use-form-context',
},
]

const advanced = [
{
text: 'Smart Form Component',
link: '/advanced/smart-form-component',
},
]

export default {
nav: [
{ text: 'Get Started', link: '/guide/', activeMatch: '/guide/' },
{ text: 'API', link: '/api/use-form', activeMatch: '/api/' },
{ text: 'Examples', link: '/examples/', activeMatch: '/examples/' }
],

sidebar: [
{
text: 'Guide',
items: guide
},
{
text: 'API Reference',
items: api
},
{
text: 'Advanced',
items: advanced
}
],
}
55 changes: 55 additions & 0 deletions docs/.vitepress/theme/config/zh-tw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const guide = [
{
text: 'Get Started',
link: '/zh-tw/guide/',
},
]

const api = [
{
text: 'useForm',
link: '/zh-tw/api/use-form',
},
{
text: 'useField',
link: '/zh-tw/api/use-field',
},
{
text: 'useFieldArray',
link: '/zh-tw/api/use-field-array',
},
{
text: 'useFormContext',
link: '/zh-tw/api/use-form-context',
},
]

const advanced = [
{
text: 'Smart Form Component',
link: '/zh-tw/advanced/smart-form-component',
},
]

export default {
nav: [
{ text: 'Get Started', link: '/zh-tw/guide/', activeMatch: '/guide/' },
{ text: 'API', link: '/zh-tw/api/use-form', activeMatch: '/api/' },
{ text: 'Examples', link: '/zh-tw/examples/', activeMatch: '/examples/' }
],

sidebar: [
{
text: 'Guide',
items: guide
},
{
text: 'API Reference',
items: api
},
{
text: 'Advanced',
items: advanced
}
],
}
134 changes: 134 additions & 0 deletions docs/zh-tw/advanced/smart-form-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Smart Form Component

้›–็„ถ Vue ็š„ `v-model` ๆŒ‡ไปคๅนซๅŠฉๆˆ‘ๅ€‘็ฐกๅŒ–ไบ†่กจๅ–ฎ่ผธๅ…ฅ็ถๅฎš๏ผŒไฝ†่™•็†ๅคงๅž‹ไธ”่ค‡้›œ็š„่กจๅ–ฎไป็„ถๆœ‰้ปž็—›่‹ฆใ€‚

ๆ™บๆ…ง่กจๅ–ฎๅ…ƒไปถ๏ผˆSmart Form Components๏ผ‰ๅฏไปฅๅนซๅŠฉๆˆ‘ๅ€‘้€ฒไธ€ๆญฅ็ฐกๅŒ–่กจๅ–ฎๅปบ็ฝฎใ€‚ ๆˆ‘ๅ€‘ๅช้œ€่ฆ็ต„ๅˆ้‚ฃไบ›่กจๅ–ฎๅ…ƒไปถ๏ผŒๅฎƒๅฐฑๆœƒ่‡ชๅ‹•ๅŒน้…ๅฐๆ‡‰็š„่กจๅ–ฎ่ณ‡ๆ–™ไธฆๅฎŒๆˆ่ผธๅ…ฅ็ถๅฎšใ€‚

```vue
<script setup lang="ts">
import SmartForm from './components/SmartForm.vue'
import SmartTextField from './components/SmartTextField.vue'
import SmartSelect from './components/SmartSelect.vue'

interface Values {
drink: string,
sugar: 'no' | 'light' | 'half' | 'half' | 'standard'
}

const initialValues = {
drink: '',
sugar: 'light',
}

const onSubmit = (values: Values) => {
console.log(values);

}

</script>

<template>
<div>
<SmartForm :initial-values="initialValues" @submit="onSubmit">
<SmartTextField name="name" />
<SmartSelect name="sugar" :options="['no', 'light', 'half', 'half', 'standard']" />

<button type="submit">Submit</button>
</SmartForm>
</div>
</template>
```

่ฎ“ๆˆ‘ๅ€‘็œ‹็œ‹ๅฆ‚ไฝ•็ทจๅฏซ้€™ไบ›ๅ…ƒไปถใ€‚

## SmartForm

SmartForm ๅ…ƒไปถๅฐ‡็‚บๅ…ƒไปถ็š„ๅพŒไปฃๆไพ› vorms ็š„็‹€ๆ…‹ๅ’Œๆ–นๆณ•ใ€‚

```vue
<script setup lang="ts">
import { useForm } from '@vorms/core';

type Values = Record<string, any>;

interface SmartFormProps {
initialValues: Values;
}

interface SmartFormEvent {
(event: 'submit', values: Values): void;
}

const props = defineProps<SmartFormProps>();
const emit = defineEmits<SmartFormEvent>();

const { handleSubmit, handleReset } = useForm({
initialValues: props.initialValues,
onSubmit(values) {
emit('submit', values);
},
});
</script>

<template>
<form @submit="handleSubmit" @reset="handleReset">
<slot name="default" />
</form>
</template>
```

## SmartTextField ๅ’Œ SmartSelect

้€™ไบ›่ผธๅ…ฅๅ…ƒไปถๅฐ‡ๆณจๅ…ฅ SmartForm ๅ…ƒไปถๆไพ›็š„็‹€ๆ…‹ๅ’Œๆ–นๆณ•๏ผŒไธฆๅœจ่ƒŒๆ™ฏ่™•็†่กจๅ–ฎ่ผธๅ…ฅ็ถๅฎšใ€‚

**SmartTextField**

```vue
<script setup lang="ts">
import { toRef } from 'vue'
import { useField } from '@vorms/core'

interface SmartTextFieldProps {
name: string;
}

const props = defineProps<SmartTextFieldProps>()

const nameRef = toRef(props, 'name')
const { value, attrs } = useField(nameRef)
</script>

<template>
<input v-model="value" type="text" v-bind="attrs">
</template>
```

**SmartSelect**

```vue
<script setup lang="ts">
import { toRef } from 'vue'
import { useField } from '@vorms/core'

interface SmartSelectProps {
name: string;
options: string[]
}

const props = defineProps<SmartSelectProps>()

const nameRef = toRef(props, 'name')
const { value, attrs } = useField(nameRef)
</script>

<template>
<select v-model="value" v-bind="attrs">
<option v-for="item in options" :key="item" :value="item">
{{ item }}
</option>
</select>
</template>
```

็พๅœจ๏ผŒๆ‚จๅฏไปฅๅœจๅฐˆๆกˆไธญๅ‰ตๅปบๅ’Œ็ต„ๅˆ่ค‡้›œ็š„ๅ…งๅฎน๏ผŒ่€Œ็„ก็ธซๆŽฅ่ปŒใ€‚
้€™ๅ€‹็†ๆƒณ็š„้ˆๆ„Ÿไพ†่‡ช [React Hook Form](https://react-hook-form.com/advanced-usage#SmartFormComponent)
Loading
Loading