@kaizen/components 1.66.1 → 1.67.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/codemods/README.md +5 -0
- package/codemods/upgradeIconV1/getNewIconPropsFromOldIconName.ts +255 -0
- package/codemods/upgradeIconV1/index.ts +33 -0
- package/codemods/upgradeIconV1/transformCaMonogramIconToBrand.spec.ts +83 -0
- package/codemods/upgradeIconV1/transformCaMonogramIconToBrand.ts +53 -0
- package/codemods/upgradeIconV1/transformIcon.spec.ts +181 -0
- package/codemods/upgradeIconV1/transformIcon.ts +115 -0
- package/codemods/upgradeIconV1/transformSpinnerIconToLoadingSpinner.spec.ts +81 -0
- package/codemods/upgradeIconV1/transformSpinnerIconToLoadingSpinner.ts +41 -0
- package/codemods/upgradeIconV1/upgradeIconV1.spec.ts +306 -0
- package/codemods/upgradeIconV1/upgradeIconV1.ts +94 -0
- package/codemods/utils/createProp.spec.ts +83 -0
- package/codemods/utils/createProp.ts +51 -0
- package/codemods/utils/getKaioTagName.spec.ts +85 -0
- package/codemods/utils/getKaioTagName.ts +129 -0
- package/codemods/utils/index.ts +3 -1
- package/codemods/utils/transformComponentsInDir.ts +32 -16
- package/codemods/utils/transformSource.ts +10 -5
- package/codemods/utils/updateJsxElementWithNewProps.ts +4 -3
- package/codemods/utils/updateKaioImports.spec.ts +223 -0
- package/codemods/utils/updateKaioImports.ts +233 -0
- package/dist/cjs/Avatar/Avatar.cjs +16 -13
- package/dist/cjs/Calendar/CalendarRange/CalendarRange.cjs +9 -7
- package/dist/cjs/Calendar/CalendarSingle/CalendarSingle.cjs +9 -7
- package/dist/cjs/Calendar/LegacyCalendarRange/LegacyCalendarRange.cjs +9 -7
- package/dist/cjs/Checkbox/Checkbox/Checkbox.cjs +5 -11
- package/dist/cjs/ClearButton/ClearButton.cjs +5 -4
- package/dist/cjs/Collapsible/Collapsible/Collapsible.cjs +4 -7
- package/dist/cjs/DateInput/DateInputWithIconButton/DateInputWithIconButton.cjs +5 -4
- package/dist/cjs/DateRangePicker/DateRangePicker.cjs +5 -4
- package/dist/cjs/ErrorPage/ErrorPage.cjs +9 -7
- package/dist/cjs/FieldMessage/FieldMessage.cjs +5 -11
- package/dist/cjs/Filter/FilterBar/subcomponents/AddFiltersMenu/AddFiltersMenu.cjs +4 -5
- package/dist/cjs/Filter/FilterButton/FilterButton/FilterButton.cjs +4 -7
- package/dist/cjs/Filter/FilterButton/FilterButtonRemovable/FilterButtonRemovable.cjs +5 -5
- package/dist/cjs/Filter/FilterMultiSelect/subcomponents/MultiSelectOption/MultiSelectOption.cjs +4 -4
- package/dist/cjs/GuidanceBlock/GuidanceBlock.cjs +5 -4
- package/dist/cjs/Illustration/utils/usePausePlay.cjs +5 -8
- package/dist/cjs/Input/InputSearch/InputSearch.cjs +4 -3
- package/dist/cjs/LikertScaleLegacy/LikertScaleLegacy.cjs +5 -6
- package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.cjs +31 -26
- package/dist/cjs/Modal/GenericModal/subcomponents/ModalHeader/ModalHeader.cjs +4 -5
- package/dist/cjs/MultiSelect/subcomponents/Checkbox/Checkbox.cjs +7 -17
- package/dist/cjs/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.cjs +4 -7
- package/dist/cjs/Notification/subcomponents/CancelButton/CancelButton.cjs +4 -3
- package/dist/cjs/Notification/subcomponents/NotificationIcon/NotificationIcon.cjs +33 -38
- package/dist/cjs/Notification/subcomponents/NotificationIcon/NotificationIcon.module.css.cjs +6 -0
- package/dist/cjs/Pagination/subcomponents/DirectionalLink/DirectionalLink.cjs +11 -19
- package/dist/cjs/Pagination/subcomponents/TruncateIndicator/TruncateIndicator.cjs +4 -5
- package/dist/cjs/Popover/Popover.cjs +5 -4
- package/dist/cjs/Popover/utils/classMappers.cjs +21 -16
- package/dist/cjs/RichTextEditor/RichTextEditor/utils/controlmap.cjs +29 -25
- package/dist/cjs/RichTextEditor/utils/plugins/LinkManager/components/LinkPopover/LinkPopover.cjs +10 -12
- package/dist/cjs/Select/Select.cjs +8 -10
- package/dist/cjs/SplitButton/subcomponents/DropdownButton/DropdownButton.cjs +4 -4
- package/dist/cjs/Table/Table.cjs +11 -10
- package/dist/cjs/Tag/Tag.cjs +21 -17
- package/dist/cjs/TextField/TextField.cjs +5 -4
- package/dist/cjs/Tile/subcomponents/GenericTile/GenericTile.cjs +8 -7
- package/dist/cjs/TitleBlockZen/TitleBlockZen.cjs +9 -12
- package/dist/cjs/TitleBlockZen/subcomponents/MainActions.cjs +7 -7
- package/dist/cjs/TitleBlockZen/subcomponents/MobileActions.cjs +10 -15
- package/dist/cjs/TitleBlockZen/subcomponents/SecondaryActions.cjs +7 -7
- package/dist/cjs/ToggleSwitch/ToggleSwitch/ToggleSwitch.cjs +5 -5
- package/dist/cjs/Workflow/subcomponents/Footer/components/ProgressStepper/ProgressStepper.cjs +13 -18
- package/dist/cjs/__future__/Icon/Icon.cjs +47 -0
- package/dist/cjs/__future__/Icon/Icon.module.css.cjs +10 -0
- package/dist/cjs/__future__/Icon/constants.cjs +8 -0
- package/dist/cjs/__future__/Select/subcomponents/Option/Option.cjs +4 -5
- package/dist/cjs/__future__/Select/subcomponents/SelectToggle/SelectToggle.cjs +5 -9
- package/dist/cjs/__future__/Tag/RemovableTag/subcomponents/RemoveButton.cjs +4 -3
- package/dist/cjs/future.cjs +2 -0
- package/dist/esm/Avatar/Avatar.mjs +16 -13
- package/dist/esm/Calendar/CalendarRange/CalendarRange.mjs +9 -7
- package/dist/esm/Calendar/CalendarSingle/CalendarSingle.mjs +9 -7
- package/dist/esm/Calendar/LegacyCalendarRange/LegacyCalendarRange.mjs +9 -7
- package/dist/esm/Checkbox/Checkbox/Checkbox.mjs +5 -11
- package/dist/esm/ClearButton/ClearButton.mjs +5 -4
- package/dist/esm/Collapsible/Collapsible/Collapsible.mjs +5 -8
- package/dist/esm/DateInput/DateInputWithIconButton/DateInputWithIconButton.mjs +5 -4
- package/dist/esm/DateRangePicker/DateRangePicker.mjs +5 -4
- package/dist/esm/ErrorPage/ErrorPage.mjs +10 -8
- package/dist/esm/FieldMessage/FieldMessage.mjs +6 -12
- package/dist/esm/Filter/FilterBar/subcomponents/AddFiltersMenu/AddFiltersMenu.mjs +4 -5
- package/dist/esm/Filter/FilterButton/FilterButton/FilterButton.mjs +5 -8
- package/dist/esm/Filter/FilterButton/FilterButtonRemovable/FilterButtonRemovable.mjs +5 -5
- package/dist/esm/Filter/FilterMultiSelect/subcomponents/MultiSelectOption/MultiSelectOption.mjs +4 -4
- package/dist/esm/GuidanceBlock/GuidanceBlock.mjs +5 -4
- package/dist/esm/Illustration/utils/usePausePlay.mjs +5 -8
- package/dist/esm/Input/InputSearch/InputSearch.mjs +4 -3
- package/dist/esm/LikertScaleLegacy/LikertScaleLegacy.mjs +5 -6
- package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.mjs +31 -26
- package/dist/esm/Modal/GenericModal/subcomponents/ModalHeader/ModalHeader.mjs +4 -5
- package/dist/esm/MultiSelect/subcomponents/Checkbox/Checkbox.mjs +7 -17
- package/dist/esm/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.mjs +5 -8
- package/dist/esm/Notification/subcomponents/CancelButton/CancelButton.mjs +4 -3
- package/dist/esm/Notification/subcomponents/NotificationIcon/NotificationIcon.mjs +33 -38
- package/dist/esm/Notification/subcomponents/NotificationIcon/NotificationIcon.module.css.mjs +4 -0
- package/dist/esm/Pagination/subcomponents/DirectionalLink/DirectionalLink.mjs +11 -19
- package/dist/esm/Pagination/subcomponents/TruncateIndicator/TruncateIndicator.mjs +4 -5
- package/dist/esm/Popover/Popover.mjs +5 -4
- package/dist/esm/Popover/utils/classMappers.mjs +21 -16
- package/dist/esm/RichTextEditor/RichTextEditor/utils/controlmap.mjs +33 -29
- package/dist/esm/RichTextEditor/utils/plugins/LinkManager/components/LinkPopover/LinkPopover.mjs +10 -12
- package/dist/esm/Select/Select.mjs +9 -11
- package/dist/esm/SplitButton/subcomponents/DropdownButton/DropdownButton.mjs +4 -4
- package/dist/esm/Table/Table.mjs +11 -10
- package/dist/esm/Tag/Tag.mjs +21 -17
- package/dist/esm/TextField/TextField.mjs +5 -4
- package/dist/esm/Tile/subcomponents/GenericTile/GenericTile.mjs +8 -7
- package/dist/esm/TitleBlockZen/TitleBlockZen.mjs +9 -12
- package/dist/esm/TitleBlockZen/subcomponents/MainActions.mjs +7 -7
- package/dist/esm/TitleBlockZen/subcomponents/MobileActions.mjs +13 -18
- package/dist/esm/TitleBlockZen/subcomponents/SecondaryActions.mjs +7 -7
- package/dist/esm/ToggleSwitch/ToggleSwitch/ToggleSwitch.mjs +5 -5
- package/dist/esm/Workflow/subcomponents/Footer/components/ProgressStepper/ProgressStepper.mjs +16 -21
- package/dist/esm/__future__/Icon/Icon.mjs +38 -0
- package/dist/esm/__future__/Icon/Icon.module.css.mjs +8 -0
- package/dist/esm/__future__/Icon/constants.mjs +6 -0
- package/dist/esm/__future__/Select/subcomponents/Option/Option.mjs +4 -5
- package/dist/esm/__future__/Select/subcomponents/SelectToggle/SelectToggle.mjs +6 -10
- package/dist/esm/__future__/Tag/RemovableTag/subcomponents/RemoveButton.mjs +4 -3
- package/dist/esm/future.mjs +1 -0
- package/dist/styles.css +562 -538
- package/dist/types/__future__/Icon/Icon.d.ts +21 -0
- package/dist/types/__future__/Icon/constants.d.ts +5 -0
- package/dist/types/__future__/Icon/index.d.ts +1 -0
- package/dist/types/__future__/Icon/types.d.ts +4 -0
- package/dist/types/__future__/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/Avatar/Avatar.module.scss +6 -8
- package/src/Avatar/Avatar.tsx +14 -5
- package/src/BrandMoment/_docs/BrandMoment.stories.tsx +6 -10
- package/src/BrandMoment/_docs/ExampleHeaders.tsx +2 -2
- package/src/Calendar/CalendarRange/CalendarRange.tsx +7 -3
- package/src/Calendar/CalendarSingle/CalendarSingle.tsx +7 -3
- package/src/Calendar/LegacyCalendarRange/LegacyCalendarRange.tsx +7 -3
- package/src/Calendar/baseCalendarClassNames.module.scss +0 -4
- package/src/Checkbox/Checkbox/Checkbox.module.scss +0 -8
- package/src/Checkbox/Checkbox/Checkbox.tsx +6 -8
- package/src/ClearButton/ClearButton.tsx +2 -2
- package/src/Collapsible/Collapsible/Collapsible.tsx +5 -6
- package/src/Collapsible/Collapsible/_docs/Collapsible.stories.tsx +2 -2
- package/src/DateInput/DateInputWithIconButton/DateInputWithIconButton.module.scss +2 -7
- package/src/DateInput/DateInputWithIconButton/DateInputWithIconButton.tsx +2 -2
- package/src/DateRangePicker/DateRangePicker.tsx +2 -2
- package/src/EmptyState/_docs/EmptyState.stickersheet.stories.tsx +8 -2
- package/src/EmptyState/_docs/EmptyState.stories.tsx +4 -2
- package/src/ErrorPage/ErrorPage.tsx +5 -3
- package/src/FieldMessage/FieldMessage.tsx +6 -14
- package/src/Filter/FilterBar/FilterBar.spec.tsx +12 -12
- package/src/Filter/FilterBar/subcomponents/AddFiltersMenu/AddFiltersMenu.tsx +2 -2
- package/src/Filter/FilterButton/FilterButton/FilterButton.module.scss +1 -1
- package/src/Filter/FilterButton/FilterButton/FilterButton.tsx +5 -6
- package/src/Filter/FilterButton/FilterButtonRemovable/FilterButtonRemovable.tsx +2 -2
- package/src/Filter/FilterDateRangePicker/FilterDateRangePicker.spec.tsx +0 -1
- package/src/Filter/FilterDateRangePicker/subcomponents/DateRangeInputField/DateRangeInputField.spec.tsx +2 -1
- package/src/Filter/FilterMultiSelect/subcomponents/MultiSelectOption/MultiSelectOption.tsx +2 -2
- package/src/Filter/FilterSelect/FilterSelect.spec.tsx +4 -5
- package/src/GuidanceBlock/GuidanceBlock.tsx +6 -2
- package/src/Icon/_docs/{Icon.stories.tsx → Icon.docs.stories.tsx} +1 -1
- package/src/Icon/_docs/Icon.mdx +1 -2
- package/src/Icon/_docs/Icon.stickersheet.stories.tsx +1 -1
- package/src/Illustration/utils/usePausePlay.tsx +7 -5
- package/src/Input/Input/_docs/Input.stickersheet.stories.tsx +7 -5
- package/src/Input/Input/_docs/Input.stories.tsx +5 -3
- package/src/Input/InputSearch/InputSearch.tsx +2 -2
- package/src/Label/Label.module.scss +4 -0
- package/src/LikertScaleLegacy/LikertScaleLegacy.tsx +2 -2
- package/src/Loading/LoadingGraphic/_docs/LoadingGraphic.stories.tsx +2 -2
- package/src/Modal/ConfirmationModal/ConfirmationModal.module.scss +2 -0
- package/src/Modal/ConfirmationModal/ConfirmationModal.tsx +32 -35
- package/src/Modal/GenericModal/subcomponents/ModalHeader/ModalHeader.tsx +2 -2
- package/src/MultiSelect/MultiSelect.spec.tsx +7 -3
- package/src/MultiSelect/subcomponents/Checkbox/Checkbox.module.scss +0 -6
- package/src/MultiSelect/subcomponents/Checkbox/Checkbox.tsx +10 -9
- package/src/MultiSelect/subcomponents/MultiSelectOptions/MultiSelectOptions.spec.tsx +11 -7
- package/src/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.tsx +5 -7
- package/src/Notification/subcomponents/CancelButton/CancelButton.tsx +2 -2
- package/src/Notification/subcomponents/GenericNotification/_mixins.scss +2 -0
- package/src/Notification/subcomponents/NotificationIcon/NotificationIcon.module.css +3 -0
- package/src/Notification/subcomponents/NotificationIcon/NotificationIcon.tsx +22 -16
- package/src/Pagination/subcomponents/DirectionalLink/DirectionalLink.module.scss +0 -4
- package/src/Pagination/subcomponents/DirectionalLink/DirectionalLink.tsx +13 -12
- package/src/Pagination/subcomponents/TruncateIndicator/TruncateIndicator.module.scss +0 -1
- package/src/Pagination/subcomponents/TruncateIndicator/TruncateIndicator.tsx +2 -2
- package/src/Popover/Popover.module.scss +3 -3
- package/src/Popover/Popover.tsx +2 -2
- package/src/Popover/utils/classMappers.tsx +6 -11
- package/src/RichTextEditor/RichTextEditor/subcomponents/ToggleIconButton/_docs/ToggleIconButton.stickersheet.stories.tsx +7 -7
- package/src/RichTextEditor/RichTextEditor/subcomponents/ToggleIconButton/_docs/ToggleIconButton.stories.tsx +2 -2
- package/src/RichTextEditor/RichTextEditor/subcomponents/Toolbar/Toolbar.spec.tsx +7 -4
- package/src/RichTextEditor/RichTextEditor/subcomponents/Toolbar/_docs/Toolbar.stories.tsx +18 -12
- package/src/RichTextEditor/RichTextEditor/utils/controlmap.tsx +25 -18
- package/src/RichTextEditor/utils/plugins/LinkManager/components/LinkPopover/LinkPopover.tsx +4 -8
- package/src/Select/Select.module.scss +2 -0
- package/src/Select/Select.tsx +10 -7
- package/src/SplitButton/subcomponents/DropdownButton/DropdownButton.spec.tsx +4 -5
- package/src/SplitButton/subcomponents/DropdownButton/DropdownButton.tsx +2 -2
- package/src/Table/Table.tsx +4 -8
- package/src/Table/_docs/Table.stickersheet.stories.tsx +4 -4
- package/src/Table/_docs/Table.stories.tsx +3 -3
- package/src/Tag/Tag.module.scss +2 -0
- package/src/Tag/Tag.tsx +7 -13
- package/src/Text/Text.module.scss +2 -0
- package/src/TextField/TextField.spec.tsx +9 -4
- package/src/TextField/TextField.tsx +2 -2
- package/src/TextField/_docs/TextField.stories.tsx +4 -3
- package/src/Tile/subcomponents/GenericTile/GenericTile.tsx +3 -3
- package/src/TitleBlockZen/TitleBlockZen.module.scss +1 -0
- package/src/TitleBlockZen/TitleBlockZen.spec.tsx +1 -1
- package/src/TitleBlockZen/TitleBlockZen.tsx +6 -9
- package/src/TitleBlockZen/_docs/TitleBlockZen.stories.tsx +5 -5
- package/src/TitleBlockZen/subcomponents/MainActions.tsx +5 -3
- package/src/TitleBlockZen/subcomponents/MobileActions.tsx +13 -16
- package/src/TitleBlockZen/subcomponents/SecondaryActions.tsx +3 -3
- package/src/ToggleSwitch/ToggleSwitch/ToggleSwitch.module.scss +0 -3
- package/src/ToggleSwitch/ToggleSwitch/ToggleSwitch.tsx +2 -2
- package/src/Workflow/_docs/Workflow.stories.tsx +4 -5
- package/src/Workflow/_docs/WorkflowHeader.stories.tsx +4 -5
- package/src/Workflow/_docs/controls/controls.tsx +4 -4
- package/src/Workflow/subcomponents/Footer/components/ProgressStepper/ProgressStepper.tsx +6 -31
- package/src/__actions__/Button/v1/Button/_docs/Button.stickersheet.stories.tsx +5 -5
- package/src/__actions__/Button/v1/Button/_docs/Button.stories.tsx +6 -5
- package/src/__actions__/Button/v1/IconButton/_docs/IconButton.stickersheet.stories.tsx +6 -6
- package/src/__actions__/Button/v1/IconButton/_docs/IconButton.stories.tsx +4 -4
- package/src/__actions__/Button/v2/Button/_docs/Button.stories.tsx +6 -5
- package/src/__actions__/Button/v2/IconButton/_docs/IconButton.stories.tsx +4 -4
- package/src/__actions__/Menu/v1/_docs/Menu.stickersheet.stories.tsx +3 -3
- package/src/__actions__/Menu/v1/_docs/Menu.stories.tsx +3 -3
- package/src/__actions__/Menu/v1/_docs/MenuContentExample.tsx +6 -6
- package/src/__actions__/Menu/v1/_docs/examples.tsx +5 -5
- package/src/__actions__/Menu/v2/_docs/Menu.stories.tsx +3 -3
- package/src/__actions__/Menu/v3/_docs/ApiSpecification.mdx +1 -3
- package/src/__actions__/Menu/v3/_docs/Menu.docs.stories.tsx +46 -45
- package/src/__actions__/Menu/v3/_docs/Menu.mdx +1 -1
- package/src/__actions__/Menu/v3/_docs/Menu.spec.stories.tsx +21 -23
- package/src/__actions__/Menu/v3/_docs/Menu.stories.tsx +12 -15
- package/src/__future__/Icon/Icon.module.css +35 -0
- package/src/__future__/Icon/Icon.spec.tsx +36 -0
- package/src/__future__/Icon/Icon.tsx +85 -0
- package/src/__future__/Icon/_docs/Icon--api-specification.mdx +98 -0
- package/src/__future__/Icon/_docs/Icon--usage-guidelines.mdx +145 -0
- package/src/__future__/Icon/_docs/Icon.docs.module.css +17 -0
- package/src/__future__/Icon/_docs/Icon.docs.stories.tsx +524 -0
- package/src/__future__/Icon/_docs/Icon.stickersheet.stories.tsx +126 -0
- package/src/__future__/Icon/_docs/assets/interface-dont.png +0 -0
- package/src/__future__/Icon/_docs/assets/tooltip-dont.png +0 -0
- package/src/__future__/Icon/constants.ts +149 -0
- package/src/__future__/Icon/index.ts +1 -0
- package/src/__future__/Icon/material-symbols-metadata.json +3370 -0
- package/src/__future__/Icon/types.ts +11 -0
- package/src/__future__/Select/subcomponents/Option/Option.tsx +2 -2
- package/src/__future__/Select/subcomponents/SelectToggle/SelectToggle.module.scss +1 -1
- package/src/__future__/Select/subcomponents/SelectToggle/SelectToggle.tsx +6 -9
- package/src/__future__/Tag/RemovableTag/_docs/RemovableTag.stories.tsx +0 -77
- package/src/__future__/Tag/RemovableTag/subcomponents/RemoveButton.module.scss +0 -56
- package/src/__future__/Tag/RemovableTag/subcomponents/RemoveButton.tsx +2 -12
- package/src/__future__/Tag/Tag/Tag.module.scss +1 -1
- package/src/__future__/Tag/Tag/_docs/Tag-migration-guide.stories.tsx +6 -17
- package/src/__future__/Tag/Tag/_docs/Tag.stickersheet.stories.tsx +5 -2
- package/src/__future__/Tag/Tag/_docs/Tag.stories.tsx +13 -6
- package/src/__future__/index.ts +1 -0
- package/src/__overlays__/Tooltip/v1/_docs/Tooltip.stickersheet.stories.tsx +10 -10
- package/src/__overlays__/Tooltip/v1/_docs/Tooltip.stories.tsx +7 -4
- package/src/__overlays__/Tooltip/v1/utils/isSemanticElement.spec.tsx +4 -11
- package/src/__overlays__/Tooltip/v3/_docs/Tooltip.docs.stories.tsx +10 -10
- package/src/__overlays__/Tooltip/v3/_docs/Tooltip.spec.stories.tsx +3 -3
- package/codemods/utils/getTagName.spec.ts +0 -24
- package/codemods/utils/getTagName.ts +0 -32
- package/dist/cjs/__future__/Tag/RemovableTag/subcomponents/RemoveTagIcon.cjs +0 -23
- package/dist/esm/__future__/Tag/RemovableTag/subcomponents/RemoveTagIcon.mjs +0 -15
- package/dist/types/__future__/Tag/RemovableTag/subcomponents/RemoveTagIcon.d.ts +0 -2
- package/src/__future__/Tag/RemovableTag/subcomponents/RemoveTagIcon.tsx +0 -21
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import {
|
|
3
|
+
createProp,
|
|
4
|
+
createStringProp,
|
|
5
|
+
createStyleProp,
|
|
6
|
+
getPropValueText,
|
|
7
|
+
updateJsxElementWithNewProps,
|
|
8
|
+
} from "../utils"
|
|
9
|
+
|
|
10
|
+
const propsToStyleMap = new Map<string, string>([
|
|
11
|
+
["color", "color"],
|
|
12
|
+
["height", "height"],
|
|
13
|
+
["width", "width"],
|
|
14
|
+
])
|
|
15
|
+
|
|
16
|
+
const transformPropRole = (
|
|
17
|
+
oldValue: string
|
|
18
|
+
): ts.JsxAttribute | null | undefined => {
|
|
19
|
+
switch (oldValue) {
|
|
20
|
+
case "presentation":
|
|
21
|
+
return createProp("isPresentational")
|
|
22
|
+
case "img":
|
|
23
|
+
// `role` is removed and `aria-label` transforms to `alt`
|
|
24
|
+
return null
|
|
25
|
+
default:
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @returns
|
|
32
|
+
* - `ts.JsxAttribute` if the prop should be transformed
|
|
33
|
+
* - `null` if the prop should be removed
|
|
34
|
+
* - `undefined` if the prop should be kept as is
|
|
35
|
+
*/
|
|
36
|
+
const transformIconProp = (
|
|
37
|
+
propName: string,
|
|
38
|
+
propValue: ts.JsxAttributeValue | undefined
|
|
39
|
+
): ts.JsxAttribute | null | undefined => {
|
|
40
|
+
switch (propName) {
|
|
41
|
+
case "role":
|
|
42
|
+
const oldValue = propValue && getPropValueText(propValue)
|
|
43
|
+
return oldValue ? transformPropRole(oldValue) : undefined
|
|
44
|
+
case "aria-label":
|
|
45
|
+
return createProp("alt", propValue)
|
|
46
|
+
case "classNameOverride":
|
|
47
|
+
return createProp("className", propValue)
|
|
48
|
+
// `aria-hidden` is not necessary as `role` will cater for presentational icons
|
|
49
|
+
case "aria-hidden":
|
|
50
|
+
// `fontSize` did nothing for svg icons
|
|
51
|
+
case "fontSize":
|
|
52
|
+
// `viewBox` no longer relevant
|
|
53
|
+
case "viewBox":
|
|
54
|
+
return null
|
|
55
|
+
default:
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const transformIcon = (
|
|
61
|
+
node: ts.JsxOpeningElement | ts.JsxSelfClosingElement,
|
|
62
|
+
name: string,
|
|
63
|
+
isFilled?: boolean
|
|
64
|
+
): ts.Node => {
|
|
65
|
+
const styles: Map<string, ts.JsxAttributeValue> = new Map()
|
|
66
|
+
|
|
67
|
+
const newAttributes = node.attributes.properties.reduce<
|
|
68
|
+
ts.JsxAttributeLike[]
|
|
69
|
+
>((acc, attr) => {
|
|
70
|
+
if (ts.isJsxAttribute(attr)) {
|
|
71
|
+
const propName = attr.name.getText()
|
|
72
|
+
|
|
73
|
+
if (propName === "inheritSize") {
|
|
74
|
+
ts.addSyntheticLeadingComment(
|
|
75
|
+
attr,
|
|
76
|
+
ts.SyntaxKind.SingleLineCommentTrivia,
|
|
77
|
+
' @todo: Apply the correct --icon-size (eg. in Tailwind: className="[--icon-size:48]")',
|
|
78
|
+
true
|
|
79
|
+
)
|
|
80
|
+
acc.push(attr)
|
|
81
|
+
return acc
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (propsToStyleMap.has(propName)) {
|
|
85
|
+
if (attr.initializer) {
|
|
86
|
+
styles.set(propsToStyleMap.get(propName) as string, attr.initializer)
|
|
87
|
+
}
|
|
88
|
+
return acc
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const newProp = transformIconProp(propName, attr.initializer)
|
|
92
|
+
|
|
93
|
+
if (newProp === null) return acc
|
|
94
|
+
|
|
95
|
+
if (newProp) {
|
|
96
|
+
acc.push(newProp)
|
|
97
|
+
return acc
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
acc.push(attr)
|
|
102
|
+
return acc
|
|
103
|
+
}, [])
|
|
104
|
+
|
|
105
|
+
if (styles.size > 0) {
|
|
106
|
+
newAttributes.unshift(createStyleProp(Object.fromEntries(styles.entries())))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isFilled) {
|
|
110
|
+
newAttributes.unshift(createProp("isFilled"))
|
|
111
|
+
}
|
|
112
|
+
newAttributes.unshift(createStringProp("name", name))
|
|
113
|
+
|
|
114
|
+
return updateJsxElementWithNewProps(node, newAttributes, "Icon")
|
|
115
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import { parseJsx } from "../__tests__/utils"
|
|
3
|
+
import { printAst } from "../utils"
|
|
4
|
+
import { transformSpinnerIconToLoadingSpinner } from "./transformSpinnerIconToLoadingSpinner"
|
|
5
|
+
|
|
6
|
+
export const mockedTransformer =
|
|
7
|
+
(alias?: string) =>
|
|
8
|
+
(context: ts.TransformationContext) =>
|
|
9
|
+
(rootNode: ts.Node): ts.Node => {
|
|
10
|
+
const visit = (node: ts.Node): ts.Node => {
|
|
11
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
12
|
+
return transformSpinnerIconToLoadingSpinner(node, alias)
|
|
13
|
+
}
|
|
14
|
+
return ts.visitEachChild(node, visit, context)
|
|
15
|
+
}
|
|
16
|
+
return ts.visitNode(rootNode, visit)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const transformInput = (sourceFile: ts.SourceFile, alias?: string): string => {
|
|
20
|
+
const result = ts.transform(sourceFile, [mockedTransformer(alias)])
|
|
21
|
+
const transformedSource = result.transformed[0] as ts.SourceFile
|
|
22
|
+
return printAst(transformedSource)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("transformSpinnerIconToLoadingSpinner()", () => {
|
|
26
|
+
it("replaces SpinnerIcon with LoadingSpinner and adds size and accessibilityLabel", () => {
|
|
27
|
+
const inputAst = parseJsx("<SpinnerIcon />")
|
|
28
|
+
const outputAst = parseJsx(
|
|
29
|
+
'<LoadingSpinner size="xs" accessibilityLabel="Loading" />'
|
|
30
|
+
)
|
|
31
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("uses alias if it is defined", () => {
|
|
35
|
+
const inputAst = parseJsx("<SpinnerIcon />")
|
|
36
|
+
const outputAst = parseJsx(
|
|
37
|
+
'<KzLoadingSpinner size="xs" accessibilityLabel="Loading" />'
|
|
38
|
+
)
|
|
39
|
+
expect(transformInput(inputAst, "KzLoadingSpinner")).toEqual(
|
|
40
|
+
printAst(outputAst)
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe("transform existing props", () => {
|
|
45
|
+
it("removes role and changes aria-label to accessibilityLabel or fallback", () => {
|
|
46
|
+
const inputAst = parseJsx(`
|
|
47
|
+
export const TestComponent = () => (
|
|
48
|
+
<>
|
|
49
|
+
<SpinnerIcon role="presentation" />
|
|
50
|
+
<SpinnerIcon role="img" aria-label="I am loading" />
|
|
51
|
+
</>
|
|
52
|
+
)
|
|
53
|
+
`)
|
|
54
|
+
const outputAst = parseJsx(`
|
|
55
|
+
export const TestComponent = () => (
|
|
56
|
+
<>
|
|
57
|
+
<LoadingSpinner size="xs" accessibilityLabel="Loading" />
|
|
58
|
+
<LoadingSpinner size="xs" accessibilityLabel="I am loading" />
|
|
59
|
+
</>
|
|
60
|
+
)
|
|
61
|
+
`)
|
|
62
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it("leaves classNameOverride as is", () => {
|
|
66
|
+
const inputAst = parseJsx('<SpinnerIcon classNameOverride="mt-16" />')
|
|
67
|
+
const outputAst = parseJsx(
|
|
68
|
+
'<LoadingSpinner size="xs" accessibilityLabel="Loading" classNameOverride="mt-16" />'
|
|
69
|
+
)
|
|
70
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("removes viewBox", () => {
|
|
74
|
+
const inputAst = parseJsx('<SpinnerIcon viewBox="0 0 100 100" />')
|
|
75
|
+
const outputAst = parseJsx(
|
|
76
|
+
'<LoadingSpinner size="xs" accessibilityLabel="Loading" />'
|
|
77
|
+
)
|
|
78
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import {
|
|
3
|
+
createStringProp,
|
|
4
|
+
getPropValueText,
|
|
5
|
+
updateJsxElementWithNewProps,
|
|
6
|
+
} from "../utils"
|
|
7
|
+
|
|
8
|
+
export const transformSpinnerIconToLoadingSpinner = (
|
|
9
|
+
node: ts.JsxOpeningElement | ts.JsxSelfClosingElement,
|
|
10
|
+
tagName: string = "LoadingSpinner"
|
|
11
|
+
): ts.Node => {
|
|
12
|
+
let accessibilityLabel = "Loading"
|
|
13
|
+
const newAttributes = node.attributes.properties.reduce<
|
|
14
|
+
ts.JsxAttributeLike[]
|
|
15
|
+
>((acc, attr) => {
|
|
16
|
+
if (ts.isJsxAttribute(attr)) {
|
|
17
|
+
const propName = attr.name.getText()
|
|
18
|
+
|
|
19
|
+
if (propName === "role") return acc
|
|
20
|
+
if (propName === "viewBox") return acc
|
|
21
|
+
|
|
22
|
+
if (propName === "aria-label") {
|
|
23
|
+
const value = attr.initializer && getPropValueText(attr.initializer)
|
|
24
|
+
if (value) {
|
|
25
|
+
accessibilityLabel = value
|
|
26
|
+
}
|
|
27
|
+
return acc
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
acc.push(attr)
|
|
32
|
+
return acc
|
|
33
|
+
}, [])
|
|
34
|
+
|
|
35
|
+
newAttributes.unshift(
|
|
36
|
+
createStringProp("accessibilityLabel", accessibilityLabel)
|
|
37
|
+
)
|
|
38
|
+
newAttributes.unshift(createStringProp("size", "xs"))
|
|
39
|
+
|
|
40
|
+
return updateJsxElementWithNewProps(node, newAttributes, tagName)
|
|
41
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { parseJsx } from "../__tests__/utils"
|
|
2
|
+
import {
|
|
3
|
+
transformSource,
|
|
4
|
+
printAst,
|
|
5
|
+
TransformConfig,
|
|
6
|
+
ImportModuleNameTagsMap,
|
|
7
|
+
} from "../utils"
|
|
8
|
+
import { upgradeIconV1 } from "./upgradeIconV1"
|
|
9
|
+
|
|
10
|
+
const transformIcons = (
|
|
11
|
+
sourceFile: TransformConfig["sourceFile"],
|
|
12
|
+
tagNames: ImportModuleNameTagsMap
|
|
13
|
+
): string =>
|
|
14
|
+
transformSource({
|
|
15
|
+
sourceFile,
|
|
16
|
+
astTransformer: upgradeIconV1,
|
|
17
|
+
tagName: tagNames,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("upgradeIconV1()", () => {
|
|
21
|
+
describe("CaMonogramIcon to Brand", () => {
|
|
22
|
+
const transformedBrandProps = 'variant="enso" style={{ width: "20px" }}'
|
|
23
|
+
|
|
24
|
+
it("updates import from CaMonogramIcon to Brand", () => {
|
|
25
|
+
const inputAst = parseJsx(`
|
|
26
|
+
import { CaMonogramIcon } from "@kaizen/components"
|
|
27
|
+
export const TestComponent = () => <CaMonogramIcon />
|
|
28
|
+
`)
|
|
29
|
+
const outputAst = parseJsx(`
|
|
30
|
+
import { Brand } from "@kaizen/components"
|
|
31
|
+
export const TestComponent = () => <Brand ${transformedBrandProps} />
|
|
32
|
+
`)
|
|
33
|
+
expect(
|
|
34
|
+
transformIcons(
|
|
35
|
+
inputAst,
|
|
36
|
+
new Map([
|
|
37
|
+
[
|
|
38
|
+
"@kaizen/components",
|
|
39
|
+
new Map([["CaMonogramIcon", "CaMonogramIcon"]]),
|
|
40
|
+
],
|
|
41
|
+
])
|
|
42
|
+
)
|
|
43
|
+
).toEqual(printAst(outputAst))
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("updates import from CaMonogramIcon using alias to Brand", () => {
|
|
47
|
+
const inputAst = parseJsx(`
|
|
48
|
+
import { CaMonogramIcon as LogoAlias } from "@kaizen/components"
|
|
49
|
+
export const TestComponent = () => <LogoAlias />
|
|
50
|
+
`)
|
|
51
|
+
const outputAst = parseJsx(`
|
|
52
|
+
import { Brand } from "@kaizen/components"
|
|
53
|
+
export const TestComponent = () => <Brand ${transformedBrandProps} />
|
|
54
|
+
`)
|
|
55
|
+
expect(
|
|
56
|
+
transformIcons(
|
|
57
|
+
inputAst,
|
|
58
|
+
new Map([
|
|
59
|
+
["@kaizen/components", new Map([["LogoAlias", "CaMonogramIcon"]])],
|
|
60
|
+
])
|
|
61
|
+
)
|
|
62
|
+
).toEqual(printAst(outputAst))
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it("does not add another Brand import if it is already imported", () => {
|
|
66
|
+
const inputAst = parseJsx(`
|
|
67
|
+
import { Brand, CaMonogramIcon } from "@kaizen/components"
|
|
68
|
+
export const TestComponent = () => <CaMonogramIcon />
|
|
69
|
+
`)
|
|
70
|
+
const outputAst = parseJsx(`
|
|
71
|
+
import { Brand } from "@kaizen/components"
|
|
72
|
+
export const TestComponent = () => <Brand ${transformedBrandProps} />
|
|
73
|
+
`)
|
|
74
|
+
expect(
|
|
75
|
+
transformIcons(
|
|
76
|
+
inputAst,
|
|
77
|
+
new Map([
|
|
78
|
+
[
|
|
79
|
+
"@kaizen/components",
|
|
80
|
+
new Map([
|
|
81
|
+
["Brand", "Brand"],
|
|
82
|
+
["CaMonogramIcon", "CaMonogramIcon"],
|
|
83
|
+
]),
|
|
84
|
+
],
|
|
85
|
+
])
|
|
86
|
+
)
|
|
87
|
+
).toEqual(printAst(outputAst))
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it("uses Brand alias for an existing import", () => {
|
|
91
|
+
const inputAst = parseJsx(`
|
|
92
|
+
import { Brand as KzBrand, CaMonogramIcon } from "@kaizen/components"
|
|
93
|
+
export const TestComponent = () => <CaMonogramIcon />
|
|
94
|
+
`)
|
|
95
|
+
const outputAst = parseJsx(`
|
|
96
|
+
import { Brand as KzBrand } from "@kaizen/components"
|
|
97
|
+
export const TestComponent = () => <KzBrand ${transformedBrandProps} />
|
|
98
|
+
`)
|
|
99
|
+
expect(
|
|
100
|
+
transformIcons(
|
|
101
|
+
inputAst,
|
|
102
|
+
new Map([
|
|
103
|
+
[
|
|
104
|
+
"@kaizen/components",
|
|
105
|
+
new Map([
|
|
106
|
+
["KzBrand", "Brand"],
|
|
107
|
+
["CaMonogramIcon", "CaMonogramIcon"],
|
|
108
|
+
]),
|
|
109
|
+
],
|
|
110
|
+
])
|
|
111
|
+
)
|
|
112
|
+
).toEqual(printAst(outputAst))
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe("SpinnerIcon to LoadingSpinner", () => {
|
|
117
|
+
const transformedLoadingSpinnerProps =
|
|
118
|
+
'size="xs" accessibilityLabel="Loading"'
|
|
119
|
+
|
|
120
|
+
it("updates import from SpinnerIcon to LoadingSpinner", () => {
|
|
121
|
+
const inputAst = parseJsx(`
|
|
122
|
+
import { SpinnerIcon } from "@kaizen/components"
|
|
123
|
+
export const TestComponent = () => <SpinnerIcon />
|
|
124
|
+
`)
|
|
125
|
+
const outputAst = parseJsx(`
|
|
126
|
+
import { LoadingSpinner } from "@kaizen/components"
|
|
127
|
+
export const TestComponent = () => <LoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
128
|
+
`)
|
|
129
|
+
expect(
|
|
130
|
+
transformIcons(
|
|
131
|
+
inputAst,
|
|
132
|
+
new Map([
|
|
133
|
+
["@kaizen/components", new Map([["SpinnerIcon", "SpinnerIcon"]])],
|
|
134
|
+
])
|
|
135
|
+
)
|
|
136
|
+
).toEqual(printAst(outputAst))
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it("updates import from SpinnerIcon using alias to LoadingSpinner", () => {
|
|
140
|
+
const inputAst = parseJsx(`
|
|
141
|
+
import { SpinnerIcon as LogoAlias } from "@kaizen/components"
|
|
142
|
+
export const TestComponent = () => <LogoAlias />
|
|
143
|
+
`)
|
|
144
|
+
const outputAst = parseJsx(`
|
|
145
|
+
import { LoadingSpinner } from "@kaizen/components"
|
|
146
|
+
export const TestComponent = () => <LoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
147
|
+
`)
|
|
148
|
+
expect(
|
|
149
|
+
transformIcons(
|
|
150
|
+
inputAst,
|
|
151
|
+
new Map([
|
|
152
|
+
["@kaizen/components", new Map([["LogoAlias", "SpinnerIcon"]])],
|
|
153
|
+
])
|
|
154
|
+
)
|
|
155
|
+
).toEqual(printAst(outputAst))
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it("does not add another LoadingSpinner import if it is already imported", () => {
|
|
159
|
+
const inputAst = parseJsx(`
|
|
160
|
+
import { LoadingSpinner, SpinnerIcon } from "@kaizen/components"
|
|
161
|
+
export const TestComponent = () => <SpinnerIcon />
|
|
162
|
+
`)
|
|
163
|
+
const outputAst = parseJsx(`
|
|
164
|
+
import { LoadingSpinner } from "@kaizen/components"
|
|
165
|
+
export const TestComponent = () => <LoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
166
|
+
`)
|
|
167
|
+
expect(
|
|
168
|
+
transformIcons(
|
|
169
|
+
inputAst,
|
|
170
|
+
new Map([
|
|
171
|
+
[
|
|
172
|
+
"@kaizen/components",
|
|
173
|
+
new Map([
|
|
174
|
+
["LoadingSpinner", "LoadingSpinner"],
|
|
175
|
+
["SpinnerIcon", "SpinnerIcon"],
|
|
176
|
+
]),
|
|
177
|
+
],
|
|
178
|
+
])
|
|
179
|
+
)
|
|
180
|
+
).toEqual(printAst(outputAst))
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it("uses LoadingSpinner alias for an existing import", () => {
|
|
184
|
+
const inputAst = parseJsx(`
|
|
185
|
+
import { LoadingSpinner as KzLoadingSpinner, SpinnerIcon } from "@kaizen/components"
|
|
186
|
+
export const TestComponent = () => <SpinnerIcon />
|
|
187
|
+
`)
|
|
188
|
+
const outputAst = parseJsx(`
|
|
189
|
+
import { LoadingSpinner as KzLoadingSpinner } from "@kaizen/components"
|
|
190
|
+
export const TestComponent = () => <KzLoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
191
|
+
`)
|
|
192
|
+
expect(
|
|
193
|
+
transformIcons(
|
|
194
|
+
inputAst,
|
|
195
|
+
new Map([
|
|
196
|
+
[
|
|
197
|
+
"@kaizen/components",
|
|
198
|
+
new Map([
|
|
199
|
+
["KzLoadingSpinner", "LoadingSpinner"],
|
|
200
|
+
["SpinnerIcon", "SpinnerIcon"],
|
|
201
|
+
]),
|
|
202
|
+
],
|
|
203
|
+
])
|
|
204
|
+
)
|
|
205
|
+
).toEqual(printAst(outputAst))
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it("transforms old Icon", () => {
|
|
210
|
+
const inputAst = parseJsx(`
|
|
211
|
+
import { FlagOnIcon } from "@kaizen/components"
|
|
212
|
+
export const TestComponent = () => <FlagOnIcon />
|
|
213
|
+
`)
|
|
214
|
+
const outputAst = parseJsx(`
|
|
215
|
+
import { Icon } from "@kaizen/components/future"
|
|
216
|
+
export const TestComponent = () => <Icon name="flag" isFilled />
|
|
217
|
+
`)
|
|
218
|
+
expect(
|
|
219
|
+
transformIcons(
|
|
220
|
+
inputAst,
|
|
221
|
+
new Map([
|
|
222
|
+
["@kaizen/components", new Map([["FlagOnIcon", "FlagOnIcon"]])],
|
|
223
|
+
])
|
|
224
|
+
)
|
|
225
|
+
).toEqual(printAst(outputAst))
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it("transforms aliased old Icon", () => {
|
|
229
|
+
const inputAst = parseJsx(`
|
|
230
|
+
import { HamburgerIcon as IconAlias } from "@kaizen/components"
|
|
231
|
+
export const TestComponent = () => <IconAlias />
|
|
232
|
+
`)
|
|
233
|
+
const outputAst = parseJsx(`
|
|
234
|
+
import { Icon } from "@kaizen/components/future"
|
|
235
|
+
export const TestComponent = () => <Icon name="menu" />
|
|
236
|
+
`)
|
|
237
|
+
expect(
|
|
238
|
+
transformIcons(
|
|
239
|
+
inputAst,
|
|
240
|
+
new Map([
|
|
241
|
+
["@kaizen/components", new Map([["IconAlias", "HamburgerIcon"]])],
|
|
242
|
+
])
|
|
243
|
+
)
|
|
244
|
+
).toEqual(printAst(outputAst))
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
describe("import statements", () => {
|
|
248
|
+
it("does not update import of components which are not Icons", () => {
|
|
249
|
+
const inputAst = parseJsx(`
|
|
250
|
+
import { AddIcon, Card } from "@kaizen/components"
|
|
251
|
+
export const TestComponent = () => <Card><AddIcon /></Card>
|
|
252
|
+
`)
|
|
253
|
+
const outputAst = parseJsx(`
|
|
254
|
+
import { Card } from "@kaizen/components"
|
|
255
|
+
import { Icon } from "@kaizen/components/future"
|
|
256
|
+
export const TestComponent = () => <Card><Icon name="add" /></Card>
|
|
257
|
+
`)
|
|
258
|
+
expect(
|
|
259
|
+
transformIcons(
|
|
260
|
+
inputAst,
|
|
261
|
+
new Map([["@kaizen/components", new Map([["AddIcon", "AddIcon"]])]])
|
|
262
|
+
)
|
|
263
|
+
).toEqual(printAst(outputAst))
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it("does not update import of components which are not from KAIO", () => {
|
|
267
|
+
const inputAst = parseJsx(`
|
|
268
|
+
import { AddIcon, HamburgerIcon as IconAlias } from "@kaizen/components"
|
|
269
|
+
import { HamburgerIcon as HamHam } from "somewhere-else"
|
|
270
|
+
export const TestComponent = () => (
|
|
271
|
+
<>
|
|
272
|
+
<AddIcon />
|
|
273
|
+
<IconAlias />
|
|
274
|
+
<HamHam />
|
|
275
|
+
</>
|
|
276
|
+
)
|
|
277
|
+
`)
|
|
278
|
+
const outputAst = parseJsx(`
|
|
279
|
+
import { Icon } from "@kaizen/components/future"
|
|
280
|
+
import { HamburgerIcon as HamHam } from "somewhere-else"
|
|
281
|
+
export const TestComponent = () => (
|
|
282
|
+
<>
|
|
283
|
+
<Icon name="add" />
|
|
284
|
+
<Icon name="menu" />
|
|
285
|
+
<HamHam />
|
|
286
|
+
</>
|
|
287
|
+
)
|
|
288
|
+
`)
|
|
289
|
+
expect(
|
|
290
|
+
transformIcons(
|
|
291
|
+
inputAst,
|
|
292
|
+
new Map([
|
|
293
|
+
[
|
|
294
|
+
"@kaizen/components",
|
|
295
|
+
new Map([
|
|
296
|
+
["AddIcon", "AddIcon"],
|
|
297
|
+
["IconAlias", "HamburgerIcon"],
|
|
298
|
+
]),
|
|
299
|
+
],
|
|
300
|
+
["somewhere-else", new Map([["HamHam", "HamburgerIcon"]])],
|
|
301
|
+
])
|
|
302
|
+
)
|
|
303
|
+
).toEqual(printAst(outputAst))
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import {
|
|
3
|
+
setImportToRemove,
|
|
4
|
+
ImportModuleNameTagsMap,
|
|
5
|
+
updateKaioImports,
|
|
6
|
+
UpdateKaioImportsArgs,
|
|
7
|
+
setImportToAdd,
|
|
8
|
+
} from "../utils"
|
|
9
|
+
import { getNewIconPropsFromOldIconName } from "./getNewIconPropsFromOldIconName"
|
|
10
|
+
import { transformCaMonogramIconToBrand } from "./transformCaMonogramIconToBrand"
|
|
11
|
+
import { transformIcon } from "./transformIcon"
|
|
12
|
+
import { transformSpinnerIconToLoadingSpinner } from "./transformSpinnerIconToLoadingSpinner"
|
|
13
|
+
|
|
14
|
+
const reverseStringMap = <Key extends string, Value extends string>(
|
|
15
|
+
map: Map<Key, Value>
|
|
16
|
+
): Map<Value, Key> => {
|
|
17
|
+
const reverseMap = new Map<Value, Key>()
|
|
18
|
+
map.forEach((value, key) => reverseMap.set(value, key))
|
|
19
|
+
return reverseMap
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const upgradeIconV1 =
|
|
23
|
+
(context: ts.TransformationContext, tagNames: ImportModuleNameTagsMap) =>
|
|
24
|
+
(rootNode: ts.Node): ts.Node => {
|
|
25
|
+
const oldImportSource = "@kaizen/components"
|
|
26
|
+
|
|
27
|
+
const kaioTagNames = tagNames.get(oldImportSource)
|
|
28
|
+
if (!kaioTagNames) return rootNode
|
|
29
|
+
|
|
30
|
+
const componentToAliasMap = reverseStringMap(kaioTagNames)
|
|
31
|
+
const importsToRemove =
|
|
32
|
+
new Map() satisfies UpdateKaioImportsArgs["importsToRemove"]
|
|
33
|
+
const importsToAdd =
|
|
34
|
+
new Map() satisfies UpdateKaioImportsArgs["importsToAdd"]
|
|
35
|
+
|
|
36
|
+
const visit = (node: ts.Node): ts.Node => {
|
|
37
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
38
|
+
const tagName = node.tagName.getText()
|
|
39
|
+
const kaioComponentName = kaioTagNames.get(tagName)
|
|
40
|
+
|
|
41
|
+
if (kaioComponentName === "CaMonogramIcon") {
|
|
42
|
+
setImportToRemove(importsToRemove, oldImportSource, kaioComponentName)
|
|
43
|
+
const alias = componentToAliasMap.get("Brand") as string
|
|
44
|
+
|
|
45
|
+
if (!kaioTagNames.has(alias)) {
|
|
46
|
+
setImportToAdd(importsToAdd, "@kaizen/components", {
|
|
47
|
+
componentName: "Brand",
|
|
48
|
+
alias: alias !== "Brand" ? alias : undefined,
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
return transformCaMonogramIconToBrand(node, alias)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (kaioComponentName === "SpinnerIcon") {
|
|
55
|
+
setImportToRemove(importsToRemove, oldImportSource, kaioComponentName)
|
|
56
|
+
const alias = componentToAliasMap.get("LoadingSpinner") as string
|
|
57
|
+
|
|
58
|
+
if (!kaioTagNames.has(alias)) {
|
|
59
|
+
setImportToAdd(importsToAdd, "@kaizen/components", {
|
|
60
|
+
componentName: "LoadingSpinner",
|
|
61
|
+
alias: alias !== "LoadingSpinner" ? alias : undefined,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
return transformSpinnerIconToLoadingSpinner(node, alias)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (kaioComponentName) {
|
|
68
|
+
const newIconProps = getNewIconPropsFromOldIconName(kaioComponentName)
|
|
69
|
+
if (newIconProps === undefined) {
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
71
|
+
console.info(
|
|
72
|
+
"SKIPPED - No new icon equivalent found for",
|
|
73
|
+
node.tagName.getText()
|
|
74
|
+
)
|
|
75
|
+
return node
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setImportToRemove(importsToRemove, oldImportSource, kaioComponentName)
|
|
79
|
+
setImportToAdd(importsToAdd, "@kaizen/components/future", {
|
|
80
|
+
componentName: "Icon",
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
return transformIcon(node, newIconProps.name, newIconProps.isFilled)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ts.visitEachChild(node, visit, context)
|
|
87
|
+
}
|
|
88
|
+
const node = ts.visitNode(rootNode, visit)
|
|
89
|
+
|
|
90
|
+
return updateKaioImports({
|
|
91
|
+
importsToRemove: importsToRemove.size > 0 ? importsToRemove : undefined,
|
|
92
|
+
importsToAdd: importsToAdd.size > 0 ? importsToAdd : undefined,
|
|
93
|
+
})(context)(node)
|
|
94
|
+
}
|