Skip to content

Commit

Permalink
feat: add Expander primitive (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeung-wah authored and dpilch committed Nov 24, 2021
1 parent c458888 commit 1c234ac
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,87 @@ export default function CheckBoxFieldPrimitive(
"
`;
exports[`amplify render tests primitives Expander 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import {
EscapeHatchProps,
Expander,
ExpanderItem,
ExpanderProps,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
export type ExpanderPrimitiveProps = React.PropsWithChildren<
Partial<ExpanderProps> & {
overrides?: EscapeHatchProps | undefined | null;
}
>;
export default function ExpanderPrimitive(
props: ExpanderPrimitiveProps
): React.ReactElement {
const { overrides: overridesProp, ...rest } = props;
const overrides = { ...overridesProp };
return (
/* @ts-ignore: TS2322 */
<Expander
type=\\"single\\"
isCollapsible={true}
{...rest}
{...getOverrideProps(overrides, \\"Expander\\")}
>
<ExpanderItem
title=\\"title1\\"
value=\\"ExpanderItem1\\"
children=\\"ExpanderItem1Content\\"
{...getOverrideProps(overrides, \\"Expander.ExpanderItem[0]\\")}
></ExpanderItem>
<ExpanderItem
title=\\"title2\\"
value=\\"ExpanderItem2\\"
children=\\"ExpanderItem2Content\\"
{...getOverrideProps(overrides, \\"Expander.ExpanderItem[1]\\")}
></ExpanderItem>
</Expander>
);
}
"
`;
exports[`amplify render tests primitives ExpanderItem 1`] = `
"/* eslint-disable */
import React from \\"react\\";
import {
EscapeHatchProps,
ExpanderItem,
ExpanderItemProps,
getOverrideProps,
} from \\"@aws-amplify/ui-react\\";
export type ComponentWithoutNameProps = React.PropsWithChildren<
Partial<ExpanderItemProps> & {
overrides?: EscapeHatchProps | undefined | null;
}
>;
export default function unknown_component_name(
props: unknown_component_nameProps
): React.ReactElement {
const { overrides: overridesProp, ...rest } = props;
const overrides = { ...overridesProp };
return (
/* @ts-ignore: TS2322 */
<ExpanderItem
title=\\"title1\\"
value=\\"ExpanderItem1\\"
children=\\"ExpanderItem1Content\\"
{...rest}
{...getOverrideProps(overrides, \\"ExpanderItem\\")}
></ExpanderItem>
);
}
"
`;
exports[`amplify render tests primitives SliderField 1`] = `
"/* eslint-disable */
import React from \\"react\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ exports[`Primitives Collection 1`] = `"<Collection items={items || []} {...rest}

exports[`Primitives Divider 1`] = `"<Divider {...rest} {...getOverrideProps(overrides, \\"Divider\\")}></Divider>"`;

exports[`Primitives Expander 1`] = `"<Expander {...rest} {...getOverrideProps(overrides, \\"Expander\\")}></Expander>"`;

exports[`Primitives ExpanderItem 1`] = `"<ExpanderItem {...rest} {...getOverrideProps(overrides, \\"ExpanderItem\\")}></ExpanderItem>"`;

exports[`Primitives Flex 1`] = `"<Flex {...rest} {...getOverrideProps(overrides, \\"Flex\\")}></Flex>"`;

exports[`Primitives Grid 1`] = `"<Grid {...rest} {...getOverrideProps(overrides, \\"Grid\\")}></Grid>"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,14 @@ describe('amplify render tests', () => {
});

describe('primitives', () => {
test('Expander', () => {
expect(generateWithAmplifyRenderer('primitives/ExpanderPrimitive').componentText).toMatchSnapshot();
});

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

test('TextField', () => {
expect(generateWithAmplifyRenderer('primitives/TextFieldPrimitive').componentText).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"componentType": "ExpanderItem",
"properties": {
"title": {
"value": "title1"
},
"value": {
"value": "ExpanderItem1"
},
"children": {
"value": "ExpanderItem1Content"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "1234-5678-9010",
"componentType": "Expander",
"name": "ExpanderPrimitive",
"properties": {
"type": {
"value": "single",
"type": "String"
},
"isCollapsible": {
"value": true,
"type": "Boolean"
}
},
"children": [
{
"componentType": "ExpanderItem",
"properties": {
"title": {
"value": "title1"
},
"value": {
"value": "ExpanderItem1"
},
"children": {
"value": "ExpanderItem1Content"
}
}
},
{
"componentType": "ExpanderItem",
"properties": {
"title": {
"value": "title2"
},
"value": {
"value": "ExpanderItem2"
},
"children": {
"value": "ExpanderItem2Content"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
CardProps,
CheckboxFieldProps,
DividerProps,
ExpanderProps,
ExpanderItemProps,
FlexProps,
GridProps,
HeadingProps,
Expand Down Expand Up @@ -130,6 +132,20 @@ export class AmplifyRenderer extends ReactStudioTemplateRenderer {
case Primitive.Divider:
return new ReactComponentRenderer<DividerProps>(component, this.importCollection, parent).renderElement();

case Primitive.Expander:
return new ReactComponentWithChildrenRenderer<ExpanderProps>(
component,
this.importCollection,
parent,
).renderElement(renderChildren);

case Primitive.ExpanderItem:
return new ReactComponentWithChildrenRenderer<ExpanderItemProps>(
component,
this.importCollection,
parent,
).renderElement(renderChildren);

case Primitive.Flex:
return new ReactComponentWithChildrenRenderer<FlexProps>(
component,
Expand Down
2 changes: 2 additions & 0 deletions packages/codegen-ui-react/lib/primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ enum Primitive {
CheckboxField = 'CheckboxField',
Collection = 'Collection',
Divider = 'Divider',
Expander = 'Expander',
ExpanderItem = 'ExpanderItem',
Flex = 'Flex',
Grid = 'Grid',
Heading = 'Heading',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ describe('Primitives', () => {
});
});

describe('Expander', () => {
it('Basic', () => {
cy.visit('http://localhost:3000/primitives-tests');
cy.get('#expander')
.find('.amplify-expander')
.within(() => {
cy.get('.amplify-expander__item')
.eq(0)
.within(() => {
cy.get('.amplify-expander__trigger').should('have.text', 'title1');
cy.get('.amplify-expander__trigger').click();
cy.get('.amplify-expander__content__text').should('have.text', 'ExpanderItem1Content');
});
cy.get('.amplify-expander__item')
.eq(1)
.within(() => {
cy.get('.amplify-expander__trigger').should('have.text', 'title2');
cy.get('.amplify-expander__trigger').click();
cy.get('.amplify-expander__content__text').should('have.text', 'ExpanderItem2Content');
});
});
});
});

describe('Flex', () => {
it('Basic', () => {
cy.visit('http://localhost:3000/primitives-tests');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
CheckboxFieldPrimitive,
CollectionPrimitive,
DividerPrimitive,
ExpanderPrimitive,
FlexPrimitive,
GridPrimitive,
HeadingPrimitive,
Expand Down Expand Up @@ -89,6 +90,10 @@ export default function PrimitivesTests() {
<Heading>Divider</Heading>
<DividerPrimitive />
</View>
<View id="expander">
<Heading>Expander</Heading>
<ExpanderPrimitive />
</View>
<View id="flex">
<Heading>Flex</Heading>
<FlexPrimitive />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "1234-5678-9010",
"componentType": "Expander",
"name": "ExpanderPrimitive",
"properties": {
"type": {
"value": "single",
"type": "String"
},
"isCollapsible": {
"value": true,
"type": "Boolean"
}
},
"children": [
{
"componentType": "ExpanderItem",
"properties": {
"title": {
"value": "title1"
},
"value": {
"value": "ExpanderItem1"
},
"children": {
"value": "ExpanderItem1Content"
}
}
},
{
"componentType": "ExpanderItem",
"properties": {
"title": {
"value": "title2"
},
"value": {
"value": "ExpanderItem2"
},
"children": {
"value": "ExpanderItem2Content"
}
}
}
]
}
1 change: 1 addition & 0 deletions packages/test-generator/lib/components/primitives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { default as CardPrimitive } from './CardPrimitive.json';
export { default as CheckboxFieldPrimitive } from './CheckboxFieldPrimitive.json';
export { default as CollectionPrimitive } from './CollectionPrimitive.json';
export { default as DividerPrimitive } from './DividerPrimitive.json';
export { default as ExpanderPrimitive } from './ExpanderPrimitive.json';
export { default as FlexPrimitive } from './FlexPrimitive.json';
export { default as GridPrimitive } from './GridPrimitive.json';
export { default as HeadingPrimitive } from './HeadingPrimitive.json';
Expand Down

0 comments on commit 1c234ac

Please sign in to comment.