All files / packages/sds-recipes/src/modules/c/saveButton saveButton.js

0% Statements 0/16
0% Branches 0/6
0% Functions 0/5
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
import { LightningElement, api } from 'lwc';
import { normalizeBoolean } from 'sds/utils';
 
export default class StatefulButton extends LightningElement {
  // Render component in native shadow mode
  static shadowSupportMode = 'native';
 
  _saved = false;
  _dirty = false;
  _disabled = false;
 
  @api
  get saved() {
    return this._saved;
  }
  set saved(value) {
    this._saved = normalizeBoolean(value);
  }
 
  @api
  get disabled() {
    return this._disabled;
  }
  set disabled(value) {
    this._disabled = normalizeBoolean(value);
    this._saved = true;
  }
 
  @api
  get dirty() {
    return this._dirty;
  }
  set dirty(value) {
    this._dirty = normalizeBoolean(value);
    if (!this._dirty) {
      this._saved = false;
      this._disabled = false;
    }
  }
 
  handleClick() {
    if (!this._disabled && !this._dirty) {
      this._saved = !this._saved;
      this._disabled = true;
    }
  }
}