private mapSyntheticPropsForVariants()

in packages/codegen-ui-react/lib/react-studio-template-renderer.ts [1311:1333]


  private mapSyntheticPropsForVariants() {
    if (!isStudioComponentWithVariants(this.component)) {
      return;
    }

    this.component.variants.forEach((variant) => {
      // loop through the keys in the dict. Ex. Button, Flex.Flex[0].Flex[0].Button[0]
      Object.entries(variant.overrides).forEach(([overrideKey, value]) => {
        const propsInOverrides = value;
        const componentType = StudioNode.getComponentTypeFromOverrideKey(overrideKey);
        if (isPrimitive(componentType)) {
          const childrenPropMapping = PrimitiveChildrenPropMapping[Primitive[componentType as Primitive]];
          if (childrenPropMapping !== undefined) {
            // only remap if children prop is not defined in this particular overrides section
            if (propsInOverrides.children === undefined && propsInOverrides[childrenPropMapping] !== undefined) {
              propsInOverrides.children = propsInOverrides[childrenPropMapping];
              delete propsInOverrides[childrenPropMapping];
            }
          }
        }
      });
    });
  }