Skip to content

Commit c75b4d3

Browse files
author
jikrana
committed
fix: sanitize props and gate warn() by env
1 parent 9345511 commit c75b4d3

2 files changed

Lines changed: 330 additions & 105 deletions

File tree

src/components/SupportUsButton.tsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,37 @@ function validateUrl(url?: string): string | undefined {
6262
}
6363

6464
// Main component function that renders the support us button, taking in various props for customization and rendering different sections such as hero, organization information, sponsors, and call-to-action based on the provided data and selected theme and button variant
65-
function SupportUsButton({
66-
Theme = "auto",
67-
organizationInformation,
68-
sponsors,
69-
ctaSection,
70-
projectInformation,
71-
Logo = true,
72-
className = "",
73-
border = {
74-
TopX1: "-1000",
75-
TopX2: "1000",
76-
BottomX1: "-1000",
77-
BottomX2: "1000",
78-
LeftY1: "-1000",
79-
LeftY2: "1000",
80-
RightY1: "-1000",
81-
RightY2: "1000",
82-
},
83-
}: supportUsButtonProps): React.JSX.Element {
84-
validateProps({
85-
Theme,
86-
organizationInformation,
87-
sponsors,
88-
ctaSection,
89-
projectInformation,
90-
Logo,
91-
className,
92-
border,
93-
});
65+
function SupportUsButton(
66+
props: supportUsButtonProps,
67+
): React.JSX.Element {
68+
const validatedProps = validateProps(props ?? ({} as supportUsButtonProps));
69+
70+
const {
71+
Theme = "auto",
72+
organizationInformation,
73+
sponsors = [],
74+
ctaSection,
75+
projectInformation,
76+
Logo = true,
77+
className = "",
78+
} = validatedProps ?? ({} as supportUsButtonProps);
79+
80+
const border = validatedProps.border ?? {
81+
TopX1: "-1000",
82+
TopX2: "1000",
83+
BottomX1: "-1000",
84+
BottomX2: "1000",
85+
LeftY1: "-1000",
86+
LeftY2: "1000",
87+
RightY1: "-1000",
88+
RightY2: "1000",
89+
};
9490
const containerRef = useRef<HTMLDivElement>(null);
91+
9592
const isAuto = Theme === "auto" || Theme === "inherit";
93+
9694
const parentStyles = useParentStyles(containerRef, isAuto);
95+
9796
const darkThemeActive =
9897
Theme === "dark" || (isAuto && isDarkColor(parentStyles.backgroundColor));
9998

0 commit comments

Comments
 (0)