Skip to content

Commit f19fdb1

Browse files
committed
fix(button): next.JS no longer complains buttons are being rendered dynamically
By using the "as" property, we create the button element as simplay a button but switch it to an anchor when href is present. "fix #14", "re #16"
1 parent 5f9fdb7 commit f19fdb1

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/components/Button.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ export type ButtonProps = React.HTMLAttributes<
1616
};
1717

1818
export const Button = (props: ButtonProps) => {
19-
const { variant, accent } = props;
20-
const ButtonElement = createButtonElement(props);
21-
return <ButtonElement {...props} />;
19+
return <ButtonElement as={props.href ? "a" : "button"} {...props} />;
2220
};
2321

24-
const createButtonElement = (props: ButtonProps) => styled(
25-
props.href ? "a" : "button"
26-
)<ButtonProps>`
22+
const ButtonElement = styled.button<ButtonProps>`
2723
font-size: ${(props) => {
2824
if (props.size === "small") return "0.75em";
2925
if (props.size === "large") return "1.25em";
@@ -66,17 +62,24 @@ const createButtonElement = (props: ButtonProps) => styled(
6662
border: ${(props) => {
6763
if (props.variant !== "outlined") return "none";
6864
return `1px solid ${
69-
props.theme[props.accent || "info"] ?? getThemeValue(props.accent || "info")
65+
props.theme[props.accent || "info"] ??
66+
getThemeValue(props.accent || "info")
7067
}`;
7168
}};
7269
background-color: ${(props) => {
7370
if (props.variant === "contained")
74-
return props.theme[props.accent || "info"] ?? getThemeValue(props.accent || "info");
71+
return (
72+
props.theme[props.accent || "info"] ??
73+
getThemeValue(props.accent || "info")
74+
);
7575
return "transparent";
7676
}};
7777
color: ${(props) => {
7878
if (props.variant === "contained") return "#fff";
79-
return props.theme[props.accent || "info"] ?? getThemeValue(props.accent || "info");
79+
return (
80+
props.theme[props.accent || "info"] ??
81+
getThemeValue(props.accent || "info")
82+
);
8083
}};
8184
8285
&:disabled {
@@ -99,15 +102,17 @@ const createButtonElement = (props: ButtonProps) => styled(
99102
filter: drop-shadow(
100103
0em 0.125em 0.625em
101104
${(props) =>
102-
props.theme[props.accent || "info"] ?? getThemeValue(props.accent || "info")}80
105+
props.theme[props.accent || "info"] ??
106+
getThemeValue(props.accent || "info")}80
103107
)
104108
brightness(110%);
105109
}
106110
&:active:not(:disabled) {
107111
filter: drop-shadow(
108112
0em 0.0625em 0.3125em
109113
${(props) =>
110-
props.theme[props.accent || "info"] ?? getThemeValue(props.accent || "info")}80
114+
props.theme[props.accent || "info"] ??
115+
getThemeValue(props.accent || "info")}80
111116
)
112117
brightness(80%);
113118
}

0 commit comments

Comments
 (0)