Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .changeset/twelve-turkeys-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris-migrator': patch
---

Add the (missing) case for migrating DisplayText to Text when size is not specified
2 changes: 1 addition & 1 deletion polaris-migrator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/polaris-migrator",
"version": "0.8.0",
"version": "0.8.1",
"description": "Codemod transformations to help upgrade your Polaris codebase",
"license": "SEE LICENSE IN LICENSE.md",
"author": "Shopify <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const displayTextSizeMap = {
extraLarge: 'heading4xl',
};

const defaultDisplayTextSize = 'medium';

/**
* Replace <DisplayText> with the <Text> component
*/
Expand Down Expand Up @@ -51,6 +53,11 @@ export function replaceDisplayText<NodeType = ASTNode>(

source.findJSXElements(localElementName).forEach((element) => {
replaceJSXElement(j, element, 'Text');

if (!hasJSXAttribute(j, element, 'size')) {
insertJSXAttribute(j, element, 'size', defaultDisplayTextSize);
}

replaceJSXAttributes(j, element, 'size', 'variant', displayTextSizeMap);

if (hasJSXAttribute(j, element, 'element')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function App() {
<DisplayText size="extraLarge">Display text</DisplayText>
<DisplayText size="large">Display text</DisplayText>
<DisplayText size="medium">Display text</DisplayText>
<DisplayText>Display text</DisplayText>
<DisplayText size="small">Display text</DisplayText>
<Heading element="h1">Heading</Heading>
<Heading>Heading</Heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function App() {
<Text variant="headingXl" as="p">
Display text
</Text>
<Text variant="headingXl" as="p">
Display text
</Text>
<Text variant="headingLg" as="p">
Display text
</Text>
Expand Down