-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
files knob #2860
files knob #2860
Changes from 3 commits
9d4aecc
1f3a011
59d1286
37258a5
30be96e
95881f2
2b67e01
ab8a566
bc2c3da
b57e8e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
function fileReaderPromise(file) { | ||
return new Promise(resolve => { | ||
const fileReader = new FileReader(); | ||
fileReader.onload = e => resolve(e.currentTarget.result); | ||
fileReader.readAsDataURL(file); | ||
}); | ||
} | ||
|
||
const FilesType = ({ knob, onChange }) => ( | ||
<input | ||
id={knob.name} | ||
type="file" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be handy to be able to pass |
||
multiple | ||
onChange={e => Promise.all(Array.from(e.target.files).map(fileReaderPromise)).then(onChange)} | ||
/> | ||
); | ||
|
||
FilesType.defaultProps = { | ||
knob: {}, | ||
onChange: value => value, | ||
}; | ||
|
||
FilesType.propTypes = { | ||
knob: PropTypes.shape({ | ||
name: PropTypes.string, | ||
}), | ||
onChange: PropTypes.func, | ||
}; | ||
|
||
FilesType.serialize = () => undefined; | ||
FilesType.deserialize = () => undefined; | ||
|
||
export default FilesType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,11 @@ import { | |
date, | ||
select, | ||
button, | ||
files, | ||
manager, | ||
} from '../base'; | ||
|
||
export { knob, text, boolean, number, color, object, array, date, select, button }; | ||
export { knob, text, boolean, number, color, object, array, date, select, button, files }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be supported in angular and polymer as well? |
||
|
||
export const vueHandler = (channel, knobStore) => getStory => context => ({ | ||
data() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this example to
examples/offisial-storybook
instead.addons/*/example
s are outdated and probably will be removed. Sorry for the confusion