Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
6 changes: 6 additions & 0 deletions packages/scratch-gui/src/components/alerts/alert.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
body .alert {
width: 100%;
display: flex;
box-sizing: border-box;
flex-direction: row;
overflow: hidden;
justify-content: flex-start;
Expand All @@ -30,6 +31,11 @@ body .alert {
box-shadow: 0px 0px 0px 2px $extensions-light;
}

.alert.blue {
border: 1px solid #4C97FF;
background: #E4F0FF;
}

.alert-spinner {
self-align: center;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/scratch-gui/src/components/button/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ButtonComponent = ({
iconSrc,
onClick,
children,
componentRef,
...props
}) => {

Expand All @@ -33,6 +34,7 @@ const ButtonComponent = ({
className
)}
onClick={onClick}
ref={componentRef}
{...props}
>
{icon}
Expand All @@ -47,7 +49,8 @@ ButtonComponent.propTypes = {
disabled: PropTypes.bool,
iconClassName: PropTypes.string,
iconSrc: PropTypes.string,
onClick: PropTypes.func
onClick: PropTypes.func,
componentRef: PropTypes.func
};

export default ButtonComponent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@import "../../css/colors.css";
@import "../../css/units.css";

.modal-container {
display: flex;
width: 200px;
padding: 12px;
flex-direction: column;
align-items: flex-start;
border-radius: 8px;
background: #855CD6;
gap: 15px;
box-sizing: border-box;
}

.label {
align-self: stretch;
color: var(--White-White, #FFF);
text-align: center;
font-family: "Helvetica Neue";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably redundant

font-size: 16px;
font-style: normal;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: is this needed?

font-weight: 700;
line-height: 24px;
}

.button-row {
font-weight: bolder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: would it be clearer to use a numeric value here as well?

display: flex;
gap: 0.5rem;
width: 100%;
}

.button-row button {
all: unset;
display: flex;
padding: 8px 16px;
justify-content: center;
align-items: center;
gap: 8px;
flex: 1 0 0;
border-radius: 40px;
background: inherit;
cursor: pointer;
}

.button-row button:focus {
outline: auto;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

}

.button-row button span {
color: var(--white-white-100, #FFF);
font-family: "Helvetica Neue";
font-size: 12px;
font-style: normal;
font-weight: 700;
line-height: 16px;
}

.button-row button.confirm-button {
background: var(--White-White, #FFF);
}

.button-row button.confirm-button span {
color: var(--Looks-Purple-2, #855CD6);
}

.button-row button.cancel-button {
border: 1px solid var(--white-white-100, #FFF);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import React, {useRef, useCallback, useEffect} from 'react';
import debounce from 'lodash.debounce';
import PropTypes from 'prop-types';
import ReactModal from 'react-modal';
import {defineMessages, FormattedMessage, useIntl} from 'react-intl';

import Box from '../box/box.jsx';

import arrowLeftIcon from './icon--arrow-left.svg';
import arrowRightIcon from './icon--arrow-right.svg';
import arrowDownIcon from './icon--arrow-down.svg';
import arrowUpIcon from './icon--arrow-up.svg';

import styles from './confirmation-prompt.css';
import useCalculatePopupPosition from '../../hooks/calculatePopupPosition.js';

const messages = defineMessages({
defaultConfirmLabel: {
defaultMessage: 'yes',
description: 'Label for confirm button in confirmation prompt',
id: 'gui.confirmationPrompt.confirm'
},
defaultCancelLabel: {
defaultMessage: 'no',
description: 'Label for cancel button in confirmation prompt',
id: 'gui.confirmationPrompt.cancel'
}
});

const modalWidth = 200;
const spaceForArrow = 16;
const arrowOffsetFromEnd = 7;
const arrowLongSide = 29;
const arrowShortSide = 13;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we truly want to make this component generic, we should make these configurable.


const ConfirmationPrompt = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse this new ConfirmationPrompt for the DeleteConfirmationPrompt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we:

  • pass the positioning params (width, arrow sizes, ..) as a configuration object to the ConfirmationPrompt
  • reuse this component for the delete confirmation prompt, since it already contains a less complex version of the logic used here

title,
message,
confirmLabel,
cancelLabel,
onConfirm,
onCancel,
isOpen,
relativeElementRef,
primaryPosition,
secondaryPosition
}) => {
const intl = useIntl();

const modalRef = useRef(null);
const [modalPositionValues, setModalPositionValues] = React.useState({});

const updatePosition = useCallback(() => {
if (relativeElementRef.current && modalRef.current) {
const pos = useCalculatePopupPosition({
relativeElementRef,
popupRef: modalRef,
primaryPosition,
secondaryPosition,
popupWidth: modalWidth,
arrowLeftIcon,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: maybe we can just pass an arrowIcons object containing the arrows for different sides.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, if the icons are the same, could we pass a single arrow icon and flip it in the desired direction with css?

arrowRightIcon,
arrowUpIcon,
arrowDownIcon,
spaceForArrow,
arrowOffsetFromEnd,
arrowShortSide,
arrowLongSide
});
setModalPositionValues(pos);
}
}, [relativeElementRef, primaryPosition, secondaryPosition]);

useEffect(() => {
if (!isOpen) return;

const debouncedUpdate = debounce(updatePosition, 50, {leading: true});

debouncedUpdate();

window.addEventListener('resize', debouncedUpdate);
return () => window.removeEventListener('resize', debouncedUpdate);
}, [isOpen, relativeElementRef, primaryPosition, secondaryPosition]);

const onModalMount = useCallback(el => {
if (!el || !isOpen) return;
modalRef.current = el;

updatePosition();
}, [isOpen, relativeElementRef, primaryPosition, secondaryPosition]);

return (
isOpen && (
<ReactModal
isOpen
onRequestClose={onCancel}
contentLabel={intl.formatMessage(title)}
style={{
content: {
top: modalPositionValues.top,
left: modalPositionValues.left,
width: modalWidth,
border: 'none',
height: 'fit-content',
backgroundColor: 'transparent',
padding: 0,
margin: 0,
position: 'absolute',
overflowX: 'hidden',
zIndex: 1000
},
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 510,
backgroundColor: 'transparent'
}
}}
>
{modalPositionValues.arrowIcon && (
<img
src={modalPositionValues.arrowIcon}
style={{
position: 'fixed',
top: modalPositionValues.arrowTop,
left: modalPositionValues.arrowLeft,
width: (primaryPosition === 'left' || primaryPosition === 'right') ?
arrowShortSide : arrowLongSide,
height: (primaryPosition === 'left' || primaryPosition === 'right') ?
arrowLongSide : arrowShortSide,
zIndex: 1001
}}
/>
)}
<Box
className={styles.modalContainer}
componentRef={onModalMount}
>
<Box className={styles.label}>
{message}
</Box>

<Box className={styles.buttonRow}>
<button
onClick={onCancel}
className={styles.cancelButton}
>
{cancelLabel ?? <FormattedMessage {...messages.defaultCancelLabel} />}
</button>

<button
onClick={onConfirm}
className={styles.confirmButton}
>
{confirmLabel ?? <FormattedMessage {...messages.defaultConfirmLabel} />}
</button>
</Box>
</Box>
</ReactModal>
)
);
};

ConfirmationPrompt.propTypes = {
isOpen: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
message: PropTypes.node.isRequired,
confirmLabel: PropTypes.node,
cancelLabel: PropTypes.node,
onConfirm: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
relativeElementRef: PropTypes.shape({current: PropTypes.instanceOf(Element)}),
primaryPosition: PropTypes.oneOf([
'left',
'right',
'up',
'down'
]).isRequired,
secondaryPosition: PropTypes.oneOf([
'left',
'right',
'up',
'down'
])
};

export default ConfirmationPrompt;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one bigger than the others? What method did you use for exporting them from Figma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some gap on the originally downloaded one. I wonder if it's worth resolving, since it has the same proportions and same length in the end.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions packages/scratch-gui/src/components/gui/gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ const GUIComponent = props => {
isRendererSupported={isRendererSupported}
isRtl={isRtl}
loading={loading}
manuallySaveThumbnails={
manuallySaveThumbnails &&
userOwnsProject
}
onUpdateProjectThumbnail={onUpdateProjectThumbnail}
stageSize={STAGE_SIZE_MODES.large}
vm={vm}
>
Expand Down Expand Up @@ -545,6 +540,10 @@ const GUIComponent = props => {
vm={vm}
ariaRole="region"
ariaLabel={intl.formatMessage(ariaMessages.stage)}
manuallySaveThumbnails={manuallySaveThumbnails}
userOwnsProject={userOwnsProject}
onUpdateProjectThumbnail={onUpdateProjectThumbnail}
isInEditor
/>
<Box
className={styles.targetWrapper}
Expand Down
8 changes: 8 additions & 0 deletions packages/scratch-gui/src/components/spinner/spinner.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
box-sizing: content-box;
}

.spinner.blue {
border-color: hsla(215, 100%, 65%, 0.4);
}

.spinner::before, .spinner::after {
width: 1.25rem;
height: 1.25rem;
Expand All @@ -29,6 +33,10 @@
animation: spin 1.5s cubic-bezier(0.4, 0.1, 0.4, 1) infinite;
}

.spinner.blue::after {
border-top-color: #4C97FF;
}

.small {
width: .5rem;
height: .5rem;
Expand Down
3 changes: 2 additions & 1 deletion packages/scratch-gui/src/components/spinner/spinner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SpinnerComponent.defaultProps = {
className: '',
large: false,
level: 'info',
small: false
small: false,
color: 'white'
};
export default SpinnerComponent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it visualises in github. Is it as intended to be?

Image

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading