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; spreadProps?: Array; - cssProps?: Array; + classProps?: Array; + supportsClassName?: boolean; } /** @@ -26,14 +27,19 @@ export function styled( */ export function styled( Component: Component, - options: { props?: Array; spreadProps?: Array; cssProps?: Array } + options: { props?: Array; spreadProps?: Array; classProps?: Array } ): FC>; /** * Actual implementation */ export function styled( Component: Component, - { props: propsToTransform, spreadProps, cssProps }: StyledOptions = {} + { + props: propsToTransform, + spreadProps, + classProps, + supportsClassName = false, + }: StyledOptions = {} ) { function Styled({ className, @@ -50,7 +56,7 @@ export function styled( componentProps, propsToTransform, spreadProps, - cssProps, + classProps, }); const { hover, focus, active, ...handlers } = useInteraction({ @@ -74,8 +80,9 @@ export function styled( propsToTransform, componentProps, spreadProps, - cssProps, + classProps, preview, + supportsClassName, }); const children = childStyles diff --git a/src/use-interaction.ts b/src/use-interaction.ts index 3155d19..75b9fd2 100644 --- a/src/use-interaction.ts +++ b/src/use-interaction.ts @@ -34,8 +34,6 @@ export function useInteraction({ onPressIn, onPressOut, className = "", - preview, - platform, }: UseInteractionOptions) { const [hover, setHover] = useState(false); const [focus, setFocus] = useState(false); @@ -161,11 +159,6 @@ export function useInteraction({ if (className.includes("active:")) { interaction.onPressIn = handlePressIn; interaction.onPressOut = handlePressOut; - - if (platform === "web" && !preview) { - interaction.onMouseUp = handlePressOut; - interaction.onMouseDown = handlePressIn; - } } } diff --git a/src/with-class-names.ts b/src/with-class-names.ts index 59797b6..003b883 100644 --- a/src/with-class-names.ts +++ b/src/with-class-names.ts @@ -4,7 +4,7 @@ export interface WithClassNames { propsToTransform?: string[]; componentProps: Record; spreadProps?: string[]; - cssProps?: string[]; + classProps?: string[]; } export function withClassNames({ className, @@ -12,14 +12,14 @@ export function withClassNames({ componentProps, propsToTransform = [], spreadProps = [], - cssProps = [], + classProps = [], }: WithClassNames) { const classes = twClassName ?? className ?? ""; const isComponent = classes.split(/\s+/).includes("component"); const allClasses = []; - for (const prop of [...propsToTransform, ...spreadProps, ...cssProps]) { + for (const prop of [...propsToTransform, ...spreadProps, ...classProps]) { if (typeof componentProps[prop] === "string") { allClasses.push(componentProps[prop]); } diff --git a/src/with-styled-props.ts b/src/with-styled-props.ts index e5d241a..21b7a90 100644 --- a/src/with-styled-props.ts +++ b/src/with-styled-props.ts @@ -11,8 +11,9 @@ export interface WithStyledPropsOptions { componentProps: Record; tw: UseTailwindCallback; spreadProps?: T[]; - cssProps?: T[]; + classProps?: T[]; preview: boolean; + supportsClassName: boolean; } export type WithStyledProps = Record & { @@ -27,14 +28,14 @@ export function withStyledProps({ styleProp, componentProps, spreadProps = [], - cssProps = [], + classProps = [], preview, }: WithStyledPropsOptions): WithStyledProps { const mainStyles = tw(classes, { flatten: false }); const styledProps: Partial> = {}; - for (const prop of cssProps) { + for (const prop of classProps) { const value = componentProps[prop]; if (typeof value === "string") { @@ -48,6 +49,7 @@ export function withStyledProps({ ).tailwindClassName; } else { const entries = Object.entries(tw(value, { flatten: true })); + if (entries.length > 0) { styledProps[prop] = undefined; for (const [key, value] of entries) {