-
Notifications
You must be signed in to change notification settings - Fork 161
[UEPR-518] Implement in-editor Manual Save Project Thumbnail logic #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
a8dd014
a193715
45c2935
84d2901
942bb59
42dedfc
d858e2c
cc1264b
4c0d824
f4698f8
6c06180
8934776
725e94e
c3addb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: 12.5rem; | ||
| padding: 0.75rem; | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| border-radius: 0.5rem; | ||
| background: $looks-secondary; | ||
| gap: 0.9375rem; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .label { | ||
| align-self: stretch; | ||
| color: $ui-white; | ||
| text-align: center; | ||
| font-family: "Helvetica Neue"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably redundant |
||
| font-size: 1rem; | ||
| font-style: normal; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: is this needed? |
||
| font-weight: 700; | ||
| line-height: 1.5rem; | ||
| } | ||
|
|
||
| .button-row { | ||
| font-weight: bolder; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
KManolov3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| display: flex; | ||
| padding: 0.5rem 1rem; | ||
| justify-content: center; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| flex: 1; | ||
| border-radius: 2.5rem; | ||
| background: inherit; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .button-row button:focus { | ||
| outline: auto; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? |
||
| } | ||
|
|
||
| .button-row button span { | ||
| color: $ui-white; | ||
| font-family: "Helvetica Neue"; | ||
| font-size: 0.75rem; | ||
| font-style: normal; | ||
| font-weight: 700; | ||
| line-height: 1rem; | ||
| } | ||
|
|
||
| .button-row button.confirm-button { | ||
| background: $ui-white; | ||
| } | ||
|
|
||
| .button-row button.confirm-button span { | ||
| color: $looks-secondary; | ||
| } | ||
|
|
||
| .button-row button.cancel-button { | ||
| border: 0.0625rem solid $ui-white; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| 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} 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 calculatePopupPosition, {PopupAlign, PopupSide} from '../../lib/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 defaultConfig = { | ||
| modalWidth: 200, | ||
| spaceForArrow: 16, | ||
| counterOffset: 7, | ||
| arrowLongSide: 29, | ||
| arrowShortSide: 13 | ||
| }; | ||
|
|
||
| const SIDE_TO_ARROW_ICON = { | ||
| [PopupSide.UP]: arrowDownIcon, | ||
| [PopupSide.DOWN]: arrowUpIcon, | ||
| [PopupSide.LEFT]: arrowRightIcon, | ||
| [PopupSide.RIGHT]: arrowLeftIcon | ||
| }; | ||
|
|
||
| const ConfirmationPrompt = ({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we reuse this new ConfirmationPrompt for the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we:
|
||
| title, | ||
| message, | ||
| confirmLabel, | ||
| cancelLabel, | ||
| onConfirm, | ||
| onCancel, | ||
| isOpen, | ||
| relativeElementRef, | ||
| side, | ||
| align, | ||
| config | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: can we use a more precise name, such as |
||
| }) => { | ||
| const { | ||
| modalWidth, | ||
| spaceForArrow, | ||
| counterOffset, | ||
| arrowLongSide, | ||
| arrowShortSide | ||
| } = {...defaultConfig, ...config}; | ||
| const arrowIcon = SIDE_TO_ARROW_ICON[side]; | ||
|
|
||
| const modalRef = useRef(null); | ||
| const [modalPositionValues, setModalPositionValues] = React.useState({}); | ||
| const [arrowHeight, arrowWidth] = (side === PopupSide.LEFT || side === PopupSide.RIGHT) ? | ||
| [arrowLongSide, arrowShortSide] : [arrowShortSide, arrowLongSide]; | ||
|
|
||
| const updatePosition = useCallback(() => { | ||
| if (relativeElementRef.current && modalRef.current) { | ||
| const pos = calculatePopupPosition({ | ||
| relativeElementRef, | ||
| popupRef: modalRef, | ||
| side, | ||
| align, | ||
| popupWidth: modalWidth, | ||
| arrowLeftIcon, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
kbangelov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| spaceForArrow, | ||
| counterOffset, | ||
| arrowShortSide, | ||
| arrowLongSide | ||
| }); | ||
| setModalPositionValues(pos); | ||
| } | ||
| }, [ | ||
| relativeElementRef, | ||
| side, | ||
| align, | ||
| modalWidth, | ||
| spaceForArrow, | ||
| counterOffset, | ||
| arrowShortSide, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What did |
||
| arrowLongSide | ||
| ]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isOpen) return; | ||
|
|
||
| const debouncedUpdate = debounce(updatePosition, 50, {leading: true}); | ||
|
|
||
| debouncedUpdate(); | ||
|
|
||
| window.addEventListener('resize', debouncedUpdate); | ||
| return () => { | ||
| window.removeEventListener('resize', debouncedUpdate); | ||
| debouncedUpdate.cancel(); | ||
| }; | ||
| }, [isOpen, updatePosition]); | ||
|
|
||
| const onModalMount = useCallback(el => { | ||
| if (!el || !isOpen) return; | ||
| modalRef.current = el; | ||
|
|
||
| updatePosition(); | ||
| }, [isOpen, updatePosition]); | ||
|
|
||
| return ( | ||
| isOpen && ( | ||
| <ReactModal | ||
| isOpen | ||
| onRequestClose={onCancel} | ||
| contentLabel={title} | ||
| style={{ | ||
| content: { | ||
kbangelov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| top: modalPositionValues.top, | ||
| left: modalPositionValues.left, | ||
| width: modalWidth, | ||
kbangelov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| border: 'none', | ||
| height: 'fit-content', | ||
| backgroundColor: 'transparent', | ||
| padding: 0, | ||
| margin: 0, | ||
| position: 'fixed', | ||
| overflowX: 'hidden', | ||
| zIndex: 1000 | ||
| }, | ||
| overlay: { | ||
| position: 'fixed', | ||
| top: 0, | ||
| left: 0, | ||
| right: 0, | ||
| bottom: 0, | ||
| zIndex: 510, | ||
| backgroundColor: 'transparent' | ||
| } | ||
| }} | ||
| > | ||
| {arrowIcon && ( | ||
| <img | ||
| src={arrowIcon} | ||
| alt="" | ||
| aria-hidden="true" | ||
| style={{ | ||
| position: 'fixed', | ||
| top: modalPositionValues.arrowTop, | ||
| left: modalPositionValues.arrowLeft, | ||
| width: arrowWidth, | ||
| height: arrowHeight, | ||
| 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, | ||
| 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)}), | ||
| side: PropTypes.oneOf(Object.values(PopupSide)).isRequired, | ||
| align: PropTypes.oneOf(Object.values(PopupAlign)), | ||
| config: PropTypes.shape({ | ||
| modalWidth: PropTypes.number, | ||
| spaceForArrow: PropTypes.number, | ||
| counterOffset: PropTypes.number, | ||
| arrowLongSide: PropTypes.number, | ||
| arrowShortSide: PropTypes.number | ||
| }) | ||
| }; | ||
|
|
||
| export default ConfirmationPrompt; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Uh oh!
There was an error while loading. Please reload this page.