Skip to content

Commit

Permalink
Do not use crypto.randomUI without polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Feb 29, 2024
1 parent 7d5032d commit f73e767
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@surfnet/sds",
"version": "0.0.101",
"version": "0.0.102",
"description": "SURF Design System for React",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
3 changes: 2 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export function sanitize(text: string) {
}

export function pseudoGuid() {
return (crypto.randomUUID && crypto.randomUUID()) || Math.round((new Date().getTime() * Math.random() * 1000)).toString()
return (crypto.randomUUID && typeof crypto.randomUUID === "function" && crypto.randomUUID()) ||
Math.round((new Date().getTime() * Math.random() * 1000)).toString()
}
3 changes: 2 additions & 1 deletion src/components/RadioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {ChangeEventHandler} from "react";
import Tooltip from "../Tooltip/index";
import "../Tooltip/TooltipParent.scss";
import {pseudoGuid} from "../../common/utils";

export interface RadioButtonProps {
label: string;
Expand All @@ -15,7 +16,7 @@ export interface RadioButtonProps {
}

const RadioButton = (props: RadioButtonProps) => {
const id = props.id || crypto.randomUUID();
const id = props.id || pseudoGuid();
const className = `sds--radio-container ${
props.tooltip ? "sds--tooltip-parent" : ""
}`;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import "./Tooltip.scss";
import {PlacesType, Tooltip as ReactTooltip} from "react-tooltip";
import {ReactComponent as InfoIcon} from "../../icons/functional-icons/info.svg";
import {sanitize} from "../../common/utils";
import {pseudoGuid, sanitize} from "../../common/utils";

export interface TooltipProps {
tip: string;
Expand All @@ -12,7 +12,7 @@ export interface TooltipProps {
}

const Tooltip = (props: React.PropsWithChildren<TooltipProps>) => {
const uniqueAnchorId = "A" + crypto.randomUUID();
const uniqueAnchorId = "A" + pseudoGuid();
return (
<div id={uniqueAnchorId} className={`sds--tooltip-container ${props.standalone ? "" : "sibbling"}`}>
{props.children ? React.Children.map(props.children, (child: any) => child) : <InfoIcon/>}
Expand Down

0 comments on commit f73e767

Please sign in to comment.