Skip to content

Commit

Permalink
fix: import custom component from local directory
Browse files Browse the repository at this point in the history
Retain unofficial support of all primitives
  • Loading branch information
dpilch committed Nov 1, 2021
1 parent 5a0fc0f commit 8859b39
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
FlexProps,
Heading,
HeadingProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
Expand All @@ -38,7 +37,7 @@ export default function SiteHeader(props: SiteHeaderProps): React.ReactElement {
<Heading
level={1}
children=\\"Title\\"
{...findChildOverrides(props.overrides, \\"Heading\\")}
{...getOverrideProps(overrides, \\"Flex.Heading\\")}
></Heading>
<Button
variation=\\"primary\\"
Expand Down Expand Up @@ -334,12 +333,11 @@ import {
Collection,
CollectionProps,
EscapeHatchProps,
ListingCard,
ListingCardProps,
findChildOverrides,
getOverrideProps,
useDataStoreBinding,
} from \\"@aws-amplify/ui-react\\";
import ListingCard, { ListingCardProps } from \\"./ListingCard\\";
import { UntitledModel } from \\"../models\\";
export type ListingCardCollectionProps = Partial<CollectionProps<any>> & {
Expand Down Expand Up @@ -392,11 +390,10 @@ import {
Collection,
CollectionProps,
EscapeHatchProps,
ListingCard,
ListingCardProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
import ListingCard, { ListingCardProps } from \\"./ListingCard\\";
export type ListingCardCollectionProps = Partial<CollectionProps<any>> & {
items?: any[];
Expand Down Expand Up @@ -464,14 +461,13 @@ exports[`amplify render tests complex component tests should generate a componen
"/* eslint-disable */
import React from \\"react\\";
import {
CustomButton,
CustomButtonProps,
EscapeHatchProps,
View,
ViewProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
import CustomButton, { CustomButtonProps } from \\"./CustomButton\\";
export type ViewWithCustomButtonProps = Partial<ViewProps> & {
overrides?: EscapeHatchProps | undefined | null;
Expand Down Expand Up @@ -917,6 +913,104 @@ export default function CustomButton(
"
`;
exports[`amplify render tests custom component children should render component with custom children 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import {
EscapeHatchProps,
View,
ViewProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
import CustomButton, { CustomButtonProps } from \\"./CustomButton\\";
export type CustomChildrenProps = Partial<ViewProps> & {
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomChildren(
props: CustomChildrenProps
): React.ReactElement {
const { overrides: overridesProp, ...rest } = props;
const overrides = { ...overridesProp };
return (
<View {...rest} {...getOverrideProps(overrides, \\"View\\")}>
<CustomButton
{...findChildOverrides(props.overrides, \\"CustomButton\\")}
></CustomButton>
</View>
);
}
"
`;
exports[`amplify render tests custom component children should render component with custom children with ES5 1`] = `
"var __assign =
(this && this.__assign) ||
function () {
__assign =
Object.assign ||
function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest =
(this && this.__rest) ||
function (s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === \\"function\\")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (
e.indexOf(p[i]) < 0 &&
Object.prototype.propertyIsEnumerable.call(s, p[i])
)
t[p[i]] = s[p[i]];
}
return t;
};
/* eslint-disable */
import React from \\"react\\";
import {
View,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
import CustomButton from \\"./CustomButton\\";
export default function CustomChildren(props) {
var overridesProp = props.overrides,
rest = __rest(props, [\\"overrides\\"]);
var overrides = __assign({}, overridesProp);
return React.createElement(
View,
__assign({}, rest, getOverrideProps(overrides, \\"View\\")),
React.createElement(
CustomButton,
__assign({}, findChildOverrides(props.overrides, \\"CustomButton\\"))
)
);
}
"
`;
exports[`amplify render tests custom component children should render declarations 1`] = `
"import React from \\"react\\";
import { EscapeHatchProps, ViewProps } from \\"@aws-amplify/ui-react\\";
export declare type CustomChildrenProps = Partial<ViewProps> & {
overrides?: EscapeHatchProps | undefined | null;
};
export default function CustomChildren(props: CustomChildrenProps): React.ReactElement;
"
`;
exports[`amplify render tests custom render config should render ES5 1`] = `
"var __assign =
(this && this.__assign) ||
Expand Down Expand Up @@ -1233,14 +1327,13 @@ exports[`amplify render tests sample code snippet tests should generate a sample
"/* eslint-disable */
import React from \\"react\\";
import {
CustomButton,
CustomButtonProps,
EscapeHatchProps,
View,
ViewProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
import CustomButton, { CustomButtonProps } from \\"./CustomButton\\";
export type ViewWithButtonProps = Partial<ViewProps> & {
overrides?: EscapeHatchProps | undefined | null;
Expand Down Expand Up @@ -1276,7 +1369,6 @@ import {
FlexProps,
Heading,
HeadingProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
Expand Down Expand Up @@ -1311,7 +1403,7 @@ export default function SiteHeader(props: SiteHeaderProps): React.ReactElement {
<Heading
level={1}
children=\\"Title\\"
{...findChildOverrides(props.overrides, \\"Heading\\")}
{...getOverrideProps(overrides, \\"Flex.Heading\\")}
></Heading>
<Button
variation=\\"primary\\"
Expand Down Expand Up @@ -1356,7 +1448,6 @@ import {
InputProps,
View,
ViewProps,
findChildOverrides,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
Expand All @@ -1377,57 +1468,57 @@ export default function ParsedFixedValues(
<Input
id=\\"string-value\\"
value=\\"raw string value\\"
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"number-value\\"
value=\\"67548\\"
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"parsed-number-value\\"
value={67548}
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"boolean-value\\"
value=\\"true\\"
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"parsed-boolean-value\\"
value={true}
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"json-value\\"
value='{\\"foo\\": \\"bar\\"}'
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"parsed-json-value\\"
value={{ foo: \\"bar\\" }}
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"array-value\\"
value=\\"[1,2,3]\\"
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"parsed-array-value\\"
value={[1, 2, 3]}
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"null-value\\"
value=\\"null\\"
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
<Input
id=\\"parsed-null-value\\"
value={null}
{...findChildOverrides(props.overrides, \\"Input\\")}
{...getOverrideProps(overrides, \\"View.Input\\")}
></Input>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,28 @@ describe('amplify render tests', () => {
it('should render parsed fixed values', () => {
expect(generateWithAmplifyRenderer('parsedFixedValues')).toMatchSnapshot();
});

describe('custom component children', () => {
it('should render component with custom children', () => {
expect(generateWithAmplifyRenderer('customChildren').componentText).toMatchSnapshot();
});

it('should render component with custom children with ES5', () => {
expect(
generateWithAmplifyRenderer('customChildren', {
target: ScriptTarget.ES5,
script: ScriptKind.JS,
}).componentText,
).toMatchSnapshot();
});

it('should render declarations', () => {
expect(
generateWithAmplifyRenderer('customChildren', {
script: ScriptKind.JS,
renderTypeDeclarations: true,
}).declaration,
).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "1234-5678-9010",
"componentType": "View",
"name": "CustomChildren",
"properties": {},
"children": [{
"componentType": "CustomButton",
"properties": {}
}]
}
Loading

0 comments on commit 8859b39

Please sign in to comment.