-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathCallToAction.js
More file actions
37 lines (30 loc) · 813 Bytes
/
CallToAction.js
File metadata and controls
37 lines (30 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import styles from './call-to-action.module.css';
const getSafeHref = (href) => {
if (typeof href !== 'string') {
return '#';
}
const value = href.trim();
if (!value || value.startsWith('/') || value.startsWith('#') || value.startsWith('?')) {
return value || '#';
}
const lowerValue = value.toLowerCase();
if (
lowerValue.startsWith('http://') ||
lowerValue.startsWith('https://') ||
lowerValue.startsWith('mailto:')
) {
return value;
}
return '#';
};
export const CallToAction = ({ href, children }) => {
return (
<a href={getSafeHref(href)} className={styles.cta}>
<div className={styles.content}>
{children}
</div>
<div className={styles.arrow}>→</div>
</a>
);
};