Tank CSS Styling

Smart.Tank is a numeric control used to display a numeric value from a range of values.

Required files

Smart.Tank requires the following scripts to be referenced on a page in order for the custom element to be successfully registered and to work correctly:

  • smart.element.js -- this is the base file that defines the common architecture of all Smart custom elements. It is part of the repository ni-kismet/smart-element.
  • smart.tank.js -- this file defines the functionality of the Smart.Tank custom element.
  • smart.numeric.js -- this file contains functions used for the processing of numeric objects.
  • smart.math.js -- this file contains many of the mathematical functions used by the Smart.Tank custom element.
  • smart.tickintervalhandler.js -- this file contains functions used for calculating the tick interval of the Smart.Tank custom element.

Smart.Tank also requires the following style sheets in order to be displayed correctly.

  • smart.base.css -- the base style sheet file.

Initialization

To initialize (instantiate) a Smart.Tank custom element, insert the following tag in an HTML page:

<smart-tank></smart-tank>

To set properties of the custom element initially, do so by setting the respective attributes of the tag, e.g.:

<smart-tank orientation="vertical" min="0" max="100" value="33" scale-position="near"></smart-tank>

Getting and setting properties dynamically

Before accessing the custom element's API in JavaScript, the custom element's instance has to be retrieved:

let customElement = document.querySelector('smart-tank');

Properties are represented as members of the custom element's instance object and can be accessed as such.

Here is an example showing how to get a property dynamically:

let min = customElement.min;

Here is an example showing how to set a property dynamically:

customElement.min = 0;

Calling methods

Before accessing the custom element's API in JavaScript, the custom element's instance has to be retrieved:

let customElement = document.querySelector('smart-tank');

Methods are represented as members of the custom element's instance object and can be accessed as such.

Here is an example showing how to call a method:

customElement.val(100);

Styling (CSS API)

Smart HTML Elements use a pair of css files - smart.base.css and smart.[theme name].css. The base stylesheet creates the styles related to the element's layout like margin, padding, border-width, position. The second CSS file applies the HTML Element's colors, fonts, borders and backgrounds. The smart.base.css should be included before the second CSS file.

CSS selectors

The following CSS selectors can be used to style Smart.Tank:

  • smart-tank - the element itself. Can be used to set width and height for the whole element.
    • .smart-container - a container that holds the inner structure of the element. Normally it shoudn't be used for styling.
      • .smart-scale.smart-scale-near - a DIV element used to draw the near scale of the tank.
      • .smart-track - a DIV container that holds the fill, thumbs and inner track (used when the ticks are placed on the track).
    • .smart-value - a DIV element that represents the fill ( the value ) of the tank.
      • .smart-tooltip - a DIV element that represents the tooltip of the first thumb.
        • .smart-tooltip-content - a DIV element that holds the value for the first thumb tooltip.
    • .smart-thumb - a DIV element that represents the first thumb of the tank.
    • .smart-track-ticks-container - a DIV element that represents the inner scale of the tank ( when ticksPosition is set to "track").
      • .smart-scale.smart-scale-far - a DIV element used to draw the far scale of the tank.

CSS variables

Smart.Tank uses the following CSS variables:

  • --smart-tank-default-width - the default width of Smart.Tank/Smart.Slider.
  • --smart-tank-default-height - the default height of Smart.Tank/Smart.Slider.
  • --smart-tank-scale-size - Vertical Tank's scale width / Horizontal Tank's scale height.
  • --smart-tank-thumb-width - thumbs width.
  • --smart-tank-thumb-height - thumbs height.
  • --smart-tank-tooltip-width - tooltip width.
  • --smart-tank-tooltip-height - tooltip height.
  • --smart-tank-tick-size - scale's major ticks size. Horizontal Tank tick height / Vertical Tank tick width.
  • --smart-tank-minor-tick-size - scale's minor ticks size.
  • --smart-tank-minimum-track-size - Horizontal Tank track minimum height / Vertical Tank track minimum width.