diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 37d5566..fc0a134 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -24,7 +24,7 @@ export const extractStyles = (path: string) => { : fs.readFileSync(path).toString(); return fileContent.match( - /([a-zA-Z_]*)(?:[.]{1})([a-zA-Z_]+[\w\-_]*)(?:[\s\.\,\{\>#\:]{0})/gim + /(h[1-6]|[a-zA-Z_]*)(?:[.]{1})([a-zA-Z_]+[\w\-_]*)(?:[\s\.\,\{\>#\:]{0})/gim ); }; diff --git a/src/index.ts b/src/index.ts index 9b64e77..3264358 100755 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,11 @@ import { PolymorphicComponent, variantsType, } from "./type"; -import { findMatchingCompoundVariants, flattenCss } from "./utils"; +import { + componentDisplayName, + findMatchingCompoundVariants, + flattenCss, +} from "./utils"; export { CSSComponentConfig, CSS, VariantProps } from "./type"; @@ -70,7 +74,7 @@ export const styled = < } componentProps.className = componentStyles.join(" "); - styledComponent.displayName = element.toString(); + styledComponent.displayName = componentDisplayName(element); return createElement(element, componentProps); } ); diff --git a/src/utils.ts b/src/utils.ts index d0b1eb5..2643fb6 100755 --- a/src/utils.ts +++ b/src/utils.ts @@ -16,3 +16,6 @@ export const findMatchingCompoundVariants = ( export const flattenCss = (css: CSS) => Array.isArray(css) ? css.join(" ") : css; + +export const componentDisplayName = (component: any) => + typeof window == "undefined" ? component.displayName : component.toString();