Skip to content

Commit ec628dc

Browse files
authored
Merge branch 'develop' into fix/console-context
2 parents 2ffce76 + 0553e6c commit ec628dc

File tree

23 files changed

+1443
-512
lines changed

23 files changed

+1443
-512
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Issues with these labels are a great place to start!
5353
- [Need Steps to Reproduce](https://github.com/processing/p5.js-web-editor/labels/Needs%20Steps%20to%20Reproduce)
5454
- [Ready for Work](https://github.com/processing/p5.js-web-editor/labels/Ready%20for%20Work)
5555

56-
A breakdown of what each label means can be found in the [Preparing an Issue Guide](#preparing-an-issue).
56+
A breakdown of what each label means can be found in the [Preparing an Issue Guide](../contributor_docs/preparing_an_issue.md).
5757

5858
When approaching these issues, know that it's okay to not know how to fix an issue! Feel free to ask questions about to approach the problem. We are all here to learn and make something awesome. Someone from the community will help you out, and asking questions is a great way to learn about the p5.js editor, its file structure, and development process.
5959

@@ -83,7 +83,7 @@ Before submitting a pull request, make sure that:
8383
---
8484

8585
## Ideas for Getting Started
86-
* Use the [p5.js Editor](https://editor.p5js.org)! Find a bug? Think of something you think would add to the project? Reference the [Preparing an Issue Guide](#preparing-an-issue) and open an issue.
86+
* Use the [p5.js Editor](https://editor.p5js.org)! Find a bug? Think of something you think would add to the project? Reference the [Preparing an Issue Guide](../contributor_docs/preparing_an_issue.md) and open an issue.
8787
* Expand an existing issue. Sometimes issues are missing steps to reproduce, or need suggestions for potential solutions. Sometimes they need another voice saying, "this is really important!"
8888
* Try getting the project running locally on your computer by following the [installation steps](./../contributor_docs/installation.md).
8989
* Look through the documentation in the [developer docs](../contributor_docs/) and the [development guide](./../contributor_docs/development.md). Is there anything that could be expanded? Is there anything missing?

client/common/ButtonOrLink.jsx

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,60 @@ import PropTypes from 'prop-types';
55
/**
66
* Helper for switching between <button>, <a>, and <Link>
77
*/
8-
const ButtonOrLink = ({ href, children, ...props }) => {
9-
if (href) {
10-
if (href.startsWith('http')) {
8+
9+
const ButtonOrLink = React.forwardRef(
10+
({ href, children, isDisabled, onClick, ...props }, ref) => {
11+
const handleClick = (e) => {
12+
if (isDisabled) {
13+
e.preventDefault();
14+
e.stopPropagation();
15+
return;
16+
}
17+
if (onClick) {
18+
onClick(e);
19+
}
20+
};
21+
22+
if (href) {
23+
if (href.startsWith('http')) {
24+
return (
25+
<a
26+
ref={ref}
27+
href={href}
28+
target="_blank"
29+
rel="noopener noreferrer"
30+
aria-disabled={isDisabled}
31+
{...props}
32+
onClick={handleClick}
33+
>
34+
{children}
35+
</a>
36+
);
37+
}
1138
return (
12-
<a href={href} target="_blank" rel="noopener noreferrer" {...props}>
39+
<Link
40+
ref={ref}
41+
to={href}
42+
aria-disabled={isDisabled}
43+
{...props}
44+
onClick={handleClick}
45+
>
1346
{children}
14-
</a>
47+
</Link>
1548
);
1649
}
1750
return (
18-
<Link to={href} {...props}>
51+
<button
52+
ref={ref}
53+
aria-disabled={isDisabled}
54+
{...props}
55+
onClick={handleClick}
56+
>
1957
{children}
20-
</Link>
58+
</button>
2159
);
2260
}
23-
return <button {...props}>{children}</button>;
24-
};
61+
);
2562

2663
/**
2764
* Accepts all the props of an HTML <a> or <button> tag.
@@ -34,15 +71,19 @@ ButtonOrLink.propTypes = {
3471
* External links should start with 'http' or 'https' and will open in a new window.
3572
*/
3673
href: PropTypes.string,
74+
isDisabled: PropTypes.bool,
3775
/**
3876
* Content of the button/link.
3977
* Can be either a string or a complex element.
4078
*/
41-
children: PropTypes.node.isRequired
79+
children: PropTypes.node.isRequired,
80+
onClick: PropTypes.func
4281
};
4382

4483
ButtonOrLink.defaultProps = {
45-
href: null
84+
href: null,
85+
isDisabled: false,
86+
onClick: null
4687
};
4788

4889
export default ButtonOrLink;

client/common/ButtonOrLink.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('ButtonOrLink', () => {
1313
render(<ButtonOrLink onClick={clickHandler}>Text</ButtonOrLink>);
1414
const button = screen.getByRole('button');
1515
expect(button).toBeInstanceOf(HTMLButtonElement);
16-
expect(button).toContainHTML('<button>Text</button>');
16+
expect(button).toContainHTML('<button aria-disabled="false">Text</button>');
1717
fireEvent.click(button);
1818
expect(clickHandler).toHaveBeenCalled();
1919
});

client/common/usePrevious.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
export default function usePrevious(value) {
4+
const ref = useRef();
5+
6+
useEffect(() => {
7+
ref.current = value;
8+
}, [value]);
9+
10+
return ref.current;
11+
}

0 commit comments

Comments
 (0)