@atlaskit/forge-react-types 0.52.1 → 0.52.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/forge-react-types
2
2
 
3
+ ## 0.52.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`baaa9523c646c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/baaa9523c646c) -
8
+ Update Lozenge and Badge prop types
9
+
3
10
  ## 0.52.1
4
11
 
5
12
  ### Patch Changes
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - BadgeProps
5
5
  *
6
- * @codegen <<SignedSource::dded43c94e5bc997c5df041eeb253927>>
6
+ * @codegen <<SignedSource::9d4cb948f5d6ac145a3d3e82ab8cfa92>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
- * @codegenDependency ../../../../forge-ui/src/components/UIKit/badge/__generated__/index.partial.tsx <<SignedSource::002a848f01b18a8dea0ea160d731edbf>>
8
+ * @codegenDependency ../../../../forge-ui/src/components/UIKit/badge/__generated__/index.partial.tsx <<SignedSource::f9bf0bacecb91875eab391c4148409c1>>
9
9
  */
10
10
  import type React from 'react';
11
11
  export type PlatformBadgeProps = Omit<_PlatformBadgeProps, 'children'> & {
@@ -20,7 +20,7 @@ type _PlatformBadgeProps = {
20
20
  /**
21
21
  * Affects the visual style of the badge.
22
22
  */
23
- appearance?: 'added' | 'default' | 'important' | 'primary' | 'primaryInverted' | 'removed';
23
+ appearance?: 'added' | 'default' | 'important' | 'primary' | 'primaryInverted' | 'removed' | 'warning' | 'discovery' | 'danger' | 'neutral' | 'success' | 'information' | 'inverse';
24
24
  children?: React.ReactNode;
25
25
  /**
26
26
  * The maximum value to display. Defaults to `99`. If the value is 100, and max is 50, "50+" will be displayed.
@@ -3,34 +3,36 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - LozengeProps
5
5
  *
6
- * @codegen <<SignedSource::2c6d1eb88477563937e65c98996d0b92>>
6
+ * @codegen <<SignedSource::abe727d97158c4d16d13504ebd7f60d6>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
- * @codegenDependency ../../../../forge-ui/src/components/UIKit/lozenge/__generated__/index.partial.tsx <<SignedSource::5e9e88bd5dd513ba567d815ada9e7eae>>
8
+ * @codegenDependency ../../../../forge-ui/src/components/UIKit/lozenge/__generated__/index.partial.tsx <<SignedSource::9799ca9fa788b29c08dfbdb778da62b4>>
9
9
  */
10
10
  import type React from 'react';
11
11
  type PlatformLozengeProps = {
12
12
  /**
13
- * Elements to be rendered inside the lozenge. This should ideally be just a word or two.
13
+ * The appearance of the lozenge. Supports both legacy semantic appearances and new accent/semantic colors.
14
+ * Legacy appearances (default, success, removed, inprogress, new, moved) are automatically mapped to the new semantic colors.
14
15
  */
15
- children?: React.ReactNode;
16
+ appearance?: 'default' | 'inprogress' | 'moved' | 'new' | 'removed' | 'success' | 'warning' | 'danger' | 'information' | 'neutral' | 'discovery' | 'accent-red' | 'accent-orange' | 'accent-yellow' | 'accent-lime' | 'accent-green' | 'accent-teal' | 'accent-blue' | 'accent-purple' | 'accent-magenta' | 'accent-gray';
16
17
  /**
17
- * A `testId` prop is provided for specified elements, which is a unique
18
- * string that appears as a data attribute `data-testid` in the rendered code,
19
- * serving as a hook for automated tests
18
+ * Elements to be rendered inside the lozenge. This should ideally be just a word or two.
20
19
  */
21
- testId?: string;
20
+ children?: React.ReactNode;
22
21
  /**
23
22
  * Determines whether to apply the bold style or not.
23
+ * @deprecated This prop is deprecated and will be removed in an upcoming major release. Use Tag component for non-bold styles.
24
24
  */
25
25
  isBold?: boolean;
26
- /**
27
- * The appearance type.
28
- */
29
- appearance?: 'default' | 'inprogress' | 'moved' | 'new' | 'removed' | 'success';
30
26
  /**
31
27
  * max-width of lozenge container. Default to 200px.
32
28
  */
33
29
  maxWidth?: string | number;
30
+ /**
31
+ * A `testId` prop is provided for specified elements, which is a unique
32
+ * string that appears as a data attribute `data-testid` in the rendered code,
33
+ * serving as a hook for automated tests
34
+ */
35
+ testId?: string;
34
36
  };
35
37
  export type LozengeProps = Pick<PlatformLozengeProps, 'appearance' | 'children' | 'isBold' | 'maxWidth' | 'testId'>;
36
38
  /**
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - BadgeProps
5
5
  *
6
- * @codegen <<SignedSource::dded43c94e5bc997c5df041eeb253927>>
6
+ * @codegen <<SignedSource::9d4cb948f5d6ac145a3d3e82ab8cfa92>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
- * @codegenDependency ../../../../forge-ui/src/components/UIKit/badge/__generated__/index.partial.tsx <<SignedSource::002a848f01b18a8dea0ea160d731edbf>>
8
+ * @codegenDependency ../../../../forge-ui/src/components/UIKit/badge/__generated__/index.partial.tsx <<SignedSource::f9bf0bacecb91875eab391c4148409c1>>
9
9
  */
10
10
  import type React from 'react';
11
11
  export type PlatformBadgeProps = Omit<_PlatformBadgeProps, 'children'> & {
@@ -20,7 +20,7 @@ type _PlatformBadgeProps = {
20
20
  /**
21
21
  * Affects the visual style of the badge.
22
22
  */
23
- appearance?: 'added' | 'default' | 'important' | 'primary' | 'primaryInverted' | 'removed';
23
+ appearance?: 'added' | 'default' | 'important' | 'primary' | 'primaryInverted' | 'removed' | 'warning' | 'discovery' | 'danger' | 'neutral' | 'success' | 'information' | 'inverse';
24
24
  children?: React.ReactNode;
25
25
  /**
26
26
  * The maximum value to display. Defaults to `99`. If the value is 100, and max is 50, "50+" will be displayed.
@@ -3,34 +3,36 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - LozengeProps
5
5
  *
6
- * @codegen <<SignedSource::2c6d1eb88477563937e65c98996d0b92>>
6
+ * @codegen <<SignedSource::abe727d97158c4d16d13504ebd7f60d6>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
- * @codegenDependency ../../../../forge-ui/src/components/UIKit/lozenge/__generated__/index.partial.tsx <<SignedSource::5e9e88bd5dd513ba567d815ada9e7eae>>
8
+ * @codegenDependency ../../../../forge-ui/src/components/UIKit/lozenge/__generated__/index.partial.tsx <<SignedSource::9799ca9fa788b29c08dfbdb778da62b4>>
9
9
  */
10
10
  import type React from 'react';
11
11
  type PlatformLozengeProps = {
12
12
  /**
13
- * Elements to be rendered inside the lozenge. This should ideally be just a word or two.
13
+ * The appearance of the lozenge. Supports both legacy semantic appearances and new accent/semantic colors.
14
+ * Legacy appearances (default, success, removed, inprogress, new, moved) are automatically mapped to the new semantic colors.
14
15
  */
15
- children?: React.ReactNode;
16
+ appearance?: 'default' | 'inprogress' | 'moved' | 'new' | 'removed' | 'success' | 'warning' | 'danger' | 'information' | 'neutral' | 'discovery' | 'accent-red' | 'accent-orange' | 'accent-yellow' | 'accent-lime' | 'accent-green' | 'accent-teal' | 'accent-blue' | 'accent-purple' | 'accent-magenta' | 'accent-gray';
16
17
  /**
17
- * A `testId` prop is provided for specified elements, which is a unique
18
- * string that appears as a data attribute `data-testid` in the rendered code,
19
- * serving as a hook for automated tests
18
+ * Elements to be rendered inside the lozenge. This should ideally be just a word or two.
20
19
  */
21
- testId?: string;
20
+ children?: React.ReactNode;
22
21
  /**
23
22
  * Determines whether to apply the bold style or not.
23
+ * @deprecated This prop is deprecated and will be removed in an upcoming major release. Use Tag component for non-bold styles.
24
24
  */
25
25
  isBold?: boolean;
26
- /**
27
- * The appearance type.
28
- */
29
- appearance?: 'default' | 'inprogress' | 'moved' | 'new' | 'removed' | 'success';
30
26
  /**
31
27
  * max-width of lozenge container. Default to 200px.
32
28
  */
33
29
  maxWidth?: string | number;
30
+ /**
31
+ * A `testId` prop is provided for specified elements, which is a unique
32
+ * string that appears as a data attribute `data-testid` in the rendered code,
33
+ * serving as a hook for automated tests
34
+ */
35
+ testId?: string;
34
36
  };
35
37
  export type LozengeProps = Pick<PlatformLozengeProps, 'appearance' | 'children' | 'isBold' | 'maxWidth' | 'testId'>;
36
38
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/forge-react-types",
3
- "version": "0.52.1",
3
+ "version": "0.52.2",
4
4
  "description": "Component types for Forge UI Kit React components",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,11 +25,11 @@
25
25
  "@atlaskit/comment": "^13.2.0",
26
26
  "@atlaskit/datetime-picker": "^17.2.0",
27
27
  "@atlaskit/dynamic-table": "^18.3.0",
28
- "@atlaskit/form": "^15.1.0",
28
+ "@atlaskit/form": "^15.2.0",
29
29
  "@atlaskit/inline-edit": "^15.4.0",
30
30
  "@atlaskit/modal-dialog": "^14.9.0",
31
- "@atlaskit/navigation-system": "^5.13.0",
32
- "@atlaskit/popup": "^4.8.0",
31
+ "@atlaskit/navigation-system": "^5.15.0",
32
+ "@atlaskit/popup": "^4.9.0",
33
33
  "@atlaskit/primitives": "^17.0.0",
34
34
  "@atlaskit/progress-bar": "^4.1.0",
35
35
  "@atlaskit/progress-tracker": "^10.4.0",
@@ -4,6 +4,7 @@ import {
4
4
  type Type as TSType,
5
5
  type UnionTypeNode,
6
6
  type TypeReferenceNode,
7
+ type Symbol as TSSymbol,
7
8
  SyntaxKind,
8
9
  } from 'ts-morph';
9
10
 
@@ -139,10 +140,17 @@ const flattenPickType = (
139
140
 
140
141
  const serializedProperties = properties
141
142
  .map((prop) => {
142
- const propertySignature = prop.getDeclarations()[0] as PropertySignature | undefined;
143
- if (!propertySignature) {
144
- return null; // Skip if no declaration
143
+ const propertySignatures = extractPropertySignatures(prop);
144
+ if (propertySignatures.length === 0) {
145
+ return null;
146
+ } else if (propertySignatures.length > 1) {
147
+ // Currently we only support union type with same property signatures or a superset signature
148
+ // as we assume this setup is to support gradual type changes behind feature flags.
149
+ // other use cases are not supported currently.
150
+ throw new Error(`Unsupported union prop type with multiple different property signatures, ${prop.getName()}`);
145
151
  }
152
+
153
+ const propertySignature = propertySignatures[0];
146
154
  const { jsDoc, typeCode } =
147
155
  propertyCallback({
148
156
  propertySignature,
@@ -162,6 +170,70 @@ const flattenPickType = (
162
170
  return `{\n${serializedProperties.map((prop) => (!!prop?.trim() ? ` ${prop}` : '')).join('\n')}\n}`;
163
171
  };
164
172
 
173
+ // Note: ADS components uses union types to rollout new component type changes gradually (behind feature flags).
174
+ // e.g. LozengeProps = LegacyLozengeProps | NewLozengeProps
175
+ // In such cases, we need to consolidate property signatures from all union members.
176
+ const extractPropertySignatures = (prop: TSSymbol): PropertySignature[] => {
177
+ const declarations = prop.getDeclarations();
178
+ if (!declarations) {
179
+ return [];
180
+ }
181
+ const signatures = declarations.filter((decl) => decl.getKind() === SyntaxKind.PropertySignature) as PropertySignature[];
182
+ if (signatures.length <= 1) {
183
+ return signatures;
184
+ }
185
+
186
+ // consolidate signatures if they are exactly the same
187
+ const uniqSignatures: PropertySignature[] = [];
188
+ const signatureTexts = new Set<string>();
189
+ for (const sig of signatures) {
190
+ const sigText = sig.getText();
191
+ if (!signatureTexts.has(sigText)) {
192
+ signatureTexts.add(sigText);
193
+ uniqSignatures.push(sig);
194
+ }
195
+ }
196
+
197
+ // next we should find one that's the supperset of others
198
+ if (uniqSignatures.length <= 1) {
199
+ return uniqSignatures;
200
+ }
201
+
202
+ const supersetSignatures: PropertySignature[] = [];
203
+ for (const sig of uniqSignatures) {
204
+ const sigType = sig.getType();
205
+ let isSuperset = true;
206
+ for (const otherSig of uniqSignatures) {
207
+ if (sig === otherSig) {
208
+ continue;
209
+ }
210
+ const otherSigType = otherSig.getType();
211
+ if (!isTypeAssignableTo(prop, otherSigType, sigType)) {
212
+ isSuperset = false;
213
+ break;
214
+ }
215
+ }
216
+ if (isSuperset) {
217
+ supersetSignatures.push(sig);
218
+ }
219
+ }
220
+
221
+ if (supersetSignatures.length > 0) {
222
+ return supersetSignatures;
223
+ }
224
+ return uniqSignatures;
225
+ };
226
+
227
+ const isTypeAssignableTo = (prop: TSSymbol, sourceType: TSType, targetType: TSType): boolean => {
228
+ const typeChecker = prop.getDeclarations()[0].getProject().getTypeChecker().compilerObject;
229
+
230
+ // ts typecker has an intneral method `isTypeAssignableTo` we can leverage here:
231
+ // https://github.com/microsoft/TypeScript/pull/56448
232
+ return (typeChecker as unknown as {
233
+ isTypeAssignableTo: (source: unknown, target: unknown) => boolean;
234
+ }).isTypeAssignableTo(sourceType.compilerType, targetType.compilerType);
235
+ };
236
+
165
237
  const getUnresolvableTypes = (tsType: TSType) => {
166
238
  const unresolvableTypes = new Set<string>();
167
239
  getUnresolvableTypesBase(tsType, unresolvableTypes);
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - BadgeProps
5
5
  *
6
- * @codegen <<SignedSource::dded43c94e5bc997c5df041eeb253927>>
6
+ * @codegen <<SignedSource::9d4cb948f5d6ac145a3d3e82ab8cfa92>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
- * @codegenDependency ../../../../forge-ui/src/components/UIKit/badge/__generated__/index.partial.tsx <<SignedSource::002a848f01b18a8dea0ea160d731edbf>>
8
+ * @codegenDependency ../../../../forge-ui/src/components/UIKit/badge/__generated__/index.partial.tsx <<SignedSource::f9bf0bacecb91875eab391c4148409c1>>
9
9
  */
10
10
  /* eslint @repo/internal/codegen/signed-source-integrity: "warn" */
11
11
 
@@ -25,7 +25,7 @@ type _PlatformBadgeProps = {
25
25
  /**
26
26
  * Affects the visual style of the badge.
27
27
  */
28
- appearance?: 'added' | 'default' | 'important' | 'primary' | 'primaryInverted' | 'removed';
28
+ appearance?: 'added' | 'default' | 'important' | 'primary' | 'primaryInverted' | 'removed' | 'warning' | 'discovery' | 'danger' | 'neutral' | 'success' | 'information' | 'inverse';
29
29
 
30
30
  children?: React.ReactNode;
31
31
  /**
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * Extract component prop types from UIKit 2 components - LozengeProps
5
5
  *
6
- * @codegen <<SignedSource::2c6d1eb88477563937e65c98996d0b92>>
6
+ * @codegen <<SignedSource::abe727d97158c4d16d13504ebd7f60d6>>
7
7
  * @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
8
- * @codegenDependency ../../../../forge-ui/src/components/UIKit/lozenge/__generated__/index.partial.tsx <<SignedSource::5e9e88bd5dd513ba567d815ada9e7eae>>
8
+ * @codegenDependency ../../../../forge-ui/src/components/UIKit/lozenge/__generated__/index.partial.tsx <<SignedSource::9799ca9fa788b29c08dfbdb778da62b4>>
9
9
  */
10
10
  /* eslint @repo/internal/codegen/signed-source-integrity: "warn" */
11
11
 
@@ -15,27 +15,29 @@ import type React from 'react';
15
15
  // Serialized type
16
16
  type PlatformLozengeProps = {
17
17
  /**
18
- * Elements to be rendered inside the lozenge. This should ideally be just a word or two.
18
+ * The appearance of the lozenge. Supports both legacy semantic appearances and new accent/semantic colors.
19
+ * Legacy appearances (default, success, removed, inprogress, new, moved) are automatically mapped to the new semantic colors.
19
20
  */
20
- children?: React.ReactNode;
21
+ appearance?: 'default' | 'inprogress' | 'moved' | 'new' | 'removed' | 'success' | 'warning' | 'danger' | 'information' | 'neutral' | 'discovery' | 'accent-red' | 'accent-orange' | 'accent-yellow' | 'accent-lime' | 'accent-green' | 'accent-teal' | 'accent-blue' | 'accent-purple' | 'accent-magenta' | 'accent-gray';
21
22
  /**
22
- * A `testId` prop is provided for specified elements, which is a unique
23
- * string that appears as a data attribute `data-testid` in the rendered code,
24
- * serving as a hook for automated tests
23
+ * Elements to be rendered inside the lozenge. This should ideally be just a word or two.
25
24
  */
26
- testId?: string;
25
+ children?: React.ReactNode;
27
26
  /**
28
27
  * Determines whether to apply the bold style or not.
28
+ * @deprecated This prop is deprecated and will be removed in an upcoming major release. Use Tag component for non-bold styles.
29
29
  */
30
30
  isBold?: boolean;
31
- /**
32
- * The appearance type.
33
- */
34
- appearance?: 'default' | 'inprogress' | 'moved' | 'new' | 'removed' | 'success';
35
31
  /**
36
32
  * max-width of lozenge container. Default to 200px.
37
33
  */
38
34
  maxWidth?: string | number;
35
+ /**
36
+ * A `testId` prop is provided for specified elements, which is a unique
37
+ * string that appears as a data attribute `data-testid` in the rendered code,
38
+ * serving as a hook for automated tests
39
+ */
40
+ testId?: string;
39
41
  };
40
42
 
41
43
  export type LozengeProps = Pick<