Cloudscape Design System Components
repository·main·Indexed 25 days ago
https://github.com/cloudscape-design/componentsAn open source design system used by Amazon Web Services (AWS) providing a set of React components and guidelines for building intuitive, engaging, and inclusive web applications at scale. Includes documentation on component conventions, internationalization (i18n), styling with design tokens, and testing procedures for React 16.8+ applications.
What's inside @cloudscape-design/components
- Cloudscape releases patch versions on a daily basis to provide bug fixes, new features, and new components. Patch versions are guaranteed to not contain breaking changes.
Understand API documentation generation
mainCloudscape generates its API documentation using@cloudscape-design/documenter. The documentation is derived from JSDoc comments located in the component interface files, specifically withinsrc/<component>/interfaces.ts.Check framework and browser compatibility
mainCloudscape components require the following environments:
Frameworks
- React 16.8+
- Jest 25+
Browsers
- Desktop: Latest 3 major versions of Google Chrome, Mozilla Firefox, and Microsoft Edge.
- macOS: Latest 3 minor versions of Apple Safari.
Note: Mobile browsers and Microsoft Internet Explorer are not supported. All viewport sizes across supported desktop browsers are supported.
Handle interactive elements in Dialog cells
mainWhen a table cell contains interactive elements like text inputs or radio groups, they may conflict with grid navigation keyboard inputs. To resolve this, you must make cell elements conditionally interactive (e.g., activated by
EnterorF2).To suppress grid navigation and allow the element to capture keyboard input, wrap the interactive content in a container with
role="dialog"or use the grid navigation API to suppress behaviors.<td> <div role="dialog"> <input value="editable cell value" /> <button>save</button> <button>discard</button> </div> </td>Apply styling using design tokens and logical properties
mainWhen styling components, avoid hardcoded values like specific colors, spacing, or font sizes. Instead, use design tokens and custom CSS properties to ensure consistency across different themes and modes.
To support Right-to-Left (RTL) layouts, use CSS logical properties instead of physical properties:
- Use
inline-start/inline-endinstead ofleft/right. - Use
block-start/block-endinstead oftop/bottom. - Use
inline-sizeinstead ofwidth. - Use
block-sizeinstead ofheight.
- Use
Install Cloudscape components
mainInstall the project dependencies using npm.
npm installRun Cloudscape tests via npm scripts
mainUse the following npm scripts to run different test suites. The scripts automatically handle environment variables like
TZ=UTCandNODE_OPTIONS=--experimental-vm-modules, as well as the dev server lifecycle for integration and motion tests.npm test # all tests npm run test:unit # unit tests npm run test:integ # integration tests (starts dev server automatically) npm run test:motion # motion tests (starts dev server automatically) npm run test:a11y # accessibility testsUpdate snapshot tests
mainSnapshot tests guard artifacts like API definitions and design tokens. Before updating snapshots, you must run a full build to ensure documenter docs are generated.
To update unit test snapshots:
TZ=UTC npx jest -u -c jest.unit.config.js src/__tests__/If design tokens have changed, you must also update integration test snapshots:
NODE_OPTIONS=--experimental-vm-modules npx jest -u -c jest.integ.config.js src/__integ__/npm run build # Update unit test snapshots TZ=UTC npx jest -u -c jest.unit.config.js src/__tests__/ # Update integration test snapshots (if design tokens changed) NODE_OPTIONS=--experimental-vm-modules npx jest -u -c jest.integ.config.js src/__integ__/Add New I18n Strings
mainTo add a new
@i18nstring, follow these steps:- Add the English source string and a translator
noteto theAWS-UI-Components-I18npackage (ati18n/<component>/en.json). - Run
npm run buildin that package. - Copy the generated
output/files into this repository'ssrc/i18n/(specificallymessages/all.<locale>.jsonbundles andmessages-types.ts). - Ensure the message key path (e.g.,
i18nStrings.sortDropdown.sortAscending) matches the interface used byuseInternalI18n.
- Add the English source string and a translator
Update test snapshots
mainWhen component APIs or design tokens change, you must update snapshots. Before updating, run a full build using
npm run buildto ensure documenter docs are generated. Use the-uflag with Jest to perform the update.# Unit snapshots TZ=UTC npx jest -u -c jest.unit.config.js src/__tests__/snapshot-tests # Integ snapshots (requires dev server running via `npm start`) NODE_OPTIONS=--experimental-vm-modules npx jest -u -c jest.integ.config.js src/__integ__/ # Snapshots inside components (e.g. when custom-css-properties.js changes) TZ=UTC npx jest -u -c jest.unit.config.js src/Define union types for component interfaces
mainTo ensure proper documentation and type referencing, do not define union types inline within an interface. Instead, define them as named type aliases within the component's namespace and reference them using the component's namespace prefix.
Example pattern: Instead of
variant?: 'primary' | 'secondary', usevariant?: ButtonProps.VariantwhereVariantis a named type alias.Implement RTL support for direction-aware logic
mainWhen CSS logical properties are insufficient for direction-aware logic, use the following tools:
- In SCSS: Use the
with-directionmixin. - In TypeScript: Use the direction detection and logical geometry helpers provided by
@cloudscape-design/component-toolkit/internal. These helpers should be used to replace physical DOM property checks.
- In SCSS: Use the