File tree Expand file tree Collapse file tree 7 files changed +140
-17
lines changed Expand file tree Collapse file tree 7 files changed +140
-17
lines changed Original file line number Diff line number Diff line change 136136 </CodePreview >
137137</ClientOnly >
138138
139+ ### 只使用 FormItem
140+
141+ ` FormItem ` 可以不放在 ` Form ` 里面,从而进行单独使用。
142+
143+ <ClientOnly >
144+ <CodePreview >
145+ <textarea lang =" vue-html " >
146+ <nt-form-item label="开关">
147+ <nt-switch />
148+ </nt-form-item>
149+ </textarea >
150+ </CodePreview >
151+ </ClientOnly >`
152+
139153## API
140154
141155### Form Props
Original file line number Diff line number Diff line change 44
55## 基础用法
66
7+ <script setup lang =" ts " >
8+ import { Input } from ' ../../src'
9+ import { ref } from ' vue'
10+
11+ const inputInt = ref (' ' )
12+
13+ function numericParse (value : string ) {
14+ let val = parseInt (value, 10 )
15+ if (Number .isNaN (val)) {
16+ val = ' '
17+ } else {
18+ val = Math .abs (val)
19+ }
20+ return String (val);
21+ }
22+ </script >
23+
24+ ### 基本使用
25+
726文本输入的基础用法。
827
928<ClientOnly ><CodePreview >
1231 </textarea >
1332</CodePreview ></ClientOnly >
1433
34+ ### 输入解析
35+
36+ 通过传递 ` parser ` 在接受到输入值的时候进行解析,例如:只允许输入正整数
37+
38+ <ClientOnly >
39+ <CodePreview >
40+ <textarea lang =" vue " >
41+ <script setup lang="ts">
42+ import { Input } from '../../src';
43+ import { ref } from 'vue';
44+ //-
45+ const inputInt = ref('')
46+ //-
47+ function numericParse(value: string) {
48+ let val = parseInt(value, 10)
49+ if (Number.isNaN(val)) {
50+ val = ''
51+ } else {
52+ val = Math.abs(val)
53+ }
54+ return String(val);
55+ }
56+ </script>
57+ <template>
58+ <nt-input v-model="inputInt" placeholder="请输入正整数" :parser="numericParse"></nt-input>
59+ </template>
60+ </textarea >
61+ <template #preview>
62+ <Input v-model =" inputInt " placeholder =" 请输入正整数 " :parser =" numericParse " />
63+ </template >
64+ </CodePreview >
65+ </ClientOnly >
66+
1567## API
1668
1769### Input Props
2274| ` html-type ` | 原始的 [ type] ( https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#input_%E7%B1%BB%E5%9E%8B ) | ` string ` | ` text ` |
2375| ` model-value ` / ` v-model ` | 绑定值 | ` string ` | — |
2476| ` placeholder ` | 占位文本 | ` string ` | — |
77+ | ` parser ` | 输入时解析值 | ` (value: string) => string ` | — |
2578
2679### Input Exposes
2780
Original file line number Diff line number Diff line change 55## 演示
66
77<script setup >
8- import { Pagination } from " ../../src"
8+ import { Pagination , Switch , FormItem } from " ../../src"
99 import { ref , watch } from ' vue'
10+
11+ const singleHide = ref (false )
1012</script >
1113
1214### 基础用法
5456 </CodePreview >
5557</ClientOnly >
5658
59+ ### 单页隐藏
60+
61+ 当只有一页时,通过 ` single-hide ` 配置隐藏分页
62+
63+ <ClientOnly >
64+ <CodePreview >
65+ <textarea lang =" vue " >
66+ <script setup lang="ts">
67+ const singleHide = ref(false)
68+ </script>
69+ <template>
70+ <nt-form-item label="单页隐藏">
71+ <nt-switch v-model="singleHide" />
72+ </nt-form-item>
73+ <hr />
74+ <nt-pagination :page-count="1" :hide-on-single-page="singleHide"></nt-pagination>
75+ </template>
76+ </textarea >
77+ <template #preview>
78+ <FormItem label =" 单页隐藏 " >
79+ <Switch v-model =" singleHide " />
80+ </FormItem >
81+ <hr />
82+ <Pagination :page-count =" 1 " :hide-on-single-page =" singleHide " ></Pagination >
83+ </template >
84+ </CodePreview >
85+ </ClientOnly >
86+
5787## API
5888
5989### Pagination Props
Original file line number Diff line number Diff line change 11<template >
22 <input
3- :value =" model "
3+ :value =" modelValue "
44 :type =" htmlType"
55 :class =" {
66 'nt-input': true,
77 'is-autosize': autosize,
88 }"
99 :placeholder =" placeholder"
10- @input ="
11- $emit('update:modelValue', ($event.target as HTMLInputElement).value)
12- "
10+ @input =" handleInput"
1311 ref =" el"
1412 />
1513</template >
1614
1715<script setup lang="ts">
18- import { onMounted , ref } from ' vue' ;
19- const model = defineModel ();
16+ import { ref } from ' vue' ;
2017
2118const el = ref <HTMLInputElement >();
2219
23- withDefaults (
20+ const props = withDefaults (
2421 defineProps <{
2522 htmlType? : string ;
2623 placeholder? : string ;
2724 autosize? : boolean ;
25+ parser? : (value : string ) => string ;
26+ modelValue? : string ;
2827 }>(),
2928 {
3029 htmlType: ' text' ,
@@ -33,12 +32,24 @@ withDefaults(
3332 },
3433);
3534
35+ const emits = defineEmits ([' update:modelValue' ]);
36+
3637function focus() {
3738 if (el .value != null ) {
3839 el .value .focus ();
3940 }
4041}
4142
43+ function handleInput(e : Event ) {
44+ const $target = e .target as HTMLInputElement ;
45+ let value = $target .value ;
46+ if (props .parser != null ) {
47+ value = props .parser (value ) as string ;
48+ $target .value = String (value );
49+ }
50+ emits (' update:modelValue' , value );
51+ }
52+
4253defineExpose ({
4354 focus ,
4455});
Original file line number Diff line number Diff line change 11<template >
2- <ul :class =" ['nt-pagination', `nt-pagination-${align}`]" >
2+ <ul
3+ :class =" ['nt-pagination', `nt-pagination-${align}`]"
4+ v-if =" !hideOnSinglePage || totalPage > 1"
5+ >
36 <!-- 上一页切换按钮 -->
47 <li class =" nt-pagination-item" >
58 <Button
@@ -98,11 +101,14 @@ const props = withDefaults(
98101 defaultCurrentPage? : number ;
99102 /** 对齐方式 */
100103 align? : ' start' | ' center' | ' end' ;
104+ /** 只有一页时是否隐藏分页器 */
105+ hideOnSinglePage? : boolean ;
101106 }>(),
102107 {
103108 pageSize: 10 ,
104109 defaultCurrentPage: 1 ,
105110 align: ' start' ,
111+ hideOnSinglePage: false ,
106112 },
107113);
108114
Original file line number Diff line number Diff line change 11.nt-form-item {
22 display : flex;
3- margin-bottom : 20 px ;
3+
44 font-size : 14px ;
55}
66.nt-form-item__label {
7+ --nt-form-label-width : auto;
8+ --nt-form-edit-height : auto;
79 display : inline-flex;
810 align-items : flex-start;
911 justify-content : flex-end;
10- width : var (--nt-form-label-width , 80 px );
11- height : var (--nt-form-edit-height , 32 px );
12- line-height : var (--nt-form-edit-height , 32 px );
12+ width : var (--nt-form-label-width );
13+ height : var (--nt-form-edit-height );
14+ line-height : var (--nt-form-edit-height );
1315 color : # 606266 ;
1416 padding : 0 10px 0 0 ;
1517}
2123.nt-form-item__content {
2224 flex : 1 ;
2325 position : relative;
26+ display : flex;
27+ align-items : center;
2428}
2529.nt-form-item__error {
2630 font-size : 12px ;
3842 width : 100% ;
3943}
4044
45+ .nt-form .nt-form-item {
46+ margin-bottom : 20px ;
47+ }
48+ .nt-form .nt-form-item__label {
49+ --nt-form-label-width : 80px ;
50+ --nt-form-edit-height : 32px ;
51+ }
52+
4153/** 行内表单 */
4254.nt-form-inline .nt-form-item {
4355 display : inline-flex;
Original file line number Diff line number Diff line change 11.nt-switch {
2- --nt-switch-height : 20 px ;
2+ --nt-switch-height : 22 px ;
33 --nt-switch-width : calc (var (--nt-switch-height ) * 2 );
44 display : inline-flex;
55 width : var (--nt-switch-width );
1515 vertical-align : middle;
1616}
1717
18- .nt-switch : hover {
19- background-color : var (--nt-primary-color-light1 , # d9f7be );
20- }
2118.nt-switch--checked {
2219 background-color : var (--nt-primary-color , # 52c41a );
2320}
You can’t perform that action at this time.
0 commit comments