// Utils import { createNamespace, pick } from '../utils'; // Components import Icon from '../icon'; import Popup, { popupSharedProps } from '../popup'; import Loading from '../loading'; const [createComponent, bem] = createNamespace('action-sheet'); export default createComponent({ props: { ...popupSharedProps, title: String, actions: Array, cancelText: String, description: String, closeOnPopstate: Boolean, closeOnClickAction: Boolean, round: { type: Boolean, default: true, }, closeIcon: { type: String, default: 'cross', }, safeAreaInsetBottom: { type: Boolean, default: true, }, }, emits: ['select', 'cancel', 'update:show'], setup(props, { slots, emit }) { const popupPropKeys = Object.keys(popupSharedProps); const onUpdateShow = (show) => { emit('update:show', show); }; const onCancel = () => { onUpdateShow(false); emit('cancel'); }; const renderHeader = () => { if (props.title) { return (
{props.title}
); } }; const renderCancel = () => { if (props.cancelText) { return [
, , ]; } }; const renderOption = (item, index) => { const { name, color, subname, loading, disabled, className } = item; const Content = loading ? ( ) : ( [ {name}, subname &&
{subname}
, ] ); const onClick = () => { emit('select', item, index); if (props.closeOnClickAction) { emit('update:show', false); } }; return ( ); }; const renderOptions = () => { if (props.actions) { return props.actions.map(renderOption); } }; return () => { const { round, description } = props; const Content = slots.default && (
{slots.default()}
); const Description = description && (
{description}
); return ( {renderHeader()} {Description} {renderOptions()} {Content} {renderCancel()} ); }; }, });