@kaizen/components 1.57.1 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/bin/codemod.sh +39 -0
  2. package/codemods/README.md +31 -0
  3. package/codemods/__tests__/utils/index.ts +1 -0
  4. package/codemods/__tests__/utils/parseJsx.ts +11 -0
  5. package/codemods/migrateBrandMomentMoodToVariant/index.ts +21 -0
  6. package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.spec.ts +44 -0
  7. package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.ts +24 -0
  8. package/codemods/migrateCardVariantToColor/index.ts +15 -0
  9. package/codemods/migrateCardVariantToColor/transformCardVariantToColor.spec.ts +91 -0
  10. package/codemods/migrateCardVariantToColor/transformCardVariantToColor.ts +32 -0
  11. package/codemods/migrateConfirmationModalMoodsToVariant/index.ts +19 -0
  12. package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.spec.ts +110 -0
  13. package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.ts +59 -0
  14. package/codemods/migrateEmptyStateIllustrationTypeToVariant/index.ts +21 -0
  15. package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.spec.ts +74 -0
  16. package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.ts +28 -0
  17. package/codemods/migrateGlobalNotificationTypeToVariant/index.ts +19 -0
  18. package/codemods/migrateInformationTileMoodToVariant/index.ts +21 -0
  19. package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.spec.ts +84 -0
  20. package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.ts +22 -0
  21. package/codemods/migrateInlineNotificationTypeToVariant/index.ts +19 -0
  22. package/codemods/migrateMultiActionTileMoodToVariant/index.ts +21 -0
  23. package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.spec.ts +84 -0
  24. package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.ts +22 -0
  25. package/codemods/migrateNotificationTypeToVariant/index.ts +1 -0
  26. package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.spec.ts +107 -0
  27. package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.ts +28 -0
  28. package/codemods/migrateProgressBarMoodToColor/index.ts +21 -0
  29. package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.spec.ts +54 -0
  30. package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.ts +26 -0
  31. package/codemods/migrateToastNotificationTypeToVariant/index.ts +19 -0
  32. package/codemods/migrateWellVariantToColor/index.ts +15 -0
  33. package/codemods/migrateWellVariantToColor/transformWellVariantToColor.spec.ts +192 -0
  34. package/codemods/migrateWellVariantToColor/transformWellVariantToColor.ts +75 -0
  35. package/codemods/removeInputEditModalMood/index.ts +19 -0
  36. package/codemods/removeInputEditModalMood/removeInputEditModalMood.spec.ts +80 -0
  37. package/codemods/removeInputEditModalMood/removeInputEditModalMood.ts +40 -0
  38. package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.spec.ts +118 -0
  39. package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.ts +64 -0
  40. package/codemods/utils/__fixtures__/KaioComponent.tsx +6 -0
  41. package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +11 -0
  42. package/codemods/utils/getPropValueText.spec.ts +75 -0
  43. package/codemods/utils/getPropValueText.ts +21 -0
  44. package/codemods/utils/getTagName.spec.ts +24 -0
  45. package/codemods/utils/getTagName.ts +32 -0
  46. package/codemods/utils/index.ts +7 -0
  47. package/codemods/utils/migrateStringProp.spec.ts +129 -0
  48. package/codemods/utils/migrateStringProp.ts +43 -0
  49. package/codemods/utils/printAst.ts +6 -0
  50. package/codemods/utils/transformComponentsInDir.ts +42 -0
  51. package/codemods/utils/transformSource.spec.ts +56 -0
  52. package/codemods/utils/transformSource.ts +25 -0
  53. package/codemods/utils/updateJsxElementWithNewProps.spec.ts +67 -0
  54. package/codemods/utils/updateJsxElementWithNewProps.ts +24 -0
  55. package/dist/cjs/BrandMoment/BrandMoment.cjs +3 -2
  56. package/dist/cjs/BrandMoment/BrandMoment.module.scss.cjs +3 -1
  57. package/dist/cjs/Card/Card.cjs +7 -6
  58. package/dist/cjs/Card/Card.module.scss.cjs +10 -2
  59. package/dist/cjs/EmptyState/EmptyState.cjs +14 -6
  60. package/dist/cjs/EmptyState/EmptyState.module.scss.cjs +3 -0
  61. package/dist/cjs/ErrorPage/ErrorPage.cjs +1 -1
  62. package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.cjs +9 -5
  63. package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.module.scss.cjs +6 -2
  64. package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs +1 -3
  65. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs +1 -3
  66. package/dist/cjs/Notification/subcomponents/GenericNotification/GenericNotification.cjs +6 -3
  67. package/dist/cjs/Notification/subcomponents/GenericNotification/GenericNotification.module.scss.cjs +5 -3
  68. package/dist/cjs/Notification/subcomponents/NotificationIcon/NotificationIcon.cjs +35 -3
  69. package/dist/cjs/ProgressBar/ProgressBar.cjs +3 -2
  70. package/dist/cjs/ProgressBar/ProgressBar.module.scss.cjs +8 -4
  71. package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.cjs +7 -5
  72. package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.module.scss.cjs +8 -6
  73. package/dist/cjs/Well/Well.cjs +5 -4
  74. package/dist/cjs/Well/Well.module.scss.cjs +9 -1
  75. package/dist/cjs/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.cjs +6 -6
  76. package/dist/cjs/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.cjs +33 -0
  77. package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.cjs +160 -0
  78. package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.cjs +28 -0
  79. package/dist/cjs/containersV1.cjs +4 -0
  80. package/dist/cjs/containersV2.cjs +4 -0
  81. package/dist/cjs/index.cjs +2 -2
  82. package/dist/esm/BrandMoment/BrandMoment.mjs +3 -2
  83. package/dist/esm/BrandMoment/BrandMoment.module.scss.mjs +3 -1
  84. package/dist/esm/Card/Card.mjs +7 -6
  85. package/dist/esm/Card/Card.module.scss.mjs +10 -2
  86. package/dist/esm/EmptyState/EmptyState.mjs +15 -7
  87. package/dist/esm/EmptyState/EmptyState.module.scss.mjs +3 -0
  88. package/dist/esm/ErrorPage/ErrorPage.mjs +1 -1
  89. package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.mjs +9 -5
  90. package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.module.scss.mjs +6 -2
  91. package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs +1 -3
  92. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs +1 -3
  93. package/dist/esm/Notification/subcomponents/GenericNotification/GenericNotification.mjs +8 -5
  94. package/dist/esm/Notification/subcomponents/GenericNotification/GenericNotification.module.scss.mjs +5 -3
  95. package/dist/esm/Notification/subcomponents/NotificationIcon/NotificationIcon.mjs +39 -5
  96. package/dist/esm/ProgressBar/ProgressBar.mjs +3 -2
  97. package/dist/esm/ProgressBar/ProgressBar.module.scss.mjs +8 -4
  98. package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.mjs +7 -5
  99. package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.module.scss.mjs +8 -6
  100. package/dist/esm/Well/Well.mjs +5 -4
  101. package/dist/esm/Well/Well.module.scss.mjs +9 -1
  102. package/dist/esm/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.mjs +6 -6
  103. package/dist/esm/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.mjs +31 -0
  104. package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.mjs +153 -0
  105. package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.mjs +26 -0
  106. package/dist/esm/containersV1.mjs +1 -0
  107. package/dist/esm/containersV2.mjs +1 -0
  108. package/dist/esm/index.mjs +1 -1
  109. package/dist/styles.css +13 -12
  110. package/dist/types/BrandMoment/BrandMoment.d.ts +19 -3
  111. package/dist/types/Card/Card.d.ts +20 -7
  112. package/dist/types/EmptyState/EmptyState.d.ts +14 -6
  113. package/dist/types/Modal/ConfirmationModal/ConfirmationModal.d.ts +25 -7
  114. package/dist/types/Modal/GenericModal/subcomponents/ModalFooter/ModalFooter.d.ts +3 -0
  115. package/dist/types/Modal/InputEditModal/InputEditModal.d.ts +4 -1
  116. package/dist/types/Notification/GlobalNotification/GlobalNotification.d.ts +3 -3
  117. package/dist/types/Notification/InlineNotification/InlineNotification.d.ts +3 -3
  118. package/dist/types/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +5 -4
  119. package/dist/types/Notification/ToastNotification/context/ToastNotificationContext.d.ts +4 -3
  120. package/dist/types/Notification/ToastNotification/types.d.ts +3 -3
  121. package/dist/types/Notification/subcomponents/GenericNotification/GenericNotification.d.ts +24 -4
  122. package/dist/types/Notification/subcomponents/NotificationIcon/NotificationIcon.d.ts +11 -4
  123. package/dist/types/Notification/types.d.ts +2 -1
  124. package/dist/types/ProgressBar/ProgressBar.d.ts +25 -6
  125. package/dist/types/Tile/subcomponents/GenericTile/GenericTile.d.ts +10 -3
  126. package/dist/types/Well/Well.d.ts +6 -2
  127. package/dist/types/Well/types.d.ts +4 -0
  128. package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.d.ts +4 -4
  129. package/dist/types/__containers__/GuidanceBlock/v2/GuidanceBlock.d.ts +59 -0
  130. package/dist/types/__containers__/GuidanceBlock/v2/index.d.ts +1 -0
  131. package/dist/types/__containers__/v1.d.ts +1 -0
  132. package/dist/types/__containers__/v2.d.ts +1 -0
  133. package/dist/types/index.d.ts +1 -1
  134. package/package.json +19 -5
  135. package/src/BrandMoment/BrandMoment.module.scss +20 -9
  136. package/src/BrandMoment/BrandMoment.tsx +26 -3
  137. package/src/BrandMoment/_docs/BrandMoment.mdx +13 -13
  138. package/src/BrandMoment/_docs/BrandMoment.stickersheet.stories.tsx +102 -0
  139. package/src/BrandMoment/_docs/BrandMoment.stories.tsx +17 -99
  140. package/src/Card/Card.module.scss +56 -7
  141. package/src/Card/Card.tsx +35 -11
  142. package/src/Card/_docs/Card.mdx +6 -3
  143. package/src/Card/_docs/Card.stickersheet.stories.tsx +44 -39
  144. package/src/Card/_docs/Card.stories.tsx +23 -23
  145. package/src/EmptyState/EmptyState.module.scss +32 -14
  146. package/src/EmptyState/EmptyState.tsx +32 -18
  147. package/src/EmptyState/_docs/EmptyState.stickersheet.stories.tsx +69 -121
  148. package/src/EmptyState/_docs/EmptyState.stories.tsx +6 -8
  149. package/src/ErrorPage/ErrorPage.tsx +1 -1
  150. package/src/Modal/ConfirmationModal/ConfirmationModal.module.scss +100 -78
  151. package/src/Modal/ConfirmationModal/ConfirmationModal.spec.tsx +5 -5
  152. package/src/Modal/ConfirmationModal/ConfirmationModal.tsx +41 -10
  153. package/src/Modal/ConfirmationModal/_docs/ConfirmationModal.mdx +3 -3
  154. package/src/Modal/ConfirmationModal/_docs/ConfirmationModal.stories.tsx +11 -4
  155. package/src/Modal/ContextModal/_docs/ContextModal.stories.tsx +3 -1
  156. package/src/Modal/GenericModal/subcomponents/ModalFooter/ModalFooter.tsx +3 -0
  157. package/src/Modal/InputEditModal/InputEditModal.tsx +4 -1
  158. package/src/Modal/InputEditModal/_docs/InputEditModal.mdx +0 -13
  159. package/src/Modal/InputEditModal/_docs/InputEditModal.stories.tsx +9 -10
  160. package/src/Notification/GlobalNotification/GlobalNotification.tsx +9 -4
  161. package/src/Notification/GlobalNotification/_docs/GlobalNotification.stickersheet.stories.tsx +68 -58
  162. package/src/Notification/GlobalNotification/_docs/GlobalNotification.stories.tsx +10 -13
  163. package/src/Notification/InlineNotification/InlineNotification.tsx +9 -4
  164. package/src/Notification/InlineNotification/_docs/InlineNotification.stickersheet.stories.tsx +79 -44
  165. package/src/Notification/InlineNotification/_docs/InlineNotification.stories.tsx +17 -17
  166. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.tsx +7 -5
  167. package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.tsx +1 -2
  168. package/src/Notification/ToastNotification/_docs/ToastNotification.stickersheet.stories.tsx +12 -7
  169. package/src/Notification/ToastNotification/_docs/ToastNotification.stories.tsx +6 -1
  170. package/src/Notification/ToastNotification/context/ToastNotificationContext.tsx +7 -3
  171. package/src/Notification/ToastNotification/types.ts +8 -3
  172. package/src/Notification/subcomponents/GenericNotification/GenericNotification.module.scss +42 -5
  173. package/src/Notification/subcomponents/GenericNotification/GenericNotification.tsx +40 -6
  174. package/src/Notification/subcomponents/GenericNotification/_mixins.scss +2 -1
  175. package/src/Notification/subcomponents/NotificationIcon/NotificationIcon.tsx +31 -5
  176. package/src/Notification/types.ts +9 -2
  177. package/src/ProgressBar/ProgressBar.module.scss +37 -25
  178. package/src/ProgressBar/ProgressBar.tsx +30 -5
  179. package/src/ProgressBar/_docs/ProgressBar.mdx +2 -3
  180. package/src/ProgressBar/_docs/ProgressBar.stickersheet.stories.tsx +95 -51
  181. package/src/ProgressBar/_docs/ProgressBar.stories.tsx +56 -25
  182. package/src/Tile/InformationTile/_docs/InformationTile.mdx +3 -2
  183. package/src/Tile/InformationTile/_docs/InformationTile.stickersheet.stories.tsx +57 -19
  184. package/src/Tile/InformationTile/_docs/InformationTile.stories.tsx +19 -7
  185. package/src/Tile/MultiActionTile/_docs/MultiActionTile.mdx +3 -2
  186. package/src/Tile/MultiActionTile/_docs/MultiActionTile.stickersheet.stories.tsx +62 -24
  187. package/src/Tile/MultiActionTile/_docs/MultiActionTile.stories.tsx +19 -7
  188. package/src/Tile/subcomponents/GenericTile/GenericTile.module.scss +34 -22
  189. package/src/Tile/subcomponents/GenericTile/GenericTile.tsx +17 -8
  190. package/src/Tile/subcomponents/GenericTile/_docs/GenericTile.stickersheet.stories.tsx +57 -19
  191. package/src/Well/Well.module.scss +70 -33
  192. package/src/Well/Well.tsx +9 -3
  193. package/src/Well/_docs/Well.mdx +9 -2
  194. package/src/Well/_docs/Well.stickersheet.stories.tsx +10 -1
  195. package/src/Well/_docs/Well.stories.tsx +54 -29
  196. package/src/Well/types.ts +15 -0
  197. package/src/__actions__/Button/v3/_docs/ApiSpecification.mdx +1 -1
  198. package/src/__actions__/Menu/v3/MenuItem.module.scss +1 -0
  199. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.module.scss +2 -2
  200. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.mdx +2 -2
  201. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.stickersheet.stories.tsx +1 -1
  202. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.stories.tsx +1 -1
  203. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss +356 -0
  204. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.spec.tsx +82 -0
  205. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.tsx +262 -0
  206. package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.mdx +38 -0
  207. package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stickersheet.stories.tsx +118 -0
  208. package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stories.tsx +152 -0
  209. package/src/__containers__/GuidanceBlock/v2/index.ts +1 -0
  210. package/src/__containers__/v1.ts +1 -0
  211. package/src/__containers__/v2.ts +1 -0
  212. package/src/index.ts +2 -1
  213. package/v1/containers/package.json +5 -0
  214. package/v2/containers/package.json +5 -0
  215. package/dist/cjs/GuidanceBlock/GuidanceBlock.module.scss.cjs +0 -33
  216. package/dist/esm/GuidanceBlock/GuidanceBlock.module.scss.mjs +0 -31
  217. package/dist/types/Tile/subcomponents/GenericTile/types.d.ts +0 -2
  218. package/src/EmptyState/_docs/EmptyState.stories.module.scss +0 -15
  219. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.spec.tsx +0 -33
  220. package/src/Tile/subcomponents/GenericTile/types.ts +0 -10
  221. /package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/index.d.ts +0 -0
  222. /package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/types.d.ts +0 -0
  223. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.spec.tsx +0 -0
  224. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.tsx +0 -0
  225. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/index.ts +0 -0
  226. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/types.ts +0 -0
