shoelace/src/components/format-bytes/format-bytes.ts

27 wiersze
627 B
TypeScript
Czysty Zwykły widok Historia

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
*/
@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
});
}
}