UNPKG

omii-ui

Version:

使用OMII开发的WebComponents库,样式采用bootstrap。可以作为标准的esmodule使用

61 lines (60 loc) 1.6 kB
const { h, classNames } = omii; import uiBase from "../uiBase"; import { getCSSStyleSheets } from "../css"; const CLASS_NAME_FADE = "fade"; const CLASS_NAME_SHOW = "show"; export default class extends uiBase { static css = () => getCSSStyleSheets("reboot", "utilities", "alert", "close", "transitions"); // static updateOnAttributeChanged = true; static defaultProps = { themeColor: "primary", closeable: false, transitionDuration: 0.15, }; static propTypes = { themeColor: String, closeable: Boolean, transitionDuration: Number, }; #closed = false; css() { return ` .fade { transition: opacity ${this.$props.transitionDuration}s linear }`; } close() { let $alert = this.$("div.alert"); $alert.classList.remove(CLASS_NAME_SHOW); this.#closed = true; setTimeout(() => { this.update(true, true); }, this.$props.transitionDuration * 1000); } render() { let { themeColor, closeable } = this.$props; if (this.#closed) return null; return ( <div className={classNames("alert", `alert-${themeColor}`, { "alert-dismissible": closeable, fade: closeable, show: closeable, })} role="alert" > <slot></slot> {closeable ? ( <button type="button" class="btn-close" aria-label="Close" onClick={() => { this.close(); }} ></button> ) : null} </div> ); } }