@sproutsocial/seeds-react-badge 1.0.5 → 2.0.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.
- package/codemods/__tests__/badge-1.x-to-2.x.test.ts +406 -0
- package/codemods/badge-1.x-to-2.x.ts +489 -0
- package/dist/codemods/badge-1.x-to-2.x.d.ts +2 -0
- package/dist/codemods/badge-1.x-to-2.x.js +285 -0
- package/dist/codemods/badge-1.x-to-2.x.js.map +1 -0
- package/dist/esm/index.js +51 -65
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +2 -9
- package/dist/index.d.ts +2 -9
- package/dist/index.js +51 -65
- package/dist/index.js.map +1 -1
- package/package.json +19 -3
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -4
- package/.turbo/turbo-build.log +0 -21
- package/CHANGELOG.md +0 -44
- package/jest.config.js +0 -9
- package/src/Badge.stories.tsx +0 -83
- package/src/Badge.tsx +0 -55
- package/src/BadgeTypes.ts +0 -30
- package/src/__tests__/features.test.tsx +0 -94
- package/src/__tests__/types.test.tsx +0 -28
- package/src/constants.ts +0 -64
- package/src/index.ts +0 -6
- package/src/styles.ts +0 -36
- package/tsconfig.json +0 -15
- package/tsup.config.ts +0 -12
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// codemods/badge-1.x-to-2.x.ts
|
|
4
|
+
var TYPE_TO_BADGE_COLOR = {
|
|
5
|
+
passive: "neutral",
|
|
6
|
+
default: "purple",
|
|
7
|
+
primary: "blue",
|
|
8
|
+
secondary: "yellow",
|
|
9
|
+
approval: "orange",
|
|
10
|
+
suggestion: "blue",
|
|
11
|
+
common: "aqua"
|
|
12
|
+
// Note: colors.container.background.decorative.aqua does not match colors.aqua.600
|
|
13
|
+
};
|
|
14
|
+
function mapTypeToBadgeColor(typeValue) {
|
|
15
|
+
if (typeValue in TYPE_TO_BADGE_COLOR) {
|
|
16
|
+
return TYPE_TO_BADGE_COLOR[typeValue];
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
function isBadgeComponent(jsxElement, j) {
|
|
21
|
+
const name = jsxElement.value.name;
|
|
22
|
+
if (!name || typeof name !== "object") return false;
|
|
23
|
+
if ("name" in name && name.name === "Badge") {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if ("type" in name && name.type === "JSXMemberExpression" && "property" in name && name.property?.name === "Badge") {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function findBadgeImport(root, j) {
|
|
32
|
+
const imports = root.find(j.ImportDeclaration);
|
|
33
|
+
let hasBadgeImport = false;
|
|
34
|
+
imports.forEach((path) => {
|
|
35
|
+
const source = path.value.source.value;
|
|
36
|
+
if (source === "@sproutsocial/racine" || source === "@sproutsocial/seeds-react-badge") {
|
|
37
|
+
const specifiers = path.value.specifiers || [];
|
|
38
|
+
specifiers.forEach((spec) => {
|
|
39
|
+
if (spec.type === "ImportSpecifier" && spec.imported?.name === "Badge" || spec.local?.name === "Badge") {
|
|
40
|
+
hasBadgeImport = true;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return hasBadgeImport;
|
|
46
|
+
}
|
|
47
|
+
function addDataAttributeTodo(ast, j, originalSource) {
|
|
48
|
+
let hasModifications = false;
|
|
49
|
+
const patterns = [
|
|
50
|
+
/data-qa-badge-type/i,
|
|
51
|
+
/data-qa-badge-tip/i,
|
|
52
|
+
/data-tip.*badge/i,
|
|
53
|
+
/badge-type/i,
|
|
54
|
+
/badge-tip/i,
|
|
55
|
+
/getByDataQaLabel\(['"]badge-type['"]/i,
|
|
56
|
+
/getByDataQaLabel\(['"]badge-tip['"]/i,
|
|
57
|
+
/queryByDataQaLabel\(['"]badge-type['"]/i,
|
|
58
|
+
/queryByDataQaLabel\(['"]badge-tip['"]/i,
|
|
59
|
+
/\.attr\(['"]data-tip['"]/i,
|
|
60
|
+
/\.attr\(['"]data-qa-badge/i,
|
|
61
|
+
/\[data-qa-badge-type\]/i,
|
|
62
|
+
/\[data-qa-badge-tip\]/i
|
|
63
|
+
];
|
|
64
|
+
const hasMatch = patterns.some((pattern) => pattern.test(originalSource));
|
|
65
|
+
if (hasMatch) {
|
|
66
|
+
const program = ast.find(j.Program).paths()[0];
|
|
67
|
+
if (program) {
|
|
68
|
+
const programBody = program.value.body;
|
|
69
|
+
const firstStatement = programBody[0];
|
|
70
|
+
const statementWithComments = firstStatement;
|
|
71
|
+
const existingComment = statementWithComments?.leadingComments?.some(
|
|
72
|
+
(comment) => comment.value && comment.value.includes("badge-1.x-to-2.x codemod")
|
|
73
|
+
) || program.value.comments?.some(
|
|
74
|
+
(comment) => comment.value && comment.value.includes("badge-1.x-to-2.x codemod")
|
|
75
|
+
);
|
|
76
|
+
if (!existingComment && firstStatement) {
|
|
77
|
+
const todoComment = j.commentBlock(
|
|
78
|
+
` TODO (badge-1.x-to-2.x codemod): Data attributes data-qa-badge-type, data-qa-badge-tip, and data-tip have been removed from Badge component. Update test selectors and data attribute references. `,
|
|
79
|
+
true
|
|
80
|
+
);
|
|
81
|
+
const statementWithComments2 = firstStatement;
|
|
82
|
+
statementWithComments2.comments = statementWithComments2.comments ? [todoComment, ...statementWithComments2.comments] : [todoComment];
|
|
83
|
+
hasModifications = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return hasModifications;
|
|
88
|
+
}
|
|
89
|
+
function transformer(file, api, options) {
|
|
90
|
+
const j = api.jscodeshift;
|
|
91
|
+
const root = j(file.source);
|
|
92
|
+
let hasModifications = false;
|
|
93
|
+
const dataAttrModifications = addDataAttributeTodo(root, j, file.source);
|
|
94
|
+
if (dataAttrModifications) {
|
|
95
|
+
hasModifications = true;
|
|
96
|
+
}
|
|
97
|
+
const hasBadgeImport = findBadgeImport(root, j);
|
|
98
|
+
if (!hasBadgeImport) {
|
|
99
|
+
return hasModifications ? root.toSource(options) : file.source;
|
|
100
|
+
}
|
|
101
|
+
const badgeElements = root.find(j.JSXElement).filter((path) => {
|
|
102
|
+
const openingElement = path.value.openingElement;
|
|
103
|
+
return openingElement && isBadgeComponent({ value: openingElement }, j);
|
|
104
|
+
});
|
|
105
|
+
badgeElements.forEach((path) => {
|
|
106
|
+
const openingElement = path.value.openingElement;
|
|
107
|
+
if (!openingElement || !isBadgeComponent({ value: openingElement }, j))
|
|
108
|
+
return;
|
|
109
|
+
const attrs = openingElement.attributes || [];
|
|
110
|
+
const newAttrs = [];
|
|
111
|
+
let hasText = false;
|
|
112
|
+
let textValue = null;
|
|
113
|
+
let hasType = false;
|
|
114
|
+
let typeIsDynamic = false;
|
|
115
|
+
let typeStr = null;
|
|
116
|
+
attrs.forEach((attr) => {
|
|
117
|
+
if (attr.type === "JSXSpreadAttribute") {
|
|
118
|
+
newAttrs.push(attr);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const attrName = attr.name.name;
|
|
122
|
+
if (attrName === "size") {
|
|
123
|
+
let sizeValue = null;
|
|
124
|
+
if (attr.value && (attr.value.type === "Literal" || attr.value.type === "StringLiteral") && typeof attr.value.value === "string") {
|
|
125
|
+
sizeValue = attr.value.value;
|
|
126
|
+
} else if (attr.value && attr.value.type === "JSXExpressionContainer" && attr.value.expression && (attr.value.expression.type === "Literal" || attr.value.expression.type === "StringLiteral") && typeof attr.value.expression.value === "string") {
|
|
127
|
+
sizeValue = attr.value.expression.value;
|
|
128
|
+
}
|
|
129
|
+
if (sizeValue === "default") {
|
|
130
|
+
newAttrs.push(
|
|
131
|
+
j.jsxAttribute(j.jsxIdentifier("size"), j.literal("large"))
|
|
132
|
+
);
|
|
133
|
+
hasModifications = true;
|
|
134
|
+
} else {
|
|
135
|
+
newAttrs.push(attr);
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (attrName === "type") {
|
|
140
|
+
hasType = true;
|
|
141
|
+
if (attr.value) {
|
|
142
|
+
if (attr.value.type === "JSXExpressionContainer") {
|
|
143
|
+
const expr = attr.value.expression;
|
|
144
|
+
if (expr && expr.type !== "Literal" && expr.type !== "StringLiteral") {
|
|
145
|
+
typeIsDynamic = true;
|
|
146
|
+
}
|
|
147
|
+
} else if (attr.value.type !== "Literal" && attr.value.type !== "StringLiteral") {
|
|
148
|
+
typeIsDynamic = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!typeIsDynamic && attr.value) {
|
|
152
|
+
if ((attr.value.type === "Literal" || attr.value.type === "StringLiteral") && typeof attr.value.value === "string") {
|
|
153
|
+
typeStr = attr.value.value;
|
|
154
|
+
} else if (attr.value.type === "JSXExpressionContainer" && attr.value.expression && (attr.value.expression.type === "Literal" || attr.value.expression.type === "StringLiteral") && typeof attr.value.expression.value === "string") {
|
|
155
|
+
typeStr = attr.value.expression.value;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
hasModifications = true;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (attrName === "badgeColor") {
|
|
162
|
+
newAttrs.push(attr);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (attrName === "tip") {
|
|
166
|
+
hasModifications = true;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (attrName === "text") {
|
|
170
|
+
hasText = true;
|
|
171
|
+
textValue = attr.value;
|
|
172
|
+
hasModifications = true;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
newAttrs.push(attr);
|
|
176
|
+
});
|
|
177
|
+
if (hasType && !typeIsDynamic && typeStr) {
|
|
178
|
+
const badgeColor = mapTypeToBadgeColor(typeStr);
|
|
179
|
+
if (badgeColor !== void 0) {
|
|
180
|
+
const existingBadgeColor = newAttrs.find(
|
|
181
|
+
(a) => a.type !== "JSXSpreadAttribute" && a.name.name === "badgeColor"
|
|
182
|
+
);
|
|
183
|
+
if (!existingBadgeColor) {
|
|
184
|
+
newAttrs.push(
|
|
185
|
+
j.jsxAttribute(j.jsxIdentifier("badgeColor"), j.literal(badgeColor))
|
|
186
|
+
);
|
|
187
|
+
hasModifications = true;
|
|
188
|
+
}
|
|
189
|
+
if (typeStr === "common") {
|
|
190
|
+
const parentPath = path.parentPath;
|
|
191
|
+
if (parentPath && parentPath.value) {
|
|
192
|
+
const parentNode = parentPath.value;
|
|
193
|
+
const todoComment = j.commentBlock(
|
|
194
|
+
` TODO (badge-1.x-to-2.x codemod): type="common" mapped to badgeColor="aqua", but colors.container.background.decorative.aqua does not match original colors.aqua.600. Verify color match. `,
|
|
195
|
+
true
|
|
196
|
+
);
|
|
197
|
+
parentNode.comments = parentNode.comments ? [todoComment, ...parentNode.comments] : [todoComment];
|
|
198
|
+
hasModifications = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
const parentPath = path.parentPath;
|
|
203
|
+
if (parentPath && parentPath.value) {
|
|
204
|
+
const parentNode = parentPath.value;
|
|
205
|
+
const todoComment = j.commentBlock(
|
|
206
|
+
` TODO (badge-1.x-to-2.x codemod): Unmapped static type value "${typeStr}". Manually update to a valid badgeColor. `,
|
|
207
|
+
true
|
|
208
|
+
);
|
|
209
|
+
parentNode.comments = parentNode.comments ? [todoComment, ...parentNode.comments] : [todoComment];
|
|
210
|
+
hasModifications = true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
openingElement.attributes = newAttrs;
|
|
215
|
+
if (hasType && typeIsDynamic) {
|
|
216
|
+
let currentPath = path.parentPath;
|
|
217
|
+
let statementNode = null;
|
|
218
|
+
while (currentPath) {
|
|
219
|
+
const node = currentPath.value;
|
|
220
|
+
if (node && typeof node === "object" && "type" in node && node.type !== "JSXElement" && node.type !== "JSXFragment" && node.type !== "JSXExpressionContainer") {
|
|
221
|
+
statementNode = node;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
currentPath = currentPath.parentPath;
|
|
225
|
+
}
|
|
226
|
+
if (!statementNode) {
|
|
227
|
+
const parentPath = path.parentPath;
|
|
228
|
+
if (parentPath && parentPath.value) {
|
|
229
|
+
statementNode = parentPath.value;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (statementNode) {
|
|
233
|
+
const todoComment = j.commentBlock(
|
|
234
|
+
` TODO (badge-1.x-to-2.x codemod): Update function/variable to return badgeColor values instead of type values. See type-to-badgeColor mapping: passive\u2192neutral, default\u2192purple, primary\u2192blue, secondary\u2192yellow, approval\u2192orange, suggestion\u2192blue, common\u2192aqua. `,
|
|
235
|
+
true
|
|
236
|
+
);
|
|
237
|
+
statementNode.comments = statementNode.comments ? [todoComment, ...statementNode.comments] : [todoComment];
|
|
238
|
+
hasModifications = true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (hasText) {
|
|
242
|
+
if (!path.value.children || path.value.children.length === 0) {
|
|
243
|
+
if (textValue) {
|
|
244
|
+
let childNodes = [];
|
|
245
|
+
if (textValue && typeof textValue === "object" && "type" in textValue) {
|
|
246
|
+
const textValueWithType = textValue;
|
|
247
|
+
if (textValueWithType.type === "Literal") {
|
|
248
|
+
childNodes = [j.jsxText(String(textValueWithType.value))];
|
|
249
|
+
} else if (textValueWithType.type === "JSXExpressionContainer") {
|
|
250
|
+
if (textValueWithType.expression) {
|
|
251
|
+
if (typeof textValueWithType.expression === "object" && "type" in textValueWithType.expression && textValueWithType.expression.type === "JSXElement") {
|
|
252
|
+
childNodes = [textValueWithType.expression];
|
|
253
|
+
} else {
|
|
254
|
+
childNodes = [textValue];
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
childNodes = [textValue];
|
|
258
|
+
}
|
|
259
|
+
} else if (textValueWithType.type === "JSXElement") {
|
|
260
|
+
childNodes = [textValue];
|
|
261
|
+
} else {
|
|
262
|
+
childNodes = [j.jsxExpressionContainer(textValue)];
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
childNodes = [j.jsxExpressionContainer(textValue)];
|
|
266
|
+
}
|
|
267
|
+
const newOpeningElement = j.jsxOpeningElement(
|
|
268
|
+
openingElement.name,
|
|
269
|
+
newAttrs
|
|
270
|
+
);
|
|
271
|
+
const newJSXElement = j.jsxElement(
|
|
272
|
+
newOpeningElement,
|
|
273
|
+
j.jsxClosingElement(openingElement.name),
|
|
274
|
+
childNodes
|
|
275
|
+
);
|
|
276
|
+
path.replace(newJSXElement);
|
|
277
|
+
hasModifications = true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return hasModifications ? root.toSource(options) : file.source;
|
|
283
|
+
}
|
|
284
|
+
module.exports = transformer;
|
|
285
|
+
//# sourceMappingURL=badge-1.x-to-2.x.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../codemods/badge-1.x-to-2.x.ts"],"sourcesContent":["import type { API, FileInfo, Options, Collection } from \"jscodeshift\";\n\n// Type to badgeColor mapping\nconst TYPE_TO_BADGE_COLOR = {\n passive: \"neutral\",\n default: \"purple\",\n primary: \"blue\",\n secondary: \"yellow\",\n approval: \"orange\",\n suggestion: \"blue\",\n common: \"aqua\", // Note: colors.container.background.decorative.aqua does not match colors.aqua.600\n} as const;\n\ntype BadgeType = keyof typeof TYPE_TO_BADGE_COLOR;\ntype BadgeColor = (typeof TYPE_TO_BADGE_COLOR)[BadgeType];\n\n// Map type value to badgeColor value\nfunction mapTypeToBadgeColor(typeValue: string): BadgeColor | undefined {\n if (typeValue in TYPE_TO_BADGE_COLOR) {\n return TYPE_TO_BADGE_COLOR[typeValue as BadgeType];\n }\n // Invalid type value - should not happen in practice\n return undefined;\n}\n\n// Check if Badge is imported from racine or seeds-react-badge\nfunction isBadgeComponent(\n jsxElement: { value: { name: unknown } },\n j: API[\"jscodeshift\"]\n): boolean {\n const name = jsxElement.value.name;\n if (!name || typeof name !== \"object\") return false;\n\n // Handle direct usage: <Badge />\n if (\"name\" in name && (name as { name: string }).name === \"Badge\") {\n return true;\n }\n\n // Handle member expressions: <Some.Badge />\n if (\n \"type\" in name &&\n (name as { type: string }).type === \"JSXMemberExpression\" &&\n \"property\" in name &&\n (name as { property?: { name?: string } }).property?.name === \"Badge\"\n ) {\n return true;\n }\n\n return false;\n}\n\n// Find Badge import from racine or seeds-react-badge\nfunction findBadgeImport(\n root: Collection<any>,\n j: API[\"jscodeshift\"]\n): boolean {\n const imports = root.find(j.ImportDeclaration);\n let hasBadgeImport = false;\n\n imports.forEach((path) => {\n const source = path.value.source.value;\n if (\n source === \"@sproutsocial/racine\" ||\n source === \"@sproutsocial/seeds-react-badge\"\n ) {\n const specifiers = path.value.specifiers || [];\n specifiers.forEach((spec) => {\n if (\n (spec.type === \"ImportSpecifier\" &&\n spec.imported?.name === \"Badge\") ||\n spec.local?.name === \"Badge\"\n ) {\n hasBadgeImport = true;\n }\n });\n }\n });\n\n return hasBadgeImport;\n}\n\n// Add TODO comment for data attribute references\nfunction addDataAttributeTodo(\n ast: Collection<any>,\n j: API[\"jscodeshift\"],\n originalSource: string\n): boolean {\n let hasModifications = false;\n\n // Patterns to search for (case-insensitive, handle both single and double quotes)\n const patterns = [\n /data-qa-badge-type/i,\n /data-qa-badge-tip/i,\n /data-tip.*badge/i,\n /badge-type/i,\n /badge-tip/i,\n /getByDataQaLabel\\(['\"]badge-type['\"]/i,\n /getByDataQaLabel\\(['\"]badge-tip['\"]/i,\n /queryByDataQaLabel\\(['\"]badge-type['\"]/i,\n /queryByDataQaLabel\\(['\"]badge-tip['\"]/i,\n /\\.attr\\(['\"]data-tip['\"]/i,\n /\\.attr\\(['\"]data-qa-badge/i,\n /\\[data-qa-badge-type\\]/i,\n /\\[data-qa-badge-tip\\]/i,\n ];\n\n // Check if any pattern matches\n const hasMatch = patterns.some((pattern) => pattern.test(originalSource));\n\n if (hasMatch) {\n // Find the Program node to add comment\n const program = ast.find(j.Program).paths()[0];\n if (program) {\n // Check if TODO comment already exists\n const programBody = program.value.body;\n const firstStatement = programBody[0];\n const statementWithComments = firstStatement as {\n leadingComments?: Array<{ value?: string }>;\n };\n const existingComment =\n statementWithComments?.leadingComments?.some(\n (comment: { value?: string }) =>\n comment.value && comment.value.includes(\"badge-1.x-to-2.x codemod\")\n ) ||\n program.value.comments?.some(\n (comment) =>\n comment.value && comment.value.includes(\"badge-1.x-to-2.x codemod\")\n );\n\n if (!existingComment && firstStatement) {\n const todoComment = j.commentBlock(\n ` TODO (badge-1.x-to-2.x codemod): Data attributes data-qa-badge-type, data-qa-badge-tip, and data-tip have been removed from Badge component. Update test selectors and data attribute references. `,\n true\n );\n\n // Add comment before the first statement using comments property (like icon-library codemod)\n const statementWithComments = firstStatement as {\n comments?: Array<{ value?: string }>;\n };\n statementWithComments.comments = statementWithComments.comments\n ? [todoComment, ...statementWithComments.comments]\n : [todoComment];\n hasModifications = true;\n }\n }\n }\n\n return hasModifications;\n}\n\nfunction transformer(\n file: FileInfo,\n api: API,\n options: Options\n): string | null {\n const j = api.jscodeshift;\n const root = j(file.source);\n let hasModifications = false;\n\n // Add TODO comments for data attribute references (check regardless of Badge imports)\n // Use original file source for pattern matching\n const dataAttrModifications = addDataAttributeTodo(root, j, file.source);\n if (dataAttrModifications) {\n hasModifications = true;\n }\n\n // Only process files that import Badge from racine or seeds-react-badge\n const hasBadgeImport = findBadgeImport(root, j);\n\n // If no Badge import, return unchanged (don't transform other Badge components)\n if (!hasBadgeImport) {\n return hasModifications ? root.toSource(options) : file.source;\n }\n\n // Find Badge JSX elements (find JSXElement, not just opening element)\n const badgeElements = root.find(j.JSXElement).filter((path) => {\n const openingElement = path.value.openingElement;\n return openingElement && isBadgeComponent({ value: openingElement }, j);\n });\n\n // Transform Badge JSX elements\n badgeElements.forEach((path) => {\n const openingElement = path.value.openingElement;\n if (!openingElement || !isBadgeComponent({ value: openingElement }, j))\n return;\n\n const attrs = openingElement.attributes || [];\n const newAttrs: Array<(typeof attrs)[number]> = [];\n let hasText = false;\n let textValue: unknown = null;\n let hasType = false;\n let typeIsDynamic = false;\n let typeStr: string | null = null; // Store extracted type value\n\n // Process all attributes\n attrs.forEach((attr) => {\n if (attr.type === \"JSXSpreadAttribute\") {\n // Keep spread attributes\n newAttrs.push(attr);\n return;\n }\n\n const attrName = attr.name.name;\n\n // Handle size=\"default\" -> size=\"large\"\n if (attrName === \"size\") {\n let sizeValue: string | null = null;\n\n if (\n attr.value &&\n (attr.value.type === \"Literal\" ||\n attr.value.type === \"StringLiteral\") &&\n typeof attr.value.value === \"string\"\n ) {\n sizeValue = attr.value.value;\n } else if (\n attr.value &&\n attr.value.type === \"JSXExpressionContainer\" &&\n attr.value.expression &&\n (attr.value.expression.type === \"Literal\" ||\n attr.value.expression.type === \"StringLiteral\") &&\n typeof attr.value.expression.value === \"string\"\n ) {\n sizeValue = attr.value.expression.value;\n }\n\n if (sizeValue === \"default\") {\n newAttrs.push(\n j.jsxAttribute(j.jsxIdentifier(\"size\"), j.literal(\"large\"))\n );\n hasModifications = true;\n } else {\n newAttrs.push(attr);\n }\n return;\n }\n\n // Handle type prop\n if (attrName === \"type\") {\n hasType = true;\n\n // Check if it's a dynamic value (variable or function call)\n if (attr.value) {\n if (attr.value.type === \"JSXExpressionContainer\") {\n const expr = attr.value.expression;\n if (\n expr &&\n expr.type !== \"Literal\" &&\n expr.type !== \"StringLiteral\"\n ) {\n typeIsDynamic = true;\n }\n } else if (\n attr.value.type !== \"Literal\" &&\n attr.value.type !== \"StringLiteral\"\n ) {\n typeIsDynamic = true;\n }\n }\n\n // Map static type values - extract typeStr but don't add badgeColor yet\n if (!typeIsDynamic && attr.value) {\n if (\n (attr.value.type === \"Literal\" ||\n attr.value.type === \"StringLiteral\") &&\n typeof attr.value.value === \"string\"\n ) {\n typeStr = attr.value.value;\n } else if (\n attr.value.type === \"JSXExpressionContainer\" &&\n attr.value.expression &&\n (attr.value.expression.type === \"Literal\" ||\n attr.value.expression.type === \"StringLiteral\") &&\n typeof attr.value.expression.value === \"string\"\n ) {\n typeStr = attr.value.expression.value;\n }\n }\n\n // Don't add type prop to newAttrs - it's being removed\n // Mark as modified since we're removing the type prop\n hasModifications = true;\n return;\n }\n\n // Handle badgeColor - keep it if it exists\n if (attrName === \"badgeColor\") {\n newAttrs.push(attr);\n return;\n }\n\n // Handle tip prop - remove it\n if (attrName === \"tip\") {\n hasModifications = true;\n return; // Don't add to newAttrs\n }\n\n // Handle text prop\n if (attrName === \"text\") {\n hasText = true;\n textValue = attr.value;\n hasModifications = true;\n // Don't add text prop to newAttrs - we'll convert to children\n return;\n }\n\n // Keep all other attributes\n newAttrs.push(attr);\n });\n\n // After processing all attributes, add badgeColor if needed\n if (hasType && !typeIsDynamic && typeStr) {\n const badgeColor = mapTypeToBadgeColor(typeStr);\n\n if (badgeColor !== undefined) {\n // Check if badgeColor already exists in newAttrs\n const existingBadgeColor = newAttrs.find(\n (a) => a.type !== \"JSXSpreadAttribute\" && a.name.name === \"badgeColor\"\n );\n\n if (!existingBadgeColor) {\n newAttrs.push(\n j.jsxAttribute(j.jsxIdentifier(\"badgeColor\"), j.literal(badgeColor))\n );\n hasModifications = true;\n }\n\n // Special handling for \"common\" type - add TODO comment\n if (typeStr === \"common\") {\n const parentPath = path.parentPath;\n if (parentPath && parentPath.value) {\n const parentNode = parentPath.value as {\n comments?: Array<{ value?: string }>;\n };\n const todoComment = j.commentBlock(\n ` TODO (badge-1.x-to-2.x codemod): type=\"common\" mapped to badgeColor=\"aqua\", but colors.container.background.decorative.aqua does not match original colors.aqua.600. Verify color match. `,\n true\n );\n parentNode.comments = parentNode.comments\n ? [todoComment, ...parentNode.comments]\n : [todoComment];\n hasModifications = true;\n }\n }\n } else {\n // Add TODO comment for unmapped static type values\n const parentPath = path.parentPath;\n if (parentPath && parentPath.value) {\n const parentNode = parentPath.value as {\n comments?: Array<{ value?: string }>;\n };\n const todoComment = j.commentBlock(\n ` TODO (badge-1.x-to-2.x codemod): Unmapped static type value \"${typeStr}\". Manually update to a valid badgeColor. `,\n true\n );\n parentNode.comments = parentNode.comments\n ? [todoComment, ...parentNode.comments]\n : [todoComment];\n hasModifications = true;\n }\n }\n }\n\n // Update attributes\n openingElement.attributes = newAttrs;\n\n // Handle dynamic type - add TODO comment\n if (hasType && typeIsDynamic) {\n // Traverse up to find the containing statement (not just immediate parent)\n let currentPath = path.parentPath;\n let statementNode: { comments?: Array<{ value?: string }> } | null = null;\n\n // Keep traversing up until we find a statement or reach the Program\n while (currentPath) {\n const node = currentPath.value;\n // Check if this is a statement (not JSX)\n if (\n node &&\n typeof node === \"object\" &&\n \"type\" in node &&\n node.type !== \"JSXElement\" &&\n node.type !== \"JSXFragment\" &&\n node.type !== \"JSXExpressionContainer\"\n ) {\n statementNode = node as { comments?: Array<{ value?: string }> };\n break;\n }\n currentPath = currentPath.parentPath;\n }\n\n // If we didn't find a statement, try to add to the JSXElement's parent\n if (!statementNode) {\n const parentPath = path.parentPath;\n if (parentPath && parentPath.value) {\n statementNode = parentPath.value as {\n comments?: Array<{ value?: string }>;\n };\n }\n }\n\n if (statementNode) {\n const todoComment = j.commentBlock(\n ` TODO (badge-1.x-to-2.x codemod): Update function/variable to return badgeColor values instead of type values. See type-to-badgeColor mapping: passive→neutral, default→purple, primary→blue, secondary→yellow, approval→orange, suggestion→blue, common→aqua. `,\n true\n );\n statementNode.comments = statementNode.comments\n ? [todoComment, ...statementNode.comments]\n : [todoComment];\n hasModifications = true;\n }\n }\n\n // Handle text prop -> children conversion\n if (hasText) {\n // path is already the JSXElement\n // Only convert if there are no existing children\n if (!path.value.children || path.value.children.length === 0) {\n if (textValue) {\n let childNodes: unknown[] = [];\n\n // Handle different text value types\n if (\n textValue &&\n typeof textValue === \"object\" &&\n \"type\" in textValue\n ) {\n const textValueWithType = textValue as {\n type: string;\n expression?: unknown;\n value?: unknown;\n };\n if (textValueWithType.type === \"Literal\") {\n childNodes = [j.jsxText(String(textValueWithType.value))];\n } else if (textValueWithType.type === \"JSXExpressionContainer\") {\n // Extract the expression from the container\n if (textValueWithType.expression) {\n if (\n typeof textValueWithType.expression === \"object\" &&\n \"type\" in textValueWithType.expression &&\n (textValueWithType.expression as { type: string }).type ===\n \"JSXElement\"\n ) {\n // JSX element inside expression container - extract it\n childNodes = [textValueWithType.expression];\n } else {\n // Keep the expression container\n childNodes = [textValue];\n }\n } else {\n childNodes = [textValue];\n }\n } else if (textValueWithType.type === \"JSXElement\") {\n // Direct JSX element\n childNodes = [textValue];\n } else {\n // Wrap in expression container\n childNodes = [j.jsxExpressionContainer(textValue as any)];\n }\n } else {\n // Wrap in expression container\n childNodes = [j.jsxExpressionContainer(textValue as any)];\n }\n\n // Create a new opening element with updated attributes\n const newOpeningElement = j.jsxOpeningElement(\n openingElement.name,\n newAttrs\n );\n\n // Create a new JSXElement with children and closing element\n const newJSXElement = j.jsxElement(\n newOpeningElement,\n j.jsxClosingElement(openingElement.name),\n childNodes as Parameters<typeof j.jsxElement>[2]\n );\n\n // Replace the old element with the new one\n path.replace(newJSXElement);\n\n hasModifications = true;\n }\n }\n }\n });\n\n return hasModifications ? root.toSource(options) : file.source;\n}\n\nmodule.exports = transformer;\n"],"mappings":";;;AAGA,IAAM,sBAAsB;AAAA,EAC1B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA;AACV;AAMA,SAAS,oBAAoB,WAA2C;AACtE,MAAI,aAAa,qBAAqB;AACpC,WAAO,oBAAoB,SAAsB;AAAA,EACnD;AAEA,SAAO;AACT;AAGA,SAAS,iBACP,YACA,GACS;AACT,QAAM,OAAO,WAAW,MAAM;AAC9B,MAAI,CAAC,QAAQ,OAAO,SAAS,SAAU,QAAO;AAG9C,MAAI,UAAU,QAAS,KAA0B,SAAS,SAAS;AACjE,WAAO;AAAA,EACT;AAGA,MACE,UAAU,QACT,KAA0B,SAAS,yBACpC,cAAc,QACb,KAA0C,UAAU,SAAS,SAC9D;AACA,WAAO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,OAAO;AAEL,2BAAa,CAAC,EAAE,uBAAuB,SAAgB,CAAC;AAAA,YAC1D;AAAA,UACF,OAAO;AAEL,yBAAa,CAAC,EAAE,uBAAuB,SAAgB,CAAC;AAAA,UAC1D;AAGA,gBAAM,oBAAoB,EAAE;AAAA,YAC1B,eAAe;AAAA,YACf;AAAA,UACF;AAGA,gBAAM,gBAAgB,EAAE;AAAA,YACtB;AAAA,YACA,EAAE,kBAAkB,eAAe,IAAI;AAAA,YACvC;AAAA,UACF;AAGA,eAAK,QAAQ,aAAa;AAE1B,6BAAmB;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,mBAAmB,KAAK,SAAS,OAAO,IAAI,KAAK;AAC1D;AAEA,OAAO,UAAU;","names":["statementWithComments"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// src/Badge.tsx
|
|
2
|
-
import "react";
|
|
3
|
-
import Box from "@sproutsocial/seeds-react-box";
|
|
4
|
-
import Icon from "@sproutsocial/seeds-react-icon";
|
|
2
|
+
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
5
3
|
|
|
6
4
|
// src/styles.ts
|
|
7
5
|
import styled from "styled-components";
|
|
@@ -421,6 +419,56 @@ var De = y(l({ cursor: true, whiteSpace: true }));
|
|
|
421
419
|
var Ve = y(L({ key: "typography", prop: "typeScale" }));
|
|
422
420
|
var mo = y(De, Ve, V, I, A, D, G, E, H, $, N, M);
|
|
423
421
|
|
|
422
|
+
// src/styles.ts
|
|
423
|
+
var StyledBadge = styled.span`
|
|
424
|
+
font-family: ${(p) => p.theme.fontFamily};
|
|
425
|
+
${(p) => p.size === "small" ? p.theme.typography[100] : p.theme.typography[200]};
|
|
426
|
+
border-radius: 9999px;
|
|
427
|
+
line-height: 16px;
|
|
428
|
+
display: inline-flex;
|
|
429
|
+
align-items: center;
|
|
430
|
+
justify-content: center;
|
|
431
|
+
color: ${(p) => p.theme.colors.text.body};
|
|
432
|
+
background: ${(p) => p.theme.colors.container.background.decorative[p.badgeColor]};
|
|
433
|
+
padding: ${(p) => p.size === "small" ? `${p.theme.space[0]} ${p.theme.space[200]}` : `${p.theme.space[300]}`};
|
|
434
|
+
${ke};
|
|
435
|
+
`;
|
|
436
|
+
|
|
437
|
+
// src/Badge.tsx
|
|
438
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
439
|
+
var Badge = ({
|
|
440
|
+
children,
|
|
441
|
+
iconName,
|
|
442
|
+
size = "small",
|
|
443
|
+
badgeColor = "blue",
|
|
444
|
+
color,
|
|
445
|
+
...rest
|
|
446
|
+
}) => {
|
|
447
|
+
return /* @__PURE__ */ jsxs(
|
|
448
|
+
StyledBadge,
|
|
449
|
+
{
|
|
450
|
+
size,
|
|
451
|
+
badgeColor,
|
|
452
|
+
"data-qa-badge": true,
|
|
453
|
+
color,
|
|
454
|
+
...rest,
|
|
455
|
+
children: [
|
|
456
|
+
iconName ? /* @__PURE__ */ jsx(
|
|
457
|
+
Icon,
|
|
458
|
+
{
|
|
459
|
+
mr: 200,
|
|
460
|
+
name: iconName,
|
|
461
|
+
size: size === "small" ? "mini" : "small",
|
|
462
|
+
"aria-hidden": true
|
|
463
|
+
}
|
|
464
|
+
) : null,
|
|
465
|
+
children
|
|
466
|
+
]
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
};
|
|
470
|
+
var Badge_default = Badge;
|
|
471
|
+
|
|
424
472
|
// src/constants.ts
|
|
425
473
|
var defaultPurple = {
|
|
426
474
|
color: "colors.text.body",
|
|
@@ -473,68 +521,6 @@ var badgeColors = {
|
|
|
473
521
|
teal: "teal"
|
|
474
522
|
};
|
|
475
523
|
|
|
476
|
-
// src/styles.ts
|
|
477
|
-
import { themeGet } from "@styled-system/theme-get";
|
|
478
|
-
var Container = styled.span`
|
|
479
|
-
font-family: ${(p) => p.theme.fontFamily};
|
|
480
|
-
${(p) => p.size === "small" ? p.theme.typography[100] : p.theme.typography[200]};
|
|
481
|
-
border-radius: 9999px;
|
|
482
|
-
line-height: 16px;
|
|
483
|
-
display: inline-block;
|
|
484
|
-
color: ${(p) => p.type ? themeGet(legacyBadgeColors[p.type].color) : p.theme.colors.text.body};
|
|
485
|
-
background: ${(p) => p.type ? themeGet(legacyBadgeColors[p.type].background) : p.theme.colors.container.background.decorative[p.badgeColor]};
|
|
486
|
-
padding: ${(p) => p.size === "small" ? `${p.theme.space[0]} ${p.theme.space[200]}` : `${p.theme.space[300]}`};
|
|
487
|
-
${ke};
|
|
488
|
-
`;
|
|
489
|
-
var styles_default = Container;
|
|
490
|
-
|
|
491
|
-
// src/Badge.tsx
|
|
492
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
493
|
-
var Badge = ({
|
|
494
|
-
children,
|
|
495
|
-
text,
|
|
496
|
-
iconName,
|
|
497
|
-
type,
|
|
498
|
-
tip,
|
|
499
|
-
size = "small",
|
|
500
|
-
badgeColor = "blue",
|
|
501
|
-
color,
|
|
502
|
-
...rest
|
|
503
|
-
}) => {
|
|
504
|
-
if (children && text) {
|
|
505
|
-
throw new Error(
|
|
506
|
-
"can't use both `children` and `text` props. Text is deprecated, consider using children."
|
|
507
|
-
);
|
|
508
|
-
}
|
|
509
|
-
return /* @__PURE__ */ jsx(
|
|
510
|
-
styles_default,
|
|
511
|
-
{
|
|
512
|
-
size: size === "default" ? "large" : size,
|
|
513
|
-
badgeColor,
|
|
514
|
-
"data-tip": tip,
|
|
515
|
-
"data-qa-badge": text || "",
|
|
516
|
-
"data-qa-badge-type": type,
|
|
517
|
-
"data-qa-badge-tip": tip || "",
|
|
518
|
-
type,
|
|
519
|
-
color,
|
|
520
|
-
...rest,
|
|
521
|
-
children: /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "center", children: [
|
|
522
|
-
iconName ? /* @__PURE__ */ jsx(
|
|
523
|
-
Icon,
|
|
524
|
-
{
|
|
525
|
-
mr: 200,
|
|
526
|
-
name: iconName,
|
|
527
|
-
size: size === "small" ? "mini" : "small",
|
|
528
|
-
"aria-hidden": true
|
|
529
|
-
}
|
|
530
|
-
) : null,
|
|
531
|
-
children || text
|
|
532
|
-
] })
|
|
533
|
-
}
|
|
534
|
-
);
|
|
535
|
-
};
|
|
536
|
-
var Badge_default = Badge;
|
|
537
|
-
|
|
538
524
|
// src/index.ts
|
|
539
525
|
var index_default = Badge_default;
|
|
540
526
|
export {
|