Skip to content

Commit

Permalink
add file-to-array-buffer to storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
meirish committed Oct 10, 2019
1 parent 36a29f4 commit 66123c3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
34 changes: 18 additions & 16 deletions ui/app/components/file-to-array-buffer.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import Component from '@ember/component';
import filesize from 'filesize';

/**
* @module FileToArrayBuffer
* `FileToArrayBuffer` is a component that will allow you to pick a file from the local file system. Once
* loaded, this file will be emitted as a JS ArrayBuffer to the passed `onChange` callback.
*
* @example
* ```js
* <FileToArrayBuffer @onChange={{action (mut file)}} />
* ```
* @param onChange=null {Function} - The function to call when the file read is complete. This function
* recieves the file as a JS ArrayBuffer
* @param [label=null {String}] - Text to use as the label for the file input If null, a default will be rendered
* @param [type=null {String} - Text to use as help under the file input

This comment has been minimized.

Copy link
@andaley

andaley Oct 11, 2019

Contributor

is type used anywhere? i didn't see it in the component source code or in file-to-array-buffer.hbs either :o

This comment has been minimized.

Copy link
@andaley

andaley Oct 11, 2019

Contributor

oh i see, is this supposed to be fileHelpText perhaps?

This comment has been minimized.

Copy link
@meirish

meirish Oct 11, 2019

Author Contributor

Oops, copy and paste failure

*
*/
export default Component.extend({
classNames: ['box', 'is-fullwidth', 'is-marginless', 'is-shadowless'],
onChange: () => {},
label: null,
fileHelpText: null,

file: null,
fileName: null,
fileSize: null,
fileLastModified: null,

/*
* @public
* @param String
* Text to use as the label for the file input
* If null, a default will be rendered
*/
label: null,

/*
* @public
* @param String
* Text to use as help under the file input
* If null, a default will be rendered
*/
fileHelpText: null,

readFile(file) {
const reader = new FileReader();
reader.onload = () => this.send('onChange', reader.result, file);
Expand Down
26 changes: 26 additions & 0 deletions ui/stories/file-to-array-buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--THIS FILE IS AUTO GENERATED. This file is generated from JSDoc comments in app/components/file-to-array-buffer.js. To make changes, first edit that file and run "yarn gen-story-md file-to-array-buffer" to re-generate the content.-->

## FileToArrayBuffer
`FileToArrayBuffer` is a component that will allow you to pick a file from the local file system. Once
loaded, this file will be emitted as a JS ArrayBuffer to the passed `onChange` callback.

**Params**

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| onChange | <code>function</code> | <code></code> | The function to call when the file read is complete. This function recieves the file as a JS ArrayBuffer |
| [label] | <code>String</code> | <code></code> | Text to use as the label for the file input If null, a default will be rendered |
| type | <code>String</code> | <code></code> | Text to use as help under the file input |

**Example**

```js
<FileToArrayBuffer @onChange={{action (mut file)}} />
```

**See**

- [Uses of FileToArrayBuffer](https://github.com/hashicorp/vault/search?l=Handlebars&q=FileToArrayBuffer+OR+file-to-array-buffer)
- [FileToArrayBuffer Source Code](https://github.com/hashicorp/vault/blob/master/ui/app/components/file-to-array-buffer.js)

---
24 changes: 24 additions & 0 deletions ui/stories/file-to-array-buffer.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

import hbs from 'htmlbars-inline-precompile';
import { storiesOf } from '@storybook/ember';
import notes from './file-to-array-buffer.md';


storiesOf('FileToArrayBuffer/', module)
.addParameters({ options: { showPanel: true } })
.add(`FileToArrayBuffer`, () => ({
template: hbs`
<h5 class="title is-5">File To Array Buffer</h5>
<FileToArrayBuffer @onChange={{this.onChange}} />
{{#if this.fileName}}
{{this.fileName}} as bytes: {{this.fileBytes}}
{{/if}}
`,
context: {
onChange(file, name) {

This comment has been minimized.

Copy link
@andaley

andaley Oct 11, 2019

Contributor

could you add knobs for changing the label and help text here as well? i tend to use knobs to test different inputs and make sure the css holds up. for instance, what would this component look like if the help text or label was super long?

console.log(`${name} contents as an ArrayBuffer:`, file);
},
},
}),
{notes}
);

0 comments on commit 66123c3

Please sign in to comment.