rn-css 1.8.3 → 1.8.5
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 +894 -413
- package/dist/index.js +0 -2
- package/dist/styleComponent.d.ts +14 -15
- package/package.json +1 -1
- package/src/index.tsx +1 -4
- package/src/styleComponent.tsx +16 -17
package/dist/index.js
CHANGED
|
@@ -35,7 +35,6 @@ Object.defineProperty(exports, "RemContext", { enumerable: true, get: function (
|
|
|
35
35
|
__exportStar(require("./useTheme"), exports);
|
|
36
36
|
const styled = (Component) => (0, styleComponent_1.default)(Component);
|
|
37
37
|
styled.ActivityIndicator = styled(RN.ActivityIndicator);
|
|
38
|
-
styled.Button = styled(RN.Button);
|
|
39
38
|
styled.DrawerLayoutAndroid = styled(RN.DrawerLayoutAndroid);
|
|
40
39
|
styled.Image = styled(RN.Image);
|
|
41
40
|
styled.ImageBackground = styled(RN.ImageBackground);
|
|
@@ -48,7 +47,6 @@ styled.Switch = styled(RN.Switch);
|
|
|
48
47
|
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView);
|
|
49
48
|
styled.RefreshControl = styled(RN.RefreshControl);
|
|
50
49
|
styled.SafeAreaView = styled(RN.SafeAreaView);
|
|
51
|
-
styled.StatusBar = styled(RN.StatusBar);
|
|
52
50
|
styled.Text = styled(RN.Text);
|
|
53
51
|
styled.TextInput = styled(RN.TextInput);
|
|
54
52
|
styled.TouchableHighlight = styled(RN.TouchableHighlight);
|
package/dist/styleComponent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { MouseEvent } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import { FlatListProps, LayoutChangeEvent, SectionListProps, StyleProp, VirtualizedListProps } from 'react-native';
|
|
3
|
+
import type { CompleteStyle, Units } from './types';
|
|
4
4
|
export declare const defaultUnits: Units;
|
|
5
5
|
export declare const RemContext: React.Context<number>;
|
|
6
6
|
export declare const FontSizeContext: React.Context<number>;
|
|
@@ -13,32 +13,31 @@ declare type Functs<T> = (arg: T & {
|
|
|
13
13
|
shared: unknown;
|
|
14
14
|
theme: DefaultTheme;
|
|
15
15
|
}) => Primitive;
|
|
16
|
-
declare type OptionalProps
|
|
16
|
+
declare type OptionalProps = {
|
|
17
17
|
rnCSS?: `${string};`;
|
|
18
18
|
onMouseEnter?: (event: MouseEvent) => void;
|
|
19
19
|
onMouseLeave?: (event: MouseEvent) => void;
|
|
20
20
|
onLayout?: (event: LayoutChangeEvent) => void;
|
|
21
21
|
children?: React.ReactNode;
|
|
22
|
-
style?: StyleProp<T>;
|
|
23
22
|
};
|
|
24
|
-
declare const styled: <
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
attrs<S_1>(opts: Partial<S_1 & Props> | ((props: S_1 & Props) => Partial<S_1 & Props>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & Props>)[]) => React.ForwardRefExoticComponent<(Props | S_1) & OptionalProps<StyleType> & {
|
|
23
|
+
declare const styled: <StyleType, InitialProps extends {
|
|
24
|
+
style?: StyleProp<StyleType>;
|
|
25
|
+
}, Props extends InitialProps & OptionalProps = InitialProps & OptionalProps>(Component: React.ComponentType<InitialProps>) => {
|
|
26
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]): React.ForwardRefExoticComponent<Props & S & {
|
|
29
27
|
ref?: React.Ref<any> | undefined;
|
|
30
28
|
}>;
|
|
29
|
+
attrs<Part extends Partial<Props>>(opts: Part | ((props: Props) => Part)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Props>)[]) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Exclude<Props, Part> & Partial<Part>> & React.RefAttributes<React.ComponentType<Props>>>;
|
|
31
30
|
};
|
|
32
31
|
export default styled;
|
|
33
32
|
export declare const styledFlatList: {
|
|
34
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S &
|
|
35
|
-
attrs<S_1>(opts: Partial<S_1 & FlatListProps<any>> | ((props: S_1 & FlatListProps<any>) => Partial<S_1 & FlatListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & FlatListProps<any>>)[]) => <Props>(componentProps: S_1 &
|
|
33
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & OptionalProps & FlatListProps<Type>) => JSX.Element;
|
|
34
|
+
attrs<S_1>(opts: Partial<S_1 & FlatListProps<any>> | ((props: S_1 & FlatListProps<any>) => Partial<S_1 & FlatListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & FlatListProps<any>>)[]) => <Props>(componentProps: S_1 & OptionalProps & FlatListProps<Props>) => JSX.Element;
|
|
36
35
|
};
|
|
37
36
|
export declare const styledSectionList: {
|
|
38
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & SectionListProps<Type, import("react-native").DefaultSectionT>
|
|
39
|
-
attrs<S_1>(opts: Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>> | ((props: S_1 & SectionListProps<any, import("react-native").DefaultSectionT>) => Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)[]) => <Props>(componentProps: S_1 & SectionListProps<Props, import("react-native").DefaultSectionT>
|
|
37
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & OptionalProps & SectionListProps<Type, import("react-native").DefaultSectionT>) => JSX.Element;
|
|
38
|
+
attrs<S_1>(opts: Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>> | ((props: S_1 & SectionListProps<any, import("react-native").DefaultSectionT>) => Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)[]) => <Props>(componentProps: S_1 & OptionalProps & SectionListProps<Props, import("react-native").DefaultSectionT>) => JSX.Element;
|
|
40
39
|
};
|
|
41
40
|
export declare const styledVirtualizedList: {
|
|
42
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S &
|
|
43
|
-
attrs<S_1>(opts: Partial<S_1 & VirtualizedListProps<any>> | ((props: S_1 & VirtualizedListProps<any>) => Partial<S_1 & VirtualizedListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & VirtualizedListProps<any>>)[]) => <Props>(componentProps: S_1 &
|
|
41
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & OptionalProps & VirtualizedListProps<Type>) => JSX.Element;
|
|
42
|
+
attrs<S_1>(opts: Partial<S_1 & VirtualizedListProps<any>> | ((props: S_1 & VirtualizedListProps<any>) => Partial<S_1 & VirtualizedListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & VirtualizedListProps<any>>)[]) => <Props>(componentProps: S_1 & OptionalProps & VirtualizedListProps<Props>) => JSX.Element;
|
|
44
43
|
};
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -2,15 +2,13 @@ import React from 'react'
|
|
|
2
2
|
import * as RN from 'react-native'
|
|
3
3
|
import './polyfill'
|
|
4
4
|
import styledComponent, { styledFlatList, styledSectionList, styledVirtualizedList } from './styleComponent'
|
|
5
|
-
import { AnyStyle } from './types'
|
|
6
5
|
export { cssToRNStyle } from './cssToRN'
|
|
7
6
|
export { SharedValue, FontSizeContext, RemContext, DefaultTheme } from './styleComponent'
|
|
8
7
|
export * from './useTheme'
|
|
9
8
|
|
|
10
|
-
const styled = <
|
|
9
|
+
const styled = <StyleType, InitialProps extends { style?: RN.StyleProp<StyleType> }>(Component: React.ComponentType<InitialProps>) => styledComponent<StyleType, InitialProps>(Component)
|
|
11
10
|
|
|
12
11
|
styled.ActivityIndicator = styled(RN.ActivityIndicator)
|
|
13
|
-
styled.Button = styled(RN.Button)
|
|
14
12
|
styled.DrawerLayoutAndroid = styled(RN.DrawerLayoutAndroid)
|
|
15
13
|
styled.Image = styled(RN.Image)
|
|
16
14
|
styled.ImageBackground = styled(RN.ImageBackground)
|
|
@@ -23,7 +21,6 @@ styled.Switch = styled(RN.Switch)
|
|
|
23
21
|
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView)
|
|
24
22
|
styled.RefreshControl = styled(RN.RefreshControl)
|
|
25
23
|
styled.SafeAreaView = styled(RN.SafeAreaView)
|
|
26
|
-
styled.StatusBar = styled(RN.StatusBar)
|
|
27
24
|
styled.Text = styled(RN.Text)
|
|
28
25
|
styled.TextInput = styled(RN.TextInput)
|
|
29
26
|
styled.TouchableHighlight = styled(RN.TouchableHighlight)
|
package/src/styleComponent.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
/* eslint-disable react/display-name */
|
|
3
3
|
import React, { MouseEvent } from 'react'
|
|
4
|
-
import {
|
|
4
|
+
import { FlatList, FlatListProps, LayoutChangeEvent, Platform, SectionList, SectionListProps, StyleProp, StyleSheet, ViewStyle, VirtualizedList, VirtualizedListProps } from 'react-native'
|
|
5
5
|
import convertStyle from './convertStyle'
|
|
6
6
|
import cssToStyle from './cssToRN'
|
|
7
7
|
import { useFontSize, useHover, useLayout, useScreenSize, useMediaQuery } from './features'
|
|
@@ -21,13 +21,12 @@ export interface DefaultTheme {}
|
|
|
21
21
|
|
|
22
22
|
type Primitive = number | string | null | undefined | boolean | CompleteStyle
|
|
23
23
|
type Functs<T> = (arg: T & { rnCSS?: string; shared: unknown, theme: DefaultTheme }) => Primitive
|
|
24
|
-
type OptionalProps
|
|
24
|
+
type OptionalProps = {
|
|
25
25
|
rnCSS?: `${string};`;
|
|
26
26
|
onMouseEnter?: (event: MouseEvent) => void;
|
|
27
27
|
onMouseLeave?: (event: MouseEvent) => void;
|
|
28
28
|
onLayout?: (event: LayoutChangeEvent) => void
|
|
29
29
|
children?: React.ReactNode;
|
|
30
|
-
style?: StyleProp<T>;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
/** Converts the tagged template string into a css string */
|
|
@@ -59,9 +58,9 @@ function removeStyle (hash: string) {
|
|
|
59
58
|
styleMap[hash].usage--
|
|
60
59
|
if (styleMap[hash].usage <= 0) delete styleMap[hash]
|
|
61
60
|
}
|
|
62
|
-
const styled = <
|
|
61
|
+
const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }, Props extends InitialProps & OptionalProps = InitialProps & OptionalProps>(Component: React.ComponentType<InitialProps>) => {
|
|
63
62
|
const styledComponent = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]) => {
|
|
64
|
-
const ForwardRefComponent = React.forwardRef<React.ComponentType<S & Props
|
|
63
|
+
const ForwardRefComponent = React.forwardRef<React.ComponentType<S & Props>, S & Props>((props: S & Props, ref) => {
|
|
65
64
|
const rem = React.useContext(RemContext)
|
|
66
65
|
const shared = React.useContext(SharedValue)
|
|
67
66
|
// Build the css string with the context
|
|
@@ -126,7 +125,7 @@ const styled = <Props, StyleType extends AnyStyle | Animated.WithAnimatedValue<A
|
|
|
126
125
|
return { style: getStyle<CompleteStyle>(hash, style), hash }
|
|
127
126
|
}, [finalStyle, units])
|
|
128
127
|
const newProps = React.useMemo(() => {
|
|
129
|
-
const newProps
|
|
128
|
+
const newProps = { style: [styleConvertedFromCSS as StyleType, props.style], onMouseEnter, onMouseLeave, onLayout }
|
|
130
129
|
if (finalStyle.textOverflow === 'ellipsis') {
|
|
131
130
|
Object.assign(newProps, { numberOfLines: 1 })
|
|
132
131
|
}
|
|
@@ -145,18 +144,18 @@ const styled = <Props, StyleType extends AnyStyle | Animated.WithAnimatedValue<A
|
|
|
145
144
|
return <Component ref={ref} {...props} {...newProps} />
|
|
146
145
|
}
|
|
147
146
|
})
|
|
148
|
-
return ForwardRefComponent as React.ForwardRefExoticComponent<Props & S &
|
|
147
|
+
return ForwardRefComponent as React.ForwardRefExoticComponent<Props & S & { ref?: React.Ref<any> }>
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
// provide styled(Comp).attrs({} | () => {}) feature
|
|
152
|
-
styledComponent.attrs = <
|
|
151
|
+
styledComponent.attrs = <Part extends Partial<Props>, >(opts: Part | ((props: Props) => Part)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Props>)[]) => {
|
|
153
152
|
const ComponentWithAttrs = styledComponent(chunks, ...functs)
|
|
154
|
-
const ForwardRefComponent = React.forwardRef<
|
|
153
|
+
const ForwardRefComponent = React.forwardRef<React.ComponentType<Props>, Exclude<Props, Part> & Partial<Part>>((props, ref) => {
|
|
155
154
|
const attrs = (opts instanceof Function) ? opts(props) : opts
|
|
156
|
-
return <ComponentWithAttrs ref={ref} {...props} {...attrs} />
|
|
155
|
+
return <ComponentWithAttrs ref={ref} {...(props as Props)} {...attrs} />
|
|
157
156
|
})
|
|
158
157
|
// TODO : Find a way to remove from the Props the properties affected by opts
|
|
159
|
-
return ForwardRefComponent
|
|
158
|
+
return ForwardRefComponent
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
return styledComponent
|
|
@@ -164,12 +163,12 @@ const styled = <Props, StyleType extends AnyStyle | Animated.WithAnimatedValue<A
|
|
|
164
163
|
|
|
165
164
|
export default styled
|
|
166
165
|
|
|
167
|
-
export const styledFlatList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & FlatListProps<Type>
|
|
168
|
-
styledFlatList.attrs = <S, >(opts: Partial<S & FlatListProps<any>> | ((props: S & FlatListProps<any>) => Partial<S & FlatListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any>>)[]) => <Props, >(componentProps: S & FlatListProps<Props>
|
|
169
|
-
export const styledSectionList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & SectionListProps<Type>
|
|
170
|
-
styledSectionList.attrs = <S, >(opts: Partial<S & SectionListProps<any>> | ((props: S & SectionListProps<any>) => Partial<S & SectionListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any>>)[]) => <Props, >(componentProps: S & SectionListProps<Props>
|
|
171
|
-
export const styledVirtualizedList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & VirtualizedListProps<Type>
|
|
172
|
-
styledVirtualizedList.attrs = <S, >(opts: Partial<S & VirtualizedListProps<any>> | ((props: S & VirtualizedListProps<any>) => Partial<S & VirtualizedListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any>>)[]) => <Props, >(componentProps: S & VirtualizedListProps<Props>
|
|
166
|
+
export const styledFlatList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & OptionalProps & FlatListProps<Type>) => invoke(styled<ViewStyle, FlatListProps<Type>>(FlatList)(chunks, ...functs), props)
|
|
167
|
+
styledFlatList.attrs = <S, >(opts: Partial<S & FlatListProps<any>> | ((props: S & FlatListProps<any>) => Partial<S & FlatListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any>>)[]) => <Props, >(componentProps: S & OptionalProps & FlatListProps<Props>) => invoke(styled<ViewStyle, FlatListProps<Props>>(FlatList).attrs<S>(opts as S)(chunks, ...functs as (Primitive | Functs<FlatListProps<Props>>)[]), componentProps as any)
|
|
168
|
+
export const styledSectionList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & OptionalProps & SectionListProps<Type>) => invoke(styled<ViewStyle, SectionListProps<Type>>(SectionList)(chunks, ...functs), props)
|
|
169
|
+
styledSectionList.attrs = <S, >(opts: Partial<S & SectionListProps<any>> | ((props: S & SectionListProps<any>) => Partial<S & SectionListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any>>)[]) => <Props, >(componentProps: S & OptionalProps & SectionListProps<Props>) => invoke(styled<ViewStyle, SectionListProps<Props>>(SectionList).attrs<S>(opts as S)(chunks, ...functs as (Primitive | Functs<SectionListProps<Props>>)[]), componentProps as any)
|
|
170
|
+
export const styledVirtualizedList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & OptionalProps & VirtualizedListProps<Type>) => invoke(styled<ViewStyle, VirtualizedListProps<Type>>(VirtualizedList)(chunks, ...functs), props)
|
|
171
|
+
styledVirtualizedList.attrs = <S, >(opts: Partial<S & VirtualizedListProps<any>> | ((props: S & VirtualizedListProps<any>) => Partial<S & VirtualizedListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any>>)[]) => <Props, >(componentProps: S & OptionalProps & VirtualizedListProps<Props>) => invoke(styled<ViewStyle, VirtualizedListProps<Props>>(VirtualizedList).attrs<S>(opts as S)(chunks, ...functs as (Primitive | Functs<VirtualizedListProps<Props>>)[]), componentProps as any)
|
|
173
172
|
|
|
174
173
|
function invoke<T> (Component: React.ComponentType<T>, props: T) {
|
|
175
174
|
return <Component {...props} />
|