Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow objects to be passed into properties to support paths in … #384

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,38 @@ export default function unknown_component_name(
"
`;

exports[`amplify render tests primitives Icon 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import {
EscapeHatchProps,
getOverrideProps,
} from \\"@aws-amplify/ui-react/internal\\";
import { Icon, IconProps } from \\"@aws-amplify/ui-react\\";

export type CustomIconProps = React.PropsWithChildren<
Partial<IconProps> & {
overrides?: EscapeHatchProps | undefined | null;
}
>;
export default function CustomIcon(props: CustomIconProps): React.ReactElement {
const { overrides, ...rest } = props;
return (
/* @ts-ignore: TS2322 */
<Icon
paths={[
{
d: \\"M18 6V4h2V2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14v-2h-4.03c1.23-.91 2.03-2.36 2.03-4v-5H8v5c0 1.64.81 3.09 2.03 4H6V4h2v2c0 .55.45 1 1 1h8c.55 0 1-.45 1-1z\\",
},
]}
{...rest}
{...getOverrideProps(overrides, \\"CustomIcon\\")}
></Icon>
);
}
"
`;

exports[`amplify render tests primitives Menu 1`] = `
"/* eslint-disable */
import React from \\"react\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ describe('amplify render tests', () => {
test('MenuButton', () => {
expect(generateWithAmplifyRenderer('primitives/MenuButtonPrimitive').componentText).toMatchSnapshot();
});

test('Icon', () => {
expect(generateWithAmplifyRenderer('primitives/IconPrimitive').componentText).toMatchSnapshot();
});
});

describe('icon-indices', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
} from 'typescript';

import { ImportCollection, ImportSource } from './imports';
import { jsonToLiteral } from './react-studio-template-renderer-helper';
import { json, jsonToLiteral } from './react-studio-template-renderer-helper';

export function getFixedComponentPropValueExpression(prop: FixedStudioComponentProperty): StringLiteral {
return factory.createStringLiteral(prop.value.toString(), true);
Expand Down Expand Up @@ -181,6 +181,11 @@ export function buildFixedLiteralExpression(
return value ? factory.createTrue() : factory.createFalse();
case 'string':
return fixedPropertyWithTypeToLiteral(value, type);
case 'object':
if (value instanceof Date) {
throw new Error('Date object is not currently supported for fixed literal expression.');
}
return jsonToLiteral(value as json);
default:
throw new Error(`Invalid type ${typeof value} for "${value}"`);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/codegen-ui/example-schemas/primitives/IconPrimitive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "1234-5678-9010",
"componentType": "Icon",
"name": "CustomIcon",
"properties": {
"paths": {
"value": [
{
"d": "M18 6V4h2V2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14v-2h-4.03c1.23-.91 2.03-2.36 2.03-4v-5H8v5c0 1.64.81 3.09 2.03 4H6V4h2v2c0 .55.45 1 1 1h8c.55 0 1-.45 1-1z"
}
]
}
}
}