Skip to content

Commit d6f42ab

Browse files
authored
fix: make styled mapping optional (#206)
1 parent 3fbb6ad commit d6f42ab

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/native/api.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import { useContext, useState } from "react";
2+
import { useContext, useState, type ComponentType } from "react";
33
import { Appearance } from "react-native";
44

55
import type { StyleDescriptor } from "react-native-css/compiler";
@@ -30,6 +30,10 @@ export {
3030

3131
export { useNativeCss };
3232

33+
const defaultMapping: StyledConfiguration<ComponentType<{ style: unknown }>> = {
34+
className: "style",
35+
};
36+
3337
/**
3438
* Generates a new Higher-Order component the wraps the base component and applies the styles.
3539
* This is added to the `interopComponents` map so that it can be used in the `wrapJSX` function
@@ -41,7 +45,7 @@ export const styled = <
4145
const M extends StyledConfiguration<C>,
4246
>(
4347
baseComponent: C,
44-
mapping: M,
48+
mapping: M = defaultMapping as M,
4549
options?: StyledOptions,
4650
) => {
4751
let component: any;

src/web/api.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
createElement,
33
useMemo,
44
type ComponentPropsWithRef,
5+
type ComponentType,
56
type PropsWithChildren,
67
} from "react";
78
import { Appearance } from "react-native";
@@ -17,12 +18,16 @@ import type {
1718
import type { ReactComponent } from "../runtime.types";
1819
import { assignStyle } from "./assign-style";
1920

21+
const defaultMapping: StyledConfiguration<ComponentType<{ style: unknown }>> = {
22+
className: "style",
23+
};
24+
2025
export const styled = <
2126
const C extends ReactComponent,
2227
const M extends StyledConfiguration<C>,
2328
>(
2429
baseComponent: C,
25-
mapping: M,
30+
mapping: M = defaultMapping as M,
2631
_options?: StyledOptions,
2732
) => {
2833
return (props: StyledProps<ComponentPropsWithRef<C>, M>) => {

0 commit comments

Comments
 (0)