package/bin/codemod.sh ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ elapsed_time() {
6
+ echo -e "${GREEN}Built in: ${BOLD}${GREEN}$SECONDS${NC} ${GREEN}seconds${NC}"
7
+ }
8
+
9
+ # Check if the correct number of arguments is provided
10
+ if [ "$#" -ne 2 ]; then
11
+ echo "Usage: $0 transformDir codemodFileName"
12
+ exit 1
13
+ fi
14
+
15
+ # Assign parameters to variables
16
+ transformDir=$1
17
+ codemodFileName=$2
18
+
19
+ # Calculated variables
20
+ BASEPATH=$(pwd "$0")
21
+ SCRIPT=$(realpath "$0")
22
+ SCRIPTPATH=$(dirname "$SCRIPT")
23
+ CODEMOD_PATH="$SCRIPTPATH/../codemods/$codemodFileName/index.ts"
24
+ TARGET_DIR="$BASEPATH/$transformDir"
25
+
26
+ # Print the parameters (for debugging purposes)
27
+ echo ""
28
+ echo "RUNNING - codemod '$codemodFileName' on the dir:"
29
+ echo "$TARGET_DIR"
30
+ echo ""
31
+
32
+ if npx tsx $CODEMOD_PATH $TARGET_DIR; then
33
+ echo "Codemod '$codemodFileName' completed successfully in directory '$transformDir'"
34
+ else
35
+ echo "Codemod '$codemodFileName' could not be run in '$TARGET_DIR'"
36
+ exit 1
37
+ fi
38
+
39
+ elapsed_time
@@ -0,0 +1,31 @@
1
+
2
+ # Kaizen codemods
3
+ This directory is a collection of codemods that can be executed via CLI with the `kaizen-codemod` command.
4
+
5
+ ## Prerequisite
6
+ Install `@kaizen/components`.
7
+
8
+ ## CLI pattern
9
+
10
+ ```
11
+ kaizen-codemod {DIR} {CODEMOD_NAME}
12
+ ```
13
+
14
+ DIR - the directory to run the codemod for. Note that node_modules are excluded.
15
+ CODEMOD_NAME - the name of the codemod (refer to list below).
16
+
17
+ Example:
18
+ ```
19
+ kaizen-codemod src migrateWellVariantToColor
20
+ ```
21
+
22
+ ## Available codemods
23
+ - `migrateBrandMomentMoodToVariant`: Migrates `BrandMoment` component prop from `mood` to `variant`.
24
+ - `migrateEmptyStateIllustrationTypeToVariant`: Migrates `EmptyState` component prop from `illustrationType` to `variant`.
25
+ - `migrateGlobalNotificationTypeToVariant`: Transforms `GlobalNotification`'s `type` prop to the new `variant` prop.
26
+ - `migrateInlineNotificationTypeToVariant`: Transforms `InlineNotification`'s `type` prop to the new `variant` prop.
27
+ - `migrateInformationTileMoodToVariant`: Migrates `InformationTile` component prop from `mood` to `variant`.
28
+ - `migrateMultiActionTileMoodToVariant`: Migrates `MultiActionTile` component prop from `mood` to `variant`.
29
+ - `migrateProgressBarMoodToColor`: Migrates `ProgressBar` component prop from `mood` to `color`
30
+ - `migrateToastNotificationTypeToVariant`: Transforms `ToastNotification`'s `type` prop to the new `variant` prop.
31
+ - `migrateWellVariantToColor`: Migrates `Well` component prop from `variant` to `color`.
@@ -0,0 +1 @@
1
+ export * from "./parseJsx"
@@ -0,0 +1,11 @@
1
+ import ts from "typescript"
2
+
3
+ // This function is used to parse a stringified JSX element into an AST
4
+ export const parseJsx = (jsx: string): ts.SourceFile =>
5
+ ts.createSourceFile(
6
+ "tempFile.tsx",
7
+ jsx,
8
+ ts.ScriptTarget.Latest,
9
+ true,
10
+ ts.ScriptKind.TSX
11
+ )
@@ -0,0 +1,21 @@
1
+ import { transformComponentsInDir } from "../utils"
2
+ import { transformBrandMomentMoodToVariant } from "./transformBrandMomentMoodToVariant"
3
+
4
+ const migrateBrandMomentMoodToVariant = (): void => {
5
+ // eslint-disable-next-line no-console
6
+ console.log(
7
+ " ~(-_- ~) Running BrandMoment mood to variant transformer (~ -_-)~"
8
+ )
9
+ const targetDir = process.argv[2]
10
+ if (!targetDir) {
11
+ process.exit(1)
12
+ }
13
+
14
+ transformComponentsInDir(
15
+ targetDir,
16
+ transformBrandMomentMoodToVariant,
17
+ "BrandMoment"
18
+ )
19
+ }
20
+
21
+ migrateBrandMomentMoodToVariant()
@@ -0,0 +1,44 @@
1
+ import { parseJsx } from "../__tests__/utils"
2
+ import { transformSource, printAst, TransformConfig } from "../utils"
3
+ import { transformBrandMomentMoodToVariant } from "./transformBrandMomentMoodToVariant"
4
+
5
+ const transformBrandMoment = (
6
+ sourceFile: TransformConfig["sourceFile"]
7
+ ): string =>
8
+ transformSource({
9
+ sourceFile,
10
+ astTransformer: transformBrandMomentMoodToVariant,
11
+ tagName: "BrandMoment",
12
+ })
13
+
14
+ describe("transformBrandMomentMoodToVariant()", () => {
15
+ it('replaces mood="informative" with variant="informative"', () => {
16
+ const inputAst = parseJsx(
17
+ 'export const TestComponent = () => <BrandMoment mood="informative" />'
18
+ )
19
+ const outputAst = parseJsx(
20
+ 'export const TestComponent = () => <BrandMoment variant="informative" />'
21
+ )
22
+ expect(transformBrandMoment(inputAst)).toEqual(printAst(outputAst))
23
+ })
24
+
25
+ it('replaces mood="positive" with variant="success"', () => {
26
+ const inputAst = parseJsx(
27
+ 'export const TestComponent = () => <BrandMoment mood="positive" />'
28
+ )
29
+ const outputAst = parseJsx(
30
+ 'export const TestComponent = () => <BrandMoment variant="success" />'
31
+ )
32
+ expect(transformBrandMoment(inputAst)).toEqual(printAst(outputAst))
33
+ })
34
+
35
+ it('replaces mood="negative" with variant="warning"', () => {
36
+ const inputAst = parseJsx(
37
+ 'export const TestComponent = () => <BrandMoment mood="negative" />'
38
+ )
39
+ const outputAst = parseJsx(
40
+ 'export const TestComponent = () => <BrandMoment variant="warning" />'
41
+ )
42
+ expect(transformBrandMoment(inputAst)).toEqual(printAst(outputAst))
43
+ })
44
+ })
@@ -0,0 +1,24 @@
1
+ import type { BrandMomentProps } from "~components/BrandMoment"
2
+ import { migrateStringProp } from "../utils"
3
+
4
+ const OLD_PROP_NAME = "mood"
5
+ const NEW_PROP_NAME = "variant"
6
+
7
+ const getNewVariantValue = (
8
+ oldValue: Exclude<BrandMomentProps[typeof OLD_PROP_NAME], undefined>
9
+ ): Exclude<BrandMomentProps[typeof NEW_PROP_NAME], undefined> => {
10
+ switch (oldValue) {
11
+ case "informative":
12
+ return "informative"
13
+ case "positive":
14
+ return "success"
15
+ case "negative":
16
+ return "warning"
17
+ }
18
+ }
19
+
20
+ export const transformBrandMomentMoodToVariant = migrateStringProp(
21
+ OLD_PROP_NAME,
22
+ NEW_PROP_NAME,
23
+ getNewVariantValue
24
+ )
@@ -0,0 +1,15 @@
1
+ import { transformComponentsInDir } from "../utils"
2
+ import { transformCardVariantToColor } from "./transformCardVariantToColor"
3
+
4
+ const migrateCardVariantToColor = (): void => {
5
+ // eslint-disable-next-line no-console
6
+ console.log(" ~(-_- ~) Running Card variant to color transformer (~ -_-)~")
7
+ const targetDir = process.argv[2]
8
+ if (!targetDir) {
9
+ process.exit(1)
10
+ }
11
+
12
+ transformComponentsInDir(targetDir, transformCardVariantToColor, "Card")
13
+ }
14
+
15
+ migrateCardVariantToColor()
@@ -0,0 +1,91 @@
1
+ import { parseJsx } from "../__tests__/utils"
2
+ import { transformSource, printAst, TransformConfig } from "../utils"
3
+ import { transformCardVariantToColor } from "./transformCardVariantToColor"
4
+
5
+ const transformCard = (sourceFile: TransformConfig["sourceFile"]): string =>
6
+ transformSource({
7
+ sourceFile,
8
+ astTransformer: transformCardVariantToColor,
9
+ tagName: "Card",
10
+ })
11
+
12
+ describe("transformCardVariantToColor()", () => {
13
+ it('replaces variant="assertive" with color="orange"', () => {
14
+ const inputAst = parseJsx(
15
+ 'export const TestComponent = () => <Card variant="assertive">Hello</Card>'
16
+ )
17
+ const outputAst = parseJsx(
18
+ 'export const TestComponent = () => <Card color="orange">Hello</Card>'
19
+ )
20
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
21
+ })
22
+
23
+ it('replaces variant="cautionary" with color="yellow"', () => {
24
+ const inputAst = parseJsx(
25
+ 'export const TestComponent = () => <Card variant="cautionary">Hello</Card>'
26
+ )
27
+ const outputAst = parseJsx(
28
+ 'export const TestComponent = () => <Card color="yellow">Hello</Card>'
29
+ )
30
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
31
+ })
32
+
33
+ it('replaces variant="default" with color="white"', () => {
34
+ const inputAst = parseJsx(
35
+ 'export const TestComponent = () => <Card variant="default">Hello</Card>'
36
+ )
37
+ const outputAst = parseJsx(
38
+ 'export const TestComponent = () => <Card color="white">Hello</Card>'
39
+ )
40
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
41
+ })
42
+
43
+ it('replaces variant="destructive" with color="red"', () => {
44
+ const inputAst = parseJsx(
45
+ 'export const TestComponent = () => <Card variant="destructive">Hello</Card>'
46
+ )
47
+ const outputAst = parseJsx(
48
+ 'export const TestComponent = () => <Card color="red">Hello</Card>'
49
+ )
50
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
51
+ })
52
+
53
+ it('replaces variant="highlight" with color="purple"', () => {
54
+ const inputAst = parseJsx(
55
+ 'export const TestComponent = () => <Card variant="highlight">Hello</Card>'
56
+ )
57
+ const outputAst = parseJsx(
58
+ 'export const TestComponent = () => <Card color="purple">Hello</Card>'
59
+ )
60
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
61
+ })
62
+
63
+ it('replaces variant="informative" with color="blue"', () => {
64
+ const inputAst = parseJsx(
65
+ 'export const TestComponent = () => <Card variant="informative">Hello</Card>'
66
+ )
67
+ const outputAst = parseJsx(
68
+ 'export const TestComponent = () => <Card color="blue">Hello</Card>'
69
+ )
70
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
71
+ })
72
+
73
+ it('replaces variant="positive" with color="green"', () => {
74
+ const inputAst = parseJsx(
75
+ 'export const TestComponent = () => <Card variant="positive">Hello</Card>'
76
+ )
77
+ const outputAst = parseJsx(
78
+ 'export const TestComponent = () => <Card color="green">Hello</Card>'
79
+ )
80
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
81
+ })
82
+ it("If no variant exists, it does not add one", () => {
83
+ const inputAst = parseJsx(
84
+ "export const TestComponent = () => <Card>Hello</Card>"
85
+ )
86
+ const outputAst = parseJsx(
87
+ "export const TestComponent = () => <Card>Hello</Card>"
88
+ )
89
+ expect(transformCard(inputAst)).toEqual(printAst(outputAst))
90
+ })
91
+ })
@@ -0,0 +1,32 @@
1
+ import type { CardProps } from "~components/Card"
2
+ import { migrateStringProp } from "../utils"
3
+
4
+ const OLD_PROP_NAME = "variant"
5
+ const NEW_PROP_NAME = "color"
6
+
7
+ const getNewVariantValue = (
8
+ oldValue: Exclude<CardProps[typeof OLD_PROP_NAME], undefined>
9
+ ): Exclude<CardProps[typeof NEW_PROP_NAME], undefined> => {
10
+ switch (oldValue) {
11
+ case "assertive":
12
+ return "orange"
13
+ case "cautionary":
14
+ return "yellow"
15
+ case "default":
16
+ return "white"
17
+ case "destructive":
18
+ return "red"
19
+ case "highlight":
20
+ return "purple"
21
+ case "informative":
22
+ return "blue"
23
+ case "positive":
24
+ return "green"
25
+ }
26
+ }
27
+
28
+ export const transformCardVariantToColor = migrateStringProp(
29
+ OLD_PROP_NAME,
30
+ NEW_PROP_NAME,
31
+ getNewVariantValue
32
+ )
@@ -0,0 +1,19 @@
1
+ import { transformComponentsInDir } from "../utils"
2
+ import { transformConfirmationModalMoodsToVariant } from "./transformConfirmationModalMoodsToVariant"
3
+ /** This is here as a script runner that migrates Well variant to their color equivalent */
4
+ const migrateModalMoodsToVariant = (): void => {
5
+ // eslint-disable-next-line no-console
6
+ console.log(" ~(-_- ~) Running ConfirmationModal transformer (~ -_-)~")
7
+ const targetDir = process.argv[2]
8
+ if (!targetDir) {
9
+ process.exit(1)
10
+ }
11
+
12
+ transformComponentsInDir(
13
+ targetDir,
14
+ transformConfirmationModalMoodsToVariant,
15
+ "ConfirmationModal"
16
+ )
17
+ }
18
+
19
+ migrateModalMoodsToVariant()
@@ -0,0 +1,110 @@
1
+ import { parseJsx } from "../__tests__/utils"
2
+ import { transformSource, printAst } from "../utils"
3
+ import { transformConfirmationModalMoodsToVariant } from "./transformConfirmationModalMoodsToVariant"
4
+
5
+ describe("transformConfirmationModalMoodsToVariant", () => {
6
+ it('replaces mood="positive" with variant="success"', () => {
7
+ const inputAst = parseJsx(`
8
+ export const TestComponent = () => <ConfirmationModal mood="positive"/>
9
+ `)
10
+ const outputAst = parseJsx(`
11
+ export const TestComponent = () => <ConfirmationModal variant="success"/>
12
+ `)
13
+ const transformed = transformSource({
14
+ sourceFile: inputAst,
15
+ astTransformer: transformConfirmationModalMoodsToVariant,
16
+ tagName: "ConfirmationModal",
17
+ })
18
+ expect(transformed).toEqual(printAst(outputAst))
19
+ })
20
+
21
+ it('replaces mood="negative" with variant="warning"', () => {
22
+ const inputAst = parseJsx(`
23
+ export const TestComponent = () => <ConfirmationModal mood="negative"/>
24
+ `)
25
+ const outputAst = parseJsx(`
26
+ export const TestComponent = () => <ConfirmationModal variant="warning"/>
27
+ `)
28
+ const transformed = transformSource({
29
+ sourceFile: inputAst,
30
+ astTransformer: transformConfirmationModalMoodsToVariant,
31
+ tagName: "ConfirmationModal",
32
+ })
33
+ expect(transformed).toEqual(printAst(outputAst))
34
+ })
35
+
36
+ it("handles multiple attributes and replace only variant", () => {
37
+ const inputAst = parseJsx(`
38
+ export const TestComponent = () => <ConfirmationModal mood="negative" id="123"/>
39
+ `)
40
+ const outputAst = parseJsx(`
41
+ export const TestComponent = () => <ConfirmationModal variant="warning" id="123"/>
42
+ `)
43
+ const transformed = transformSource({
44
+ sourceFile: inputAst,
45
+ astTransformer: transformConfirmationModalMoodsToVariant,
46
+ tagName: "ConfirmationModal",
47
+ })
48
+ expect(transformed).toBe(printAst(outputAst))
49
+ })
50
+
51
+ it("transforms multiple ConfirmationModals", () => {
52
+ const inputAst = parseJsx(`
53
+ export const TestComponent = () => <div><ConfirmationModal mood="positive"/><ConfirmationModal mood="negative"/></div>
54
+ `)
55
+ const outputAst = parseJsx(`
56
+ export const TestComponent = () => <div><ConfirmationModal variant="success"/><ConfirmationModal variant="warning"/></div>
57
+ `)
58
+ const transformed = transformSource({
59
+ sourceFile: inputAst,
60
+ astTransformer: transformConfirmationModalMoodsToVariant,
61
+ tagName: "ConfirmationModal",
62
+ })
63
+ expect(transformed).toBe(printAst(outputAst))
64
+ })
65
+
66
+ it("transforms ConfirmationModal with arbitrary braces", () => {
67
+ const inputAst = parseJsx(`
68
+ export const TestComponent = () => <div><ConfirmationModal mood={"positive"}/><ConfirmationModal mood={'assertive'}/><ConfirmationModal mood={\`positive\`}/></div>
69
+ `)
70
+ const outputAst = parseJsx(`
71
+ export const TestComponent = () => <div><ConfirmationModal variant="success"/><ConfirmationModal variant="cautionary"/><ConfirmationModal variant="success"/></div>
72
+ `)
73
+ const transformed = transformSource({
74
+ sourceFile: inputAst,
75
+ astTransformer: transformConfirmationModalMoodsToVariant,
76
+ tagName: "ConfirmationModal",
77
+ })
78
+ expect(transformed).toBe(printAst(outputAst))
79
+ })
80
+
81
+ it("won't add variant if variant already exists", () => {
82
+ const inputAst = parseJsx(`
83
+ export const TestComponent = () => <div><ConfirmationModal variant="success"/></div>
84
+ `)
85
+ const outputAst = parseJsx(`
86
+ export const TestComponent = () => <div><ConfirmationModal variant="success"/></div>
87
+ `)
88
+ const transformed = transformSource({
89
+ sourceFile: inputAst,
90
+ astTransformer: transformConfirmationModalMoodsToVariant,
91
+ tagName: "ConfirmationModal",
92
+ })
93
+ expect(transformed).toBe(printAst(outputAst))
94
+ })
95
+
96
+ it("won't modify variants usings variables", () => {
97
+ const inputAst = parseJsx(`
98
+ export const TestComponent = () => <div><ConfirmationModal variant={confirmationModalVariable}/></div>
99
+ `)
100
+ const outputAst = parseJsx(`
101
+ export const TestComponent = () => <div><ConfirmationModal variant={confirmationModalVariable}/></div>
102
+ `)
103
+ const transformed = transformSource({
104
+ sourceFile: inputAst,
105
+ astTransformer: transformConfirmationModalMoodsToVariant,
106
+ tagName: "ConfirmationModal",
107
+ })
108
+ expect(transformed).toBe(printAst(outputAst))
109
+ })
110
+ })
@@ -0,0 +1,59 @@
1
+ import ts from "typescript"
2
+ import { getPropValueText } from "../utils/getPropValueText"
3
+
4
+ /** Recurses through AST to find and update any jsx element that matched the tagName */
5
+ export const transformConfirmationModalMoodsToVariant =
6
+ (context: ts.TransformationContext, tagName: string) =>
7
+ (rootNode: ts.Node): ts.Node => {
8
+ function visit(node: ts.Node): ts.Node {
9
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
10
+ if (node.tagName.getText() === tagName) {
11
+ const newAttributes = node.attributes.properties.map(attr => {
12
+ if (ts.isJsxAttribute(attr) && attr.name.getText() === "mood") {
13
+ const valueName =
14
+ attr.initializer && getPropValueText(attr.initializer)
15
+
16
+ if (valueName) {
17
+ let variantValue: string = ""
18
+ switch (valueName) {
19
+ case "positive":
20
+ variantValue = "success"
21
+ break
22
+ case "negative":
23
+ variantValue = "warning"
24
+ break
25
+ case "assertive":
26
+ variantValue = "cautionary"
27
+ break
28
+ }
29
+ return ts.factory.createJsxAttribute(
30
+ ts.factory.createIdentifier("variant"),
31
+ ts.factory.createStringLiteral(variantValue)
32
+ )
33
+ }
34
+ }
35
+
36
+ return attr
37
+ })
38
+
39
+ if (ts.isJsxOpeningElement(node)) {
40
+ return ts.factory.updateJsxOpeningElement(
41
+ node,
42
+ node.tagName,
43
+ node.typeArguments,
44
+ ts.factory.createJsxAttributes(newAttributes)
45
+ )
46
+ } else if (ts.isJsxSelfClosingElement(node)) {
47
+ return ts.factory.updateJsxSelfClosingElement(
48
+ node,
49
+ node.tagName,
50
+ node.typeArguments,
51
+ ts.factory.createJsxAttributes(newAttributes)
52
+ )
53
+ }
54
+ }
55
+ }
56
+ return ts.visitEachChild(node, visit, context)
57
+ }
58
+ return ts.visitNode(rootNode, visit)
59
+ }
@@ -0,0 +1,21 @@
1
+ import { transformComponentsInDir } from "../utils"
2
+ import { transformEmptyStateIllustrationTypeToVariant } from "./transformEmptyStateIllustrationTypeToVariant"
3
+
4
+ const migrateEmptyStateIllustrationTypeToVariant = (): void => {
5
+ // eslint-disable-next-line no-console
6
+ console.log(
7
+ " ~(-_- ~) Running EmptyState illustrationType to variant transformer (~ -_-)~"
8
+ )
9
+ const targetDir = process.argv[2]
10
+ if (!targetDir) {
11
+ process.exit(1)
12
+ }
13
+
14
+ transformComponentsInDir(
15
+ targetDir,
16
+ transformEmptyStateIllustrationTypeToVariant,
17
+ "EmptyState"
18
+ )
19
+ }
20
+
21
+ migrateEmptyStateIllustrationTypeToVariant()
@@ -0,0 +1,74 @@
1
+ import { parseJsx } from "../__tests__/utils"
2
+ import { transformSource, printAst, TransformConfig } from "../utils"
3
+ import { transformEmptyStateIllustrationTypeToVariant } from "./transformEmptyStateIllustrationTypeToVariant"
4
+
5
+ const transformEmptyState = (
6
+ sourceFile: TransformConfig["sourceFile"]
7
+ ): string =>
8
+ transformSource({
9
+ sourceFile,
10
+ astTransformer: transformEmptyStateIllustrationTypeToVariant,
11
+ tagName: "EmptyState",
12
+ })
13
+
14
+ describe("transformEmptyStateIllustrationTypeToVariant()", () => {
15
+ it('replaces illustrationType="positive" with variant="success"', () => {
16
+ const inputAst = parseJsx(
17
+ 'export const TestComponent = () => <EmptyState illustrationType="positive">Hello</EmptyState>'
18
+ )
19
+ const outputAst = parseJsx(
20
+ 'export const TestComponent = () => <EmptyState variant="success">Hello</EmptyState>'
21
+ )
22
+ expect(transformEmptyState(inputAst)).toEqual(printAst(outputAst))
23
+ })
24
+
25
+ it('replaces illustrationType="informative" with variant="informative"', () => {
26
+ const inputAst = parseJsx(
27
+ 'export const TestComponent = () => <EmptyState illustrationType="informative">Hello</EmptyState>'
28
+ )
29
+ const outputAst = parseJsx(
30
+ 'export const TestComponent = () => <EmptyState variant="informative">Hello</EmptyState>'
31
+ )
32
+ expect(transformEmptyState(inputAst)).toEqual(printAst(outputAst))
33
+ })
34
+
35
+ it('replaces illustrationType="negative" with variant="warning"', () => {
36
+ const inputAst = parseJsx(
37
+ 'export const TestComponent = () => <EmptyState illustrationType="negative">Hello</EmptyState>'
38
+ )
39
+ const outputAst = parseJsx(
40
+ 'export const TestComponent = () => <EmptyState variant="warning">Hello</EmptyState>'
41
+ )
42
+ expect(transformEmptyState(inputAst)).toEqual(printAst(outputAst))
43
+ })
44
+
45
+ it('replaces illustrationType="action" with variant="warning"', () => {
46
+ const inputAst = parseJsx(
47
+ 'export const TestComponent = () => <EmptyState illustrationType="action">Hello</EmptyState>'
48
+ )
49
+ const outputAst = parseJsx(
50
+ 'export const TestComponent = () => <EmptyState variant="warning">Hello</EmptyState>'
51
+ )
52
+ expect(transformEmptyState(inputAst)).toEqual(printAst(outputAst))
53
+ })
54
+
55
+ it('replaces illustrationType="neutral" with variant="expert-advice"', () => {
56
+ const inputAst = parseJsx(
57
+ 'export const TestComponent = () => <EmptyState illustrationType="neutral">Hello</EmptyState>'
58
+ )
59
+ const outputAst = parseJsx(
60
+ 'export const TestComponent = () => <EmptyState variant="expert-advice">Hello</EmptyState>'
61
+ )
62
+ expect(transformEmptyState(inputAst)).toEqual(printAst(outputAst))
63
+ })
64
+
65
+ it("does not add variant if illustrationType was not defined", () => {
66
+ const inputAst = parseJsx(
67
+ "export const TestComponent = () => <EmptyState>Hello</EmptyState>"
68
+ )
69
+ const outputAst = parseJsx(
70
+ "export const TestComponent = () => <EmptyState>Hello</EmptyState>"
71
+ )
72
+ expect(transformEmptyState(inputAst)).toEqual(printAst(outputAst))
73
+ })
74
+ })
@@ -0,0 +1,28 @@
1
+ import type { EmptyStateProps } from "~components/EmptyState"
2
+ import { migrateStringProp } from "../utils"
3
+
4
+ const OLD_PROP_NAME = "illustrationType"
5
+ const NEW_PROP_NAME = "variant"
6
+
7
+ const getNewVariantValue = (
8
+ oldValue: Exclude<EmptyStateProps[typeof OLD_PROP_NAME], undefined>
9
+ ): Exclude<EmptyStateProps[typeof NEW_PROP_NAME], undefined> => {
10
+ switch (oldValue) {
11
+ case "informative":
12
+ return "informative"
13
+ case "positive":
14
+ return "success"
15
+ case "negative":
16
+ return "warning"
17
+ case "action":
18
+ return "warning"
19
+ case "neutral":
20
+ return "expert-advice"
21
+ }
22
+ }
23
+
24
+ export const transformEmptyStateIllustrationTypeToVariant = migrateStringProp(
25
+ OLD_PROP_NAME,
26
+ NEW_PROP_NAME,
27
+ getNewVariantValue
28
+ )
@@ -0,0 +1,19 @@
1
+ import { transformNotificationTypeToVariant } from "../migrateNotificationTypeToVariant"
2
+ import { transformComponentsInDir } from "../utils"
3
+ /** This is here as a script runner that migrates GlobalNotification variant to their color equivalent */
4
+ const migrateGlobalNotificationTypeToVariant = (): void => {
5
+ // eslint-disable-next-line no-console
6
+ console.log(" ~(-_- ~) Running GlobalNotification transformer (~ -_-)~")
7
+ const targetDir = process.argv[2]
8
+ if (!targetDir) {
9
+ process.exit(1)
10
+ }
11
+
12
+ transformComponentsInDir(
13
+ targetDir,
14
+ transformNotificationTypeToVariant,
15
+ "GlobalNotification"
16
+ )
17
+ }
18
+
19
+ migrateGlobalNotificationTypeToVariant()