chore(ActionSheet): use tsx (#8071)

This commit is contained in:
neverland 2021-02-03 10:57:52 +08:00 committed by GitHub
parent 66963db3ed
commit 3da3dfe7dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -51,9 +51,10 @@
</van-action-sheet> </van-action-sheet>
</template> </template>
<script> <script lang="ts">
import { computed, reactive, toRefs } from 'vue'; import { computed, reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import { ActionSheetAction } from '..';
import Toast from '../../toast'; import Toast from '../../toast';
const i18n = { const i18n = {
@ -100,28 +101,29 @@ export default {
}, },
}); });
const simpleActions = computed(() => [ const simpleActions = computed<ActionSheetAction[]>(() => [
{ name: t('option1') }, { name: t('option1') },
{ name: t('option2') }, { name: t('option2') },
{ name: t('option3') }, { name: t('option3') },
]); ]);
const statusActions = computed(() => [ const statusActions = computed<ActionSheetAction[]>(() => [
{ name: t('coloredOption'), color: '#ee0a24' }, { name: t('coloredOption'), color: '#ee0a24' },
{ name: t('disabledOption'), disabled: true }, { name: t('disabledOption'), disabled: true },
{ loading: true }, { loading: true },
]); ]);
const actionsWithDescription = computed(() => [ const actionsWithDescription = computed<ActionSheetAction[]>(() => [
{ name: t('option1') }, { name: t('option1') },
{ name: t('option2') }, { name: t('option2') },
{ name: t('option3'), subname: t('subname') }, { name: t('option3'), subname: t('subname') },
]); ]);
const onSelect = (item) => { const onSelect = (item: ActionSheetAction) => {
state.show.basic = false; state.show.basic = false;
Toast(item.name); Toast(item.name);
}; };
const onCancel = () => Toast(t('cancel')); const onCancel = () => Toast(t('cancel'));
return { return {

View File

@ -1,3 +1,5 @@
import { PropType } from 'vue';
// Utils // Utils
import { createNamespace, pick } from '../utils'; import { createNamespace, pick } from '../utils';
@ -8,11 +10,21 @@ import Loading from '../loading';
const [createComponent, bem] = createNamespace('action-sheet'); const [createComponent, bem] = createNamespace('action-sheet');
export type ActionSheetAction = {
name?: string;
color?: string;
subname?: string;
loading?: boolean;
disabled?: boolean;
callback?: (action: ActionSheetAction) => void;
className?: any;
};
export default createComponent({ export default createComponent({
props: { props: {
...popupSharedProps, ...popupSharedProps,
title: String, title: String,
actions: Array, actions: Array as PropType<ActionSheetAction[]>,
cancelText: String, cancelText: String,
description: String, description: String,
closeOnPopstate: Boolean, closeOnPopstate: Boolean,
@ -40,7 +52,7 @@ export default createComponent({
setup(props, { slots, emit }) { setup(props, { slots, emit }) {
const popupPropKeys = Object.keys(popupSharedProps); const popupPropKeys = Object.keys(popupSharedProps);
const onUpdateShow = (show) => { const onUpdateShow = (show: boolean) => {
emit('update:show', show); emit('update:show', show);
}; };
@ -77,7 +89,7 @@ export default createComponent({
} }
}; };
const renderOption = (item, index) => { const renderOption = (item: ActionSheetAction, index: number) => {
const { const {
name, name,
color, color,