UNPKG

@coreui/vue

Version:

UI Components Library for Vue.js

87 lines (83 loc) 2.61 kB
'use strict'; var vue = require('vue'); var CCloseButton = require('../close-button/CCloseButton.js'); var props = require('../../props.js'); const CAlert = vue.defineComponent({ name: 'CAlert', props: { /** * Sets the color context of the component to one of CoreUI’s themed colors. * * @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light' */ color: props.Color, /** * Optionally add a close button to alert and allow it to self dismisss. */ dismissible: Boolean, /** * Set the alert variant to a solid. * * @values 'solid' */ variant: { type: String, validator: (value) => { return value === 'solid'; }, }, /** * Toggle the visibility of alert component. */ visible: { type: Boolean, default: true, }, }, emits: [ /** * Callback fired when the component requests to be closed. */ 'close', ], setup(props, { slots, emit }) { const visible = vue.ref(props.visible); vue.watch(() => props.visible, () => { visible.value = props.visible; }); const handleDismiss = () => { visible.value = false; emit('close'); }; return () => vue.h(vue.Transition, { enterFromClass: '', enterActiveClass: 'fade', enterToClass: 'fade show', leaveActiveClass: 'fade', }, { default: () => visible.value && vue.h('div', { class: [ 'alert', props.variant === 'solid' ? `bg-${props.color} text-white border-0` : `alert-${props.color}`, { [`alert-${props.color}`]: props.color, 'alert-dismissible': props.dismissible, }, ], }, [ slots.default && slots.default(), props.dismissible && vue.h(CCloseButton.CCloseButton, { onClick: () => { handleDismiss(); }, }), ]), }); }, }); exports.CAlert = CAlert; //# sourceMappingURL=CAlert.js.map