Skip to content

Commit a23ced8

Browse files
committed
fix: component size type refactoring
1 parent 256b828 commit a23ced8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+225
-93
lines changed

src/_mixins/use-form-item.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type { ComputedRef, Ref } from 'vue'
2-
import type { FormValidationStatus } from '../form/src/public-types'
2+
import type {
3+
FormItemSize,
4+
FormValidationStatus
5+
} from '../form/src/public-types'
36
import { computed, inject, onBeforeUnmount, provide } from 'vue'
47
import { createInjectionKey } from '../_utils'
58

6-
type FormItemSize = 'small' | 'medium' | 'large'
79
type AllowedSize = 'tiny' | 'small' | 'medium' | 'large' | 'huge' | number
810

911
export interface FormItemInjection {

src/button-group/src/ButtonGroup.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import type { PropType } from 'vue'
22
import type { ExtractPublicPropTypes } from '../../_utils'
3-
import type { Size } from '../../button/src/interface'
3+
import type { ButtonSize } from '../../button/src/public-types'
44
import { defineComponent, h, provide } from 'vue'
55
import { useConfig, useStyle } from '../../_mixins'
66
import { useRtl } from '../../_mixins/use-rtl'
77
import { buttonGroupInjectionKey } from './context'
88
import style from './styles/index.cssr'
99

1010
export interface ButtonGroupInjection {
11-
size?: Size | undefined
11+
size?: ButtonSize | undefined
1212
}
1313

1414
export const buttonGroupProps = {
15-
size: {
16-
type: String as PropType<Size | undefined>,
17-
default: undefined
18-
},
15+
size: String as PropType<ButtonSize | undefined>,
1916
vertical: Boolean
2017
} as const
2118

src/button-group/src/styles/index.cssr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { CNode } from 'css-render'
2-
import type { Type } from '../../../button/src/interface'
2+
import type { ButtonType } from '../../../button/src/public-types'
33
import { c, cB, cE, cM, cNotM } from '../../../_utils/cssr/index'
44

55
export const zero = '0!important'
66
export const n1 = '-1px!important'
77

8-
function createLeftBorderStyle(type: Type): CNode {
8+
function createLeftBorderStyle(type: ButtonType): CNode {
99
return cM(`${type}-type`, [
1010
c('& +', [
1111
cB('button', {}, [
@@ -22,7 +22,7 @@ function createLeftBorderStyle(type: Type): CNode {
2222
])
2323
}
2424

25-
function createTopBorderStyle(type: Type): CNode {
25+
function createTopBorderStyle(type: ButtonType): CNode {
2626
return cM(`${type}-type`, [
2727
c('& +', [
2828
cB('button', [

src/button-group/src/styles/rtl.cssr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { CNode } from 'css-render'
2-
import type { Type } from '../../../button/src/interface'
2+
import type { ButtonType } from '../../../button/src/public-types'
33
import { c, cB, cE, cM, cNotM } from '../../../_utils/cssr'
44
import { n1, zero } from './index.cssr'
55

6-
function createRightBorderStyle(type: Type): CNode {
6+
function createRightBorderStyle(type: ButtonType): CNode {
77
return cM(`${type}-type`, [
88
c('& +', [
99
cB('button', {}, [

src/button/src/Button.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import type { BaseWaveRef } from '../../_internal'
1111
import type { ThemeProps } from '../../_mixins'
1212
import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils'
1313
import type { ButtonTheme } from '../styles'
14-
import type { Size, Type } from './interface'
15-
import type { ButtonSpinProps } from './public-types'
14+
import type { ButtonSize, ButtonSpinProps, ButtonType } from './public-types'
1615
import { changeColor } from 'seemly'
1716
import { useMemo } from 'vooks'
1817
import { computed, defineComponent, h, inject, ref, watchEffect } from 'vue'
@@ -47,7 +46,7 @@ export const buttonProps = {
4746
loading: Boolean,
4847
disabled: Boolean,
4948
circle: Boolean,
50-
size: String as PropType<Size>,
49+
size: String as PropType<ButtonSize>,
5150
ghost: Boolean,
5251
round: Boolean,
5352
secondary: Boolean,
@@ -67,7 +66,7 @@ export const buttonProps = {
6766
default: 'button'
6867
},
6968
type: {
70-
type: String as PropType<Type>,
69+
type: String as PropType<ButtonType>,
7170
default: 'default'
7271
},
7372
dashed: Boolean,

src/button/src/interface.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/button/src/public-types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
import type { SharedSpinProps } from '../../_internal'
22

3+
export type ButtonSize = 'tiny' | 'small' | 'medium' | 'large'
34
export type ButtonSpinProps = SharedSpinProps
5+
export type ButtonType
6+
= | 'default'
7+
| 'tertiary'
8+
| 'primary'
9+
| 'info'
10+
| 'success'
11+
| 'warning'
12+
| 'error'

src/config-provider/demos/enUS/index.demo-entry.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ size.vue
2626
| abstract | `boolean` | `false` | If `n-config-provider` has no wrapper DOM | |
2727
| breakpoints | `{ [k: string]: number }` | `{ xs: <640, s: ≥640, m: ≥1024, l: ≥1280, xl: ≥1536, xxl: ≥1920 }` | Responsive breakpoints, it will be used in `n-grid`. The prop is not responsive, you need to set it on its first mount. | |
2828
| cls-prefix | `string` | `undefined` | The class prefix of all inner components. (Since `2.40.0`) If you don't set the `cls-prefix` prop of `n-config-provider`, it will inherit the class prefix from its parent by default. Note that this prop is not reactive. | |
29-
| component-options | `GlobalComponentConfig` | `undefined` | Global component options. `renderEmpty` can be configured per component. If set to `undefined` it will inherit its parent `n-config-provider`. | |
29+
| component-options | `GlobalComponentConfig` | `undefined` | Global component options. Some props can be configured per component. If set to `undefined` it will inherit its parent `n-config-provider`. | |
3030
| date-locale | `DateLocale \| null` | `undefined` | The date locale object to be consumed by its child. If set to `null` it will use the default `dateEnUS` locale. If set to `undefined` it will inherit its parent `n-config-provider`. | |
3131
| inline-theme-disabled | `boolean` | `false` | Whether to disabled inline theme CSS variables. If you won't change theme overrides frequently in client side, and need SSR or make devtools looks clear. You can enable the prop. Note that the prop is not responsive. | 2.26.0 |
3232
| katex | `object` | `undefined` | Katex object for `n-equation`. | 2.34.0 |
@@ -42,17 +42,87 @@ size.vue
4242

4343
```ts
4444
interface GlobalComponentConfig {
45+
Button?: {
46+
size?: ButtonSize
47+
}
48+
Card?: {
49+
size?: CardSize
50+
}
4551
Cascader?: {
4652
renderEmpty?: () => VNodeChild
4753
}
54+
Checkbox?: {
55+
size?: CheckboxSize
56+
}
4857
DataTable?: {
58+
size?: DataTableSize
4959
renderFilter?: DataTableRenderFilter
5060
renderSorter?: DataTableRenderSorter
5161
renderEmpty?: () => VNodeChild
5262
}
63+
DatePicker?: {
64+
timePickerSize?: TimePickerSize
65+
}
66+
Descriptions?: {
67+
size?: DescriptionsSize
68+
}
69+
Dialog?: {
70+
iconPlacement?: IconPlacement
71+
}
72+
Dropdown?: {
73+
size?: DropdownSize
74+
}
75+
DynamicInput?: {
76+
buttonSize?: ButtonSize
77+
}
78+
DynamicTags?: {
79+
size?: DynamicTagsSize
80+
}
81+
Empty?: Pick<EmptyProps, 'description' | 'renderIcon'>
82+
Form?: {
83+
size?: FormSize
84+
}
85+
Input?: {
86+
size?: InputSize
87+
}
88+
Pagination?: {
89+
size?: PaginationSize
90+
inputSize?: InputSize
91+
selectSize?: SelectSize
92+
}
93+
Popselect?: {
94+
size?: PopselectSize
95+
}
96+
Radio?: {
97+
size?: RadioSize
98+
}
99+
Rate?: {
100+
size?: RateSize
101+
}
102+
Result?: {
103+
size?: ResultSize
104+
}
53105
Select?: {
54106
renderEmpty?: () => VNodeChild
55107
}
108+
Skeleton?: {
109+
size?: SkeletonSize
110+
}
111+
Space?: {
112+
size?: SpaceSize
113+
}
114+
Switch?: {
115+
size?: SwitchSize
116+
}
117+
Table?: {
118+
size?: TableSize
119+
}
120+
Tabs?: {
121+
size?: TabsSize
122+
}
123+
Tag?: {
124+
size?: TagSize
125+
}
56126
Transfer?: {
57127
renderEmpty?: () => VNodeChild
58128
}

src/config-provider/demos/zhCN/index.demo-entry.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ size.vue
2626
| abstract | `boolean` | `false` | 是否不存在 DOM 包裹 | |
2727
| breakpoints | `{ [k: string]: number }` | `{ xs: <640, s: ≥640, m: ≥1024, l: ≥1280, xl: ≥1536, xxl: ≥1920 }` | 屏幕响应式断点,对 `n-grid` 生效。这个属性不是响应式的,你需要在组件第一次挂载时就设定好 | |
2828
| cls-prefix | `string` | `undefined` | 内部所有组件的类的前缀。(从 `2.40.0` 开始)如果不设置 `n-config-provider` 的类前缀 `cls-prefix`,则默认继承父级的类前缀。注意,该属性不是响应式的。 | |
29-
| component-options | `GlobalComponentConfig` | `undefined` | 全局组件配置项。`renderEmpty` 按组件维度分别配置。为 `undefined` 时会继承上级 `n-config-provider` | |
29+
| component-options | `GlobalComponentConfig` | `undefined` | 全局组件配置项。一些属性可以按组件维度分别配置。为 `undefined` 时会继承上级 `n-config-provider` | |
3030
| date-locale | `DateLocale \| null` | `undefined` | 对后代组件生效的日期语言对象,为 `null` 时会使用默认 `dateEnUS`,为 `undefined` 时会继承上级 `n-config-provider` | |
3131
| inline-theme-disabled | `boolean` | `false` | 是否禁用 inline css 主题变量,如果你不会频繁调整主题变量,并且需要 SSR 或者想让 devtools 看起来更干净,可以打开这个选项。注意,这个属性不是响应式的 | 2.26.0 |
3232
| katex | `object` | `undefined` | 公式组件需要的 katex 对象 | 2.34.0 |
@@ -42,17 +42,87 @@ size.vue
4242

4343
```ts
4444
interface GlobalComponentConfig {
45+
Button?: {
46+
size?: ButtonSize
47+
}
48+
Card?: {
49+
size?: CardSize
50+
}
4551
Cascader?: {
4652
renderEmpty?: () => VNodeChild
4753
}
54+
Checkbox?: {
55+
size?: CheckboxSize
56+
}
4857
DataTable?: {
58+
size?: DataTableSize
4959
renderFilter?: DataTableRenderFilter
5060
renderSorter?: DataTableRenderSorter
5161
renderEmpty?: () => VNodeChild
5262
}
63+
DatePicker?: {
64+
timePickerSize?: TimePickerSize
65+
}
66+
Descriptions?: {
67+
size?: DescriptionsSize
68+
}
69+
Dialog?: {
70+
iconPlacement?: IconPlacement
71+
}
72+
Dropdown?: {
73+
size?: DropdownSize
74+
}
75+
DynamicInput?: {
76+
buttonSize?: ButtonSize
77+
}
78+
DynamicTags?: {
79+
size?: DynamicTagsSize
80+
}
81+
Empty?: Pick<EmptyProps, 'description' | 'renderIcon'>
82+
Form?: {
83+
size?: FormSize
84+
}
85+
Input?: {
86+
size?: InputSize
87+
}
88+
Pagination?: {
89+
size?: PaginationSize
90+
inputSize?: InputSize
91+
selectSize?: SelectSize
92+
}
93+
Popselect?: {
94+
size?: PopselectSize
95+
}
96+
Radio?: {
97+
size?: RadioSize
98+
}
99+
Rate?: {
100+
size?: RateSize
101+
}
102+
Result?: {
103+
size?: ResultSize
104+
}
53105
Select?: {
54106
renderEmpty?: () => VNodeChild
55107
}
108+
Skeleton?: {
109+
size?: SkeletonSize
110+
}
111+
Space?: {
112+
size?: SpaceSize
113+
}
114+
Switch?: {
115+
size?: SwitchSize
116+
}
117+
Table?: {
118+
size?: TableSize
119+
}
120+
Tabs?: {
121+
size?: TabsSize
122+
}
123+
Tag?: {
124+
size?: TagSize
125+
}
56126
Transfer?: {
57127
renderEmpty?: () => VNodeChild
58128
}

src/config-provider/src/internal-interface.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { BackTopTheme } from '../../back-top/styles'
1313
import type { BadgeTheme } from '../../badge/styles'
1414
import type { BreadcrumbTheme } from '../../breadcrumb/styles'
1515
import type { ButtonGroupTheme } from '../../button-group/styles/light'
16-
import type { Size as ButtonSize } from '../../button/src/interface'
16+
import type { ButtonSize } from '../../button/src/public-types'
1717
import type { ButtonTheme } from '../../button/styles'
1818
import type { CalendarTheme } from '../../calendar/styles'
1919
import type { CardSize } from '../../card/src/public-types'
@@ -52,7 +52,7 @@ import type { EquationTheme } from '../../equation/styles'
5252
import type { FlexTheme } from '../../flex/styles'
5353
import type { FloatButtonGroupTheme } from '../../float-button-group/styles'
5454
import type { FloatButtonTheme } from '../../float-button/styles'
55-
import type { Size as FormSize } from '../../form/src/interface'
55+
import type { FormSize } from '../../form/src/public-types'
5656
import type { FormTheme } from '../../form/styles'
5757
import type { GradientTextTheme } from '../../gradient-text/styles'
5858
import type { HeatmapTheme } from '../../heatmap/styles'
@@ -61,7 +61,7 @@ import type { IconTheme } from '../../icon/styles'
6161
import type { ImageTheme } from '../../image/styles'
6262
import type { InputNumberTheme } from '../../input-number/styles'
6363
import type { InputOtpTheme } from '../../input-otp/styles'
64-
import type { Size as InputSize } from '../../input/src/interface'
64+
import type { InputSize } from '../../input/src/public-types'
6565
import type { InputTheme } from '../../input/styles'
6666
import type { LayoutTheme } from '../../layout/styles'
6767
import type { RowTheme } from '../../legacy-grid/styles'
@@ -77,11 +77,11 @@ import type { MessageTheme } from '../../message/styles'
7777
import type { ModalTheme } from '../../modal/styles'
7878
import type { NotificationTheme } from '../../notification/styles'
7979
import type { PageHeaderTheme } from '../../page-header/styles'
80-
import type { Size as PaginationSize } from '../../pagination/src/interface'
80+
import type { PaginationSize } from '../../pagination/src/public-types'
8181
import type { PaginationTheme } from '../../pagination/styles'
8282
import type { PopconfirmTheme } from '../../popconfirm/styles'
8383
import type { PopoverTheme } from '../../popover/styles'
84-
import type { PopselectSize } from '../../popselect/src/interface'
84+
import type { PopselectSize } from '../../popselect/src/public-types'
8585
import type { PopselectTheme } from '../../popselect/styles'
8686
import type { ProgressTheme } from '../../progress/styles'
8787
import type { QrCodeTheme } from '../../qr-code/styles'
@@ -91,7 +91,7 @@ import type { RateSize } from '../../rate/src/public-types'
9191
import type { RateTheme } from '../../rate/styles'
9292
import type { ResultSize } from '../../result/src/public-types'
9393
import type { ResultTheme } from '../../result/styles'
94-
import type { Size as SelectSize } from '../../select/src/interface'
94+
import type { SelectSize } from '../../select/src/public-types'
9595
import type { SelectTheme } from '../../select/styles'
9696
import type { SkeletonSize } from '../../skeleton/src/public-types'
9797
import type { SkeletonTheme } from '../../skeleton/styles'
@@ -111,7 +111,7 @@ import type { TabsTheme } from '../../tabs/styles'
111111
import type { TagSize } from '../../tag/src/public-types'
112112
import type { TagTheme } from '../../tag/styles'
113113
import type { ThingTheme } from '../../thing/styles'
114-
import type { Size as TimePickerSize } from '../../time-picker/src/interface'
114+
import type { TimePickerSize } from '../../time-picker/src/public-types'
115115
import type { TimePickerTheme } from '../../time-picker/styles'
116116
import type { TimelineTheme } from '../../timeline/styles'
117117
import type { TooltipTheme } from '../../tooltip/styles'

0 commit comments

Comments
 (0)