@atlaskit/lozenge 11.1.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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2019 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Lozenge
2
+
3
+ A lozenge is a visual indicator used to highlight an item's status for quick recognition.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn add @atlaskit/lozenge
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Detailed docs and example usage can be found [here](https://atlassian.design/components/lozenge/).
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+
3
+ import Lozenge from '../src';
4
+
5
+ export default () => <Lozenge isBold>Default bold</Lozenge>;
@@ -0,0 +1,18 @@
1
+ import { JSCodeshift } from 'jscodeshift';
2
+ import { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import {
5
+ createTransformer,
6
+ hasImportDeclaration,
7
+ } from '@atlaskit/codemod-utils';
8
+
9
+ import moveObjectAppearanceToStyle from './migrations/11.0.0-lite-mode/move-object-appearance-to-style';
10
+ import removeThemeProp from './migrations/11.0.0-lite-mode/remove-theme-prop';
11
+
12
+ const transformer = createTransformer(
13
+ [moveObjectAppearanceToStyle, removeThemeProp],
14
+ (j: JSCodeshift, source: Collection<Node>) =>
15
+ hasImportDeclaration(j, source, '@atlaskit/lozenge'),
16
+ );
17
+
18
+ export default transformer;
@@ -0,0 +1,172 @@
1
+ import transformer from '../11.0.0-lite-mode';
2
+
3
+ const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
4
+
5
+ describe('Lozenge codemod', () => {
6
+ defineInlineTest(
7
+ { default: transformer, parser: 'tsx' },
8
+ {},
9
+ `
10
+ import React from 'react';
11
+ import Lozenge from '@atlaskit/lozenge';
12
+
13
+ const App = () => {
14
+ return (
15
+ <Lozenge
16
+ appearance={{ backgroundColor: 'yellow', textColor: 'blue' }}
17
+ >
18
+ Custom
19
+ </Lozenge>
20
+ );
21
+ }
22
+ `,
23
+ `
24
+ import React from 'react';
25
+ import Lozenge from '@atlaskit/lozenge';
26
+
27
+ const App = () => {
28
+ return (
29
+ <Lozenge
30
+ style={{
31
+ backgroundColor: { backgroundColor: 'yellow', textColor: 'blue' }["backgroundColor"],
32
+ color: { backgroundColor: 'yellow', textColor: 'blue' }["textColor"]
33
+ }}
34
+ >
35
+ Custom
36
+ </Lozenge>
37
+ );
38
+ }
39
+ `,
40
+ `should move object appearance values to style prop`,
41
+ );
42
+
43
+ defineInlineTest(
44
+ { default: transformer, parser: 'tsx' },
45
+ {},
46
+ `
47
+ import React from 'react';
48
+ import Lozenge from '@atlaskit/custom-lozenge';
49
+
50
+ const App = () => {
51
+ return (
52
+ <Lozenge
53
+ appearance={{ backgroundColor: 'yellow', textColor: 'blue' }}
54
+ >
55
+ Custom
56
+ </Lozenge>
57
+ );
58
+ }
59
+ `,
60
+ `
61
+ import React from 'react';
62
+ import Lozenge from '@atlaskit/custom-lozenge';
63
+
64
+ const App = () => {
65
+ return (
66
+ <Lozenge
67
+ appearance={{ backgroundColor: 'yellow', textColor: 'blue' }}
68
+ >
69
+ Custom
70
+ </Lozenge>
71
+ );
72
+ }
73
+ `,
74
+ `should not be modified when not imported from "@atlaskit/lozenge"`,
75
+ );
76
+
77
+ defineInlineTest(
78
+ { default: transformer, parser: 'tsx' },
79
+ {},
80
+ `
81
+ import React from 'react';
82
+ import Lozenge from '@atlaskit/lozenge';
83
+
84
+ const App = () => {
85
+ return (
86
+ <Lozenge appearance='default'>
87
+ Custom
88
+ </Lozenge>
89
+ );
90
+ }
91
+ `,
92
+ `
93
+ import React from 'react';
94
+ import Lozenge from '@atlaskit/lozenge';
95
+
96
+ const App = () => {
97
+ return (
98
+ <Lozenge appearance='default'>
99
+ Custom
100
+ </Lozenge>
101
+ );
102
+ }
103
+ `,
104
+ `should not be modified when appearance prop is not an object`,
105
+ );
106
+
107
+ defineInlineTest(
108
+ { default: transformer, parser: 'tsx' },
109
+ {},
110
+ `
111
+ import React from 'react';
112
+ import Lozenge from '@atlaskit/lozenge';
113
+
114
+ const App = (props) => {
115
+ return (
116
+ <Lozenge appearance={props.appearance}>
117
+ Custom
118
+ </Lozenge>
119
+ );
120
+ }
121
+ `,
122
+ `
123
+ import React from 'react';
124
+ import Lozenge from '@atlaskit/lozenge';
125
+
126
+ const App = (props) => {
127
+ return (
128
+ <Lozenge appearance={props.appearance}>
129
+ Custom
130
+ </Lozenge>
131
+ );
132
+ }
133
+ `,
134
+ `should not be modified when appearance prop is dynamic`,
135
+ );
136
+
137
+ defineInlineTest(
138
+ { default: transformer, parser: 'tsx' },
139
+ {},
140
+ `
141
+ import React from 'react';
142
+ import Lozenge from '@atlaskit/lozenge';
143
+
144
+ const App = () => {
145
+ return (
146
+ <Lozenge
147
+ appearance="default"
148
+ style={{ backgroundColor: 'red' }}
149
+ >
150
+ Custom
151
+ </Lozenge>
152
+ );
153
+ }
154
+ `,
155
+ `
156
+ import React from 'react';
157
+ import Lozenge from '@atlaskit/lozenge';
158
+
159
+ const App = () => {
160
+ return (
161
+ <Lozenge
162
+ appearance="default"
163
+ style={{ backgroundColor: 'red' }}
164
+ >
165
+ Custom
166
+ </Lozenge>
167
+ );
168
+ }
169
+ `,
170
+ `should not be modified when appearance prop is not type of object and style prop is also present`,
171
+ );
172
+ });
@@ -0,0 +1,93 @@
1
+ import transformer from '../11.0.0-lite-mode';
2
+
3
+ const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
4
+
5
+ describe('remove theme prop', () => {
6
+ defineInlineTest(
7
+ { default: transformer, parser: 'tsx' },
8
+ {},
9
+ `
10
+ import React from 'react';
11
+ import Lozenge from '@atlaskit/lozenge';
12
+ import { useTheme } from '../../theme';
13
+
14
+ const LozengeTheme = (themeProps) => ({
15
+ dark: { backgroundColor: 'blue', color: 'white' },
16
+ light: { backgroundColor: 'blue', color: 'white' },
17
+ });
18
+
19
+ const App = () => {
20
+ return (
21
+ <Lozenge theme={useTheme(LozengeTheme)}>
22
+ Custom
23
+ </Lozenge>
24
+ );
25
+ }
26
+ `,
27
+ `
28
+ /* TODO: (from codemod)
29
+ We could not automatically convert this code to the new API.
30
+
31
+ This file uses \`Lozenge\`’s \`theme\` prop. This has been deprecated and removed.
32
+
33
+ You will have to change your usage to use the \`style\` prop.
34
+ See the example on https://atlaskit.atlassian.com/examples/design-system/lozenge/with-custom-theme */
35
+ import React from 'react';
36
+ import Lozenge from '@atlaskit/lozenge';
37
+ import { useTheme } from '../../theme';
38
+
39
+ const LozengeTheme = (themeProps) => ({
40
+ dark: { backgroundColor: 'blue', color: 'white' },
41
+ light: { backgroundColor: 'blue', color: 'white' },
42
+ });
43
+
44
+ const App = () => {
45
+ return (
46
+ <Lozenge>
47
+ Custom
48
+ </Lozenge>
49
+ );
50
+ }
51
+ `,
52
+ `should remove theme if it is defined inline`,
53
+ );
54
+
55
+ defineInlineTest(
56
+ { default: transformer, parser: 'tsx' },
57
+ {},
58
+ `
59
+ import React from 'react';
60
+ import Lozenge from '@atlaskit/lozenge';
61
+ import { lozengeTheme } from '../../theme';
62
+
63
+ const App = () => {
64
+ return (
65
+ <Lozenge theme={lozengeTheme}>
66
+ Custom
67
+ </Lozenge>
68
+ );
69
+ }
70
+ `,
71
+ `
72
+ /* TODO: (from codemod)
73
+ We could not automatically convert this code to the new API.
74
+
75
+ This file uses \`Lozenge\`’s \`theme\` prop. This has been deprecated and removed.
76
+
77
+ You will have to change your usage to use the \`style\` prop.
78
+ See the example on https://atlaskit.atlassian.com/examples/design-system/lozenge/with-custom-theme */
79
+ import React from 'react';
80
+ import Lozenge from '@atlaskit/lozenge';
81
+ import { lozengeTheme } from '../../theme';
82
+
83
+ const App = () => {
84
+ return (
85
+ <Lozenge>
86
+ Custom
87
+ </Lozenge>
88
+ );
89
+ }
90
+ `,
91
+ `should remove theme if it is imported`,
92
+ );
93
+ });
@@ -0,0 +1,92 @@
1
+ import { ASTPath, JSCodeshift, JSXAttribute, JSXElement } from 'jscodeshift';
2
+ import { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import {
5
+ getDefaultSpecifier,
6
+ getJSXAttributesByName,
7
+ } from '@atlaskit/codemod-utils';
8
+
9
+ const APPEARANCE_PROP_NAME = 'appearance';
10
+
11
+ const STYLE_PROP_NAME = 'style';
12
+
13
+ const moveObjectAppearanceToStyle = (
14
+ j: JSCodeshift,
15
+ source: Collection<Node>,
16
+ ) => {
17
+ const defaultSpecifier = getDefaultSpecifier(j, source, '@atlaskit/lozenge');
18
+
19
+ if (!defaultSpecifier) {
20
+ return;
21
+ }
22
+
23
+ source
24
+ .findJSXElements(defaultSpecifier)
25
+ .forEach((element: ASTPath<JSXElement>) => {
26
+ getJSXAttributesByName(j, element, APPEARANCE_PROP_NAME).forEach(
27
+ (attribute: ASTPath<JSXAttribute>) => {
28
+ const { value } = attribute.node;
29
+
30
+ if (!value) {
31
+ return;
32
+ }
33
+
34
+ switch (value.type) {
35
+ case 'JSXExpressionContainer':
36
+ const { expression: appearanceExpression } = value;
37
+ if (appearanceExpression.type === 'ObjectExpression') {
38
+ const styleAttributes = getJSXAttributesByName(
39
+ j,
40
+ element,
41
+ STYLE_PROP_NAME,
42
+ );
43
+
44
+ if (styleAttributes.length === 0) {
45
+ j(element)
46
+ .find(j.JSXOpeningElement)
47
+ .forEach((openingElement) => {
48
+ openingElement.node.attributes?.push(
49
+ j.jsxAttribute(
50
+ j.jsxIdentifier(STYLE_PROP_NAME),
51
+ j.jsxExpressionContainer(
52
+ getMappedAppearance(j, appearanceExpression),
53
+ ),
54
+ ),
55
+ );
56
+ });
57
+ j(attribute).remove();
58
+ }
59
+ }
60
+ break;
61
+ }
62
+ },
63
+ );
64
+ });
65
+ };
66
+
67
+ function getMappedAppearance(
68
+ j: JSCodeshift,
69
+ expression: Parameters<typeof j.memberExpression>[0],
70
+ ) {
71
+ const backgroundColorMemberExpression = j.memberExpression(
72
+ expression,
73
+ j.stringLiteral('backgroundColor'),
74
+ );
75
+ backgroundColorMemberExpression.computed = true;
76
+
77
+ const textColorMemberExpression = j.memberExpression(
78
+ expression,
79
+ j.stringLiteral('textColor'),
80
+ );
81
+ textColorMemberExpression.computed = true;
82
+
83
+ return j.objectExpression([
84
+ j.objectProperty(
85
+ j.identifier('backgroundColor'),
86
+ backgroundColorMemberExpression,
87
+ ),
88
+ j.objectProperty(j.identifier('color'), textColorMemberExpression),
89
+ ]);
90
+ }
91
+
92
+ export default moveObjectAppearanceToStyle;
@@ -0,0 +1,18 @@
1
+ import { createRemoveFuncWithDefaultSpecifierFor } from '../../utils';
2
+
3
+ const comment = `
4
+ We could not automatically convert this code to the new API.
5
+
6
+ This file uses \`Lozenge\`’s \`theme\` prop. This has been deprecated and removed.
7
+
8
+ You will have to change your usage to use the \`style\` prop.
9
+ See the example on https://atlaskit.atlassian.com/examples/design-system/lozenge/with-custom-theme
10
+ `;
11
+
12
+ const removeThemeProp = createRemoveFuncWithDefaultSpecifierFor(
13
+ '@atlaskit/lozenge',
14
+ 'theme',
15
+ comment,
16
+ );
17
+
18
+ export default removeThemeProp;
@@ -0,0 +1,30 @@
1
+ // eslint-disable-next-line @repo/internal/fs/filename-pattern-match
2
+ import core from 'jscodeshift';
3
+ import { Collection } from 'jscodeshift/src/Collection';
4
+
5
+ import {
6
+ addCommentToStartOfFile,
7
+ getDefaultSpecifier,
8
+ getJSXAttributesByName,
9
+ } from '@atlaskit/codemod-utils';
10
+
11
+ export const createRemoveFuncWithDefaultSpecifierFor = (
12
+ component: string,
13
+ prop: string,
14
+ comment?: string,
15
+ ) => (j: core.JSCodeshift, source: Collection<Node>) => {
16
+ const specifier = getDefaultSpecifier(j, source, component);
17
+
18
+ if (!specifier) {
19
+ return;
20
+ }
21
+
22
+ source.findJSXElements(specifier).forEach((element) => {
23
+ getJSXAttributesByName(j, element, prop).forEach((attribute: any) => {
24
+ if (comment) {
25
+ addCommentToStartOfFile({ j, base: source, message: comment });
26
+ }
27
+ j(attribute).remove();
28
+ });
29
+ });
30
+ };