Skip to content

Commit

Permalink
feat: support external links
Browse files Browse the repository at this point in the history
  • Loading branch information
kupara committed Nov 7, 2019
1 parent 3cde6d4 commit ed7234c
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 26 deletions.
34 changes: 26 additions & 8 deletions src/components/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,30 @@
jsx: (() => (
<section className={classes.root}>
{(() => {
const { icon, titleText, bodyText, buttonLink, buttonText } = options;
const {
icon,
titleText,
bodyText,
buttonLink,
buttonText,
linkToExternal,
} = options;
const renderLink = () =>
linkToExternal ? (
<a
href={linkToExternal}
className={[classes.button, classes.link].join(' ')}
>
<B.Text value={buttonText} />
</a>
) : (
<B.Link
endpointId={buttonLink}
className={[classes.button, classes.link].join(' ')}
>
<B.Text value={buttonText} />
</B.Link>
);
return (
<>
<div className={classes.iconWrapper}>
Expand All @@ -30,13 +53,8 @@
</div>
<div className={classes.controlsWrapper}>
<div className={classes.buttonsWrapper}>
{buttonText && buttonLink ? (
<B.Link
endpointId={buttonLink}
className={[classes.button, classes.link].join(' ')}
>
<B.Text value={buttonText} />
</B.Link>
{buttonText && (buttonLink || linkToExternal) ? (
renderLink()
) : (
<button type="button" className={classes.button}>
<B.Text value={buttonText} />
Expand Down
19 changes: 18 additions & 1 deletion src/components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@
jsx: (
<span className={classes.wrapper}>
{(() => {
const { linkTo, disabled, buttonText } = options;
const { linkTo, linkToExternal, disabled, buttonText } = options;

if (linkToExternal && linkToExternal !== '') {
return (
<a
href={linkToExternal}
className={[
classes.root,
classes['size-normal'],
classes.link,
B.env === 'dev' ? classes.noEvents : '',
].join(' ')}
>
<B.Text value={buttonText} />
</a>
);
}

if (linkTo && linkTo !== '') {
return (
<B.Link
Expand Down
34 changes: 26 additions & 8 deletions src/components/navigationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
jsx: (
<li className={classes.navigationItem}>
{(() => {
const { navigationContent, endpointId } = options;
const { navigationContent, endpointId, linkToExternal } = options;

if (navigationContent.length === 0)
return (
Expand All @@ -22,17 +22,35 @@
</span>
);

if (B.env === 'prod' && linkToExternal) {
return (
navigationContent.length > 0 && (
<a href={linkToExternal} className={classes.navigationLink}>
<B.Text value={navigationContent} />
</a>
)
);
}

if (B.env === 'prod' && endpointId) {
return (
navigationContent.length > 0 && (
<B.Link
endpointId={endpointId}
className={classes.navigationLink}
>
<B.Text value={navigationContent} />
</B.Link>
)
);
}

return (
navigationContent.length > 0 &&
(B.env === 'prod' && endpointId ? (
<B.Link endpointId={endpointId} className={classes.navigationLink}>
<B.Text value={navigationContent} />
</B.Link>
) : (
navigationContent.length > 0 && (
<span className={classes.navigationLink}>
<B.Text value={navigationContent} />
</span>
))
)
);
})()}
</li>
Expand Down
34 changes: 26 additions & 8 deletions src/components/sideNavItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
jsx: (
<li className={classes.navigationItem}>
{(() => {
const { navigationContent, endpointId } = options;
const { navigationContent, endpointId, linkToExternal } = options;
if (!navigationContent)
return (
<span
Expand All @@ -21,17 +21,35 @@
</span>
);

if (B.env === 'prod' && linkToExternal) {
return (
navigationContent.length > 0 && (
<a href={linkToExternal} className={classes.navigationLink}>
<B.Text value={navigationContent} />
</a>
)
);
}

if (B.env === 'prod' && endpointId) {
return (
navigationContent.length > 0 && (
<B.Link
endpointId={endpointId}
className={classes.navigationLink}
>
<B.Text value={navigationContent} />
</B.Link>
)
);
}

return (
navigationContent.length > 0 &&
(B.env === 'prod' && endpointId ? (
<B.Link endpointId={endpointId} className={classes.navigationLink}>
<B.Text value={navigationContent} />
</B.Link>
) : (
navigationContent.length > 0 && (
<span className={classes.navigationLink}>
<B.Text value={navigationContent} />
</span>
))
)
);
})()}
</li>
Expand Down
9 changes: 9 additions & 0 deletions src/prefabs/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
key: 'buttonLink',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
{
value: ['0rem', '0rem', 'M', '0rem'],
label: 'Outer space',
Expand Down
11 changes: 10 additions & 1 deletion src/prefabs/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@
},
{
value: '',
label: 'Link to',
label: 'Link to Page',
key: 'linkTo',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
{
value: 'Primary',
label: 'Button Color',
Expand Down
27 changes: 27 additions & 0 deletions src/prefabs/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand All @@ -59,6 +68,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand All @@ -77,6 +95,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand Down
9 changes: 9 additions & 0 deletions src/prefabs/navigationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand Down
9 changes: 9 additions & 0 deletions src/prefabs/sideNavItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand Down
18 changes: 18 additions & 0 deletions src/prefabs/sidebarLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand All @@ -57,6 +66,15 @@
key: 'endpointId',
type: 'ENDPOINT',
},
{
value: '',
label: 'URL (overrides internal link)',
key: 'linkToExternal',
type: 'TEXT',
configuration: {
placeholder: 'Starts with https:// or http://',
},
},
],
descendants: [],
},
Expand Down

0 comments on commit ed7234c

Please sign in to comment.