@kaizen/components 1.57.2 → 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.
- package/bin/codemod.sh +39 -0
- package/codemods/README.md +31 -0
- package/codemods/__tests__/utils/index.ts +1 -0
- package/codemods/__tests__/utils/parseJsx.ts +11 -0
- package/codemods/migrateBrandMomentMoodToVariant/index.ts +21 -0
- package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.spec.ts +44 -0
- package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.ts +24 -0
- package/codemods/migrateCardVariantToColor/index.ts +15 -0
- package/codemods/migrateCardVariantToColor/transformCardVariantToColor.spec.ts +91 -0
- package/codemods/migrateCardVariantToColor/transformCardVariantToColor.ts +32 -0
- package/codemods/migrateConfirmationModalMoodsToVariant/index.ts +19 -0
- package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.spec.ts +110 -0
- package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.ts +59 -0
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/index.ts +21 -0
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.spec.ts +74 -0
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.ts +28 -0
- package/codemods/migrateGlobalNotificationTypeToVariant/index.ts +19 -0
- package/codemods/migrateInformationTileMoodToVariant/index.ts +21 -0
- package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.spec.ts +84 -0
- package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.ts +22 -0
- package/codemods/migrateInlineNotificationTypeToVariant/index.ts +19 -0
- package/codemods/migrateMultiActionTileMoodToVariant/index.ts +21 -0
- package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.spec.ts +84 -0
- package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.ts +22 -0
- package/codemods/migrateNotificationTypeToVariant/index.ts +1 -0
- package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.spec.ts +107 -0
- package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.ts +28 -0
- package/codemods/migrateProgressBarMoodToColor/index.ts +21 -0
- package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.spec.ts +54 -0
- package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.ts +26 -0
- package/codemods/migrateToastNotificationTypeToVariant/index.ts +19 -0
- package/codemods/migrateWellVariantToColor/index.ts +15 -0
- package/codemods/migrateWellVariantToColor/transformWellVariantToColor.spec.ts +192 -0
- package/codemods/migrateWellVariantToColor/transformWellVariantToColor.ts +75 -0
- package/codemods/removeInputEditModalMood/index.ts +19 -0
- package/codemods/removeInputEditModalMood/removeInputEditModalMood.spec.ts +80 -0
- package/codemods/removeInputEditModalMood/removeInputEditModalMood.ts +40 -0
- package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.spec.ts +118 -0
- package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.ts +64 -0
- package/codemods/utils/__fixtures__/KaioComponent.tsx +6 -0
- package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +11 -0
- package/codemods/utils/getPropValueText.spec.ts +75 -0
- package/codemods/utils/getPropValueText.ts +21 -0
- package/codemods/utils/getTagName.spec.ts +24 -0
- package/codemods/utils/getTagName.ts +32 -0
- package/codemods/utils/index.ts +7 -0
- package/codemods/utils/migrateStringProp.spec.ts +129 -0
- package/codemods/utils/migrateStringProp.ts +43 -0
- package/codemods/utils/printAst.ts +6 -0
- package/codemods/utils/transformComponentsInDir.ts +42 -0
- package/codemods/utils/transformSource.spec.ts +56 -0
- package/codemods/utils/transformSource.ts +25 -0
- package/codemods/utils/updateJsxElementWithNewProps.spec.ts +67 -0
- package/codemods/utils/updateJsxElementWithNewProps.ts +24 -0
- package/dist/cjs/BrandMoment/BrandMoment.cjs +3 -2
- package/dist/cjs/BrandMoment/BrandMoment.module.scss.cjs +3 -1
- package/dist/cjs/Card/Card.cjs +7 -6
- package/dist/cjs/Card/Card.module.scss.cjs +10 -2
- package/dist/cjs/EmptyState/EmptyState.cjs +14 -6
- package/dist/cjs/EmptyState/EmptyState.module.scss.cjs +3 -0
- package/dist/cjs/ErrorPage/ErrorPage.cjs +1 -1
- package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.cjs +9 -5
- package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.module.scss.cjs +6 -2
- package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs +1 -3
- package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs +1 -3
- package/dist/cjs/Notification/subcomponents/GenericNotification/GenericNotification.cjs +6 -3
- package/dist/cjs/Notification/subcomponents/GenericNotification/GenericNotification.module.scss.cjs +5 -3
- package/dist/cjs/Notification/subcomponents/NotificationIcon/NotificationIcon.cjs +35 -3
- package/dist/cjs/ProgressBar/ProgressBar.cjs +3 -2
- package/dist/cjs/ProgressBar/ProgressBar.module.scss.cjs +8 -4
- package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.cjs +7 -5
- package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.module.scss.cjs +8 -6
- package/dist/cjs/Well/Well.cjs +5 -4
- package/dist/cjs/Well/Well.module.scss.cjs +9 -1
- package/dist/cjs/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.cjs +6 -6
- package/dist/cjs/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.cjs +33 -0
- package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.cjs +160 -0
- package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.cjs +28 -0
- package/dist/cjs/containersV1.cjs +4 -0
- package/dist/cjs/containersV2.cjs +4 -0
- package/dist/cjs/index.cjs +2 -2
- package/dist/esm/BrandMoment/BrandMoment.mjs +3 -2
- package/dist/esm/BrandMoment/BrandMoment.module.scss.mjs +3 -1
- package/dist/esm/Card/Card.mjs +7 -6
- package/dist/esm/Card/Card.module.scss.mjs +10 -2
- package/dist/esm/EmptyState/EmptyState.mjs +15 -7
- package/dist/esm/EmptyState/EmptyState.module.scss.mjs +3 -0
- package/dist/esm/ErrorPage/ErrorPage.mjs +1 -1
- package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.mjs +9 -5
- package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.module.scss.mjs +6 -2
- package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs +1 -3
- package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs +1 -3
- package/dist/esm/Notification/subcomponents/GenericNotification/GenericNotification.mjs +8 -5
- package/dist/esm/Notification/subcomponents/GenericNotification/GenericNotification.module.scss.mjs +5 -3
- package/dist/esm/Notification/subcomponents/NotificationIcon/NotificationIcon.mjs +39 -5
- package/dist/esm/ProgressBar/ProgressBar.mjs +3 -2
- package/dist/esm/ProgressBar/ProgressBar.module.scss.mjs +8 -4
- package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.mjs +7 -5
- package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.module.scss.mjs +8 -6
- package/dist/esm/Well/Well.mjs +5 -4
- package/dist/esm/Well/Well.module.scss.mjs +9 -1
- package/dist/esm/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.mjs +6 -6
- package/dist/esm/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.mjs +31 -0
- package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.mjs +153 -0
- package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.mjs +26 -0
- package/dist/esm/containersV1.mjs +1 -0
- package/dist/esm/containersV2.mjs +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/styles.css +13 -12
- package/dist/types/BrandMoment/BrandMoment.d.ts +19 -3
- package/dist/types/Card/Card.d.ts +20 -7
- package/dist/types/EmptyState/EmptyState.d.ts +14 -6
- package/dist/types/Modal/ConfirmationModal/ConfirmationModal.d.ts +25 -7
- package/dist/types/Modal/GenericModal/subcomponents/ModalFooter/ModalFooter.d.ts +3 -0
- package/dist/types/Modal/InputEditModal/InputEditModal.d.ts +4 -1
- package/dist/types/Notification/GlobalNotification/GlobalNotification.d.ts +3 -3
- package/dist/types/Notification/InlineNotification/InlineNotification.d.ts +3 -3
- package/dist/types/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +5 -4
- package/dist/types/Notification/ToastNotification/context/ToastNotificationContext.d.ts +4 -3
- package/dist/types/Notification/ToastNotification/types.d.ts +3 -3
- package/dist/types/Notification/subcomponents/GenericNotification/GenericNotification.d.ts +24 -4
- package/dist/types/Notification/subcomponents/NotificationIcon/NotificationIcon.d.ts +11 -4
- package/dist/types/Notification/types.d.ts +2 -1
- package/dist/types/ProgressBar/ProgressBar.d.ts +25 -6
- package/dist/types/Tile/subcomponents/GenericTile/GenericTile.d.ts +10 -3
- package/dist/types/Well/Well.d.ts +6 -2
- package/dist/types/Well/types.d.ts +4 -0
- package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.d.ts +4 -4
- package/dist/types/__containers__/GuidanceBlock/v2/GuidanceBlock.d.ts +59 -0
- package/dist/types/__containers__/GuidanceBlock/v2/index.d.ts +1 -0
- package/dist/types/__containers__/v1.d.ts +1 -0
- package/dist/types/__containers__/v2.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +17 -3
- package/src/BrandMoment/BrandMoment.module.scss +20 -9
- package/src/BrandMoment/BrandMoment.tsx +26 -3
- package/src/BrandMoment/_docs/BrandMoment.mdx +13 -13
- package/src/BrandMoment/_docs/BrandMoment.stickersheet.stories.tsx +102 -0
- package/src/BrandMoment/_docs/BrandMoment.stories.tsx +17 -99
- package/src/Card/Card.module.scss +56 -7
- package/src/Card/Card.tsx +35 -11
- package/src/Card/_docs/Card.mdx +6 -3
- package/src/Card/_docs/Card.stickersheet.stories.tsx +44 -39
- package/src/Card/_docs/Card.stories.tsx +23 -23
- package/src/EmptyState/EmptyState.module.scss +32 -14
- package/src/EmptyState/EmptyState.tsx +32 -18
- package/src/EmptyState/_docs/EmptyState.stickersheet.stories.tsx +69 -121
- package/src/EmptyState/_docs/EmptyState.stories.tsx +6 -8
- package/src/ErrorPage/ErrorPage.tsx +1 -1
- package/src/Modal/ConfirmationModal/ConfirmationModal.module.scss +100 -78
- package/src/Modal/ConfirmationModal/ConfirmationModal.spec.tsx +5 -5
- package/src/Modal/ConfirmationModal/ConfirmationModal.tsx +41 -10
- package/src/Modal/ConfirmationModal/_docs/ConfirmationModal.mdx +3 -3
- package/src/Modal/ConfirmationModal/_docs/ConfirmationModal.stories.tsx +11 -4
- package/src/Modal/ContextModal/_docs/ContextModal.stories.tsx +3 -1
- package/src/Modal/GenericModal/subcomponents/ModalFooter/ModalFooter.tsx +3 -0
- package/src/Modal/InputEditModal/InputEditModal.tsx +4 -1
- package/src/Modal/InputEditModal/_docs/InputEditModal.mdx +0 -13
- package/src/Modal/InputEditModal/_docs/InputEditModal.stories.tsx +9 -10
- package/src/Notification/GlobalNotification/GlobalNotification.tsx +9 -4
- package/src/Notification/GlobalNotification/_docs/GlobalNotification.stickersheet.stories.tsx +68 -58
- package/src/Notification/GlobalNotification/_docs/GlobalNotification.stories.tsx +10 -13
- package/src/Notification/InlineNotification/InlineNotification.tsx +9 -4
- package/src/Notification/InlineNotification/_docs/InlineNotification.stickersheet.stories.tsx +79 -44
- package/src/Notification/InlineNotification/_docs/InlineNotification.stories.tsx +17 -17
- package/src/Notification/ToastNotification/ToastNotification/ToastNotification.tsx +7 -5
- package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.tsx +1 -2
- package/src/Notification/ToastNotification/_docs/ToastNotification.stickersheet.stories.tsx +12 -7
- package/src/Notification/ToastNotification/_docs/ToastNotification.stories.tsx +6 -1
- package/src/Notification/ToastNotification/context/ToastNotificationContext.tsx +7 -3
- package/src/Notification/ToastNotification/types.ts +8 -3
- package/src/Notification/subcomponents/GenericNotification/GenericNotification.module.scss +42 -5
- package/src/Notification/subcomponents/GenericNotification/GenericNotification.tsx +40 -6
- package/src/Notification/subcomponents/GenericNotification/_mixins.scss +2 -1
- package/src/Notification/subcomponents/NotificationIcon/NotificationIcon.tsx +31 -5
- package/src/Notification/types.ts +9 -2
- package/src/ProgressBar/ProgressBar.module.scss +37 -25
- package/src/ProgressBar/ProgressBar.tsx +30 -5
- package/src/ProgressBar/_docs/ProgressBar.mdx +2 -3
- package/src/ProgressBar/_docs/ProgressBar.stickersheet.stories.tsx +95 -51
- package/src/ProgressBar/_docs/ProgressBar.stories.tsx +56 -25
- package/src/Tile/InformationTile/_docs/InformationTile.mdx +3 -2
- package/src/Tile/InformationTile/_docs/InformationTile.stickersheet.stories.tsx +57 -19
- package/src/Tile/InformationTile/_docs/InformationTile.stories.tsx +19 -7
- package/src/Tile/MultiActionTile/_docs/MultiActionTile.mdx +3 -2
- package/src/Tile/MultiActionTile/_docs/MultiActionTile.stickersheet.stories.tsx +62 -24
- package/src/Tile/MultiActionTile/_docs/MultiActionTile.stories.tsx +19 -7
- package/src/Tile/subcomponents/GenericTile/GenericTile.module.scss +34 -22
- package/src/Tile/subcomponents/GenericTile/GenericTile.tsx +17 -8
- package/src/Tile/subcomponents/GenericTile/_docs/GenericTile.stickersheet.stories.tsx +57 -19
- package/src/Well/Well.module.scss +70 -33
- package/src/Well/Well.tsx +9 -3
- package/src/Well/_docs/Well.mdx +9 -2
- package/src/Well/_docs/Well.stickersheet.stories.tsx +10 -1
- package/src/Well/_docs/Well.stories.tsx +54 -29
- package/src/Well/types.ts +15 -0
- package/src/__actions__/Button/v3/_docs/ApiSpecification.mdx +1 -1
- package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.module.scss +2 -2
- package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.mdx +2 -2
- package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.stickersheet.stories.tsx +1 -1
- package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/_docs/GuidanceBlock.stories.tsx +1 -1
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss +356 -0
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.spec.tsx +82 -0
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.tsx +262 -0
- package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.mdx +38 -0
- package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stickersheet.stories.tsx +118 -0
- package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stories.tsx +152 -0
- package/src/__containers__/GuidanceBlock/v2/index.ts +1 -0
- package/src/__containers__/v1.ts +1 -0
- package/src/__containers__/v2.ts +1 -0
- package/src/index.ts +2 -1
- package/v1/containers/package.json +5 -0
- package/v2/containers/package.json +5 -0
- package/dist/cjs/GuidanceBlock/GuidanceBlock.module.scss.cjs +0 -33
- package/dist/esm/GuidanceBlock/GuidanceBlock.module.scss.mjs +0 -31
- package/dist/types/Tile/subcomponents/GenericTile/types.d.ts +0 -2
- package/src/EmptyState/_docs/EmptyState.stories.module.scss +0 -15
- package/src/Notification/ToastNotification/ToastNotification/ToastNotification.spec.tsx +0 -33
- package/src/Tile/subcomponents/GenericTile/types.ts +0 -10
- /package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/index.d.ts +0 -0
- /package/dist/types/{GuidanceBlock → __containers__/GuidanceBlock/v1}/types.d.ts +0 -0
- /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.spec.tsx +0 -0
- /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/GuidanceBlock.tsx +0 -0
- /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/index.ts +0 -0
- /package/src/{GuidanceBlock → __containers__/GuidanceBlock/v1}/types.ts +0 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { parseJsx } from "../__tests__/utils"
|
|
2
|
+
import { transformSource, printAst } from "../utils"
|
|
3
|
+
import { transformWellVariantToColor } from "./transformWellVariantToColor"
|
|
4
|
+
|
|
5
|
+
describe("transformWellVariantToColor", () => {
|
|
6
|
+
it('replaces variant="default" with color="gray"', () => {
|
|
7
|
+
const inputAst = parseJsx(`
|
|
8
|
+
import {Well} from "@kaizen/components"
|
|
9
|
+
export const TestComponent = () => <Well variant="default">Test</Well>
|
|
10
|
+
`)
|
|
11
|
+
const outputAst = parseJsx(`
|
|
12
|
+
import {Well} from "@kaizen/components"
|
|
13
|
+
export const TestComponent = () => <Well color="gray">Test</Well>
|
|
14
|
+
`)
|
|
15
|
+
const transformed = transformSource({
|
|
16
|
+
sourceFile: inputAst,
|
|
17
|
+
astTransformer: transformWellVariantToColor,
|
|
18
|
+
tagName: "Well",
|
|
19
|
+
})
|
|
20
|
+
expect(transformed).toEqual(printAst(outputAst))
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('replaces variant="informative" with color="blue"', () => {
|
|
24
|
+
const inputAst = parseJsx(`
|
|
25
|
+
import {Well} from "@kaizen/components"
|
|
26
|
+
export const TestComponent = () => <Well variant="informative">Test</Well>
|
|
27
|
+
`)
|
|
28
|
+
const outputAst = parseJsx(`
|
|
29
|
+
import {Well} from "@kaizen/components"
|
|
30
|
+
export const TestComponent = () => <Well color="blue">Test</Well>
|
|
31
|
+
`)
|
|
32
|
+
const transformed = transformSource({
|
|
33
|
+
sourceFile: inputAst,
|
|
34
|
+
astTransformer: transformWellVariantToColor,
|
|
35
|
+
tagName: "Well",
|
|
36
|
+
})
|
|
37
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('adds color="gray" if variant is not specified', () => {
|
|
41
|
+
const inputAst = parseJsx(`
|
|
42
|
+
import {Well} from "@kaizen/components"
|
|
43
|
+
export const TestComponent = () => <Well>Test</Well>
|
|
44
|
+
`)
|
|
45
|
+
const outputAst = parseJsx(`
|
|
46
|
+
import {Well} from "@kaizen/components"
|
|
47
|
+
export const TestComponent = () => <Well color="gray">Test</Well>
|
|
48
|
+
`)
|
|
49
|
+
const transformed = transformSource({
|
|
50
|
+
sourceFile: inputAst,
|
|
51
|
+
astTransformer: transformWellVariantToColor,
|
|
52
|
+
tagName: "Well",
|
|
53
|
+
})
|
|
54
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it("handles multiple attributes and replace only variant", () => {
|
|
58
|
+
const inputAst = parseJsx(`
|
|
59
|
+
import {Well} from "@kaizen/components"
|
|
60
|
+
export const TestComponent = () => <Well variant="informative" id="123">Test</Well>
|
|
61
|
+
`)
|
|
62
|
+
const outputAst = parseJsx(`
|
|
63
|
+
import {Well} from "@kaizen/components"
|
|
64
|
+
export const TestComponent = () => <Well color="blue" id="123">Test</Well>
|
|
65
|
+
`)
|
|
66
|
+
const transformed = transformSource({
|
|
67
|
+
sourceFile: inputAst,
|
|
68
|
+
astTransformer: transformWellVariantToColor,
|
|
69
|
+
tagName: "Well",
|
|
70
|
+
})
|
|
71
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("handles multiple attributes and add color if variant is not specified", () => {
|
|
75
|
+
const inputAst = parseJsx(`
|
|
76
|
+
import {Well} from "@kaizen/components"
|
|
77
|
+
export const TestComponent = () => <Well id="123">Test</Well>
|
|
78
|
+
`)
|
|
79
|
+
const outputAst = parseJsx(`
|
|
80
|
+
import {Well} from "@kaizen/components"
|
|
81
|
+
export const TestComponent = () => <Well id="123" color="gray">Test</Well>
|
|
82
|
+
`)
|
|
83
|
+
const transformed = transformSource({
|
|
84
|
+
sourceFile: inputAst,
|
|
85
|
+
astTransformer: transformWellVariantToColor,
|
|
86
|
+
tagName: "Well",
|
|
87
|
+
})
|
|
88
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("handles nested Well components", () => {
|
|
92
|
+
const inputAst = parseJsx(`
|
|
93
|
+
import {Well} from "@kaizen/components"
|
|
94
|
+
export const TestComponent = () => <div><Well id="123">Test</Well></div>
|
|
95
|
+
`)
|
|
96
|
+
const outputAst = parseJsx(`
|
|
97
|
+
import {Well} from "@kaizen/components"
|
|
98
|
+
export const TestComponent = () => <div><Well id="123" color="gray">Test</Well></div>
|
|
99
|
+
`)
|
|
100
|
+
const transformed = transformSource({
|
|
101
|
+
sourceFile: inputAst,
|
|
102
|
+
astTransformer: transformWellVariantToColor,
|
|
103
|
+
tagName: "Well",
|
|
104
|
+
})
|
|
105
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it("transforms multiple Wells", () => {
|
|
109
|
+
const inputAst = parseJsx(`
|
|
110
|
+
import {Well} from "@kaizen/components"
|
|
111
|
+
export const TestComponent = () => <div><Well variant="informative">Test</Well><Well>Test 2</Well></div>
|
|
112
|
+
`)
|
|
113
|
+
const outputAst = parseJsx(`
|
|
114
|
+
import {Well} from "@kaizen/components"
|
|
115
|
+
export const TestComponent = () => <div><Well color="blue">Test</Well><Well color="gray">Test 2</Well></div>
|
|
116
|
+
`)
|
|
117
|
+
const transformed = transformSource({
|
|
118
|
+
sourceFile: inputAst,
|
|
119
|
+
astTransformer: transformWellVariantToColor,
|
|
120
|
+
tagName: "Well",
|
|
121
|
+
})
|
|
122
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it("transforms Well with arbitrary braces", () => {
|
|
126
|
+
const inputAst = parseJsx(`
|
|
127
|
+
import {Well} from "@kaizen/components"
|
|
128
|
+
export const TestComponent = () => <div><Well variant={"informative"}>Test</Well><Well variant={'assertive'}>Test</Well><Well variant={\`positive\`}>Test</Well></div>
|
|
129
|
+
`)
|
|
130
|
+
const outputAst = parseJsx(`
|
|
131
|
+
import {Well} from "@kaizen/components"
|
|
132
|
+
export const TestComponent = () => <div><Well color="blue">Test</Well><Well color="orange">Test</Well><Well color="green">Test</Well></div>
|
|
133
|
+
`)
|
|
134
|
+
const transformed = transformSource({
|
|
135
|
+
sourceFile: inputAst,
|
|
136
|
+
astTransformer: transformWellVariantToColor,
|
|
137
|
+
tagName: "Well",
|
|
138
|
+
})
|
|
139
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it("won't add color if color already exists", () => {
|
|
143
|
+
const inputAst = parseJsx(`
|
|
144
|
+
import {Well} from "@kaizen/components"
|
|
145
|
+
export const TestComponent = () => <div><Well color="blue">Test</Well></div>
|
|
146
|
+
`)
|
|
147
|
+
const outputAst = parseJsx(`
|
|
148
|
+
import {Well} from "@kaizen/components"
|
|
149
|
+
export const TestComponent = () => <div><Well color="blue">Test</Well></div>
|
|
150
|
+
`)
|
|
151
|
+
const transformed = transformSource({
|
|
152
|
+
sourceFile: inputAst,
|
|
153
|
+
astTransformer: transformWellVariantToColor,
|
|
154
|
+
tagName: "Well",
|
|
155
|
+
})
|
|
156
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it("won't modify variants usings variables", () => {
|
|
160
|
+
const inputAst = parseJsx(`
|
|
161
|
+
import {Well} from "@kaizen/components"
|
|
162
|
+
export const TestComponent = () => <div><Well variant={wellVariable}>Test</Well></div>
|
|
163
|
+
`)
|
|
164
|
+
const outputAst = parseJsx(`
|
|
165
|
+
import {Well} from "@kaizen/components"
|
|
166
|
+
export const TestComponent = () => <div><Well variant={wellVariable}>Test</Well></div>
|
|
167
|
+
`)
|
|
168
|
+
const transformed = transformSource({
|
|
169
|
+
sourceFile: inputAst,
|
|
170
|
+
astTransformer: transformWellVariantToColor,
|
|
171
|
+
tagName: "Well",
|
|
172
|
+
})
|
|
173
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it("transforms aliased Well components", () => {
|
|
177
|
+
const inputAst = parseJsx(`
|
|
178
|
+
import {Well as KaizenWell} from "@kaizen/components"
|
|
179
|
+
export const TestComponent = () => <div><KaizenWell variant="informative">Test</KaizenWell></div>
|
|
180
|
+
`)
|
|
181
|
+
const outputAst = parseJsx(`
|
|
182
|
+
import {Well as KaizenWell} from "@kaizen/components"
|
|
183
|
+
export const TestComponent = () => <div><KaizenWell color="blue">Test</KaizenWell></div>
|
|
184
|
+
`)
|
|
185
|
+
const transformed = transformSource({
|
|
186
|
+
sourceFile: inputAst,
|
|
187
|
+
astTransformer: transformWellVariantToColor,
|
|
188
|
+
tagName: "KaizenWell",
|
|
189
|
+
})
|
|
190
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
191
|
+
})
|
|
192
|
+
})
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import { updateJsxElementWithNewProps } from "../utils"
|
|
3
|
+
import { getPropValueText } from "../utils/getPropValueText"
|
|
4
|
+
|
|
5
|
+
/** Recurses through AST to find and update any jsx element that matched the tagName */
|
|
6
|
+
export const transformWellVariantToColor =
|
|
7
|
+
(context: ts.TransformationContext, tagName: string) =>
|
|
8
|
+
(rootNode: ts.Node): ts.Node => {
|
|
9
|
+
function visit(node: ts.Node): ts.Node {
|
|
10
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
11
|
+
if (node.tagName.getText() === tagName) {
|
|
12
|
+
let hasVariant = false
|
|
13
|
+
let hasColor = false
|
|
14
|
+
let newAttributes = node.attributes.properties.map(attr => {
|
|
15
|
+
if (ts.isJsxAttribute(attr) && attr.name.getText() === "variant") {
|
|
16
|
+
hasVariant = true
|
|
17
|
+
const valueName =
|
|
18
|
+
attr.initializer && getPropValueText(attr.initializer)
|
|
19
|
+
|
|
20
|
+
if (valueName) {
|
|
21
|
+
let colorValue: string = "gray"
|
|
22
|
+
switch (valueName) {
|
|
23
|
+
case "default":
|
|
24
|
+
colorValue = "gray"
|
|
25
|
+
break
|
|
26
|
+
case "informative":
|
|
27
|
+
colorValue = "blue"
|
|
28
|
+
break
|
|
29
|
+
case "cautionary":
|
|
30
|
+
colorValue = "yellow"
|
|
31
|
+
break
|
|
32
|
+
case "assertive":
|
|
33
|
+
colorValue = "orange"
|
|
34
|
+
break
|
|
35
|
+
case "negative":
|
|
36
|
+
colorValue = "red"
|
|
37
|
+
break
|
|
38
|
+
case "positive":
|
|
39
|
+
colorValue = "green"
|
|
40
|
+
break
|
|
41
|
+
case "prominent":
|
|
42
|
+
colorValue = "purple"
|
|
43
|
+
break
|
|
44
|
+
default:
|
|
45
|
+
colorValue = "gray"
|
|
46
|
+
}
|
|
47
|
+
return ts.factory.createJsxAttribute(
|
|
48
|
+
ts.factory.createIdentifier("color"),
|
|
49
|
+
ts.factory.createStringLiteral(colorValue)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (ts.isJsxAttribute(attr) && attr.name.getText() === "color") {
|
|
54
|
+
hasColor = true
|
|
55
|
+
}
|
|
56
|
+
return attr
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
if (!hasColor && !hasVariant) {
|
|
60
|
+
newAttributes = [
|
|
61
|
+
...newAttributes,
|
|
62
|
+
ts.factory.createJsxAttribute(
|
|
63
|
+
ts.factory.createIdentifier("color"),
|
|
64
|
+
ts.factory.createStringLiteral("gray")
|
|
65
|
+
),
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return updateJsxElementWithNewProps(node, newAttributes)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return ts.visitEachChild(node, visit, context)
|
|
73
|
+
}
|
|
74
|
+
return ts.visitNode(rootNode, visit)
|
|
75
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { transformComponentsInDir } from "../utils"
|
|
2
|
+
import { removeInputEditModalMood } from "./removeInputEditModalMood"
|
|
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 InputEditModal transformer (~ -_-)~")
|
|
7
|
+
const targetDir = process.argv[2]
|
|
8
|
+
if (!targetDir) {
|
|
9
|
+
process.exit(1)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
transformComponentsInDir(
|
|
13
|
+
targetDir,
|
|
14
|
+
removeInputEditModalMood,
|
|
15
|
+
"InputEditModal"
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
migrateModalMoodsToVariant()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { parseJsx } from "../__tests__/utils"
|
|
2
|
+
import { transformSource, printAst } from "../utils"
|
|
3
|
+
import { removeInputEditModalMood } from "./removeInputEditModalMood"
|
|
4
|
+
|
|
5
|
+
describe("removeInputEditModalMood", () => {
|
|
6
|
+
it("removed mood", () => {
|
|
7
|
+
const inputAst = parseJsx(`
|
|
8
|
+
export const TestComponent = () => <InputEditModal mood="positive"/>
|
|
9
|
+
`)
|
|
10
|
+
const outputAst = parseJsx(`
|
|
11
|
+
export const TestComponent = () => <InputEditModal />
|
|
12
|
+
`)
|
|
13
|
+
const transformed = transformSource({
|
|
14
|
+
sourceFile: inputAst,
|
|
15
|
+
astTransformer: removeInputEditModalMood,
|
|
16
|
+
tagName: "InputEditModal",
|
|
17
|
+
})
|
|
18
|
+
expect(transformed).toEqual(printAst(outputAst))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it("handles multiple attributes and remove only mood", () => {
|
|
22
|
+
const inputAst = parseJsx(`
|
|
23
|
+
export const TestComponent = () => <InputEditModal mood="destructive" id="123"/>
|
|
24
|
+
`)
|
|
25
|
+
const outputAst = parseJsx(`
|
|
26
|
+
export const TestComponent = () => <InputEditModal id="123"/>
|
|
27
|
+
`)
|
|
28
|
+
const transformed = transformSource({
|
|
29
|
+
sourceFile: inputAst,
|
|
30
|
+
astTransformer: removeInputEditModalMood,
|
|
31
|
+
tagName: "InputEditModal",
|
|
32
|
+
})
|
|
33
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it("transforms multiple InputEditModals", () => {
|
|
37
|
+
const inputAst = parseJsx(`
|
|
38
|
+
export const TestComponent = () => <div><InputEditModal mood="positive"/><InputEditModal mood="destructive"/></div>
|
|
39
|
+
`)
|
|
40
|
+
const outputAst = parseJsx(`
|
|
41
|
+
export const TestComponent = () => <div><InputEditModal /><InputEditModal /></div>
|
|
42
|
+
`)
|
|
43
|
+
const transformed = transformSource({
|
|
44
|
+
sourceFile: inputAst,
|
|
45
|
+
astTransformer: removeInputEditModalMood,
|
|
46
|
+
tagName: "InputEditModal",
|
|
47
|
+
})
|
|
48
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it("transforms InputEditModal with arbitrary braces", () => {
|
|
52
|
+
const inputAst = parseJsx(`
|
|
53
|
+
export const TestComponent = () => <div><InputEditModal mood={"positive"}/><InputEditModal mood={'assertive'}/><InputEditModal mood={\`positive\`}/></div>
|
|
54
|
+
`)
|
|
55
|
+
const outputAst = parseJsx(`
|
|
56
|
+
export const TestComponent = () => <div><InputEditModal /><InputEditModal /><InputEditModal /></div>
|
|
57
|
+
`)
|
|
58
|
+
const transformed = transformSource({
|
|
59
|
+
sourceFile: inputAst,
|
|
60
|
+
astTransformer: removeInputEditModalMood,
|
|
61
|
+
tagName: "InputEditModal",
|
|
62
|
+
})
|
|
63
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it("won't modify variants usings variables", () => {
|
|
67
|
+
const inputAst = parseJsx(`
|
|
68
|
+
export const TestComponent = () => <div><InputEditModal mood={InputEditModalVariable}/></div>
|
|
69
|
+
`)
|
|
70
|
+
const outputAst = parseJsx(`
|
|
71
|
+
export const TestComponent = () => <div><InputEditModal /></div>
|
|
72
|
+
`)
|
|
73
|
+
const transformed = transformSource({
|
|
74
|
+
sourceFile: inputAst,
|
|
75
|
+
astTransformer: removeInputEditModalMood,
|
|
76
|
+
tagName: "InputEditModal",
|
|
77
|
+
})
|
|
78
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
|
|
3
|
+
/** Recurses through AST to find and update any jsx element that matched the tagName */
|
|
4
|
+
export const removeInputEditModalMood =
|
|
5
|
+
(context: ts.TransformationContext, tagName: string) =>
|
|
6
|
+
(rootNode: ts.Node): ts.Node => {
|
|
7
|
+
function visit(node: ts.Node): ts.Node {
|
|
8
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
9
|
+
if (node.tagName.getText() === tagName) {
|
|
10
|
+
const newAttributes = node.attributes.properties.reduce<
|
|
11
|
+
ts.JsxAttributeLike[]
|
|
12
|
+
>((acc, attr) => {
|
|
13
|
+
if (ts.isJsxAttribute(attr) && attr.name.getText() === "mood") {
|
|
14
|
+
return acc
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return [...acc, attr]
|
|
18
|
+
}, [])
|
|
19
|
+
|
|
20
|
+
if (ts.isJsxOpeningElement(node)) {
|
|
21
|
+
return ts.factory.updateJsxOpeningElement(
|
|
22
|
+
node,
|
|
23
|
+
node.tagName,
|
|
24
|
+
node.typeArguments,
|
|
25
|
+
ts.factory.createJsxAttributes(newAttributes)
|
|
26
|
+
)
|
|
27
|
+
} else if (ts.isJsxSelfClosingElement(node)) {
|
|
28
|
+
return ts.factory.updateJsxSelfClosingElement(
|
|
29
|
+
node,
|
|
30
|
+
node.tagName,
|
|
31
|
+
node.typeArguments,
|
|
32
|
+
ts.factory.createJsxAttributes(newAttributes)
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return ts.visitEachChild(node, visit, context)
|
|
38
|
+
}
|
|
39
|
+
return ts.visitNode(rootNode, visit)
|
|
40
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { parseJsx } from "../__tests__/utils"
|
|
2
|
+
import { transformSource, printAst } from "../utils"
|
|
3
|
+
import { transformGuidanceBlockVariantProp } from "./transformGuidanceBlockVariantProp"
|
|
4
|
+
|
|
5
|
+
describe("transformGuidanceBlockVariantProp", () => {
|
|
6
|
+
it("removes all instances of `positive`, `negative`, `informative`, `cautionary`, `assertive`", () => {
|
|
7
|
+
const inputAst = parseJsx(`
|
|
8
|
+
const TestComponent = () => <GuidanceBlock variant="positive" />
|
|
9
|
+
const TestComponent = () => <GuidanceBlock variant="negative" />
|
|
10
|
+
const TestComponent = () => <GuidanceBlock variant="informative" />
|
|
11
|
+
const TestComponent = () => <GuidanceBlock variant="cautionary" />
|
|
12
|
+
const TestComponent = () => <GuidanceBlock variant="assertive" />
|
|
13
|
+
`)
|
|
14
|
+
const outputAst = parseJsx(`
|
|
15
|
+
const TestComponent = () => <GuidanceBlock />
|
|
16
|
+
const TestComponent = () => <GuidanceBlock />
|
|
17
|
+
const TestComponent = () => <GuidanceBlock />
|
|
18
|
+
const TestComponent = () => <GuidanceBlock />
|
|
19
|
+
const TestComponent = () => <GuidanceBlock />
|
|
20
|
+
`)
|
|
21
|
+
const transformed = transformSource({
|
|
22
|
+
sourceFile: inputAst,
|
|
23
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
24
|
+
tagName: "GuidanceBlock",
|
|
25
|
+
})
|
|
26
|
+
expect(transformed).toEqual(printAst(outputAst))
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('replaces variant="expert-advice" with variant="prominent"', () => {
|
|
30
|
+
const inputAst = parseJsx(`
|
|
31
|
+
export const TestComponent = () => <GuidanceBlock variant="expert-advice" />
|
|
32
|
+
`)
|
|
33
|
+
const outputAst = parseJsx(`
|
|
34
|
+
export const TestComponent = () => <GuidanceBlock variant="prominent" />
|
|
35
|
+
`)
|
|
36
|
+
const transformed = transformSource({
|
|
37
|
+
sourceFile: inputAst,
|
|
38
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
39
|
+
tagName: "GuidanceBlock",
|
|
40
|
+
})
|
|
41
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("handles multiple attributes and replace only variant", () => {
|
|
45
|
+
const inputAst = parseJsx(`
|
|
46
|
+
export const TestComponent = () => <GuidanceBlock variant="positive" id="123" />
|
|
47
|
+
`)
|
|
48
|
+
const outputAst = parseJsx(`
|
|
49
|
+
export const TestComponent = () => <GuidanceBlock id="123" />
|
|
50
|
+
`)
|
|
51
|
+
const transformed = transformSource({
|
|
52
|
+
sourceFile: inputAst,
|
|
53
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
54
|
+
tagName: "GuidanceBlock",
|
|
55
|
+
})
|
|
56
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("handles nested GuidanceBlock components", () => {
|
|
60
|
+
const inputAst = parseJsx(`
|
|
61
|
+
export const TestComponent = () => <div><GuidanceBlock variant="positive" id="123" /></div>
|
|
62
|
+
`)
|
|
63
|
+
const outputAst = parseJsx(`
|
|
64
|
+
export const TestComponent = () => <div><GuidanceBlock id="123" /></div>
|
|
65
|
+
`)
|
|
66
|
+
const transformed = transformSource({
|
|
67
|
+
sourceFile: inputAst,
|
|
68
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
69
|
+
tagName: "GuidanceBlock",
|
|
70
|
+
})
|
|
71
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("transforms multiple GuidanceBlock", () => {
|
|
75
|
+
const inputAst = parseJsx(`
|
|
76
|
+
export const TestComponent = () => <div><GuidanceBlock variant="positive" /><GuidanceBlock variant="positive" /></div>
|
|
77
|
+
`)
|
|
78
|
+
const outputAst = parseJsx(`
|
|
79
|
+
export const TestComponent = () => <div><GuidanceBlock /><GuidanceBlock /></div>
|
|
80
|
+
`)
|
|
81
|
+
const transformed = transformSource({
|
|
82
|
+
sourceFile: inputAst,
|
|
83
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
84
|
+
tagName: "GuidanceBlock",
|
|
85
|
+
})
|
|
86
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it("transforms GuidanceBlock with arbitrary braces", () => {
|
|
90
|
+
const inputAst = parseJsx(`
|
|
91
|
+
export const TestComponent = () => <div><GuidanceBlock variant={"informative"} /><GuidanceBlock variant={'assertive'} /><GuidanceBlock variant={\`expert-advice\`} /></div>
|
|
92
|
+
`)
|
|
93
|
+
const outputAst = parseJsx(`
|
|
94
|
+
export const TestComponent = () => <div><GuidanceBlock /><GuidanceBlock /><GuidanceBlock variant="prominent" /></div>
|
|
95
|
+
`)
|
|
96
|
+
const transformed = transformSource({
|
|
97
|
+
sourceFile: inputAst,
|
|
98
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
99
|
+
tagName: "GuidanceBlock",
|
|
100
|
+
})
|
|
101
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it("won't modify variants usings variables", () => {
|
|
105
|
+
const inputAst = parseJsx(`
|
|
106
|
+
export const TestComponent = () => <div><GuidanceBlock variant={wellVariable} /></div>
|
|
107
|
+
`)
|
|
108
|
+
const outputAst = parseJsx(`
|
|
109
|
+
export const TestComponent = () => <div><GuidanceBlock variant={wellVariable} /></div>
|
|
110
|
+
`)
|
|
111
|
+
const transformed = transformSource({
|
|
112
|
+
sourceFile: inputAst,
|
|
113
|
+
astTransformer: transformGuidanceBlockVariantProp,
|
|
114
|
+
tagName: "GuidanceBlock",
|
|
115
|
+
})
|
|
116
|
+
expect(transformed).toBe(printAst(outputAst))
|
|
117
|
+
})
|
|
118
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
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 transformGuidanceBlockVariantProp =
|
|
6
|
+
(context: ts.TransformationContext, tagName: string) =>
|
|
7
|
+
(rootNode: ts.Node): ts.Node => {
|
|
8
|
+
function visit(node: ts.Node): ts.Node {
|
|
9
|
+
if (ts.isJsxSelfClosingElement(node)) {
|
|
10
|
+
if (node.tagName.getText() === tagName) {
|
|
11
|
+
const newAttributes = node.attributes.properties.reduce<
|
|
12
|
+
ts.JsxAttributeLike[]
|
|
13
|
+
>((acc, attr) => {
|
|
14
|
+
if (ts.isJsxAttribute(attr) && attr.name.getText() === "variant") {
|
|
15
|
+
const valueName =
|
|
16
|
+
attr.initializer && getPropValueText(attr.initializer)
|
|
17
|
+
|
|
18
|
+
const oldValues = [
|
|
19
|
+
"positive",
|
|
20
|
+
"negative",
|
|
21
|
+
"informative",
|
|
22
|
+
"cautionary",
|
|
23
|
+
"assertive",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
if (valueName) {
|
|
27
|
+
if (oldValues.includes(valueName)) {
|
|
28
|
+
// Remove the attribute for old values
|
|
29
|
+
return acc
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (valueName === "expert-advice") {
|
|
33
|
+
// Replace the attribute value for expert-advice
|
|
34
|
+
return [
|
|
35
|
+
...acc,
|
|
36
|
+
ts.factory.createJsxAttribute(
|
|
37
|
+
attr.name,
|
|
38
|
+
ts.factory.createStringLiteral("prominent")
|
|
39
|
+
),
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Keep the attribute for other values
|
|
44
|
+
return [...acc, attr]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [...acc, attr]
|
|
49
|
+
}, [])
|
|
50
|
+
|
|
51
|
+
if (ts.isJsxSelfClosingElement(node)) {
|
|
52
|
+
return ts.factory.updateJsxSelfClosingElement(
|
|
53
|
+
node,
|
|
54
|
+
node.tagName,
|
|
55
|
+
node.typeArguments,
|
|
56
|
+
ts.factory.createJsxAttributes(newAttributes)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return ts.visitEachChild(node, visit, context)
|
|
62
|
+
}
|
|
63
|
+
return ts.visitNode(rootNode, visit)
|
|
64
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { Pancakes } from "@kaizen/components"
|
|
4
|
+
/* eslint-disable react/jsx-curly-brace-presence */
|
|
5
|
+
export const KaioComponent = (): JSX.Element => <Pancakes topping="butter" />
|
|
6
|
+
/* eslint-enable react/jsx-curly-brace-presence */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`transformSource updates the value of Pancakes topping to jam 1`] = `
|
|
4
|
+
"import * as React from "react";
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { Pancakes } from "@kaizen/components";
|
|
7
|
+
/* eslint-disable react/jsx-curly-brace-presence */
|
|
8
|
+
export const KaioComponent = (): JSX.Element => <Pancakes topping="jam"/>;
|
|
9
|
+
/* eslint-enable react/jsx-curly-brace-presence */
|
|
10
|
+
"
|
|
11
|
+
`;
|