2021-03-08 12:51:31 +00:00
|
|
|
import { LitElement, property } from 'lit-element';
|
|
|
|
import { tag } from '../../internal/decorators';
|
2021-02-26 14:09:13 +00:00
|
|
|
import { formatBytes } from '../../internal/number';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.0
|
|
|
|
* @status stable
|
|
|
|
*/
|
2021-03-08 12:51:31 +00:00
|
|
|
@tag('sl-format-bytes')
|
2021-03-06 17:01:39 +00:00
|
|
|
export class SlFormatBytes extends LitElement {
|
2021-02-26 14:09:13 +00:00
|
|
|
/** The number to format in bytes. */
|
2021-03-06 17:01:39 +00:00
|
|
|
@property({ type: Number }) value = 0;
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
/** The unit to display. */
|
2021-03-06 17:01:39 +00:00
|
|
|
@property() unit: 'bytes' | 'bits' = 'bytes';
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
/** The locale to use when formatting the number. */
|
2021-03-06 17:01:39 +00:00
|
|
|
@property() locale: string;
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return formatBytes(this.value, {
|
|
|
|
unit: this.unit,
|
|
|
|
locale: this.locale
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|