@kaizen/components 0.0.0-canary-button-codemod-canary-20250212054517 → 0.0.0-canary-link-canary-release-20250224232728

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/bin/codemod.sh +0 -2
  2. package/codemods/README.md +0 -45
  3. package/codemods/utils/createProp.spec.ts +19 -75
  4. package/codemods/utils/createProp.ts +1 -8
  5. package/codemods/utils/getKaioTagName.ts +5 -13
  6. package/codemods/utils/index.ts +0 -1
  7. package/dist/cjs/Filter/FilterBar/subcomponents/FilterBarButton/FilterBarButton.cjs +1 -0
  8. package/dist/cjs/Filter/FilterMultiSelect/subcomponents/Trigger/FilterTriggerButton/FilterTriggerButton.cjs +1 -0
  9. package/dist/cjs/Filter/FilterMultiSelect/subcomponents/Trigger/RemovableFilterTrigger/RemovableFilterTrigger.cjs +1 -0
  10. package/dist/cjs/Link/Link.cjs +45 -0
  11. package/dist/cjs/Link/Link.module.css.cjs +20 -0
  12. package/dist/cjs/Link/subcomponents/LinkContent.cjs +34 -0
  13. package/dist/cjs/index.cjs +4 -0
  14. package/dist/esm/Filter/FilterBar/subcomponents/FilterBarButton/FilterBarButton.mjs +1 -0
  15. package/dist/esm/Filter/FilterMultiSelect/subcomponents/Trigger/FilterTriggerButton/FilterTriggerButton.mjs +1 -0
  16. package/dist/esm/Filter/FilterMultiSelect/subcomponents/Trigger/RemovableFilterTrigger/RemovableFilterTrigger.mjs +1 -0
  17. package/dist/esm/Link/Link.mjs +40 -0
  18. package/dist/esm/Link/Link.module.css.mjs +18 -0
  19. package/dist/esm/Link/subcomponents/LinkContent.mjs +26 -0
  20. package/dist/esm/index.mjs +2 -0
  21. package/dist/styles.css +8789 -8659
  22. package/dist/types/Filter/FilterBar/subcomponents/FilterBarButton/FilterBarButton.d.ts +1 -1
  23. package/dist/types/Filter/FilterButton/index.d.ts +1 -0
  24. package/dist/types/Filter/FilterMultiSelect/types.d.ts +2 -1
  25. package/dist/types/Link/Link.d.ts +39 -0
  26. package/dist/types/Link/index.d.ts +1 -0
  27. package/dist/types/Link/subcomponents/LinkContent.d.ts +8 -0
  28. package/dist/types/RichTextEditor/utils/commands/fixtures/helpers.d.ts +0 -1
  29. package/dist/types/RichTextEditor/utils/commands/fixtures/index.d.ts +2 -0
  30. package/dist/types/RichTextEditor/utils/commands/fixtures/mockRangeForBoundingRect.d.ts +1 -0
  31. package/dist/types/__rc__/Icon/constants.d.ts +1 -1
  32. package/dist/types/index.d.ts +1 -0
  33. package/package.json +6 -1
  34. package/src/Filter/FilterButton/index.ts +1 -0
  35. package/src/Filter/FilterMultiSelect/types.ts +3 -1
  36. package/src/Link/Link.module.css +119 -0
  37. package/src/Link/Link.tsx +90 -0
  38. package/src/Link/_docs/Link--api-specification.mdx +133 -0
  39. package/src/Link/_docs/Link--api-usage-guidelines.mdx +107 -0
  40. package/src/Link/_docs/Link.doc.stories.tsx +238 -0
  41. package/src/Link/_docs/Link.stickersheet.stories.tsx +191 -0
  42. package/src/Link/index.ts +1 -0
  43. package/src/Link/subcomponents/LinkContent.tsx +31 -0
  44. package/src/LinkButton/_docs/LinkButton--api-specification.mdx +1 -57
  45. package/src/RichTextEditor/utils/commands/addMark.spec.ts +1 -5
  46. package/src/RichTextEditor/utils/commands/fixtures/helpers.ts +0 -31
  47. package/src/RichTextEditor/utils/commands/fixtures/index.ts +2 -0
  48. package/src/RichTextEditor/utils/commands/fixtures/mockRangeForBoundingRect.ts +32 -0
  49. package/src/__rc__/Button/_docs/Button--usage-guidelines.mdx +170 -1
  50. package/src/__rc__/Button/_docs/Button.docs.stories.tsx +264 -9
  51. package/src/__rc__/Button/_docs/assets/button_anatomy.png +0 -0
  52. package/src/__rc__/Button/_docs/assets/button_icon_only_spec.png +0 -0
  53. package/src/__rc__/Button/_docs/assets/button_icon_spec.png +0 -0
  54. package/src/__rc__/Button/_docs/assets/button_spec.png +0 -0
  55. package/src/__rc__/Icon/constants.ts +1 -0
  56. package/src/__rc__/Tabs/subcomponents/Tab/Tab.module.css +5 -2
  57. package/src/__rc__/Tabs/subcomponents/TabList/TabList.module.css +11 -4
  58. package/src/index.ts +1 -0
  59. package/codemods/upgradeV1Buttons/index.ts +0 -19
  60. package/codemods/upgradeV1Buttons/transformV1ButtonAttributes.spec.ts +0 -202
  61. package/codemods/upgradeV1Buttons/transformV1ButtonAttributes.ts +0 -132
  62. package/codemods/upgradeV1Buttons/upgradeV1Buttons.spec.ts +0 -658
  63. package/codemods/upgradeV1Buttons/upgradeV1Buttons.ts +0 -93
  64. package/codemods/utils/createJsxElementWithChildren.spec.ts +0 -119
  65. package/codemods/utils/createJsxElementWithChildren.ts +0 -55
  66. package/src/__rc__/Button/_docs/Button--migration-guide.mdx +0 -58
