import { use } from '../utils'; import { emit, inherit } from '../utils/functional'; import { PopupMixin } from '../mixins/popup'; import Icon from '../icon'; import Loading from '../loading'; import Popup from '../popup'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { DefaultSlots } from '../utils/use/sfc'; import { PopupMixinProps } from '../mixins/popup/type'; export type ActionsheetItem = { name: string; subname?: string; loading?: boolean; disabled?: boolean; className?: string; callback?: (item: ActionsheetItem) => void; }; export type ActionsheetProps = PopupMixinProps & { title?: string; actions: ActionsheetItem[]; cancelText?: string; safeAreaInsetBottom?: boolean; }; const [sfc, bem] = use('actionsheet'); function Actionsheet( h: CreateElement, props: ActionsheetProps, slots: DefaultSlots, ctx: RenderContext ) { const { title, cancelText } = props; const onCancel = () => { emit(ctx, 'input', false); emit(ctx, 'cancel'); }; const Header = () => (
{title}
); const Option = (item: ActionsheetItem, index: number) => (
{ event.stopPropagation(); if (!item.disabled && !item.loading) { if (item.callback) { item.callback(item); } emit(ctx, 'select', item, index); } }} > {item.loading ? ( ) : ( [ {item.name}, item.subname && {item.subname} ] )}
); return ( { emit(ctx, 'input', value); }} {...inherit(ctx)} > {title ? Header() : props.actions.map(Option)} {slots.default &&
{slots.default()}
} {cancelText && (
{cancelText}
)}
); } Actionsheet.props = { ...PopupMixin.props, title: String, actions: Array, cancelText: String, safeAreaInsetBottom: Boolean, overlay: { type: Boolean, default: true }, closeOnClickOverlay: { type: Boolean, default: true } }; export default sfc(Actionsheet);