Skip to content

Commit

Permalink
Create class MinimalFileInput
Browse files Browse the repository at this point in the history
  • Loading branch information
csavelief committed Dec 11, 2023
1 parent f3ae94b commit c8c6fb2
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 13 deletions.
87 changes: 87 additions & 0 deletions dist/cjs/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cjs/main.js.map

Large diffs are not rendered by default.

89 changes: 88 additions & 1 deletion dist/esm/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esm/main.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<link href="blueprintjs/blueprint-datetime.css" rel="stylesheet"/>
</head>
<body>
<div id="file-input"></div>
<div id="suggest"></div>
<div id="multiselect"></div>
<div id="list"></div>
Expand Down Expand Up @@ -488,6 +489,20 @@
});
}

function testFileInput() {

const root = document.getElementById('file-input');

const fileInput = new com.computablefacts.blueprintjs.MinimalFileInput(root);
// fileInput.disabled = true;
fileInput.text = 'Sélectionner un fichier...';
fileInput.buttonText = 'Rechercher...';

fileInput.onSelectionChange((file) => {
console.log(file);
});
}

testWhoAmI();
testTable();
testSelect1();
Expand All @@ -508,6 +523,7 @@
testList();
testMultiSelect();
testSuggest();
testFileInput();

</script>
</body>
Expand Down
18 changes: 9 additions & 9 deletions dist/main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main.min.js.map

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/blueprintjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Card,
Checkbox,
Drawer,
FileInput,
Icon,
Intent,
Menu,
Expand Down Expand Up @@ -2091,4 +2092,91 @@ blueprintjs.MinimalSuggest = class extends blueprintjs.Blueprintjs {
}
});
}
}

/**
* A skeleton to ease the creation of a minimal Blueprintjs file input element.
*
* @memberOf module:blueprintjs
* @extends {blueprintjs.Blueprintjs}
* @type {blueprintjs.MinimalFileInput}
*/
blueprintjs.MinimalFileInput = class extends blueprintjs.Blueprintjs {

/**
* @param {Element} container the parent element.
* @constructor
*/
constructor(container) {
super(container);
this.observers_ = new observers.Subject();
this.disabled_ = false;
this.text_ = null;
this.buttonText_ = null;
this.fill_ = true;
this.render();
}

get disabled() {
return this.disabled_;
}

set disabled(value) {
this.disabled_ = value;
this.render();
}

get fill() {
return this.fill_;
}

set fill(value) {
this.fill_ = value;
this.render();
}

get text() {
return this.text_;
}

set text(value) {
this.text_ = value;
this.render();
}

get buttonText() {
return this.buttonText_;
}

set buttonText(value) {
this.buttonText_ = value;
this.render();
}

/**
* Listen to the `selection-change` event.
*
* @param {function(*): void} callback the callback to call when the event is triggered.
* @name onSelectionChange
* @function
* @public
*/
onSelectionChange(callback) {
this.observers_.register('selection-change', (file) => {
// console.log('Selected file is ', file);
if (callback) {
callback(file);
}
});
}

_newElement() {
return React.createElement(FileInput, {
disabled: this.disabled, text: this.text, buttonText: this.buttonText, fill: this.fill, onInputChange: (el) => {
this.text = el.target.files[0].name;
this.render();
this.observers_.notify('selection-change', el.target.files[0]);
},
});
}
}

0 comments on commit c8c6fb2

Please sign in to comment.