gd-bs 5.8.6 → 5.8.9

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/index.html CHANGED
@@ -978,10 +978,11 @@
978
978
  id: "offcanvas-demo",
979
979
  title: "Offcanvas Demo",
980
980
  body: "<h5>Hello Canvas</h5><input />",
981
- size: 5,
982
- type: 3,
981
+ size: 7,
982
+ type: 2,
983
983
  options: {
984
- backdrop: true
984
+ autoClose: false,
985
+ backdrop: false
985
986
  }
986
987
  });
987
988
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gd-bs",
3
- "version": "5.8.6",
3
+ "version": "5.8.9",
4
4
  "description": "Bootstrap JavaScript, TypeScript and Web Components library.",
5
5
  "main": "build/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -501,6 +501,12 @@ export class FormControl implements IFormControl {
501
501
 
502
502
  // See if this is a textbox
503
503
  if (this._tb) {
504
+ // See if this is a file
505
+ if (this._props.type == FormControlTypes.File) {
506
+ // Return the file information
507
+ return this._tb.getFileInfo();
508
+ }
509
+
504
510
  // Return the value
505
511
  return this._tb.getValue();
506
512
  }
@@ -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
 
@@ -242,9 +254,6 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
242
254
 
243
255
  // File
244
256
  case InputGroupTypes.File:
245
- this.el.classList.add("form-file");
246
- input.classList.remove("form-control");
247
- input.classList.add("form-file-input");
248
257
  input.type = "file";
249
258
  break;
250
259
 
@@ -278,6 +287,8 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
278
287
  * Public Interface
279
288
  */
280
289
 
290
+ getFileInfo() { return this._fileValue; }
291
+
281
292
  getValue() { return this.elTextbox.value; }
282
293
 
283
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