@pandacss/generator 0.0.0-dev-20230414155459 → 0.0.0-dev-20230414155738

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -698,19 +698,27 @@ function generateRecipes(ctx) {
698
698
  name: "create-recipe",
699
699
  dts: "",
700
700
  js: import_outdent9.outdent`
701
+ ${ctx.file.import("css, mergeCss", "../css/css")}
702
+ ${ctx.file.import("cx", "../css/cx")}
701
703
  ${ctx.file.import("createCss, withoutSpace, compact", "../helpers")}
702
704
 
703
- export const createRecipe = (name, defaultVariants) => {
705
+ export const createRecipe = (name, defaultVariants, compoundVariants) => {
704
706
  return (variants) => {
705
707
  const transform = (prop, value) => {
708
+ if (compoundVariants.length > 0 && typeof variants[prop] === 'object') {
709
+ throw new Error(
710
+ \`[recipe:\${name}:\${prop}:\${value}] Conditions are not supported when using compound variants.\`,
711
+ )
712
+ }
713
+
706
714
  if (value === '__ignore__') {
707
715
  return { className: name }
708
716
  }
709
-
717
+
710
718
  value = withoutSpace(value)
711
719
  return { className: \`\${name}--\${prop}${separator}\${value}\` }
712
720
  }
713
-
721
+
714
722
  const context = {
715
723
  hash: ${hash ? "true" : "false"},
716
724
  utility: {
@@ -718,14 +726,29 @@ function generateRecipes(ctx) {
718
726
  transform,
719
727
  }
720
728
  }
721
-
722
- const css = createCss(context)
723
-
724
- return css({
729
+
730
+ const recipeCss = createCss(context)
731
+ const recipeStyles = {
725
732
  [name]: '__ignore__',
726
733
  ...defaultVariants,
727
- ...compact(variants)
734
+ ...compact(variants),
735
+ }
736
+
737
+ let result = {}
738
+ compoundVariants.forEach((compoundVariant) => {
739
+ const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
740
+ if (key === 'css') return true
741
+
742
+ const values = Array.isArray(value) ? value : [value]
743
+ return values.some((value) => recipeStyles[key] === value)
744
+ })
745
+
746
+ if (isMatching) {
747
+ result = mergeCss(result, compoundVariant.css)
748
+ }
728
749
  })
750
+
751
+ return cx(recipeCss(recipeStyles), css(result))
729
752
  }
730
753
  }
731
754
  `
@@ -734,13 +757,15 @@ function generateRecipes(ctx) {
734
757
  createRecipeFn,
735
758
  ...ctx.recipes.details.map((recipe) => {
736
759
  const { config, upperName, variantKeyMap, dashName } = recipe;
737
- const { name, description, defaultVariants } = config;
760
+ const { name, description, defaultVariants, compoundVariants } = config;
738
761
  return {
739
762
  name: dashName,
740
763
  js: import_outdent9.outdent`
741
764
  ${ctx.file.import("createRecipe", "./create-recipe")}
742
765
 
743
- export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})})
766
+ export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})}, ${JSON.stringify(
767
+ compoundVariants ?? []
768
+ )})
744
769
  ${name}.variants = ${JSON.stringify(variantKeyMap)}
745
770
  `,
746
771
  dts: import_outdent9.outdent`
@@ -749,15 +774,15 @@ function generateRecipes(ctx) {
749
774
  type ${upperName}Variant = {
750
775
  ${Object.keys(variantKeyMap).map((key) => `${key}: ${(0, import_shared2.unionType)(variantKeyMap[key])}`).join("\n")}
751
776
  }
752
-
777
+
753
778
  type ${upperName}VariantMap = {
754
779
  [key in keyof ${upperName}Variant]: Array<${upperName}Variant[key]>
755
780
  }
756
-
781
+
757
782
  export type ${upperName}Variants = {
758
- [key in keyof ${upperName}Variant]?: ConditionalValue<${upperName}Variant[key]>
783
+ [key in keyof ${upperName}Variant]?: ${compoundVariants?.length ? `${upperName}Variant[key]` : `ConditionalValue<${upperName}Variant[key]>`}
759
784
  }
760
-
785
+
761
786
  ${description ? `/** ${description} */` : ""}
762
787
  export declare function ${name}(variants?: ${upperName}Variants): string & {
763
788
  variants: ${upperName}VariantMap
package/dist/index.mjs CHANGED
@@ -667,19 +667,27 @@ function generateRecipes(ctx) {
667
667
  name: "create-recipe",
668
668
  dts: "",
669
669
  js: outdent9`
670
+ ${ctx.file.import("css, mergeCss", "../css/css")}
671
+ ${ctx.file.import("cx", "../css/cx")}
670
672
  ${ctx.file.import("createCss, withoutSpace, compact", "../helpers")}
671
673
 
672
- export const createRecipe = (name, defaultVariants) => {
674
+ export const createRecipe = (name, defaultVariants, compoundVariants) => {
673
675
  return (variants) => {
674
676
  const transform = (prop, value) => {
677
+ if (compoundVariants.length > 0 && typeof variants[prop] === 'object') {
678
+ throw new Error(
679
+ \`[recipe:\${name}:\${prop}:\${value}] Conditions are not supported when using compound variants.\`,
680
+ )
681
+ }
682
+
675
683
  if (value === '__ignore__') {
676
684
  return { className: name }
677
685
  }
678
-
686
+
679
687
  value = withoutSpace(value)
680
688
  return { className: \`\${name}--\${prop}${separator}\${value}\` }
681
689
  }
682
-
690
+
683
691
  const context = {
684
692
  hash: ${hash ? "true" : "false"},
685
693
  utility: {
@@ -687,14 +695,29 @@ function generateRecipes(ctx) {
687
695
  transform,
688
696
  }
689
697
  }
690
-
691
- const css = createCss(context)
692
-
693
- return css({
698
+
699
+ const recipeCss = createCss(context)
700
+ const recipeStyles = {
694
701
  [name]: '__ignore__',
695
702
  ...defaultVariants,
696
- ...compact(variants)
703
+ ...compact(variants),
704
+ }
705
+
706
+ let result = {}
707
+ compoundVariants.forEach((compoundVariant) => {
708
+ const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
709
+ if (key === 'css') return true
710
+
711
+ const values = Array.isArray(value) ? value : [value]
712
+ return values.some((value) => recipeStyles[key] === value)
713
+ })
714
+
715
+ if (isMatching) {
716
+ result = mergeCss(result, compoundVariant.css)
717
+ }
697
718
  })
719
+
720
+ return cx(recipeCss(recipeStyles), css(result))
698
721
  }
699
722
  }
700
723
  `
@@ -703,13 +726,15 @@ function generateRecipes(ctx) {
703
726
  createRecipeFn,
704
727
  ...ctx.recipes.details.map((recipe) => {
705
728
  const { config, upperName, variantKeyMap, dashName } = recipe;
706
- const { name, description, defaultVariants } = config;
729
+ const { name, description, defaultVariants, compoundVariants } = config;
707
730
  return {
708
731
  name: dashName,
709
732
  js: outdent9`
710
733
  ${ctx.file.import("createRecipe", "./create-recipe")}
711
734
 
712
- export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})})
735
+ export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})}, ${JSON.stringify(
736
+ compoundVariants ?? []
737
+ )})
713
738
  ${name}.variants = ${JSON.stringify(variantKeyMap)}
714
739
  `,
715
740
  dts: outdent9`
@@ -718,15 +743,15 @@ function generateRecipes(ctx) {
718
743
  type ${upperName}Variant = {
719
744
  ${Object.keys(variantKeyMap).map((key) => `${key}: ${unionType2(variantKeyMap[key])}`).join("\n")}
720
745
  }
721
-
746
+
722
747
  type ${upperName}VariantMap = {
723
748
  [key in keyof ${upperName}Variant]: Array<${upperName}Variant[key]>
724
749
  }
725
-
750
+
726
751
  export type ${upperName}Variants = {
727
- [key in keyof ${upperName}Variant]?: ConditionalValue<${upperName}Variant[key]>
752
+ [key in keyof ${upperName}Variant]?: ${compoundVariants?.length ? `${upperName}Variant[key]` : `ConditionalValue<${upperName}Variant[key]>`}
728
753
  }
729
-
754
+
730
755
  ${description ? `/** ${description} */` : ""}
731
756
  export declare function ${name}(variants?: ${upperName}Variants): string & {
732
757
  variants: ${upperName}VariantMap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "0.0.0-dev-20230414155459",
3
+ "version": "0.0.0-dev-20230414155738",
4
4
  "description": "The css generator for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -20,16 +20,16 @@
20
20
  "pluralize": "8.0.0",
21
21
  "postcss": "8.4.21",
22
22
  "ts-pattern": "4.2.2",
23
- "@pandacss/core": "0.0.0-dev-20230414155459",
24
- "@pandacss/logger": "0.0.0-dev-20230414155459",
25
- "@pandacss/is-valid-prop": "0.0.0-dev-20230414155459",
26
- "@pandacss/shared": "0.0.0-dev-20230414155459",
27
- "@pandacss/types": "0.0.0-dev-20230414155459",
28
- "@pandacss/token-dictionary": "0.0.0-dev-20230414155459"
23
+ "@pandacss/core": "0.0.0-dev-20230414155738",
24
+ "@pandacss/logger": "0.0.0-dev-20230414155738",
25
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230414155738",
26
+ "@pandacss/shared": "0.0.0-dev-20230414155738",
27
+ "@pandacss/types": "0.0.0-dev-20230414155738",
28
+ "@pandacss/token-dictionary": "0.0.0-dev-20230414155738"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/pluralize": "0.0.29",
32
- "@pandacss/fixture": "0.0.0-dev-20230414155459"
32
+ "@pandacss/fixture": "0.0.0-dev-20230414155738"
33
33
  },
34
34
  "scripts": {
35
35
  "prebuild": "tsx scripts/prebuild.ts",