@kaizen/components 1.73.0 → 1.73.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codemod.sh +2 -0
- package/codemods/README.md +46 -0
- package/codemods/upgradeV1Buttons/index.ts +19 -0
- package/codemods/upgradeV1Buttons/transformV1ButtonAttributes.spec.ts +210 -0
- package/codemods/upgradeV1Buttons/transformV1ButtonAttributes.ts +146 -0
- package/codemods/upgradeV1Buttons/upgradeV1Buttons.spec.ts +658 -0
- package/codemods/upgradeV1Buttons/upgradeV1Buttons.ts +93 -0
- package/codemods/utils/createJsxElementWithChildren.spec.ts +119 -0
- package/codemods/utils/createJsxElementWithChildren.ts +55 -0
- package/codemods/utils/createProp.spec.ts +75 -19
- package/codemods/utils/createProp.ts +8 -1
- package/codemods/utils/getKaioTagName.ts +13 -5
- package/codemods/utils/index.ts +1 -0
- package/dist/styles.css +8788 -8788
- package/package.json +1 -1
- package/src/Icon/_docs/Icon.mdx +1 -1
- package/src/__next__/Button/_docs/Button--migration-guide.mdx +81 -0
- package/src/__next__/Icon/_docs/Icon--api-specification.mdx +1 -1
- package/src/__next__/Icon/_docs/Icon--usage-guidelines.mdx +1 -1
- package/src/__next__/Menu/_docs/Menu--api-specification.mdx +1 -1
- package/src/__next__/Menu/_docs/Menu--usage-guidelines.mdx +1 -1
- package/src/__next__/Select/_docs/Select.mdx +2 -2
- package/src/__next__/Select/_docs/Select.stickersheet.stories.tsx +1 -1
- package/src/__next__/Select/_docs/Select.stories.tsx +1 -1
- package/src/__next__/Tabs/_docs/Tabs--api-specification.mdx +1 -1
- package/src/__next__/Tag/RemovableTag/_docs/RemovableTag.mdx +1 -1
- package/src/__next__/Tooltip/_docs/ApiSpecification.mdx +1 -1
- package/src/__next__/Tooltip/_docs/Tooltip.mdx +1 -1
package/bin/codemod.sh
CHANGED
|
@@ -31,6 +31,8 @@ echo ""
|
|
|
31
31
|
|
|
32
32
|
if npx tsx@latest $CODEMOD_PATH $TARGET_DIR; then
|
|
33
33
|
echo "Codemod '$codemodFileName' completed successfully in directory '$transformDir'"
|
|
34
|
+
echo "---"
|
|
35
|
+
echo "Run linting and prettier to correct issues with re-writes"
|
|
34
36
|
else
|
|
35
37
|
echo "Codemod '$codemodFileName' could not be run in '$TARGET_DIR'"
|
|
36
38
|
exit 1
|
package/codemods/README.md
CHANGED
|
@@ -103,6 +103,52 @@ Released in `1.60.0`
|
|
|
103
103
|
|
|
104
104
|
Removes `Popover` component props `variant` and `customIcon`.
|
|
105
105
|
|
|
106
|
+
### `upgradeV1Buttons`
|
|
107
|
+
|
|
108
|
+
Released in `1.73.1`
|
|
109
|
+
|
|
110
|
+
Migrates V1 `Button` and `IconButton` component to next `Button` or `LinkButton`.
|
|
111
|
+
|
|
112
|
+
#### Props
|
|
113
|
+
|
|
114
|
+
- `label` becomes `children`
|
|
115
|
+
- eg. `<IconButton label="Hello" />` becomes `<Button>Hello</Button>`
|
|
116
|
+
- `onClick` becomes `onPress`
|
|
117
|
+
- Variants:
|
|
118
|
+
- Default (undefined):
|
|
119
|
+
- For `Button` becomes `variant="secondary"`
|
|
120
|
+
- For `IconButton` becomes `variant="tertiary"`
|
|
121
|
+
- `primary` becomes `variant="primary"`
|
|
122
|
+
- `secondary` becomes `variant="tertiary"`
|
|
123
|
+
- `destructive` will be removed (no longer available as a variant)
|
|
124
|
+
- Sizes:
|
|
125
|
+
- Default (undefined) becomes `large`
|
|
126
|
+
- `small` becomes `medium`
|
|
127
|
+
- `regular` becomes `large`
|
|
128
|
+
- `reversed` becomes `isReversed`
|
|
129
|
+
- `classNameOverride` becomes `className`
|
|
130
|
+
- `data-automation-id` becomes `data-testid`
|
|
131
|
+
- `disabled` becomes `isDisabled`
|
|
132
|
+
- `newTabAndIUnderstandTheAccessibilityImplications` becomes `target="_blank"`
|
|
133
|
+
- `rel="noopener noreferrer"` is also added
|
|
134
|
+
- `component` will not be removed by the codemod, but will throw a TypeScript error as the prop itself no longer exists
|
|
135
|
+
- For `IconButton` only:
|
|
136
|
+
- `hasHiddenLabel` will be added
|
|
137
|
+
|
|
138
|
+
#### Component transformation
|
|
139
|
+
|
|
140
|
+
- `Button`/`IconButton` without the `href` or `component` prop will become `next/Button`
|
|
141
|
+
- `Button`/`IconButton` with the `href` prop will become `LinkButton`
|
|
142
|
+
- `Button`/`IconButton` with the `component` prop will become `LinkButton`
|
|
143
|
+
- `component` prop will remain to throw an intentional type error to ensure manual intervention (see migration guide)
|
|
144
|
+
|
|
145
|
+
#### Imports
|
|
146
|
+
|
|
147
|
+
All imports of V1 Buttons will now point to either:
|
|
148
|
+
|
|
149
|
+
- `@kaizen/components/next` for `Button`
|
|
150
|
+
- `@kaizen/components` for `LinkButton`
|
|
151
|
+
|
|
106
152
|
### `upgradeIconV1`
|
|
107
153
|
|
|
108
154
|
Released in `1.67.0`; last updated in `1.68.1`
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { transformComponentsInDir } from '../utils'
|
|
2
|
+
import { upgradeV1Buttons } from './upgradeV1Buttons'
|
|
3
|
+
|
|
4
|
+
const run = (): void => {
|
|
5
|
+
console.log('It is recommended that the `upgradeIconV1` codemod be run prior to this')
|
|
6
|
+
console.log('---')
|
|
7
|
+
console.log('~(-_- ~) Running V1 Buttons upgrade (~ -_-)~')
|
|
8
|
+
|
|
9
|
+
const targetDir = process.argv[2]
|
|
10
|
+
if (!targetDir) {
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
transformComponentsInDir(targetDir, ['IconButton', 'Button'], (tagNames) => [
|
|
15
|
+
upgradeV1Buttons(tagNames),
|
|
16
|
+
])
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
run()
|
|
@@ -0,0 +1,210 @@
|
|
|
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
|
+
it('will remove usage of `disableTabFocusAndIUnderstandTheAccessibilityImplications`', () => {
|
|
64
|
+
const inputAst = parseJsx(
|
|
65
|
+
'<Button label="Pancakes" disableTabFocusAndIUnderstandTheAccessibilityImplications />',
|
|
66
|
+
)
|
|
67
|
+
const outputAst = parseJsx('<Button variant="secondary" size="large">Pancakes</Button>')
|
|
68
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('transform existing props', () => {
|
|
72
|
+
it('changes onClick to onPress', () => {
|
|
73
|
+
const inputAst = parseJsx('<Button label="Pancakes" onClick={handleClick} />')
|
|
74
|
+
const outputAst = parseJsx(
|
|
75
|
+
'<Button onPress={handleClick} variant="secondary" size="large">Pancakes</Button>',
|
|
76
|
+
)
|
|
77
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('changes reversed to isReversed', () => {
|
|
81
|
+
const inputAst = parseJsx(`
|
|
82
|
+
<>
|
|
83
|
+
<Button label="Pancakes" reversed />
|
|
84
|
+
<Button label="Pancakes" reversed={false} />
|
|
85
|
+
</>
|
|
86
|
+
`)
|
|
87
|
+
const outputAst = parseJsx(`
|
|
88
|
+
<>
|
|
89
|
+
<Button isReversed variant="secondary" size="large">Pancakes</Button>
|
|
90
|
+
<Button isReversed={false} variant="secondary" size="large">Pancakes</Button>
|
|
91
|
+
</>
|
|
92
|
+
`)
|
|
93
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('changes classNameOverride to className', () => {
|
|
97
|
+
const inputAst = parseJsx('<Button label="Pancakes" classNameOverride="hello" />')
|
|
98
|
+
const outputAst = parseJsx(
|
|
99
|
+
'<Button className="hello" variant="secondary" size="large">Pancakes</Button>',
|
|
100
|
+
)
|
|
101
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('changes data-automation-id to data-testid', () => {
|
|
105
|
+
const inputAst = parseJsx('<Button label="Pancakes" data-automation-id="pancakes" />')
|
|
106
|
+
const outputAst = parseJsx(
|
|
107
|
+
'<Button data-testid="pancakes" variant="secondary" size="large">Pancakes</Button>',
|
|
108
|
+
)
|
|
109
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('changes disabled to isDisabled', () => {
|
|
113
|
+
const inputAst = parseJsx(`
|
|
114
|
+
<>
|
|
115
|
+
<Button label="Pancakes" disabled />
|
|
116
|
+
<Button label="Pancakes" disabled={false} />
|
|
117
|
+
</>
|
|
118
|
+
`)
|
|
119
|
+
const outputAst = parseJsx(`
|
|
120
|
+
<>
|
|
121
|
+
<Button isDisabled variant="secondary" size="large">Pancakes</Button>
|
|
122
|
+
<Button isDisabled={false} variant="secondary" size="large">Pancakes</Button>
|
|
123
|
+
</>
|
|
124
|
+
`)
|
|
125
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('changes newTabAndIUnderstandTheAccessibilityImplications to target="_blank" and rel="noopener noreferrer"', () => {
|
|
129
|
+
const inputAst = parseJsx(
|
|
130
|
+
'<Button href="#" label="Pancakes" newTabAndIUnderstandTheAccessibilityImplications />',
|
|
131
|
+
)
|
|
132
|
+
const outputAst = parseJsx(
|
|
133
|
+
'<LinkButton href="#" target="_blank" rel="noopener noreferrer" variant="secondary" size="large">Pancakes</LinkButton>',
|
|
134
|
+
)
|
|
135
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe('transform variant', () => {
|
|
139
|
+
it('changes default (undefined) for Button to variant secondary', () => {
|
|
140
|
+
const inputAst = parseJsx('<Button label="Pancakes" />')
|
|
141
|
+
const outputAst = parseJsx('<Button variant="secondary" size="large">Pancakes</Button>')
|
|
142
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('changes default (undefined) for IconButton to variant tertiary', () => {
|
|
146
|
+
const inputAst = parseJsx('<IconButton label="Pancakes" />')
|
|
147
|
+
const outputAst = parseJsx(
|
|
148
|
+
'<Button variant="tertiary" size="large" hasHiddenLabel>Pancakes</Button>',
|
|
149
|
+
)
|
|
150
|
+
expect(transformInput(inputAst, 'IconButton')).toEqual(printAst(outputAst))
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('changes primary to variant primary', () => {
|
|
154
|
+
const inputAst = parseJsx('<Button label="Pancakes" primary />')
|
|
155
|
+
const outputAst = parseJsx('<Button variant="primary" size="large">Pancakes</Button>')
|
|
156
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('changes secondary to variant tertiary', () => {
|
|
160
|
+
const inputAst = parseJsx('<Button label="Pancakes" secondary />')
|
|
161
|
+
const outputAst = parseJsx('<Button variant="tertiary" size="large">Pancakes</Button>')
|
|
162
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('removes destructive', () => {
|
|
166
|
+
const inputAst = parseJsx(`
|
|
167
|
+
<>
|
|
168
|
+
<Button label="Pancakes" destructive />
|
|
169
|
+
<Button label="Pancakes" primary destructive />
|
|
170
|
+
<Button label="Pancakes" secondary destructive />
|
|
171
|
+
</>
|
|
172
|
+
`)
|
|
173
|
+
const outputAst = parseJsx(`
|
|
174
|
+
<>
|
|
175
|
+
<Button variant="secondary" size="large">Pancakes</Button>
|
|
176
|
+
<Button variant="primary" size="large">Pancakes</Button>
|
|
177
|
+
<Button variant="tertiary" size="large">Pancakes</Button>
|
|
178
|
+
</>
|
|
179
|
+
`)
|
|
180
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
describe('transform size', () => {
|
|
185
|
+
it('changes default (undefined) to large', () => {
|
|
186
|
+
const inputAst = parseJsx('<Button label="Pancakes" />')
|
|
187
|
+
const outputAst = parseJsx('<Button variant="secondary" size="large">Pancakes</Button>')
|
|
188
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('changes small to medium', () => {
|
|
192
|
+
const inputAst = parseJsx('<Button label="Pancakes" size="small" />')
|
|
193
|
+
const outputAst = parseJsx('<Button size="medium" variant="secondary">Pancakes</Button>')
|
|
194
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('changes regular to large', () => {
|
|
198
|
+
const inputAst = parseJsx('<Button label="Pancakes" size="regular" />')
|
|
199
|
+
const outputAst = parseJsx('<Button size="large" variant="secondary">Pancakes</Button>')
|
|
200
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('does not change a non-string value', () => {
|
|
204
|
+
const inputAst = parseJsx('<Button label="Pancakes" size={size} />')
|
|
205
|
+
const outputAst = parseJsx('<Button size={size} variant="secondary">Pancakes</Button>')
|
|
206
|
+
expect(transformInput(inputAst)).toEqual(printAst(outputAst))
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
})
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import ts from 'typescript'
|
|
2
|
+
import { type ButtonProps as V1ButtonProps } from '~components/Button'
|
|
3
|
+
import { type ButtonProps as NextButtonProps } from '~components/__next__/Button'
|
|
4
|
+
import { createProp, createStringProp, getPropValueText } from '../utils'
|
|
5
|
+
|
|
6
|
+
const getNewSizeValue = (
|
|
7
|
+
oldValue: Exclude<V1ButtonProps['size'], undefined>,
|
|
8
|
+
): Exclude<NextButtonProps['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 'fullWidth':
|
|
37
|
+
return createProp('isFullWidth', propValue)
|
|
38
|
+
case 'working':
|
|
39
|
+
return createProp('isPending', propValue)
|
|
40
|
+
case 'workingLabel':
|
|
41
|
+
return createProp('pendingLabel', propValue)
|
|
42
|
+
case 'workingLabelHidden':
|
|
43
|
+
return createProp('hasHiddenPendingLabel', propValue)
|
|
44
|
+
case 'onMouseDown':
|
|
45
|
+
return createProp('onPressStart', propValue)
|
|
46
|
+
case 'disableTabFocusAndIUnderstandTheAccessibilityImplications':
|
|
47
|
+
return null
|
|
48
|
+
case 'newTabAndIUnderstandTheAccessibilityImplications':
|
|
49
|
+
return null
|
|
50
|
+
case 'disabled':
|
|
51
|
+
return createProp('isDisabled', propValue)
|
|
52
|
+
case 'size': {
|
|
53
|
+
if (!propValue) return createStringProp('size', 'large')
|
|
54
|
+
|
|
55
|
+
const sizeValue = getPropValueText(propValue) as Exclude<V1ButtonProps['size'], undefined>
|
|
56
|
+
return sizeValue
|
|
57
|
+
? createStringProp('size', getNewSizeValue(sizeValue))
|
|
58
|
+
: createProp('size', propValue)
|
|
59
|
+
}
|
|
60
|
+
case 'primary':
|
|
61
|
+
return createStringProp('variant', 'primary')
|
|
62
|
+
case 'secondary':
|
|
63
|
+
return createStringProp('variant', 'tertiary')
|
|
64
|
+
case 'destructive':
|
|
65
|
+
return null
|
|
66
|
+
default:
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type TransformedButtonAttributes = {
|
|
72
|
+
targetComponentName: string
|
|
73
|
+
newAttributes: ts.JsxAttributeLike[]
|
|
74
|
+
childrenValue: ts.JsxAttributeValue | undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const transformV1ButtonAttributes = (
|
|
78
|
+
node: ts.JsxSelfClosingElement,
|
|
79
|
+
kaioComponentName: string,
|
|
80
|
+
): TransformedButtonAttributes => {
|
|
81
|
+
let childrenValue: ts.JsxAttributeValue | undefined
|
|
82
|
+
let hasSizeProp = false
|
|
83
|
+
let hasVariant = false
|
|
84
|
+
let hasLinkAttr = false
|
|
85
|
+
|
|
86
|
+
const newAttributes = node.attributes.properties.reduce<ts.JsxAttributeLike[]>((acc, attr) => {
|
|
87
|
+
if (ts.isJsxAttribute(attr)) {
|
|
88
|
+
const propName = attr.name.getText()
|
|
89
|
+
|
|
90
|
+
if (propName === 'label') {
|
|
91
|
+
childrenValue = attr.initializer
|
|
92
|
+
return acc
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (propName === 'newTabAndIUnderstandTheAccessibilityImplications') {
|
|
96
|
+
acc.push(createStringProp('target', '_blank'))
|
|
97
|
+
acc.push(createStringProp('rel', 'noopener noreferrer'))
|
|
98
|
+
return acc
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (propName === 'primary' || propName === 'secondary') {
|
|
102
|
+
hasVariant = true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (propName === 'size') {
|
|
106
|
+
hasSizeProp = true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (propName === 'href' || propName === 'component') {
|
|
110
|
+
hasLinkAttr = true
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const newProp = transformProp(propName, attr.initializer)
|
|
114
|
+
|
|
115
|
+
if (newProp === null) return acc
|
|
116
|
+
|
|
117
|
+
if (newProp) {
|
|
118
|
+
acc.push(newProp)
|
|
119
|
+
return acc
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
acc.push(attr)
|
|
124
|
+
return acc
|
|
125
|
+
}, [])
|
|
126
|
+
|
|
127
|
+
if (!hasVariant) {
|
|
128
|
+
newAttributes.push(
|
|
129
|
+
createStringProp('variant', kaioComponentName === 'IconButton' ? 'tertiary' : 'secondary'),
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!hasSizeProp) {
|
|
134
|
+
newAttributes.push(createStringProp('size', 'large'))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (kaioComponentName === 'IconButton') {
|
|
138
|
+
newAttributes.push(createProp('hasHiddenLabel'))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
targetComponentName: hasLinkAttr ? 'LinkButton' : 'Button',
|
|
143
|
+
newAttributes,
|
|
144
|
+
childrenValue,
|
|
145
|
+
}
|
|
146
|
+
}
|