Skip to content

Commit

Permalink
Merge branch 'develop' into issue-processing#2923
Browse files Browse the repository at this point in the history
  • Loading branch information
lindapaiste authored Jan 26, 2024
2 parents 1693492 + 2b99345 commit bc20b47
Show file tree
Hide file tree
Showing 90 changed files with 3,655 additions and 2,665 deletions.
53 changes: 53 additions & 0 deletions .storybook/decorator-theme.js
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']
}
};
8 changes: 6 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router';

import ThemeProvider from '../client/modules/App/components/ThemeProvider';
import configureStore from '../client/store';
import '../client/i18n-test';
import '../client/styles/storybook.css'
import { withThemeProvider, themeToolbarItem } from './decorator-theme';

const initialState = window.__INITIAL_STATE__;

Expand All @@ -21,5 +21,9 @@ export const decorators = [
</MemoryRouter>
</Provider>
),
]
withThemeProvider
];

export const globalTypes = {
theme: themeToolbarItem
};
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you have found a bug in the p5.js Web Editor, you can file it under the ["iss

### How Do I Know My Issue or Pull Request is Getting Reviewed?

To see which pull requests and issues are currently being reviewed, check the [PR Review Board](https://github.com/processing/p5.js-web-editor/projects/9) or the following Milestones: [PATCH Release](https://github.com/processing/p5.js-web-editor/milestone/10), [MINOR Release](https://github.com/processing/p5.js-web-editor/milestone/8).
To see which pull requests and issues are currently being reviewed, check the [PR Review Board](https://github.com/processing/p5.js-web-editor/projects/9) or the following Milestones: [MINOR Release](https://github.com/processing/p5.js-web-editor/milestone/8).

Issues and Pull Requests categorized under the PATCH or MINOR Release Milestones will be prioritized since they are planned to be merged for the next release to Production. Please feel free to [comment on this pinned issue](https://github.com/processing/p5.js-web-editor/issues/2534) if you would like your issue to be considered for the next release!

Expand All @@ -38,9 +38,7 @@ Issues and Pull Requests categorized under the PATCH or MINOR Release Milestones

We will aim to deploy on a 1-2 month basis. Here are some dates we’re working towards:

2.9.3 PATCH Release: By November 17, 2023

2.10.0 MINOR Release: By December 15, 2023
2.11.0 MINOR Release: By January 16, 2023

[You can read more about Semantic Versioning and the differences between a MINOR and PATCH release](https://semver.org/).

Expand Down
64 changes: 5 additions & 59 deletions client/common/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const displays = {
const StyledButton = styled.button`
&&& {
font-weight: bold;
display: flex;
display: ${({ display }) =>
display === displays.inline ? 'inline-flex' : 'flex'};
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -107,57 +108,6 @@ const StyledInlineButton = styled.button`
}
`;

const StyledIconButton = styled.button`
&&& {
display: flex;
justify-content: center;
align-items: center;
width: ${remSize(32)}px;
height: ${remSize(32)}px;
text-decoration: none;
color: ${({ kind }) => prop(`Button.${kind}.default.foreground`)};
background-color: ${({ kind }) => prop(`Button.${kind}.hover.background`)};
cursor: pointer;
border: 1px solid transparent;
border-radius: 50%;
padding: ${remSize(8)} ${remSize(25)};
line-height: 1;
&:hover:not(:disabled) {
color: ${({ kind }) => prop(`Button.${kind}.hover.foreground`)};
background-color: ${({ kind }) =>
prop(`Button.${kind}.hover.background`)};
svg * {
fill: ${({ kind }) => prop(`Button.${kind}.hover.foreground`)};
}
}
&:active:not(:disabled) {
color: ${({ kind }) => prop(`Button.${kind}.active.foreground`)};
background-color: ${({ kind }) =>
prop(`Button.${kind}.active.background`)};
svg * {
fill: ${({ kind }) => prop(`Button.${kind}.active.foreground`)};
}
}
&:disabled {
color: ${({ kind }) => prop(`Button.${kind}.disabled.foreground`)};
background-color: ${({ kind }) =>
prop(`Button.${kind}.disabled.background`)};
cursor: not-allowed;
}
> * + * {
margin-left: ${remSize(8)};
}
}
`;

/**
* A Button performs an primary action
*/
Expand All @@ -184,12 +134,8 @@ const Button = ({
);
let StyledComponent = StyledButton;

if (display === displays.inline) {
StyledComponent = StyledInlineButton;
}

if (iconOnly) {
StyledComponent = StyledIconButton;
StyledComponent = StyledInlineButton;
}

if (href) {
Expand Down Expand Up @@ -265,7 +211,7 @@ Button.propTypes = {
/**
* The display type of the button—inline or block
*/
display: PropTypes.string,
display: PropTypes.oneOf(Object.values(displays)),
/**
* SVG icon to place after child content
*/
Expand All @@ -286,7 +232,7 @@ Button.propTypes = {
* Specifying an href will use an <a> to link to the URL
*/
href: PropTypes.string,
/*
/**
* An ARIA Label used for accessibility
*/
'aria-label': PropTypes.string,
Expand Down
1 change: 1 addition & 0 deletions client/common/IconButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const IconButton = (props) => {
return (
<ButtonWrapper
iconBefore={icon && <Icon />}
iconOnly
display={Button.displays.inline}
focusable="false"
{...otherProps}
Expand Down
25 changes: 25 additions & 0 deletions client/common/RouterTab.jsx
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.
45 changes: 45 additions & 0 deletions client/common/useModalClose.js
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;
}
3 changes: 2 additions & 1 deletion client/components/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled from 'styled-components';
import { remSize, prop } from '../theme';
import IconButton from '../common/IconButton';

const DropdownWrapper = styled.ul`
export const DropdownWrapper = styled.ul`
background-color: ${prop('Modal.background')};
border: 1px solid ${prop('Modal.border')};
box-shadow: 0 0 18px 0 ${prop('shadowColor')};
Expand Down Expand Up @@ -52,6 +52,7 @@ const DropdownWrapper = styled.ul`
& button span,
& a {
padding: ${remSize(8)} ${remSize(16)};
font-size: ${remSize(12)};
}
* {
Expand Down
96 changes: 96 additions & 0 deletions client/components/Dropdown/DropdownMenu.jsx
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;
Loading

0 comments on commit bc20b47

Please sign in to comment.