@@ -1,202 +0,0 @@
1
- import ts from 'typescript'
2
- import { parseJsx } from '../__tests__/utils'
3
- import { createJsxElementWithChildren, printAst } from '../utils'
4
- import { transformV1ButtonAttributes } from './transformV1ButtonAttributes'
5
-
6
- export const mockedTransformer =
7
- (kaioComponentName: string) =>
8
- (context: ts.TransformationContext) =>
9
- (rootNode: ts.Node): ts.Node => {
10
- const visit = (node: ts.Node): ts.Node => {
11
- if (ts.isJsxSelfClosingElement(node)) {
12
- const { targetComponentName, newAttributes, childrenValue } = transformV1ButtonAttributes(
13
- node,
14
- kaioComponentName,
15
- )
16
- return createJsxElementWithChildren(targetComponentName, newAttributes, childrenValue)
17
- }
18
- return ts.visitEachChild(node, visit, context)
19
- }
20
- return ts.visitNode(rootNode, visit)
21
- }
22
-
23
- const transformInput = (
24
- sourceFile: ts.SourceFile,
25
- kaioComponentName: string = 'Button',
26
- ): string => {
27
- const result = ts.transform(sourceFile, [mockedTransformer(kaioComponentName)])
28
- const transformedSource = result.transformed[0] as ts.SourceFile
29
- return printAst(transformedSource)
30
- }
31
-
32
- describe('transformV1ButtonAttributes()', () => {
33
- it('changes label to children', () => {
34
- const inputAst = parseJsx('<Button label="Pancakes" />')
35
- const outputAst = parseJsx('<Button variant="secondary" size="large">Pancakes</Button>')
36
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
37
- })
38
-
39
- it('replaces IconButton with Button and changes label to children and adds hasHiddenLabel', () => {
40
- const inputAst = parseJsx('<IconButton icon={icon} label="Pancakes" />')
41
- const outputAst = parseJsx(
42
- '<Button icon={icon} variant="tertiary" size="large" hasHiddenLabel>Pancakes</Button>',
43
- )
44
- expect(transformInput(inputAst, 'IconButton')).toEqual(printAst(outputAst))
45
- })
46
-
47
- it('replaces V1 Buttons with LinkButton if href exists', () => {
48
- const inputAst = parseJsx('<Button label="Pancakes" href="#" />')
49
- const outputAst = parseJsx(
50
- '<LinkButton href="#" variant="secondary" size="large">Pancakes</LinkButton>',
51
- )
52
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
53
- })
54
-
55
- it('replaces V1 Buttons with LinkButton if component prop exists', () => {
56
- const inputAst = parseJsx('<Button label="Pancakes" component={Component} />')
57
- const outputAst = parseJsx(
58
- '<LinkButton component={Component} variant="secondary" size="large">Pancakes</LinkButton>',
59
- )
60
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
61
- })
62
-
63
- describe('transform existing props', () => {
64
- it('changes onClick to onPress', () => {
65
- const inputAst = parseJsx('<Button label="Pancakes" onClick={handleClick} />')
66
- const outputAst = parseJsx(
67
- '<Button onPress={handleClick} variant="secondary" size="large">Pancakes</Button>',
68
- )
69
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
70
- })
71
-
72
- it('changes reversed to isReversed', () => {
73
- const inputAst = parseJsx(`
74
- <>
75
- <Button label="Pancakes" reversed />
76
- <Button label="Pancakes" reversed={false} />
77
- </>
78
- `)
79
- const outputAst = parseJsx(`
80
- <>
81
- <Button isReversed variant="secondary" size="large">Pancakes</Button>
82
- <Button isReversed={false} variant="secondary" size="large">Pancakes</Button>
83
- </>
84
- `)
85
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
86
- })
87
-
88
- it('changes classNameOverride to className', () => {
89
- const inputAst = parseJsx('<Button label="Pancakes" classNameOverride="hello" />')
90
- const outputAst = parseJsx(
91
- '<Button className="hello" variant="secondary" size="large">Pancakes</Button>',
92
- )
93
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
94
- })
95
-
96
- it('changes data-automation-id to data-testid', () => {
97
- const inputAst = parseJsx('<Button label="Pancakes" data-automation-id="pancakes" />')
98
- const outputAst = parseJsx(
99
- '<Button data-testid="pancakes" variant="secondary" size="large">Pancakes</Button>',
100
- )
101
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
102
- })
103
-
104
- it('changes disabled to isDisabled', () => {
105
- const inputAst = parseJsx(`
106
- <>
107
- <Button label="Pancakes" disabled />
108
- <Button label="Pancakes" disabled={false} />
109
- </>
110
- `)
111
- const outputAst = parseJsx(`
112
- <>
113
- <Button isDisabled variant="secondary" size="large">Pancakes</Button>
114
- <Button isDisabled={false} variant="secondary" size="large">Pancakes</Button>
115
- </>
116
- `)
117
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
118
- })
119
-
120
- it('changes newTabAndIUnderstandTheAccessibilityImplications to target="_blank" and rel="noopener noreferrer"', () => {
121
- const inputAst = parseJsx(
122
- '<Button label="Pancakes" newTabAndIUnderstandTheAccessibilityImplications />',
123
- )
124
- const outputAst = parseJsx(
125
- '<Button target="_blank" rel="noopener noreferrer" variant="secondary" size="large">Pancakes</Button>',
126
- )
127
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
128
- })
129
-
130
- describe('transform variant', () => {
131
- it('changes default (undefined) for Button to variant secondary', () => {
132
- const inputAst = parseJsx('<Button label="Pancakes" />')
133
- const outputAst = parseJsx('<Button variant="secondary" size="large">Pancakes</Button>')
134
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
135
- })
136
-
137
- it('changes default (undefined) for IconButton to variant tertiary', () => {
138
- const inputAst = parseJsx('<IconButton label="Pancakes" />')
139
- const outputAst = parseJsx(
140
- '<Button variant="tertiary" size="large" hasHiddenLabel>Pancakes</Button>',
141
- )
142
- expect(transformInput(inputAst, 'IconButton')).toEqual(printAst(outputAst))
143
- })
144
-
145
- it('changes primary to variant primary', () => {
146
- const inputAst = parseJsx('<Button label="Pancakes" primary />')
147
- const outputAst = parseJsx('<Button variant="primary" size="large">Pancakes</Button>')
148
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
149
- })
150
-
151
- it('changes secondary to variant tertiary', () => {
152
- const inputAst = parseJsx('<Button label="Pancakes" secondary />')
153
- const outputAst = parseJsx('<Button variant="tertiary" size="large">Pancakes</Button>')
154
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
155
- })
156
-
157
- it('removes destructive', () => {
158
- const inputAst = parseJsx(`
159
- <>
160
- <Button label="Pancakes" destructive />
161
- <Button label="Pancakes" primary destructive />
162
- <Button label="Pancakes" secondary destructive />
163
- </>
164
- `)
165
- const outputAst = parseJsx(`
166
- <>
167
- <Button variant="secondary" size="large">Pancakes</Button>
168
- <Button variant="primary" size="large">Pancakes</Button>
169
- <Button variant="tertiary" size="large">Pancakes</Button>
170
- </>
171
- `)
172
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
173
- })
174
- })
175
-
176
- describe('transform size', () => {
177
- it('changes default (undefined) to large', () => {
178
- const inputAst = parseJsx('<Button label="Pancakes" />')
179
- const outputAst = parseJsx('<Button variant="secondary" size="large">Pancakes</Button>')
180
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
181
- })
182
-
183
- it('changes small to medium', () => {
184
- const inputAst = parseJsx('<Button label="Pancakes" size="small" />')
185
- const outputAst = parseJsx('<Button size="medium" variant="secondary">Pancakes</Button>')
186
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
187
- })
188
-
189
- it('changes regular to large', () => {
190
- const inputAst = parseJsx('<Button label="Pancakes" size="regular" />')
191
- const outputAst = parseJsx('<Button size="large" variant="secondary">Pancakes</Button>')
192
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
193
- })
194
-
195
- it('does not change a non-string value', () => {
196
- const inputAst = parseJsx('<Button label="Pancakes" size={size} />')
197
- const outputAst = parseJsx('<Button size={size} variant="secondary">Pancakes</Button>')
198
- expect(transformInput(inputAst)).toEqual(printAst(outputAst))
199
- })
200
- })
201
- })
202
- })
@@ -1,132 +0,0 @@
1
- import ts from 'typescript'
2
- import { type ButtonProps as V1ButtonProps } from '~components/Button'
3
- import { type ButtonProps as RCButtonProps } from '~components/__rc__/Button'
4
- import { createProp, createStringProp, getPropValueText } from '../utils'
5
-
6
- const getNewSizeValue = (
7
- oldValue: Exclude<V1ButtonProps['size'], undefined>,
8
- ): Exclude<RCButtonProps['size'], undefined> => {
9
- switch (oldValue) {
10
- case 'small':
11
- return 'medium'
12
- case 'regular':
13
- return 'large'
14
- }
15
- }
16
-
17
- /**
18
- * @returns
19
- * - `ts.JsxAttribute` if the prop should be transformed
20
- * - `null` if the prop should be removed
21
- * - `undefined` if the prop should be kept as is
22
- */
23
- const transformProp = (
24
- propName: string,
25
- propValue: ts.JsxAttributeValue | undefined,
26
- ): ts.JsxAttribute | null | undefined => {
27
- switch (propName) {
28
- case 'onClick':
29
- return createProp('onPress', propValue)
30
- case 'reversed':
31
- return createProp('isReversed', propValue)
32
- case 'classNameOverride':
33
- return createProp('className', propValue)
34
- case 'data-automation-id':
35
- return createProp('data-testid', propValue)
36
- case 'disabled':
37
- return createProp('isDisabled', propValue)
38
- case 'size': {
39
- if (!propValue) return createStringProp('size', 'large')
40
-
41
- const sizeValue = getPropValueText(propValue) as Exclude<V1ButtonProps['size'], undefined>
42
- return sizeValue
43
- ? createStringProp('size', getNewSizeValue(sizeValue))
44
- : createProp('size', propValue)
45
- }
46
- case 'primary':
47
- return createStringProp('variant', 'primary')
48
- case 'secondary':
49
- return createStringProp('variant', 'tertiary')
50
- case 'destructive':
51
- return null
52
- default:
53
- return undefined
54
- }
55
- }
56
-
57
- type TransformedButtonAttributes = {
58
- targetComponentName: string
59
- newAttributes: ts.JsxAttributeLike[]
60
- childrenValue: ts.JsxAttributeValue | undefined
61
- }
62
-
63
- export const transformV1ButtonAttributes = (
64
- node: ts.JsxSelfClosingElement,
65
- kaioComponentName: string,
66
- ): TransformedButtonAttributes => {
67
- let childrenValue: ts.JsxAttributeValue | undefined
68
- let hasSizeProp = false
69
- let hasVariant = false
70
- let hasLinkAttr = false
71
-
72
- const newAttributes = node.attributes.properties.reduce<ts.JsxAttributeLike[]>((acc, attr) => {
73
- if (ts.isJsxAttribute(attr)) {
74
- const propName = attr.name.getText()
75
-
76
- if (propName === 'label') {
77
- childrenValue = attr.initializer
78
- return acc
79
- }
80
-
81
- if (propName === 'newTabAndIUnderstandTheAccessibilityImplications') {
82
- acc.push(createStringProp('target', '_blank'))
83
- acc.push(createStringProp('rel', 'noopener noreferrer'))
84
- return acc
85
- }
86
-
87
- if (propName === 'primary' || propName === 'secondary') {
88
- hasVariant = true
89
- }
90
-
91
- if (propName === 'size') {
92
- hasSizeProp = true
93
- }
94
-
95
- if (propName === 'href' || propName === 'component') {
96
- hasLinkAttr = true
97
- }
98
-
99
- const newProp = transformProp(propName, attr.initializer)
100
-
101
- if (newProp === null) return acc
102
-
103
- if (newProp) {
104
- acc.push(newProp)
105
- return acc
106
- }
107
- }
108
-
109
- acc.push(attr)
110
- return acc
111
- }, [])
112
-
113
- if (!hasVariant) {
114
- newAttributes.push(
115
- createStringProp('variant', kaioComponentName === 'IconButton' ? 'tertiary' : 'secondary'),
116
- )
117
- }
118
-
119
- if (!hasSizeProp) {
120
- newAttributes.push(createStringProp('size', 'large'))
121
- }
122
-
123
- if (kaioComponentName === 'IconButton') {
124
- newAttributes.push(createProp('hasHiddenLabel'))
125
- }
126
-
127
- return {
128
- targetComponentName: hasLinkAttr ? 'LinkButton' : 'Button',
129
- newAttributes,
130
- childrenValue,
131
- }
132
- }