@kaizen/components 1.57.2 → 1.58.1

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 (232) 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 +135 -0
  39. package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.ts +77 -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/Icon/subcomponents/SVG/SVG.cjs +2 -3
  63. package/dist/cjs/Illustration/subcomponents/VideoPlayer/VideoPlayer.cjs +1 -1
  64. package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.cjs +9 -5
  65. package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.module.scss.cjs +6 -2
  66. package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs +1 -3
  67. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs +1 -3
  68. package/dist/cjs/Notification/subcomponents/GenericNotification/GenericNotification.cjs +6 -3
  69. package/dist/cjs/Notification/subcomponents/GenericNotification/GenericNotification.module.scss.cjs +5 -3
  70. package/dist/cjs/Notification/subcomponents/NotificationIcon/NotificationIcon.cjs +35 -3
  71. package/dist/cjs/ProgressBar/ProgressBar.cjs +3 -2
  72. package/dist/cjs/ProgressBar/ProgressBar.module.scss.cjs +8 -4
  73. package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.cjs +7 -5
  74. package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.module.scss.cjs +8 -6
  75. package/dist/cjs/Well/Well.cjs +5 -4
  76. package/dist/cjs/Well/Well.module.scss.cjs +9 -1
  77. package/dist/cjs/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.cjs +6 -6
  78. package/dist/cjs/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.cjs +33 -0
  79. package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.cjs +160 -0
  80. package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.cjs +28 -0
  81. package/dist/cjs/containersV1.cjs +4 -0
  82. package/dist/cjs/containersV2.cjs +4 -0
  83. package/dist/cjs/index.cjs +2 -2
  84. package/dist/esm/BrandMoment/BrandMoment.mjs +3 -2
  85. package/dist/esm/BrandMoment/BrandMoment.module.scss.mjs +3 -1
  86. package/dist/esm/Card/Card.mjs +7 -6
  87. package/dist/esm/Card/Card.module.scss.mjs +10 -2
  88. package/dist/esm/EmptyState/EmptyState.mjs +15 -7
  89. package/dist/esm/EmptyState/EmptyState.module.scss.mjs +3 -0
  90. package/dist/esm/ErrorPage/ErrorPage.mjs +1 -1
  91. package/dist/esm/Icon/subcomponents/SVG/SVG.mjs +2 -3
  92. package/dist/esm/Illustration/subcomponents/VideoPlayer/VideoPlayer.mjs +1 -1
  93. package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.mjs +9 -5
  94. package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.module.scss.mjs +6 -2
  95. package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs +1 -3
  96. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs +1 -3
  97. package/dist/esm/Notification/subcomponents/GenericNotification/GenericNotification.mjs +8 -5
  98. package/dist/esm/Notification/subcomponents/GenericNotification/GenericNotification.module.scss.mjs +5 -3
  99. package/dist/esm/Notification/subcomponents/NotificationIcon/NotificationIcon.mjs +39 -5
  100. package/dist/esm/ProgressBar/ProgressBar.mjs +3 -2
  101. package/dist/esm/ProgressBar/ProgressBar.module.scss.mjs +8 -4
  102. package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.mjs +7 -5
  103. package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.module.scss.mjs +8 -6
  104. package/dist/esm/Well/Well.mjs +5 -4
  105. package/dist/esm/Well/Well.module.scss.mjs +9 -1
  106. package/dist/esm/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.mjs +6 -6
  107. package/dist/esm/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.mjs +31 -0
  108. package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.mjs +153 -0
  109. package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.mjs +26 -0
  110. package/dist/esm/containersV1.mjs +1 -0
  111. package/dist/esm/containersV2.mjs +1 -0
  112. package/dist/esm/index.mjs +1 -1
  113. package/dist/styles.css +13 -12
  114. package/dist/types/BrandMoment/BrandMoment.d.ts +19 -3
  115. package/dist/types/Card/Card.d.ts +20 -7
  116. package/dist/types/EmptyState/EmptyState.d.ts +14 -6
  117. package/dist/types/Icon/subcomponents/SVG/SVG.d.ts +1 -2
  118. package/dist/types/Modal/ConfirmationModal/ConfirmationModal.d.ts +25 -7
  119. package/dist/types/Modal/GenericModal/subcomponents/ModalFooter/ModalFooter.d.ts +3 -0
  120. package/dist/types/Modal/InputEditModal/InputEditModal.d.ts +4 -1
  121. package/dist/types/Notification/GlobalNotification/GlobalNotification.d.ts +3 -3
  122. package/dist/types/Notification/InlineNotification/InlineNotification.d.ts +3 -3
  123. package/dist/types/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +5 -4
  124. package/dist/types/Notification/ToastNotification/context/ToastNotificationContext.d.ts +4 -3
  125. package/dist/types/Notification/ToastNotification/types.d.ts +3 -3
  126. package/dist/types/Notification/subcomponents/GenericNotification/GenericNotification.d.ts +24 -4
  127. package/dist/types/Notification/subcomponents/NotificationIcon/NotificationIcon.d.ts +11 -4
  128. package/dist/types/Notification/types.d.ts +2 -1
  129. package/dist/types/ProgressBar/ProgressBar.d.ts +25 -6
  130. package/dist/types/Tile/subcomponents/GenericTile/GenericTile.d.ts +10 -3
  131. package/dist/types/Well/Well.d.ts +6 -2
  132. package/dist/types/Well/types.d.ts +4 -0
  133. package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.d.ts +4 -4
  134. package/dist/types/__containers__/GuidanceBlock/v2/GuidanceBlock.d.ts +59 -0
  135. package/dist/types/__containers__/GuidanceBlock/v2/index.d.ts +1 -0
  136. package/dist/types/__containers__/v1.d.ts +1 -0
  137. package/dist/types/__containers__/v2.d.ts +1 -0
  138. package/dist/types/index.d.ts +1 -1
  139. package/package.json +28 -13
  140. package/src/BrandMoment/BrandMoment.module.scss +20 -9
  141. package/src/BrandMoment/BrandMoment.tsx +26 -3
  142. package/src/BrandMoment/_docs/BrandMoment.mdx +13 -13
  143. package/src/BrandMoment/_docs/BrandMoment.stickersheet.stories.tsx +102 -0
  144. package/src/BrandMoment/_docs/BrandMoment.stories.tsx +17 -99
  145. package/src/Card/Card.module.scss +56 -7
  146. package/src/Card/Card.tsx +35 -11
  147. package/src/Card/_docs/Card.mdx +6 -3
  148. package/src/Card/_docs/Card.stickersheet.stories.tsx +44 -39
  149. package/src/Card/_docs/Card.stories.tsx +23 -23
  150. package/src/EmptyState/EmptyState.module.scss +32 -14
  151. package/src/EmptyState/EmptyState.tsx +32 -18
  152. package/src/EmptyState/_docs/EmptyState.stickersheet.stories.tsx +69 -121
  153. package/src/EmptyState/_docs/EmptyState.stories.tsx +6 -8
  154. package/src/ErrorPage/ErrorPage.tsx +1 -1
  155. package/src/Icon/subcomponents/SVG/SVG.tsx +1 -4
  156. package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.tsx +1 -1
  157. package/src/Modal/ConfirmationModal/ConfirmationModal.module.scss +100 -78
  158. package/src/Modal/ConfirmationModal/ConfirmationModal.spec.tsx +5 -5
  159. package/src/Modal/ConfirmationModal/ConfirmationModal.tsx +41 -10
  160. package/src/Modal/ConfirmationModal/_docs/ConfirmationModal.mdx +3 -3
  161. package/src/Modal/ConfirmationModal/_docs/ConfirmationModal.stories.tsx +11 -4
  162. package/src/Modal/ContextModal/_docs/ContextModal.stories.tsx +3 -1
  163. package/src/Modal/GenericModal/subcomponents/ModalFooter/ModalFooter.tsx +3 -0
  164. package/src/Modal/InputEditModal/InputEditModal.tsx +4 -1
  165. package/src/Modal/InputEditModal/_docs/InputEditModal.mdx +0 -13
  166. package/src/Modal/InputEditModal/_docs/InputEditModal.stories.tsx +9 -10
  167. package/src/Notification/GlobalNotification/GlobalNotification.tsx +9 -4
  168. package/src/Notification/GlobalNotification/_docs/GlobalNotification.stickersheet.stories.tsx +68 -58
  169. package/src/Notification/GlobalNotification/_docs/GlobalNotification.stories.tsx +10 -13
  170. package/src/Notification/InlineNotification/InlineNotification.tsx +9 -4
  171. package/src/Notification/InlineNotification/_docs/InlineNotification.stickersheet.stories.tsx +79 -44
  172. package/src/Notification/InlineNotification/_docs/InlineNotification.stories.tsx +17 -17
  173. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.tsx +7 -5
  174. package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.tsx +1 -2
  175. package/src/Notification/ToastNotification/_docs/ToastNotification.stickersheet.stories.tsx +12 -7
  176. package/src/Notification/ToastNotification/_docs/ToastNotification.stories.tsx +6 -1
  177. package/src/Notification/ToastNotification/context/ToastNotificationContext.tsx +7 -3
  178. package/src/Notification/ToastNotification/types.ts +8 -3
  179. package/src/Notification/subcomponents/GenericNotification/GenericNotification.module.scss +42 -5
  180. package/src/Notification/subcomponents/GenericNotification/GenericNotification.tsx +40 -6
  181. package/src/Notification/subcomponents/GenericNotification/_mixins.scss +2 -1
  182. package/src/Notification/subcomponents/NotificationIcon/NotificationIcon.tsx +31 -5
  183. package/src/Notification/types.ts +9 -2
  184. package/src/ProgressBar/ProgressBar.module.scss +37 -25
  185. package/src/ProgressBar/ProgressBar.tsx +30 -5
  186. package/src/ProgressBar/_docs/ProgressBar.mdx +2 -3
  187. package/src/ProgressBar/_docs/ProgressBar.stickersheet.stories.tsx +95 -51
  188. package/src/ProgressBar/_docs/ProgressBar.stories.tsx +56 -25
  189. package/src/Tile/InformationTile/_docs/InformationTile.mdx +3 -2
  190. package/src/Tile/InformationTile/_docs/InformationTile.stickersheet.stories.tsx +57 -19
  191. package/src/Tile/InformationTile/_docs/InformationTile.stories.tsx +19 -7
  192. package/src/Tile/MultiActionTile/_docs/MultiActionTile.mdx +3 -2
  193. package/src/Tile/MultiActionTile/_docs/MultiActionTile.stickersheet.stories.tsx +62 -24
  194. package/src/Tile/MultiActionTile/_docs/MultiActionTile.stories.tsx +19 -7
  195. package/src/Tile/subcomponents/GenericTile/GenericTile.module.scss +34 -22
  196. package/src/Tile/subcomponents/GenericTile/GenericTile.tsx +17 -8
  197. package/src/Tile/subcomponents/GenericTile/_docs/GenericTile.stickersheet.stories.tsx +57 -19
  198. package/src/Well/Well.module.scss +70 -33
  199. package/src/Well/Well.tsx +9 -3
  200. package/src/Well/_docs/Well.mdx +9 -2
  201. package/src/Well/_docs/Well.stickersheet.stories.tsx +10 -1
  202. package/src/Well/_docs/Well.stories.tsx +54 -29
  203. package/src/Well/types.ts +15 -0
  204. package/src/__actions__/Button/v3/_docs/ApiSpecification.mdx +1 -1
  205. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.module.scss +2 -2
  206. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.mdx +2 -2
  207. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.stickersheet.stories.tsx +1 -1
  208. package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.stories.tsx +1 -1
  209. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss +356 -0
  210. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.spec.tsx +82 -0
  211. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.tsx +262 -0
  212. package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.mdx +38 -0
  213. package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stickersheet.stories.tsx +118 -0
  214. package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stories.tsx +152 -0
  215. package/src/__containers__/GuidanceBlock/v2/index.ts +1 -0
  216. package/src/__containers__/v1.ts +1 -0
  217. package/src/__containers__/v2.ts +1 -0
  218. package/src/index.ts +2 -1
  219. package/v1/containers/package.json +5 -0
  220. package/v2/containers/package.json +5 -0
  221. package/dist/cjs/GuidanceBlock/GuidanceBlock.module.scss.cjs +0 -33
  222. package/dist/esm/GuidanceBlock/GuidanceBlock.module.scss.mjs +0 -31
  223. package/dist/types/Tile/subcomponents/GenericTile/types.d.ts +0 -2
  224. package/src/EmptyState/_docs/EmptyState.stories.module.scss +0 -15
  225. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.spec.tsx +0 -33
  226. package/src/Tile/subcomponents/GenericTile/types.ts +0 -10
  227. /package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/index.d.ts +0 -0
  228. /package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/types.d.ts +0 -0
  229. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.spec.tsx +0 -0
  230. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.tsx +0 -0
  231. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/index.ts +0 -0
  232. /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/types.ts +0 -0
