mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-15 10:17:54 +08:00
fix: ensure StyledProps are exported
This commit is contained in:
@@ -2,6 +2,7 @@ export * from "./provider";
|
||||
export * from "./use-tailwind";
|
||||
export * from "./styled";
|
||||
export * from "./styled-component";
|
||||
export type { StyledProps } from "./utils/styled";
|
||||
export { useColorScheme } from "./context/color-scheme";
|
||||
export { useComponent, ComponentContext } from "./context/component";
|
||||
export { usePlatform } from "./context/platform";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as React from "react";
|
||||
import { styled } from "./styled";
|
||||
import { Component, StyledProps } from "./utils/styled";
|
||||
import { StyledProps } from "./utils/styled";
|
||||
|
||||
export type StyledComponentProps<P> = StyledProps<P> & {
|
||||
component: Component<P>;
|
||||
component: React.ComponentType<P>;
|
||||
};
|
||||
|
||||
export function StyledComponent<P>({
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { ComponentProps, createElement, FC } from "react";
|
||||
import { Component, StyledProps, StyledPropsWithKeys } from "./utils/styled";
|
||||
import {
|
||||
ComponentProps,
|
||||
createElement,
|
||||
FC,
|
||||
ReactNode,
|
||||
ComponentType,
|
||||
} from "react";
|
||||
import { StyledProps, StyledPropsWithKeys } from "./utils/styled";
|
||||
import { ComponentContext } from "./context/component";
|
||||
import { useInteraction } from "./use-interaction";
|
||||
import { withStyledChildren } from "./with-styled-children";
|
||||
@@ -7,6 +13,7 @@ import { withStyledProps } from "./with-styled-props";
|
||||
import { useTailwind } from "./use-tailwind";
|
||||
import { withClassNames } from "./with-class-names";
|
||||
import { usePlatform } from "./context/platform";
|
||||
import { StyleProp } from "react-native";
|
||||
|
||||
export interface StyledOptions<P> {
|
||||
props?: Array<keyof P & string>;
|
||||
@@ -19,21 +26,23 @@ export interface StyledOptions<P> {
|
||||
* Normal usage
|
||||
*/
|
||||
export function styled<T>(
|
||||
Component: Component<T>,
|
||||
Component: ComponentType<T>,
|
||||
options?: { props?: undefined; spreadProps?: undefined }
|
||||
): FC<StyledProps<T>>;
|
||||
/**
|
||||
* With either props or valueProps
|
||||
*/
|
||||
export function styled<T, K extends keyof T & string>(
|
||||
Component: Component<T>,
|
||||
Component: ComponentType<T>,
|
||||
options: { props?: Array<K>; spreadProps?: Array<K>; classProps?: Array<K> }
|
||||
): FC<StyledPropsWithKeys<T, K>>;
|
||||
/**
|
||||
* Actual implementation
|
||||
*/
|
||||
export function styled<T>(
|
||||
Component: Component<T>,
|
||||
export function styled<
|
||||
T extends { style?: StyleProp<unknown>; children?: ReactNode | undefined }
|
||||
>(
|
||||
Component: ComponentType<T>,
|
||||
{
|
||||
props: propsToTransform,
|
||||
spreadProps,
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
import { ComponentType, PropsWithChildren } from "react";
|
||||
import { ImageStyle, StyleProp, TextStyle, ViewStyle } from "react-native";
|
||||
export type StyledProps<P> = P & {
|
||||
className?: string;
|
||||
tw?: string;
|
||||
};
|
||||
|
||||
export type Component<P> = ComponentType<P>;
|
||||
|
||||
export type InferStyle<T> = T extends { style?: StyleProp<infer S> }
|
||||
? S & (ViewStyle | TextStyle | ImageStyle)
|
||||
: never;
|
||||
|
||||
export type StyledProps<P, T = InferStyle<P>> = PropsWithChildren<
|
||||
P & {
|
||||
className?: string;
|
||||
tw?: string;
|
||||
style?: StyleProp<T | RWNCssStyle>;
|
||||
}
|
||||
>;
|
||||
|
||||
export type StyledPropsWithKeys<P, K extends keyof P> = PropsWithChildren<
|
||||
P & {
|
||||
className?: string;
|
||||
tw?: string;
|
||||
style?: StyleProp<InferStyle<P> | RWNCssStyle>;
|
||||
} & { [key in K]: P[key] | string }
|
||||
>;
|
||||
export type StyledPropsWithKeys<P, K extends keyof P> = P & {
|
||||
className?: string;
|
||||
tw?: string;
|
||||
} & { [key in K]: P[key] | string };
|
||||
|
||||
export type RWNCssStyle = {
|
||||
$$css: true;
|
||||
|
||||
Reference in New Issue
Block a user