@atlaskit/button 20.4.1 → 20.4.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.
@@ -1,223 +0,0 @@
1
- jest.autoMockOff();
2
-
3
- import transformer from '../../15.0.0-lite-mode';
4
- import { check } from '../_framework';
5
-
6
- describe('Change `type ButtonAppearances` to `type Appearance`', () => {
7
- check({
8
- transformer,
9
- it: 'should separate types into a different export from the components',
10
- original: `
11
- import Button, { ButtonAppearances } from '@atlaskit/button';
12
-
13
- export type Mine = ButtonAppearances & 'purple';
14
-
15
- function App() {
16
- return (
17
- <Button onClick={() => console.log('hi')}>click me</Button>
18
- );
19
- }
20
- `,
21
- expected: `
22
- import { Appearance } from '@atlaskit/button/types';
23
- import Button from '@atlaskit/button/custom-theme-button';
24
-
25
- export type Mine = Appearance & 'purple';
26
-
27
- function App() {
28
- return (
29
- <Button onClick={() => console.log('hi')}>click me</Button>
30
- );
31
- }
32
- `,
33
- });
34
- });
35
-
36
- describe('Changing <Button /> usage', () => {
37
- check({
38
- transformer,
39
- it: 'should move to custom theme button',
40
- original: `
41
- import React from 'react';
42
- import Button from '@atlaskit/button';
43
-
44
- function App() {
45
- return (
46
- <Button onClick={() => console.log('hi')}>click me</Button>
47
- );
48
- }
49
- `,
50
- expected: `
51
- import React from 'react';
52
- import Button from '@atlaskit/button/custom-theme-button';
53
-
54
- function App() {
55
- return (
56
- <Button onClick={() => console.log('hi')}>click me</Button>
57
- );
58
- }
59
- `,
60
- });
61
-
62
- check({
63
- transformer,
64
- it: 'should move over when not used in JSX',
65
- original: `
66
- import React from 'react';
67
- import Button from '@atlaskit/button';
68
-
69
- expect(Button).toBeTruthy();
70
- `,
71
- expected: `
72
- import React from 'react';
73
- import Button from '@atlaskit/button/custom-theme-button';
74
-
75
- expect(Button).toBeTruthy();
76
- `,
77
- });
78
-
79
- check({
80
- transformer,
81
- it: 'should respect self closing tags',
82
- original: `
83
- import React from 'react';
84
- import Button from '@atlaskit/button';
85
-
86
- function App() {
87
- return <Button onClick={() => console.log('hi')} />;
88
- }
89
- `,
90
- expected: `
91
- import React from 'react';
92
- import Button from '@atlaskit/button/custom-theme-button';
93
-
94
- function App() {
95
- return <Button onClick={() => console.log('hi')} />;
96
- }
97
- `,
98
- });
99
-
100
- check({
101
- transformer,
102
- it: 'should respect the existing alias',
103
- original: `
104
- import React from 'react';
105
- import Button from './our-button';
106
- import AkButton from '@atlaskit/button';
107
-
108
- export function App() {
109
- return (
110
- <>
111
- <Button onClick={() => console.log('hi')} />
112
- <AkButton onClick={() => console.log('hi')} />
113
- </>
114
- );
115
- }
116
- `,
117
- expected: `
118
- import React from 'react';
119
- import Button from './our-button';
120
- import AkButton from '@atlaskit/button/custom-theme-button';
121
-
122
- export function App() {
123
- return (
124
- <>
125
- <Button onClick={() => console.log('hi')} />
126
- <AkButton onClick={() => console.log('hi')} />
127
- </>
128
- );
129
- }
130
- `,
131
- });
132
- });
133
-
134
- describe('`type ButtonProps` to `type CustomButtonProps`', () => {
135
- check({
136
- transformer,
137
- it: 'should move to the new type',
138
- original: `
139
- import React from 'react';
140
- import Button, { ButtonProps } from '@atlaskit/button';
141
-
142
- function App() {
143
- return <Button>click me</Button>;
144
- }
145
- `,
146
- expected: `
147
- import React from 'react';
148
- import { CustomThemeButtonProps } from '@atlaskit/button/types';
149
- import Button from '@atlaskit/button/custom-theme-button';
150
-
151
- function App() {
152
- return <Button>click me</Button>;
153
- }
154
- `,
155
- });
156
-
157
- check({
158
- transformer,
159
- it: 'should respect aliasing',
160
- original: `
161
- import React from 'react';
162
- import Button, { ButtonProps as Foo } from '@atlaskit/button';
163
-
164
- export type Bar = Foo & { name: string };
165
-
166
- function App() {
167
- return <Button>click me</Button>;
168
- }
169
- `,
170
- expected: `
171
- import React from 'react';
172
- import { CustomThemeButtonProps as Foo } from '@atlaskit/button/types';
173
- import Button from '@atlaskit/button/custom-theme-button';
174
-
175
- export type Bar = Foo & { name: string };
176
-
177
- function App() {
178
- return <Button>click me</Button>;
179
- }
180
- `,
181
- });
182
-
183
- check({
184
- transformer,
185
- it: 'should avoid clashes',
186
- original: `
187
- import React from 'react';
188
- import { CustomThemeButtonProps } from './my-types';
189
- import Button, { ButtonProps } from '@atlaskit/button';
190
-
191
- export type Bar = CustomThemeButtonProps & ButtonProps & { name: string };
192
-
193
- function App() {
194
- return <Button>click me</Button>;
195
- }
196
- `,
197
- expected: `
198
- import React from 'react';
199
- import { CustomThemeButtonProps } from './my-types';
200
- import { CustomThemeButtonProps as DSCustomThemeButtonProps } from '@atlaskit/button/types';
201
- import Button from '@atlaskit/button/custom-theme-button';
202
-
203
- export type Bar = CustomThemeButtonProps & DSCustomThemeButtonProps & { name: string };
204
-
205
- function App() {
206
- return <Button>click me</Button>;
207
- }
208
- `,
209
- });
210
-
211
- check({
212
- transformer,
213
- it: 'should move from type entry point',
214
- original: `
215
- import React from 'react';
216
- import { ButtonProps } from '@atlaskit/button/types';
217
- `,
218
- expected: `
219
- import React from 'react';
220
- import { CustomThemeButtonProps } from '@atlaskit/button/types';
221
- `,
222
- });
223
- });
@@ -1,255 +0,0 @@
1
- jest.autoMockOff();
2
-
3
- import safe from '../../15.0.0-lite-mode';
4
- import optimistic from '../../optimistic-15.0.0-lite-mode';
5
- import { check } from '../_framework';
6
-
7
- [
8
- {
9
- name: 'safe',
10
- transformer: safe,
11
- },
12
- {
13
- name: 'optimistic',
14
- transformer: optimistic,
15
- },
16
- ].forEach(({ name, transformer }) => {
17
- describe(`Transformer: ${name}`, () => {
18
- describe('Change `type ButtonAppearances` to `type Appearance`', () => {
19
- check({
20
- it: 'should rename ButtonAppearances type to Appearance',
21
- transformer,
22
- original: `
23
- import { ButtonAppearances } from '@atlaskit/button';
24
-
25
- const value: ButtonAppearances = 'primary';
26
- `,
27
- expected: `
28
- import { Appearance } from '@atlaskit/button/types';
29
-
30
- const value: Appearance = 'primary';
31
- `,
32
- });
33
-
34
- check({
35
- it: 'should respect existing aliasing',
36
- transformer,
37
- original: `
38
- import { ButtonAppearances as CustomAppearance } from '@atlaskit/button';
39
-
40
- const value: CustomAppearance = 'primary';
41
- `,
42
- expected: `
43
- import { Appearance as CustomAppearance } from '@atlaskit/button/types';
44
-
45
- const value: CustomAppearance = 'primary';
46
- `,
47
- });
48
-
49
- check({
50
- it: 'should fallback to a `DSButtonAppearance` type alias if the `Appearance` identifier name is unavailable',
51
- transformer,
52
- original: `
53
- import { Appearance } from 'some-other-package';
54
- import { ButtonAppearances } from '@atlaskit/button';
55
-
56
- const value1: Appearance = 4;
57
- const value2: ButtonAppearances = 'primary';
58
- `,
59
- expected: `
60
- import { Appearance } from 'some-other-package';
61
- import { Appearance as DSButtonAppearance } from '@atlaskit/button/types';
62
-
63
- const value1: Appearance = 4;
64
- const value2: DSButtonAppearance = 'primary';
65
- `,
66
- });
67
-
68
- check({
69
- it: 'should use the existing type entry point',
70
- transformer,
71
- original: `
72
- import { ButtonAppearances as CustomAppearance } from '@atlaskit/button/types';
73
-
74
- const value: CustomAppearance = 'primary';
75
- `,
76
- expected: `
77
- import { Appearance as CustomAppearance } from '@atlaskit/button/types';
78
-
79
- const value: CustomAppearance = 'primary';
80
- `,
81
- });
82
- });
83
-
84
- describe('ButtonGroup', () => {
85
- const expectedImport: string =
86
- transformer === optimistic
87
- ? '@atlaskit/button/standard-button'
88
- : '@atlaskit/button/custom-theme-button';
89
-
90
- check({
91
- transformer,
92
- it: 'should move button group over to the new import',
93
- original: `
94
- import React from 'react';
95
- import Button, { ButtonGroup } from '@atlaskit/button';
96
-
97
- function App() {
98
- return <ButtonGroup><Button>click me</Button></ButtonGroup>;
99
- }
100
- `,
101
- expected: `
102
- import React from 'react';
103
- import ButtonGroup from '@atlaskit/button/button-group';
104
- import Button from '${expectedImport}';
105
-
106
- function App() {
107
- return <ButtonGroup><Button>click me</Button></ButtonGroup>;
108
- }
109
- `,
110
- });
111
-
112
- check({
113
- transformer,
114
- it: 'should respect aliasing',
115
- original: `
116
- import React from 'react';
117
- import Button, { ButtonGroup as AkButtonGroup } from '@atlaskit/button';
118
-
119
- function App() {
120
- return <AkButtonGroup><Button>click me</Button></AkButtonGroup>;
121
- }
122
- `,
123
- expected: `
124
- import React from 'react';
125
- import AkButtonGroup from '@atlaskit/button/button-group';
126
- import Button from '${expectedImport}';
127
-
128
- function App() {
129
- return <AkButtonGroup><Button>click me</Button></AkButtonGroup>;
130
- }
131
- `,
132
- });
133
-
134
- check({
135
- transformer,
136
- it: 'avoid clashing when shifting',
137
- original: `
138
- import React from 'react';
139
- import { ButtonGroup } from '@atlaskit/button';
140
-
141
- expect(ButtonGroup).toBeTruthy();
142
- `,
143
- expected: `
144
- import React from 'react';
145
- import ButtonGroup from '@atlaskit/button/button-group';
146
-
147
- expect(ButtonGroup).toBeTruthy();
148
- `,
149
- });
150
-
151
- check({
152
- transformer,
153
- it: 'should move over when not used in JSX',
154
- original: `
155
- import React from 'react';
156
- import { ButtonGroup } from '@atlaskit/button';
157
-
158
- expect(ButtonGroup).toBeTruthy();
159
- `,
160
- expected: `
161
- import React from 'react';
162
- import ButtonGroup from '@atlaskit/button/button-group';
163
-
164
- expect(ButtonGroup).toBeTruthy();
165
- `,
166
- });
167
-
168
- check({
169
- transformer,
170
- it: 'should avoid touching unrelated button groups',
171
- original: `
172
- import React from 'react';
173
- import Button from '@atlaskit/button';
174
- import { ButtonGroup } from './something';
175
-
176
- function App() {
177
- return <ButtonGroup><Button>click me</Button></ButtonGroup>;
178
- }
179
- `,
180
- expected: `
181
- import React from 'react';
182
- import Button from '${expectedImport}';
183
- import { ButtonGroup } from './something';
184
-
185
- function App() {
186
- return <ButtonGroup><Button>click me</Button></ButtonGroup>;
187
- }
188
- `,
189
- });
190
- });
191
-
192
- describe('Theme', () => {
193
- check({
194
- it: 'should move Theme to the custom-theme-button export',
195
- transformer,
196
- original: `
197
- import React from 'react';
198
- import { Theme } from '@atlaskit/button';
199
- `,
200
- expected: `
201
- import React from 'react';
202
- import { Theme } from '@atlaskit/button/custom-theme-button';
203
- `,
204
- });
205
-
206
- check({
207
- it: 'should respect aliasing',
208
- transformer,
209
- original: `
210
- import React from 'react';
211
- import { Theme as ButtonTheme } from '@atlaskit/button';
212
-
213
- type Value = ButtonTheme & { foo: string };
214
- `,
215
- expected: `
216
- import React from 'react';
217
- import { Theme as ButtonTheme } from '@atlaskit/button/custom-theme-button';
218
-
219
- type Value = ButtonTheme & { foo: string };
220
- `,
221
- });
222
-
223
- const expectedName: string = transformer === optimistic ? 'CustomThemeButton' : 'Button';
224
-
225
- check({
226
- it: 'should merge imports',
227
- transformer,
228
- original: `
229
- import React from 'react';
230
- import Button, { Theme as ButtonTheme } from '@atlaskit/button';
231
-
232
- function App() {
233
- return (
234
- <ButtonTheme.Provider value={customTheme}>
235
- <Button theme={customTheme}>click me</Button>
236
- </ButtonTheme.Provider>
237
- );
238
- }
239
- `,
240
- expected: `
241
- import React from 'react';
242
- import ${expectedName}, { Theme as ButtonTheme } from '@atlaskit/button/custom-theme-button';
243
-
244
- function App() {
245
- return (
246
- <ButtonTheme.Provider value={customTheme}>
247
- <${expectedName} theme={customTheme}>click me</${expectedName}>
248
- </ButtonTheme.Provider>
249
- );
250
- }
251
- `,
252
- });
253
- });
254
- });
255
- });
@@ -1,167 +0,0 @@
1
- import { type NodePath } from 'ast-types/lib/node-path';
2
- import type { default as core, FileInfo, JSXElement } from 'jscodeshift';
3
- import { type Collection } from 'jscodeshift/src/Collection';
4
-
5
- import {
6
- addToImport,
7
- changeImportFor,
8
- hasImportDeclaration,
9
- removeImport,
10
- tryCreateImport,
11
- } from './helpers-generic';
12
-
13
- export function convertButtonType({
14
- j,
15
- base,
16
- elements,
17
- name,
18
- newPackageName,
19
- }: {
20
- j: core.JSCodeshift;
21
- base: Collection<any>;
22
- elements: NodePath<JSXElement, JSXElement>[];
23
- name: string;
24
- newPackageName: string;
25
- }) {
26
- // Don't need to do anything if there are no elements of this type
27
- if (!elements.length) {
28
- return;
29
- }
30
-
31
- tryCreateImport({
32
- j,
33
- base,
34
- relativeToPackage: '@atlaskit/button',
35
- packageName: newPackageName,
36
- });
37
-
38
- addToImport({
39
- j,
40
- base,
41
- importSpecifier: j.importDefaultSpecifier(j.identifier(name)),
42
- packageName: newPackageName,
43
- });
44
-
45
- elements.forEach((path: NodePath<JSXElement, JSXElement>) => {
46
- path.replace(
47
- j.jsxElement(
48
- j.jsxOpeningElement(
49
- // name: new!
50
- j.jsxIdentifier(name),
51
- // keep the old attributes
52
- path.value.openingElement.attributes,
53
- // self closing
54
- path.value.openingElement.selfClosing,
55
- ),
56
- // Only create a closing element if the original had one
57
- // <Button /> => <Button /> (rather than <Button></Button>)
58
- path.value.closingElement ? j.jsxClosingElement(j.jsxIdentifier(name)) : null,
59
- path.value.children,
60
- ),
61
- );
62
- });
63
- }
64
-
65
- export function changeType({
66
- j,
67
- base,
68
- oldName,
69
- newName,
70
- fallbackNameAlias,
71
- }: {
72
- j: core.JSCodeshift;
73
- base: Collection<any>;
74
- oldName: string;
75
- newName: string;
76
- fallbackNameAlias: string;
77
- }) {
78
- changeImportFor({
79
- j,
80
- base,
81
- option: {
82
- type: 'change-name',
83
- oldName,
84
- newName,
85
- fallbackNameAlias,
86
- },
87
- oldPackagePath: '@atlaskit/button',
88
- newPackagePath: '@atlaskit/button/types',
89
- });
90
- changeImportFor({
91
- j,
92
- base,
93
- option: {
94
- type: 'change-name',
95
- oldName,
96
- newName,
97
- fallbackNameAlias,
98
- },
99
- oldPackagePath: '@atlaskit/button/types',
100
- newPackagePath: '@atlaskit/button/types',
101
- });
102
- }
103
-
104
- export function transformButton({
105
- j,
106
- file,
107
- custom: fn,
108
- }: {
109
- j: core.JSCodeshift;
110
- file: FileInfo;
111
- custom: (base: Collection<any>) => void;
112
- }) {
113
- const base: Collection<any> = j(file.source);
114
-
115
- // Exit early if not relevant
116
- // We are doing this so we don't touch the formatting of unrelated files
117
- const willChange: boolean =
118
- hasImportDeclaration(j, file.source, '@atlaskit/button') ||
119
- hasImportDeclaration(j, file.source, '@atlaskit/button/types');
120
-
121
- if (!willChange) {
122
- return file.source;
123
- }
124
-
125
- changeType({
126
- j,
127
- base,
128
- oldName: 'ButtonAppearances',
129
- newName: 'Appearance',
130
- fallbackNameAlias: 'DSButtonAppearance',
131
- });
132
-
133
- changeImportFor({
134
- j,
135
- base,
136
- // Not changing the name
137
- option: {
138
- type: 'keep-name',
139
- name: 'Theme',
140
- behaviour: 'keep-as-named-import',
141
- },
142
- oldPackagePath: '@atlaskit/button',
143
- newPackagePath: '@atlaskit/button/custom-theme-button',
144
- });
145
-
146
- changeImportFor({
147
- j,
148
- base,
149
- option: {
150
- type: 'keep-name',
151
- name: 'ButtonGroup',
152
- behaviour: 'move-to-default-import',
153
- },
154
- oldPackagePath: '@atlaskit/button',
155
- newPackagePath: '@atlaskit/button/button-group',
156
- });
157
-
158
- fn(base);
159
-
160
- removeImport({
161
- j,
162
- base,
163
- packageName: '@atlaskit/button',
164
- });
165
-
166
- return base.toSource({ quote: 'single' });
167
- }