Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 34dde64

Browse files
author
ChrisTerBeke
authored
Merge pull request #52 from Ultimaker/icon-updates
improve image upload component
2 parents 0c831a4 + 74569f1 commit 34dde64

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

src/components/image_upload.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface ImageUploadProps {
1818
shape?: ImageShape;
1919
/** Default image URL */
2020
defaultURL?: string
21+
/** Placeholder label */
22+
placeholderLabel?: string
2123
}
2224

2325
export interface ImageUploadState {
@@ -57,7 +59,7 @@ export class ImageUpload extends React.Component<ImageUploadProps, ImageUploadSt
5759
this.setState({
5860
dropActive: false
5961
});
60-
62+
6163
const file = files[0];
6264
this.setState({ fileURL: file.preview });
6365
this.props.onFileSelection(file);
@@ -76,15 +78,15 @@ export class ImageUpload extends React.Component<ImageUploadProps, ImageUploadSt
7678
}
7779

7880
render(): JSX.Element {
79-
const { size, shape } = this.props;
81+
const { size, shape, placeholderLabel } = this.props;
8082
const { fileURL, dropActive } = this.state;
8183

82-
const iconClasses = classNames({ 'hide': fileURL !== null });
84+
const iconClasses = classNames({ 'hide-icon': fileURL !== null, 'icon-with-label': placeholderLabel });
8385
const hoverAreaClasses = classNames('hover-area', { 'show': dropActive });
8486

8587
return <Dropzone className="image-upload" style={{ width: size, height: size }}
86-
accept="image/jpeg, image/png"
87-
multiple={false}
88+
accept="image/jpeg, image/png"
89+
multiple={false}
8890
onDragEnter={this._onDragEnter}
8991
onDragLeave={this._onDragLeave}
9092
onDrop={(files) => this._onDropHandler(files)}
@@ -93,21 +95,27 @@ export class ImageUpload extends React.Component<ImageUploadProps, ImageUploadSt
9395
<div className={hoverAreaClasses}>
9496
<div className={iconClasses}>
9597
<UploadIcon />
98+
99+
{placeholderLabel &&
100+
<div className="placeholder-label">
101+
{placeholderLabel}
102+
</div>
103+
}
96104
</div>
97105

98106
{fileURL &&
99107
<div className={`cover cover--${shape}`}></div>
100108
}
101109
</div>
102-
110+
103111
{!fileURL &&
104112
<div className={`placeholder placeholder--${shape}`}></div>
105113
}
106-
114+
107115
{fileURL &&
108116
<Image src={fileURL} shape={shape} size={size} />
109117
}
110-
118+
111119
</Dropzone>
112120
}
113121
}

src/components/input_field_input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class InputFieldInput extends React.Component<InputFieldInputProps, {}> {
158158
defaultURL={defaultValue ? defaultValue.toString() : null}
159159
onFileSelection={onChangeHandler}
160160
shape={imageShape}
161+
placeholderLabel={placeholder}
161162
/>
162163
)
163164
}

src/sass/_icons.sass

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
height: 2.2rem
88

99
svg
10-
width: 2.2rem
11-
height: 2.2rem
10+
width: 100%
11+
height: 100%
1212

1313
&.icon--circle
1414
border-radius: 50%

src/sass/_image_upload.sass

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
left: 0
1414

1515
&:hover, &.show
16-
.cover, .icon
16+
.cover, .icon, .placeholder-label
1717
visibility: visible !important
1818
opacity: 1 !important
1919

@@ -23,6 +23,9 @@
2323
.icon svg
2424
fill: $input-field-color-border-hover
2525

26+
.placeholder-label
27+
color: $color-text
28+
2629
.cover
2730
background-color: rgba(255, 255, 255, 0)
2831
position: absolute
@@ -40,10 +43,20 @@
4043
position: relative
4144
height: 100%
4245
width: 100%
43-
46+
4447
&.placeholder--round
4548
border-radius: 9999px
4649

50+
.placeholder-label
51+
position: absolute
52+
top: 65%
53+
left: 50%
54+
transform: translate(-50%, 0)
55+
color: $color-text-light
56+
width: 80%
57+
text-align: center
58+
z-index: 1
59+
4760
.icon
4861
position: absolute
4962
top: 50%
@@ -52,13 +65,19 @@
5265
width: 50%
5366
height: 50%
5467
z-index: 1
68+
opacity: 0.5
69+
transition: opacity 0.2s ease-out
70+
71+
.icon-with-label
72+
.icon
73+
top: 40%
5574

56-
&.hide
75+
.hide-icon
76+
.icon, .placeholder-label
5777
visibility: hidden
5878
opacity: 0
5979
transition: opacity 0.2s ease-out
6080

6181
svg
62-
fill: rgba(0, 0, 0, 0.35)
6382
transition: fill 0.2s ease-out
6483
width: 100%

src/stories/form.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ const defaultValue = 'round';
124124
stories.add('Image upload', withInfo(
125125
'Image drag and drop or click to upload'
126126
)(() =>
127-
<ImageUpload shape={selectV2('Image shape', options, defaultValue)} onFileSelection={action('changed')} />
127+
<ImageUpload
128+
size={text('Size', '18rem')}
129+
shape={selectV2('Image shape', options, defaultValue)}
130+
onFileSelection={action('changed')}
131+
placeholderLabel={text('Placeholder Label', 'Upload an image')} />
128132
));
129133

130134
stories.add('Date picker', withInfo(

0 commit comments

Comments
 (0)