Skip to content

Commit

Permalink
chore(ui/**/props): 修改string类型为具体可选项的联合类型,优化类型提示。
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Apr 25, 2021
1 parent af74e30 commit 3cc20cd
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/button/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ function sizeValidator(size: string): boolean {

export const props = {
type: {
type: String,
type: String as PropType<'default' | 'primary' | 'info' | 'success' | 'warning' | 'danger'>,
default: 'default',
validator: typeValidator,
},
size: {
type: String,
type: String as PropType<'normal' | 'mini' | 'small' | 'large'>,
default: 'normal',
validator: sizeValidator,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/checkbox-group/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const props = {
type: [String, Number],
},
direction: {
type: String,
type: String as PropType<'horizontal' | 'vertical'>,
default: 'horizontal',
},
validateTrigger: {
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/dialog/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const props = {
type: String,
},
messageAlign: {
type: String,
type: String as PropType<'left' | 'center' | 'right'>,
default: 'left',
validator: messageAlignValidator,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/image/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const props = {
type: String,
},
fit: {
type: String,
type: String as PropType<'fill' | 'contain' | 'cover' | 'none' | 'scale-down'>,
validator: fitValidator,
default: 'fill',
},
Expand All @@ -34,7 +34,7 @@ export const props = {
},
lazy: {
type: Boolean,
default: false
default: false,
},
ripple: {
type: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/input/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const props = {
type: [String, Number],
},
type: {
type: String,
type: String as PropType<'text' | 'password'>,
default: 'text',
validator: typeValidator,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/menu/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const props = {
default: false,
},
alignment: {
type: String,
type: String as PropType<'top' | 'bottom'>,
default: 'top',
validator: alignmentValidator,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/popup/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const props = {
default: false,
},
position: {
type: String,
type: String as PropType<'top' | 'bottom' | 'right' | 'left' | 'center'>,
default: 'center',
validator: positionValidator,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/radio-group/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const props = {
default: undefined,
},
direction: {
type: String,
type: String as PropType<'horizontal' | 'vertical'>,
default: 'horizontal',
},
validateTrigger: {
Expand Down
24 changes: 9 additions & 15 deletions packages/varlet-ui/src/row/props.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
import { PropType } from 'vue'

function justifyValidator(justify: string) {
return [
'flex-start',
'flex-end',
'center',
'space-between',
'space-around'
].includes(justify)
return ['flex-start', 'flex-end', 'center', 'space-between', 'space-around'].includes(justify)
}

function alignValidator(align: string) {
return ['flex-start', 'flex-center', 'flex-end'].includes(align)
return ['flex-start', 'center', 'flex-end'].includes(align)
}

export const props = {
gutter: {
type: [String, Number],
default: 0
default: 0,
},
justify: {
type: String,
type: String as PropType<'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around'>,
default: 'flex-start',
validator: justifyValidator
validator: justifyValidator,
},
align: {
type: String,
type: String as PropType<'flex-start' | 'center' | 'flex-end'>,
default: 'flex-start',
validator: alignValidator
validator: alignValidator,
},
onClick: {
type: Function as PropType<(e: Event) => void>
}
type: Function as PropType<(e: Event) => void>,
},
}
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/select/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const props = {
default: ',',
},
textAlign: {
type: String,
type: String as PropType<'left' | 'right' | 'center'>,
default: 'left',
validator: textAlignValidator,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/tabs/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const props = {
default: 0,
},
layoutDirection: {
type: String,
type: String as PropType<'horizontal' | 'vertical'>,
default: 'horizontal',
validator: directionValidator,
},
itemDirection: {
type: String,
type: String as PropType<'horizontal' | 'vertical'>,
default: 'horizontal',
validator: directionValidator,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/types/row.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { VarComponent } from './varComponent'
interface RowProps {
gutter?: string | number
justify?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around'
align?: 'flex-start' | 'flex-center' | 'flex-end'
align?: 'flex-start' | 'center' | 'flex-end'
onClick?: (e: Event) => void
}

Expand Down

0 comments on commit 3cc20cd

Please sign in to comment.