Skip to content

Commit e540876

Browse files
authored
refactor: reorganize all components (youzan#8303)
1 parent 3144a63 commit e540876

File tree

193 files changed

+1307
-400
lines changed

Some content is hidden

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

193 files changed

+1307
-400
lines changed

src/action-bar-button/index.tsx renamed to src/action-bar-button/ActionBarButton.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { computed, PropType } from 'vue';
1+
import { computed, PropType, defineComponent } from 'vue';
22
import { createNamespace } from '../utils';
3-
import { ACTION_BAR_KEY } from '../action-bar';
3+
import { ACTION_BAR_KEY } from '../action-bar/ActionBar';
44

55
// Composables
66
import { useParent } from '@vant/use';
@@ -10,9 +10,11 @@ import { useRoute, routeProps } from '../composables/use-route';
1010
// Components
1111
import Button, { ButtonType } from '../button';
1212

13-
const [createComponent, bem] = createNamespace('action-bar-button');
13+
const [name, bem] = createNamespace('action-bar-button');
14+
15+
export default defineComponent({
16+
name,
1417

15-
export default createComponent({
1618
props: {
1719
...routeProps,
1820
type: String as PropType<ButtonType>,

src/action-bar-button/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { installable } from '../utils';
2+
import _ActionBarButton from './ActionBarButton';
3+
4+
const ActionBarButton = installable(_ActionBarButton);
5+
6+
export default ActionBarButton;
7+
export { ActionBarButton };

src/action-bar-icon/index.tsx renamed to src/action-bar-icon/ActionBarIcon.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { defineComponent } from 'vue';
12
import { createNamespace, UnknownProp } from '../utils';
2-
import { ACTION_BAR_KEY } from '../action-bar';
3+
import { ACTION_BAR_KEY } from '../action-bar/ActionBar';
34

45
// Composables
56
import { useParent } from '@vant/use';
@@ -9,9 +10,11 @@ import { useRoute, routeProps } from '../composables/use-route';
910
import Icon from '../icon';
1011
import Badge from '../badge';
1112

12-
const [createComponent, bem] = createNamespace('action-bar-icon');
13+
const [name, bem] = createNamespace('action-bar-icon');
14+
15+
export default defineComponent({
16+
name,
1317

14-
export default createComponent({
1518
props: {
1619
...routeProps,
1720
dot: Boolean,

src/action-bar-icon/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { installable } from '../utils';
2+
import _ActionBarIcon from './ActionBarIcon';
3+
4+
const ActionBarIcon = installable(_ActionBarIcon);
5+
6+
export default ActionBarIcon;
7+
export { ActionBarIcon };

src/action-bar/index.tsx renamed to src/action-bar/ActionBar.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import { defineComponent } from 'vue';
12
import { createNamespace } from '../utils';
23
import { useChildren } from '@vant/use';
34

4-
const [createComponent, bem] = createNamespace('action-bar');
5+
const [name, bem] = createNamespace('action-bar');
56

6-
export const ACTION_BAR_KEY = Symbol('ActionBar');
7+
export const ACTION_BAR_KEY = Symbol(name);
8+
9+
export default defineComponent({
10+
name,
711

8-
export default createComponent({
912
props: {
1013
safeAreaInsetBottom: {
1114
type: Boolean,

src/action-bar/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { installable } from '../utils';
2+
import _ActionBar from './ActionBar';
3+
4+
const ActionBar = installable(_ActionBar);
5+
6+
export default ActionBar;
7+
export { ActionBar };

src/action-sheet/index.tsx renamed to src/action-sheet/ActionSheet.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nextTick, PropType } from 'vue';
1+
import { nextTick, PropType, defineComponent } from 'vue';
22

33
// Utils
44
import { createNamespace, pick } from '../utils';
@@ -9,7 +9,7 @@ import Popup from '../popup';
99
import Loading from '../loading';
1010
import { popupSharedProps, popupSharedPropKeys } from '../popup/shared';
1111

12-
const [createComponent, bem] = createNamespace('action-sheet');
12+
const [name, bem] = createNamespace('action-sheet');
1313

1414
export type ActionSheetAction = {
1515
name?: string;
@@ -21,7 +21,9 @@ export type ActionSheetAction = {
2121
className?: unknown;
2222
};
2323

24-
export default createComponent({
24+
export default defineComponent({
25+
name,
26+
2527
props: {
2628
...popupSharedProps,
2729
title: String,

src/action-sheet/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { installable } from '../utils';
2+
import _ActionSheet from './ActionSheet';
3+
4+
const ActionSheet = installable(_ActionSheet);
5+
6+
export default ActionSheet;
7+
export { ActionSheet };
8+
export type { ActionSheetAction } from './ActionSheet';

src/address-edit/index.tsx renamed to src/address-edit/AddressEdit.tsx

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { ref, watch, computed, nextTick, reactive, PropType } from 'vue';
1+
import {
2+
ref,
3+
watch,
4+
computed,
5+
nextTick,
6+
reactive,
7+
PropType,
8+
defineComponent,
9+
} from 'vue';
210

311
// Utils
412
import { ComponentInstance, createNamespace, isObject } from '../utils';
@@ -16,11 +24,11 @@ import Toast from '../toast';
1624
import Button from '../button';
1725
import Dialog from '../dialog';
1826
import Switch from '../switch';
19-
import Detail, { AddressEditSearchItem } from './Detail';
27+
import AddressEditDetail, { AddressEditSearchItem } from './AddressEditDetail';
2028

21-
const [createComponent, bem, t] = createNamespace('address-edit');
29+
const [name, bem, t] = createNamespace('address-edit');
2230

23-
export type AddressInfo = {
31+
export type AddressEditInfo = {
2432
tel: string;
2533
name: string;
2634
city: string;
@@ -33,7 +41,7 @@ export type AddressInfo = {
3341
addressDetail: string;
3442
};
3543

36-
const defaultData: AddressInfo = {
44+
const defaultData: AddressEditInfo = {
3745
name: '',
3846
tel: '',
3947
city: '',
@@ -50,7 +58,9 @@ function isPostal(value: string) {
5058
return /^\d{6}$/.test(value);
5159
}
5260

53-
export default createComponent({
61+
export default defineComponent({
62+
name,
63+
5464
props: {
5565
areaList: Object as PropType<AreaList>,
5666
isSaving: Boolean,
@@ -85,7 +95,7 @@ export default createComponent({
8595
default: 200,
8696
},
8797
addressInfo: {
88-
type: Object as PropType<Partial<AddressInfo>>,
98+
type: Object as PropType<Partial<AddressEditInfo>>,
8999
default: () => ({ ...defaultData }),
90100
},
91101
telValidator: {
@@ -118,7 +128,7 @@ export default createComponent({
118128
const areaRef = ref<ComponentInstance>();
119129

120130
const state = reactive({
121-
data: {} as AddressInfo,
131+
data: {} as AddressEditInfo,
122132
showAreaPopup: false,
123133
detailFocused: false,
124134
errorInfo: {
@@ -359,7 +369,7 @@ export default createComponent({
359369
state.showAreaPopup = !disableArea;
360370
}}
361371
/>
362-
<Detail
372+
<AddressEditDetail
363373
show={props.showDetail}
364374
value={data.addressDetail}
365375
focused={state.detailFocused}

src/address-edit/Detail.tsx renamed to src/address-edit/AddressEditDetail.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropType, ref } from 'vue';
1+
import { PropType, ref, defineComponent } from 'vue';
22

33
// Utils
44
import { ComponentInstance, createNamespace } from '../utils';
@@ -8,15 +8,17 @@ import { isAndroid } from '../utils/validate/system';
88
import Cell from '../cell';
99
import Field from '../field';
1010

11-
const [createComponent, bem, t] = createNamespace('address-edit-detail');
11+
const [name, bem, t] = createNamespace('address-edit-detail');
1212
const android = isAndroid();
1313

1414
export type AddressEditSearchItem = {
1515
name: string;
1616
address: string;
1717
};
1818

19-
export default createComponent({
19+
export default defineComponent({
20+
name,
21+
2022
props: {
2123
show: Boolean,
2224
value: String,

src/address-edit/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { installable } from '../utils';
2+
import _AddressEdit from './AddressEdit';
3+
4+
const AddressEdit = installable(_AddressEdit);
5+
6+
export default AddressEdit;
7+
export { AddressEdit };

src/address-list/index.tsx renamed to src/address-list/AddressList.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import { PropType } from 'vue';
1+
import { PropType, defineComponent } from 'vue';
22

33
// Utils
44
import { createNamespace } from '../utils';
55

66
// Components
77
import Button from '../button';
88
import RadioGroup from '../radio-group';
9-
import AddressItem, { AddressListItem } from './Item';
9+
import AddressListItem, { AddressListAddress } from './AddressListItem';
1010

11-
const [createComponent, bem, t] = createNamespace('address-list');
11+
const [name, bem, t] = createNamespace('address-list');
12+
13+
export default defineComponent({
14+
name,
1215

13-
export default createComponent({
1416
props: {
1517
modelValue: [Number, String],
1618
disabledText: String,
1719
addButtonText: String,
1820
defaultTagText: String,
1921
list: {
20-
type: Array as PropType<AddressListItem[]>,
22+
type: Array as PropType<AddressListAddress[]>,
2123
default: () => [],
2224
},
2325
disabledList: {
24-
type: Array as PropType<AddressListItem[]>,
26+
type: Array as PropType<AddressListAddress[]>,
2527
default: () => [],
2628
},
2729
switchable: {
@@ -42,7 +44,7 @@ export default createComponent({
4244

4345
setup(props, { slots, emit }) {
4446
const renderItem = (
45-
item: AddressListItem,
47+
item: AddressListAddress,
4648
index: number,
4749
disabled?: boolean
4850
) => {
@@ -63,7 +65,7 @@ export default createComponent({
6365
};
6466

6567
return (
66-
<AddressItem
68+
<AddressListItem
6769
v-slots={{
6870
bottom: slots['item-bottom'],
6971
}}
@@ -79,7 +81,7 @@ export default createComponent({
7981
);
8082
};
8183

82-
const renderList = (list: AddressListItem[], disabled?: boolean) => {
84+
const renderList = (list: AddressListAddress[], disabled?: boolean) => {
8385
if (list) {
8486
return list.map((item, index) => renderItem(item, index, disabled));
8587
}

src/address-list/Item.tsx renamed to src/address-list/AddressListItem.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropType } from 'vue';
1+
import { PropType, defineComponent } from 'vue';
22

33
// Utils
44
import { createNamespace } from '../utils';
@@ -9,23 +9,25 @@ import Icon from '../icon';
99
import Cell from '../cell';
1010
import Radio from '../radio';
1111

12-
const [createComponent, bem] = createNamespace('address-item');
12+
const [name, bem] = createNamespace('address-item');
1313

14-
export type AddressListItem = {
14+
export type AddressListAddress = {
1515
id: number | string;
1616
tel: number | string;
1717
name: string;
1818
address: string;
1919
isDefault?: boolean;
2020
};
2121

22-
export default createComponent({
22+
export default defineComponent({
23+
name,
24+
2325
props: {
2426
disabled: Boolean,
2527
switchable: Boolean,
2628
defaultTagText: String,
2729
address: {
28-
type: Object as PropType<AddressListItem>,
30+
type: Object as PropType<AddressListAddress>,
2931
required: true,
3032
},
3133
},

src/address-list/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { installable } from '../utils';
2+
import _AddressList from './AddressList';
3+
4+
const AddressList = installable(_AddressList);
5+
6+
export default AddressList;
7+
export { AddressList };

src/area/index.tsx renamed to src/area/Area.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import {
77
nextTick,
88
PropType,
99
onMounted,
10+
defineComponent,
1011
} from 'vue';
1112

1213
// Utils
1314
import { deepClone } from '../utils/deep-clone';
1415
import { pick, createNamespace, ComponentInstance } from '../utils';
16+
import { pickerProps } from '../picker/Picker';
1517

1618
// Composables
1719
import { useExpose } from '../composables/use-expose';
1820

1921
// Components
20-
import Picker, { pickerProps } from '../picker';
22+
import Picker from '../picker';
2123

22-
const [createComponent, bem] = createNamespace('area');
24+
const [name, bem] = createNamespace('area');
2325

2426
const EMPTY_CODE = '000000';
2527

@@ -40,7 +42,9 @@ export type AreaColumnOption = {
4042

4143
type ColumnType = 'province' | 'county' | 'city';
4244

43-
export default createComponent({
45+
export default defineComponent({
46+
name,
47+
4448
props: {
4549
...pickerProps,
4650
value: String,

src/area/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { installable } from '../utils';
2+
import _Area from './Area';
3+
4+
const Area = installable(_Area);
5+
6+
export default Area;
7+
export { Area };
8+
export type { AreaList, AreaColumnOption } from './Area';

src/badge/index.tsx renamed to src/badge/Badge.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import type { PropType, CSSProperties } from 'vue';
1+
import { PropType, CSSProperties, defineComponent } from 'vue';
22
import { isDef, createNamespace } from '../utils';
33
import { isNumeric } from '../utils/validate/number';
44

5-
const [createComponent, bem] = createNamespace('badge');
5+
const [name, bem] = createNamespace('badge');
6+
7+
export default defineComponent({
8+
name,
69

7-
export default createComponent({
810
props: {
911
dot: Boolean,
1012
max: [Number, String],

0 commit comments

Comments
 (0)