@@ -0,0 +1,75 @@
1
+ import ts from "typescript"
2
+ import { parseJsx } from "../__tests__/utils"
3
+ import { getPropValueText } from "./getPropValueText"
4
+
5
+ export const getJsxAttributeValue = (
6
+ node: ts.Node
7
+ ): ts.JsxAttributeValue | undefined => {
8
+ const visitNode = (
9
+ visitedNode: ts.Node
10
+ ): ts.JsxAttributeValue | undefined => {
11
+ if (ts.isJsxAttribute(visitedNode)) {
12
+ return visitedNode.initializer
13
+ }
14
+
15
+ return visitedNode.forEachChild(visitNode)
16
+ }
17
+
18
+ return visitNode(node)
19
+ }
20
+
21
+ describe("getPropValueText", () => {
22
+ it("will return the text value of a string literal", () => {
23
+ const pancakeAst = parseJsx('<Pancake topping="jam" />')
24
+ const mockAttribute = getJsxAttributeValue(
25
+ pancakeAst
26
+ ) as ts.JsxAttributeValue
27
+
28
+ expect(getPropValueText(mockAttribute)).toEqual("jam")
29
+ })
30
+
31
+ it("will return the text value of a expression with double quotes", () => {
32
+ const pancakeAst = parseJsx('<Pancake topping={"jam"} />')
33
+ const mockAttribute = getJsxAttributeValue(
34
+ pancakeAst
35
+ ) as ts.JsxAttributeValue
36
+
37
+ expect(getPropValueText(mockAttribute)).toEqual("jam")
38
+ })
39
+
40
+ it("will return the text value of a expression with single quotes", () => {
41
+ const pancakeAst = parseJsx("<Pancake topping={'jam'} />")
42
+ const mockAttribute = getJsxAttributeValue(
43
+ pancakeAst
44
+ ) as ts.JsxAttributeValue
45
+
46
+ expect(getPropValueText(mockAttribute)).toEqual("jam")
47
+ })
48
+
49
+ it("will return the text value of a expression with backticks", () => {
50
+ const pancakeAst = parseJsx("<Pancake topping={`jam`} />")
51
+ const mockAttribute = getJsxAttributeValue(
52
+ pancakeAst
53
+ ) as ts.JsxAttributeValue
54
+
55
+ expect(getPropValueText(mockAttribute)).toEqual("jam")
56
+ })
57
+
58
+ it("will return undefined if a JSX element is used as a value", () => {
59
+ const pancakeAst = parseJsx("<Pancake topping={<Cheese />} />")
60
+ const mockAttribute = getJsxAttributeValue(
61
+ pancakeAst
62
+ ) as ts.JsxAttributeValue
63
+
64
+ expect(getPropValueText(mockAttribute)).toBeUndefined()
65
+ })
66
+
67
+ it("will return undefined if a boolean value", () => {
68
+ const pancakeAst = parseJsx("<Pancake topping={false} />")
69
+ const mockAttribute = getJsxAttributeValue(
70
+ pancakeAst
71
+ ) as ts.JsxAttributeValue
72
+
73
+ expect(getPropValueText(mockAttribute)).toBeUndefined()
74
+ })
75
+ })
@@ -0,0 +1,21 @@
1
+ import ts from "typescript"
2
+
3
+ /** a helper function to get prop's value text from a JSX attribute */
4
+ export const getPropValueText = (
5
+ propValue: ts.JsxAttributeValue
6
+ ): string | undefined => {
7
+ if (ts.isStringLiteral(propValue)) {
8
+ return propValue.text
9
+ }
10
+
11
+ const expression = ts.isJsxExpression(propValue) && propValue.expression
12
+
13
+ if (expression) {
14
+ const expressionText = expression.getText()
15
+
16
+ if (expressionText.match(/^['"`]/)) {
17
+ return expressionText.replace(/^['"`]|['"`]$/g, "")
18
+ }
19
+ }
20
+ return undefined
21
+ }
@@ -0,0 +1,24 @@
1
+ import { parseJsx } from "../__tests__/utils"
2
+ import { getTagName } from "./getTagName"
3
+
4
+ describe("getTagName", () => {
5
+ it("returns the import name if it matches the target specifier", () => {
6
+ const input = parseJsx('import { Well } from "@kaizen/components"')
7
+ const tagName = getTagName(input, "Well")
8
+ expect(tagName).toBe("Well")
9
+ })
10
+
11
+ it("returns the import alias if it matches the target specifier", () => {
12
+ const input = parseJsx(
13
+ 'import { Well as KaizenWell } from "@kaizen/components"'
14
+ )
15
+ const tagName = getTagName(input, "Well")
16
+ expect(tagName).toBe("KaizenWell")
17
+ })
18
+
19
+ it("returns undefined if there is no match to the target specifier", () => {
20
+ const input = parseJsx('import { Well } from "@kaizen/well"')
21
+ const tagName = getTagName(input, "Well")
22
+ expect(tagName).toBe(undefined)
23
+ })
24
+ })
@@ -0,0 +1,32 @@
1
+ import ts from "typescript"
2
+
3
+ /** Recurses through AST to find the import specifier name and check it against the `importSpecifierTarget`. If found, it will return the import name or alias, otherwise will return `undefined` */
4
+ export const getTagName = (
5
+ node: ts.Node,
6
+ importSpecifierTarget: string
7
+ ): string | undefined => {
8
+ let alias: string | undefined
9
+
10
+ const visitNode = (visitedNode: ts.Node): string | undefined => {
11
+ if (ts.isImportDeclaration(visitedNode)) {
12
+ const moduleSpecifier = visitedNode.moduleSpecifier.getText()
13
+ if (moduleSpecifier.includes("@kaizen/components")) {
14
+ const namedBindings = visitedNode.importClause?.namedBindings
15
+ if (namedBindings && ts.isNamedImports(namedBindings)) {
16
+ namedBindings.elements.forEach(importSpecifier => {
17
+ const importName = importSpecifier.name.getText()
18
+ const tagName = importSpecifier.propertyName
19
+ ? importSpecifier.propertyName.getText()
20
+ : importName
21
+ if (tagName === importSpecifierTarget) {
22
+ alias = importName
23
+ }
24
+ })
25
+ }
26
+ }
27
+ }
28
+ return alias || ts.forEachChild(visitedNode, visitNode) || undefined
29
+ }
30
+
31
+ return visitNode(node)
32
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./getPropValueText"
2
+ export * from "./getTagName"
3
+ export * from "./migrateStringProp"
4
+ export * from "./printAst"
5
+ export * from "./transformComponentsInDir"
6
+ export * from "./transformSource"
7
+ export * from "./updateJsxElementWithNewProps"
@@ -0,0 +1,129 @@
1
+ import { parseJsx } from "../__tests__/utils"
2
+ import { transformSource, printAst, TransformConfig } from "../utils"
3
+ import { migrateStringProp } from "./migrateStringProp"
4
+
5
+ const transformTopping = (oldValue: string): string => {
6
+ switch (oldValue) {
7
+ case "butter":
8
+ return "jam"
9
+ default:
10
+ return "blueberries"
11
+ }
12
+ }
13
+
14
+ const testMigrateStringProp = (
15
+ sourceFile: TransformConfig["sourceFile"]
16
+ ): string =>
17
+ transformSource({
18
+ sourceFile,
19
+ astTransformer: migrateStringProp(
20
+ "toppingOld",
21
+ "toppingNew",
22
+ transformTopping
23
+ ),
24
+ tagName: "Pancakes",
25
+ })
26
+
27
+ describe("migrateStringProp()", () => {
28
+ describe("replaces old prop name and value with new prop name and value", () => {
29
+ it("applies to self closing elements", () => {
30
+ const inputAst = parseJsx(
31
+ 'export const TestComponent = () => <Pancakes toppingOld="butter" />'
32
+ )
33
+ const outputAst = parseJsx(
34
+ 'export const TestComponent = () => <Pancakes toppingNew="jam" />'
35
+ )
36
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
37
+ })
38
+
39
+ it("applies to JSX opening elements", () => {
40
+ const inputAst = parseJsx(
41
+ 'export const TestComponent = () => <Pancakes toppingOld="butter">Hello</Pancakes>'
42
+ )
43
+ const outputAst = parseJsx(
44
+ 'export const TestComponent = () => <Pancakes toppingNew="jam">Hello</Pancakes>'
45
+ )
46
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
47
+ })
48
+ })
49
+
50
+ it("handles multiple attributes and replaces only the provided prop", () => {
51
+ const inputAst = parseJsx(
52
+ 'export const TestComponent = () => <Pancakes toppingOld="butter" id="123" />'
53
+ )
54
+ const outputAst = parseJsx(
55
+ 'export const TestComponent = () => <Pancakes toppingNew="jam" id="123" />'
56
+ )
57
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
58
+ })
59
+
60
+ it("transforms multiple components", () => {
61
+ const inputAst = parseJsx(`
62
+ export const TestComponent = () => (
63
+ <div>
64
+ <Pancakes toppingOld="butter" />
65
+ <Pancakes toppingOld="honey" />
66
+ </div>
67
+ )
68
+ `)
69
+ const outputAst = parseJsx(`
70
+ export const TestComponent = () => (
71
+ <div>
72
+ <Pancakes toppingNew="jam" />
73
+ <Pancakes toppingNew="blueberries" />
74
+ </div>
75
+ )
76
+ `)
77
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
78
+ })
79
+
80
+ it("transforms arbitrary braces", () => {
81
+ const inputAst = parseJsx(`
82
+ export const TestComponent = () => (
83
+ <div>
84
+ <Pancakes toppingOld={"butter"} />
85
+ <Pancakes toppingOld={'butter'} />
86
+ <Pancakes toppingOld={\`butter\`} />
87
+ </div>
88
+ )
89
+ `)
90
+ const outputAst = parseJsx(`
91
+ export const TestComponent = () => (
92
+ <div>
93
+ <Pancakes toppingNew="jam" />
94
+ <Pancakes toppingNew="jam" />
95
+ <Pancakes toppingNew="jam" />
96
+ </div>
97
+ )
98
+ `)
99
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
100
+ })
101
+
102
+ it("does not add new prop if old prop is not defined", () => {
103
+ const inputAst = parseJsx("export const TestComponent = () => <Pancakes />")
104
+ const outputAst = parseJsx(
105
+ "export const TestComponent = () => <Pancakes />"
106
+ )
107
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
108
+ })
109
+
110
+ it("does not add new prop if new prop already exists", () => {
111
+ const inputAst = parseJsx(
112
+ 'export const TestComponent = () => <Pancakes toppingNew="jam" />'
113
+ )
114
+ const outputAst = parseJsx(
115
+ 'export const TestComponent = () => <Pancakes toppingNew="jam" />'
116
+ )
117
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
118
+ })
119
+
120
+ it("does not modify old prop using variables", () => {
121
+ const inputAst = parseJsx(
122
+ "export const TestComponent = () => <Pancakes toppingOld={var} />"
123
+ )
124
+ const outputAst = parseJsx(
125
+ "export const TestComponent = () => <Pancakes toppingOld={var} />"
126
+ )
127
+ expect(testMigrateStringProp(inputAst)).toEqual(printAst(outputAst))
128
+ })
129
+ })
@@ -0,0 +1,43 @@
1
+ import ts from "typescript"
2
+ import { getPropValueText } from "./getPropValueText"
3
+ import { updateJsxElementWithNewProps } from "./updateJsxElementWithNewProps"
4
+
5
+ /** Recurses through AST to find and update any jsx element that matched the tagName */
6
+ export const migrateStringProp =
7
+ <OldValue extends string, NewValue extends string>(
8
+ oldPropName: string,
9
+ newPropName: string,
10
+ valueTransformer: (value: OldValue) => NewValue
11
+ ) =>
12
+ (context: ts.TransformationContext, tagName: string) =>
13
+ (rootNode: ts.Node): ts.Node => {
14
+ const visit = (node: ts.Node): ts.Node => {
15
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
16
+ if (node.tagName.getText() === tagName) {
17
+ const newAttributes = node.attributes.properties.map(attr => {
18
+ if (
19
+ ts.isJsxAttribute(attr) &&
20
+ attr.name.getText() === oldPropName
21
+ ) {
22
+ const oldValue =
23
+ attr.initializer && getPropValueText(attr.initializer)
24
+
25
+ if (oldValue) {
26
+ const newValue = valueTransformer(oldValue as OldValue)
27
+ return ts.factory.createJsxAttribute(
28
+ ts.factory.createIdentifier(newPropName),
29
+ ts.factory.createStringLiteral(newValue)
30
+ )
31
+ }
32
+ }
33
+
34
+ return attr
35
+ })
36
+
37
+ return updateJsxElementWithNewProps(node, newAttributes)
38
+ }
39
+ }
40
+ return ts.visitEachChild(node, visit, context)
41
+ }
42
+ return ts.visitNode(rootNode, visit)
43
+ }
@@ -0,0 +1,6 @@
1
+ import ts from "typescript"
2
+ /** A util that prints that is used to print the AST as a string */
3
+ export const printAst = (ast: ts.SourceFile): string => {
4
+ const printer = ts.createPrinter()
5
+ return printer.printFile(ast)
6
+ }
@@ -0,0 +1,42 @@
1
+ import fs from "fs"
2
+ import path from "path"
3
+ import ts from "typescript"
4
+ import { transformSource, getTagName, TransformConfig } from "."
5
+
6
+ /** Walks the directory and runs the runs the AST transformer on the given component name */
7
+ export const transformComponentsInDir = (
8
+ dir: string,
9
+ transformer: TransformConfig["astTransformer"],
10
+ componentName: string
11
+ ): void => {
12
+ if (dir.includes("node_modules")) {
13
+ return
14
+ }
15
+
16
+ const files = fs.readdirSync(dir)
17
+ files.forEach(file => {
18
+ const fullPath = path.join(dir, file)
19
+ if (fs.statSync(fullPath).isDirectory()) {
20
+ transformComponentsInDir(fullPath, transformer, componentName)
21
+ } else if (fullPath.endsWith(".tsx")) {
22
+ const source = fs.readFileSync(fullPath, "utf8")
23
+ const sourceFile = ts.createSourceFile(
24
+ fullPath,
25
+ source,
26
+ ts.ScriptTarget.Latest,
27
+ true
28
+ )
29
+ const tagName = getTagName(sourceFile, componentName)
30
+
31
+ if (tagName) {
32
+ const updatedSourceFile = transformSource({
33
+ sourceFile,
34
+ astTransformer: transformer,
35
+ tagName,
36
+ })
37
+
38
+ fs.writeFileSync(fullPath, updatedSourceFile, "utf8")
39
+ }
40
+ }
41
+ })
42
+ }
@@ -0,0 +1,56 @@
1
+ import fs from "fs"
2
+ import path from "path"
3
+ import ts from "typescript"
4
+ import { parseJsx } from "../__tests__/utils"
5
+ import { TransformConfig, transformSource } from "./transformSource"
6
+
7
+ export const mockedTransformer =
8
+ (context: ts.TransformationContext) =>
9
+ (rootNode: ts.Node): ts.Node => {
10
+ function visit(node: ts.Node): ts.Node {
11
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
12
+ if (node.tagName.getText() === "Pancakes") {
13
+ const newAttributes = node.attributes.properties.map(attr => {
14
+ if (ts.isJsxAttribute(attr) && attr.name.getText() === "topping") {
15
+ return ts.factory.updateJsxAttribute(
16
+ attr,
17
+ attr.name,
18
+ ts.factory.createStringLiteral("jam")
19
+ )
20
+ }
21
+ return attr
22
+ })
23
+ if (ts.isJsxSelfClosingElement(node)) {
24
+ return ts.factory.updateJsxSelfClosingElement(
25
+ node,
26
+ node.tagName,
27
+ node.typeArguments,
28
+ ts.factory.createJsxAttributes(newAttributes)
29
+ )
30
+ }
31
+ }
32
+ }
33
+ return ts.visitEachChild(node, visit, context)
34
+ }
35
+ return ts.visitNode(rootNode, visit)
36
+ }
37
+
38
+ describe("transformSource", () => {
39
+ it("updates the value of Pancakes topping to jam", () => {
40
+ const filePath = path.resolve(
41
+ path.join(__dirname, "./__fixtures__/KaioComponent.tsx")
42
+ )
43
+ const fileContent = fs.readFileSync(filePath, "utf8")
44
+ const sourceFile = parseJsx(fileContent)
45
+
46
+ const mockTransformConfig = {
47
+ sourceFile,
48
+ astTransformer: mockedTransformer,
49
+ tagName: "mockAlias",
50
+ } satisfies TransformConfig
51
+
52
+ const transformed = transformSource(mockTransformConfig)
53
+
54
+ expect(transformed).toMatchSnapshot()
55
+ })
56
+ })
@@ -0,0 +1,25 @@
1
+ import ts from "typescript"
2
+ import { printAst } from "./printAst"
3
+
4
+ export type TransformConfig = {
5
+ sourceFile: ts.SourceFile
6
+ astTransformer: (
7
+ context: ts.TransformationContext,
8
+ tagName: string
9
+ ) => (rootNode: ts.Node) => ts.Node
10
+ tagName: string
11
+ }
12
+
13
+ /** Transforms the source file with the transformer and target import alias provided */
14
+ export const transformSource = ({
15
+ sourceFile,
16
+ astTransformer,
17
+ tagName,
18
+ }: TransformConfig): string => {
19
+ const result = ts.transform(sourceFile, [
20
+ context => astTransformer(context, tagName),
21
+ ])
22
+ const transformedSource = result.transformed[0] as ts.SourceFile
23
+
24
+ return printAst(transformedSource)
25
+ }
@@ -0,0 +1,67 @@
1
+ import ts from "typescript"
2
+ import { parseJsx } from "../__tests__/utils"
3
+ import { updateJsxElementWithNewProps } from "./updateJsxElementWithNewProps"
4
+
5
+ const printNode = (node: ts.Node, source: ts.SourceFile): string => {
6
+ const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })
7
+ return printer.printNode(ts.EmitHint.Unspecified, node, source)
8
+ }
9
+
10
+ describe("updateJsxElementWithNewProps()", () => {
11
+ it("adds a prop to a self closing element", () => {
12
+ const source = parseJsx("<Pancakes />")
13
+ const jsxElement = source.statements[0] as ts.ExpressionStatement
14
+
15
+ const newAttributes = [
16
+ ts.factory.createJsxAttribute(
17
+ ts.factory.createIdentifier("topping"),
18
+ ts.factory.createStringLiteral("butter")
19
+ ),
20
+ ]
21
+ const updatedNode = updateJsxElementWithNewProps(
22
+ jsxElement.expression,
23
+ newAttributes
24
+ )
25
+
26
+ const result = printNode(updatedNode, source)
27
+ expect(result).toBe('<Pancakes topping="butter"/>')
28
+ })
29
+
30
+ it("removes a prop to a self closing element", () => {
31
+ const source = parseJsx('<Pancakes topping="butter" />')
32
+ const jsxElement = source.statements[0] as ts.ExpressionStatement
33
+
34
+ const updatedNode = updateJsxElementWithNewProps(jsxElement.expression, [])
35
+
36
+ const result = printNode(updatedNode, source)
37
+ expect(result).toBe("<Pancakes />")
38
+ })
39
+
40
+ it("adds a prop to a JSX opening element", () => {
41
+ const source = parseJsx("<Pancakes>Hello</Pancakes>")
42
+ const jsxElement = source.statements[0] as ts.ExpressionStatement
43
+ const node = (jsxElement.expression as ts.JsxElement).openingElement
44
+
45
+ const newAttributes = [
46
+ ts.factory.createJsxAttribute(
47
+ ts.factory.createIdentifier("topping"),
48
+ ts.factory.createStringLiteral("butter")
49
+ ),
50
+ ]
51
+ const updatedNode = updateJsxElementWithNewProps(node, newAttributes)
52
+
53
+ const result = printNode(updatedNode, source)
54
+ expect(result).toBe('<Pancakes topping="butter">')
55
+ })
56
+
57
+ it("removes a prop to a JSX opening element", () => {
58
+ const source = parseJsx('<Pancakes topping="butter">Hello</Pancakes>')
59
+ const jsxElement = source.statements[0] as ts.ExpressionStatement
60
+ const node = (jsxElement.expression as ts.JsxElement).openingElement
61
+
62
+ const updatedNode = updateJsxElementWithNewProps(node, [])
63
+
64
+ const result = printNode(updatedNode, source)
65
+ expect(result).toBe("<Pancakes>")
66
+ })
67
+ })
@@ -0,0 +1,24 @@
1
+ import ts from "typescript"
2
+
3
+ export const updateJsxElementWithNewProps = (
4
+ node: ts.Node,
5
+ newAttributes: ts.JsxAttributeLike[]
6
+ ): ts.Node => {
7
+ if (ts.isJsxOpeningElement(node)) {
8
+ return ts.factory.updateJsxOpeningElement(
9
+ node,
10
+ node.tagName,
11
+ node.typeArguments,
12
+ ts.factory.createJsxAttributes(newAttributes)
13
+ )
14
+ } else if (ts.isJsxSelfClosingElement(node)) {
15
+ return ts.factory.updateJsxSelfClosingElement(
16
+ node,
17
+ node.tagName,
18
+ node.typeArguments,
19
+ ts.factory.createJsxAttributes(newAttributes)
20
+ )
21
+ }
22
+
23
+ return node
24
+ }
@@ -23,6 +23,7 @@ var classnames__default = /*#__PURE__*/_interopDefault(classnames);
23
23
  */
24
24
  var BrandMoment = function (_a) {
25
25
  var mood = _a.mood,
26
+ variant = _a.variant,
26
27
  illustration = _a.illustration,
27
28
  header = _a.header,
28
29
  body = _a.body,
@@ -30,10 +31,10 @@ var BrandMoment = function (_a) {
30
31
  secondaryAction = _a.secondaryAction,
31
32
  text = _a.text,
32
33
  classNameOverride = _a.classNameOverride,
33
- restProps = tslib.__rest(_a, ["mood", "illustration", "header", "body", "primaryAction", "secondaryAction", "text", "classNameOverride"]);
34
+ restProps = tslib.__rest(_a, ["mood", "variant", "illustration", "header", "body", "primaryAction", "secondaryAction", "text", "classNameOverride"]);
34
35
  var queries = useMediaQueries.useMediaQueries().queries;
35
36
  return React__default.default.createElement("div", tslib.__assign({
36
- className: classnames__default.default(BrandMoment_module.body, BrandMoment_module[mood], classNameOverride)
37
+ className: classnames__default.default(BrandMoment_module.body, variant ? BrandMoment_module[variant] : BrandMoment_module[mood], classNameOverride)
37
38
  }, restProps), React__default.default.createElement("header", {
38
39
  className: BrandMoment_module.header
39
40
  }, header), React__default.default.createElement("main", {
@@ -2,9 +2,11 @@
2
2
 
3
3
  var styles = {
4
4
  "body": "BrandMoment-module_body__J4lls",
5
- "informative": "BrandMoment-module_informative__Qvwcd",
6
5
  "positive": "BrandMoment-module_positive__78wqJ",
7
6
  "negative": "BrandMoment-module_negative__atXal",
7
+ "informative": "BrandMoment-module_informative__Qvwcd",
8
+ "success": "BrandMoment-module_success__v503M",
9
+ "warning": "BrandMoment-module_warning__dWih8",
8
10
  "container": "BrandMoment-module_container__4ORHI",
9
11
  "header": "BrandMoment-module_header__EAP5Q",
10
12
  "main": "BrandMoment-module_main__cdWko",
@@ -20,15 +20,16 @@ var Card = function (_a) {
20
20
  var children = _a.children,
21
21
  _b = _a.tag,
22
22
  tag = _b === void 0 ? "div" : _b,
23
- _c = _a.variant,
24
- variant = _c === void 0 ? "default" : _c,
23
+ variant = _a.variant,
24
+ _c = _a.color,
25
+ color = _c === void 0 ? "white" : _c,
25
26
  _d = _a.isElevated,
26
27
  isElevated = _d === void 0 ? false : _d,
27
28
  classNameOverride = _a.classNameOverride,
28
- props = tslib.__rest(_a, ["children", "tag", "variant", "isElevated", "classNameOverride"]);
29
- var Tag = tag;
30
- return React__default.default.createElement(Tag, tslib.__assign({
31
- className: classnames__default.default(Card_module.wrapper, Card_module[variant], classNameOverride, isElevated && Card_module.elevated)
29
+ props = tslib.__rest(_a, ["children", "tag", "variant", "color", "isElevated", "classNameOverride"]);
30
+ var Element = tag;
31
+ return React__default.default.createElement(Element, tslib.__assign({
32
+ className: classnames__default.default(Card_module.wrapper, variant ? Card_module[variant] : Card_module[color], classNameOverride, isElevated && Card_module.elevated)
32
33
  }, props), children);
33
34
  };
34
35
  Card.displayName = "Card";
@@ -2,13 +2,21 @@
2
2
 
3
3
  var styles = {
4
4
  "wrapper": "Card-module_wrapper__h5MUx",
5
+ "elevated": "Card-module_elevated__m7z8s",
6
+ "blue": "Card-module_blue__3-ogH",
7
+ "gray": "Card-module_gray__laFe8",
8
+ "green": "Card-module_green__FOeLt",
9
+ "orange": "Card-module_orange__hIZPr",
10
+ "purple": "Card-module_purple__7tEwm",
11
+ "red": "Card-module_red__e6deN",
12
+ "white": "Card-module_white__HD1ph",
13
+ "yellow": "Card-module_yellow__j4aX-",
5
14
  "default": "Card-module_default__MzW74",
6
15
  "informative": "Card-module_informative__4yRSy",
7
16
  "positive": "Card-module_positive__KvUqp",
8
17
  "cautionary": "Card-module_cautionary__iMWR-",
9
18
  "destructive": "Card-module_destructive__9wC8X",
10
19
  "assertive": "Card-module_assertive__6d1GM",
11
- "highlight": "Card-module_highlight__2GSL-",
12
- "elevated": "Card-module_elevated__m7z8s"
20
+ "highlight": "Card-module_highlight__2GSL-"
13
21
  };
14
22
  module.exports = styles;