diff --git a/__tests__/tailwindcss/fill.tsx b/__tests__/tailwindcss/fill.tsx index 02b4f3f..095cb88 100644 --- a/__tests__/tailwindcss/fill.tsx +++ b/__tests__/tailwindcss/fill.tsx @@ -31,7 +31,7 @@ const cases: Array<[string, string]> = [ ["rose-50", "#fff1f2"], ]; -const StyledCircle = styled(Circle, { cssProps: ["fill", "stroke"] }); +const StyledCircle = styled(Circle, { classProps: ["fill", "stroke"] }); describe("Svg - Fill", () => { test.each(cases)("fill-%s", (unit) => { diff --git a/__tests__/tailwindcss/stroke-width.tsx b/__tests__/tailwindcss/stroke-width.tsx index 50658e9..7fcfdc8 100644 --- a/__tests__/tailwindcss/stroke-width.tsx +++ b/__tests__/tailwindcss/stroke-width.tsx @@ -9,7 +9,7 @@ const cases: Array<[string, string]> = [ ["2", "2"], ]; -const StyledCircle = styled(Circle, { cssProps: ["fill", "stroke"] }); +const StyledCircle = styled(Circle, { classProps: ["fill", "stroke"] }); describe("Svg - Stroke Width", () => { test.each(cases)("stroke-%s", (unit) => { diff --git a/__tests__/tailwindcss/stroke.tsx b/__tests__/tailwindcss/stroke.tsx index 54a4fa0..541c0d7 100644 --- a/__tests__/tailwindcss/stroke.tsx +++ b/__tests__/tailwindcss/stroke.tsx @@ -31,7 +31,7 @@ const cases: Array<[string, string]> = [ ["rose-50", "#fff1f2"], ]; -const StyledCircle = styled(Circle, { cssProps: ["fill", "stroke"] }); +const StyledCircle = styled(Circle, { classProps: ["fill", "stroke"] }); describe("Svg - Stroke", () => { test.each(cases)("stroke-%s", (unit) => { diff --git a/src/classname-to-inline-style.ts b/src/classname-to-inline-style.ts index 9945f96..001cadc 100644 --- a/src/classname-to-inline-style.ts +++ b/src/classname-to-inline-style.ts @@ -58,7 +58,9 @@ function getStyles(className: string) { if (rule) { for (const key of rule.style as unknown as string[]) { // eslint-disable-next-line @typescript-eslint/no-explicit-any - stylesheet[cacheKey][className][key] = (rule.style as any)[key]; + stylesheet[cacheKey][className][toCamelCase(key)] = (rule.style as any)[ + key + ]; } } @@ -68,3 +70,9 @@ function getStyles(className: string) { function isCSSStyleRule(rule: CSSRule): rule is CSSStyleRule { return "selectorText" in rule; } + +function toCamelCase(value: string) { + return value + .toLowerCase() + .replace(/[^\dA-Za-z]+(.)/g, (_, chr) => chr.toUpperCase()); +} diff --git a/src/styled.tsx b/src/styled.tsx index 2d0841e..e9d7d6c 100644 --- a/src/styled.tsx +++ b/src/styled.tsx @@ -11,7 +11,8 @@ import { usePlatform } from "./context/platform"; export interface StyledOptions
{
props?: Array {
componentProps: Record;
spreadProps?: T[];
- cssProps?: T[];
+ classProps?: T[];
preview: boolean;
+ supportsClassName: boolean;
}
export type WithStyledProps = Record({
styleProp,
componentProps,
spreadProps = [],
- cssProps = [],
+ classProps = [],
preview,
}: WithStyledPropsOptions): WithStyledProps {
const mainStyles = tw(classes, { flatten: false });
const styledProps: Partial({
).tailwindClassName;
} else {
const entries = Object.entries(tw(value, { flatten: true }));
+
if (entries.length > 0) {
styledProps[prop] = undefined;
for (const [key, value] of entries) {