ID

Components & helpers

The building blocks every page is made of, and the small JavaScript helpers they share.

The component catalog

Your main reference is UI Kit › Components. Every component there is a live example with two buttons below it:

  • Show code reveals the exact HTML of the example above it, so the two never differ.
  • Copy puts that HTML on your clipboard, ready to paste into a page in src/pages/.

The other UI Kit pages (charts, forms, pickers, upload, data tables and more) work the same way: each example comes with its code.

Component classes

These components work on any page — the styles are in assets/css/selaras.css and the shared behavior in assets/js/selaras.js, which every page already loads.

ComponentMain classesNotes
Buttons.sl-btn .sl-btn-primary .sl-btn-light .sl-btn-sm .sl-icon-btn .sl-linkbtnColors, sizes, icon-only and text-style buttons
Badges & status.sl-status .sl-status--success .sl-chip .sl-kbdTones: success, warning, danger, info, neutral, secondary
Avatars.sl-av .sl-stack .sl-person .sl-thumbInitials, a group, an avatar with a name, image tiles
Alerts.sl-alert .sl-alert--info data-sl-dismissFour tones; the close button removes the alert
Forms.sl-field .sl-control .sl-help .sl-field-err .sl-addonA label, the input, help text and an error message
Choices.sl-choices .sl-check .sl-radio .sl-switch .sl-segCheckboxes, radios, switches, segmented control
Special inputs.sl-input .sl-pass .sl-meter .sl-otpSearch, password with strength meter, one-time code
Cards & KPIs.sl-card .sl-card-head .sl-card-title .sl-kpi .sl-kpi-valuePanels and statistic tiles
Tabs.sl-tabs .sl-tabs-panelClicks and arrow keys handled by selaras.js
Tables.sl-table-wrap .sl-table .sl-pagerScrolls sideways on small screens
Progress & loading.sl-progress .sl-spin .sl-skelBars, spinner, loading placeholders
Menus.sl-menuSkin for Bootstrap’s .dropdown-menu
Modals & toasts.sl-modal .sl-modal-head .sl-modal-body .sl-modal-foot .sl-toastBootstrap modals and tooltips, styled
Empty states.sl-emptyAn icon, a message and actions

The catalog has more: breadcrumb and pagination, accordion, list group, timeline, carousel, popover and offcanvas. Icons are Tabler Icons, written as <i class="ti ti-home"></i>. Bootstrap 5 is loaded on every page, so its grid and utility classes (row, col-md-6, d-flex, gap-3…) are available too.

JavaScript helpers

Three helpers are available on every page, from assets/js/selaras.js:

HelperWhat it does
window.slChartDraws ApexCharts charts that follow the active theme and the light/dark mode.
window.slFmtFormats numbers, money, dates and times in the page language.
window.slI18nTranslates text written by your scripts.

Charts — window.slChart

Charts use ApexCharts. Draw them through window.slChart and they take their colors from the active theme and redraw by themselves when the theme or the light/dark mode changes.

FunctionWhat it does
draw(selector, factory)Draws a chart into the element. The factory returns ApexCharts options and runs again on every theme change.
base()The shared look: font, axis and grid colors, no toolbar, no legend, no data labels.
merge(a, b)Deep-merges your options into base().
colors()The current theme colors as hex values (series, text, lines, surface).
tip(title, rows)Builds a tooltip in the Selaras style for the tooltip.custom option.

An example — a bar chart of orders per day. Add an element to your page:

HTML
<div class="sl-card">
  <div id="chart-orders" role="img" aria-label="Orders per day, Sep 21 to Sep 27"></div>
</div>

Then draw it from your page script (a file listed in the page’s "scripts" meta, which loads after selaras.js):

