-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): [form] add xDesign theme (#1507)
- Loading branch information
Showing
13 changed files
with
372 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
examples/sites/demos/pc/app/form/error-slot-composition-api.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<div class="demo-form"> | ||
<tiny-form ref="ruleFormRef" :model="createData" :rules="rules"> | ||
<tiny-form-item label="姓名" prop="name"> | ||
<tiny-input v-model="createData.name"></tiny-input> | ||
</tiny-form-item> | ||
<tiny-form-item label="年龄" prop="age"> | ||
<tiny-input v-model="createData.age"></tiny-input> | ||
<template #error> | ||
<span>错误提示内容插槽</span> | ||
</template> | ||
</tiny-form-item> | ||
<tiny-form-item label="昵称" prop="nickname" validate-type="text"> | ||
<tiny-input v-model="createData.nickname"></tiny-input> | ||
<template #error="message"> | ||
<span class="error-slot">{{ message }}</span> | ||
</template> | ||
</tiny-form-item> | ||
<tiny-form-item> | ||
<tiny-button type="primary" @click="validateField"> 校验 </tiny-button> | ||
</tiny-form-item> | ||
</tiny-form> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
import { Form as TinyForm, FormItem as TinyFormItem, Input as TinyInput, Button as TinyButton } from '@opentiny/vue' | ||
const createData = ref({ | ||
name: '', | ||
age: '', | ||
nickname: '' | ||
}) | ||
const rules = ref({ | ||
name: [ | ||
{ required: true, message: '必填', trigger: 'blur' }, | ||
{ min: 2, max: 11, message: '长度必须不小于2', trigger: ['change', 'blur'] } | ||
], | ||
age: { required: true }, | ||
nickname: [ | ||
{ required: true, message: '昵称必填' }, | ||
{ min: 2, max: 11, message: '昵称长度必须不小于2切不大于11', trigger: ['change', 'blur'] } | ||
] | ||
}) | ||
const ruleFormRef = ref() | ||
function validateField() { | ||
ruleFormRef.value.validate(() => {}) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.demo-form { | ||
width: 380px; | ||
} | ||
.error-slot { | ||
color: #ffd0a6; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test('错误提示插槽', async ({ page }) => { | ||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
await page.goto('form#error-slot') | ||
|
||
const demo = page.locator('#error-slot') | ||
const getTooltipByText = (text: string) => page.locator('.tiny-tooltip').getByText(text) | ||
const validBtn = demo.getByRole('button', { name: '校验' }).first() | ||
|
||
await validBtn.click() | ||
await expect(getTooltipByText('必填')).toBeVisible() | ||
await expect(getTooltipByText('错误提示内容插槽')).toBeVisible() | ||
await expect(page.locator('.error-slot')).toBeVisible() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<template> | ||
<div class="demo-form"> | ||
<tiny-form ref="ruleFormRef" :model="createData" :rules="rules"> | ||
<tiny-form-item label="姓名" prop="name"> | ||
<tiny-input v-model="createData.name"></tiny-input> | ||
</tiny-form-item> | ||
<tiny-form-item label="年龄" prop="age"> | ||
<tiny-input v-model="createData.age"></tiny-input> | ||
<template #error> | ||
<span>错误提示内容插槽</span> | ||
</template> | ||
</tiny-form-item> | ||
<tiny-form-item label="昵称" prop="nickname" validate-type="text"> | ||
<tiny-input v-model="createData.nickname"></tiny-input> | ||
<template #error="message"> | ||
<span class="error-slot">{{ message }}</span> | ||
</template> | ||
</tiny-form-item> | ||
<tiny-form-item> | ||
<tiny-button type="primary" @click="validateField"> 校验 </tiny-button> | ||
</tiny-form-item> | ||
</tiny-form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { Form, FormItem, Input, Button } from '@opentiny/vue' | ||
export default { | ||
components: { | ||
TinyForm: Form, | ||
TinyFormItem: FormItem, | ||
TinyInput: Input, | ||
TinyButton: Button | ||
}, | ||
data() { | ||
return { | ||
createData: { | ||
name: '', | ||
age: '', | ||
nickname: '' | ||
}, | ||
rules: { | ||
name: [ | ||
{ required: true, message: '必填', trigger: 'blur' }, | ||
{ min: 2, max: 11, message: '长度必须不小于2', trigger: ['change', 'blur'] } | ||
], | ||
age: { required: true }, | ||
nickname: [ | ||
{ required: true, message: '昵称必填' }, | ||
{ min: 2, max: 11, message: '昵称长度必须不小于2切不大于11', trigger: ['change', 'blur'] } | ||
] | ||
} | ||
} | ||
}, | ||
methods: { | ||
validateField() { | ||
this.$refs.ruleFormRef.validate(() => {}) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.demo-form { | ||
width: 380px; | ||
} | ||
.error-slot { | ||
color: #ffd0a6; | ||
} | ||
</style> |
48 changes: 48 additions & 0 deletions
48
examples/sites/demos/pc/app/form/extra-tip-composition-api.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<div class="demo-form"> | ||
<tiny-form ref="ruleFormRef" :model="createData" :rules="rules" validate-type="text"> | ||
<tiny-form-item label="姓名" prop="name" extra="需要填写真实姓名"> | ||
<tiny-input v-model="createData.name"></tiny-input> | ||
</tiny-form-item> | ||
<tiny-form-item label="年龄" prop="age" extra="需要填写真实年龄"> | ||
<tiny-input v-model="createData.age"></tiny-input> | ||
</tiny-form-item> | ||
<tiny-form-item> | ||
<tiny-button type="primary" @click="submit"> 提交 </tiny-button> | ||
</tiny-form-item> | ||
</tiny-form> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
import { Form as TinyForm, FormItem as TinyFormItem, Input as TinyInput, Button as TinyButton } from '@opentiny/vue' | ||
const createData = ref({ | ||
name: '', | ||
age: '' | ||
}) | ||
const rules = ref({ | ||
name: [ | ||
{ required: true, message: '必填' }, | ||
{ min: 2, max: 11, message: '长度必须不小于2' } | ||
], | ||
age: { required: true } | ||
}) | ||
const ruleFormRef = ref() | ||
function submit() { | ||
ruleFormRef.value.validate(() => {}) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.demo-form { | ||
width: 380px; | ||
} | ||
.error-slot { | ||
color: #ffd0a6; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test('错误提示插槽', async ({ page }) => { | ||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
await page.goto('form#extra-tip') | ||
|
||
const demo = page.locator('#extra-tip') | ||
const validBtn = demo.getByRole('button', { name: '提交' }).first() | ||
|
||
await expect(demo.getByText('需要填写真实姓名')).toBeVisible() | ||
await expect(demo.getByText('需要填写真实年龄')).toBeVisible() | ||
await validBtn.click() | ||
await expect(demo.getByText('需要填写真实姓名')).toBeVisible() | ||
await expect(demo.getByText('需要填写真实年龄')).toBeVisible() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<div class="demo-form"> | ||
<tiny-form ref="ruleFormRef" :model="createData" :rules="rules" validate-type="text"> | ||
<tiny-form-item label="姓名" prop="name" extra="需要填写真实姓名"> | ||
<tiny-input v-model="createData.name"></tiny-input> | ||
</tiny-form-item> | ||
<tiny-form-item label="年龄" prop="age" extra="需要填写真实年龄"> | ||
<tiny-input v-model="createData.age"></tiny-input> | ||
</tiny-form-item> | ||
<tiny-form-item> | ||
<tiny-button type="primary" @click="submit"> 提交 </tiny-button> | ||
</tiny-form-item> | ||
</tiny-form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { Form, FormItem, Input, Button } from '@opentiny/vue' | ||
export default { | ||
components: { | ||
TinyForm: Form, | ||
TinyFormItem: FormItem, | ||
TinyInput: Input, | ||
TinyButton: Button | ||
}, | ||
data() { | ||
return { | ||
createData: { | ||
name: '', | ||
age: '' | ||
}, | ||
rules: { | ||
name: [ | ||
{ required: true, message: '必填' }, | ||
{ min: 2, max: 11, message: '长度必须不小于2' } | ||
], | ||
age: { required: true } | ||
} | ||
} | ||
}, | ||
methods: { | ||
submit() { | ||
this.$refs.ruleFormRef.validate(() => {}) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.demo-form { | ||
width: 380px; | ||
} | ||
.error-slot { | ||
color: #ffd0a6; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.