Skip to content

Commit 0a328b2

Browse files
committed
Migrate defaultProps to JS default params
This PR migrates all use of defaultProps to JS default params Closes #30
1 parent e000089 commit 0a328b2

File tree

9 files changed

+75
-159
lines changed

9 files changed

+75
-159
lines changed

src/lib/Alert/Alert.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import "./Alert.scss";
2525
* @param id - HTML element identifier
2626
*/
2727
export const Alert: React.FC<AlertProps> = ({
28-
title,
28+
title = "",
2929
message,
30-
redirectLabel,
31-
redirectUrl,
32-
variant,
33-
className,
34-
id,
30+
redirectLabel = "",
31+
redirectUrl = "",
32+
variant = AlertVariant.INFO,
33+
className = "",
34+
id = "",
3535
}) => {
3636
const styling = clsx({
3737
c4alert: true,
@@ -73,13 +73,3 @@ export const Alert: React.FC<AlertProps> = ({
7373
</div>
7474
);
7575
};
76-
77-
Alert.defaultProps = {
78-
title: "",
79-
redirectLabel: "",
80-
redirectUrl: "",
81-
/* @ts-ignore value in Enum */
82-
variant: "INFO",
83-
className: "",
84-
id: "",
85-
};

src/lib/Button/Button.tsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import clsx from "clsx";
3-
import { ButtonProps, ButtonSize, ButtonVariant } from "./Button.types";
3+
import { ButtonProps, ButtonSize, ButtonType, ButtonVariant } from "./Button.types";
44
import "./Button.scss";
55

66
/**
@@ -26,17 +26,17 @@ import "./Button.scss";
2626
*/
2727
export const Button: React.FC<ButtonProps> = ({
2828
label,
29-
type,
30-
variant,
31-
external,
32-
disabled,
33-
iconLeft,
34-
iconRight,
35-
size,
36-
href,
29+
type = ButtonType.BUTTON,
30+
variant = ButtonVariant.PRIMARY,
31+
external = false,
32+
disabled = false,
33+
iconLeft = "",
34+
iconRight = "",
35+
size = ButtonSize.NARROW,
36+
href = "",
3737
onClick,
38-
className,
39-
id,
38+
className = "",
39+
id = "",
4040
}) => {
4141
const styling = clsx({
4242
c4button: true,
@@ -80,20 +80,3 @@ export const Button: React.FC<ButtonProps> = ({
8080
</button>
8181
);
8282
};
83-
84-
Button.defaultProps = {
85-
/* @ts-ignore value in Enum */
86-
type: "button",
87-
/* @ts-ignore value in Enum */
88-
variant: "PRIMARY",
89-
disabled: false,
90-
iconLeft: "",
91-
iconRight: "",
92-
/* @ts-ignore value in Enum */
93-
size: "NARROW",
94-
href: "",
95-
external: false,
96-
onClick: undefined,
97-
className: "",
98-
id: "",
99-
};

src/lib/ContestStatus/ContestStatus.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import "./ContestStatus.scss";
1616
*/
1717
export const ContestStatus: React.FC<ContestStatusProps> = ({
1818
status,
19-
className,
20-
id,
19+
className = "",
20+
id = "",
2121
}) => {
2222
const styling = clsx({
2323
statusindicator: true,
@@ -38,8 +38,3 @@ export const ContestStatus: React.FC<ContestStatusProps> = ({
3838
)
3939
);
4040
};
41-
42-
ContestStatus.defaultProps = {
43-
className: "",
44-
id: "",
45-
};

src/lib/ContestTile/ContestTile.tsx

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {
77
} from "./ContestTile.types";
88
import { getDates } from "../../utils/time";
99
import { Status } from "../ContestStatus/ContestStatus.types";
10-
import {
11-
formatDistanceToNow,
12-
formatDistanceToNowStrict,
13-
} from "date-fns";
10+
import { formatDistanceToNow, formatDistanceToNowStrict } from "date-fns";
1411
import "./ContestTile.scss";
1512
import CompactTemplate from "./CompactTemplate";
1613
import DefaultTemplate from "./DefaultTemplate";
@@ -147,58 +144,53 @@ export const Countdown = ({
147144
* @param description - Description for the current contest.
148145
*/
149146
export const ContestTile: React.FC<ContestTileProps> = ({
150-
htmlId,
151-
variant,
147+
htmlId = "",
148+
variant = ContestTileVariant.DARK,
152149
contestData,
153150
bountyData,
154-
sponsorImage,
155-
sponsorUrl,
151+
sponsorImage = undefined,
152+
sponsorUrl = undefined,
156153
title,
157154
description,
158155
}) => {
159-
const isDefault = variant === ContestTileVariant.DARK || variant === ContestTileVariant.LIGHT;
156+
const isDefault =
157+
variant === ContestTileVariant.DARK || variant === ContestTileVariant.LIGHT;
160158

161159
useEffect(() => {
162160
// Loads polyfill to support container queries in older browsers.
163161
const loadContainerQueryPolyfill = () => {
164-
const supportsContainerQueries = "container" in document.documentElement.style;
162+
const supportsContainerQueries =
163+
"container" in document.documentElement.style;
165164
if (!supportsContainerQueries) {
166165
// @ts-ignore
167166
import("container-query-polyfill");
168167
}
169-
}
168+
};
170169

171170
loadContainerQueryPolyfill();
172171
}, []);
173172

174-
return (isDefault
175-
? <DefaultTemplate
176-
variant={variant}
177-
htmlId={htmlId}
178-
title={title}
179-
description={description}
180-
sponsorImage={sponsorImage}
181-
sponsorUrl={sponsorUrl}
182-
contestData={contestData}
183-
bountyData={bountyData}
173+
return isDefault ? (
174+
<DefaultTemplate
175+
variant={variant}
176+
htmlId={htmlId}
177+
title={title}
178+
description={description}
179+
sponsorImage={sponsorImage}
180+
sponsorUrl={sponsorUrl}
181+
contestData={contestData}
182+
bountyData={bountyData}
184183
/>
185-
: <CompactTemplate
186-
variant={variant}
187-
htmlId={htmlId}
188-
title={title}
189-
description={description}
190-
sponsorImage={sponsorImage}
191-
sponsorUrl={sponsorUrl}
192-
contestData={contestData}
193-
bountyData={bountyData}
184+
) : (
185+
<CompactTemplate
186+
variant={variant}
187+
htmlId={htmlId}
188+
title={title}
189+
description={description}
190+
sponsorImage={sponsorImage}
191+
sponsorUrl={sponsorUrl}
192+
contestData={contestData}
193+
bountyData={bountyData}
194194
/>
195195
);
196196
};
197-
198-
ContestTile.defaultProps = {
199-
htmlId: "",
200-
/* @ts-ignore */
201-
variant: "DARK",
202-
sponsorImage: undefined,
203-
sponsorUrl: undefined,
204-
};

src/lib/Dropdown/Dropdown.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import "./Dropdown.scss";
1616
*/
1717
export const Dropdown = ({
1818
id,
19-
wrapperClass,
20-
triggerButtonClass,
21-
openOnHover,
19+
wrapperClass = "",
20+
triggerButtonClass = "",
21+
openOnHover = true,
2222
triggerButton,
23-
triggerAriaLabel,
24-
hideDownArrow,
23+
triggerAriaLabel = "See more options",
24+
hideDownArrow = false,
2525
children,
2626
}: DropdownProps) => {
2727
const [isOpen, setIsOpen] = useState(false);
@@ -70,11 +70,3 @@ export const Dropdown = ({
7070
</div>
7171
);
7272
};
73-
74-
Dropdown.defaultProps = {
75-
wrapperClass: "",
76-
triggerButtonClass: "",
77-
triggerAriaLabel: "See more options",
78-
openOnHover: true,
79-
hideDownArrow: false,
80-
};

src/lib/EyebrowBar/EyebrowBar.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import "./EyebrowBar.scss";
1212
* @param text - Main text displayed in the component.
1313
*/
1414
export const EyebrowBar: React.FC<EyebrowBarProps> = ({
15-
buttonLabel,
16-
className,
17-
external,
18-
href,
19-
id,
15+
buttonLabel = "Learn more",
16+
className = undefined,
17+
external = false,
18+
href = undefined,
19+
id = undefined,
2020
text,
2121
}) => {
2222
return (
@@ -40,11 +40,3 @@ export const EyebrowBar: React.FC<EyebrowBarProps> = ({
4040
</div>
4141
);
4242
};
43-
44-
EyebrowBar.defaultProps = {
45-
buttonLabel: "Learn more",
46-
className: undefined,
47-
external: false,
48-
href: undefined,
49-
id: undefined,
50-
};

src/lib/Input/Input.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ const mappedTypes = (
7676
*/
7777
export const Input: React.FC<InputProps> = ({
7878
inputId,
79-
fieldType,
80-
isMultiSelect,
81-
variant,
82-
required,
79+
fieldType = "text",
80+
isMultiSelect = false,
81+
variant = InputVariant.FIELD,
82+
required = false,
8383
label,
8484
helpText,
85-
disabled,
85+
disabled = false,
8686
maxLength,
8787
placeholder,
8888
selectValue,
89-
forceValidation,
89+
forceValidation = false,
9090
selectOptions,
9191
validator,
9292
value,
@@ -233,13 +233,3 @@ export const Input: React.FC<InputProps> = ({
233233
</fieldset>
234234
);
235235
};
236-
237-
Input.defaultProps = {
238-
disabled: false,
239-
fieldType: "text",
240-
forceValidation: false,
241-
isMultiSelect: false,
242-
required: false,
243-
// @ts-ignore
244-
variant: "FIELD",
245-
};

src/lib/NavBar/NavBar.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ const Login = ({
166166
export const NavBar: React.FC<NavBarProps> = ({
167167
id,
168168
className,
169-
isLoggedIn,
170-
userImage,
171-
username,
172-
hideConnectWalletDropdown,
169+
isLoggedIn = false,
170+
userImage = "/",
171+
username = undefined,
172+
hideConnectWalletDropdown = false,
173173
logoutHandler,
174174
loginHandler,
175175
modalHandler,
176-
navLinks,
176+
navLinks = [],
177177
}) => {
178178
const [mobileNavOpen, setMobileNavOpen] = useState(false);
179179

@@ -273,11 +273,3 @@ export const NavBar: React.FC<NavBarProps> = ({
273273
</>
274274
);
275275
};
276-
277-
NavBar.defaultProps = {
278-
isLoggedIn: false,
279-
hideConnectWalletDropdown: false,
280-
navLinks: [],
281-
username: undefined,
282-
userImage: "/",
283-
};

src/lib/Tag/Tag.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import "./Tag.scss";
2222
* @param id - HTML element identifier.
2323
*/
2424
export const Tag: React.FC<TagProps> = ({
25-
variant,
26-
size,
27-
iconLeft,
25+
variant = TagVariant.DEFAULT,
26+
size = TagSize.NARROW,
27+
iconLeft = "",
2828
label,
29-
className,
30-
id,
29+
className = "",
30+
id = "",
3131
}) => {
3232
const styling = clsx({
3333
c4tag: true,
@@ -47,13 +47,3 @@ export const Tag: React.FC<TagProps> = ({
4747
</div>
4848
);
4949
};
50-
51-
Tag.defaultProps = {
52-
/* @ts-ignore value in Enum */
53-
variant: "DEFAULT",
54-
/* @ts-ignore value in Enum */
55-
size: "NARROW",
56-
iconLeft: "",
57-
className: "",
58-
id: "",
59-
};

0 commit comments

Comments
 (0)