rn-css 1.8.12 → 1.8.14
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/cssToRN/convert.js +26 -6
- package/dist/features.d.ts +2 -2
- package/dist/features.js +5 -5
- package/dist/styleComponent.js +3 -3
- package/package.json +1 -1
- package/src/cssToRN/convert.ts +25 -6
- package/src/features.tsx +4 -4
- package/src/styleComponent.tsx +3 -3
package/dist/cssToRN/convert.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cornerValue = exports.sideValue = exports.font = exports.transform = exports.textDecoration = exports.background = exports.placeContent = exports.flexFlow = exports.flex = exports.shadow = exports.borderLike = exports.border = void 0;
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
|
|
6
|
+
* Optionally accept "auto" value (for margins)
|
|
7
|
+
* @param value The value to check
|
|
8
|
+
* @param acceptAuto true if auto is an accepted value
|
|
9
|
+
* @returns true if the value is a number
|
|
10
|
+
*/
|
|
11
|
+
function isNumber(value, acceptAuto) {
|
|
12
|
+
if (acceptAuto && value === 'auto')
|
|
13
|
+
return true;
|
|
6
14
|
return value.match(/^[+-]?(\.\d|\d|calc\(|max\(|min\()/mg);
|
|
7
15
|
}
|
|
8
|
-
/**
|
|
9
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
|
|
18
|
+
* Optionally accept "auto" value (for margins)
|
|
19
|
+
* @param value The value to check
|
|
20
|
+
* @param acceptAuto true if auto is an accepted value
|
|
21
|
+
* @returns true if the value is a number
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Split the value into numbers values and non numbers values
|
|
25
|
+
* @param value The value to check
|
|
26
|
+
* @param acceptAuto true if auto is an accepted value
|
|
27
|
+
* @returns An object containing the number and non number values as arrays.
|
|
28
|
+
*/
|
|
29
|
+
function findNumbers(value, acceptAuto) {
|
|
10
30
|
const result = {
|
|
11
31
|
nonNumbers: [],
|
|
12
32
|
numbers: []
|
|
@@ -21,7 +41,7 @@ function findNumbers(value) {
|
|
|
21
41
|
if (group)
|
|
22
42
|
result.nonNumbers.push(val);
|
|
23
43
|
else
|
|
24
|
-
result[isNumber(val) ? 'numbers' : 'nonNumbers'].push(val);
|
|
44
|
+
result[isNumber(val, acceptAuto) ? 'numbers' : 'nonNumbers'].push(val);
|
|
25
45
|
});
|
|
26
46
|
return result;
|
|
27
47
|
}
|
|
@@ -219,7 +239,7 @@ exports.font = font;
|
|
|
219
239
|
function sideValue(prefixKey, value, postFix = '') {
|
|
220
240
|
if (value === 'none')
|
|
221
241
|
return sideValue(prefixKey, '0', postFix);
|
|
222
|
-
const [top = value, right = top, bottom = top, left = right] = findNumbers(value).numbers;
|
|
242
|
+
const [top = value, right = top, bottom = top, left = right] = findNumbers(value, prefixKey === 'margin').numbers;
|
|
223
243
|
return {
|
|
224
244
|
[prefixKey + 'Top' + postFix]: top,
|
|
225
245
|
[prefixKey + 'Left' + postFix]: left,
|
package/dist/features.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export declare const useScreenSize: () => {
|
|
|
9
9
|
vmax: number;
|
|
10
10
|
};
|
|
11
11
|
/** Hook that will apply the style reserved for hover state if needed */
|
|
12
|
-
export declare const useHover: (
|
|
12
|
+
export declare const useHover: (onMouseEnter: ((event: MouseEvent) => void) | undefined, onMouseLeave: ((event: MouseEvent) => void | undefined) | undefined, needsHover: boolean) => {
|
|
13
13
|
hover: boolean;
|
|
14
|
-
|
|
14
|
+
onMouseEnter: ((event: MouseEvent) => void) | undefined;
|
|
15
15
|
onMouseLeave: ((event: MouseEvent) => void | undefined) | undefined;
|
|
16
16
|
};
|
|
17
17
|
/** Hook that will apply the style provided in the media queries */
|
package/dist/features.js
CHANGED
|
@@ -18,19 +18,19 @@ const useScreenSize = () => {
|
|
|
18
18
|
};
|
|
19
19
|
exports.useScreenSize = useScreenSize;
|
|
20
20
|
/** Hook that will apply the style reserved for hover state if needed */
|
|
21
|
-
const useHover = (
|
|
21
|
+
const useHover = (onMouseEnter, onMouseLeave, needsHover) => {
|
|
22
22
|
const [hover, setHover] = react_1.default.useState(false);
|
|
23
23
|
const hoverStart = react_1.default.useMemo(() => needsHover ? (event) => {
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
if (onMouseEnter)
|
|
25
|
+
onMouseEnter(event);
|
|
26
26
|
setHover(true);
|
|
27
|
-
} : undefined, [needsHover,
|
|
27
|
+
} : undefined, [needsHover, onMouseEnter]);
|
|
28
28
|
const hoverStop = react_1.default.useMemo(() => needsHover ? (event) => {
|
|
29
29
|
if (onMouseLeave)
|
|
30
30
|
onMouseLeave(event);
|
|
31
31
|
setHover(false);
|
|
32
32
|
} : undefined, [needsHover, onMouseLeave]);
|
|
33
|
-
return { hover,
|
|
33
|
+
return { hover, onMouseEnter: hoverStart || onMouseEnter, onMouseLeave: hoverStop || onMouseLeave };
|
|
34
34
|
};
|
|
35
35
|
exports.useHover = useHover;
|
|
36
36
|
/** Hook that will apply the style provided in the media queries */
|
package/dist/styleComponent.js
CHANGED
|
@@ -65,7 +65,7 @@ const styled = (Component) => {
|
|
|
65
65
|
needsHover: !!rnStyle.hover
|
|
66
66
|
}), [css, rnStyle.hover]);
|
|
67
67
|
// Handle hover
|
|
68
|
-
const {
|
|
68
|
+
const { onMouseEnter, onMouseLeave, hover } = (0, features_1.useHover)(props.onMouseEnter, props.onMouseLeave, needsHover);
|
|
69
69
|
const tempStyle = react_1.default.useMemo(() => {
|
|
70
70
|
const style = { ...rnStyle };
|
|
71
71
|
delete style.media;
|
|
@@ -111,12 +111,12 @@ const styled = (Component) => {
|
|
|
111
111
|
return { style: getStyle(hash, style), hash };
|
|
112
112
|
}, [finalStyle, units]);
|
|
113
113
|
const newProps = react_1.default.useMemo(() => {
|
|
114
|
-
const newProps = { style: [styleConvertedFromCSS, props.style],
|
|
114
|
+
const newProps = { style: [styleConvertedFromCSS, props.style], onMouseEnter, onMouseLeave, onLayout };
|
|
115
115
|
if (finalStyle.textOverflow === 'ellipsis') {
|
|
116
116
|
Object.assign(newProps, { numberOfLines: 1 });
|
|
117
117
|
}
|
|
118
118
|
return newProps;
|
|
119
|
-
}, [finalStyle.textOverflow, onLayout,
|
|
119
|
+
}, [finalStyle.textOverflow, onLayout, onMouseEnter, onMouseLeave, props.style, styleConvertedFromCSS]);
|
|
120
120
|
react_1.default.useEffect(() => () => removeStyle(hash), [hash]);
|
|
121
121
|
// em !== parentEm alone is a bit dangerous as the component would rerender when the font size change
|
|
122
122
|
if (em !== parentEm || finalStyle.fontSize !== undefined) {
|
package/package.json
CHANGED
package/src/cssToRN/convert.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import type { Style, Transform } from '../types'
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
|
|
5
|
+
* Optionally accept "auto" value (for margins)
|
|
6
|
+
* @param value The value to check
|
|
7
|
+
* @param acceptAuto true if auto is an accepted value
|
|
8
|
+
* @returns true if the value is a number
|
|
9
|
+
*/
|
|
10
|
+
function isNumber (value: string, acceptAuto?: boolean) {
|
|
11
|
+
if (acceptAuto && value === 'auto') return true
|
|
5
12
|
return value.match(/^[+-]?(\.\d|\d|calc\(|max\(|min\()/mg)
|
|
6
13
|
}
|
|
7
14
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
|
|
17
|
+
* Optionally accept "auto" value (for margins)
|
|
18
|
+
* @param value The value to check
|
|
19
|
+
* @param acceptAuto true if auto is an accepted value
|
|
20
|
+
* @returns true if the value is a number
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Split the value into numbers values and non numbers values
|
|
24
|
+
* @param value The value to check
|
|
25
|
+
* @param acceptAuto true if auto is an accepted value
|
|
26
|
+
* @returns An object containing the number and non number values as arrays.
|
|
27
|
+
*/
|
|
28
|
+
function findNumbers (value: string, acceptAuto?: boolean) {
|
|
10
29
|
const result = {
|
|
11
30
|
nonNumbers: [] as string[],
|
|
12
31
|
numbers: [] as string[]
|
|
@@ -17,7 +36,7 @@ function findNumbers (value: string) {
|
|
|
17
36
|
if (val.startsWith('"') || val.startsWith("'")) group = val.charAt(0)
|
|
18
37
|
if (group && val.endsWith(group)) group = ''
|
|
19
38
|
if (group) result.nonNumbers.push(val)
|
|
20
|
-
else result[isNumber(val) ? 'numbers' : 'nonNumbers'].push(val)
|
|
39
|
+
else result[isNumber(val, acceptAuto) ? 'numbers' : 'nonNumbers'].push(val)
|
|
21
40
|
})
|
|
22
41
|
return result
|
|
23
42
|
}
|
|
@@ -188,7 +207,7 @@ export function font (value: string) {
|
|
|
188
207
|
/** Parses a css value for the side of an element (border-width, margin, padding) */
|
|
189
208
|
export function sideValue <T extends 'padding' | 'margin' | 'border'> (prefixKey: T, value: string, postFix: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : '' = ''): { [x: string]: string} {
|
|
190
209
|
if (value === 'none') return sideValue(prefixKey, '0', postFix)
|
|
191
|
-
const [top = value, right = top, bottom = top, left = right] = findNumbers(value).numbers
|
|
210
|
+
const [top = value, right = top, bottom = top, left = right] = findNumbers(value, prefixKey === 'margin').numbers
|
|
192
211
|
return {
|
|
193
212
|
[prefixKey + 'Top' + postFix]: top,
|
|
194
213
|
[prefixKey + 'Left' + postFix]: left,
|
package/src/features.tsx
CHANGED
|
@@ -14,17 +14,17 @@ export const useScreenSize = () => {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/** Hook that will apply the style reserved for hover state if needed */
|
|
17
|
-
export const useHover = (
|
|
17
|
+
export const useHover = (onMouseEnter: undefined | ((event: MouseEvent) => void), onMouseLeave: undefined | ((event: MouseEvent) => void | undefined), needsHover: boolean) => {
|
|
18
18
|
const [hover, setHover] = React.useState(false)
|
|
19
19
|
const hoverStart = React.useMemo(() => needsHover ? (event: MouseEvent) => {
|
|
20
|
-
if (
|
|
20
|
+
if (onMouseEnter) onMouseEnter(event)
|
|
21
21
|
setHover(true)
|
|
22
|
-
} : undefined, [needsHover,
|
|
22
|
+
} : undefined, [needsHover, onMouseEnter])
|
|
23
23
|
const hoverStop = React.useMemo(() => needsHover ? (event: MouseEvent) => {
|
|
24
24
|
if (onMouseLeave) onMouseLeave(event)
|
|
25
25
|
setHover(false)
|
|
26
26
|
} : undefined, [needsHover, onMouseLeave])
|
|
27
|
-
return { hover,
|
|
27
|
+
return { hover, onMouseEnter: hoverStart || onMouseEnter, onMouseLeave: hoverStop || onMouseLeave }
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** Hook that will apply the style provided in the media queries */
|
package/src/styleComponent.tsx
CHANGED
|
@@ -78,7 +78,7 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
78
78
|
}), [css, rnStyle.hover])
|
|
79
79
|
|
|
80
80
|
// Handle hover
|
|
81
|
-
const {
|
|
81
|
+
const { onMouseEnter, onMouseLeave, hover } = useHover(props.onMouseEnter, props.onMouseLeave, needsHover)
|
|
82
82
|
const tempStyle = React.useMemo<Style>(() => {
|
|
83
83
|
const style = { ...rnStyle }
|
|
84
84
|
delete style.media
|
|
@@ -127,12 +127,12 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
127
127
|
return { style: getStyle<CompleteStyle>(hash, style), hash }
|
|
128
128
|
}, [finalStyle, units])
|
|
129
129
|
const newProps = React.useMemo(() => {
|
|
130
|
-
const newProps = { style: [styleConvertedFromCSS as StyleType, props.style],
|
|
130
|
+
const newProps = { style: [styleConvertedFromCSS as StyleType, props.style], onMouseEnter, onMouseLeave, onLayout }
|
|
131
131
|
if (finalStyle.textOverflow === 'ellipsis') {
|
|
132
132
|
Object.assign(newProps, { numberOfLines: 1 })
|
|
133
133
|
}
|
|
134
134
|
return newProps
|
|
135
|
-
}, [finalStyle.textOverflow, onLayout,
|
|
135
|
+
}, [finalStyle.textOverflow, onLayout, onMouseEnter, onMouseLeave, props.style, styleConvertedFromCSS])
|
|
136
136
|
|
|
137
137
|
React.useEffect(() => () => removeStyle(hash), [hash])
|
|
138
138
|
|