@kaizen/components 1.69.1 → 1.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/codemods/migrateBrandMomentMoodToVariant/index.ts +5 -3
  2. package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.spec.ts +16 -5
  3. package/codemods/migrateCardVariantToColor/index.ts +5 -3
  4. package/codemods/migrateCardVariantToColor/transformCardVariantToColor.spec.ts +16 -5
  5. package/codemods/migrateConfirmationModalMoodsToVariant/index.ts +3 -1
  6. package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.spec.ts +27 -44
  7. package/codemods/migrateEmptyStateIllustrationTypeToVariant/index.ts +5 -3
  8. package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.spec.ts +16 -5
  9. package/codemods/migrateGlobalNotificationTypeToVariant/index.ts +5 -3
  10. package/codemods/migrateInformationTileMoodToVariant/index.ts +5 -3
  11. package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.spec.ts +16 -7
  12. package/codemods/migrateInlineNotificationTypeToVariant/index.ts +5 -3
  13. package/codemods/migrateMultiActionTileMoodToVariant/index.ts +5 -3
  14. package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.spec.ts +16 -7
  15. package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.spec.ts +42 -43
  16. package/codemods/migrateProgressBarMoodToColor/index.ts +5 -3
  17. package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.spec.ts +16 -5
  18. package/codemods/migrateToastNotificationTypeToVariant/index.ts +6 -4
  19. package/codemods/migrateWellVariantToColor/index.ts +5 -3
  20. package/codemods/migrateWellVariantToColor/transformWellVariantToColor.spec.ts +26 -68
  21. package/codemods/migrateWellVariantToColor/transformWellVariantToColor.ts +10 -4
  22. package/codemods/removeInputEditModalMood/index.ts +3 -1
  23. package/codemods/removeInputEditModalMood/removeInputEditModalMood.spec.ts +23 -20
  24. package/codemods/removePopoverVariant/index.ts +1 -1
  25. package/codemods/removePopoverVariant/removePopoverVariant.spec.ts +23 -25
  26. package/codemods/upgradeIconV1/index.ts +2 -17
  27. package/codemods/upgradeIconV1/upgradeIconV1.spec.ts +18 -120
  28. package/codemods/upgradeIconV1/upgradeIconV1.ts +21 -28
  29. package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +0 -10
  30. package/codemods/utils/getKaioTagName.spec.ts +167 -23
  31. package/codemods/utils/getKaioTagName.ts +71 -35
  32. package/codemods/utils/migrateStringProp.spec.ts +16 -5
  33. package/codemods/utils/migrateStringProp.ts +10 -3
  34. package/codemods/utils/removeProps.spec.ts +26 -25
  35. package/codemods/utils/removeProps.ts +10 -3
  36. package/codemods/utils/transformComponentsInDir.ts +40 -13
  37. package/codemods/utils/transformSource.spec.ts +1 -27
  38. package/codemods/utils/transformSource.ts +0 -26
  39. package/codemods/utils/updateKaioImports.ts +2 -0
  40. package/dist/cjs/LinkButton/LinkButton.cjs +59 -0
  41. package/dist/cjs/LinkButton/LinkButton.module.css.cjs +6 -0
  42. package/dist/cjs/__rc__/Button/Button.module.css.cjs +1 -1
  43. package/dist/cjs/index.cjs +2 -0
  44. package/dist/esm/LinkButton/LinkButton.mjs +53 -0
  45. package/dist/esm/LinkButton/LinkButton.module.css.mjs +4 -0
  46. package/dist/esm/__rc__/Button/Button.module.css.mjs +1 -1
  47. package/dist/esm/index.mjs +1 -0
  48. package/dist/styles.css +3259 -3229
  49. package/dist/types/LinkButton/LinkButton.d.ts +11 -0
  50. package/dist/types/LinkButton/index.d.ts +1 -0
  51. package/dist/types/__rc__/Button/Button.d.ts +6 -5
  52. package/dist/types/index.d.ts +1 -2
  53. package/package.json +1 -1
  54. package/src/LinkButton/LinkButton.module.css +4 -0
  55. package/src/LinkButton/LinkButton.tsx +71 -0
  56. package/src/LinkButton/_docs/LinkButton--api-specification.mdx +281 -0
  57. package/src/LinkButton/_docs/LinkButton--usage-guidelines.mdx +29 -0
  58. package/src/LinkButton/_docs/LinkButton.doc.stories.tsx +136 -0
  59. package/src/LinkButton/_docs/LinkButton.spec.stories.tsx +80 -0
  60. package/src/LinkButton/_docs/LinkButton.stickersheet.stories.tsx +130 -0
  61. package/src/LinkButton/index.ts +1 -0
  62. package/src/__rc__/Button/Button.module.css +44 -19
  63. package/src/__rc__/Button/Button.tsx +8 -4
  64. package/src/__rc__/Button/_docs/Button--api-specification.mdx +5 -5
  65. package/src/__rc__/Button/_docs/Button--usage-guidelines.mdx +2 -5
  66. package/src/index.ts +1 -2
