@kaizen/components 1.61.2 → 1.62.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 +0 -1
- package/dist/cjs/{__containers__/GuidanceBlock/v2 → GuidanceBlock}/GuidanceBlock.cjs +6 -6
- package/dist/cjs/GuidanceBlock/GuidanceBlock.module.scss.cjs +33 -0
- package/dist/cjs/Modal/ConfirmationModal/ConfirmationModal.cjs +1 -1
- package/dist/cjs/__future__/Select/Select.cjs +1 -6
- package/dist/cjs/__future__/Select/subcomponents/ListBox/ListBox.cjs +1 -2
- package/dist/cjs/__future__/Select/subcomponents/ListBox/ListBox.module.scss.cjs +1 -2
- package/dist/cjs/__layout__/Workflow/v2/subcomponents/Footer/components/ProgressStepper/ProgressStepper.cjs +2 -4
- package/dist/cjs/__layout__/Workflow/v3/subcomponents/Footer/components/ProgressStepper/ProgressStepper.cjs +2 -3
- package/dist/cjs/index.cjs +2 -2
- package/dist/esm/{__containers__/GuidanceBlock/v2 → GuidanceBlock}/GuidanceBlock.mjs +6 -6
- package/dist/esm/GuidanceBlock/GuidanceBlock.module.scss.mjs +31 -0
- package/dist/esm/Modal/ConfirmationModal/ConfirmationModal.mjs +1 -1
- package/dist/esm/__future__/Select/Select.mjs +1 -6
- package/dist/esm/__future__/Select/subcomponents/ListBox/ListBox.mjs +1 -2
- package/dist/esm/__future__/Select/subcomponents/ListBox/ListBox.module.scss.mjs +1 -2
- package/dist/esm/__layout__/Workflow/v2/subcomponents/Footer/components/ProgressStepper/ProgressStepper.mjs +2 -4
- package/dist/esm/__layout__/Workflow/v3/subcomponents/Footer/components/ProgressStepper/ProgressStepper.mjs +2 -3
- package/dist/esm/index.mjs +1 -1
- package/dist/styles.css +1450 -1777
- package/dist/types/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/GuidanceBlock.d.ts +4 -4
- package/dist/types/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/Collapsible/Collapsible/_docs/Collapsible.mdx +0 -2
- package/src/Filter/FilterSelect/FilterSelect.spec.tsx +1 -3
- package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/GuidanceBlock.module.scss +2 -2
- package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/_docs/GuidanceBlock.mdx +2 -2
- package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/_docs/GuidanceBlock.stickersheet.stories.tsx +1 -1
- package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/_docs/GuidanceBlock.stories.tsx +1 -1
- package/src/Modal/ConfirmationModal/ConfirmationModal.tsx +5 -1
- package/src/MultiSelect/subcomponents/Popover/Popover.module.scss +1 -0
- package/src/__future__/Select/Select.spec.tsx +4 -4
- package/src/__future__/Select/Select.tsx +1 -10
- package/src/__future__/Select/subcomponents/ListBox/ListBox.module.scss +3 -3
- package/src/__future__/Select/subcomponents/ListBox/ListBox.tsx +1 -1
- package/src/__layout__/Workflow/v2/subcomponents/Footer/components/ProgressStepper/ProgressStepper.module.scss +8 -2
- package/src/__layout__/Workflow/v2/subcomponents/Footer/components/ProgressStepper/ProgressStepper.tsx +2 -7
- package/src/__layout__/Workflow/v3/subcomponents/Footer/components/ProgressStepper/ProgressStepper.module.css +5 -0
- package/src/__layout__/Workflow/v3/subcomponents/Footer/components/ProgressStepper/ProgressStepper.tsx +2 -6
- package/src/index.ts +1 -2
- package/codemods/updateGuidanceBlockVariantProp/index.ts +0 -19
- package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.spec.ts +0 -135
- package/codemods/updateGuidanceBlockVariantProp/transformGuidanceBlockVariantProp.ts +0 -77
- package/dist/cjs/__containers__/GuidanceBlock/v1/GuidanceBlock.cjs +0 -160
- package/dist/cjs/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.cjs +0 -33
- package/dist/cjs/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.cjs +0 -28
- package/dist/cjs/containersV1.cjs +0 -4
- package/dist/cjs/containersV2.cjs +0 -4
- package/dist/esm/__containers__/GuidanceBlock/v1/GuidanceBlock.mjs +0 -153
- package/dist/esm/__containers__/GuidanceBlock/v1/GuidanceBlock.module.scss.mjs +0 -31
- package/dist/esm/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss.mjs +0 -26
- package/dist/esm/containersV1.mjs +0 -1
- package/dist/esm/containersV2.mjs +0 -1
- package/dist/types/__containers__/GuidanceBlock/v2/GuidanceBlock.d.ts +0 -59
- package/dist/types/__containers__/GuidanceBlock/v2/index.d.ts +0 -1
- package/dist/types/__containers__/v1.d.ts +0 -1
- package/dist/types/__containers__/v2.d.ts +0 -1
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.module.scss +0 -356
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.spec.tsx +0 -82
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.tsx +0 -262
- package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.mdx +0 -38
- package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stickersheet.stories.tsx +0 -118
- package/src/__containers__/GuidanceBlock/v2/_docs/GuidanceBlock.stories.tsx +0 -152
- package/src/__containers__/GuidanceBlock/v2/index.ts +0 -1
- package/src/__containers__/v1.ts +0 -1
- package/src/__containers__/v2.ts +0 -1
- package/v1/containers/package.json +0 -5
- package/v2/containers/package.json +0 -5
- /package/dist/types/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/index.d.ts +0 -0
- /package/dist/types/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/types.d.ts +0 -0
- /package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/GuidanceBlock.spec.tsx +0 -0
- /package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/GuidanceBlock.tsx +0 -0
- /package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/index.ts +0 -0
- /package/src/{__containers__/GuidanceBlock/v1 → GuidanceBlock}/types.ts +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { HeadingProps } from "
|
|
3
|
-
import { SceneProps, SpotProps } from "
|
|
4
|
-
import { ButtonProps } from "
|
|
5
|
-
import { TooltipProps } from "
|
|
2
|
+
import { HeadingProps } from "../Heading";
|
|
3
|
+
import { SceneProps, SpotProps } from "../Illustration";
|
|
4
|
+
import { ButtonProps } from "../__actions__/v2";
|
|
5
|
+
import { TooltipProps } from "../__overlays__/Tooltip/v1";
|
|
6
6
|
import { VariantType } from "./types";
|
|
7
7
|
export type ActionProps = ButtonProps & {
|
|
8
8
|
tooltip?: TooltipProps;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from "./ErrorPage";
|
|
|
20
20
|
export * from "./FieldGroup";
|
|
21
21
|
export * from "./FieldMessage";
|
|
22
22
|
export * from "./Filter";
|
|
23
|
+
export * from "./GuidanceBlock";
|
|
23
24
|
export * from "./Heading";
|
|
24
25
|
export * from "./Icon";
|
|
25
26
|
export * from "./Illustration";
|
|
@@ -60,4 +61,3 @@ export * from "./__layout__/Workflow/v1";
|
|
|
60
61
|
export * from "./__overlays__/Tooltip/v1";
|
|
61
62
|
export * from "./__actions__/Menu/v1";
|
|
62
63
|
export * from "./__actions__/Button/v1";
|
|
63
|
-
export * from "./__containers__/GuidanceBlock/v1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaizen/components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.62.0",
|
|
4
4
|
"description": "Kaizen component library",
|
|
5
5
|
"author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
|
|
6
6
|
"homepage": "https://cultureamp.design",
|
|
@@ -120,8 +120,8 @@
|
|
|
120
120
|
"svgo": "^3.3.2",
|
|
121
121
|
"tslib": "^2.6.3",
|
|
122
122
|
"tsx": "^4.17.0",
|
|
123
|
-
"@kaizen/design-tokens": "10.6.
|
|
124
|
-
"@kaizen/package-bundler": "1.1.
|
|
123
|
+
"@kaizen/design-tokens": "10.6.1",
|
|
124
|
+
"@kaizen/package-bundler": "1.1.5"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
127
|
"@cultureamp/i18n-react-intl": "^2.5.9",
|
|
@@ -30,8 +30,6 @@ Collapsibles are used to collapse and expand content inline on a page. This lets
|
|
|
30
30
|
|
|
31
31
|
<DocsStory of={CollapsibleStories.CustomHeader} />
|
|
32
32
|
|
|
33
|
-
<DocsStory of={CollapsibleStories.Sticky} sourceState="shown" />
|
|
34
|
-
|
|
35
33
|
### Controlled
|
|
36
34
|
|
|
37
35
|
Control the open state using a `useState` (or similar) by setting the `controlled` prop to `true`
|
|
@@ -107,9 +107,7 @@ describe("<FilterSelect>", () => {
|
|
|
107
107
|
render(<FilterSelectWrapper isOpen />)
|
|
108
108
|
expect(screen.queryByRole("listbox")).toBeVisible()
|
|
109
109
|
await waitFor(() => {
|
|
110
|
-
expect(
|
|
111
|
-
screen.queryByRole("option", { name: "Regular" })
|
|
112
|
-
).toHaveFocus()
|
|
110
|
+
expect(screen.queryByRole("listbox")).toHaveFocus()
|
|
113
111
|
})
|
|
114
112
|
})
|
|
115
113
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
@import "~@kaizen/design-tokens/sass/color";
|
|
5
5
|
@import "~@kaizen/design-tokens/sass/animation";
|
|
6
6
|
@import "~@kaizen/design-tokens/sass/spacing";
|
|
7
|
-
@import "
|
|
8
|
-
@import "
|
|
7
|
+
@import "../../styles/utils/responsive";
|
|
8
|
+
@import "../../styles/utils/button-reset";
|
|
9
9
|
|
|
10
10
|
@mixin guidance-block-under-480 {
|
|
11
11
|
@media (max-width: 480px) {
|
|
@@ -4,7 +4,7 @@ import * as GuidanceBlockStories from "./GuidanceBlock.stories"
|
|
|
4
4
|
|
|
5
5
|
<Meta of={GuidanceBlockStories} />
|
|
6
6
|
|
|
7
|
-
# GuidanceBlock
|
|
7
|
+
# GuidanceBlock
|
|
8
8
|
|
|
9
9
|
<ResourceLinks
|
|
10
10
|
sourceCode="https://github.com/cultureamp/kaizen-design-system/tree/main/packages/components/src/GuidanceBlock"
|
|
@@ -13,7 +13,7 @@ import * as GuidanceBlockStories from "./GuidanceBlock.stories"
|
|
|
13
13
|
|
|
14
14
|
/>
|
|
15
15
|
|
|
16
|
-
<KAIOInstallation exportNames="GuidanceBlock"
|
|
16
|
+
<KAIOInstallation exportNames="GuidanceBlock" />
|
|
17
17
|
|
|
18
18
|
## Overview
|
|
19
19
|
|
|
@@ -12,7 +12,7 @@ import { GuidanceBlock, GuidanceBlockProps } from "../index"
|
|
|
12
12
|
import { variantsMap } from "../types"
|
|
13
13
|
|
|
14
14
|
export default {
|
|
15
|
-
title: "Containers/GuidanceBlock
|
|
15
|
+
title: "Containers/GuidanceBlock",
|
|
16
16
|
parameters: {
|
|
17
17
|
chromatic: { disable: false },
|
|
18
18
|
controls: { disable: true },
|
|
@@ -210,7 +210,11 @@ export const ConfirmationModal = ({
|
|
|
210
210
|
</ModalBody>
|
|
211
211
|
<ModalFooter
|
|
212
212
|
actions={footerActions}
|
|
213
|
-
appearance={
|
|
213
|
+
appearance={
|
|
214
|
+
mood === "negative" || variant == "warning"
|
|
215
|
+
? "destructive"
|
|
216
|
+
: "primary"
|
|
217
|
+
}
|
|
214
218
|
unpadded={unpadded}
|
|
215
219
|
/>
|
|
216
220
|
</div>
|
|
@@ -194,11 +194,11 @@ describe("<Select />", () => {
|
|
|
194
194
|
})
|
|
195
195
|
|
|
196
196
|
describe("Given the menu is opened", () => {
|
|
197
|
-
it("
|
|
197
|
+
it("focuses the listbox initially", async () => {
|
|
198
198
|
const { getByRole } = render(<SelectWrapper defaultOpen />)
|
|
199
199
|
expect(getByRole("listbox")).toBeVisible()
|
|
200
200
|
await waitFor(() => {
|
|
201
|
-
expect(getByRole("
|
|
201
|
+
expect(getByRole("listbox")).toHaveFocus()
|
|
202
202
|
})
|
|
203
203
|
})
|
|
204
204
|
it("is closed when hits the escape key", async () => {
|
|
@@ -305,12 +305,12 @@ describe("<Select />", () => {
|
|
|
305
305
|
})
|
|
306
306
|
})
|
|
307
307
|
|
|
308
|
-
it("
|
|
308
|
+
it("focuses the last item in the list on up arrow press", async () => {
|
|
309
309
|
const { getByRole } = render(<SelectWrapper />)
|
|
310
310
|
await user.tab()
|
|
311
311
|
await user.keyboard("{ArrowUp}")
|
|
312
312
|
await waitFor(() => {
|
|
313
|
-
expect(getByRole("option", { name: "
|
|
313
|
+
expect(getByRole("option", { name: "Magic" })).toHaveFocus()
|
|
314
314
|
})
|
|
315
315
|
})
|
|
316
316
|
|
|
@@ -191,16 +191,7 @@ export const Select = <Option extends SelectOption = SelectOption>({
|
|
|
191
191
|
trigger(selectToggleProps, selectToggleProps.ref)
|
|
192
192
|
)}
|
|
193
193
|
{state.isOpen && (
|
|
194
|
-
<Popover
|
|
195
|
-
id={popoverId}
|
|
196
|
-
portalContainer={portalContainer}
|
|
197
|
-
refs={refs}
|
|
198
|
-
focusOnProps={{
|
|
199
|
-
onEscapeKey: state.close,
|
|
200
|
-
onClickOutside: state.close,
|
|
201
|
-
noIsolation: true,
|
|
202
|
-
}}
|
|
203
|
-
>
|
|
194
|
+
<Popover id={popoverId} portalContainer={portalContainer} refs={refs}>
|
|
204
195
|
<SelectProvider<Option> state={state}>
|
|
205
196
|
<SelectPopoverContents menuProps={menuProps}>
|
|
206
197
|
{children}
|
|
@@ -23,7 +23,7 @@ export const ListBox = <Option extends SelectOption>({
|
|
|
23
23
|
const { state } = useSelectContext<Option>()
|
|
24
24
|
const ref = React.useRef<HTMLUListElement>(null)
|
|
25
25
|
const { listBoxProps } = useListBox(
|
|
26
|
-
{ ...menuProps, disallowEmptySelection: true
|
|
26
|
+
{ ...menuProps, disallowEmptySelection: true },
|
|
27
27
|
state,
|
|
28
28
|
ref
|
|
29
29
|
)
|
|
@@ -87,9 +87,15 @@ $indicator-size: 1.25rem;
|
|
|
87
87
|
.stepperDescription {
|
|
88
88
|
display: flex;
|
|
89
89
|
justify-content: center;
|
|
90
|
+
color: var(--color-white);
|
|
91
|
+
font-family: var(--typography-paragraph-small-font-family);
|
|
92
|
+
font-weight: var(--typography-paragraph-small-font-weight);
|
|
93
|
+
font-size: var(--typography-paragraph-small-font-size);
|
|
94
|
+
line-height: var(--typography-paragraph-small-line-height);
|
|
95
|
+
letter-spacing: var(--typography-paragraph-small-letter-spacing);
|
|
90
96
|
|
|
91
|
-
@media (
|
|
92
|
-
|
|
97
|
+
@media (width >= 768px) {
|
|
98
|
+
/* sr hidden styles */
|
|
93
99
|
position: absolute;
|
|
94
100
|
width: 0;
|
|
95
101
|
height: 0;
|
|
@@ -133,14 +133,9 @@ export const ProgressStepper = ({
|
|
|
133
133
|
)
|
|
134
134
|
})}
|
|
135
135
|
</ol>
|
|
136
|
-
<
|
|
137
|
-
classNameOverride={styles.stepperDescription}
|
|
138
|
-
variant="small"
|
|
139
|
-
color="white"
|
|
140
|
-
id="stepper-description"
|
|
141
|
-
>
|
|
136
|
+
<span className={styles.stepperDescription} id="stepper-description">
|
|
142
137
|
Step {currentStepIndex + 1} of {steps.length}
|
|
143
|
-
</
|
|
138
|
+
</span>
|
|
144
139
|
</div>
|
|
145
140
|
)
|
|
146
141
|
}
|
|
@@ -92,6 +92,11 @@
|
|
|
92
92
|
.stepperDescription {
|
|
93
93
|
display: flex;
|
|
94
94
|
justify-content: center;
|
|
95
|
+
font-family: var(--typography-paragraph-small-font-family);
|
|
96
|
+
font-weight: var(--typography-paragraph-small-font-weight);
|
|
97
|
+
font-size: var(--typography-paragraph-small-font-size);
|
|
98
|
+
line-height: var(--typography-paragraph-small-line-height);
|
|
99
|
+
letter-spacing: var(--typography-paragraph-small-letter-spacing);
|
|
95
100
|
|
|
96
101
|
@media (width >= 768px) {
|
|
97
102
|
/* sr hidden styles */
|
|
@@ -140,13 +140,9 @@ export const ProgressStepper = ({
|
|
|
140
140
|
)
|
|
141
141
|
})}
|
|
142
142
|
</ol>
|
|
143
|
-
<
|
|
144
|
-
classNameOverride={styles.stepperDescription}
|
|
145
|
-
variant="small"
|
|
146
|
-
id="stepper-description"
|
|
147
|
-
>
|
|
143
|
+
<span className={styles.stepperDescription} id="stepper-description">
|
|
148
144
|
Step {currentStepIndex + 1} of {steps.length}
|
|
149
|
-
</
|
|
145
|
+
</span>
|
|
150
146
|
</div>
|
|
151
147
|
)
|
|
152
148
|
}
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export * from "./ErrorPage"
|
|
|
20
20
|
export * from "./FieldGroup"
|
|
21
21
|
export * from "./FieldMessage"
|
|
22
22
|
export * from "./Filter"
|
|
23
|
-
|
|
23
|
+
export * from "./GuidanceBlock"
|
|
24
24
|
export * from "./Heading"
|
|
25
25
|
export * from "./Icon"
|
|
26
26
|
export * from "./Illustration"
|
|
@@ -61,4 +61,3 @@ export * from "./__layout__/Workflow/v1"
|
|
|
61
61
|
export * from "./__overlays__/Tooltip/v1"
|
|
62
62
|
export * from "./__actions__/Menu/v1"
|
|
63
63
|
export * from "./__actions__/Button/v1"
|
|
64
|
-
export * from "./__containers__/GuidanceBlock/v1"
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { transformComponentsInDir } from "../utils"
|
|
2
|
-
import { transformGuidanceBlockVariantProp } from "./transformGuidanceBlockVariantProp"
|
|
3
|
-
/** This is here as a script runner that updates GuidanceBlock variants to v2 variants */
|
|
4
|
-
const updateGuidanceBlockVariantProp = (): void => {
|
|
5
|
-
// eslint-disable-next-line no-console
|
|
6
|
-
console.log(" ~(-_- ~) Running GuidanceBlock transformer (~ -_-)~")
|
|
7
|
-
const targetDir = process.argv[2]
|
|
8
|
-
if (!targetDir) {
|
|
9
|
-
process.exit(1)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
transformComponentsInDir(
|
|
13
|
-
targetDir,
|
|
14
|
-
transformGuidanceBlockVariantProp,
|
|
15
|
-
"GuidanceBlock"
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
updateGuidanceBlockVariantProp()
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { parseJsx } from "../__tests__/utils"
|
|
2
|
-
import { transformSource, printAst } from "../utils"
|
|
3
|
-
import { transformGuidanceBlockVariantProp } from "./transformGuidanceBlockVariantProp"
|
|
4
|
-
|
|
5
|
-
describe("transformGuidanceBlockVariantProp", () => {
|
|
6
|
-
it("updates the import statement for GuidanceBlock to the new family version", () => {
|
|
7
|
-
const inputAst = parseJsx(`
|
|
8
|
-
import { GuidanceBlock } from "@kaizen/components"
|
|
9
|
-
import { Card } from "@kaizen/components"
|
|
10
|
-
`)
|
|
11
|
-
const outputAst = parseJsx(`
|
|
12
|
-
import { GuidanceBlock } from "@kaizen/components/v2/containers"
|
|
13
|
-
import { Card } from "@kaizen/components"
|
|
14
|
-
`)
|
|
15
|
-
const transformed = transformSource({
|
|
16
|
-
sourceFile: inputAst,
|
|
17
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
18
|
-
tagName: "GuidanceBlock",
|
|
19
|
-
})
|
|
20
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it("removes all instances of `positive`, `negative`, `informative`, `cautionary`, `assertive`", () => {
|
|
24
|
-
const inputAst = parseJsx(`
|
|
25
|
-
const TestComponent = () => <GuidanceBlock variant="positive" />
|
|
26
|
-
const TestComponent = () => <GuidanceBlock variant="negative" />
|
|
27
|
-
const TestComponent = () => <GuidanceBlock variant="informative" />
|
|
28
|
-
const TestComponent = () => <GuidanceBlock variant="cautionary" />
|
|
29
|
-
const TestComponent = () => <GuidanceBlock variant="assertive" />
|
|
30
|
-
`)
|
|
31
|
-
const outputAst = parseJsx(`
|
|
32
|
-
const TestComponent = () => <GuidanceBlock />
|
|
33
|
-
const TestComponent = () => <GuidanceBlock />
|
|
34
|
-
const TestComponent = () => <GuidanceBlock />
|
|
35
|
-
const TestComponent = () => <GuidanceBlock />
|
|
36
|
-
const TestComponent = () => <GuidanceBlock />
|
|
37
|
-
`)
|
|
38
|
-
const transformed = transformSource({
|
|
39
|
-
sourceFile: inputAst,
|
|
40
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
41
|
-
tagName: "GuidanceBlock",
|
|
42
|
-
})
|
|
43
|
-
expect(transformed).toEqual(printAst(outputAst))
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('replaces variant="expert-advice" with variant="prominent"', () => {
|
|
47
|
-
const inputAst = parseJsx(`
|
|
48
|
-
export const TestComponent = () => <GuidanceBlock variant="expert-advice" />
|
|
49
|
-
`)
|
|
50
|
-
const outputAst = parseJsx(`
|
|
51
|
-
export const TestComponent = () => <GuidanceBlock variant="prominent" />
|
|
52
|
-
`)
|
|
53
|
-
const transformed = transformSource({
|
|
54
|
-
sourceFile: inputAst,
|
|
55
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
56
|
-
tagName: "GuidanceBlock",
|
|
57
|
-
})
|
|
58
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it("handles multiple attributes and replace only variant", () => {
|
|
62
|
-
const inputAst = parseJsx(`
|
|
63
|
-
export const TestComponent = () => <GuidanceBlock variant="positive" id="123" />
|
|
64
|
-
`)
|
|
65
|
-
const outputAst = parseJsx(`
|
|
66
|
-
export const TestComponent = () => <GuidanceBlock id="123" />
|
|
67
|
-
`)
|
|
68
|
-
const transformed = transformSource({
|
|
69
|
-
sourceFile: inputAst,
|
|
70
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
71
|
-
tagName: "GuidanceBlock",
|
|
72
|
-
})
|
|
73
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it("handles nested GuidanceBlock components", () => {
|
|
77
|
-
const inputAst = parseJsx(`
|
|
78
|
-
export const TestComponent = () => <div><GuidanceBlock variant="positive" id="123" /></div>
|
|
79
|
-
`)
|
|
80
|
-
const outputAst = parseJsx(`
|
|
81
|
-
export const TestComponent = () => <div><GuidanceBlock id="123" /></div>
|
|
82
|
-
`)
|
|
83
|
-
const transformed = transformSource({
|
|
84
|
-
sourceFile: inputAst,
|
|
85
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
86
|
-
tagName: "GuidanceBlock",
|
|
87
|
-
})
|
|
88
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it("transforms multiple GuidanceBlock", () => {
|
|
92
|
-
const inputAst = parseJsx(`
|
|
93
|
-
export const TestComponent = () => <div><GuidanceBlock variant="positive" /><GuidanceBlock variant="positive" /></div>
|
|
94
|
-
`)
|
|
95
|
-
const outputAst = parseJsx(`
|
|
96
|
-
export const TestComponent = () => <div><GuidanceBlock /><GuidanceBlock /></div>
|
|
97
|
-
`)
|
|
98
|
-
const transformed = transformSource({
|
|
99
|
-
sourceFile: inputAst,
|
|
100
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
101
|
-
tagName: "GuidanceBlock",
|
|
102
|
-
})
|
|
103
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it("transforms GuidanceBlock with arbitrary braces", () => {
|
|
107
|
-
const inputAst = parseJsx(`
|
|
108
|
-
export const TestComponent = () => <div><GuidanceBlock variant={"informative"} /><GuidanceBlock variant={'assertive'} /><GuidanceBlock variant={\`expert-advice\`} /></div>
|
|
109
|
-
`)
|
|
110
|
-
const outputAst = parseJsx(`
|
|
111
|
-
export const TestComponent = () => <div><GuidanceBlock /><GuidanceBlock /><GuidanceBlock variant="prominent" /></div>
|
|
112
|
-
`)
|
|
113
|
-
const transformed = transformSource({
|
|
114
|
-
sourceFile: inputAst,
|
|
115
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
116
|
-
tagName: "GuidanceBlock",
|
|
117
|
-
})
|
|
118
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it("won't modify variants usings variables", () => {
|
|
122
|
-
const inputAst = parseJsx(`
|
|
123
|
-
export const TestComponent = () => <div><GuidanceBlock variant={varName} /></div>
|
|
124
|
-
`)
|
|
125
|
-
const outputAst = parseJsx(`
|
|
126
|
-
export const TestComponent = () => <div><GuidanceBlock variant={varName} /></div>
|
|
127
|
-
`)
|
|
128
|
-
const transformed = transformSource({
|
|
129
|
-
sourceFile: inputAst,
|
|
130
|
-
astTransformer: transformGuidanceBlockVariantProp,
|
|
131
|
-
tagName: "GuidanceBlock",
|
|
132
|
-
})
|
|
133
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
134
|
-
})
|
|
135
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
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.isImportDeclaration(node) && node.getText().includes(tagName)) {
|
|
10
|
-
const newModuleSpecifier = ts.factory.createStringLiteral(
|
|
11
|
-
"@kaizen/components/v2/containers"
|
|
12
|
-
)
|
|
13
|
-
return ts.factory.updateImportDeclaration(
|
|
14
|
-
node,
|
|
15
|
-
node.modifiers,
|
|
16
|
-
node.importClause,
|
|
17
|
-
newModuleSpecifier,
|
|
18
|
-
node.attributes
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (ts.isJsxSelfClosingElement(node)) {
|
|
23
|
-
if (node.tagName.getText() === tagName) {
|
|
24
|
-
const newAttributes = node.attributes.properties.reduce<
|
|
25
|
-
ts.JsxAttributeLike[]
|
|
26
|
-
>((acc, attr) => {
|
|
27
|
-
if (ts.isJsxAttribute(attr) && attr.name.getText() === "variant") {
|
|
28
|
-
const valueName =
|
|
29
|
-
attr.initializer && getPropValueText(attr.initializer)
|
|
30
|
-
|
|
31
|
-
const oldValues = [
|
|
32
|
-
"positive",
|
|
33
|
-
"negative",
|
|
34
|
-
"informative",
|
|
35
|
-
"cautionary",
|
|
36
|
-
"assertive",
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
if (valueName) {
|
|
40
|
-
if (oldValues.includes(valueName)) {
|
|
41
|
-
// Remove the attribute for old values
|
|
42
|
-
return acc
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (valueName === "expert-advice") {
|
|
46
|
-
// Replace the attribute value for expert-advice
|
|
47
|
-
return [
|
|
48
|
-
...acc,
|
|
49
|
-
ts.factory.createJsxAttribute(
|
|
50
|
-
attr.name,
|
|
51
|
-
ts.factory.createStringLiteral("prominent")
|
|
52
|
-
),
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Keep the attribute for other values
|
|
57
|
-
return [...acc, attr]
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return [...acc, attr]
|
|
62
|
-
}, [])
|
|
63
|
-
|
|
64
|
-
if (ts.isJsxSelfClosingElement(node)) {
|
|
65
|
-
return ts.factory.updateJsxSelfClosingElement(
|
|
66
|
-
node,
|
|
67
|
-
node.tagName,
|
|
68
|
-
node.typeArguments,
|
|
69
|
-
ts.factory.createJsxAttributes(newAttributes)
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return ts.visitEachChild(node, visit, context)
|
|
75
|
-
}
|
|
76
|
-
return ts.visitNode(rootNode, visit)
|
|
77
|
-
}
|