Home / Function/ applyToCvaCalls() — ui Function Reference

applyToCvaCalls() — ui Function Reference

Architecture documentation for the applyToCvaCalls() function in transform-style-map.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  983d9e21_ede7_170e_88fa_6bfb84e023a1["applyToCvaCalls()"]
  cef4e429_7112_fef5_ae0b_a838a57ccf71["transform-style-map.ts"]
  983d9e21_ede7_170e_88fa_6bfb84e023a1 -->|defined in| cef4e429_7112_fef5_ae0b_a838a57ccf71
  69e29c3a_597d_3ecf_b7be_50b09c93f556["transformStyleMap()"]
  69e29c3a_597d_3ecf_b7be_50b09c93f556 -->|calls| 983d9e21_ede7_170e_88fa_6bfb84e023a1
  e405253b_cc7a_b5b7_8daf_ff3eda64d06b["applyStyleToCvaString()"]
  983d9e21_ede7_170e_88fa_6bfb84e023a1 -->|calls| e405253b_cc7a_b5b7_8daf_ff3eda64d06b
  style 983d9e21_ede7_170e_88fa_6bfb84e023a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/styles/transform-style-map.ts lines 82–147

function applyToCvaCalls(
  sourceFile: SourceFile,
  styleMap: StyleMap,
  matchedClasses: Set<string>
) {
  sourceFile.forEachDescendant((node) => {
    if (!Node.isCallExpression(node)) {
      return
    }

    const expression = node.getExpression()
    if (!Node.isIdentifier(expression) || expression.getText() !== "cva") {
      return
    }

    const baseArg = node.getArguments()[0]
    if (Node.isStringLiteral(baseArg)) {
      applyStyleToCvaString(baseArg, styleMap, matchedClasses)
    }

    const configArg = node.getArguments()[1]
    if (!configArg || !Node.isObjectLiteralExpression(configArg)) {
      return
    }

    const variantsProp = configArg
      .getProperties()
      .find(
        (prop) =>
          Node.isPropertyAssignment(prop) &&
          Node.isIdentifier(prop.getNameNode()) &&
          prop.getNameNode().getText() === "variants"
      )

    if (!variantsProp || !Node.isPropertyAssignment(variantsProp)) {
      return
    }

    const variantsObj = variantsProp.getInitializer()
    if (!variantsObj || !Node.isObjectLiteralExpression(variantsObj)) {
      return
    }

    variantsObj.getProperties().forEach((typeProp) => {
      if (!Node.isPropertyAssignment(typeProp)) {
        return
      }

      const typeObj = typeProp.getInitializer()
      if (!typeObj || !Node.isObjectLiteralExpression(typeObj)) {
        return
      }

      typeObj.getProperties().forEach((variantProp) => {
        if (!Node.isPropertyAssignment(variantProp)) {
          return
        }

        const variantValue = variantProp.getInitializer()
        if (variantValue && Node.isStringLiteral(variantValue)) {
          applyStyleToCvaString(variantValue, styleMap, matchedClasses)
        }
      })
    })
  })
}

Subdomains

Frequently Asked Questions

What does applyToCvaCalls() do?
applyToCvaCalls() is a function in the ui codebase, defined in packages/shadcn/src/styles/transform-style-map.ts.
Where is applyToCvaCalls() defined?
applyToCvaCalls() is defined in packages/shadcn/src/styles/transform-style-map.ts at line 82.
What does applyToCvaCalls() call?
applyToCvaCalls() calls 1 function(s): applyStyleToCvaString.
What calls applyToCvaCalls()?
applyToCvaCalls() is called by 1 function(s): transformStyleMap.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free