Merge branch 'dev' into next

This commit is contained in:
chenjiahan 2022-03-27 18:12:42 +08:00
commit a541090f3a
128 changed files with 427 additions and 362 deletions

View File

@ -0,0 +1,5 @@
export { useTranslate, initDemoLocale } from './use-translate';
/** Generate the CDN URL of assets. */
export const cdnURL = (path: string) =>
`https://cdn.jsdelivr.net/npm/@vant/assets/${path}`;

View File

@ -2,7 +2,7 @@
import VanActionBar from '..'; import VanActionBar from '..';
import VanActionBarIcon from '../../action-bar-icon'; import VanActionBarIcon from '../../action-bar-icon';
import VanActionBarButton from '../../action-bar-button'; import VanActionBarButton from '../../action-bar-button';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanActionSheet, { ActionSheetAction } from '..'; import VanActionSheet, { ActionSheetAction } from '..';
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -2,7 +2,7 @@
import VanAddressEdit from '..'; import VanAddressEdit from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { areaList } from '@vant/area-data'; import { areaList } from '@vant/area-data';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -1,7 +1,12 @@
import { defineComponent, type PropType } from 'vue'; import { defineComponent, type PropType } from 'vue';
// Utils // Utils
import { createNamespace, extend, makeRequiredProp } from '../utils'; import {
extend,
createNamespace,
makeRequiredProp,
type Numeric,
} from '../utils';
// Components // Components
import { Tag } from '../tag'; import { Tag } from '../tag';
@ -12,8 +17,8 @@ import { Radio } from '../radio';
const [name, bem] = createNamespace('address-item'); const [name, bem] = createNamespace('address-item');
export type AddressListAddress = { export type AddressListAddress = {
id: number | string; id: Numeric;
tel: number | string; tel: Numeric;
name: string; name: string;
address: string; address: string;
isDefault?: boolean; isDefault?: boolean;

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanAddressList from '..'; import VanAddressList from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -3,7 +3,7 @@ import VanArea from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { areaList } from '@vant/area-data'; import { areaList } from '@vant/area-data';
import { areaListEn } from './area-en'; import { areaListEn } from './area-en';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -13,6 +13,7 @@ import {
numericProp, numericProp,
makeStringProp, makeStringProp,
createNamespace, createNamespace,
type Numeric,
} from '../utils'; } from '../utils';
const [name, bem] = createNamespace('badge'); const [name, bem] = createNamespace('badge');
@ -28,7 +29,7 @@ const badgeProps = {
max: numericProp, max: numericProp,
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'), tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
color: String, color: String,
offset: Array as unknown as PropType<[string | number, string | number]>, offset: Array as unknown as PropType<[Numeric, Numeric]>,
content: numericProp, content: numericProp,
showZero: truthProp, showZero: truthProp,
position: makeStringProp<BadgePosition>('top-right'), position: makeStringProp<BadgePosition>('top-right'),

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanBadge from '..'; import VanBadge from '..';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import VanButton from '..'; import VanButton from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -107,7 +107,7 @@ const t = useTranslate({
<van-button <van-button
plain plain
type="primary" type="primary"
icon="https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png" :icon="cdnURL('user-active.png')"
:text="t('button')" :text="t('button')"
/> />
</demo-block> </demo-block>

View File

@ -1,6 +1,6 @@
<script setup> <script setup>
import VanCalendar from '..'; import VanCalendar from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const minDate = new Date(2012, 0, 10); const minDate = new Date(2012, 0, 10);
const maxDate = new Date(2012, 2, 20); const maxDate = new Date(2012, 2, 20);

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanCalendar from '..'; import VanCalendar from '..';
import { reactive } from 'vue'; import { reactive } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import TiledDisplay from './TiledDisplay.vue'; import TiledDisplay from './TiledDisplay.vue';
import type { CalendarDayItem } from '../types'; import type { CalendarDayItem } from '../types';

View File

@ -1,4 +1,5 @@
import type { ComponentPublicInstance, ComputedRef, Ref } from 'vue'; import type { ComponentPublicInstance, ComputedRef, Ref } from 'vue';
import type { Numeric } from '../utils';
import type { CalendarProps } from './Calendar'; import type { CalendarProps } from './Calendar';
import type { CalendarMonthProps } from './CalendarMonth'; import type { CalendarMonthProps } from './CalendarMonth';
@ -18,7 +19,7 @@ export type CalendarDayType =
export type CalendarDayItem = { export type CalendarDayItem = {
date?: Date; date?: Date;
text?: string | number; text?: Numeric;
type?: CalendarDayType; type?: CalendarDayType;
topInfo?: string; topInfo?: string;
className?: unknown; className?: unknown;

View File

@ -2,7 +2,7 @@
import VanCard from '..'; import VanCard from '..';
import VanTag from '../../tag'; import VanTag from '../../tag';
import VanButton from '../../button'; import VanButton from '../../button';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -16,7 +16,7 @@ const t = useTranslate({
}, },
}); });
const imageURL = 'https://cdn.jsdelivr.net/npm/@vant/assets/ipad.jpeg'; const imageURL = cdnURL('ipad.jpeg');
</script> </script>
<template> <template>

View File

@ -14,6 +14,7 @@ import {
makeStringProp, makeStringProp,
createNamespace, createNamespace,
HAPTICS_FEEDBACK, HAPTICS_FEEDBACK,
type Numeric,
} from '../utils'; } from '../utils';
// Components // Components
@ -68,7 +69,7 @@ export default defineComponent({
const getSelectedOptionsByValue = ( const getSelectedOptionsByValue = (
options: CascaderOption[], options: CascaderOption[],
value: string | number value: Numeric
): CascaderOption[] | undefined => { ): CascaderOption[] | undefined => {
for (const option of options) { for (const option of options) {
if (option[valueKey] === value) { if (option[valueKey] === value) {

View File

@ -3,10 +3,11 @@ import VanField from '../../field';
import VanPopup from '../../popup'; import VanPopup from '../../popup';
import VanCascader, { CascaderOption } from '..'; import VanCascader, { CascaderOption } from '..';
import { computed, reactive } from 'vue'; import { computed, reactive } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { deepClone } from '../../utils/deep-clone'; import { deepClone } from '../../utils/deep-clone';
import zhCNOptions from './area-zh-CN'; import zhCNOptions from './area-zh-CN';
import enUSOptions from './area-en-US'; import enUSOptions from './area-en-US';
import type { Numeric } from '../../utils';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -55,7 +56,7 @@ const t = useTranslate({
type StateItem = { type StateItem = {
show: boolean; show: boolean;
value: string | number | undefined; value: Numeric | undefined;
result: string; result: string;
options?: CascaderOption[]; options?: CascaderOption[];
tabIndex?: number; tabIndex?: number;
@ -129,7 +130,7 @@ const onFinish = (
{ {
value, value,
selectedOptions, selectedOptions,
}: { value: number | string; selectedOptions: CascaderOption[] } }: { value: Numeric; selectedOptions: CascaderOption[] }
) => { ) => {
const result = selectedOptions const result = selectedOptions
.map((option) => option.text || option.name) .map((option) => option.text || option.name)

View File

@ -1,6 +1,8 @@
import type { Numeric } from '../utils';
export type CascaderOption = { export type CascaderOption = {
text?: string; text?: string;
value?: string | number; value?: Numeric;
color?: string; color?: string;
disabled?: boolean; disabled?: boolean;
children?: CascaderOption[]; children?: CascaderOption[];

View File

@ -3,7 +3,7 @@ import VanCellGroup from '../../cell-group';
import VanCell from '..'; import VanCell from '..';
import VanTag from '../../tag'; import VanTag from '../../tag';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -7,6 +7,7 @@ import {
unknownProp, unknownProp,
makeStringProp, makeStringProp,
makeRequiredProp, makeRequiredProp,
type Numeric,
} from '../utils'; } from '../utils';
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -16,7 +17,7 @@ export type CheckerLabelPosition = 'left' | 'right';
export type CheckerParent = { export type CheckerParent = {
props: { props: {
disabled?: boolean; disabled?: boolean;
iconSize?: number | string; iconSize?: Numeric;
direction?: CheckerDirection; direction?: CheckerDirection;
checkedColor?: string; checkedColor?: string;
}; };

View File

@ -5,7 +5,7 @@ import VanButton from '../../button';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ref, reactive } from 'vue'; import { ref, reactive } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import { useRefs } from '../../composables/use-refs'; import { useRefs } from '../../composables/use-refs';
import type { CheckboxInstance } from '../types'; import type { CheckboxInstance } from '../types';
import type { CheckboxGroupInstance } from '../../checkbox-group'; import type { CheckboxGroupInstance } from '../../checkbox-group';
@ -49,7 +49,7 @@ const state = reactive({
checkbox3: true, checkbox3: true,
checkboxShape: true, checkboxShape: true,
checkboxLabel: true, checkboxLabel: true,
checboxIcon: true, checkboxIcon: true,
list: ['a', 'b'], list: ['a', 'b'],
result: ['a', 'b'], result: ['a', 'b'],
result2: [], result2: [],
@ -58,9 +58,8 @@ const state = reactive({
horizontalResult: [], horizontalResult: [],
}); });
const activeIcon = 'https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png'; const activeIcon = cdnURL('user-active.png');
const inactiveIcon = const inactiveIcon = cdnURL('user-inactive.png');
'https://cdn.jsdelivr.net/npm/@vant/assets/user-inactive.png';
const group = ref<CheckboxGroupInstance>(); const group = ref<CheckboxGroupInstance>();
const [refs, setRefs] = useRefs<CheckboxInstance>(); const [refs, setRefs] = useRefs<CheckboxInstance>();
@ -105,7 +104,7 @@ const toggleAll = () => {
</demo-block> </demo-block>
<demo-block :title="t('customIconSize')"> <demo-block :title="t('customIconSize')">
<van-checkbox v-model="state.checboxIcon" icon-size="24px"> <van-checkbox v-model="state.checkboxIcon" icon-size="24px">
{{ t('customIconSize') }} {{ t('customIconSize') }}
</van-checkbox> </van-checkbox>
</demo-block> </demo-block>

View File

@ -16,13 +16,14 @@ import {
makeNumberProp, makeNumberProp,
makeNumericProp, makeNumericProp,
createNamespace, createNamespace,
type Numeric,
} from '../utils'; } from '../utils';
const [name, bem] = createNamespace('circle'); const [name, bem] = createNamespace('circle');
let uid = 0; let uid = 0;
const format = (rate: string | number) => Math.min(Math.max(+rate, 0), 100); const format = (rate: Numeric) => Math.min(Math.max(+rate, 0), 100);
function getPath(clockwise: boolean, viewBoxSize: number) { function getPath(clockwise: boolean, viewBoxSize: number) {
const sweepFlag = clockwise ? 1 : 0; const sweepFlag = clockwise ? 1 : 0;

View File

@ -2,7 +2,7 @@
import VanCircle from '..'; import VanCircle from '..';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanRow from '../../row'; import VanRow from '../../row';
import VanCol from '..'; import VanCol from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -4,14 +4,19 @@ import {
type InjectionKey, type InjectionKey,
type ExtractPropTypes, type ExtractPropTypes,
} from 'vue'; } from 'vue';
import { truthProp, createNamespace, BORDER_TOP_BOTTOM } from '../utils'; import {
truthProp,
createNamespace,
BORDER_TOP_BOTTOM,
type Numeric,
} from '../utils';
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
const [name, bem] = createNamespace('collapse'); const [name, bem] = createNamespace('collapse');
export type CollapseProvide = { export type CollapseProvide = {
toggle: (name: number | string, expanded: boolean) => void; toggle: (name: Numeric, expanded: boolean) => void;
isExpanded: (name: number | string) => boolean; isExpanded: (name: Numeric) => boolean;
}; };
export const COLLAPSE_KEY: InjectionKey<CollapseProvide> = Symbol(name); export const COLLAPSE_KEY: InjectionKey<CollapseProvide> = Symbol(name);
@ -20,9 +25,7 @@ const collapseProps = {
border: truthProp, border: truthProp,
accordion: Boolean, accordion: Boolean,
modelValue: { modelValue: {
type: [String, Number, Array] as PropType< type: [String, Number, Array] as PropType<Numeric | Numeric[]>,
string | number | Array<string | number>
>,
default: '', default: '',
}, },
}; };
@ -30,7 +33,7 @@ const collapseProps = {
export type CollapseProps = ExtractPropTypes<typeof collapseProps>; export type CollapseProps = ExtractPropTypes<typeof collapseProps>;
function validateModelValue( function validateModelValue(
modelValue: string | number | Array<string | number>, modelValue: Numeric | Numeric[],
accordion: boolean accordion: boolean
) { ) {
if (accordion && Array.isArray(modelValue)) { if (accordion && Array.isArray(modelValue)) {
@ -58,28 +61,26 @@ export default defineComponent({
setup(props, { emit, slots }) { setup(props, { emit, slots }) {
const { linkChildren } = useChildren(COLLAPSE_KEY); const { linkChildren } = useChildren(COLLAPSE_KEY);
const updateName = (name: number | string | Array<number | string>) => { const updateName = (name: Numeric | Numeric[]) => {
emit('change', name); emit('change', name);
emit('update:modelValue', name); emit('update:modelValue', name);
}; };
const toggle = (name: number | string, expanded: boolean) => { const toggle = (name: Numeric, expanded: boolean) => {
const { accordion, modelValue } = props; const { accordion, modelValue } = props;
if (accordion) { if (accordion) {
updateName(name === modelValue ? '' : name); updateName(name === modelValue ? '' : name);
} else if (expanded) { } else if (expanded) {
updateName((modelValue as Array<number | string>).concat(name)); updateName((modelValue as Numeric[]).concat(name));
} else { } else {
updateName( updateName(
(modelValue as Array<number | string>).filter( (modelValue as Numeric[]).filter((activeName) => activeName !== name)
(activeName) => activeName !== name
)
); );
} }
}; };
const isExpanded = (name: number | string) => { const isExpanded = (name: Numeric) => {
const { accordion, modelValue } = props; const { accordion, modelValue } = props;
if ( if (
@ -91,7 +92,7 @@ export default defineComponent({
return accordion return accordion
? modelValue === name ? modelValue === name
: (modelValue as Array<number | string>).includes(name); : (modelValue as Numeric[]).includes(name);
}; };
linkChildren({ toggle, isExpanded }); linkChildren({ toggle, isExpanded });

View File

@ -3,7 +3,7 @@ import VanCollapse from '..';
import VanCollapseItem from '../../collapse-item'; import VanCollapseItem from '../../collapse-item';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -13,6 +13,7 @@ import {
kebabCase, kebabCase,
makeStringProp, makeStringProp,
createNamespace, createNamespace,
type Numeric,
} from '../utils'; } from '../utils';
const [name, bem] = createNamespace('config-provider'); const [name, bem] = createNamespace('config-provider');
@ -29,14 +30,14 @@ export const CONFIG_PROVIDER_KEY: InjectionKey<ConfigProviderProvide> =
const configProviderProps = { const configProviderProps = {
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'), tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
theme: makeStringProp<ConfigProviderTheme>('light'), theme: makeStringProp<ConfigProviderTheme>('light'),
themeVars: Object as PropType<Record<string, string | number>>, themeVars: Object as PropType<Record<string, Numeric>>,
iconPrefix: String, iconPrefix: String,
}; };
export type ConfigProviderProps = ExtractPropTypes<typeof configProviderProps>; export type ConfigProviderProps = ExtractPropTypes<typeof configProviderProps>;
function mapThemeVarsToCSSVars(themeVars: Record<string, string | number>) { function mapThemeVarsToCSSVars(themeVars: Record<string, Numeric>) {
const cssVars: Record<string, string | number> = {}; const cssVars: Record<string, Numeric> = {};
Object.keys(themeVars).forEach((key) => { Object.keys(themeVars).forEach((key) => {
cssVars[`--van-${kebabCase(key)}`] = themeVars[key]; cssVars[`--van-${kebabCase(key)}`] = themeVars[key];
}); });

View File

@ -8,7 +8,7 @@ import VanSwitch from '../../switch';
import VanSlider from '../../slider'; import VanSlider from '../../slider';
import VanButton from '../../button'; import VanButton from '../../button';
import VanConfigProvider from '..'; import VanConfigProvider from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanContactCard from '..'; import VanContactCard from '..';
import { computed } from 'vue'; import { computed } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import VanContactEdit, { type ContactEditInfo } from '..'; import VanContactEdit, { type ContactEditInfo } from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -1,7 +1,7 @@
import { defineComponent, type PropType, type ExtractPropTypes } from 'vue'; import { defineComponent, type PropType, type ExtractPropTypes } from 'vue';
// Utils // Utils
import { createNamespace, unknownProp } from '../utils'; import { createNamespace, unknownProp, type Numeric } from '../utils';
// Components // Components
import { Tag } from '../tag'; import { Tag } from '../tag';
@ -14,8 +14,8 @@ import { RadioGroup } from '../radio-group';
const [name, bem, t] = createNamespace('contact-list'); const [name, bem, t] = createNamespace('contact-list');
export type ContactListItem = { export type ContactListItem = {
id?: number | string; id?: Numeric;
tel: number | string; tel: Numeric;
name: string; name: string;
isDefault?: boolean; isDefault?: boolean;
}; };

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanContactList from '..'; import VanContactList from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -3,7 +3,7 @@ import VanGrid from '../../grid';
import VanGridItem from '../../grid-item'; import VanGridItem from '../../grid-item';
import VanCountDown, { type CountDownInstance } from '..'; import VanCountDown, { type CountDownInstance } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -3,7 +3,7 @@ import VanCouponCell from '../../coupon-cell';
import VanPopup from '../../popup'; import VanPopup from '../../popup';
import VanCouponList from '..'; import VanCouponList from '..';
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { CouponInfo } from '../../coupon'; import { CouponInfo } from '../../coupon';
import { Toast } from '../../toast'; import { Toast } from '../../toast';

View File

@ -1,5 +1,6 @@
import { later, mount } from '../../../test'; import { later, mount } from '../../../test';
import { CouponList } from '..'; import { CouponList } from '..';
import { cdnURL } from '../../../docs/site';
const coupon = { const coupon = {
id: 1, id: 1,
@ -106,7 +107,7 @@ test('should have two "van-coupon-list__empty" classes when render coupon list i
test('should use custom src when using empty-image prop', async () => { test('should use custom src when using empty-image prop', async () => {
const wrapper = mount(CouponList, { const wrapper = mount(CouponList, {
props: { props: {
emptyImage: 'https://cdn.jsdelivr.net/npm/@vant/assets/xxx.jpeg', emptyImage: cdnURL('xxx.jpeg'),
}, },
}); });

View File

@ -1,10 +1,15 @@
import { computed, defineComponent, type PropType } from 'vue'; import { computed, defineComponent, type PropType } from 'vue';
import { makeStringProp, createNamespace, makeRequiredProp } from '../utils'; import {
makeStringProp,
createNamespace,
makeRequiredProp,
type Numeric,
} from '../utils';
import { getDate, formatAmount, formatDiscount } from './utils'; import { getDate, formatAmount, formatDiscount } from './utils';
import { Checkbox } from '../checkbox'; import { Checkbox } from '../checkbox';
export type CouponInfo = { export type CouponInfo = {
id: string | number; id: Numeric;
name: string; name: string;
endAt: number; endAt: number;
value: number; value: number;

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import { Dialog } from '..'; import { Dialog } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import type { DialogAction } from '../types'; import type { DialogAction } from '../types';
const VanDialog = Dialog.Component; const VanDialog = Dialog.Component;
@ -36,7 +36,7 @@ const t = useTranslate({
}); });
const show = ref(false); const show = ref(false);
const image = 'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg'; const image = cdnURL('apple-3.jpeg');
const onClickAlert = () => { const onClickAlert = () => {
Dialog.alert({ Dialog.alert({

View File

@ -1,6 +1,6 @@
import { Dialog } from './function-call'; import { Dialog } from './function-call';
import type { CSSProperties, TeleportProps } from 'vue'; import type { CSSProperties, TeleportProps } from 'vue';
import type { Interceptor } from '../utils'; import type { Interceptor, Numeric } from '../utils';
export type DialogTheme = 'default' | 'round-button'; export type DialogTheme = 'default' | 'round-button';
export type DialogAction = 'confirm' | 'cancel'; export type DialogAction = 'confirm' | 'cancel';
@ -9,7 +9,7 @@ export type DialogMessageAlign = 'left' | 'center' | 'right';
export type DialogOptions = { export type DialogOptions = {
title?: string; title?: string;
width?: string | number; width?: Numeric;
theme?: DialogTheme; theme?: DialogTheme;
message?: DialogMessage; message?: DialogMessage;
overlay?: boolean; overlay?: boolean;

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import VanDivider from '..'; import VanDivider from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,10 +1,11 @@
import type { DropdownItemProps } from './DropdownItem'; import type { DropdownItemProps } from './DropdownItem';
import type { VNode, ComponentPublicInstance } from 'vue'; import type { VNode, ComponentPublicInstance } from 'vue';
import type { Numeric } from '../utils';
export type DropdownItemOption = { export type DropdownItemOption = {
text: string; text: string;
icon?: string; icon?: string;
value: number | string; value: Numeric;
}; };
export type DropdownItemExpose = { export type DropdownItemExpose = {

View File

@ -5,7 +5,7 @@ import VanCell from '../../cell';
import VanSwitch from '../../switch'; import VanSwitch from '../../switch';
import VanButton from '../../button'; import VanButton from '../../button';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import type { DropdownItemInstance } from '../../dropdown-item'; import type { DropdownItemInstance } from '../../dropdown-item';
const t = useTranslate({ const t = useTranslate({

View File

@ -4,7 +4,7 @@ import VanTabs from '../../tabs';
import VanTab from '../../tab'; import VanTab from '../../tab';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -52,7 +52,7 @@ const active = ref('error');
<demo-block :title="t('customImage')"> <demo-block :title="t('customImage')">
<van-empty <van-empty
class="custom-image" class="custom-image"
image="https://cdn.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" :image="cdnURL('custom-empty-image.png')"
:description="t('description')" :description="t('description')"
/> />
</demo-block> </demo-block>

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -3,7 +3,7 @@ import VanField from '..';
import VanButton from '../../button'; import VanButton from '../../button';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanField from '..'; import VanField from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -4,7 +4,7 @@ import VanField from '../../field';
import VanButton from '../../button'; import VanButton from '../../button';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { FieldValidateError } from '../../field/types'; import { FieldValidateError } from '../../field/types';
const t = useTranslate({ const t = useTranslate({

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import VanForm from '..'; import VanForm from '..';
import VanRate from '../../rate'; import VanRate from '../../rate';
import VanRadio from '../../radio'; import VanRadio from '../../radio';
@ -54,9 +54,7 @@ const rate = ref(3);
const radio = ref('1'); const radio = ref('1');
const slider = ref(50); const slider = ref(50);
const stepper = ref(1); const stepper = ref(1);
const uploader = ref([ const uploader = ref([{ url: cdnURL('leaf.jpeg') }]);
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/leaf.jpeg' },
]);
const checkbox = ref(false); const checkbox = ref(false);
const checkboxGroup = ref([]); const checkboxGroup = ref([]);
const switchChecked = ref(false); const switchChecked = ref(false);

View File

@ -4,7 +4,7 @@ import VanField from '../../field';
import VanPopup from '../../popup'; import VanPopup from '../../popup';
import { ref } from 'vue'; import { ref } from 'vue';
import { areaList } from '@vant/area-data'; import { areaList } from '@vant/area-data';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { areaListEn } from '../../area/demo/area-en'; import { areaListEn } from '../../area/demo/area-en';
import type { PickerConfirmEventParams } from '../../picker'; import type { PickerConfirmEventParams } from '../../picker';

View File

@ -2,7 +2,7 @@
import VanField from '../../field'; import VanField from '../../field';
import VanCalendar from '../../calendar'; import VanCalendar from '../../calendar';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -3,7 +3,7 @@ import VanField from '../../field';
import VanPopup from '../../popup'; import VanPopup from '../../popup';
import VanDatePicker from '../../date-picker'; import VanDatePicker from '../../date-picker';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import type { PickerConfirmEventParams } from '../../picker'; import type { PickerConfirmEventParams } from '../../picker';
const t = useTranslate({ const t = useTranslate({

View File

@ -3,7 +3,7 @@ import VanField from '../../field';
import VanPopup from '../../popup'; import VanPopup from '../../popup';
import VanPicker, { PickerConfirmEventParams } from '../../picker'; import VanPicker, { PickerConfirmEventParams } from '../../picker';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { basicColumns } from '../../picker/demo/data'; import { basicColumns } from '../../picker/demo/data';
const t = useTranslate({ const t = useTranslate({

View File

@ -4,7 +4,7 @@ import VanField from '../../field';
import VanButton from '../../button'; import VanButton from '../../button';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { FieldValidateError } from '../../field/types'; import { FieldValidateError } from '../../field/types';
import { Toast } from '../../toast'; import { Toast } from '../../toast';

View File

@ -2,7 +2,7 @@
import VanGrid from '..'; import VanGrid from '..';
import VanGridItem from '../../grid-item'; import VanGridItem from '../../grid-item';
import VanImage from '../../image'; import VanImage from '../../image';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -48,22 +48,13 @@ const t = useTranslate({
<demo-block :title="t('customContent')"> <demo-block :title="t('customContent')">
<van-grid :border="false" :column-num="3"> <van-grid :border="false" :column-num="3">
<van-grid-item> <van-grid-item>
<van-image <van-image fit="contain" :src="cdnURL('apple-1.jpeg')" />
fit="contain"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg"
/>
</van-grid-item> </van-grid-item>
<van-grid-item> <van-grid-item>
<van-image <van-image fit="contain" :src="cdnURL('apple-2.jpeg')" />
fit="contain"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg"
/>
</van-grid-item> </van-grid-item>
<van-grid-item> <van-grid-item>
<van-image <van-image fit="contain" :src="cdnURL('apple-3.jpeg')" />
fit="contain"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg"
/>
</van-grid-item> </van-grid-item>
</van-grid> </van-grid>
</demo-block> </demo-block>

View File

@ -6,7 +6,7 @@ import VanRow from '../../row';
import VanCol from '../../col'; import VanCol from '../../col';
import icons from '@vant/icons'; import icons from '@vant/icons';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import { Notify } from '../../notify'; import { Notify } from '../../notify';
// from https://30secondsofcode.org // from https://30secondsofcode.org
@ -63,7 +63,7 @@ const t = useTranslate({
const tab = ref(0); const tab = ref(0);
const demoIcon = 'chat-o'; const demoIcon = 'chat-o';
const demoImage = 'https://cdn.jsdelivr.net/npm/@vant/assets/icon-demo.png'; const demoImage = cdnURL('icon-demo.png');
const copy = (icon: string, option: Record<string, unknown> = {}) => { const copy = (icon: string, option: Record<string, unknown> = {}) => {
let tag = `<van-icon name="${icon}"`; let tag = `<van-icon name="${icon}"`;

View File

@ -1,5 +1,6 @@
import { Icon } from '..'; import { Icon } from '..';
import { mount } from '../../../test'; import { mount } from '../../../test';
import { cdnURL } from '../../../docs/site';
test('should render icon with builtin icon name correctly', () => { test('should render icon with builtin icon name correctly', () => {
const wrapper = mount(Icon, { const wrapper = mount(Icon, {
@ -13,7 +14,7 @@ test('should render icon with builtin icon name correctly', () => {
test('should render icon with url name correctly', () => { test('should render icon with url name correctly', () => {
const wrapper = mount(Icon, { const wrapper = mount(Icon, {
props: { props: {
name: 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg', name: cdnURL('cat.jpeg'),
}, },
}); });
expect(wrapper.html()).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ImagePreview, ImagePreviewOptions } from '..'; import { ImagePreview, ImagePreviewOptions } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const VanImagePreview = ImagePreview.Component; const VanImagePreview = ImagePreview.Component;
@ -33,10 +33,10 @@ const t = useTranslate({
}); });
const images = [ const images = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-4.jpeg', cdnURL('apple-4.jpeg'),
]; ];
const show = ref(false); const show = ref(false);

View File

@ -1,10 +1,11 @@
import { DOMWrapper } from '@vue/test-utils/dist/domWrapper'; import { DOMWrapper } from '@vue/test-utils/dist/domWrapper';
import { cdnURL } from '../../../docs/site';
import { trigger } from '../../../test'; import { trigger } from '../../../test';
export const images = [ export const images = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
]; ];
function triggerTwoFingerTouchmove( function triggerTwoFingerTouchmove(

View File

@ -3,7 +3,7 @@ import VanRow from '../../row';
import VanImage from '..'; import VanImage from '..';
import VanCol from '../../col'; import VanCol from '../../col';
import VanLoading from '../../loading'; import VanLoading from '../../loading';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -28,7 +28,7 @@ const t = useTranslate({
}, },
}); });
const image = 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg'; const image = cdnURL('cat.jpeg');
const fits = ['contain', 'cover', 'fill', 'none', 'scale-down'] as const; const fits = ['contain', 'cover', 'fill', 'none', 'scale-down'] as const;
const positions1 = ['left', 'center', 'right'] as const; const positions1 = ['left', 'center', 'right'] as const;
const positions2 = ['top', 'center', 'bottom'] as const; const positions2 = ['top', 'center', 'bottom'] as const;

View File

@ -25,6 +25,7 @@ import {
createNamespace, createNamespace,
getRootScrollTop, getRootScrollTop,
setRootScrollTop, setRootScrollTop,
type Numeric,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -58,7 +59,7 @@ const indexBarProps = {
highlightColor: String, highlightColor: String,
stickyOffsetTop: makeNumberProp(0), stickyOffsetTop: makeNumberProp(0),
indexList: { indexList: {
type: Array as PropType<Array<string | number>>, type: Array as PropType<Numeric[]>,
default: genAlphabet, default: genAlphabet,
}, },
}; };
@ -76,7 +77,7 @@ export default defineComponent({
setup(props, { emit, slots }) { setup(props, { emit, slots }) {
const root = ref<HTMLElement>(); const root = ref<HTMLElement>();
const activeAnchor = ref<string | number>(''); const activeAnchor = ref<Numeric>('');
const touch = useTouch(); const touch = useTouch();
const scrollParent = useScrollParent(root); const scrollParent = useScrollParent(root);
@ -207,7 +208,7 @@ export default defineComponent({
); );
}); });
const scrollTo = (index: string | number) => { const scrollTo = (index: Numeric) => {
selectActiveIndex = String(index); selectActiveIndex = String(index);
const match = getMatchAnchor(selectActiveIndex); const match = getMatchAnchor(selectActiveIndex);

View File

@ -5,7 +5,7 @@ import VanIndexBar from '..';
import VanIndexAnchor from '../../index-anchor'; import VanIndexAnchor from '../../index-anchor';
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,4 +1,5 @@
import type { ComponentPublicInstance } from 'vue'; import type { ComponentPublicInstance } from 'vue';
import type { Numeric } from '../utils';
import type { IndexBarProps } from './IndexBar'; import type { IndexBarProps } from './IndexBar';
export type IndexBarProvide = { export type IndexBarProvide = {
@ -6,7 +7,7 @@ export type IndexBarProvide = {
}; };
export type IndexBarExpose = { export type IndexBarExpose = {
scrollTo: (index: string | number) => void; scrollTo: (index: Numeric) => void;
}; };
export type IndexBarInstance = ComponentPublicInstance< export type IndexBarInstance = ComponentPublicInstance<

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import Lazyload from '..'; import Lazyload from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
if (window.app) { if (window.app) {
window.app.use(Lazyload, { lazyComponent: true }); window.app.use(Lazyload, { lazyComponent: true });
@ -18,19 +18,13 @@ const t = useTranslate({
}); });
const imageList = [ const imageList = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-4.jpeg', cdnURL('apple-4.jpeg'),
];
const backgroundImageList = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-5.jpeg',
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-6.jpeg',
];
const componentImageList = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-8.jpeg',
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-7.jpeg',
]; ];
const backgroundImageList = [cdnURL('apple-5.jpeg'), cdnURL('apple-6.jpeg')];
const componentImageList = [cdnURL('apple-8.jpeg'), cdnURL('apple-7.jpeg')];
</script> </script>
<template> <template>

View File

@ -5,7 +5,7 @@ import VanList from '..';
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanPullRefresh from '../../pull-refresh'; import VanPullRefresh from '../../pull-refresh';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import VanLoading from '..'; import VanLoading from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanNavBar from '..'; import VanNavBar from '..';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -2,7 +2,7 @@
import VanNoticeBar from '..'; import VanNoticeBar from '..';
import VanSwipe from '../../swipe'; import VanSwipe from '../../swipe';
import VanSwipeItem from '../../swipe-item'; import VanSwipeItem from '../../swipe-item';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -3,7 +3,7 @@ import VanCell from '../../cell';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { ref } from 'vue'; import { ref } from 'vue';
import { Notify, type NotifyType } from '..'; import { Notify, type NotifyType } from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const VanNotify = Notify.Component; const VanNotify = Notify.Component;

View File

@ -1,6 +1,7 @@
import { Notify } from './function-call'; import { Notify } from './function-call';
import type { Numeric } from '../utils';
export type NotifyMessage = string | number; export type NotifyMessage = Numeric;
export type NotifyType = 'primary' | 'success' | 'danger' | 'warning'; export type NotifyType = 'primary' | 'success' | 'danger' | 'warning';

View File

@ -21,6 +21,7 @@ import {
stopPropagation, stopPropagation,
createNamespace, createNamespace,
HAPTICS_FEEDBACK, HAPTICS_FEEDBACK,
type Numeric,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -34,7 +35,7 @@ const [name, bem] = createNamespace('number-keyboard');
export type NumberKeyboardTheme = 'default' | 'custom'; export type NumberKeyboardTheme = 'default' | 'custom';
type KeyConfig = { type KeyConfig = {
text?: number | string; text?: Numeric;
type?: KeyType; type?: KeyType;
color?: string; color?: string;
wider?: boolean; wider?: boolean;

View File

@ -3,7 +3,7 @@ import VanCell from '../../cell';
import VanField from '../../field'; import VanField from '../../field';
import VanNumberKeyboard from '..'; import VanNumberKeyboard from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -2,7 +2,7 @@
import VanButton from '../../button'; import VanButton from '../../button';
import VanOverlay from '..'; import VanOverlay from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -11,19 +11,20 @@ import {
makeNumericProp, makeNumericProp,
createNamespace, createNamespace,
BORDER_SURROUND, BORDER_SURROUND,
type Numeric,
} from '../utils'; } from '../utils';
const [name, bem, t] = createNamespace('pagination'); const [name, bem, t] = createNamespace('pagination');
type PageItem = { type PageItem = {
text: string | number; text: Numeric;
number: number; number: number;
active?: boolean; active?: boolean;
}; };
const makePage = ( const makePage = (
number: number, number: number,
text: string | number, text: Numeric,
active?: boolean active?: boolean
): PageItem => ({ number, text, active }); ): PageItem => ({ number, text, active });

View File

@ -2,7 +2,7 @@
import VanPagination from '..'; import VanPagination from '..';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -3,7 +3,7 @@ import VanPasswordInput from '..';
import VanNumberKeyboard from '../../number-keyboard'; import VanNumberKeyboard from '../../number-keyboard';
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { ComponentInstance } from '../../utils'; import { ComponentInstance } from '../../utils';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -13,7 +13,7 @@ import {
customKeyColumns, customKeyColumns,
} from './data'; } from './data';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,5 +1,6 @@
/* eslint-disable no-use-before-define */ /* eslint-disable no-use-before-define */
import type { ComponentPublicInstance } from 'vue'; import type { ComponentPublicInstance } from 'vue';
import type { Numeric } from '../utils';
import type { PickerProps } from './Picker'; import type { PickerProps } from './Picker';
export type PickerToolbarPosition = 'top' | 'bottom'; export type PickerToolbarPosition = 'top' | 'bottom';
@ -11,8 +12,8 @@ export type PickerFieldNames = {
}; };
export type PickerOption = { export type PickerOption = {
text?: string | number; text?: Numeric;
value?: string | number; value?: Numeric;
disabled?: boolean; disabled?: boolean;
children?: PickerColumn; children?: PickerColumn;
className?: unknown; className?: unknown;

View File

@ -8,7 +8,7 @@ import VanPicker from '../../picker';
import VanGrid from '../../grid'; import VanGrid from '../../grid';
import VanGridItem from '../../grid-item'; import VanGridItem from '../../grid-item';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanPopup from '..'; import VanPopup from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,5 +1,11 @@
import { computed, defineComponent, type ExtractPropTypes } from 'vue'; import { computed, defineComponent, type ExtractPropTypes } from 'vue';
import { addUnit, truthProp, numericProp, createNamespace } from '../utils'; import {
addUnit,
truthProp,
numericProp,
createNamespace,
type Numeric,
} from '../utils';
const [name, bem] = createNamespace('progress'); const [name, bem] = createNamespace('progress');
@ -15,7 +21,7 @@ const progressProps = {
percentage: { percentage: {
type: numericProp, type: numericProp,
default: 0, default: 0,
validator: (value: number | string) => value >= 0 && value <= 100, validator: (value: Numeric) => value >= 0 && value <= 100,
}, },
}; };

View File

@ -2,7 +2,7 @@
import VanProgress from '..'; import VanProgress from '..';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -3,7 +3,7 @@ import VanTabs from '../../tabs';
import VanTab from '../../tab'; import VanTab from '../../tab';
import VanPullRefresh from '..'; import VanPullRefresh from '..';
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({
@ -48,8 +48,8 @@ const preloadImage = () => {
const doge = new Image(); const doge = new Image();
const dogeFire = new Image(); const dogeFire = new Image();
doge.src = 'https://cdn.jsdelivr.net/npm/@vant/assets/doge.png'; doge.src = cdnURL('doge.png');
dogeFire.src = 'https://cdn.jsdelivr.net/npm/@vant/assets/doge-fire.jpeg'; dogeFire.src = cdnURL('doge-fire.jpeg');
}; };
onMounted(preloadImage); onMounted(preloadImage);
@ -82,21 +82,15 @@ onMounted(preloadImage);
<template #pulling="{ distance }"> <template #pulling="{ distance }">
<img <img
class="doge" class="doge"
src="https://cdn.jsdelivr.net/npm/@vant/assets/doge.png" :src="cdnURL('doge.png')"
:style="{ transform: `scale(${distance / 80})` }" :style="{ transform: `scale(${distance / 80})` }"
/> />
</template> </template>
<template #loosing> <template #loosing>
<img <img :src="cdnURL('doge.png')" class="doge" />
src="https://cdn.jsdelivr.net/npm/@vant/assets/doge.png"
class="doge"
/>
</template> </template>
<template #loading> <template #loading>
<img <img :src="cdnURL('doge-fire.jpeg')" class="doge" />
src="https://cdn.jsdelivr.net/npm/@vant/assets/doge-fire.jpeg"
class="doge"
/>
</template> </template>
<p>{{ tips }}</p> <p>{{ tips }}</p>
</van-pull-refresh> </van-pull-refresh>

View File

@ -4,7 +4,7 @@ import VanRadio from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -42,9 +42,8 @@ const radioLabel = ref('1');
const radioShape = ref('1'); const radioShape = ref('1');
const radioIconSize = ref('1'); const radioIconSize = ref('1');
const radioHorizontal = ref('1'); const radioHorizontal = ref('1');
const activeIcon = 'https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png'; const activeIcon = cdnURL('user-active.png');
const inactiveIcon = const inactiveIcon = cdnURL('user-inactive.png');
'https://cdn.jsdelivr.net/npm/@vant/assets/user-inactive.png';
</script> </script>
<template> <template>

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanRate from '..'; import VanRate from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanSearch from '..'; import VanSearch from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanShareSheet, { ShareSheetOption, ShareSheetOptions } from '..'; import VanShareSheet, { ShareSheetOption, ShareSheetOptions } from '..';
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({
@ -73,15 +73,15 @@ const multiLineOptions = computed(() => [
const customIconOptions = computed(() => [ const customIconOptions = computed(() => [
{ {
name: t('name'), name: t('name'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/custom-icon-fire.png', icon: cdnURL('custom-icon-fire.png'),
}, },
{ {
name: t('name'), name: t('name'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/custom-icon-light.png', icon: cdnURL('custom-icon-light.png'),
}, },
{ {
name: t('name'), name: t('name'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/custom-icon-water.png', icon: cdnURL('custom-icon-water.png'),
}, },
]); ]);

View File

@ -4,7 +4,7 @@ import VanGridItem from '../../grid-item';
import VanSidebar from '..'; import VanSidebar from '..';
import VanSidebarItem from '../../sidebar-item'; import VanSidebarItem from '../../sidebar-item';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -7,6 +7,7 @@ import {
makeStringProp, makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace, createNamespace,
type Numeric,
} from '../utils'; } from '../utils';
const [name, bem] = createNamespace('skeleton'); const [name, bem] = createNamespace('skeleton');
@ -26,9 +27,7 @@ const skeletonProps = {
titleWidth: numericProp, titleWidth: numericProp,
avatarShape: makeStringProp<SkeletonAvatarShape>('round'), avatarShape: makeStringProp<SkeletonAvatarShape>('round'),
rowWidth: { rowWidth: {
type: [Number, String, Array] as PropType< type: [Number, String, Array] as PropType<Numeric | Numeric[]>,
number | string | (number | string)[]
>,
default: DEFAULT_ROW_WIDTH, default: DEFAULT_ROW_WIDTH,
}, },
}; };

View File

@ -2,7 +2,7 @@
import VanSkeleton from '..'; import VanSkeleton from '..';
import VanSwitch from '../../switch'; import VanSwitch from '../../switch';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -35,7 +35,7 @@ const show = ref(false);
<van-switch v-model="show" /> <van-switch v-model="show" />
<van-skeleton title avatar :row="3" :loading="!show"> <van-skeleton title avatar :row="3" :loading="!show">
<div class="demo-preview"> <div class="demo-preview">
<img src="https://cdn.jsdelivr.net/npm/@vant/assets/logo.png" /> <img :src="cdnURL('logo.png')" />
<div class="demo-content"> <div class="demo-content">
<h3>{{ t('title') }}</h3> <h3>{{ t('title') }}</h3>
<p>{{ t('desc') }}</p> <p>{{ t('desc') }}</p>

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanSlider from '..'; import VanSlider from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -24,6 +24,7 @@ import {
callInterceptor, callInterceptor,
makeNumericProp, makeNumericProp,
HAPTICS_FEEDBACK, HAPTICS_FEEDBACK,
type Numeric,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -34,7 +35,7 @@ const [name, bem] = createNamespace('stepper');
const LONG_PRESS_INTERVAL = 200; const LONG_PRESS_INTERVAL = 200;
const LONG_PRESS_START_TIME = 600; const LONG_PRESS_START_TIME = 600;
const isEqual = (value1?: string | number, value2?: string | number) => const isEqual = (value1?: Numeric, value2?: Numeric) =>
String(value1) === String(value2); String(value1) === String(value2);
export type StepperTheme = 'default' | 'round'; export type StepperTheme = 'default' | 'round';
@ -82,7 +83,7 @@ export default defineComponent({
], ],
setup(props, { emit }) { setup(props, { emit }) {
const format = (value: string | number) => { const format = (value: Numeric) => {
const { min, max, allowEmpty, decimalLength } = props; const { min, max, allowEmpty, decimalLength } = props;
if (allowEmpty && value === '') { if (allowEmpty && value === '') {
@ -139,7 +140,7 @@ export default defineComponent({
} }
}; };
const setValue = (value: string | number) => { const setValue = (value: Numeric) => {
if (props.beforeChange) { if (props.beforeChange) {
callInterceptor(props.beforeChange, { callInterceptor(props.beforeChange, {
args: [value], args: [value],

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanStepper from '..'; import VanStepper from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({

View File

@ -3,7 +3,7 @@ import VanSteps from '..';
import VanStep from '../../step'; import VanStep from '../../step';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -2,7 +2,7 @@
import VanSticky from '..'; import VanSticky from '..';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

Some files were not shown because too many files have changed in this diff Show More