-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: show warning when using cellPadding and cellSpacing
- Loading branch information
1 parent
c067250
commit e246dc7
Showing
15 changed files
with
82 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
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,7 @@ | ||
import { log } from '../log.js'; | ||
|
||
export const cellPropWarning = () => { | ||
log.warn( | ||
'Use of the `cellPadding` and `cellSpacing` properties are discouraged due to inconsistencies between email clients' | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,28 +1,34 @@ | ||
import { debug } from '../debug.js'; | ||
import type { BaseProps, JsxEmailComponent } from '../types.js'; | ||
|
||
import { cellPropWarning } from './helpers.js'; | ||
|
||
export interface SectionProps extends BaseProps<'table'> {} | ||
|
||
const debugProps = debug.elements.enabled ? { dataType: 'jsx-email/section' } : {}; | ||
|
||
export const Section: JsxEmailComponent<SectionProps> = ({ children, style, ...props }) => ( | ||
<table | ||
align="center" | ||
width="100%" | ||
style={style} | ||
border={0} | ||
cellPadding="0" | ||
cellSpacing="0" | ||
role="presentation" | ||
{...props} | ||
{...debugProps} | ||
> | ||
<tbody> | ||
<tr> | ||
<td>{children}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
export const Section: JsxEmailComponent<SectionProps> = ({ children, style, ...props }) => { | ||
if (props.cellPadding || props.cellSpacing) cellPropWarning(); | ||
|
||
return ( | ||
<table | ||
align="center" | ||
width="100%" | ||
style={style} | ||
border={0} | ||
cellPadding="0" | ||
cellSpacing="0" | ||
role="presentation" | ||
{...props} | ||
{...debugProps} | ||
> | ||
<tbody> | ||
<tr> | ||
<td>{children}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
Section.displayName = 'Section'; |
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,5 +1,7 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`<Container> component > doesn't override cellPadding and cellSpacing 1`] = `"<div style=\\"table-layout:fixed;width:100%\\"><div style=\\"margin:0 auto;max-width:300px\\"><span><!--[if mso]><table align=\\"center\\" width=\\"300\\" style=\\"border-spacing: 0; width:300px;\\" role=\\"presentation\\"><tr><td><![endif]--></span><table align=\\"center\\" width=\\"100%\\" role=\\"presentation\\" cellSpacing=\\"10\\" cellPadding=\\"10\\" border=\\"0\\" style=\\"max-width:300px\\"><tbody><tr style=\\"width:100%\\"><td align=\\"center\\"><button>Hi</button></td></tr></tbody></table><span><!--[if mso]></td></tr></table><![endif]--></span></div></div>"`; | ||
exports[`<Container> component > renders alternate alignment 1`] = `"<div style=\\"table-layout:fixed;width:100%\\"><div style=\\"margin:0 auto;max-width:600px\\"><span><!--[if mso]><table align=\\"right\\" width=\\"600\\" style=\\"border-spacing: 0; width:600px;\\" role=\\"presentation\\"><tr><td><![endif]--></span><table align=\\"right\\" width=\\"100%\\" role=\\"presentation\\" cellSpacing=\\"0\\" cellPadding=\\"0\\" border=\\"0\\" style=\\"max-width:600px\\"><tbody><tr style=\\"width:100%\\"><td align=\\"right\\"><button>Hi</button></td></tr></tbody></table><span><!--[if mso]></td></tr></table><![endif]--></span></div></div>"`; | ||
exports[`<Container> component > renders correctly 1`] = `"<div style=\\"table-layout:fixed;width:100%\\"><div style=\\"margin:0 auto;max-width:300px\\"><span><!--[if mso]><table align=\\"center\\" width=\\"300\\" style=\\"border-spacing: 0; width:300px;\\" role=\\"presentation\\"><tr><td><![endif]--></span><table align=\\"center\\" width=\\"100%\\" role=\\"presentation\\" cellSpacing=\\"0\\" cellPadding=\\"0\\" border=\\"0\\" style=\\"max-width:300px\\"><tbody><tr style=\\"width:100%\\"><td align=\\"center\\"><button>Hi</button></td></tr></tbody></table><span><!--[if mso]></td></tr></table><![endif]--></span></div></div>"`; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`<Row> component > doesn't override cellPadding and cellSpacing 1`] = `"<table align=\\"center\\" width=\\"100%\\" role=\\"presentation\\" cellSpacing=\\"10\\" cellPadding=\\"10\\" border=\\"0\\"><tbody style=\\"width:100%\\"><tr style=\\"width:100%\\"></tr></tbody></table>"`; | ||
exports[`<Row> component > renders correctly 1`] = `"<table align=\\"center\\" width=\\"100%\\" role=\\"presentation\\" cellSpacing=\\"0\\" cellPadding=\\"0\\" border=\\"0\\"><tbody style=\\"width:100%\\"><tr style=\\"width:100%\\"></tr></tbody></table>"`; |
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,3 +1,5 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`<Section> component > doesn't override cellPadding and cellSpacing 1`] = `"<table align=\\"center\\" width=\\"100%\\" border=\\"0\\" cellPadding=\\"10\\" cellSpacing=\\"10\\" role=\\"presentation\\"><tbody><tr><td><td>Lorem ipsum</td></td></tr></tbody></table>"`; | ||
exports[`<Section> component > renders correctly 1`] = `"<table align=\\"center\\" width=\\"100%\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" role=\\"presentation\\"><tbody><tr><td>Lorem ipsum</td></tr></tbody></table>"`; |
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
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.