diff --git a/src/checkbox-group/CheckboxGroup.tsx b/src/checkbox-group/CheckboxGroup.tsx index a8fd5e175..88084b07d 100644 --- a/src/checkbox-group/CheckboxGroup.tsx +++ b/src/checkbox-group/CheckboxGroup.tsx @@ -1,4 +1,4 @@ -import { PropType, watch, defineComponent } from 'vue'; +import { PropType, watch, defineComponent, ExtractPropTypes } from 'vue'; import { createNamespace } from '../utils'; import { useChildren } from '@vant/use'; import { useExpose } from '../composables/use-expose'; @@ -9,6 +9,18 @@ const [name, bem] = createNamespace('checkbox-group'); export const CHECKBOX_GROUP_KEY = Symbol(name); +const props = { + max: [Number, String], + disabled: Boolean, + direction: String as PropType, + iconSize: [Number, String], + checkedColor: String, + modelValue: { + type: Array as PropType, + default: () => [], + }, +}; + export type CheckboxGroupToggleAllOptions = | boolean | { @@ -17,27 +29,14 @@ export type CheckboxGroupToggleAllOptions = }; export type CheckboxGroupProvide = CheckerParent & { - props: { - max: number | string; - modelValue: unknown[]; - }; + props: ExtractPropTypes; updateValue: (value: unknown[]) => void; }; export default defineComponent({ name, - props: { - max: [Number, String], - disabled: Boolean, - direction: String as PropType, - iconSize: [Number, String], - checkedColor: String, - modelValue: { - type: Array as PropType, - default: () => [], - }, - }, + props, emits: ['change', 'update:modelValue'], diff --git a/src/dropdown-menu/DropdownMenu.tsx b/src/dropdown-menu/DropdownMenu.tsx index 7692aa6da..9ae8a90d5 100644 --- a/src/dropdown-menu/DropdownMenu.tsx +++ b/src/dropdown-menu/DropdownMenu.tsx @@ -5,6 +5,7 @@ import { PropType, CSSProperties, defineComponent, + ExtractPropTypes, } from 'vue'; // Utils @@ -25,45 +26,40 @@ export const DROPDOWN_KEY = Symbol(name); export type DropdownMenuDirection = 'up' | 'down'; +const props = { + zIndex: [Number, String], + activeColor: String, + overlay: { + type: Boolean, + default: true, + }, + duration: { + type: [Number, String], + default: 0.2, + }, + direction: { + type: String as PropType, + default: 'down', + }, + closeOnClickOutside: { + type: Boolean, + default: true, + }, + closeOnClickOverlay: { + type: Boolean, + default: true, + }, +}; + export type DropdownMenuProvide = { - props: { - zIndex?: number | string; - overlay: boolean; - duration: number | string; - direction: DropdownMenuDirection; - activeColor?: string; - closeOnClickOverlay: boolean; - }; + props: ExtractPropTypes; offset: Ref; }; export default defineComponent({ name, - props: { - zIndex: [Number, String], - activeColor: String, - overlay: { - type: Boolean, - default: true, - }, - duration: { - type: [Number, String], - default: 0.2, - }, - direction: { - type: String as PropType, - default: 'down', - }, - closeOnClickOutside: { - type: Boolean, - default: true, - }, - closeOnClickOverlay: { - type: Boolean, - default: true, - }, - }, + props, setup(props, { slots }) { const root = ref(); diff --git a/src/grid/Grid.tsx b/src/grid/Grid.tsx index d59201a51..9007ba958 100644 --- a/src/grid/Grid.tsx +++ b/src/grid/Grid.tsx @@ -1,4 +1,4 @@ -import { PropType, defineComponent } from 'vue'; +import { PropType, defineComponent, ExtractPropTypes } from 'vue'; import { createNamespace, addUnit } from '../utils'; import { BORDER_TOP } from '../utils/constant'; import { useChildren } from '@vant/use'; @@ -9,41 +9,34 @@ export const GRID_KEY = Symbol(name); export type GridDirection = 'horizontal' | 'vertical'; +const props = { + square: Boolean, + gutter: [Number, String], + iconSize: [Number, String], + direction: String as PropType, + clickable: Boolean, + columnNum: { + type: [Number, String], + default: 4, + }, + center: { + type: Boolean, + default: true, + }, + border: { + type: Boolean, + default: true, + }, +}; + export type GridProvide = { - props: { - center: boolean; - border: boolean; - square?: boolean; - gutter?: number | string; - iconSize?: number | string; - columnNum: number | string; - direction?: GridDirection; - clickable?: boolean; - }; + props: ExtractPropTypes; }; export default defineComponent({ name, - props: { - square: Boolean, - gutter: [Number, String], - iconSize: [Number, String], - direction: String as PropType, - clickable: Boolean, - columnNum: { - type: [Number, String], - default: 4, - }, - center: { - type: Boolean, - default: true, - }, - border: { - type: Boolean, - default: true, - }, - }, + props, setup(props, { slots }) { const { linkChildren } = useChildren(GRID_KEY); diff --git a/src/index-bar/IndexBar.tsx b/src/index-bar/IndexBar.tsx index 4678477f7..a01066ca8 100644 --- a/src/index-bar/IndexBar.tsx +++ b/src/index-bar/IndexBar.tsx @@ -7,6 +7,7 @@ import { onMounted, CSSProperties, defineComponent, + ExtractPropTypes, } from 'vue'; // Utils @@ -31,14 +32,6 @@ import { import { useTouch } from '../composables/use-touch'; import { useExpose } from '../composables/use-expose'; -export type IndexBarProvide = { - props: { - sticky: boolean; - zIndex?: number | string; - highlightColor?: string; - }; -}; - function genAlphabet() { const charCodeOfA = 'A'.charCodeAt(0); const indexList = Array(26) @@ -52,25 +45,31 @@ const [name, bem] = createNamespace('index-bar'); export const INDEX_BAR_KEY = Symbol(name); +const props = { + zIndex: [Number, String], + highlightColor: String, + sticky: { + type: Boolean, + default: true, + }, + stickyOffsetTop: { + type: Number, + default: 0, + }, + indexList: { + type: Array as PropType, + default: genAlphabet, + }, +}; + +export type IndexBarProvide = { + props: ExtractPropTypes; +}; + export default defineComponent({ name, - props: { - zIndex: [Number, String], - highlightColor: String, - sticky: { - type: Boolean, - default: true, - }, - stickyOffsetTop: { - type: Number, - default: 0, - }, - indexList: { - type: Array as PropType, - default: genAlphabet, - }, - }, + props, emits: ['select', 'change'], diff --git a/src/radio-group/RadioGroup.tsx b/src/radio-group/RadioGroup.tsx index 98081c533..8864449a7 100644 --- a/src/radio-group/RadioGroup.tsx +++ b/src/radio-group/RadioGroup.tsx @@ -1,4 +1,4 @@ -import { watch, defineComponent } from 'vue'; +import { watch, defineComponent, ExtractPropTypes } from 'vue'; import { UnknownProp, createNamespace } from '../utils'; import { useChildren } from '@vant/use'; import { useLinkField } from '../composables/use-link-field'; @@ -8,23 +8,23 @@ const [name, bem] = createNamespace('radio-group'); export const RADIO_KEY = Symbol(name); +const props = { + disabled: Boolean, + iconSize: [Number, String], + direction: String, + modelValue: UnknownProp, + checkedColor: String, +}; + export type RadioGroupProvide = CheckerParent & { - props: { - modelValue: unknown; - }; + props: ExtractPropTypes; updateValue: (value: unknown) => void; }; export default defineComponent({ name, - props: { - disabled: Boolean, - iconSize: [Number, String], - direction: String, - modelValue: UnknownProp, - checkedColor: String, - }, + props, emits: ['change', 'update:modelValue'], diff --git a/src/steps/Steps.tsx b/src/steps/Steps.tsx index e6a4a6804..4678b268b 100644 --- a/src/steps/Steps.tsx +++ b/src/steps/Steps.tsx @@ -1,4 +1,4 @@ -import { PropType, defineComponent } from 'vue'; +import { PropType, defineComponent, ExtractPropTypes } from 'vue'; import { createNamespace } from '../utils'; import { useChildren } from '@vant/use'; @@ -8,40 +8,34 @@ export const STEPS_KEY = Symbol(name); export type StepsDirection = 'horizontal' | 'vertical'; +const props = { + finishIcon: String, + activeColor: String, + inactiveIcon: String, + inactiveColor: String, + active: { + type: [Number, String], + default: 0, + }, + direction: { + type: String as PropType, + default: 'horizontal', + }, + activeIcon: { + type: String, + default: 'checked', + }, +}; + export type StepsProvide = { - props: { - active: number | string; - direction: StepsDirection; - activeIcon: string; - finishIcon?: string; - activeColor?: string; - inactiveIcon?: string; - inactiveColor?: string; - }; + props: ExtractPropTypes; onClickStep: (index: number) => void; }; export default defineComponent({ name, - props: { - finishIcon: String, - activeColor: String, - inactiveIcon: String, - inactiveColor: String, - active: { - type: [Number, String], - default: 0, - }, - direction: { - type: String as PropType, - default: 'horizontal', - }, - activeIcon: { - type: String, - default: 'checked', - }, - }, + props, emits: ['click-step'], diff --git a/src/swipe/Swipe.tsx b/src/swipe/Swipe.tsx index 70d2408b3..1d9e0acfa 100644 --- a/src/swipe/Swipe.tsx +++ b/src/swipe/Swipe.tsx @@ -10,6 +10,7 @@ import { onDeactivated, onBeforeUnmount, defineComponent, + ExtractPropTypes, } from 'vue'; // Utils @@ -35,16 +36,48 @@ const [name, bem] = createNamespace('swipe'); export const SWIPE_KEY = Symbol(name); +const props = { + width: [Number, String], + height: [Number, String], + vertical: Boolean, + lazyRender: Boolean, + indicatorColor: String, + loop: { + type: Boolean, + default: true, + }, + autoplay: { + type: [Number, String], + default: 0, + }, + duration: { + type: [Number, String], + default: 500, + }, + touchable: { + type: Boolean, + default: true, + }, + initialSwipe: { + type: [Number, String], + default: 0, + }, + showIndicators: { + type: Boolean, + default: true, + }, + stopPropagation: { + type: Boolean, + default: true, + }, +}; + export type SwipeToOptions = { immediate?: boolean; }; export type SwipeProvide = { - props: { - loop: boolean; - vertical?: boolean; - lazyRender?: boolean; - }; + props: ExtractPropTypes; size: ComputedRef; count: ComputedRef; activeIndicator: ComputedRef; @@ -53,41 +86,7 @@ export type SwipeProvide = { export default defineComponent({ name, - props: { - width: [Number, String], - height: [Number, String], - vertical: Boolean, - lazyRender: Boolean, - indicatorColor: String, - loop: { - type: Boolean, - default: true, - }, - autoplay: { - type: [Number, String], - default: 0, - }, - duration: { - type: [Number, String], - default: 500, - }, - touchable: { - type: Boolean, - default: true, - }, - initialSwipe: { - type: [Number, String], - default: 0, - }, - showIndicators: { - type: Boolean, - default: true, - }, - stopPropagation: { - type: Boolean, - default: true, - }, - }, + props, emits: ['change'], diff --git a/src/tabbar/Tabbar.tsx b/src/tabbar/Tabbar.tsx index efe50f41f..948f8a16a 100644 --- a/src/tabbar/Tabbar.tsx +++ b/src/tabbar/Tabbar.tsx @@ -1,4 +1,4 @@ -import { ref, PropType, defineComponent } from 'vue'; +import { ref, PropType, defineComponent, ExtractPropTypes } from 'vue'; // Utils import { createNamespace, getZIndexStyle } from '../utils'; @@ -13,43 +13,40 @@ const [name, bem] = createNamespace('tabbar'); export const TABBAR_KEY = Symbol(name); +const props = { + route: Boolean, + zIndex: [Number, String], + placeholder: Boolean, + activeColor: String, + beforeChange: Function as PropType, + inactiveColor: String, + modelValue: { + type: [Number, String], + default: 0, + }, + border: { + type: Boolean, + default: true, + }, + fixed: { + type: Boolean, + default: true, + }, + safeAreaInsetBottom: { + type: Boolean as PropType, + default: null, + }, +}; + export type TabbarProvide = { - props: { - route?: boolean; - modelValue: number | string; - activeColor?: string; - inactiveColor?: string; - }; + props: ExtractPropTypes; setActive: (active: number | string) => void; }; export default defineComponent({ name, - props: { - route: Boolean, - zIndex: [Number, String], - placeholder: Boolean, - activeColor: String, - beforeChange: Function as PropType, - inactiveColor: String, - modelValue: { - type: [Number, String], - default: 0, - }, - border: { - type: Boolean, - default: true, - }, - fixed: { - type: Boolean, - default: true, - }, - safeAreaInsetBottom: { - type: Boolean as PropType, - default: null, - }, - }, + props, emits: ['change', 'update:modelValue'], diff --git a/src/tabs/Tabs.tsx b/src/tabs/Tabs.tsx index 24b834076..88b47d08f 100644 --- a/src/tabs/Tabs.tsx +++ b/src/tabs/Tabs.tsx @@ -10,6 +10,7 @@ import { CSSProperties, defineComponent, ComponentPublicInstance, + ExtractPropTypes, } from 'vue'; // Utils @@ -52,13 +53,51 @@ export const TABS_KEY = Symbol(name); export type TabsType = 'line' | 'card'; +const props = { + color: String, + border: Boolean, + sticky: Boolean, + animated: Boolean, + swipeable: Boolean, + scrollspy: Boolean, + background: String, + lineWidth: [Number, String], + lineHeight: [Number, String], + beforeChange: Function as PropType, + titleActiveColor: String, + titleInactiveColor: String, + type: { + type: String as PropType, + default: 'line', + }, + active: { + type: [Number, String], + default: 0, + }, + ellipsis: { + type: Boolean, + default: true, + }, + duration: { + type: [Number, String], + default: 0.3, + }, + offsetTop: { + type: [Number, String], + default: 0, + }, + lazyRender: { + type: Boolean, + default: true, + }, + swipeThreshold: { + type: [Number, String], + default: 5, + }, +}; + export type TabsProvide = { - props: { - animated?: boolean; - swipeable?: boolean; - scrollspy?: boolean; - lazyRender: boolean; - }; + props: ExtractPropTypes; setLine: () => void; onRendered: (name: string | number, title?: string) => void; scrollIntoView: (immediate?: boolean) => void; @@ -68,48 +107,7 @@ export type TabsProvide = { export default defineComponent({ name, - props: { - color: String, - border: Boolean, - sticky: Boolean, - animated: Boolean, - swipeable: Boolean, - scrollspy: Boolean, - background: String, - lineWidth: [Number, String], - lineHeight: [Number, String], - beforeChange: Function as PropType, - titleActiveColor: String, - titleInactiveColor: String, - type: { - type: String as PropType, - default: 'line', - }, - active: { - type: [Number, String], - default: 0, - }, - ellipsis: { - type: Boolean, - default: true, - }, - duration: { - type: [Number, String], - default: 0.3, - }, - offsetTop: { - type: [Number, String], - default: 0, - }, - lazyRender: { - type: Boolean, - default: true, - }, - swipeThreshold: { - type: [Number, String], - default: 5, - }, - }, + props, emits: ['click', 'change', 'scroll', 'disabled', 'rendered', 'update:active'],