diff --git a/packages/studio-ui-codegen-react/lib/__tests__/__snapshots__/studio-ui-codegen-react.test.ts.snap b/packages/studio-ui-codegen-react/lib/__tests__/__snapshots__/studio-ui-codegen-react.test.ts.snap
index 43ef91436..d04533c94 100644
--- a/packages/studio-ui-codegen-react/lib/__tests__/__snapshots__/studio-ui-codegen-react.test.ts.snap
+++ b/packages/studio-ui-codegen-react/lib/__tests__/__snapshots__/studio-ui-codegen-react.test.ts.snap
@@ -3,9 +3,11 @@
exports[`amplify render tests basic component tests should generate a simple box component 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { View } from \\"@aws-amplify/ui-react\\";
+import { EscapeHatchProps, View, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type TestProps = {} & CommonProps;
+export type TestProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function Test(props: TestProps): JSX.Element {
return ();
}"
@@ -14,9 +16,11 @@ export default function Test(props: TestProps): JSX.Element {
exports[`amplify render tests basic component tests should generate a simple button component 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { Button } from \\"@aws-amplify/ui-react\\";
+import { Button, EscapeHatchProps, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type CustomButtonProps = {} & CommonProps;
+export type CustomButtonProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function CustomButton(props: CustomButtonProps): JSX.Element {
return ();
}"
@@ -25,9 +29,11 @@ export default function CustomButton(props: CustomButtonProps): JSX.Element {
exports[`amplify render tests basic component tests should generate a simple text component 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { Text } from \\"@aws-amplify/ui-react\\";
+import { EscapeHatchProps, Text, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type CustomTextProps = {} & CommonProps;
+export type CustomTextProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function CustomText(props: CustomTextProps): JSX.Element {
return (Text Value);
}"
@@ -36,9 +42,11 @@ export default function CustomText(props: CustomTextProps): JSX.Element {
exports[`amplify render tests complex component tests should generate a button within a box component 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { Button, View } from \\"@aws-amplify/ui-react\\";
+import { Button, EscapeHatchProps, View, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type BoxWithButtonProps = {} & CommonProps;
+export type BoxWithButtonProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function BoxWithButton(props: BoxWithButtonProps): JSX.Element {
return ();
}"
@@ -47,9 +55,11 @@ export default function BoxWithButton(props: BoxWithButtonProps): JSX.Element {
exports[`amplify render tests complex component tests should generate a component with custom child 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { CustomButton, View } from \\"@aws-amplify/ui-react\\";
+import { CustomButton, EscapeHatchProps, View, findChildOverrides, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type BoxWithCustomButtonProps = {} & CommonProps;
+export type BoxWithCustomButtonProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function BoxWithCustomButton(props: BoxWithCustomButtonProps): JSX.Element {
return ();
}"
@@ -58,9 +68,11 @@ export default function BoxWithCustomButton(props: BoxWithCustomButtonProps): JS
exports[`amplify render tests complex component tests should generate a component with exposeAs prop 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { Button, View } from \\"@aws-amplify/ui-react\\";
+import { Button, EscapeHatchProps, View, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type BoxWithButtonProps = {} & CommonProps;
+export type BoxWithButtonProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function BoxWithButton(props: BoxWithButtonProps): JSX.Element {
return ();
}"
@@ -69,9 +81,11 @@ export default function BoxWithButton(props: BoxWithButtonProps): JSX.Element {
exports[`amplify render tests sample code snippet tests should generate a sample code snippet for components 1`] = `
"/* eslint-disable */
import React from \\"react\\";
-import { CustomButton, View } from \\"@aws-amplify/ui-react\\";
+import { CustomButton, EscapeHatchProps, View, findChildOverrides, getOverrideProps } from \\"@aws-amplify/ui-react\\";
-export type BoxWithButtonProps = {} & CommonProps;
+export type BoxWithButtonProps = {} & {
+ overrides?: EscapeHatchProps | undefined | null;
+};
export default function BoxWithButton(props: BoxWithButtonProps): JSX.Element {
return ();
}"
diff --git a/packages/studio-ui-codegen-react/lib/import-collection.ts b/packages/studio-ui-codegen-react/lib/import-collection.ts
index 503aa1290..3abd8efb5 100644
--- a/packages/studio-ui-codegen-react/lib/import-collection.ts
+++ b/packages/studio-ui-codegen-react/lib/import-collection.ts
@@ -61,7 +61,7 @@ export class ImportCollection {
factory.createImportClause(
undefined,
factory.createNamedImports(
- [...value].map((item) => {
+ [...value].sort().map((item) => {
return factory.createImportSpecifier(undefined, factory.createIdentifier(item));
}),
),
diff --git a/packages/studio-ui-codegen-react/lib/react-component-renderer.ts b/packages/studio-ui-codegen-react/lib/react-component-renderer.ts
index 429acfb46..b93dfb771 100644
--- a/packages/studio-ui-codegen-react/lib/react-component-renderer.ts
+++ b/packages/studio-ui-codegen-react/lib/react-component-renderer.ts
@@ -43,6 +43,7 @@ export abstract class ReactComponentRenderer extends ComponentRendererB
factory.createStringLiteral(tagName),
]),
);
+ this.importCollection.addImport('@aws-amplify/ui-react', 'getOverrideProps');
attributes.push(overrideAttr);
}
}
diff --git a/packages/studio-ui-codegen-react/lib/react-component-with-children-renderer.ts b/packages/studio-ui-codegen-react/lib/react-component-with-children-renderer.ts
index e7eaf2503..c9e0cca34 100644
--- a/packages/studio-ui-codegen-react/lib/react-component-with-children-renderer.ts
+++ b/packages/studio-ui-codegen-react/lib/react-component-with-children-renderer.ts
@@ -76,6 +76,7 @@ export abstract class ReactComponentWithChildrenRenderer extends Compon
factory.createStringLiteral(tagName),
]),
);
+ this.importCollection.addImport('@aws-amplify/ui-react', 'getOverrideProps');
attributes.push(overrideAttr);
}
@@ -89,6 +90,7 @@ export abstract class ReactComponentWithChildrenRenderer extends Compon
factory.createStringLiteral(tagName),
]),
);
+ this.importCollection.addImport('@aws-amplify/ui-react', 'findChildOverrides');
attributes.push(findChildOverrideAttr);
}
diff --git a/packages/studio-ui-codegen-react/lib/react-studio-template-renderer.ts b/packages/studio-ui-codegen-react/lib/react-studio-template-renderer.ts
index 4b2100cb4..2f2340586 100644
--- a/packages/studio-ui-codegen-react/lib/react-studio-template-renderer.ts
+++ b/packages/studio-ui-codegen-react/lib/react-studio-template-renderer.ts
@@ -111,6 +111,7 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
console.log('JSX rendered');
const wrappedFunction = this.renderFunctionWrapper(this.component.name ?? StudioRendererConstants.unknownName, jsx);
+ const propsDeclaration = this.renderBindingPropsType(this.component);
const imports = this.importCollection.buildImportStatements();
@@ -123,7 +124,6 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
componentText += EOL;
- const propsDeclaration = this.renderBindingPropsType(this.component);
const propsPrinted = printer.printNode(EmitHint.Unspecified, propsDeclaration, file);
componentText += propsPrinted;
@@ -210,14 +210,26 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
renderBindingPropsType(component: StudioComponent): TypeAliasDeclaration {
const componentPropType = getComponentPropName(component.name);
+ this.importCollection.addImport('@aws-amplify/ui-react', 'EscapeHatchProps');
return factory.createTypeAliasDeclaration(
undefined,
- factory.createModifiersFromModifierFlags(ModifierFlags.Export),
- componentPropType,
+ [factory.createModifier(ts.SyntaxKind.ExportKeyword)],
+ factory.createIdentifier(componentPropType),
undefined,
factory.createIntersectionTypeNode([
this.buildBindingPropNodes(component),
- factory.createTypeReferenceNode('CommonProps', undefined),
+ factory.createTypeLiteralNode([
+ factory.createPropertySignature(
+ undefined,
+ factory.createIdentifier('overrides'),
+ factory.createToken(ts.SyntaxKind.QuestionToken),
+ factory.createUnionTypeNode([
+ factory.createTypeReferenceNode(factory.createIdentifier('EscapeHatchProps'), undefined),
+ factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),
+ factory.createLiteralTypeNode(factory.createNull()),
+ ]),
+ ),
+ ]),
]),
);
}