bytes-label

Label to show number of bytes (f.e file size, free space, etc) with unit in such a way that the end user can choose the unit (kB, MB,...).


Keywords
Polymer, web-components, web-component, label, bytes, size, count
License
MIT
Install
bower install bytes-label

Documentation

bytes-label

bytes-label is a web-component designed to show number of bytes (f.e file size, disk size, disk free space, disk space in use, etc) with unit in such a way that the end user can choose the unit (bytes, kilobytes, megabytes, ...). Basically it's a label with a combobox (select element) from where the end user can select the multiplier of the unit. Available multipliers change according to the value (number of bytes) assigned to the label so that the number shown always has value >= 1 (i.e if the value is 2000 then bytes and kilobytes can be used, if the value is 2000000 then megabytes too can be used and so on). The biggest unit supported is yottabyte / yobibyte (respectively 1 YB is 10008 bytes and 1 YiB is 10248 bytes).

Installation

To install the component using bower run the command below from your project root

bower install bytes-label --save

or get it from the github:

git clone git://github.com/ainvaltin/bytes-label.git

The only file needed (what you should redistribute with your webapp) is bytes-label.html.

Dependencies

This component depends on the Polymer.

Usage

Import the bytes-label.html file and then use <bytes-label> tag:

<link rel="import" href="/bower_components/bytes-label/bytes-label.html">
...
<bytes-label value="42000"></bytes-label>

Attributes

  • value: integer. Number of bytes to show as the label's caption, must be >= 0.

  • decimalKilo: boolean, default false. Whether to use binary kilobyte (when false) or decimal kilobyte (when true). As with other boolean attributes you just omit it when you want to set it to false and use it when you want to set it to true. Thus, in order to use decimal kilobyte use

    <bytes-label value="42000" decimalKilo></bytes-label>

    but to use binary kilobyte just omit the decimalKilo attribute:

    <bytes-label value="42000"></bytes-label>
  • decimals: integer. Number of decimal places to show, must be >= 0, default 1 (one). Trailing zeroes are removed so it is really "show at most decimals decimals".

Styling

Label's content (the number of bytes specified by the value attribute) can be styled using numberOfBytes class, ie

bytes-label::shadow .numberOfBytes { color:red; font-weight:bold; }

To target specific label use the id attribute of the label to define style:

<style shim-shadowdom>
  #foo::shadow .numberOfBytes { color: red; }
</style>
...
<bytes-label id="foo" value="42000"></bytes-label>

Note the use of shim-shadowdom attribute on the styles tag (or stylesheet link) - this must be used in order for the ::shadow selector to be available on browsers which don't support it natively (which is all browsers except Chrome at this point of time).

License

MIT