@furo/ui5
Version:
SAP UI5 Web Components data bindings for furo-web
100 lines (86 loc) • 2.43 kB
JavaScript
import { LitElement, html, css } from 'lit';
import { FieldNodeAdapter } from '@furo/data/src/lib/FieldNodeAdapter.js';
import { Env } from '@furo/framework/src/furo.js';
/**
* `display-int32`
* The display-int32 component displays a FieldNode of type `int32` in read only mode.
*
* The component uses locale from the environment to display the date value accordingly.
* https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
*
* Every display-xxx component should implement the following API:
* - function: bindData(fieldNode){...}
*
* @summary display renderer for `int32`
* @element display-int32
*/
export class DisplayInt32 extends FieldNodeAdapter(LitElement) {
constructor() {
super();
/**
*
* @type {string}
* @private
*/
this._displayValue = '';
}
static get styles() {
// language=CSS
return css`
:host {
display: inline;
white-space: nowrap;
}
:host([hidden]) {
display: none;
}
:host([disabled]) {
opacity: var(--_ui5_input_disabled_opacity, 0.4);
}
:host([data-size*='size-l']),
:host([data-size*='size-xl']) {
padding-top: 0.5rem;
}
:host([value-state='Positive']),
:host([value-state='Success']) {
color: var(--sapPositiveColor, #107e3e);
}
:host([value-state='Informative']),
:host([value-state='Information']) {
color: var(--sapInformativeColor, #0a6ed1);
}
:host([value-state='Negative']),
:host([value-state='Error']) {
color: var(--sapNegativeColor, #b00);
}
:host([value-state='Critical']),
:host([value-state='Warning']) {
color: var(--sapCrticalColor, #e9730c);
}
`;
}
onFnaFieldValueChanged(value) {
this._fieldValue = value;
this._formatDisplay(value);
}
_formatDisplay(number) {
if (number !== null) {
const displayValue = new Intl.NumberFormat(Env.locale, {}).format(number);
if (displayValue !== 'NaN') {
this._displayValue = displayValue;
this.requestUpdate();
}
}
}
/**
* render function
* @private
* @returns {TemplateResult|TemplateResult}
*/
render() {
// language=HTML
// prettier-ignore
return html`${this._displayValue}`;
}
}
window.customElements.define('display-int32', DisplayInt32);