imajus:bootstrap-helpers

v0.0.10Published 3 weeks ago

Overview

Some Meteor Blaze templates to speed up layout development for Bootstrap3 & Bootstrap4 UI frameworks.

Installation

meteor add imajus:bootstrap-helpers

Related packages

Contents

Package provide different sets of templates for Bootstrap3 and Bootstrap4 UI frameworks.

Bootstrap 3

Following helpers are provided for Bootstrap 3:

  • {{>breadcrumbs items=Array}} – Renders breadcrumbs component. Expects items array of objects with following structure:
    1{
    2  // Item text
    3  label: String,
    4  // (optional) <li> attributes
    5  liAtts: Object,
    6  // (optional) <a> src attribute value, if not provided a label will be displayed as static text
    7  href: String,
    8  // (optional) Additional anchor attributes, skipped if href is not provided
    9  anchorAtts: Object,
    10}
  • {{#carousel items=Array}}...{{/carousel}} - Renders carousel component.
  • {{>i bs=String fa=String}} - Renders Bootstrap3 or FontAwesome4 icon. Supports various appeareance modifiers (FontAwesome4 only):
    {{>i fa='cog' spin=true size="4x" border=true pull="right"}}
  • {{#collapse id=String active=Boolean title=String}}...{{/collapse}} - Renders collapse component.
    {{#collapse id="myContent" title='Click to see'}}
      Some initially hidden content goes here.
    {{/collapse}}
  • {{#modal id=String title=String close=String submit=String options=Object}}...{{/modal}} - Renders modal component. Initially, modal is hidden and you're supposed to call $('#myModal').modal('show') in order to display it.
    {{#modal id="myModal" title="My modal" close="Dismiss" submit="OK" options=modalOptions}}
      <p>Custom modal content goes here.</p>
      <p>"modalOptions" must be an object or Template helper which returns an object</p>
    {{/modal}}
    Note: The options object is passed to Bootstrap modal initialization function as is, e.g. passing variable which contains object { show: true } will make the modal to appear right after rendering.
  • {{#pageHeader heading=String}}...{{/pageHeader}} - Renders page header component.
  • {{#panel id=String type=String title=String badge=String}}...{{/panel}} - Renders panel component.

Bootstrap 4

By default, the package works with Bootstrap3 layout. If you need to switch to Bootstrap4, put this somewhere in your client initialization logic (before it starts rendering any templates):

1import { BootstrapHelpers } from 'meteor/imajus:bootstrap-helpers';
2BootstrapHelpers.forBootstrap4 = true;

Following components are provided for Bootstrap4:

  • {{>breadcrumbs ...}} - Same as for Bootstrap3.
  • {{#carousel ...}}...{{/carousel}} - Same as for Bootstrap3.
  • {{>i fa=String}} - Renders FontAwesome4 icon. Supports same icon modifiers as for Bootstrap3.
  • {{#collapse ...}}...{{/collapse}} - Same as for Bootstrap3.
  • {{#modal id=String title=String modalClass=String closeBtnLabel=String clostBtnType=String submitBtnLabel=String submitBtnType=String noHeader=Boolean noHeaderClose=Boolean noFooter=Boolean options=Object}}...{{/modal}} - Renders modal component. Parameters closeBtnLabel, closeBtnType, submitBtnLabel, submitBtnType, noHeader, noHeaderClose, noFooter are all optional and allows to tune modal appearence for your needs. You can adjust modal dialog classes using dialogClasses parameter.

Initially, modal is hidden and you suppose to call $('#myModal').modal('show') in order to display it.

{{#modal id='myModal' title='My modal' closeBtnLabel='Dismiss' submitBtnLabel='OK' options=modalOptions}}
  <p>Custom modal content goes here.</p>
  <p>"modalOptions" must be an object or Template helper which returns an object</p>
{{/modal}}

Note: The options object is passed to Bootstrap modal initialization function as is, e.g. passing variable which contains object { show: true } will make the modal to appear right after rendering.

  • {{#pageHeader heading=String}}...{{/pageHeader}} - Same as for Bootstrap3.
  • {{>card title=String loading=Boolean}}...{{/card}} - Renders card component, which is a direct successor of the Bootstrap3 panel component. Additionally, allows to render a loading animation when the data is not yet ready for displaying.
  • {{>toast message=String heading=String brand=String}}...{{/toast}} - Renders Toast component. The most useful when used via JavaScript API:
    {{!-- Put this in your layout template --}}
    <div class="position-relative mt-3">
      {{>toastContainer}}
    </div>
    1import { showToast, showError } from 'meteor/imajus:bootstrap-helpers';
    2showToast({
    3  heading: 'Greeting',
    4  message: 'Hello, world!',
    5  brand: 'success',
    6});
    7showError(new Error('Something went wrong!'));
  • {{>navbar title=String root=String items=Array theme=('light'|'dark') expand=('sm'|'md'|'lg'|'xl') align=(null|'center'|'right') active=(Boolean|Function)}} — Renders Navbar component. The items value needs to be built with JavaScript:
    1import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
    2Template.Layout.helpers({
    3  navbarItems: () => [
    4    {
    5      label: 'Events',
    6      link: FlowRouter.path('Events.browse'),
    7      active: () => ['Events.browse', 'Events.create', 'Events.edit'].includes(FlowRouter.getRouteName()),
    8    },
    9    {
    10      label: 'Registrations',
    11      link: FlowRouter.path('Registrations.browse'),
    12      active: () => FlowRouter.getRouteName() === 'Registrations.browse',
    13    },
    14  ],
    15});