forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into issue-processing#2923
- Loading branch information
Showing
90 changed files
with
3,655 additions
and
2,665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { upperFirst } from 'lodash'; | ||
import React from 'react'; | ||
import styled, { ThemeProvider } from 'styled-components'; | ||
import theme, { prop } from '../client/theme'; | ||
|
||
const PreviewArea = styled.div` | ||
background: ${prop('backgroundColor')}; | ||
flex-grow: 1; | ||
padding: 2rem; | ||
& > h4 { | ||
margin-top: 0; | ||
color: ${prop('primaryTextColor')}; | ||
} | ||
`; | ||
|
||
const themeKeys = Object.keys(theme); | ||
|
||
export const withThemeProvider = (Story, context) => { | ||
const setting = context.globals.theme; | ||
if (setting === 'all') { | ||
return ( | ||
<div style={{ display: 'flex', flexWrap: 'wrap' }}> | ||
{Object.keys(theme).map((themeName) => ( | ||
<ThemeProvider theme={theme[themeName]} key={themeName}> | ||
<PreviewArea className={themeName}> | ||
<h4>{upperFirst(themeName)}</h4> | ||
<Story /> | ||
</PreviewArea> | ||
</ThemeProvider> | ||
))} | ||
</div> | ||
); | ||
} else { | ||
const themeName = setting; | ||
return ( | ||
<ThemeProvider theme={theme[themeName]}> | ||
<PreviewArea className={themeName}> | ||
<Story /> | ||
</PreviewArea> | ||
</ThemeProvider> | ||
); | ||
} | ||
}; | ||
|
||
export const themeToolbarItem = { | ||
description: 'Global theme for components', | ||
defaultValue: 'all', | ||
toolbar: { | ||
title: 'Theme', | ||
icon: 'mirror', | ||
items: [...themeKeys, 'all'] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
/** | ||
* Wraps the react-router `NavLink` with dashboard-header__tab styling. | ||
*/ | ||
const Tab = ({ children, to }) => ( | ||
<li className="dashboard-header__tab"> | ||
<NavLink | ||
className="dashboard-header__tab__title" | ||
activeClassName="dashboard-header__tab--selected" | ||
to={{ pathname: to, state: { skipSavingPath: true } }} | ||
> | ||
{children} | ||
</NavLink> | ||
</li> | ||
); | ||
|
||
Tab.propTypes = { | ||
children: PropTypes.string.isRequired, | ||
to: PropTypes.string.isRequired | ||
}; | ||
|
||
export default Tab; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import useKeyDownHandlers from './useKeyDownHandlers'; | ||
|
||
/** | ||
* Common logic for Modal, Overlay, etc. | ||
* | ||
* Pass in the `onClose` handler. | ||
* | ||
* Can optionally pass in a ref, in case the `onClose` function needs to use the ref. | ||
* | ||
* Calls the provided `onClose` function on: | ||
* - Press Escape key. | ||
* - Click outside the element. | ||
* | ||
* Returns a ref to attach to the outermost element of the modal. | ||
* | ||
* @param {() => void} onClose | ||
* @param {React.MutableRefObject<HTMLElement | null>} [passedRef] | ||
* @return {React.MutableRefObject<HTMLElement | null>} | ||
*/ | ||
export default function useModalClose(onClose, passedRef) { | ||
const createdRef = useRef(null); | ||
const modalRef = passedRef || createdRef; | ||
|
||
useEffect(() => { | ||
modalRef.current?.focus(); | ||
|
||
function handleClick(e) { | ||
// ignore clicks on the component itself | ||
if (modalRef.current && !modalRef.current.contains(e.target)) { | ||
onClose?.(); | ||
} | ||
} | ||
|
||
document.addEventListener('click', handleClick, false); | ||
|
||
return () => { | ||
document.removeEventListener('click', handleClick, false); | ||
}; | ||
}, [onClose, modalRef]); | ||
|
||
useKeyDownHandlers({ escape: onClose }); | ||
|
||
return modalRef; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, { forwardRef, useCallback, useRef, useState } from 'react'; | ||
import useModalClose from '../../common/useModalClose'; | ||
import DownArrowIcon from '../../images/down-filled-triangle.svg'; | ||
import { DropdownWrapper } from '../Dropdown'; | ||
|
||
// TODO: enable arrow keys to navigate options from list | ||
|
||
const DropdownMenu = forwardRef( | ||
( | ||
{ children, anchor, 'aria-label': ariaLabel, align, className, classes }, | ||
ref | ||
) => { | ||
// Note: need to use a ref instead of a state to avoid stale closures. | ||
const focusedRef = useRef(false); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const close = useCallback(() => setIsOpen(false), [setIsOpen]); | ||
|
||
const anchorRef = useModalClose(close, ref); | ||
|
||
const toggle = useCallback(() => { | ||
setIsOpen((prevState) => !prevState); | ||
}, [setIsOpen]); | ||
|
||
const handleFocus = () => { | ||
focusedRef.current = true; | ||
}; | ||
|
||
const handleBlur = () => { | ||
focusedRef.current = false; | ||
setTimeout(() => { | ||
if (!focusedRef.current) { | ||
close(); | ||
} | ||
}, 200); | ||
}; | ||
|
||
return ( | ||
<div ref={anchorRef} className={className}> | ||
<button | ||
className={classes.button} | ||
aria-label={ariaLabel} | ||
tabIndex="0" | ||
onClick={toggle} | ||
onBlur={handleBlur} | ||
onFocus={handleFocus} | ||
> | ||
{anchor ?? <DownArrowIcon focusable="false" aria-hidden="true" />} | ||
</button> | ||
{isOpen && ( | ||
<DropdownWrapper | ||
className={classes.list} | ||
align={align} | ||
onMouseUp={() => { | ||
setTimeout(close, 0); | ||
}} | ||
onBlur={handleBlur} | ||
onFocus={handleFocus} | ||
> | ||
{children} | ||
</DropdownWrapper> | ||
)} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
DropdownMenu.propTypes = { | ||
/** | ||
* Provide <MenuItem> elements as children to control the contents of the menu. | ||
*/ | ||
children: PropTypes.node.isRequired, | ||
/** | ||
* Can optionally override the contents of the button which opens the menu. | ||
* Defaults to <DownArrowIcon> | ||
*/ | ||
anchor: PropTypes.node, | ||
'aria-label': PropTypes.string.isRequired, | ||
align: PropTypes.oneOf(['left', 'right']), | ||
className: PropTypes.string, | ||
classes: PropTypes.shape({ | ||
button: PropTypes.string, | ||
list: PropTypes.string | ||
}) | ||
}; | ||
|
||
DropdownMenu.defaultProps = { | ||
anchor: null, | ||
align: 'right', | ||
className: '', | ||
classes: {} | ||
}; | ||
|
||
export default DropdownMenu; |
Oops, something went wrong.