@cfpb/cfpb-design-system 3.13.0 → 3.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfpb/cfpb-design-system",
3
- "version": "3.13.0",
3
+ "version": "3.13.1",
4
4
  "description": "CFPB's UI framework",
5
5
  "exports": {
6
6
  ".": "./src/index.js",
@@ -50,4 +50,5 @@ export class CfpbButton extends LitElement {
50
50
  }
51
51
  }
52
52
 
53
- window.customElements.define('cfpb-button', CfpbButton);
53
+ window.customElements.get('cfpb-button') ||
54
+ window.customElements.define('cfpb-button', CfpbButton);
@@ -15,14 +15,16 @@ export class CfpbFileUpload extends LitElement {
15
15
  static get properties() {
16
16
  return {
17
17
  isDetailHidden: { type: Boolean },
18
- fileName: { type: String },
18
+ fileName: { type: String }, // The file name.
19
+ accept: { type: String }, // The accepted file types.
20
+ value: { type: String }, // The raw file name.
21
+ files: { type: FileList }, // A FileList object.
19
22
  };
20
23
  }
21
24
 
22
25
  constructor() {
23
26
  super();
24
- this.isDetailHidden = true;
25
- this.fileName = '';
27
+ this.#hideDetails();
26
28
  }
27
29
 
28
30
  fileInput = createRef();
@@ -40,9 +42,26 @@ export class CfpbFileUpload extends LitElement {
40
42
 
41
43
  #showDetails() {
42
44
  this.fileName = this.#getUploadName(this.fileInput.value.value);
45
+ this.value = this.fileInput.value.value;
46
+ this.files = this.fileInput.value.files;
43
47
  this.isDetailHidden = false;
44
48
  }
45
49
 
50
+ #hideDetails() {
51
+ this.fileName = '';
52
+ this.value = '';
53
+ this.files = {};
54
+ this.isDetailHidden = true;
55
+ }
56
+
57
+ #checkStatus() {
58
+ if (this.fileInput.value.value == '') {
59
+ this.#hideDetails();
60
+ } else {
61
+ this.#showDetails();
62
+ }
63
+ }
64
+
46
65
  render() {
47
66
  return html`
48
67
  <cfpb-button
@@ -54,11 +73,12 @@ export class CfpbFileUpload extends LitElement {
54
73
  <slot></slot>
55
74
  </cfpb-button>
56
75
  <input
57
- id="file-upload"
58
76
  class="a-btn a-btn--secondary"
59
77
  type="file"
60
78
  hidden
61
- @input="${() => this.#showDetails()}"
79
+ accept="${this.accept}"
80
+ @input="${() => this.#checkStatus()}"
81
+ @cancel="${() => this.#checkStatus()}"
62
82
  ${ref(this.fileInput)}
63
83
  />
64
84
  <div
@@ -68,7 +88,7 @@ export class CfpbFileUpload extends LitElement {
68
88
  >
69
89
  <h4>File added</h4>
70
90
  <ul>
71
- <li>${this.fileName} ${this.isDetailHidden}</li>
91
+ <li>${this.fileName}</li>
72
92
  </ul>
73
93
  <p>
74
94
  To remove or replace your file, select a new file and upload again.
@@ -78,4 +98,5 @@ export class CfpbFileUpload extends LitElement {
78
98
  }
79
99
  }
80
100
 
81
- window.customElements.define('cfpb-file-upload', CfpbFileUpload);
101
+ window.customElements.get('cfpb-file-upload') ||
102
+ window.customElements.define('cfpb-file-upload', CfpbFileUpload);