Skip to content

Commit c7dbb67

Browse files
authored
feat(form): [form] form component adapt to old theme (#2562)
1 parent 7095d44 commit c7dbb67

File tree

15 files changed

+128
-13
lines changed

15 files changed

+128
-13
lines changed

examples/sites/demos/apis/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default {
4444
{
4545
name: 'hide-required-asterisk',
4646
type: 'boolean',
47-
defaultValue: 'true',
47+
defaultValue: 'false',
4848
desc: {
4949
'zh-CN': '是否隐藏必填字段的标签旁边的红色星号',
5050
'en-US': 'Whether to hide the red asterisk next to the label of mandatory fields'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<div>
3+
<tiny-config-provider :design="design">
4+
<tiny-form :model="formData" class="demo-form">
5+
<tiny-form-item label="年龄" prop="age" required>
6+
<tiny-numeric v-model="formData.age"></tiny-numeric>
7+
</tiny-form-item>
8+
<tiny-form-item label="姓名" prop="name" required>
9+
<tiny-input v-model="formData.name"></tiny-input>
10+
</tiny-form-item>
11+
</tiny-form>
12+
</tiny-config-provider>
13+
</div>
14+
</template>
15+
16+
<script setup>
17+
import { ref } from 'vue'
18+
import { TinyConfigProvider, TinyForm, TinyFormItem, TinyInput, TinyNumeric } from '@opentiny/vue'
19+
20+
const design = ref({
21+
name: 'smb', // 设计规范名称
22+
version: '1.0.0', // 设计规范版本号
23+
components: {
24+
Form: {
25+
hideRequiredAsterisk: true
26+
}
27+
}
28+
})
29+
30+
const formData = ref({
31+
name: '',
32+
age: ''
33+
})
34+
</script>
35+
36+
<style scoped>
37+
.demo-form {
38+
width: 380px;
39+
}
40+
</style>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('测试隐藏星号', async ({ page }) => {
4+
page.on('pageerror', (exception) => expect(exception).toBeNull())
5+
await page.goto('config-provider#form')
6+
7+
await expect(page.locator('#form .tiny-form')).toBeVisible()
8+
const beforeElement = await page.evaluate(() => {
9+
const labelBefore = document.querySelector('.tiny-form .tiny-form-item__label')
10+
const { display, content } = window.getComputedStyle(labelBefore, '::before')
11+
return { display, content }
12+
})
13+
expect(beforeElement.content).toBe('none')
14+
})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<div>
3+
<tiny-config-provider :design="design">
4+
<tiny-form :model="formData" class="demo-form">
5+
<tiny-form-item label="年龄" prop="age" required>
6+
<tiny-numeric v-model="formData.age"></tiny-numeric>
7+
</tiny-form-item>
8+
<tiny-form-item label="姓名" prop="name" required>
9+
<tiny-input v-model="formData.name"></tiny-input>
10+
</tiny-form-item>
11+
</tiny-form>
12+
</tiny-config-provider>
13+
</div>
14+
</template>
15+
16+
<script>
17+
import { TinyConfigProvider, TinyForm, TinyFormItem, TinyInput, TinyNumeric } from '@opentiny/vue'
18+
19+
export default {
20+
components: {
21+
TinyConfigProvider,
22+
TinyForm,
23+
TinyFormItem,
24+
TinyInput,
25+
TinyNumeric
26+
},
27+
data() {
28+
return {
29+
design: {
30+
name: 'smb', // 设计规范名称
31+
version: '1.0.0', // 设计规范版本号
32+
components: {
33+
Form: {
34+
hideRequiredAsterisk: true
35+
}
36+
}
37+
},
38+
formData: {
39+
name: '',
40+
age: ''
41+
}
42+
}
43+
}
44+
}
45+
</script>
46+
47+
<style scoped>
48+
.demo-form {
49+
width: 380px;
50+
}
51+
</style>

examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ export default {
4040
'en-US': 'Container labels can be customized through<code>tag</code>.'
4141
},
4242
codeFiles: ['tag.vue']
43+
},
44+
{
45+
demoId: 'form',
46+
name: {
47+
'zh-CN': '隐藏表单必填星号',
48+
'en-US': 'Hide all form required asterisks'
49+
},
50+
desc: {
51+
'zh-CN': '通过 <code>design</code> 设置所有表单组件默认不显示必填星号。',
52+
'en-US': 'Set the all form component via <code>design</code> to not display required asterisks by default.'
53+
},
54+
codeFiles: ['form.vue']
4355
}
4456
]
4557
}

examples/sites/demos/pc/app/form/smb-required.spec.ts renamed to examples/sites/demos/pc/app/form/hide-required.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { test, expect } from '@playwright/test'
22

33
test('必填项红色星号', async ({ page }) => {
44
page.on('pageerror', (exception) => expect(exception).toBeNull())
5-
await page.goto('form#smb-required')
5+
await page.goto('form#hide-required')
66

7-
const demo = page.locator('#smb-required')
7+
const demo = page.locator('#hide-required')
88
const form = demo.locator('.tiny-form')
99
const firstLabel = form.locator('.tiny-form-item__label').first()
1010
const switchBtn = demo.locator('.tiny-switch')

examples/sites/demos/pc/app/form/slot-label-composition-api.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</tiny-form-item>
1212
<tiny-form-item prop="url">
1313
<template #label>
14-
<div class="custom-label" v-auto-tip>超过两行文字,省略显示</div>
14+
<div class="custom-label" v-auto-tip>超过两行文字,显示省略号</div>
1515
</template>
1616
<tiny-input v-model="createData.url"></tiny-input>
1717
</tiny-form-item>

examples/sites/demos/pc/app/form/slot-label.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ test('测试表单标签文本插槽', async ({ page }) => {
1010

1111
await expect(formItem.first().locator('.tiny-form-item__label')).toHaveText('必填')
1212
await expect(formItem.nth(1).locator('.tiny-form-item__label')).toHaveText('日期')
13-
await expect(formItem.nth(2).locator('.tiny-form-item__label')).toHaveText('超过两行文字,省略显示')
13+
await expect(formItem.nth(2).locator('.tiny-form-item__label')).toHaveText('超过两行文字,显示省略号')
1414
await expect(formItem.nth(3).locator('.tiny-form-item__label')).toHaveText('等级')
1515
})

examples/sites/demos/pc/app/form/slot-label.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</tiny-form-item>
1212
<tiny-form-item prop="url">
1313
<template #label>
14-
<div class="custom-label" v-auto-tip>超过两行文字,省略显示</div>
14+
<div class="custom-label" v-auto-tip>超过两行文字,显示省略号</div>
1515
</template>
1616
<tiny-input v-model="createData.url"></tiny-input>
1717
</tiny-form-item>

examples/sites/demos/pc/app/form/webdoc/form.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,18 @@ export default {
263263
codeFiles: ['group-form.vue']
264264
},
265265
{
266-
demoId: 'smb-required',
266+
demoId: 'hide-required',
267267
name: {
268268
'zh-CN': '必填项红色星号',
269269
'en-US': 'Required items with a red asterisk'
270270
},
271271
desc: {
272272
'zh-CN':
273-
'<p>通过 <code>hide-required-asterisk</code> 设置是否隐藏标签前的红色星号,默认为 <code>true</code> 。</p>',
273+
'<p>通过 <code>hide-required-asterisk</code> 设置是否隐藏标签前的红色星号,默认为 <code>false</code> 。</p>',
274274
'en-US':
275-
'By setting whether to hide the red asterisk in front of the label through <code>hide required asterisk</code> , it defaults to <code>true</code>.'
275+
'By setting whether to hide the red asterisk in front of the label through <code>hide required asterisk</code> , it defaults to <code>false</code>.'
276276
},
277-
codeFiles: ['smb-required.vue']
277+
codeFiles: ['hide-required.vue']
278278
},
279279
{
280280
demoId: 'popper-options',

packages/design/aurora/src/form/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ export default {
66
labelWidth: '100px',
77
tooltipType: 'error'
88
},
9-
hideRequiredAsterisk: false,
109
messageType: 'absolute'
1110
}

packages/design/saas/src/form/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ export default {
66
labelWidth: '100px',
77
tooltipType: 'error'
88
},
9-
hideRequiredAsterisk: false,
109
messageType: 'absolute'
1110
}

packages/renderless/src/form/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const computedAutoLabelWidth =
4747
export const computedHideRequiredAsterisk =
4848
({ props, designConfig }: Pick<IFormRenderlessParams, 'props' | 'designConfig'>) =>
4949
(): boolean => {
50-
return props.hideRequiredAsterisk ?? designConfig?.hideRequiredAsterisk ?? true
50+
return props.hideRequiredAsterisk ?? designConfig?.hideRequiredAsterisk ?? false
5151
}
5252

5353
export const computedValidateIcon =

0 commit comments

Comments
 (0)