Skip to content

add scope tokens array by type node #670

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add scope tokens array by type node #670

wants to merge 1 commit into from

Conversation

mck
Copy link
Collaborator

@mck mck commented Mar 3, 2025

User description

This adds the Figma scope for an array of tokens by it's type

CleanShot 2025-03-03 at 10 07 36@2x


PR Type

  • Enhancement
  • Tests

Description

  • Added a new node for array token scoping.

  • Integrated Figma scope mapping by token type.

  • Included tests covering various token scenarios.

  • Updated changeset for release.


Changes walkthrough 📝

Relevant files
Enhancement
index.ts
Integrate token array node in main index.                               

packages/nodes-figma/src/nodes/index.ts

  • Imported new node module.
  • Added node to export array.
+3/-1     
scopeTokenArrayByType.ts
Add new token array by type node implementation.                 

packages/nodes-figma/src/nodes/scopeTokenArrayByType.ts

  • Introduced ScopeTokenArrayByType class.
  • Implements token type to Figma scope mapping.
  • Uses mergeTokenExtensions to preserve extensions.
  • Processes an array of tokens.
  • +80/-0   
    Tests
    scopeTokenArrayByType.test.ts
    Add tests for new token array node.                                           

    packages/nodes-figma/tests/scopeTokenArrayByType.test.ts

  • Added test for color token scopes.
  • Added test for dimension token scopes.
  • Tested merging of existing extensions.
  • +101/-0 
    Documentation
    tidy-kids-raise.md
    Update changeset for token array node.                                     

    .changeset/tidy-kids-raise.md

    • Updated changeset file for the new node addition.
    +5/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • This adds the Figma scope for an array of tokens by it's type
    Copy link

    changeset-bot bot commented Mar 3, 2025

    🦋 Changeset detected

    Latest commit: 13ce480

    The changes in this PR will be included in the next version bump.

    This PR includes changesets to release 1 package
    Name Type
    @tokens-studio/graph-engine-nodes-figma Minor

    Not sure what this means? Click here to learn what changesets are.

    Click here if you're a maintainer who wants to add another changeset to this PR

    @mck mck self-assigned this Mar 3, 2025
    Copy link
    Contributor

    github-actions bot commented Mar 3, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Type Safety

    The token parameter in the getScopesByType function is currently untyped. Consider adding an explicit type annotation—possibly leveraging the SingleToken type—to improve type safety and code clarity.

    getScopesByType = token => {
    	switch (token.type) {
    		case 'color':
    			return ['ALL_FILLS', 'STROKE_COLOR', 'EFFECT_COLOR'];
    		case 'dimension':
    			return [
    				'GAP',
    				'WIDTH_HEIGHT',
    				'CORNER_RADIUS',
    				'STROKE_FLOAT',
    				'EFFECT_FLOAT',
    				'PARAGRAPH_INDENT'
    			];
    		case 'spacing':
    			return ['GAP', 'WIDTH_HEIGHT'];
    		case 'borderRadius':
    			return ['CORNER_RADIUS'];
    		case 'fontFamilies':
    			return ['FONT_FAMILY'];
    		case 'fontWeights':
    			return ['FONT_WEIGHT'];
    		case 'fontSizes':
    			return ['FONT_SIZE'];
    		case 'lineHeights':
    			return ['LINE_HEIGHT'];
    		case 'letterSpacing':
    			return ['LETTER_SPACING'];
    		case 'paragraphSpacing':
    			return ['PARAGRAPH_SPACING'];
    		case 'opacity':
    			return ['OPACITY'];
    		case 'sizing':
    			return ['WIDTH_HEIGHT'];
    		default:
    			return [];
    	}
    };
    Node Order

    Confirm that the reordering of nodes (including re-adding scopeString and adding scopeTokenArrayByType) in the nodes array is intentional and aligned with module loading or execution order requirements.

    scopeString,
    scopeTokenArrayByType

    Copy link
    Contributor

    github-actions bot commented Mar 3, 2025

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    }

    // Reuse the same scopes mapping as the single token version
    getScopesByType = token => {
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    if it's reusing this large switch, would it not make sense to put it in a separate function?

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants