gd-bs 5.8.7 → 5.8.8

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": "gd-bs",
3
- "version": "5.8.7",
3
+ "version": "5.8.8",
4
4
  "description": "Bootstrap JavaScript, TypeScript and Web Components library.",
5
5
  "main": "build/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { IInputGroup, IInputGroupProps } from "./types";
1
+ import { IInputGroup, IInputGroupFileValue, IInputGroupProps } from "./types";
2
2
  import { Base } from "../base";
3
3
  import { Button } from "../button";
4
4
  import { HTML } from "./templates";
@@ -22,6 +22,7 @@ export enum InputGroupTypes {
22
22
  * @param props The input group properties.
23
23
  */
24
24
  class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
25
+ private _fileValue: IInputGroupFileValue = null;
25
26
  private _initFl: boolean = false;
26
27
 
27
28
  // Constructor
@@ -57,28 +58,10 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
57
58
  if (label) {
58
59
  this.props.id ? label.setAttribute("for", this.props.id) : null;
59
60
 
60
- // See if this is a file
61
- if (this.props.type == InputGroupTypes.File) {
62
- // Set the class
63
- label.classList.add("form-file-label");
64
-
65
- // Set the text
66
- let spanText = document.createElement("span");
67
- spanText.classList.add("form-file-text");
68
- spanText.innerHTML = this.props.label || "Choose a file...";
69
- label.appendChild(spanText);
70
-
71
- // Set the button
72
- let spanButton = document.createElement("span");
73
- spanButton.classList.add("form-file-button");
74
- spanButton.innerHTML = "Browse";
75
- label.appendChild(spanButton);
76
- } else {
77
- // Set the label if it exists
78
- if (this.props.label) { label.innerHTML = this.props.label; }
79
- // Else, remove it
80
- else { this.el.removeChild(label); }
81
- }
61
+ // Set the label if it exists
62
+ if (this.props.label) { label.innerHTML = this.props.label; }
63
+ // Else, remove it
64
+ else { this.el.removeChild(label); }
82
65
  }
83
66
 
84
67
  // See if the label exists
@@ -186,6 +169,35 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
186
169
  }, 1);
187
170
  });
188
171
  }
172
+
173
+ // See if this is a file
174
+ if (this.props.type == InputGroupTypes.File) {
175
+ // Set the change event
176
+ (elInput as HTMLInputElement).addEventListener("onchange", (ev) => {
177
+ // Get the source file
178
+ let srcFile = ev.target["files"][0];
179
+ if (srcFile) {
180
+ let reader = new FileReader();
181
+
182
+ // Set the file loaded event
183
+ reader.onloadend = (ev: any) => {
184
+ this._fileValue = {
185
+ data: ev.target.result,
186
+ name: srcFile.name
187
+ };
188
+ }
189
+
190
+ // Set the error
191
+ reader.onerror = (ev: any) => {
192
+ // Log
193
+ console.log("Error reading the file", srcFile, ev.target.error);
194
+ }
195
+
196
+ // Read the file
197
+ reader.readAsArrayBuffer(srcFile);
198
+ }
199
+ });
200
+ }
189
201
  }
190
202
  }
191
203
 
@@ -275,6 +287,8 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
275
287
  * Public Interface
276
288
  */
277
289
 
290
+ getFileInfo() { return this._fileValue; }
291
+
278
292
  getValue() { return this.elTextbox.value; }
279
293
 
280
294
  // Sets the textbox value
@@ -39,8 +39,13 @@ export const InputGroupTypes: IInputGroupTypes;
39
39
  import { IBaseProps } from "../types";
40
40
  import { IButtonProps } from "../button/types";
41
41
 
42
+ /** Input Group File Value */
43
+ export interface IInputGroupFileValue {
44
+
45
+ }
46
+
42
47
  /**
43
- * Button Group
48
+ * Input Group
44
49
  */
45
50
  export interface IInputGroup {
46
51
  /** The input group element. */
@@ -49,6 +54,9 @@ export interface IInputGroup {
49
54
  /** Reference to the textbox input/textarea element. */
50
55
  elTextbox: HTMLInputElement | HTMLTextAreaElement;
51
56
 
57
+ /** Method to get the file information. */
58
+ getFileInfo: () => IInputGroupFileValue;
59
+
52
60
  /** Method to get the value. */
53
61
  getValue: () => string;
54
62