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

View File

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