Skip to content

allow string props for image width/height #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/kitchenSink.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const email = (
<Box cellSpacing={20} width="100%" style={{ borderTop: '3px solid black' }}>
<Item>
<Span color="gray" lineHeight={20}>Generated by <A href="https://github.com/chromakode/react-html-email">react-html-email</A></Span>
<Image data-mc-bar="bar" data-mc-baz="baz" alt="react" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/57/React.js_logo.svg/100px-React.js_logo.svg.png" width={100} height={100} />
<Image data-mc-bar="bar" data-mc-baz="baz" alt="react" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/57/React.js_logo.svg/100px-React.js_logo.svg.png" width="auto" height={100} />
</Item>
</Box>
</Item>
Expand Down
10 changes: 8 additions & 2 deletions src/components/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export default function Image(props) {
Image.propTypes = {
alt: PropTypes.string.isRequired,
src: PropTypes.string.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
width: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
height: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
style: EmailPropTypes.style,
}
2 changes: 1 addition & 1 deletion test/renderEmail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('renderEmail', () => {

it('produces expected output from a kitchen sink example', () => {
const actualOutput = renderEmail(kitchenSink)
const expectedOutput = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Test Email</title><style type="text/css">@media only screen and (max-device-width: 480px) {\n font-size: 20px !important;\n}</style></head><body style="width:100%;margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;"><table width="100%" height="100%" cellpadding="0" cellspacing="0" align="left" valign="top"><tbody><tr><td align="center" valign="top"><table width="600" align="center" cellpadding="0" cellspacing="0" valign="top"><tbody><tr><td><span style="font-family:sans-serif;font-size:15px;line-height:15px;color:#000;">Hello, world!</span></td></tr><tr><td><table cellspacing="20" width="100%" style="border-top:3px solid black;" cellpadding="0" align="left" valign="top"><tbody><tr><td><span style="font-family:sans-serif;font-size:14px;line-height:20px;color:gray;">Generated by <a href="https://github.com/chromakode/react-html-email" target="_blank" style="text-decoration:underline;">react-html-email</a></span><img data-mc-bar="bar" data-mc-baz="baz" alt="react" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/57/React.js_logo.svg/100px-React.js_logo.svg.png" width="100" height="100" style="display:block;outline:none;border:none;text-decoration:none;"/></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></body></html>'
const expectedOutput = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Test Email</title><style type="text/css">@media only screen and (max-device-width: 480px) {\n font-size: 20px !important;\n}</style></head><body style="width:100%;margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;"><table width="100%" height="100%" cellpadding="0" cellspacing="0" align="left" valign="top"><tbody><tr><td align="center" valign="top"><table width="600" align="center" cellpadding="0" cellspacing="0" valign="top"><tbody><tr><td><span style="font-family:sans-serif;font-size:15px;line-height:15px;color:#000;">Hello, world!</span></td></tr><tr><td><table cellspacing="20" width="100%" style="border-top:3px solid black;" cellpadding="0" align="left" valign="top"><tbody><tr><td><span style="font-family:sans-serif;font-size:14px;line-height:20px;color:gray;">Generated by <a href="https://github.com/chromakode/react-html-email" target="_blank" style="text-decoration:underline;">react-html-email</a></span><img data-mc-bar="bar" data-mc-baz="baz" alt="react" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/57/React.js_logo.svg/100px-React.js_logo.svg.png" width="auto" height="100" style="display:block;outline:none;border:none;text-decoration:none;"/></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></body></html>'
expect(actualOutput).toBe(expectedOutput)
})

Expand Down