generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 220
chore: add AGENTS.md and conventions #4387
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
Open
amanabiy
wants to merge
12
commits into
main
Choose a base branch
from
dev-v3-amanabiy-ai-instructions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d92a591
test: testing ai instructions
amanabiy 11af693
chore: improve docs
amanabiy 92871de
chore: improve docs according to feedback
amanabiy 6bb8323
chore: removing relations in docs/ files
amanabiy 17d9487
chore: clean up docs to make it more structured
amanabiy 1f02410
chore: rename file to make it more descriptive
amanabiy a4b8853
chore: simplify by removing file paths
amanabiy 26d495c
chore: centralize the import for the common guide
amanabiy 5a85f8a
chore: modularize CONTRIBUTING.md
amanabiy 1d29949
chore: improve the doc
amanabiy eabee97
chore: update the docs
amanabiy 1eac186
chore: update the docs
amanabiy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # AGENTS.md | ||
|
|
||
| React component library for [Cloudscape Design System](https://cloudscape.design/) — an open source design system for building accessible, inclusive web experiences at scale. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| See [docs/SETUP.md](docs/SETUP.md) for setup, building, and running locally. | ||
|
|
||
| ## Docs Index | ||
|
|
||
| See [docs/CLOUDSCAPE_COMPONENTS_GUIDE.md](docs/CLOUDSCAPE_COMPONENTS_GUIDE.md) for guides on component conventions, styling, writing tests, and more. | ||
| For running tests and configs, see [docs/RUNNING_TESTS.md](docs/RUNNING_TESTS.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # API Documentation Comments | ||
|
|
||
| This project uses `@cloudscape-design/documenter` to generate API docs from JSDoc comments in component interface files (`src/<component>/interfaces.ts`). | ||
|
|
||
| ## Special Tags | ||
|
|
||
| - `@i18n` — marks internationalization properties | ||
| - `@analytics` — marks analytics metadata properties | ||
| - `@deprecated` — marks deprecated properties (include replacement info) | ||
| - `@displayname` — overrides the display name (e.g. `children` → `text`) | ||
| - `@awsuiSystem` — tags a property or import by internal system (e.g. `@awsuiSystem core`), used for internal classification | ||
|
|
||
| ## Sub-types | ||
|
|
||
| Define union types as named type aliases in the component's namespace, not as inline unions. Then reference them in the interface: `variant?: ButtonProps.Variant`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Cloudscape Components Documentation | ||
|
|
||
| Reference docs for contributing to [cloudscape-design/components](https://github.com/cloudscape-design/components). | ||
|
|
||
| - [General Guide](https://github.com/cloudscape-design/components/blob/main/docs/GENERAL_GUIDE.md) — setup, building, running locally, frameworks, versioning | ||
| - [Component Conventions](https://github.com/cloudscape-design/components/blob/main/docs/COMPONENT_CONVENTIONS.md) — component structure, props, events, refs | ||
| - [Styling](https://github.com/cloudscape-design/components/blob/main/docs/STYLING.md) — design tokens, CSS rules, RTL support | ||
| - [Writing Tests](https://github.com/cloudscape-design/components/blob/main/docs/WRITING_TESTS.md) — test utils, unit and integration tests | ||
| - [Running Tests](https://github.com/cloudscape-design/components/blob/main/docs/RUNNING_TESTS.md) — test configs and commands | ||
| - [Code Style](https://github.com/cloudscape-design/components/blob/main/docs/CODE_STYLE.md) — prettier, stylelint, eslint | ||
| - [TEST Pages](https://github.com/cloudscape-design/components/blob/main/docs/TEST_PAGES.md) — dev/test pages and running in the browser | ||
| - [API Docs](https://github.com/cloudscape-design/components/blob/main/docs/API_DOCS.md) — API documentation comments | ||
| - [Internals](https://github.com/cloudscape-design/components/blob/main/docs/INTERNALS.md) — internal shared utilities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Code Style | ||
|
|
||
| Run `npm run lint` to check formatting and linting. The project uses: | ||
|
|
||
| - **Prettier** for code formatting | ||
| - **Stylelint** for CSS/SCSS linting | ||
| - **ESLint** for JavaScript/TypeScript linting | ||
|
|
||
| See the respective config files in the project root for rules. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Component Conventions | ||
|
|
||
| ## Component Structure | ||
|
|
||
| Each component is exposed from `src/<component-name>/index.tsx`. | ||
|
|
||
| - `applyDisplayName` — readable name in consumers' devtools | ||
|
|
||
| ### Internal Component (`internal.tsx`) | ||
|
|
||
| The APIs exported from `src/<component>/index.tsx` are public and must not be used internally by other components. For internal usage, each component exposes a private counterpart at `internal.tsx`. | ||
|
|
||
| ## Props & Interfaces | ||
|
|
||
| - Props interface: `${ComponentName}Props`, namespace sub-types under it (e.g. `${ComponentName}Props.Variant`) | ||
| - Union types must be type aliases (no inline unions) | ||
| - Array types must use `ReadonlyArray<T>` | ||
amanabiy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| For how to document props, see [API_DOCS.md](API_DOCS.md). | ||
|
|
||
| ## Events | ||
|
|
||
| Use `CancelableEventHandler<DetailType>` or `NonCancelableEventHandler<DetailType>`. All `on*` props must use these interfaces (build fails otherwise). | ||
|
|
||
| Events are similar to native events with `event.preventDefault()` for cancelable events, but are not dispatched via DOM. | ||
|
|
||
| ## Refs | ||
|
|
||
| The component ref API does not give access to the underlying DOM node. Instead, we expose specific methods — most commonly `focus()`, for which a dedicated util `useForwardFocus` is available. | ||
|
|
||
| When a component accepts a ref, create `${ComponentName}ForwardRefType` as follows: | ||
|
|
||
| ```tsx | ||
| interface MyComponentForwardRefType { | ||
| <T>(props: MyComponentProps<T> & { ref?: React.Ref<MyComponentProps.Ref> }): JSX.Element; | ||
| } | ||
| ``` | ||
|
|
||
| ## Controllable Components | ||
|
|
||
| Use the same behavior as built-in React components: | ||
|
|
||
| 1. If only `onChange` is provided → uncontrolled (component manages its own state, `onChange` fires for side effects) | ||
| 2. If `value` is provided → controlled (with or without `onChange`; without `onChange` it's read-only) | ||
|
|
||
| Implementation: | ||
| 1. Create a controlled component first | ||
| 2. Use `useControllable` to wrap customer-provided properties — gives you a `[value, setValue]` pair | ||
| 3. If `value` is provided without `onChange`, `useControllable` emits a console warning | ||
|
|
||
| ## I18n | ||
|
|
||
| Centralize all translatable strings under a skippable property (e.g. `i18nStrings`). Internationalization code lives in `src/i18n/`. The `useInternalI18n` hook is what components use to resolve translated strings. | ||
|
|
||
| ```tsx | ||
| const i18n = useInternalI18n('alert'); | ||
| <InternalButton ariaLabel={i18n('dismissAriaLabel', dismissAriaLabel)} /> | ||
| ``` | ||
|
|
||
| ## Dependencies | ||
|
|
||
| Before adding any dependency: must support React 16.8+ and latest 3 major Chrome/Firefox/Edge, no global state, ESM preferred. | ||
|
|
||
| ## Test Utils | ||
|
|
||
| Test-utils core is a separate package: https://github.com/cloudscape-design/test-utils | ||
|
|
||
| - Test-utils should not have any dependencies — they can be used with any tech stack. | ||
| - Test-utils extend `ComponentWrapper`. `ElementWrapper` is only a return type when no more specific type is available. | ||
| - Methods must have explicitly declared return types (enforced via ESLint). | ||
| - Wrapper classes must have a static `rootSelector` property. | ||
| - For methods that always return a value, add a non-null assertion. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Directory Layout | ||
|
|
||
| ``` | ||
amanabiy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ├── __mocks__ - jest mocks for external dependencies | ||
| │ | ||
| ├── build-tools - build tasks and configuration for gulp | ||
| │ | ||
| ├── pages - react pages for development, scenario and permutation testing | ||
| │ └── <page>.page.tsx | ||
| │ | ||
| ├── src | ||
| │ ├── __a11y__ - global a11y tests for all components | ||
| │ ├── __integ__ - global integ tests for all components | ||
| │ ├── __tests__ - global unit tests for all components | ||
| │ │ | ||
| │ ├── <component-dir> | ||
| │ │ ├── __tests__ - jest unit tests | ||
| │ │ ├── __integ__ - jest integration tests | ||
| │ │ ├── __motion__ - jest motion tests | ||
| │ │ ├── index.tsx - main component file (imports other files and styles) | ||
| │ │ └── styles.scss - main SCSS file | ||
| │ │ | ||
| │ ├── test-utils - test utils for components | ||
| │ │ ├── dom - main source code for test utils | ||
| │ │ └── selectors - utils for integration testing, generated from the code in `dom` folder | ||
| │ │ | ||
| │ ├── i18n - internationalization: messages, providers, and the useInternalI18n hook | ||
| │ │ | ||
| │ └── internal - library internals | ||
| │ ├── base-component - necessary declarations for every public component | ||
| │ ├── components - internal utility components | ||
| │ ├── events - utilities for firing public events | ||
| │ ├── hooks - internal utility hooks | ||
| │ ├── generated - generated code from style-dictionary | ||
| │ └── styles - base styles and SCSS-mixins | ||
| │ | ||
| ├── lib - build output | ||
amanabiy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| │ ├── components - the primary components package | ||
| │ ├── components-definitions - generated metadata for components | ||
| │ └── design-tokens - exported design tokens | ||
| │ | ||
| └── style-dictionary - design token definitions (colors, spacing, typography, etc.) | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.