Skip to content

Commit 5d84dff

Browse files
authored
Merge pull request #31 from scratchfoundation/integration-branch-kaloyan
Integration branch kaloyan
2 parents 7c3c594 + e3d4b98 commit 5d84dff

File tree

21 files changed

+1154
-687
lines changed

21 files changed

+1154
-687
lines changed

packages/scratch-gui/src/components/delete-button/delete-button.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
transition: all 0.15s ease-out;
2929
}
3030

31+
.delete-button-clicked {
32+
background-color: $data-primary;
33+
}
34+
3135
.delete-icon {
3236
position: relative;
3337
margin: 0.25rem;

packages/scratch-gui/src/components/delete-button/delete-button.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const DeleteButton = props => (
1616
tabIndex={props.tabIndex}
1717
onClick={props.onClick}
1818
>
19-
<div className={styles.deleteButtonVisible}>
19+
<div
20+
className={classNames(styles.deleteButtonVisible, {
21+
[styles.deleteButtonClicked]: props.isConfirmationModalOpened
22+
})}
23+
>
2024
<img
2125
className={styles.deleteIcon}
2226
src={deleteIcon}
@@ -29,6 +33,7 @@ const DeleteButton = props => (
2933
DeleteButton.propTypes = {
3034
className: PropTypes.string,
3135
onClick: PropTypes.func.isRequired,
36+
isConfirmationModalOpened: PropTypes.bool,
3237
tabIndex: PropTypes.number
3338
};
3439

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@import "../../css/colors.css";
2+
@import "../../css/units.css";
3+
4+
.modal-container {
5+
display: flex;
6+
flex-direction: row;
7+
border: none;
8+
}
9+
10+
.arrow-container {
11+
display: flex;
12+
align-items: center;
13+
margin-right: -7px;
14+
}
15+
16+
.arrow-container-left {
17+
margin-right: -7px;
18+
}
19+
20+
.arrow-container-right {
21+
margin-left: -7px;
22+
}
23+
24+
.body {
25+
padding: 1rem 1.5rem;
26+
border-radius: 0.5rem;
27+
background: $looks-secondary;
28+
}
29+
30+
.label {
31+
color: $ui-white;
32+
font-size: 1.25rem;
33+
font-weight: 700;
34+
margin: 1rem 0 1.5rem;
35+
}
36+
37+
.button-row {
38+
font-weight: bolder;
39+
display: flex;
40+
}
41+
42+
.button-row button {
43+
display: flex;
44+
gap: 0.5rem;
45+
justify-content: center;
46+
width: 47%;
47+
padding: 0.75rem 1rem;
48+
border-radius: 2rem;
49+
border: 1px solid $ui-black-transparent;
50+
color: $looks-secondary;
51+
background: $ui-white;
52+
font-weight: 600;
53+
font-size: 0.85rem;
54+
cursor: pointer;
55+
margin: auto;
56+
}
57+
58+
.button-row button.ok-button {
59+
margin-left: 0;
60+
}
61+
62+
.button-row button.cancel-button {
63+
margin-right: 0;
64+
}
65+
66+
.message {
67+
margin-top: 0.25rem;
68+
}
69+
70+
.delete-icon {
71+
height: 1.5rem;
72+
width: 1.5rem;
73+
}
74+
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import {defineMessages, FormattedMessage, injectIntl, intlShape} from 'react-intl';
2+
import React from 'react';
3+
import PropTypes from 'prop-types';
4+
import classNames from 'classnames';
5+
6+
import Box from '../box/box.jsx';
7+
import ReactModal from 'react-modal';
8+
import deleteIcon from './icon--delete.svg';
9+
import undoIcon from './icon--undo.svg';
10+
import arrowLeftIcon from './icon--arrow-left.svg';
11+
import arrowRightIcon from './icon--arrow-right.svg';
12+
13+
import styles from './delete-confirmation-prompt.css';
14+
15+
// TODO: Parametrize from outside if we want more custom messaging
16+
const messages = defineMessages({
17+
shouldDeleteSpriteMessage: {
18+
defaultMessage: 'Are you sure you want to delete this sprite?',
19+
description: 'Message to indicate whether selected sprite should be deleted.',
20+
id: 'gui.gui.shouldDeleteSprite'
21+
},
22+
shouldDeleteCostumeMessage: {
23+
defaultMessage: 'Are you sure you want to delete this costume?',
24+
description: 'Message to indicate whether selected costume should be deleted.',
25+
id: 'gui.gui.shouldDeleteCostume'
26+
},
27+
shouldDeleteSoundMessage: {
28+
defaultMessage: 'Are you sure you want to delete this sound?',
29+
description: 'Message to indicate whether selected sound should be deleted.',
30+
id: 'gui.gui.shouldDeleteSound'
31+
},
32+
confirmOption: {
33+
defaultMessage: 'yes',
34+
description: 'Yes - should delete the sprite',
35+
id: 'gui.gui.confirm'
36+
},
37+
cancelOption: {
38+
defaultMessage: 'no',
39+
description: 'No - cancel deletion',
40+
id: 'gui.gui.cancel'
41+
},
42+
confirmDeletionHeading: {
43+
defaultMessage: 'Confirm Asset Deletion',
44+
description: 'Heading of confirmation prompt to delete asset',
45+
id: 'gui.gui.deleteAssetHeading'
46+
}
47+
});
48+
49+
const modalWidth = 300;
50+
const calculateModalPosition = (relativeElemRef, modalPosition) => {
51+
const refPosition = relativeElemRef.getBoundingClientRect();
52+
53+
if (modalPosition === 'left') {
54+
return {
55+
top: refPosition.top - refPosition.height,
56+
left: refPosition.left - modalWidth - 25
57+
};
58+
}
59+
60+
if (modalPosition === 'right') {
61+
return {
62+
top: refPosition.top - refPosition.height,
63+
left: refPosition.right + 25
64+
};
65+
}
66+
67+
return {};
68+
};
69+
70+
const getMessage = entityType => {
71+
if (entityType === 'COSTUME') {
72+
return messages.shouldDeleteCostumeMessage;
73+
}
74+
75+
if (entityType === 'SOUND') {
76+
return messages.shouldDeleteSoundMessage;
77+
}
78+
79+
return messages.shouldDeleteSpriteMessage;
80+
};
81+
82+
const DeleteConfirmationPrompt = ({
83+
intl,
84+
onCancel,
85+
onOk,
86+
modalPosition,
87+
entityType,
88+
relativeElemRef
89+
}) => {
90+
const modalPositionValues = calculateModalPosition(relativeElemRef, modalPosition);
91+
92+
return (<ReactModal
93+
isOpen
94+
// We have to inline the styles, since a part
95+
// of them are dynamically generated
96+
style={{
97+
content: {
98+
...modalPositionValues,
99+
width: modalWidth,
100+
border: 'none',
101+
height: 'fit-content',
102+
backgroundColor: 'transparent',
103+
padding: 0,
104+
margin: 0,
105+
position: 'absolute',
106+
overflowX: 'hidden',
107+
zIndex: 1000
108+
},
109+
overlay: {
110+
position: 'fixed',
111+
top: 0,
112+
left: 0,
113+
right: 0,
114+
bottom: 0,
115+
zIndex: 510,
116+
backgroundColor: 'transparent'
117+
}
118+
}}
119+
contentLabel={intl.formatMessage(messages.confirmDeletionHeading)}
120+
onRequestClose={onCancel}
121+
>
122+
<Box className={styles.modalContainer}>
123+
{ modalPosition === 'right' ?
124+
<Box className={classNames(styles.arrowContainer, styles.arrowContainerLeft)}>
125+
<img
126+
className={styles.deleteIcon}
127+
src={arrowLeftIcon}
128+
/>
129+
</Box> : null }
130+
<Box className={styles.body}>
131+
<Box className={styles.label}>
132+
<FormattedMessage {...getMessage(entityType)} />
133+
</Box>
134+
<Box className={styles.buttonRow}>
135+
<button
136+
className={styles.okButton}
137+
onClick={onOk}
138+
role="button"
139+
>
140+
<img
141+
className={styles.deleteIcon}
142+
src={deleteIcon}
143+
/>
144+
<div className={styles.message}>
145+
<FormattedMessage {...messages.confirmOption} />
146+
</div>
147+
</button>
148+
<button
149+
className={styles.cancelButton}
150+
onClick={onCancel}
151+
role="button"
152+
>
153+
<img
154+
className={styles.deleteIcon}
155+
src={undoIcon}
156+
/>
157+
<div className={styles.message}>
158+
<FormattedMessage {...messages.cancelOption} />
159+
</div>
160+
</button>
161+
</Box>
162+
</Box>
163+
{modalPosition === 'left' ?
164+
<Box className={classNames(styles.arrowContainer, styles.arrowContainerRight)}>
165+
<img
166+
className={styles.deleteIcon}
167+
src={arrowRightIcon}
168+
/>
169+
</Box> : null }
170+
</Box>
171+
</ReactModal>);
172+
};
173+
174+
DeleteConfirmationPrompt.propTypes = {
175+
onOk: PropTypes.func.isRequired,
176+
onCancel: PropTypes.func.isRequired,
177+
relativeElemRef: PropTypes.object,
178+
entityType: PropTypes.string,
179+
modalPosition: PropTypes.string,
180+
intl: intlShape.isRequired
181+
};
182+
183+
const DeleteConfirmationPromptIntl = injectIntl(DeleteConfirmationPrompt);
184+
185+
export default DeleteConfirmationPromptIntl;
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Loading

packages/scratch-gui/src/components/library/library.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
height: calc(100% - $library-header-height - $library-filter-bar-height - 2rem);
2020
}
2121

22+
.library-category {
23+
display: flex;
24+
flex-direction: column;
25+
}
26+
27+
.library-category-title {
28+
padding-Left: .5rem;
29+
font-weight: bold;
30+
font-size: 2rem;
31+
color: $text-primary;
32+
}
33+
34+
.library-category-items {
35+
display: flex;
36+
flex-wrap: wrap;
37+
padding-bottom: 1rem;
38+
}
39+
2240
.filter-bar {
2341
display: flex;
2442
flex-direction: row;

0 commit comments

Comments
 (0)