Skip to content

Commit 00ff2bd

Browse files
adamrayabendvc
andauthored
Fix Page Designer ImageWithText Link component (#1092)
* Fix PD ImageWithText Link component by using Chakra UI Link * Use isAbsoluteURL to use react-router Link or Chakra Link component * PR Feedback * Clean up * Update packages/template-retail-react-app/app/page-designer/assets/image-with-text/index.jsx Co-authored-by: Ben Chypak <bchypak@mobify.com> * Remove temporal page-viewer page to facilitate review --------- Co-authored-by: Ben Chypak <bchypak@mobify.com>
1 parent 6b9d436 commit 00ff2bd

File tree

2 files changed

+21
-3
lines changed
  • packages/template-retail-react-app/app/page-designer

2 files changed

+21
-3
lines changed

packages/template-retail-react-app/app/page-designer/assets/image-with-text/index.jsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
*/
77
import React from 'react'
88
import PropTypes from 'prop-types'
9-
import {Box, Image, Text} from '@chakra-ui/react'
9+
import {Box, Image, Link as ChakraLink, Text} from '@chakra-ui/react'
1010
import Link from '../../../components/link'
11+
import {isAbsoluteURL} from '../../utils'
1112

1213
/**
1314
* Image with text component
@@ -22,6 +23,9 @@ import Link from '../../../components/link'
2223
*/
2324
export const ImageWithText = ({ITCLink, ITCText, image, heading, alt}) => {
2425
const hasCaption = ITCText || heading
26+
const isAbsolute = isAbsoluteURL(ITCLink)
27+
const LinkWrapper = isAbsolute ? ChakraLink : Link
28+
const linkProps = isAbsolute ? {href: ITCLink} : {to: ITCLink}
2529

2630
return (
2731
<Box className={'image-with-text'}>
@@ -35,7 +39,7 @@ export const ImageWithText = ({ITCLink, ITCText, image, heading, alt}) => {
3539
<picture>
3640
<source srcSet={image?.src?.tablet} media="(min-width: 48em)" />
3741
<source srcSet={image?.src?.desktop} media="(min-width: 64em)" />
38-
<Link to={ITCLink}>
42+
<LinkWrapper {...linkProps}>
3943
<Image
4044
className={'image-with-text-image'}
4145
data-testid={'image-with-text-image'}
@@ -45,7 +49,7 @@ export const ImageWithText = ({ITCLink, ITCText, image, heading, alt}) => {
4549
title={alt}
4650
filter={'brightness(40%)'}
4751
/>
48-
</Link>
52+
</LinkWrapper>
4953
</picture>
5054
{hasCaption && (
5155
<Text as="figcaption">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2023, Salesforce, Inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
/**
9+
* Determines whether the specified URL is absolute
10+
*
11+
* @param {string} url The URL to test
12+
* @returns {boolean} True if the specified URL is absolute, otherwise false
13+
*/
14+
export const isAbsoluteURL = (url) => /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url)

0 commit comments

Comments
 (0)