JavaScript
(function () {
  var K = window.slChart, F = window.slFmt, _t = window.slI18n.t;
  if (!K) return;   // ApexCharts is not loaded on this page

  var days = ['2026-09-21', '2026-09-22', '2026-09-23', '2026-09-24',
              '2026-09-25', '2026-09-26', '2026-09-27'];
  var orders = [42, 51, 47, 63, 58, 71, 39];

  K.draw('#chart-orders', function () {
    // series: C.primary, C.secondary, C.d3, C.d4
    // interface: C.ink, C.ink3, C.ink4, C.line, C.lineStrong, C.surface
    var C = K.colors();
    return K.merge(K.base(), {
      chart: { type: 'bar', height: 260 },
      series: [{ name: _t('Orders'), data: orders }],
      colors: [C.primary],
      xaxis: { categories: days.map(function (d) { return F.short(d); }) },
      yaxis: { labels: { formatter: function (v) { return F.num(v); } } },
      tooltip: {
        custom: function (o) {
          var i = o.dataPointIndex;
          return K.tip(F.date(days[i]), [
            { c: C.primary, n: _t('Orders'), v: F.num(orders[i]) }
          ]);
        }
      }
    });
  });
})();

Use the series colors in a fixed order — first primary, then secondary, then the third and fourth data colors — so the same kind of data keeps the same color across charts. UI Kit › Charts has 13 chart types built this way, each with its source.

Where charts are available

ApexCharts and window.slChart are loaded on every page that has the sidebar (src/layout.html). The sign-in, error and store pages do not load them.

Numbers, money and dates — window.slFmt

Format every figure through window.slFmt instead of writing it by hand. It follows the page language: on the English pages money is in dollars with cents, on the Indonesian pages in rupiah without decimals, and dates and times use each language’s own order.

JavaScript
var F = window.slFmt;
//                                  English          Indonesian
F.money(1234.5);                 // '$1,234.50'      'Rp1.235'
F.num(5717);                     // '5,717'          '5.717'
F.pct(12.4, 1);                  // '12.4%'          '12,4%'
F.moneyShort(1500);              // '$1.5k'          'Rp1,5rb'
F.date('2026-09-23');            // 'Sep 23, 2026'   '23 Sep 2026'
F.short('2026-09-23');           // 'Sep 23'         '23 Sep'
F.dayDate('2026-09-23');         // 'Wed, Sep 23'    'Rab, 23 Sep'
F.clock('2026-09-23T14:05');     // '2:05 PM'        '14.05'

F.parse('1,234.50');             // 1234.5  — an amount typed in a field
F.parse('');                     // null    — empty field
F.parse('abc');                  // NaN     — not an amount

Dates can be ISO text or Date objects. F.lang tells you the page language ('en' or 'id'), and F.cur the currency symbol. More helpers — int, bigMoney, monthYear, span, clockRange, hour, time, loose — are described in a short comment at the top of assets/js/selaras.js.

Text in scripts — window.slI18n

Text that your JavaScript writes goes through window.slI18n, so it can be translated. On the English pages it returns the text unchanged.

JavaScript
var _t = window.slI18n.t, _tn = window.slI18n.tn;

_t('Saved');                                   // 'Saved' (or its translation)
_t('Sent to {name}', { name: 'Ava' });         // placeholders are filled in
_tn(3, '{n} item', '{n} items');               // '3 items' (singular or plural)
window.slI18n.key('my-app-data');              // a storage key per language

How translations are stored and added is described in Languages.

Ready-made widgets

Three widgets written for Selaras need no extra library. The date picker and the uploader each come with a script — add it to the page’s "scripts" meta; the toast needs only markup and a few lines of JavaScript.

Date picker

assets/js/sl-datepicker.js picks a single date or a range and works fully with the keyboard. Mark the field with data-sl-datepicker:

HTML
<div class="sl-field">
  <label for="dueDate">Due date</label>
  <div class="sl-dp" data-sl-datepicker data-min="2026-01-01">
    <input class="sl-control" id="dueDate" type="text" autocomplete="off">
    <button class="sl-dp-toggle" type="button" aria-label="Choose due date">
      <i class="ti ti-calendar" aria-hidden="true"></i>
    </button>
  </div>
</div>
  • data-mode="range" picks a start and an end date; data-min and data-max limit the dates (ISO format).
  • The chosen date is stored as ISO text in data-value on the .sl-dp element (data-start and data-end for a range), and the input fires a change event.
  • People can also type a date into the input; it is checked when the field loses focus.
  • Fields that already exist are set up when the script loads. For a field you add later, call window.slDatepicker.setup(element).
JavaScript
document.getElementById('dueDate').addEventListener('change', function (e) {
  var picker = e.target.closest('[data-sl-datepicker]');
  var iso = picker.getAttribute('data-value');   // '2026-10-06'
});

