Alert (TAlert)

VueJs Alert component with configurable classes and infinite variants. Friendly with utility-first frameworks like TailwindCSS.

Playground:


Basic example

<t-alert variant="error" show>
  Something goes wrong
</t-alert>
Something goes wrong

Props

PropertyTypeDefault valueDescription
tagNameString'div'The tag used as wrapper
bodyTagNameString'div'The tag that wraps the alert text
dismissibleBooleantrueIf the alert can be closed and has close button
showBooleanfalseIf the alert should be shown
timeoutNumberundefinedTime in milliseconds before the alert is auto hidden
classesObject{...} (see below)The default CSS classes
fixedClassesObject{...} (see below)The default CSS Fixed classes shared for all variants
variantsObjectundefinedThe different variants of classes the component have
variant[String, Object]undefinedThe variant that should be used

Classes and variants format

This component expects an object with classes named after every child element.

The properties in that object are the following:

PropertyDescription
wrapperWrapper of the alert
bodyWrapper of the text
closeClose button
closeIconClose button svg icon

Example

{
  fixedClasses: {
    wrapper: 'rounded p-4 flex text-sm border-l-4',
    body: 'flex-grow',
    close: 'ml-4 rounded',
    closeIcon: 'h-5 w-5 fill-current'
  },
  classes: {
    wrapper: 'bg-blue-100 border-blue-500',
    body: 'text-blue-700',
    close: 'text-blue-700 hover:text-blue-500 hover:bg-blue-200',
    closeIcon: 'h-5 w-5 fill-current'
  },
  variants: {
    danger: {
      wrapper: 'bg-red-100 border-red-500',
      body: 'text-red-700',
      close: 'text-red-700 hover:text-red-500 hover:bg-red-200'
    },
    success: {
      wrapper: 'bg-green-100 border-green-500',
      body: 'text-green-700',
      close: 'text-green-700  hover:text-green-500 hover:bg-green-200'
    }
  }
}

Events

EventArgumentsDescription
shown-Emitted when the alert is shown
hidden-Emitted when alert is hidden

Slots

SlotDescription
defaultContent of the alert
closeContent of the dismiss button