diff --git a/.changeset/twelve-turkeys-exist.md b/.changeset/twelve-turkeys-exist.md new file mode 100644 index 00000000000..e4e3410ff31 --- /dev/null +++ b/.changeset/twelve-turkeys-exist.md @@ -0,0 +1,5 @@ +--- +'@shopify/polaris-migrator': patch +--- + +Add the (missing) case for migrating DisplayText to Text when size is not specified diff --git a/polaris-migrator/src/migrations/react-replace-text-components/steps/replace-display-text.ts b/polaris-migrator/src/migrations/react-replace-text-components/steps/replace-display-text.ts index ad16491d784..0ead5294fa3 100644 --- a/polaris-migrator/src/migrations/react-replace-text-components/steps/replace-display-text.ts +++ b/polaris-migrator/src/migrations/react-replace-text-components/steps/replace-display-text.ts @@ -21,6 +21,8 @@ const displayTextSizeMap = { extraLarge: 'heading4xl', }; +const defaultDisplayTextSize = 'medium'; + /** * Replace with the component */ @@ -51,6 +53,11 @@ export function replaceDisplayText( 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')) { diff --git a/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.input.tsx b/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.input.tsx index d81f72a0ae2..4ffbdf8ff5e 100644 --- a/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.input.tsx +++ b/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.input.tsx @@ -19,6 +19,7 @@ export function App() { Display text Display text Display text + Display text Display text Heading Heading diff --git a/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.output.tsx b/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.output.tsx index ea1cb7297b2..687a4a9b02d 100644 --- a/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.output.tsx +++ b/polaris-migrator/src/migrations/react-replace-text-components/tests/react-replace-text-components.output.tsx @@ -18,6 +18,9 @@ export function App() { Display text + + Display text + Display text