Updated FileInput with more customizable features, GroupCreate
• Updated: - FileInput with more customizable features - GroupCreate file input
This commit is contained in:
parent
5adf3a6ead
commit
80e489fab1
@ -1,3 +1,5 @@
|
|||||||
|
import { CX } from '../constants'
|
||||||
|
import Icon from './icon'
|
||||||
import Image from './image'
|
import Image from './image'
|
||||||
import Text from './text'
|
import Text from './text'
|
||||||
|
|
||||||
@ -9,12 +11,16 @@ export default class FileInput extends PureComponent {
|
|||||||
fileType: PropTypes.string,
|
fileType: PropTypes.string,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
title: PropTypes.string,
|
title: PropTypes.string,
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
height: PropTypes.string,
|
height: PropTypes.string,
|
||||||
width: PropTypes.string,
|
width: PropTypes.string,
|
||||||
|
isBordered: PropTypes.bool,
|
||||||
|
className: PropTypes.string,
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
fileType: 'image'
|
fileType: 'image',
|
||||||
|
isBordered: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -30,14 +36,31 @@ export default class FileInput extends PureComponent {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
id,
|
||||||
fileType,
|
fileType,
|
||||||
disabled,
|
disabled,
|
||||||
title,
|
title,
|
||||||
height,
|
height,
|
||||||
width,
|
width,
|
||||||
|
className,
|
||||||
|
isBordered,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { file } = this.state
|
const { file } = this.state
|
||||||
|
|
||||||
|
const containerClasses = CX(className, {
|
||||||
|
default: 1,
|
||||||
|
alignItemsCenter: 1,
|
||||||
|
cursorPointer: 1,
|
||||||
|
justifyContentCenter: 1,
|
||||||
|
overflowHidden: true,
|
||||||
|
radiusSmall: isBordered,
|
||||||
|
px10: isBordered,
|
||||||
|
py10: isBordered,
|
||||||
|
border2PX: isBordered,
|
||||||
|
borderColorSecondary: isBordered,
|
||||||
|
borderDashed: isBordered,
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
@ -50,8 +73,8 @@ export default class FileInput extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<label
|
<label
|
||||||
className={[_s.default, _s.alignItemsCenter, _s.radiusSmall, _s.cursorPointer, _s.px10, _s.py10, _s.justifyContentCenter, _s.border2PX, _s.borderColorSecondary, _s.borderDashed].join(' ')}
|
className={containerClasses}
|
||||||
htmlFor={`file-input-${title}`}
|
htmlFor={`file-input-${id}`}
|
||||||
style={{
|
style={{
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
@ -64,15 +87,13 @@ export default class FileInput extends PureComponent {
|
|||||||
{
|
{
|
||||||
!file &&
|
!file &&
|
||||||
<div className={[_s.posAbs, _s.cursorPointer].join(' ')}>
|
<div className={[_s.posAbs, _s.cursorPointer].join(' ')}>
|
||||||
<Text size='medium' color='secondary'>
|
<Icon id='add-image' size='32px' className={_s.fillSecondary} />
|
||||||
Click Here to Upload
|
|
||||||
</Text>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
id={`file-input-${title}`}
|
id={`file-input-${id}`}
|
||||||
className={_s.displayNone}
|
className={_s.displayNone}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={this.handleOnChange}
|
onChange={this.handleOnChange}
|
||||||
|
@ -114,7 +114,11 @@ class GroupCreate extends ImmutablePureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleCoverImageChange = (e) => {
|
handleCoverImageChange = (e) => {
|
||||||
|
try {
|
||||||
this.props.onCoverImageChange(e.target.files[0])
|
this.props.onCoverImageChange(e.target.files[0])
|
||||||
|
} catch (error) {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = (e) => {
|
handleSubmit = (e) => {
|
||||||
@ -165,11 +169,13 @@ class GroupCreate extends ImmutablePureComponent {
|
|||||||
|
|
||||||
<FileInput
|
<FileInput
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
|
id='group-cover-photo'
|
||||||
title={intl.formatMessage(coverImage === null ? messages.coverImage : messages.coverImageChange)}
|
title={intl.formatMessage(coverImage === null ? messages.coverImage : messages.coverImageChange)}
|
||||||
onChange={this.handleCoverImageChange}
|
onChange={this.handleCoverImageChange}
|
||||||
file={group ? group.get('cover_image_url') : undefined}
|
file={group ? group.get('cover_image_url') : undefined}
|
||||||
width='340px'
|
width='340px'
|
||||||
height='145px'
|
height='145px'
|
||||||
|
isBordered
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Divider isInvisible />
|
<Divider isInvisible />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user