import { tag, WeElement, classNames, h, render } from 'omi' import * as css from './index.scss' //@ts-ignore import '../theme.ts' interface Props { items: any[], actions?: any[], onClose?: (evt) => void, show?: boolean, type: 'ios' | 'android' } @tag('m-action-sheet') class ActionSheet extends WeElement { static defaultProps = { type: '', items: [], actions: [], show: false } static propTypes = { type: String, items: Object, actions: Object, show: Boolean } static css = css renderMenuItem() { return this.props.items.map((menu, idx) => { if (typeof menu === 'string') { return
this.menuClick(menu)} className='m-actionsheet__cell'> {menu}
} const { label, className, ...others } = menu const cls = classNames({ 'm-actionsheet__cell': true, [className]: className }) return (
this.menuClick(menu)} className={cls}> {label}
) }) } actionClick = (item) => { this.fire('actionclick', item) } menuClick = (item) => { this.fire('itemclick', item) } renderActions() { return this.props.actions.map((action, idx) => { const { label, className, ...others } = action const cls = classNames({ 'm-actionsheet__cell': true, [className]: className }) return (
this.actionClick(action)} {...others} className={cls}> {label}
) }) } handleMaskClick = () => { this.fire('close') } render() { const { show, type, onClose, items, actions, ...others } = this.props const cls = classNames({ 'm-actionsheet': true, 'm-actionsheet_toggle': show }) let styleType = type ? type : 'ios' return (
{this.renderMenuItem()}
{this.renderActions()}
) } } let dom export default function actionSheet(options) { if (dom) { document.body.removeChild(dom) dom = null } dom = render(, 'body') } function close() { if (dom) { document.body.removeChild(dom) dom = null } }