@stokr/components-library 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/BackButton/BackButton.js +5 -2
- package/dist/components/BlogPost/BlogPost.js +2 -1
- package/dist/components/Checkbox/Checkbox.d.ts +2 -2
- package/dist/components/Checkbox/Checkbox.styles.js +6 -0
- package/dist/components/Checklist/ChecklistCard.js +5 -3
- package/dist/components/Payment/PaymentDetailsCard.js +2 -1
- package/dist/components/Payment/PaymentPendingCard.js +2 -1
- package/dist/components/Payment/PaymentSuccessCard.js +3 -2
- package/dist/components/SmartLink/SmartLink.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/utils/safeUrl.d.ts +6 -0
- package/dist/utils/safeUrl.js +10 -0
- package/package.json +3 -2
|
@@ -2,13 +2,16 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { useNavigate } from "react-router-dom";
|
|
5
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
5
6
|
import { StyledBackButtonExternal, BackButtonIcon, StyledBackButton, StyledWindowBackButton } from "./BackButton.styles.js";
|
|
6
7
|
const BackButton = ({ children, to, href }) => {
|
|
7
8
|
const navigate = useNavigate();
|
|
8
|
-
|
|
9
|
+
const safeHref = safeUrl(href);
|
|
10
|
+
const safeTo = typeof to === "string" ? safeUrl(to) : to;
|
|
11
|
+
return safeHref ? /* @__PURE__ */ jsxs(StyledBackButtonExternal, { href: safeHref, children: [
|
|
9
12
|
/* @__PURE__ */ jsx(BackButtonIcon, {}),
|
|
10
13
|
children
|
|
11
|
-
] }) :
|
|
14
|
+
] }) : safeTo ? /* @__PURE__ */ jsxs(StyledBackButton, { to: safeTo, children: [
|
|
12
15
|
/* @__PURE__ */ jsx(BackButtonIcon, {}),
|
|
13
16
|
children
|
|
14
17
|
] }) : /* @__PURE__ */ jsxs(StyledWindowBackButton, { onClick: () => navigate(-1), children: [
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useRef, useEffect } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
4
5
|
import { Container, ImageWrapper, LoaderWrapper, LoaderImage, Image, Content, Category, TextWrapper, BottomRow, StyledButton } from "./BlogPost.styles.js";
|
|
5
6
|
import { loaderGif } from "../StokrLoader/StokrLoader.js";
|
|
6
7
|
import { Breakdown } from "../breakdown/Breakdown.js";
|
|
@@ -73,7 +74,7 @@ const BlogPost = ({
|
|
|
73
74
|
StyledButton,
|
|
74
75
|
{
|
|
75
76
|
onClick: () => {
|
|
76
|
-
if (link && !onClick) window.location.href = link;
|
|
77
|
+
if (safeUrl(link) && !onClick) window.location.href = link;
|
|
77
78
|
if (onClick) onClick();
|
|
78
79
|
},
|
|
79
80
|
children: CTAText
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CSSProperties, InputHTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
export declare const CheckBoxCaption: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
3
|
-
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value'> {
|
|
3
|
+
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultChecked'> {
|
|
4
4
|
id: string;
|
|
5
5
|
text?: ReactNode;
|
|
6
6
|
/** Heading above the checkbox. */
|
|
7
7
|
label?: string;
|
|
8
|
-
value?: string;
|
|
8
|
+
value?: string | number | boolean;
|
|
9
9
|
large?: boolean;
|
|
10
10
|
error?: boolean;
|
|
11
11
|
touched?: boolean;
|
|
@@ -97,6 +97,12 @@ const Input = styled.div`
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
&:focus-visible + label:before {
|
|
101
|
+
box-shadow:
|
|
102
|
+
0 0 0 2px ${theme.cWhite},
|
|
103
|
+
0 0 0 4px ${theme.cPrimary};
|
|
104
|
+
}
|
|
105
|
+
|
|
100
106
|
&:checked + label {
|
|
101
107
|
&:before {
|
|
102
108
|
background-color: ${(props) => props.$disabled ? "#9b9b9b" : theme.cPrimary};
|
|
@@ -4,11 +4,13 @@ import PropTypes from "prop-types";
|
|
|
4
4
|
import { MaterialIcon } from "../MaterialIcon/MaterialIcon.js";
|
|
5
5
|
import { CardContainer, IconBlock, IconCopy, CardTitle, CardDescription } from "./ChecklistCard.styles.js";
|
|
6
6
|
import { colors } from "../../styles/colors.js";
|
|
7
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
7
8
|
import SvgWarningFilled from "../../static/images/warning-filled.svg.js";
|
|
8
9
|
import { Link } from "react-router-dom";
|
|
9
10
|
const ICON_MAP = {
|
|
10
11
|
done: {
|
|
11
12
|
material: "check",
|
|
13
|
+
weight: 600,
|
|
12
14
|
color: colors.freshGreen
|
|
13
15
|
},
|
|
14
16
|
missing: {
|
|
@@ -31,8 +33,8 @@ const ChecklistCard = ({
|
|
|
31
33
|
isClickable = true,
|
|
32
34
|
...rest
|
|
33
35
|
}) => {
|
|
34
|
-
const { icon, material, color } = ICON_MAP[iconState] || ICON_MAP["missing"];
|
|
35
|
-
const iconElement = material ? /* @__PURE__ */ jsx(MaterialIcon, { name: material, size: 20, color }) : /* @__PURE__ */ jsx("span", { style: { display: "inline-flex", width: 20, height: 20, color }, children: icon });
|
|
36
|
+
const { icon, material, weight, color } = ICON_MAP[iconState] || ICON_MAP["missing"];
|
|
37
|
+
const iconElement = material ? /* @__PURE__ */ jsx(MaterialIcon, { name: material, size: 20, color, weight }) : /* @__PURE__ */ jsx("span", { style: { display: "inline-flex", width: 20, height: 20, color }, children: icon });
|
|
36
38
|
const content = /* @__PURE__ */ jsxs(
|
|
37
39
|
CardContainer,
|
|
38
40
|
{
|
|
@@ -51,7 +53,7 @@ const ChecklistCard = ({
|
|
|
51
53
|
]
|
|
52
54
|
}
|
|
53
55
|
);
|
|
54
|
-
if (link && !onClick && !disabled) {
|
|
56
|
+
if (link && (typeof link !== "string" || safeUrl(link)) && !onClick && !disabled) {
|
|
55
57
|
return /* @__PURE__ */ jsx(Link, { to: link, tabIndex: 0, "aria-disabled": disabled, style: { textDecoration: "none", color: "inherit" }, children: content });
|
|
56
58
|
}
|
|
57
59
|
return content;
|
|
@@ -2,6 +2,7 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
|
2
2
|
import React__default from "react";
|
|
3
3
|
import styled from "styled-components";
|
|
4
4
|
import { colors } from "../../styles/colors.js";
|
|
5
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
5
6
|
import { InfoIcon } from "../InfoIcon/InfoIcon.js";
|
|
6
7
|
import { ArrowSimple } from "../icons/ArrowSimple.js";
|
|
7
8
|
import { getCurrencyConfig, getCurrencyIcon, formatAmountForDisplay } from "../../utils/formatCurrencyValue.js";
|
|
@@ -227,7 +228,7 @@ const DetailItem = ({ label, value, tooltip, placeholder, isCustom, href, target
|
|
|
227
228
|
if (isCustom && value) {
|
|
228
229
|
return value;
|
|
229
230
|
}
|
|
230
|
-
if (href) {
|
|
231
|
+
if (safeUrl(href)) {
|
|
231
232
|
return /* @__PURE__ */ jsxs(ExternalLink, { href, target: target || "_blank", rel: "noopener noreferrer", children: [
|
|
232
233
|
/* @__PURE__ */ jsx(ExternalLinkIconImg, { src: externalLinkIcon, alt: "" }),
|
|
233
234
|
value || placeholder || "-"
|
|
@@ -3,6 +3,7 @@ import "react";
|
|
|
3
3
|
import styled, { keyframes } from "styled-components";
|
|
4
4
|
import { ComponentWrapper } from "../ComponentWrapper/ComponentWrapper.styles.js";
|
|
5
5
|
import { colors } from "../../styles/colors.js";
|
|
6
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
6
7
|
import { Button } from "../Button/Button.styles.js";
|
|
7
8
|
import { DetailRows } from "./DetailRows.js";
|
|
8
9
|
import { CodeWrapper } from "./PaymentDisplay.js";
|
|
@@ -85,7 +86,7 @@ const PaymentPendingCard = ({
|
|
|
85
86
|
Button,
|
|
86
87
|
{
|
|
87
88
|
as: actionHref ? "a" : "button",
|
|
88
|
-
href: actionHref,
|
|
89
|
+
href: safeUrl(actionHref),
|
|
89
90
|
target: actionHref ? "_blank" : void 0,
|
|
90
91
|
rel: actionHref ? "noopener noreferrer" : void 0,
|
|
91
92
|
onClick: onActionClick,
|
|
@@ -3,6 +3,7 @@ import "react";
|
|
|
3
3
|
import styled from "styled-components";
|
|
4
4
|
import { ComponentWrapper } from "../ComponentWrapper/ComponentWrapper.styles.js";
|
|
5
5
|
import { colors } from "../../styles/colors.js";
|
|
6
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
6
7
|
import { Button } from "../Button/Button.styles.js";
|
|
7
8
|
import { CodeWrapper, AmountIcon, AmountValue, AmountCurrency } from "./PaymentDisplay.js";
|
|
8
9
|
import { DetailsToggle } from "./DetailsToggle.js";
|
|
@@ -115,7 +116,7 @@ const PaymentSuccessCard = ({
|
|
|
115
116
|
ActionButton,
|
|
116
117
|
{
|
|
117
118
|
as: secondaryActionHref ? "a" : "button",
|
|
118
|
-
href: secondaryActionHref,
|
|
119
|
+
href: safeUrl(secondaryActionHref),
|
|
119
120
|
target: secondaryActionHref ? "_blank" : void 0,
|
|
120
121
|
rel: secondaryActionHref ? "noopener noreferrer" : void 0,
|
|
121
122
|
onClick: onSecondaryActionClick,
|
|
@@ -126,7 +127,7 @@ const PaymentSuccessCard = ({
|
|
|
126
127
|
]
|
|
127
128
|
}
|
|
128
129
|
),
|
|
129
|
-
primaryActionLabel && /* @__PURE__ */ jsx(ActionButton, { as: primaryActionHref ? "a" : "button", href: primaryActionHref, onClick: onPrimaryActionClick, children: primaryActionLabel })
|
|
130
|
+
primaryActionLabel && /* @__PURE__ */ jsx(ActionButton, { as: primaryActionHref ? "a" : "button", href: safeUrl(primaryActionHref), onClick: onPrimaryActionClick, children: primaryActionLabel })
|
|
130
131
|
] }),
|
|
131
132
|
children
|
|
132
133
|
] }) });
|
|
@@ -2,11 +2,15 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { Link } from "react-router-dom";
|
|
5
|
+
import { safeUrl } from "../../utils/safeUrl.js";
|
|
5
6
|
const isExternalUrl = (to) => {
|
|
6
7
|
if (typeof to !== "string" || to === "") return false;
|
|
7
8
|
return /^([a-z][a-z0-9+.-]*:|\/\/)/i.test(to);
|
|
8
9
|
};
|
|
9
10
|
const SmartLink = ({ to, children, ...rest }) => {
|
|
11
|
+
if (typeof to === "string" && to && !safeUrl(to)) {
|
|
12
|
+
return /* @__PURE__ */ jsx("a", { ...rest, children });
|
|
13
|
+
}
|
|
10
14
|
if (isExternalUrl(to)) {
|
|
11
15
|
return /* @__PURE__ */ jsx("a", { href: to, ...rest, children });
|
|
12
16
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -241,6 +241,7 @@ export declare const StepControllerProvider: AnyComponent, StepControllerContext
|
|
|
241
241
|
export declare const StepControllerConsumer: AnyComponent
|
|
242
242
|
export declare const SmartLink: AnyComponent
|
|
243
243
|
export declare const isExternalUrl: (url: unknown) => boolean
|
|
244
|
+
export { safeUrl } from './utils/safeUrl'
|
|
244
245
|
export declare const Switch: AnyComponent
|
|
245
246
|
export declare const Tabs: AnyComponent, Tab: AnyComponent
|
|
246
247
|
export declare const Breakdown: AnyComponent
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,7 @@ import { SectionTitle } from "./components/SectionTitle/SectionTitle.styles.js";
|
|
|
65
65
|
import { StepController } from "./components/StepController/StepController.js";
|
|
66
66
|
import { StepControllerConsumer, StepControllerContext, StepControllerProvider } from "./components/StepController/StepControllerContext.js";
|
|
67
67
|
import { SmartLink, isExternalUrl } from "./components/SmartLink/SmartLink.js";
|
|
68
|
+
import { safeUrl } from "./utils/safeUrl.js";
|
|
68
69
|
import { Switch } from "./components/Switch/Switch.js";
|
|
69
70
|
import { Tabs } from "./components/Tabs/Tabs.js";
|
|
70
71
|
import { Text } from "./components/Text/Text.styles.js";
|
|
@@ -420,6 +421,7 @@ export {
|
|
|
420
421
|
roundTo,
|
|
421
422
|
default4 as rwd,
|
|
422
423
|
rwdMax,
|
|
424
|
+
safeUrl,
|
|
423
425
|
sanitizeAmountInput,
|
|
424
426
|
saveAs,
|
|
425
427
|
scrollToElement,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The URL when it is safe to put in an `href` or navigate to, otherwise `undefined`. Allows http(s), mailto, tel,
|
|
3
|
+
* protocol-relative and relative URLs; blocks every other scheme (`javascript:`, `data:`, `vbscript:`, `blob:`, ...),
|
|
4
|
+
* including ones hidden with spaces or control characters, which browsers ignore when parsing.
|
|
5
|
+
*/
|
|
6
|
+
export declare const safeUrl: (url: unknown) => string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const ALLOWED_SCHEMES = ["http:", "https:", "mailto:", "tel:"];
|
|
2
|
+
const safeUrl = (url) => {
|
|
3
|
+
if (typeof url !== "string" || url === "") return void 0;
|
|
4
|
+
const scheme = url.replace(/[\u0000- \u007f]/g, "").match(/^[a-z][a-z0-9+.-]*:/i);
|
|
5
|
+
if (scheme && !ALLOWED_SCHEMES.includes(scheme[0].toLowerCase())) return void 0;
|
|
6
|
+
return url;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
safeUrl
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stokr/components-library",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "STOKR - Components Library",
|
|
5
5
|
"author": "Bilal Hodzic <bilal@stokr.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": [
|
|
24
24
|
"**/*.css",
|
|
25
|
-
"./dist/styles/global.js"
|
|
25
|
+
"./dist/styles/global.js",
|
|
26
|
+
"./src/storybook/materialIcons.ts"
|
|
26
27
|
],
|
|
27
28
|
"repository": {
|
|
28
29
|
"type": "git",
|