Alerts

Star
The Trowel project is abandonned. Trowel core and the Trowel components are no more maintained or supported. More infos

Download

You can fetch Trowel Alerts with npm, yarn or bower.

# With bower
$ bower install --save trowel-alerts

# With npm
$ npm install --save trowel-alerts

# With yarn
$ yarn add trowel-alerts

You can also download a zip archive right here.

Installation

Scss

The main scss file to include to your main .scss file is located at the ./src/scss/alerts.scss. As a Trowel Component, it also requires two dependencies to compile the scss code. Here an scss installation snippet.

// Trowel core (need to be imported first)
@import './path/to/dependencies/trowel-core/src/trowel';

// Trowel Alerts
@import './path/to/dependencies/trowel-alerts/src/scss/alerts';

JavaScript

You have several javascript files for different use cases :

Twig template

The twig template ready to be include or embed is located at ./src/twig/alert.html.twig.

Usage

<div class="alert alert--primary" role="alert">
  ...
</div>

Themes

By default, you have access to four alert themes. You can of course, totally change thoses themes, delete or add some, through trowel variables.

<div class="alert alert--primary" role="alert">
  ...
</div>

<div class="alert alert--success" role="alert">
  ...
</div>

<div class="alert alert--warning" role="alert">
  ...
</div>

<div class="alert alert--danger" role="alert">
  ...
</div>

Sizes

You also, by default, have access to 4 sizes :

<div class="alert alert--primary alert--xs" role="alert">
  ...
</div>

<div class="alert alert--primary alert--sm" role="alert">
  ...
</div>

<div class="alert alert--primary" role="alert">
  ...
</div>

<div class="alert alert--primary alert--lg" role="alert">
  ...
</div>

Auto-delete

You can add a button following the markup below. When the user click on this button, it will delete the alert.

<div class="alert alert--primary" role="alert">
  <button class="alert__times" data-alert="times">&times;</button>

  ...
</div>

In order to make it work you need to setup some javascript. You have two ways to make it work :

Javascript usage into html

<script src="./path/to/trowel-alerts/javascript/alerts.js"></script>

<script type="text/javascript">
  var alerts = new TrowelAlerts(document.querySelectorAll('.alert'));
</script>

Javascript usage with an import

import TrowelAlerts from './path/to/trowel-alerts/src/javascript/alerts';

const alerts = new TrowelAlerts(document.querySelectorAll('.alert'));

Twig usage

Instead of writing html, you can embed the twig template :

{% embed 'path/to/trowel-alerts/src/twig/alert.html.twig' with {
  'modifiers': ['primary'],
} %}
  {% block body %}lorem ipsum...{% endblock %}
{% endembed %}

If you want to add some modifiers on the block selector (.breadcrumb), you can set the array modifiers with as many modifiers as you need :

{% embed 'path/to/trowel-alerts/src/twig/alert.html.twig' with {
  'modifiers': ['primary', 'xs'],
} %}
  {% block body %}lorem ipsum...{% endblock %}
{% endembed %}

To add the times button just set as true times

{% embed 'path/to/trowel-alerts/src/twig/alert.html.twig' with {
  'times': true,
} %}
  {% block body %}lorem ipsum...{% endblock %}
{% endembed %}

Sass reference

Syntax variables

You can override the global syntax config for a specific component with the following variables

VARIABLE DEFAULT VALUE DESCRIPTION
$alerts--syntax null syntax config for .alert

Enables

You can avoid the generation of some css with the following variables

VARIABLE DEFAULT VALUE DESCRIPTION
$alerts-times--enabled true enable the generation of style rules for the .alert__times block

Component variables

VARIABLE DEFAULT VALUE DESCRIPTION
$alerts--font-size (
  'default': 1rem,
  '-xs': 0.65rem,
  '-sm': 0.8rem,
  '-lg': 1.2rem,
)
sets the font-size property
$alerts--font-family 'Open Sans', verdana, sans-serif sets the font-family property
$alerts--font-weight null sets the font-weight property
$alerts--text-transform null sets the text-transform property
$alerts--letter-spacing null sets the letter-spacing property
$alerts--line-height 1.2 sets the line-height property
$alerts--text-align null sets the text-align property
$alerts--text-decoration null sets the text-decoration property
$alerts--margin 0 0 1em sets the margin property
$alerts--padding 0.65em 1.65em sets the padding property
$alerts--border-width null sets the border-width property
$alerts--border-style null sets the border-style property
$alerts--border-color null sets the border-color property
$alerts--border-radius 0.2em sets the border-radius property
$alerts--color rgb(255, 255, 255) sets the color property
$alerts--box-shadow null sets the box-shadow property
$alerts--background null sets the background property
$alerts--background-color (
  '-primary': rgb(31, 13, 51),
  '-success': rgb(55, 211, 189),
  '-warning': rgb(255, 176, 0),
  '-danger': rgb(253, 65, 100),
)
sets the background-color property
$alerts--float null sets the float property
$alerts--width null sets the width property
$alerts--height null sets the height property
$alerts--max-width null sets the max-width property
$alerts--max-height null sets the max-height property
Times    
VARIABLE DEFAULT VALUE DESCRIPTION
$alerts-times--opacity null sets the opacity property for .alert__times
$alerts-times--float right sets the float property for .alert__times
$alerts-times--font-size inherit sets the font-size property for .alert__times
$alerts-times--font-weight null sets the font-weight property for .alert__times
$alerts-times--line-height null sets the line-height property for .alert__times
$alerts-times--color inherit sets the color property for .alert__times
$alerts-times--text-shadow null sets the text-shadow property for .alert__times
$alerts-times--box-shadow null sets the box-shadow property for .alert__times
$alerts-times--margin null sets the margin property for .alert__times
$alerts-times--padding 0 0 0.325em 0.825em sets the padding property for .alert__times
$alerts-times--border-width null sets the border-width property for .alert__times
$alerts-times--border-style null sets the border-style property for .alert__times
$alerts-times--border-color null sets the border-color property for .alert__times
$alerts-times--border-radius null sets the border-radius property for .alert__times
$alerts-times--background-color null sets the background-color property for .alert__times