// Utils import { createNamespace, pick } from '../utils'; // Components import Popup, { popupSharedProps } from '../popup'; const PRESET_ICONS = [ 'qq', 'link', 'weibo', 'wechat', 'poster', 'qrcode', 'weapp-qrcode', 'wechat-moments', ]; function getIconURL(icon) { if (PRESET_ICONS.indexOf(icon) !== -1) { return `https://img.yzcdn.cn/vant/share-sheet-${icon}.png`; } return icon; } const [createComponent, bem, t] = createNamespace('share-sheet'); export default createComponent({ props: { ...popupSharedProps, title: String, cancelText: String, description: String, options: { type: Array, default: () => [], }, closeOnPopstate: { type: Boolean, default: true, }, safeAreaInsetBottom: { type: Boolean, default: true, }, }, emits: ['cancel', 'select', 'update:show'], setup(props, { emit, slots }) { const toggle = (value) => { emit('update:show', value); }; const onCancel = () => { toggle(false); emit('cancel'); }; const onSelect = (option, index) => { emit('select', option, index); }; const renderHeader = () => { const title = slots.title ? slots.title() : props.title; const description = slots.description ? slots.description() : props.description; if (title || description) { return (
{title &&

{title}

} {description && ( {description} )}
); } }; const renderOption = (option, index) => { const { name, icon, className, description } = option; return (
{ onSelect(option, index); }} > {name && {name}} {description && ( {description} )}
); }; const renderOptions = (options, border) => (
{options.map(renderOption)}
); const renderRows = () => { const { options } = props; if (Array.isArray(options[0])) { return options.map((item, index) => renderOptions(item, index !== 0)); } return renderOptions(options); }; const renderCancelText = () => { const text = props.cancelText ?? t('cancel'); if (text) { return ( ); } }; return () => ( {renderHeader()} {renderRows()} {renderCancelText()} ); }, });