@@ -1,16 +1,18 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
  import { createEncodedSourceFile } from './createEncodedSourceFile'
4
- import { getKaioTagName } from './getKaioTagName'
5
- import { transformSourceForTagName, type TransformSourceForTagNameArgs } from './transformSource'
4
+ import {
5
+ getKaioTagNamesMapByComponentName,
6
+ getKaioTagNamesMapByPattern,
7
+ type TagImportAttributesMap,
8
+ } from './getKaioTagName'
9
+ import { transformSource, type TransformSourceArgs } from './transformSource'
6
10
 
7
11
  export const traverseDir = (
8
12
  dir: string,
9
13
  transformFile: (componentFilePath: string, sourceCode: string) => void,
10
14
  ): void => {
11
- if (dir.includes('node_modules')) {
12
- return
13
- }
15
+ if (dir.includes('node_modules')) return
14
16
 
15
17
  const files = fs.readdirSync(dir)
16
18
 
@@ -26,21 +28,46 @@ export const traverseDir = (
26
28
  })
27
29
  }
28
30
 
29
- /** Walks the directory and runs the AST transformer on the given component name */
31
+ /**
32
+ * Walks the directory and runs the AST transformers on the given component name
33
+ */
30
34
  export const transformComponentsInDir = (
31
35
  dir: string,
32
- transformer: TransformSourceForTagNameArgs['astTransformer'],
33
- componentName: string,
36
+ componentNames: string[],
37
+ transformers: (kaioTagNamesMap: TagImportAttributesMap) => TransformSourceArgs['transformers'],
34
38
  ): void => {
35
39
  const transformFile = (componentFilePath: string, sourceCode: string): void => {
36
40
  const sourceFile = createEncodedSourceFile(componentFilePath, sourceCode)
41
+ const kaioTagNamesMap = getKaioTagNamesMapByComponentName(sourceFile, componentNames)
42
+ if (kaioTagNamesMap) {
43
+ const updatedSourceFile = transformSource({
44
+ sourceFile,
45
+ transformers: transformers(kaioTagNamesMap),
46
+ })
47
+
48
+ fs.writeFileSync(componentFilePath, updatedSourceFile, 'utf8')
49
+ }
50
+ }
37
51
 
38
- const tagName = getKaioTagName(sourceFile, componentName)
39
- if (tagName) {
40
- const updatedSourceFile = transformSourceForTagName({
52
+ traverseDir(dir, transformFile)
53
+ }
54
+
55
+ /**
56
+ * Walks the directory and runs the AST transformers on the given component name regex pattern
57
+ * eg. "Icon$" will match all components that end with `Icon`
58
+ */
59
+ export const transformComponentsInDirByPattern = (
60
+ dir: string,
61
+ componentNamePattern: RegExp | string,
62
+ transformers: (kaioTagNamesMap: TagImportAttributesMap) => TransformSourceArgs['transformers'],
63
+ ): void => {
64
+ const transformFile = (componentFilePath: string, sourceCode: string): void => {
65
+ const sourceFile = createEncodedSourceFile(componentFilePath, sourceCode)
66
+ const kaioTagNamesMap = getKaioTagNamesMapByPattern(sourceFile, componentNamePattern)
67
+ if (kaioTagNamesMap) {
68
+ const updatedSourceFile = transformSource({
41
69
  sourceFile,
42
- astTransformer: transformer,
43
- tagName,
70
+ transformers: transformers(kaioTagNamesMap),
44
71
  })
45
72
 
46
73
  fs.writeFileSync(componentFilePath, updatedSourceFile, 'utf8')
@@ -2,11 +2,7 @@ import fs from 'fs'
2
2
  import path from 'path'
3
3
  import ts from 'typescript'
4
4
  import { createEncodedSourceFile } from './createEncodedSourceFile'
5
- import {
6
- transformSource,
7
- transformSourceForTagName,
8
- type TransformSourceForTagNameArgs,
9
- } from './transformSource'
5
+ import { transformSource } from './transformSource'
10
6
 
11
7
  const visit =
12
8
  (context: ts.TransformationContext, tagName: string) =>
@@ -55,25 +51,3 @@ describe('transformSource()', () => {
55
51
  expect(transformed).toMatchSnapshot()
56
52
  })
57
53
  })
58
-
59
- describe('transformSourceForTagName', () => {
60
- it('updates the value of Pancakes topping to jam', () => {
61
- const filePath = path.resolve(path.join(__dirname, './__fixtures__/KaioComponent.tsx'))
62
- const fileContent = fs.readFileSync(filePath, 'utf8')
63
- const sourceFile = createEncodedSourceFile(filePath, fileContent)
64
- const mockTransformer =
65
- (context: ts.TransformationContext, tagName: string) =>
66
- (rootNode: ts.SourceFile): ts.SourceFile =>
67
- ts.visitNode(rootNode, visit(context, tagName)) as ts.SourceFile
68
-
69
- const mockTransformSourceForTagNameArgs = {
70
- sourceFile,
71
- astTransformer: mockTransformer,
72
- tagName: 'Pancakes',
73
- } satisfies TransformSourceForTagNameArgs
74
-
75
- const transformed = transformSourceForTagName(mockTransformSourceForTagNameArgs)
76
-
77
- expect(transformed).toMatchSnapshot()
78
- })
79
- })
@@ -12,29 +12,3 @@ export const transformSource = ({ sourceFile, transformers }: TransformSourceArg
12
12
  const transformedSource = printAst(result.transformed[0])
13
13
  return decodeEmptyLines(transformedSource)
14
14
  }
15
-
16
- /**
17
- * @deprecated - use transformSource instead of transformSourceForTagName
18
- */
19
- export type TransformSourceForTagNameArgs = {
20
- sourceFile: ts.SourceFile
21
- astTransformer: (
22
- context: ts.TransformationContext,
23
- tagName: string,
24
- ) => (rootNode: ts.SourceFile) => ts.SourceFile
25
- tagName: string
26
- }
27
-
28
- /**
29
- * @deprecated - use transformSource instead
30
- * Transforms the source file with the transformer and target import alias provided
31
- */
32
- export const transformSourceForTagName = ({
33
- sourceFile,
34
- astTransformer,
35
- tagName,
36
- }: TransformSourceForTagNameArgs): string =>
37
- transformSource({
38
- sourceFile,
39
- transformers: [(context) => astTransformer(context, tagName)],
40
- })
@@ -121,6 +121,8 @@ export const updateKaioImports =
121
121
  if (!ts.isSourceFile(rootNode)) return rootNode
122
122
 
123
123
  if (!importsToRemove && !importsToAdd) return rootNode
124
+ if (importsToRemove && importsToRemove.size === 0 && importsToAdd && importsToAdd.size === 0)
125
+ return rootNode
124
126
 
125
127
  const { factory } = context
126
128
 
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var React = require('react');
5
+ var reactAriaComponents = require('react-aria-components');
6
+ var buttonStyles = require('~components/__rc__/Button/Button.module.css');
7
+ require('classnames');
8
+ require('../Loading/LoadingGraphic/LoadingGraphic.cjs');
9
+ require('../Loading/LoadingHeading/LoadingHeading.cjs');
10
+ require('../Loading/LoadingInput/LoadingInput.cjs');
11
+ require('../Loading/LoadingParagraph/LoadingParagraph.cjs');
12
+ require('../Loading/LoadingSpinner/LoadingSpinner.cjs');
13
+ require('../VisuallyHidden/VisuallyHidden.cjs');
14
+ var ButtonContent = require('../__rc__/Button/subcomponents/ButtonContent/ButtonContent.cjs');
15
+ var mergeClassNames = require('../utils/mergeClassNames.cjs');
16
+ var LinkButton_module = require('./LinkButton.module.css.cjs');
17
+ var ReversedColors = require('../__utilities__/ReversedColors/v3/ReversedColors.cjs');
18
+ function _interopDefault(e) {
19
+ return e && e.__esModule ? e : {
20
+ default: e
21
+ };
22
+ }
23
+ var React__default = /*#__PURE__*/_interopDefault(React);
24
+ var buttonStyles__default = /*#__PURE__*/_interopDefault(buttonStyles);
25
+ var LinkButton = React.forwardRef(function (_a, ref) {
26
+ var children = _a.children,
27
+ _b = _a.variant,
28
+ variant = _b === void 0 ? 'primary' : _b,
29
+ _c = _a.size,
30
+ size = _c === void 0 ? 'medium' : _c,
31
+ icon = _a.icon,
32
+ _d = _a.iconPosition,
33
+ iconPosition = _d === void 0 ? 'start' : _d,
34
+ _e = _a.hasHiddenLabel,
35
+ hasHiddenLabel = _e === void 0 ? false : _e,
36
+ _f = _a.isFullWidth,
37
+ isFullWidth = _f === void 0 ? false : _f,
38
+ isDisabled = _a.isDisabled,
39
+ className = _a.className,
40
+ isReversed = _a.isReversed,
41
+ otherProps = tslib.__rest(_a, ["children", "variant", "size", "icon", "iconPosition", "hasHiddenLabel", "isFullWidth", "isDisabled", "className", "isReversed"]);
42
+ var shouldUseReverse = ReversedColors.useReversedColors();
43
+ var isReversedVariant = isReversed !== null && isReversed !== void 0 ? isReversed : shouldUseReverse;
44
+ return React__default.default.createElement(reactAriaComponents.Link, tslib.__assign({
45
+ ref: ref,
46
+ className: mergeClassNames.mergeClassNames(LinkButton_module.linkButton, buttonStyles__default.default.button, buttonStyles__default.default[size], hasHiddenLabel && buttonStyles__default.default["".concat(size, "IconButton")], isDisabled && buttonStyles__default.default.isDisabled, isReversedVariant ? buttonStyles__default.default["".concat(variant, "Reversed")] : buttonStyles__default.default[variant], isFullWidth && buttonStyles__default.default.fullWidth, className),
47
+ isDisabled: isDisabled
48
+ }, otherProps), function (racStateProps) {
49
+ var childIsFunction = typeof children === 'function';
50
+ return React__default.default.createElement(ButtonContent.ButtonContent, {
51
+ size: size,
52
+ icon: icon,
53
+ iconPosition: iconPosition,
54
+ hasHiddenLabel: hasHiddenLabel
55
+ }, childIsFunction ? children(racStateProps) : children);
56
+ });
57
+ });
58
+ LinkButton.displayName = 'LinkButton';
59
+ exports.LinkButton = LinkButton;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ var styles = {
4
+ "linkButton": "LinkButton-module_linkButton__Kvn6k"
5
+ };
6
+ module.exports = styles;
@@ -10,11 +10,11 @@ var styles = {
10
10
  "mediumIconButton": "Button-module_mediumIconButton__amipN",
11
11
  "largeIconButton": "Button-module_largeIconButton__h0dR8",
12
12
  "secondary": "Button-module_secondary__dSBU1",
13
+ "isDisabled": "Button-module_isDisabled__FDp7k",
13
14
  "tertiary": "Button-module_tertiary__7iiaM",
14
15
  "primaryReversed": "Button-module_primaryReversed__Asrrp",
15
16
  "secondaryReversed": "Button-module_secondaryReversed__us2lk",
16
17
  "tertiaryReversed": "Button-module_tertiaryReversed__lB1o6",
17
- "isDisabled": "Button-module_isDisabled__FDp7k",
18
18
  "hideContentWidth": "Button-module_hideContentWidth__WTIHN",
19
19
  "retainContentWidth": "Button-module_retainContentWidth__dRMEx"
20
20
  };
@@ -317,6 +317,7 @@ var KaizenProvider = require('./KaizenProvider/KaizenProvider.cjs');
317
317
  var Label = require('./Label/Label.cjs');
318
318
  var LabelledMessage = require('./LabelledMessage/LabelledMessage.cjs');
319
319
  var LikertScaleLegacy = require('./LikertScaleLegacy/LikertScaleLegacy.cjs');
320
+ var LinkButton = require('./LinkButton/LinkButton.cjs');
320
321
  var LoadingGraphic = require('./Loading/LoadingGraphic/LoadingGraphic.cjs');
321
322
  var LoadingHeading = require('./Loading/LoadingHeading/LoadingHeading.cjs');
322
323
  var LoadingInput = require('./Loading/LoadingInput/LoadingInput.cjs');
@@ -936,6 +937,7 @@ exports.KaizenProvider = KaizenProvider.KaizenProvider;
936
937
  exports.Label = Label.Label;
937
938
  exports.LabelledMessage = LabelledMessage.LabelledMessage;
938
939
  exports.LikertScaleLegacy = LikertScaleLegacy.LikertScaleLegacy;
940
+ exports.LinkButton = LinkButton.LinkButton;
939
941
  exports.LoadingGraphic = LoadingGraphic.LoadingGraphic;
940
942
  exports.LoadingHeading = LoadingHeading.LoadingHeading;
941
943
  exports.LoadingInput = LoadingInput.LoadingInput;
@@ -0,0 +1,53 @@
1
+ import { __rest, __assign } from 'tslib';
2
+ import React, { forwardRef } from 'react';
3
+ import { Link } from 'react-aria-components';
4
+ import buttonStyles from '~components/__rc__/Button/Button.module.css';
5
+ import 'classnames';
6
+ import '../Loading/LoadingGraphic/LoadingGraphic.mjs';
7
+ import '../Loading/LoadingHeading/LoadingHeading.mjs';
8
+ import '../Loading/LoadingInput/LoadingInput.mjs';
9
+ import '../Loading/LoadingParagraph/LoadingParagraph.mjs';
10
+ import '../Loading/LoadingSpinner/LoadingSpinner.mjs';
11
+ import '../VisuallyHidden/VisuallyHidden.mjs';
12
+ import { ButtonContent } from '../__rc__/Button/subcomponents/ButtonContent/ButtonContent.mjs';
13
+ import { mergeClassNames } from '../utils/mergeClassNames.mjs';
14
+ import styles from './LinkButton.module.css.mjs';
15
+ import { useReversedColors } from '../__utilities__/ReversedColors/v3/ReversedColors.mjs';
16
+ const LinkButton = /*#__PURE__*/function () {
17
+ const LinkButton = /*#__PURE__*/forwardRef(function (_a, ref) {
18
+ var children = _a.children,
19
+ _b = _a.variant,
20
+ variant = _b === void 0 ? 'primary' : _b,
21
+ _c = _a.size,
22
+ size = _c === void 0 ? 'medium' : _c,
23
+ icon = _a.icon,
24
+ _d = _a.iconPosition,
25
+ iconPosition = _d === void 0 ? 'start' : _d,
26
+ _e = _a.hasHiddenLabel,
27
+ hasHiddenLabel = _e === void 0 ? false : _e,
28
+ _f = _a.isFullWidth,
29
+ isFullWidth = _f === void 0 ? false : _f,
30
+ isDisabled = _a.isDisabled,
31
+ className = _a.className,
32
+ isReversed = _a.isReversed,
33
+ otherProps = __rest(_a, ["children", "variant", "size", "icon", "iconPosition", "hasHiddenLabel", "isFullWidth", "isDisabled", "className", "isReversed"]);
34
+ var shouldUseReverse = useReversedColors();
35
+ var isReversedVariant = isReversed !== null && isReversed !== void 0 ? isReversed : shouldUseReverse;
36
+ return /*#__PURE__*/React.createElement(Link, __assign({
37
+ ref: ref,
38
+ className: mergeClassNames(styles.linkButton, buttonStyles.button, buttonStyles[size], hasHiddenLabel && buttonStyles["".concat(size, "IconButton")], isDisabled && buttonStyles.isDisabled, isReversedVariant ? buttonStyles["".concat(variant, "Reversed")] : buttonStyles[variant], isFullWidth && buttonStyles.fullWidth, className),
39
+ isDisabled: isDisabled
40
+ }, otherProps), function (racStateProps) {
41
+ var childIsFunction = typeof children === 'function';
42
+ return /*#__PURE__*/React.createElement(ButtonContent, {
43
+ size: size,
44
+ icon: icon,
45
+ iconPosition: iconPosition,
46
+ hasHiddenLabel: hasHiddenLabel
47
+ }, childIsFunction ? children(racStateProps) : children);
48
+ });
49
+ });
50
+ LinkButton.displayName = 'LinkButton';
51
+ return LinkButton;
52
+ }();
53
+ export { LinkButton };
@@ -0,0 +1,4 @@
1
+ var styles = {
2
+ "linkButton": "LinkButton-module_linkButton__Kvn6k"
3
+ };
4
+ export { styles as default };
@@ -8,11 +8,11 @@ var styles = {
8
8
  "mediumIconButton": "Button-module_mediumIconButton__amipN",
9
9
  "largeIconButton": "Button-module_largeIconButton__h0dR8",
10
10
  "secondary": "Button-module_secondary__dSBU1",
11
+ "isDisabled": "Button-module_isDisabled__FDp7k",
11
12
  "tertiary": "Button-module_tertiary__7iiaM",
12
13
  "primaryReversed": "Button-module_primaryReversed__Asrrp",
13
14
  "secondaryReversed": "Button-module_secondaryReversed__us2lk",
14
15
  "tertiaryReversed": "Button-module_tertiaryReversed__lB1o6",
15
- "isDisabled": "Button-module_isDisabled__FDp7k",
16
16
  "hideContentWidth": "Button-module_hideContentWidth__WTIHN",
17
17
  "retainContentWidth": "Button-module_retainContentWidth__dRMEx"
18
18
  };
@@ -315,6 +315,7 @@ export { KaizenProvider } from './KaizenProvider/KaizenProvider.mjs';
315
315
  export { Label } from './Label/Label.mjs';
316
316
  export { LabelledMessage } from './LabelledMessage/LabelledMessage.mjs';
317
317
  export { LikertScaleLegacy } from './LikertScaleLegacy/LikertScaleLegacy.mjs';
318
+ export { LinkButton } from './LinkButton/LinkButton.mjs';
318
319
  export { LoadingGraphic } from './Loading/LoadingGraphic/LoadingGraphic.mjs';
319
320
  export { LoadingHeading } from './Loading/LoadingHeading/LoadingHeading.mjs';
320
321
  export { LoadingInput } from './Loading/LoadingInput/LoadingInput.mjs';