Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/SvgUploadPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,29 @@ class SvgStringInput extends React.Component {
return false
}

generateId() {
const title = this.props.type.title.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => index == 0 ? word.toLowerCase() : word.toUpperCase()).replace(/\s+/g, '')
return `svg-upload--${this.props.parent._key}--${title}`
}

render() {
const { value, type, level } = this.props;
const id = this.generateId();

return (
<FormField label={type.title} level={level} description={type.description}>
<div className={`${styles.svgPreviewBackground} ${value && styles.hasValue}`}>
<input
accept=".svg"
id="svg-upload"
id={id}
ref={this.inputRef}
type="file"
placeholder={type.placeholder}
onChange={this.handleChange}
name="svg_upload"
onSubmit={this.onSubmit}
/>
<label htmlFor="svg-upload">Upload SVG</label>
<label htmlFor={id}>Upload SVG</label>

{value && (
<div className={styles.svgWrapper}>
Expand Down