diff --git a/fixtures/components/system-tag/example/index.tsx b/fixtures/components/system-tag/example/index.tsx new file mode 100644 index 0000000..49f0f5b --- /dev/null +++ b/fixtures/components/system-tag/example/index.tsx @@ -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 ( + + ); +} diff --git a/fixtures/components/system-tag/tsconfig.json b/fixtures/components/system-tag/tsconfig.json new file mode 100644 index 0000000..82c6d86 --- /dev/null +++ b/fixtures/components/system-tag/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "." + }, + "include": ["./**/*.tsx"] +} diff --git a/src/components/build-definition.ts b/src/components/build-definition.ts index 33bcfbd..286f405 100644 --- a/src/components/build-definition.ts +++ b/src/components/build-definition.ts @@ -135,6 +135,9 @@ 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, @@ -142,6 +145,7 @@ export default function buildDefinition( 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, diff --git a/src/components/interfaces.ts b/src/components/interfaces.ts index bf02fb7..e700c35 100644 --- a/src/components/interfaces.ts +++ b/src/components/interfaces.ts @@ -19,6 +19,8 @@ export interface ComponentProperty { inlineType?: TypeDefinition; defaultValue?: string; analyticsTag?: string; + visualRefreshTag?: string; + systemTags?: Array; } export interface ComponentRegion { diff --git a/test/components/system-tag.test.ts b/test/components/system-tag.test.ts new file mode 100644 index 0000000..a645f7b --- /dev/null +++ b/test/components/system-tag.test.ts @@ -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, + }, + ]); +});