Skip to content

chore: Style api docs-forward tools - #247

Open
pan-kot wants to merge 2 commits into
mainfrom
style-api-docs-forward
Open

chore: Style api docs-forward tools#247
pan-kot wants to merge 2 commits into
mainfrom
style-api-docs-forward

Conversation

@pan-kot

@pan-kot pan-kot commented Aug 13, 2026

Copy link
Copy Markdown
Member

A follow-up for #233 (see how it is applied: https://github.com/cloudscape-design/components/pull/4901/changes#diff-d9121ef7ddab55ffde139a30ce4f5e7f2961d8450cc6b4488649863cc135eccb).

While style-api.docs(...) annotates component's own tokens, the style-api.docs-forward(...) annotates ones that point to components used via internal composition. For example, in the Alert there are two slots:

  • root - alert's body, declaring style tokens such as color, background-color, and more;
  • dismissButton - alert's dismiss button, which uses Button internally. The corresponding classNames.dismissButton is passed down as Button's classNames.button.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.10%. Comparing base (d7cc26a) to head (60b04ed).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #247   +/-   ##
=======================================
  Coverage   98.09%   98.10%           
=======================================
  Files          56       56           
  Lines        1787     1793    +6     
  Branches      517      497   -20     
=======================================
+ Hits         1753     1759    +6     
  Misses         34       34           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pan-kot
pan-kot requested a review from avinashbot August 13, 2026 10:10
@pan-kot
pan-kot marked this pull request as ready for review August 14, 2026 06:16
@pan-kot
pan-kot requested a review from a team as a code owner August 14, 2026 06:16
slots.push({ name, tokens: tokens.split(/[\s,]+/).filter(Boolean) });
} else {
throw new Error(`Found multiple style-api.docs(...) annotations with the same name: "${name}"`);
slots.push({ name, forwardsTo: { component, slot } });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's possible to check the values at this stage? At least that the component exists, and possibly that the slot is declared in the component's styles (this part might introduce a circular dependency risk)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not do this in this util, as its purpose is simply to parse the data from CSS. However, this is a nice suggestion for the components part - which uses the tool to read metadata from all components, and can therefore ensure the validity. We can even check that the slots correspond to the components classNames structure. I will definitely add these validations!

Comment thread src/internal/style-api/docs.ts Outdated
// both forms.

const MARKER = /awsui:style-api-slot\s+name=([\w-]+)\s+tokens=([^*]*)\*\//g;
const MARKER = /awsui:style-api-slot\s+name=([\w-]+)\s+(?:tokens=([^*]*)|component=([\w-]+)\s+slot=([\w-]+)\s*)\*\//g;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a review comment, just a thought — using regular expressions for parsing this means that if we pass an invalid string (e.g. `"column layout" with a space), it's just going to be silently ignored rather than throw an error, which might lead to confusion and frustration.

Maybe it's worth having a more liberal regex (something like MIXIN_REGEX = /awsui:style-api-slot.*/)? So if MIXIN_REGEX matches and MARKER doesn't match, something went wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I will experiment with this 👍

@pan-kot
pan-kot requested a review from avinashbot August 18, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants