Skip to content

Commit 502ec85

Browse files
authored
Merge pull request #2961 from SUI-Components/feat/hide-delete-button
Feat/hide delete button
2 parents 3c98e28 + 8524304 commit 502ec85

6 files changed

Lines changed: 116 additions & 18 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import PropTypes from 'prop-types'
2+
3+
import {Article, Code, H2, Paragraph} from '@s-ui/documentation-library'
4+
5+
import MoleculePhotoUploader from '../../src/index.js'
6+
import {
7+
_addPhotoTextButton,
8+
_addPhotoTextSkeleton,
9+
_callbackPhotosRejected,
10+
_callbackPhotosUploaded,
11+
_callbackUploadPhoto,
12+
_dragPhotoDividerTextInitialContent,
13+
_dragPhotoTextInitialContent,
14+
_dropPhotosHere,
15+
_errorCorruptedPhotoUploaded,
16+
_errorFileExcededMaxSize,
17+
_errorFormatPhotoUploaded,
18+
_errorInitialPhotoDownloadError,
19+
_limitPhotosUploaded,
20+
_limitPhotosUploadedNotification,
21+
_mainPhotoLabel,
22+
_maxPhotos,
23+
_notificationErrorFormatPhotoUploaded,
24+
_uploadingPhotosText
25+
} from '../config.js'
26+
import {
27+
_addMorePhotosIcon,
28+
_deleteIcon,
29+
_dragPhotosIcon,
30+
_infoIcon,
31+
_rejectPhotosIcon,
32+
_retryErrorPhotosIcon,
33+
_rotateIcon
34+
} from '../icons.js'
35+
36+
const HideDeleteButtonArticle = ({className}) => {
37+
return (
38+
<Article className={className}>
39+
<H2>Hide Delete Button</H2>
40+
<Paragraph>
41+
When <Code>showDeleteButton</Code> prop is set to <Code>false</Code>, the delete button will be hidden from the
42+
thumb cards. This is useful when you want to prevent users from deleting uploaded photos.
43+
</Paragraph>
44+
<Paragraph>Try uploading some photos below to see how the delete button is hidden:</Paragraph>
45+
<MoleculePhotoUploader
46+
addMorePhotosIcon={_addMorePhotosIcon}
47+
addPhotoTextButton={_addPhotoTextButton}
48+
addPhotoTextSkeleton={_addPhotoTextSkeleton}
49+
callbackPhotosRejected={_callbackPhotosRejected}
50+
callbackPhotosUploaded={_callbackPhotosUploaded}
51+
callbackUploadPhoto={_callbackUploadPhoto}
52+
deleteIcon={_deleteIcon}
53+
dragPhotosIcon={_dragPhotosIcon}
54+
dragPhotoTextInitialContent={_dragPhotoTextInitialContent}
55+
dragPhotoDividerTextInitialContent={_dragPhotoDividerTextInitialContent}
56+
dropPhotosHereText={_dropPhotosHere}
57+
errorCorruptedPhotoUploadedText={_errorCorruptedPhotoUploaded}
58+
errorFileExcededMaxSizeText={_errorFileExcededMaxSize}
59+
errorFormatPhotoUploadedText={_errorFormatPhotoUploaded}
60+
errorInitialPhotoDownloadErrorText={_errorInitialPhotoDownloadError}
61+
showDeleteButton={false}
62+
infoIcon={_infoIcon}
63+
limitPhotosUploadedText={_limitPhotosUploaded}
64+
limitPhotosUploadedNotification={_limitPhotosUploadedNotification}
65+
mainPhotoLabel={_mainPhotoLabel}
66+
maxPhotos={_maxPhotos}
67+
notificationErrorFormatPhotoUploaded={_notificationErrorFormatPhotoUploaded}
68+
rejectPhotosIcon={_rejectPhotosIcon}
69+
retryIcon={_retryErrorPhotosIcon}
70+
rotateIcon={_rotateIcon}
71+
uploadingPhotosText={_uploadingPhotosText}
72+
/>
73+
</Article>
74+
)
75+
}
76+
77+
HideDeleteButtonArticle.displayName = 'ShowDeleteButtonArticle'
78+
79+
HideDeleteButtonArticle.propTypes = {
80+
className: PropTypes.string
81+
}
82+
83+
export default HideDeleteButtonArticle

components/molecule/photoUploader/demo/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Code, H1, Paragraph} from '@s-ui/documentation-library'
22

