rn-css 2.0.2 → 2.1.0

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.
@@ -17,7 +17,7 @@ function convertValue(key, value, units) {
17
17
  return 0;
18
18
  }
19
19
  // colors should be left untouched
20
- if (value.startsWith('#'))
20
+ if (value.startsWith('#') || value.startsWith('linear-gradient'))
21
21
  return value;
22
22
  // Percentage values need to rely on an other unit as reference
23
23
  const finalUnits = { ...units };
@@ -136,7 +136,9 @@ function placeContent(value) {
136
136
  exports.placeContent = placeContent;
137
137
  function background(value) {
138
138
  const values = value.match(/(linear-gradient\(|url\().*?\)|[^\s]+/mg) || [];
139
- const backgroundColor = values.reverse().find(isColor) || 'transparent';
139
+ const backgroundColor = values.reverse().find(isColor) ||
140
+ (values[0]?.startsWith('linear-gradient') && values[0].split(',').map(val => val.trim()).find(isColor)) ||
141
+ 'transparent';
140
142
  // We support everything on web
141
143
  return react_native_1.Platform.OS === 'web' ? { backgroundColor, background: value } : { backgroundColor };
142
144
  }
@@ -160,7 +160,7 @@ const styled = (Component) => {
160
160
  const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
161
161
  const castProps = props;
162
162
  const attrs = (opts instanceof Function) ? opts(castProps) : opts;
163
- return react_1.default.createElement(ComponentWithAttrs, { ref: ref, ...castProps, ...attrs });
163
+ return react_1.default.createElement(ComponentWithAttrs, { ref: ref, ...attrs, ...castProps });
164
164
  });
165
165
  // TODO : Find a way to remove from the Props the properties affected by opts
166
166
  return ForwardRefComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js",
@@ -16,7 +16,7 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
16
16
  return 0
17
17
  }
18
18
  // colors should be left untouched
19
- if (value.startsWith('#')) return value
19
+ if (value.startsWith('#') || value.startsWith('linear-gradient')) return value
20
20
 
21
21
  // Percentage values need to rely on an other unit as reference
22
22
  const finalUnits = { ...units }
@@ -119,7 +119,9 @@ export function placeContent (value: string) {
119
119
 
120
120
  export function background (value: string) {
121
121
  const values = value.match(/(linear-gradient\(|url\().*?\)|[^\s]+/mg) || []
122
- const backgroundColor = values.reverse().find(isColor) || 'transparent'
122
+ const backgroundColor = values.reverse().find(isColor) ||
123
+ (values[0]?.startsWith('linear-gradient') && values[0].split(',').map(val => val.trim()).find(isColor)) ||
124
+ 'transparent'
123
125
  // We support everything on web
124
126
  return Platform.OS === 'web' ? { backgroundColor, background: value } : { backgroundColor }
125
127
  }
@@ -189,7 +189,7 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
189
189
  const ForwardRefComponent = React.forwardRef<any, Omit<Props, keyof Result> & Part & Partial<Pick<Props, Extract<keyof Props, keyof Result>>>>((props, ref) => {
190
190
  const castProps = props as unknown as Props & Part
191
191
  const attrs = (opts instanceof Function) ? opts(castProps) : opts
192
- return <ComponentWithAttrs ref={ref} {...castProps} {...attrs} />
192
+ return <ComponentWithAttrs ref={ref} {...attrs} {...castProps} />
193
193
  })
194
194
  // TODO : Find a way to remove from the Props the properties affected by opts
195
195
  return ForwardRefComponent
@@ -207,6 +207,6 @@ styledSectionList.attrs = <S, Result extends Partial<S & SectionListProps<any> &
207
207
  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)
208
208
  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)
209
209
 
210
- function invoke<T> (Component: React.ComponentType<T>, props: T) {
210
+ function invoke<T extends object> (Component: React.ComponentType<T>, props: T) {
211
211
  return <Component {...props} />
212
212
  }