rn-css 1.8.4 → 1.8.6

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.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);
@@ -1,6 +1,6 @@
1
1
  import React, { MouseEvent } from 'react';
2
- import { Animated, FlatListProps, LayoutChangeEvent, SectionListProps, StyleProp, VirtualizedListProps } from 'react-native';
3
- import type { AnyStyle, CompleteStyle, Units } from './types';
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<T extends AnyStyle | Animated.WithAnimatedValue<AnyStyle> = AnyStyle> = {
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: <Props, StyleType extends AnyStyle | Animated.WithAnimatedObject<import("react-native").ViewStyle> | Animated.WithAnimatedObject<import("react-native").TextStyle> | Animated.WithAnimatedObject<import("react-native").ImageStyle> = AnyStyle>(Component: React.ComponentType<Props>) => {
25
- <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]): React.ForwardRefExoticComponent<Props & S & OptionalProps<StyleType> & {
26
- ref?: React.Ref<any> | undefined;
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, Result extends Partial<Part & Props> = Partial<Part & Props>>(opts: Result | ((props: Part & Props) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Part & Props>)[]) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Exclude<Props & Part, Result> & Partial<Props & Part>> & React.RefAttributes<React.ComponentType<Props & Part>>>;
31
30
  };
32
31
  export default styled;
33
32
  export declare const styledFlatList: {
34
- <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & FlatListProps<Type> & OptionalProps<AnyStyle>) => JSX.Element;
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 & FlatListProps<Props> & OptionalProps<AnyStyle>) => JSX.Element;
33
+ <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & FlatListProps<Type>) => JSX.Element;
34
+ attrs<S_1>(opts: (S_1 & FlatListProps<any> & OptionalProps) | ((props: S_1 & FlatListProps<any> & OptionalProps) => Partial<S_1 & OptionalProps & FlatListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & OptionalProps & 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> & OptionalProps<AnyStyle>) => JSX.Element;
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> & OptionalProps<AnyStyle>) => JSX.Element;
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>(opts: (S_1 & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps) | ((props: S_1 & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps) => Partial<S_1 & OptionalProps & 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 & VirtualizedListProps<Type> & OptionalProps<AnyStyle>) => JSX.Element;
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 & VirtualizedListProps<Props> & OptionalProps<AnyStyle>) => JSX.Element;
41
+ <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & VirtualizedListProps<Type>) => JSX.Element;
42
+ attrs<S_1>(opts: (S_1 & VirtualizedListProps<any> & OptionalProps) | ((props: S_1 & VirtualizedListProps<any> & OptionalProps) => Partial<S_1 & OptionalProps & 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
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 = <T, >(Component: React.ComponentType<T>) => styledComponent<T, AnyStyle | RN.Animated.WithAnimatedValue<AnyStyle>>(Component)
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)
@@ -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 { Animated, FlatList, FlatListProps, LayoutChangeEvent, Platform, SectionList, SectionListProps, StyleProp, StyleSheet, VirtualizedList, VirtualizedListProps } from 'react-native'
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<T extends AnyStyle | Animated.WithAnimatedValue<AnyStyle> = AnyStyle> = {
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 = <Props, StyleType extends AnyStyle | Animated.WithAnimatedValue<AnyStyle> = AnyStyle>(Component: React.ComponentType<Props>) => {
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 & OptionalProps<StyleType>>, S & Props & OptionalProps<StyleType>>((props: S & Props & OptionalProps<StyleType>, ref) => {
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: OptionalProps<StyleType> = { style: [styleConvertedFromCSS as StyleType, props.style], onMouseEnter, onMouseLeave, onLayout }
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 & OptionalProps<StyleType> & { ref?: React.Ref<any> }>
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 = <S, >(opts: Partial<S & Props> | ((props: S & Props) => Partial<S & Props>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]) => {
151
+ styledComponent.attrs = <Part, Result extends Partial<Part & Props> = Partial<Part & Props>>(opts: Result | ((props: Part & Props) => Result)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<Part & Props>)[]) => {
153
152
  const ComponentWithAttrs = styledComponent(chunks, ...functs)
154
- const ForwardRefComponent = React.forwardRef<typeof Component, S & Props>((props: Props & S, ref) => {
153
+ const ForwardRefComponent = React.forwardRef<React.ComponentType<Props & Part>, Exclude<Props & Part, Result> & Partial<Props & Part>>((props, ref) => {
155
154
  const attrs = (opts instanceof Function) ? opts(props) : opts
156
155
  return <ComponentWithAttrs ref={ref} {...props} {...attrs} />
157
156
  })
158
157
  // TODO : Find a way to remove from the Props the properties affected by opts
159
- return ForwardRefComponent as React.ForwardRefExoticComponent<(Props | S) & OptionalProps<StyleType> & { ref?: React.Ref<any> }>
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> & OptionalProps) => invoke(styled<FlatListProps<Type>>(FlatList)(chunks, ...functs), props)
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> & OptionalProps) => invoke(styled<FlatListProps<Props>>(FlatList).attrs<S & FlatListProps<Props>>(opts)(chunks, ...functs), componentProps)
169
- export const styledSectionList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & SectionListProps<Type> & OptionalProps) => invoke(styled<SectionListProps<Type>>(SectionList)(chunks, ...functs), props)
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> & OptionalProps) => invoke(styled<SectionListProps<Props>>(SectionList).attrs<S & SectionListProps<Props>>(opts)(chunks, ...functs), componentProps as any)
171
- export const styledVirtualizedList = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]) => <Type, >(props: S & VirtualizedListProps<Type> & OptionalProps) => invoke(styled<VirtualizedListProps<Type>>(VirtualizedList)(chunks, ...functs), props)
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> & OptionalProps) => invoke(styled<VirtualizedListProps<Props>>(VirtualizedList).attrs<S & VirtualizedListProps<Props>>(opts)(chunks, ...functs), componentProps)
166
+ 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, >(opts: S & FlatListProps<any> & OptionalProps | ((props: S & FlatListProps<any> & OptionalProps) => Partial<S & OptionalProps & FlatListProps<any>>)) => (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & OptionalProps & FlatListProps<any>>)[]) => <Props, >(componentProps: S & OptionalProps & FlatListProps<Props>) => invoke(styled<ViewStyle, FlatListProps<Props>>(FlatList).attrs<S>(opts)(chunks, ...functs), componentProps as any)
168
+ 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, >(opts: S & SectionListProps<any> & OptionalProps | ((props: S & SectionListProps<any> & OptionalProps) => Partial<S & OptionalProps & 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)(chunks, ...functs), componentProps as any)
170
+ 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, >(opts: S & VirtualizedListProps<any> & OptionalProps | ((props: S & VirtualizedListProps<any> & OptionalProps) => Partial<S & OptionalProps & 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)(chunks, ...functs), componentProps as any)
173
172
 
174
173
  function invoke<T> (Component: React.ComponentType<T>, props: T) {
175
174
  return <Component {...props} />