rn-css 1.8.9 → 1.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +204 -222
- package/dist/styleComponent.d.ts +4 -4
- package/dist/styleComponent.js +2 -0
- package/package.json +1 -1
- package/src/styleComponent.tsx +10 -7
package/dist/styleComponent.d.ts
CHANGED
|
@@ -26,18 +26,18 @@ declare const styled: <StyleType, InitialProps extends {
|
|
|
26
26
|
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]): React.ForwardRefExoticComponent<Props & S & {
|
|
27
27
|
ref?: React.Ref<any> | undefined;
|
|
28
28
|
}>;
|
|
29
|
-
attrs<Part, Result extends Partial<Props & Part> = Partial<Props & Part>>(opts:
|
|
29
|
+
attrs<Part, Result extends Partial<Props & Part> = Partial<Props & Part>>(opts: Result | ((props: Props & Part) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Props & Part>)[]) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Omit<Props, keyof Result> & Part & Partial<Pick<Props, Extract<keyof Props, keyof Result>>>> & React.RefAttributes<any>>;
|
|
30
30
|
};
|
|
31
31
|
export default styled;
|
|
32
32
|
export declare const styledFlatList: {
|
|
33
33
|
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & FlatListProps<Type>) => JSX.Element;
|
|
34
|
-
attrs<S_1
|
|
34
|
+
attrs<S_1, Result extends Partial<S_1 & FlatListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & FlatListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<FlatListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
35
35
|
};
|
|
36
36
|
export declare const styledSectionList: {
|
|
37
37
|
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps>)[]): <Type>(props: S & OptionalProps & SectionListProps<Type, import("react-native").DefaultSectionT>) => JSX.Element;
|
|
38
|
-
attrs<S_1
|
|
38
|
+
attrs<S_1, Result extends Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & SectionListProps<any, import("react-native").DefaultSectionT>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<SectionListProps<Props, import("react-native").DefaultSectionT> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
39
39
|
};
|
|
40
40
|
export declare const styledVirtualizedList: {
|
|
41
41
|
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & VirtualizedListProps<Type>) => JSX.Element;
|
|
42
|
-
attrs<S_1
|
|
42
|
+
attrs<S_1, Result extends Partial<S_1 & VirtualizedListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & VirtualizedListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<VirtualizedListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
43
43
|
};
|
package/dist/styleComponent.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.styledVirtualizedList = exports.styledSectionList = exports.styledFlatList = exports.SharedValue = exports.FontSizeContext = exports.RemContext = exports.defaultUnits = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
7
8
|
/* eslint-disable react/prop-types */
|
|
8
9
|
/* eslint-disable react/display-name */
|
|
9
10
|
const react_1 = __importDefault(require("react"));
|
|
@@ -131,6 +132,7 @@ const styled = (Component) => {
|
|
|
131
132
|
// provide styled(Comp).attrs({} | () => {}) feature
|
|
132
133
|
styledComponent.attrs = (opts) => (chunks, ...functs) => {
|
|
133
134
|
const ComponentWithAttrs = styledComponent(chunks, ...functs);
|
|
135
|
+
// We need to limit the props control to only Result https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBATgUwIZTQUQB7ZgAmaRAwnALYAOAPAAopzUDOAfABQU0BciH1Jqz6NmLAJSIAvG0QYwAT0kBvAFCJkCFlET5CJYt2rT+gsSKETpstRo3ooIFEiMDL49YgC+nvWmL+5FTUAHRYUCgsJrQASmgsIAA2OmgEgVH0GCiwGIkMlmyc4ZF8cQnJkjKItnYQWjqMaHVgwDAA5k5YpEYmbua6eBCJICT5YgA0iGVJUGyVNp52iA5OLsEcyiFbZqyTW2FQESxeHks+SyvOiI3NrR0oXUE0nufLaI5XfgGGwao+qqBILAEIgen1hNVENhtHxtCgYGA2pNtApEmhYREEW1vCpPJckDsWH9VM1tNd0Ld2j0pMh0F0viQntQuMFxAcjhsofEoHwAORwADWvJxqhuCDurmUiBRaL50KgwpOQA
|
|
134
136
|
const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
|
|
135
137
|
const attrs = (opts instanceof Function) ? opts(props) : opts;
|
|
136
138
|
return react_1.default.createElement(ComponentWithAttrs, { ref: ref, ...props, ...attrs });
|
package/package.json
CHANGED
package/src/styleComponent.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
1
2
|
/* eslint-disable react/prop-types */
|
|
2
3
|
/* eslint-disable react/display-name */
|
|
3
4
|
import React, { MouseEvent } from 'react'
|
|
@@ -58,6 +59,7 @@ function removeStyle (hash: string) {
|
|
|
58
59
|
styleMap[hash].usage--
|
|
59
60
|
if (styleMap[hash].usage <= 0) delete styleMap[hash]
|
|
60
61
|
}
|
|
62
|
+
|
|
61
63
|
const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }, Props extends InitialProps & OptionalProps = InitialProps & OptionalProps>(Component: React.ComponentType<InitialProps>) => {
|
|
62
64
|
const styledComponent = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]) => {
|
|
63
65
|
const ForwardRefComponent = React.forwardRef<any, S & Props>((props: S & Props, ref) => {
|
|
@@ -148,11 +150,12 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
// provide styled(Comp).attrs({} | () => {}) feature
|
|
151
|
-
styledComponent.attrs = <Part, Result extends Partial<Props & Part> = Partial<Props & Part>>(opts:
|
|
153
|
+
styledComponent.attrs = <Part, Result extends Partial<Props & Part> = Partial<Props & Part>>(opts: Result | ((props: Props & Part) => Result)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Props & Part>)[]) => {
|
|
152
154
|
const ComponentWithAttrs = styledComponent(chunks, ...functs)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
// We need to limit the props control to only Result https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBATgUwIZTQUQB7ZgAmaRAwnALYAOAPAAopzUDOAfABQU0BciH1Jqz6NmLAJSIAvG0QYwAT0kBvAFCJkCFlET5CJYt2rT+gsSKETpstRo3ooIFEiMDL49YgC+nvWmL+5FTUAHRYUCgsJrQASmgsIAA2OmgEgVH0GCiwGIkMlmyc4ZF8cQnJkjKItnYQWjqMaHVgwDAA5k5YpEYmbua6eBCJICT5YgA0iGVJUGyVNp52iA5OLsEcyiFbZqyTW2FQESxeHks+SyvOiI3NrR0oXUE0nufLaI5XfgGGwao+qqBILAEIgen1hNVENhtHxtCgYGA2pNtApEmhYREEW1vCpPJckDsWH9VM1tNd0Ld2j0pMh0F0viQntQuMFxAcjhsofEoHwAORwADWvJxqhuCDurmUiBRaL50KgwpOQA
|
|
156
|
+
const ForwardRefComponent = React.forwardRef<any, Omit<Props, keyof Result> & Part & Partial<Pick<Props, Extract<keyof Props, keyof Result>>>>((props, ref) => {
|
|
157
|
+
const attrs = (opts instanceof Function) ? opts(props as Props & Part) : opts
|
|
158
|
+
return <ComponentWithAttrs ref={ref} {...(props as Props & Part)} {...attrs} />
|
|
156
159
|
})
|
|
157
160
|
// TODO : Find a way to remove from the Props the properties affected by opts
|
|
158
161
|
return ForwardRefComponent
|
|
@@ -164,11 +167,11 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
164
167
|
export default styled
|
|
165
168
|
|
|
166
169
|
export const styledFlatList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any> & OptionalProps>)[]) => <Type, >(props: S & OptionalProps & FlatListProps<Type>) => invoke(styled<ViewStyle, FlatListProps<Type>>(FlatList)(chunks, ...functs), props)
|
|
167
|
-
styledFlatList.attrs = <S,
|
|
170
|
+
styledFlatList.attrs = <S, Result extends Partial<S & FlatListProps<any> & OptionalProps> = {} > (opts: Result | ((props: S & OptionalProps & FlatListProps<any>) => Result)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Props, >(componentProps: Omit<FlatListProps<Props> & OptionalProps, keyof Result> & S & Partial<Result>) => invoke(styled<ViewStyle, FlatListProps<Props>>(FlatList).attrs<S>(opts)(chunks, ...functs), componentProps as any)
|
|
168
171
|
export const styledSectionList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any> & OptionalProps>)[]) => <Type, >(props: S & OptionalProps & SectionListProps<Type>) => invoke(styled<ViewStyle, SectionListProps<Type>>(SectionList)(chunks, ...functs), props)
|
|
169
|
-
styledSectionList.attrs = <S,
|
|
172
|
+
styledSectionList.attrs = <S, Result extends Partial<S & SectionListProps<any> & OptionalProps> = {} >(opts: Result | ((props: S & OptionalProps & SectionListProps<any>) => Result)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Props, >(componentProps: Omit<SectionListProps<Props> & OptionalProps, keyof Result> & S & Partial<Result>) => invoke(styled<ViewStyle, SectionListProps<Props>>(SectionList).attrs<S>(opts)(chunks, ...functs), componentProps as any)
|
|
170
173
|
export const styledVirtualizedList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any> & OptionalProps>)[]) => <Type, >(props: S & OptionalProps & VirtualizedListProps<Type>) => invoke(styled<ViewStyle, VirtualizedListProps<Type>>(VirtualizedList)(chunks, ...functs), props)
|
|
171
|
-
styledVirtualizedList.attrs = <S,
|
|
174
|
+
styledVirtualizedList.attrs = <S, Result extends Partial<S & VirtualizedListProps<any> & OptionalProps> = {} >(opts: Result | ((props: S & OptionalProps & VirtualizedListProps<any>) => Result)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Props, >(componentProps: Omit<VirtualizedListProps<Props> & OptionalProps, keyof Result> & S & Partial<Result>) => invoke(styled<ViewStyle, VirtualizedListProps<Props>>(VirtualizedList).attrs<S>(opts)(chunks, ...functs), componentProps as any)
|
|
172
175
|
|
|
173
176
|
function invoke<T> (Component: React.ComponentType<T>, props: T) {
|
|
174
177
|
return <Component {...props} />
|