Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
feat(segmented-controll): make prop fontSize accept both number and s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
b2nil committed Dec 14, 2020
1 parent b6b426f commit c40d35a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/components/segmented-control/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const AtSegmentedControl = defineComponent({
default: '#6190E8'
},
fontSize: {
type: Number,
default: 28
type: [Number, String],
default: 28,
validator: (prop: number | string) => {
return typeof parseInt(`${prop}`) === 'number'
}
},
disabled: {
type: Boolean,
Expand All @@ -42,7 +45,7 @@ const AtSegmentedControl = defineComponent({
},
},

setup(props: AtSegmentedControlProps, { attrs, slots }) {
setup(props: AtSegmentedControlProps, { attrs }) {

const rootClass = computed(() => ({
'at-segmented-control': true,
Expand All @@ -60,14 +63,14 @@ const AtSegmentedControl = defineComponent({

const itemStyle = computed(() => ({
color: props.selectedColor,
fontSize: pxTransform(props.fontSize!),
fontSize: pxTransform(parseInt(`${props.fontSize!}`)),
borderColor: props.selectedColor,
backgroundColor: props.color
}))

const selectedItemStyle = computed(() => ({
color: props.color,
fontSize: pxTransform(props.fontSize!),
fontSize: pxTransform(parseInt(`${props.fontSize!}`)),
borderColor: props.selectedColor,
backgroundColor: props.selectedColor
}))
Expand Down
4 changes: 2 additions & 2 deletions types/segmented-control.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export interface AtSegmentedControlProps extends AtComponent {
*/
selectedColor?: string
/**
* 字体大小,单位 h5 为 rem,小程序为 rem
* 字体大小,单位 h5 为 rem,小程序为 rpx
* @default 28
*/
fontSize?: number
fontSize?: number | string
/**
* 是否禁止点击
* @default false
Expand Down

0 comments on commit c40d35a

Please sign in to comment.