-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from vtex-apps/dynamicIframeSrc
adding dynamicIframe component
- Loading branch information
Showing
20 changed files
with
1,825 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "vtex", | ||
"root": true, | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"jest": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"eslintIntegration": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "iframe", | ||
"private": true, | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"lint": "eslint --ext js,jsx,ts,tsx ." | ||
}, | ||
"devDependencies": { | ||
"@types/node": "12.12.21", | ||
"eslint": "6.7.2", | ||
"eslint-config-vtex": "11.2.1", | ||
"eslint-config-vtex-react": "5.1.0", | ||
"prettier": "1.19.1", | ||
"typescript": "3.7.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "vtex-react", | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jest": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Iframe from './Iframe' | ||
import React from 'react' | ||
import { useRuntime } from 'vtex.render-runtime' | ||
|
||
const DynamicIframe: StorefrontFunctionComponent<DynamicIframeProps> = ({ | ||
dynamicSrc = '', | ||
width, | ||
height, | ||
title, | ||
}) => { | ||
const { | ||
route: { params }, | ||
} = useRuntime() | ||
|
||
const src = dynamicSrc.replace(/({[A-z0-9]*})/g, function(match: string) { | ||
const thisParam = match.replace(/{|}/g, '') | ||
return params[thisParam] | ||
}) | ||
|
||
return <Iframe title={title} src={src} width={width} height={height} /> | ||
} | ||
|
||
interface DynamicIframeProps { | ||
dynamicSrc: string | ||
width?: number | ||
height?: number | ||
title?: string | ||
} | ||
|
||
DynamicIframe.schema = { | ||
title: 'editor.dynamiciframe.title', | ||
type: 'object', | ||
properties: { | ||
dynamicSrc: { | ||
title: 'editor.dynamiciframe.dynamicSrc.title', | ||
description: 'editor.dynamiciframe.dynamicSrc.description', | ||
type: 'string', | ||
default: null, | ||
}, | ||
width: { | ||
title: 'editor.dynamiciframe.width.title', | ||
type: 'number', | ||
default: null, | ||
}, | ||
height: { | ||
title: 'editor.dynamiciframe.height.title', | ||
type: 'number', | ||
default: null, | ||
}, | ||
title: { | ||
title: 'editor.dynamiciframe.title.title', | ||
type: 'string', | ||
default: null, | ||
}, | ||
}, | ||
} | ||
|
||
export default DynamicIframe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const useCssHandles = (obj: object) => obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const useRuntime = jest.fn() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import React from 'react' | ||
import { render } from '@vtex/test-tools/react' | ||
import Component from '../components/index' | ||
import DynamicIframe from '../DynamicIframe' | ||
import { useRuntime } from 'vtex.render-runtime' | ||
|
||
describe('HelloWorld Component', () => { | ||
const { getByText } = render(<Component />) | ||
const mockedUseRuntime = useRuntime as jest.Mock | ||
|
||
it('should render the example in TypeScript', () => { | ||
expect(getByText(/This is an example/)).toBeDefined() | ||
describe('DynamicIframe', () => { | ||
it('should render the right URL', () => { | ||
mockedUseRuntime.mockImplementation(() => { | ||
return { | ||
route: { | ||
params: { | ||
param1: 'foo', | ||
param2: 'bar', | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
const { container } = render( | ||
<DynamicIframe dynamicSrc="https://{param1}.com/{param2}.aspx" /> | ||
) | ||
|
||
const iframe = container.querySelector('iframe') as HTMLIFrameElement | ||
|
||
expect(iframe.src).toBe('https://foo.com/bar.aspx') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.