33
import DefaultArticle from './articles/DefaultArticle.js'
4+
import HideDeleteButtonArticle from './articles/HideDeleteButtonArticle.js'
45
import InitialPhotosArticle from './articles/InitialPhotosArticle.js'
56
import WithContentArticle from './articles/WithContentArticle.js'
67
import {CLASS_DEMO_SECTION} from './config.js'
@@ -15,6 +16,8 @@ const Demo = () => {
1516
</Paragraph>
1617
<DefaultArticle className={CLASS_DEMO_SECTION} />
1718
<br />
19+
<HideDeleteButtonArticle className={CLASS_DEMO_SECTION} />
20+
<br />
1821
<InitialPhotosArticle className={CLASS_DEMO_SECTION} />
1922
<br />
2023
<WithContentArticle className={CLASS_DEMO_SECTION} />

components/molecule/photoUploader/src/PhotosPreview/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const PhotosPreview = ({
4343
dragIcon,
4444
errorInitialPhotoDownloadErrorText,
4545
files,
46+
showDeleteButton,
4647
inputId,
4748
isPhotoUploaderFully,
4849
mainPhotoLabel,
@@ -178,6 +179,7 @@ const PhotosPreview = ({
178179
deleteButtonAriaLabel={deleteButtonAriaLabel}
179180
deleteIcon={deleteIcon()}
180181
dragIcon={dragIcon()}
182+
showDeleteButton={showDeleteButton}
181183
iconSize={thumbIconSize}
182184
image={file}
183185
index={index}
@@ -253,6 +255,7 @@ PhotosPreview.propTypes = {
253255
dragIcon: PropTypes.node,
254256
errorInitialPhotoDownloadErrorText: PropTypes.string.isRequired,
255257
files: PropTypes.array.isRequired,
258+
showDeleteButton: PropTypes.bool,
256259
inputId: PropTypes.string.isRequired,
257260
isPhotoUploaderFully: PropTypes.bool.isRequired,
258261
mainPhotoLabel: PropTypes.string.isRequired,

components/molecule/photoUploader/src/ThumbCard/index.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ThumbCard = ({
2222
deleteButtonAriaLabel,
2323
deleteIcon,
2424
dragIcon,
25+
showDeleteButton = true,
2526
iconSize = ATOM_ICON_SIZES.small,
2627
image,
2728
index,
@@ -66,23 +67,25 @@ const ThumbCard = ({
6667
</div>
6768
<Content file={image} index={index} />
6869
<div className={ACTION_THUMB_CARD_CLASS_NAME}>
69-
<div className={BUTTON_THUMB_CARD_CLASS_NAME}>
70-
<AtomButton
71-
aria-label={`${deleteButtonAriaLabel} ${thumbCardLabel}`}
72-
design={atomButtonDesigns.LINK}
73-
fullWidth
74-
onClick={() => callbackDeleteItem(index)}
75-
size={atomButtonSizes.SMALL}
76-
tabIndex="0"
77-
type="button"
78-
>
79-
<div className={`${BUTTON_THUMB_CARD_CLASS_NAME}Icon`}>
80-
<AtomIcon color={ATOM_ICON_COLORS.currentColor} size={iconSize}>
81-
{deleteIcon}
82-
</AtomIcon>
83-
</div>
84-
</AtomButton>
85-
</div>
70+
{showDeleteButton && (
71+
<div className={BUTTON_THUMB_CARD_CLASS_NAME}>
72+
<AtomButton
73+
aria-label={`${deleteButtonAriaLabel} ${thumbCardLabel}`}
74+
design={atomButtonDesigns.LINK}
75+
fullWidth
76+
onClick={() => callbackDeleteItem(index)}
77+
size={atomButtonSizes.SMALL}
78+
tabIndex="0"
79+
type="button"
80+
>
81+
<div className={`${BUTTON_THUMB_CARD_CLASS_NAME}Icon`}>
82+
<AtomIcon color={ATOM_ICON_COLORS.currentColor} size={iconSize}>
83+
{deleteIcon}
84+
</AtomIcon>
85+
</div>
86+
</AtomButton>
87+
</div>
88+
)}
8689
{hasErrors ? (
8790
<div className={BUTTON_THUMB_CARD_CLASS_NAME}>
8891
<AtomButton
@@ -135,6 +138,7 @@ ThumbCard.propTypes = {
135138
deleteButtonAriaLabel: PropTypes.string.isRequired,
136139
deleteIcon: PropTypes.node.isRequired,
137140
dragIcon: PropTypes.node.isRequired,
141+
showDeleteButton: PropTypes.bool,
138142
iconSize: PropTypes.oneOf(Object.keys(ATOM_ICON_SIZES)),
139143
image: PropTypes.object.isRequired,
140144
index: PropTypes.number,

components/molecule/photoUploader/src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const MoleculePhotoUploader = forwardRef(
6868
errorFormatPhotoUploadedText,
6969
errorInitialPhotoDownloadErrorText,
7070
errorSaveImageEndpoint,
71+
showDeleteButton = true,
7172
id = DEFAULT_INPUT_ID,
7273
infoIcon = noop,
7374
initialPhotos = [],
@@ -313,6 +314,7 @@ const MoleculePhotoUploader = forwardRef(
313314
deleteIcon={deleteIcon}
314315
dragDelay={dragDelay}
315316
dragIcon={dragIcon}
317+
showDeleteButton={showDeleteButton}
316318
errorInitialPhotoDownloadErrorText={errorInitialPhotoDownloadErrorText}
317319
files={files}
318320
inputId={id}
@@ -454,6 +456,9 @@ MoleculePhotoUploader.propTypes = {
454456
/** Text showed when the user drag files into the dropzone, to indicate he can drop */
455457
dropPhotosHereText: PropTypes.string.isRequired,
456458

459+
/** Show the delete button on thumb cards */
460+
showDeleteButton: PropTypes.bool,
461+
457462
/** Id of the input element */
458463
id: PropTypes.string,
459464

components/molecule/photoUploader/src/styles/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ $skeleton-class: '#{$base-class}-skeleton';
301301
display: flex;
302302
justify-content: center;
303303
padding: $p-photo-uploader-action-buttons;
304-
width: 50%;
304+
width: 100%;
305305

306306
&:first-of-type {
307307
border-radius: 0 0 0 $bdrs-photo-uploader-thumb-card;

0 commit comments

Comments
 (0)