Skip to content
Closed
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
50 changes: 50 additions & 0 deletions fixtures/components/system-tag/example/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';

export namespace ExampleProps {
export type Variant =
/** primary use-case */
| 'primary'
/**
* secondary use-case
* @awsuiSystem core
* */
| 'secondary';
}

export interface ExampleProps {
/**
* Color
*
* @awsuiSystem core
*/
color?: string;

/**
* Font family
*
* More text
* @awsuiSystem core
* @awsuiSystem something
*/
fontFamily?: string;

/**
* Variant
*/
variant?: ExampleProps.Variant;

/**
* Main content
*/
children?: React.ReactNode;
}

export default function Example({ color, fontFamily, children }: ExampleProps) {
return (
<button color={color} style={{ fontFamily }}>
{children}
</button>
);
}
7 changes: 7 additions & 0 deletions fixtures/components/system-tag/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["./**/*.tsx"]
}
4 changes: 4 additions & 0 deletions src/components/build-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,17 @@ export default function buildDefinition(
functions: buildMethodsDefinition(objects.find(def => def.name === 'Ref')),
properties: onlyProps.map(prop => {
const { typeName, typeDefinition } = getPropertyType(prop.type);
const systemTags = prop.comment?.tags
?.filter(tag => tag.tagName.toLowerCase() === 'awsuisystem')
.map(tag => tag?.text.trim());
return {
name: prop.name,
type: typeName,
inlineType: typeDefinition,
optional: schema.utils.isOptionalDeclaration(prop),
description: schema.code.buildNodeDescription(prop),
defaultValue: defaultValues[prop.name],
systemTags: systemTags?.length ? systemTags : undefined,
visualRefreshTag: prop.comment?.tags?.find(tag => tag.tagName === 'visualrefresh')?.text.trim(),
deprecatedTag: prop.comment?.tags?.find(tag => tag.tagName === 'deprecated')?.text.trim(),
i18nTag: prop.comment?.tags?.some(tag => tag.tagName === 'i18n') || undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/components/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ComponentProperty {
inlineType?: TypeDefinition;
defaultValue?: string;
analyticsTag?: string;
visualRefreshTag?: string;
systemTags?: Array<string>;
}

export interface ComponentRegion {
Expand Down
49 changes: 49 additions & 0 deletions test/components/system-tag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { ComponentDefinition } from '../../src/components/interfaces';
import { buildProject } from './test-helpers';

let component: ComponentDefinition;
beforeAll(() => {
const result = buildProject('system-tag');
expect(result).toHaveLength(1);

component = result[0];
});

test('should have correct region definitions', () => {
expect(component.properties).toEqual([
{
name: 'color',
description: 'Color',
type: 'string',
optional: true,
systemTags: ['core'],
},
{
name: 'fontFamily',
description: 'Font family\nMore text',
type: 'string',
optional: true,
systemTags: ['core', 'something'],
},
{
name: 'variant',
description: 'Variant',
type: 'string',
optional: true,
inlineType: {
name: 'ExampleProps.Variant',
type: 'union',
values: ['primary', 'secondary'],
},
},
]);
expect(component.regions).toEqual([
{
name: 'children',
description: 'Main content',
isDefault: true,
},
]);
});
Loading