Skip to content

Commit

Permalink
fix: updating generated theme to work in test app
Browse files Browse the repository at this point in the history
  • Loading branch information
alharris-at committed Oct 19, 2021
1 parent 8cbf8cc commit 113a594
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type SiteHeaderProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function SiteHeader(props: SiteHeaderProps): React.ReactElement {
const overrides = { ...props.overrides };
Expand Down Expand Up @@ -61,7 +61,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type TestProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function Test(props: TestProps): React.ReactElement {
const overrides = { ...props.overrides };
Expand All @@ -87,7 +87,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CustomButtonProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomButton(
props: CustomButtonProps
Expand Down Expand Up @@ -115,7 +115,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CustomTextProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomText(props: CustomTextProps): React.ReactElement {
const overrides = { ...props.overrides };
Expand Down Expand Up @@ -146,12 +146,12 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CollectionOfCustomButtonsProps = {
width?: Number,
backgroundColor?: String,
buttonColor?: UserPreferences,
items?: any[],
width?: Number;
backgroundColor?: String;
buttonColor?: UserPreferences;
items?: any[];
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CollectionOfCustomButtons(
props: CollectionOfCustomButtonsProps
Expand Down Expand Up @@ -224,12 +224,12 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CollectionOfCustomButtonsProps = {
width?: Number,
backgroundColor?: String,
buttonColor?: UserPreferences,
items?: any[],
width?: Number;
backgroundColor?: String;
buttonColor?: UserPreferences;
items?: any[];
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CollectionOfCustomButtons(
props: CollectionOfCustomButtonsProps
Expand Down Expand Up @@ -308,9 +308,9 @@ import {
import { UntitledModel } from \\"../models\\";
export type ListingCardCollectionProps = {
items?: any[],
items?: any[];
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function ListingCardCollection(
props: ListingCardCollectionProps
Expand Down Expand Up @@ -362,9 +362,9 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type ListingCardCollectionProps = {
items?: any[],
items?: any[];
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function ListingCardCollection(
props: ListingCardCollectionProps
Expand Down Expand Up @@ -401,7 +401,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type BoxWithButtonProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function BoxWithButton(
props: BoxWithButtonProps
Expand Down Expand Up @@ -432,7 +432,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type BoxWithCustomButtonProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function BoxWithCustomButton(
props: BoxWithCustomButtonProps
Expand Down Expand Up @@ -462,7 +462,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type BoxWithButtonProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function BoxWithButton(
props: BoxWithButtonProps
Expand Down Expand Up @@ -491,9 +491,9 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type TextWithDataBindingProps = {
textValue?: String,
textValue?: String;
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function TextWithDataBinding(
props: TextWithDataBindingProps
Expand Down Expand Up @@ -525,12 +525,12 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type ComponentWithDataBindingProps = {
width?: Number,
isDisabled?: Boolean,
buttonUser?: User,
buttonColor?: String,
width?: Number;
isDisabled?: Boolean;
buttonUser?: User;
buttonColor?: String;
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function ComponentWithDataBinding(
props: ComponentWithDataBindingProps
Expand Down Expand Up @@ -562,9 +562,9 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type SectionHeadingProps = {
newProp6fd1?: UntitledModel,
newProp6fd1?: UntitledModel;
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function SectionHeading(
props: SectionHeadingProps
Expand Down Expand Up @@ -624,10 +624,10 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CustomButtonProps = {
variant: \\"primary\\" | \\"secondary\\",
size?: \\"large\\",
variant: \\"primary\\" | \\"secondary\\";
size?: \\"large\\";
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomButton(
props: CustomButtonProps
Expand Down Expand Up @@ -672,11 +672,11 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CustomButtonProps = {
width?: Number,
buttonUser?: User,
buttonColor?: String,
width?: Number;
buttonUser?: User;
buttonColor?: String;
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomButton(
props: CustomButtonProps
Expand Down Expand Up @@ -708,11 +708,11 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type CustomButtonProps = {
width?: Number,
buttonUser?: User,
buttonColor?: String,
width?: Number;
buttonUser?: User;
buttonColor?: String;
} & {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomButton(
props: CustomButtonProps
Expand Down Expand Up @@ -854,7 +854,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type BoxWithButtonProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function BoxWithButton(
props: BoxWithButtonProps
Expand Down Expand Up @@ -888,7 +888,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type SiteHeaderProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function SiteHeader(props: SiteHeaderProps): React.ReactElement {
const overrides = { ...props.overrides };
Expand Down Expand Up @@ -962,9 +962,7 @@ import {
Theme,
extendTheming,
} from \\"@aws-amplify/ui-react\\";
export default function withTheme<T>(
WrappedComponent: React.ReactComponent<T>
) {
export default function withTheme<T>(WrappedComponent: React.ComponentType<T>) {
const theme = {
components: {
alert: {
Expand Down Expand Up @@ -996,11 +994,11 @@ export default function withTheme<T>(
const theming = extendTheming(theme);
useEffect(() => {
Object.entries(theming.CSSVariables).forEach(([key, value]) => {
document.documentElement.style.setProperty(key, value);
document.documentElement.style.setProperty(key, value as string | null);
});
});
return (
<AmplifyProvider theming={theming}>
<AmplifyProvider theming={theming} components={{}}>
<WrappedComponent {...props} />
</AmplifyProvider>
);
Expand Down Expand Up @@ -1070,7 +1068,7 @@ export default function withTheme(WrappedComponent) {
});
return React.createElement(
AmplifyProvider,
{ theming: theming },
{ theming: theming, components: {} },
React.createElement(WrappedComponent, __assign({}, props))
);
};
Expand All @@ -1090,9 +1088,7 @@ import {
Theme,
extendTheming,
} from \\"@aws-amplify/ui-react\\";
export default function withTheme<T>(
WrappedComponent: React.ReactComponent<T>
) {
export default function withTheme<T>(WrappedComponent: React.ComponentType<T>) {
const theme = {
components: {
alert: {
Expand Down Expand Up @@ -1124,11 +1120,11 @@ export default function withTheme<T>(
const theming = extendTheming(theme);
useEffect(() => {
Object.entries(theming.CSSVariables).forEach(([key, value]) => {
document.documentElement.style.setProperty(key, value);
document.documentElement.style.setProperty(key, value as string | null);
});
});
return (
<AmplifyProvider theming={theming}>
<AmplifyProvider theming={theming} components={{}}>
<WrappedComponent {...props} />
</AmplifyProvider>
);
Expand All @@ -1151,7 +1147,7 @@ import {
} from \\"@aws-amplify/ui-react\\";
export type ProfileProps = {
overrides?: EscapeHatchProps | undefined | null,
overrides?: EscapeHatchProps | undefined | null;
};
export default function Profile(props: ProfileProps): React.ReactElement {
const {} = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function transpile(
},
}).outputText;

const componentText = prettier.format(transpiledCode, { parser: 'babel', plugins: [parserBabel] });
const componentText = prettier.format(transpiledCode, { parser: 'typescript', plugins: [parserBabel] });

/* createProgram is less performant than traspileModule and should only be used when necessary.
* createProgram is used here becuase transpileModule cannot produce type declarations.
Expand Down Expand Up @@ -91,7 +91,7 @@ export function transpile(
};
}

return { componentText: prettier.format(code, { parser: 'babel', plugins: [parserBabel] }) };
return { componentText: prettier.format(code, { parser: 'typescript', plugins: [parserBabel] }) };
}

export function buildPrinter(fileName: string, renderConfig: ReactRenderConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
factory.createIdentifier('WrappedComponent'),
undefined,
factory.createTypeReferenceNode(
factory.createQualifiedName(factory.createIdentifier('React'), factory.createIdentifier('ReactComponent')),
factory.createQualifiedName(factory.createIdentifier('React'), factory.createIdentifier('ComponentType')),
[factory.createTypeReferenceNode(factory.createIdentifier('T'), undefined)],
),
undefined,
Expand Down Expand Up @@ -200,11 +200,11 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
* const theming = extendTheming(theme);
* useEffect(() => {
* Object.entries(theming.CSSVariables).forEach(([key, value]) => {
* document.documentElement.style.setProperty(key, value);
* document.documentElement.style.setProperty(key, value as string | null);
* });
* });
* return (
* <AmplifyProvider theming={theming}>
* <AmplifyProvider theming={theming} components={{}}>
* <WrappedComponent {...props} />
* </AmplifyProvider>
* );
Expand Down Expand Up @@ -250,6 +250,10 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
factory.createIdentifier('theming'),
factory.createJsxExpression(undefined, factory.createIdentifier('theming')),
),
factory.createJsxAttribute(
factory.createIdentifier('components'),
factory.createJsxExpression(undefined, factory.createObjectLiteralExpression([], false)),
),
]),
),
[
Expand Down Expand Up @@ -301,7 +305,7 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
/*
* useEffect(() => {
* Object.entries(theming.CSSVariables).forEach(([key, value]) => {
* document.documentElement.style.setProperty(key, value);
* document.documentElement.style.setProperty(key, (value as string | null));
* });
* });
*/
Expand Down Expand Up @@ -380,7 +384,18 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
factory.createIdentifier('setProperty'),
),
undefined,
[factory.createIdentifier('key'), factory.createIdentifier('value')],
[
factory.createIdentifier('key'),
factory.createParenthesizedExpression(
factory.createAsExpression(
factory.createIdentifier('value'),
factory.createUnionTypeNode([
factory.createKeywordTypeNode(SyntaxKind.StringKeyword),
factory.createLiteralTypeNode(factory.createNull()),
]),
),
),
],
),
),
],
Expand Down
1 change: 0 additions & 1 deletion packages/test-generator/lib/generators/GenerateTestApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ new TestGenerator({
'ComponentWithVariant', // TODO: Support Variant E2E Tests
'ComponentWithActionSignOut', // TODO: Support Auth Action E2E Tests
'ComponentWithActionNavigation', // TODO: Support Navigation Action E2E Tests
'ExampleTheme', // TODO: Support Theme E2E Tests
],
}).generate();
3 changes: 2 additions & 1 deletion packages/test-generator/test-app-templates/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import BoxTest from './ui-components/BoxTest';
import BoxWithButton from './ui-components/BoxWithButton';
import CustomButton from './ui-components/CustomButton';
import CustomText from './ui-components/CustomText';
import withTheme from './ui-components/theme';
/* eslint-enable import/extensions */

function App() {
Expand Down Expand Up @@ -76,4 +77,4 @@ function App() {
);
}

export default App;
export default withTheme(App);

0 comments on commit 113a594

Please sign in to comment.