The demo pages set data-today to a fixed date so the examples always look the same. Leave it out and the picker uses the real date.

File upload

assets/js/sl-upload.js handles drag & drop or browse, checks type and size with a clear reason when a file is refused, and shows a progress bar and an image preview per file:

HTML
<div class="sl-upload" data-sl-upload
     data-types="image/png,image/jpeg,application/pdf" data-max-mb="5" data-max-files="6">
  <input class="visually-hidden" type="file" id="files" multiple accept=".png,.jpg,.jpeg,.pdf">
  <label class="sl-upload-zone" for="files">
    <span class="sl-upload-icon" aria-hidden="true"><i class="ti ti-cloud-upload"></i></span>
    <strong>Drop files here or <span class="sl-upload-browse">browse</span></strong>
    <small>PNG, JPG or PDF · up to 5 MB each</small>
  </label>
  <ul class="sl-upload-list"></ul>
</div>
  • data-types lists the allowed MIME types, data-max-mb the size limit per file and data-max-files the number of files. Each one is optional.
  • When a file finishes, the .sl-upload element fires an sl-upload:done event with the File in event.detail.
  • For an uploader you add later, call window.slUploadSetup(element).
The upload is simulated

No file leaves the browser. To send files to your server, replace the upload() function in sl-upload.js with your own fetch or XMLHttpRequest call.

Toast

A toast is a short message in the bottom corner, for example after saving. Place a container once on the page:

HTML
<div class="sl-toast-wrap" role="status" aria-live="polite">
  <div class="sl-toast" id="myToast" hidden>
    <i class="ti ti-circle-check" aria-hidden="true"></i>
    <span id="myToastMsg"></span>
  </div>
</div>

The toast slides in when it gets the is-in class. A minimal function to show it for six seconds:

JavaScript
var toastTimer;
function showToast(msg) {
  var el = document.getElementById('myToast');
  document.getElementById('myToastMsg').textContent = msg;
  el.hidden = false;
  requestAnimationFrame(function () { el.classList.add('is-in'); });
  clearTimeout(toastTimer);
  toastTimer = setTimeout(function () {
    el.classList.remove('is-in');
    setTimeout(function () { el.hidden = true; }, 220);
  }, 6000);
}

There is no global toast function — each app keeps its own small one. For a version with an Undo button that pauses while hovered or focused, copy toast() from assets/js/ecommerce.js. For dialog-style toasts, UI Kit › SweetAlert shows SweetAlert2 styled to match.

Class names

  • Every Selaras component class starts with sl-. States use an is- class, such as is-in or is-done.
  • Give your own classes a prefix of your own (for example app-). Then they can never collide with a Selaras or Bootstrap class, now or after an update.
  • Page-specific classes in Selaras carry a short page prefix after sl- (for example sl-cx- for the component catalog). Do the same when a page needs its own styles.
  • The skins for third-party libraries (FullCalendar, DataTables, Flatpickr and others) target the library’s own classes. Each one sits under its own heading comment in selaras.css.

Accessibility

The components come with keyboard support and the right ARIA attributes, so you start from accessible markup:

  • Tabs — arrow keys, Home and End move between tabs; only the selected tab is in the Tab order.
  • Customizer options — the theme and mode choices behave as radio groups and work with the arrow keys.
  • Alerts — closing an alert moves focus to the next element instead of the top of the page.
  • Modals, dropdowns, offcanvas, tooltips and popovers use Bootstrap’s built-in keyboard and focus handling.
  • Date picker — follows the WAI-ARIA date picker dialog pattern: arrow keys, Page Up/Down for months, Enter to pick, Escape to close.
  • File upload — the real file input stays reachable with the keyboard, and results are announced to screen readers.
  • Toasts are announced through an aria-live region.
  • Charts have role="img" and a text summary in aria-label; the charts in UI Kit › Charts can also be shown as a table.
  • Focus is always visible when you use the keyboard, animations are turned off when the system asks for reduced motion, and the text colors of all five themes meet WCAG AA contrast in light and dark mode.

When you build new markup, keep the same habits: give icon-only buttons an aria-label, mark decorative icons with aria-hidden="true" and connect every input to a <label>.