tweakpane-plugin-file-import v1.1.1
tweakpane-plugin-file-import
A Tweakpane plugin for importing files.
The version
1.0.0and upwards of this package only supportsTweakpane v4.If you are still using
Tweakpane v3, you can only use thev0of this package.You can install it.
npm i tweakpane-plugin-file-import@0.2.0And use it like so.
<script src="https://unpkg.com/tweakpane@3.0.5/dist/tweakpane.js"></script> <script src="./tweakpane-plugin-file-import.min.js"></script> <script> const pane = new Tweakpane.Pane(); pane.registerPlugin(TweakpaneFileImportPlugin); </script>
Installation
You need Tweakpane v4 to install this plugin.
You may use https://unpkg.com/tweakpane-plugin-file-import to get the latest version
and add it as a <script> tag on your HTML page.
You can install with npm:
npm i tweakpane-plugin-file-importAnd import it like so.
import {Pane} from 'tweakpane';
import * as TweakpaneFileImportPlugin from 'tweakpane-plugin-file-import';
const pane = new Pane();
pane.registerPlugin(TweakpaneFileImportPlugin);Check
test/browser.htmlfor an example of the plugin being used.
Usage
Simply initialize the params with an empty string and pass the optional parameters.
const params = {
	file: '',
};
// If you're using Tweakpane v3 -------
pane
	.addInput(params, 'file', {
		view: 'file-input',
		lineCount: 3,
		filetypes: ['.png', '.jpg'],
		invalidFiletypeMessage: "We can't accept those filetypes!"
	})
	.on('change', (ev) => {
		console.log(ev.value);
	});
// If you're using Tweakpane v4 -------
pane
	.addBinding(params, 'file', {
		view: 'file-input',
		lineCount: 3,
		filetypes: ['.png', '.jpg'],
		invalidFiletypeMessage: "We can't accept those filetypes!"
	})
	.on('change', (ev) => {
		console.log(ev.value);
	});Optional parameters
| property | type | description | 
|---|---|---|
| lineCount | int | Number of lines for the height of the container. Similar to FPS graph | 
| filetypes | array | Array of valid file extensions. | 
| invalidFiletypeMessage | string | String shown when the user tries to upload an invalid filetype. | 
Contributing
If you want to contribute to this package, you are free to open a pull request. 😊
Quickstart
You'll need to have
Node 16or upwards installed in order to properly install and runpackage.jsonscript commands.
Install dependencies:
npm installTo build the source code and watch changes, run:
npm run build:dev
npm startAfter this, simply open test/browser.html to see the results.
File structure
This project follows the same structure as any other Tweakpane third-party plugin.
|- src
|  |- controller ...... Controller for the custom view
|  |- sass ............ Plugin CSS
|  `- view ............ Custom view
|  |- index.ts ........ Entrypoint
|  |- plugin.ts ....... Plugin
|- dist ............... Compiled files
`- test
   `- browser.html .... Plugin usage in an HTML file