rn-css 2.0.0 → 2.0.2
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/styleComponent.js +1 -1
- package/dist/useTheme.d.ts +2 -2
- package/package.json +1 -1
- package/src/styleComponent.tsx +1 -1
- package/src/useTheme.tsx +3 -3
package/dist/styleComponent.js
CHANGED
|
@@ -26,7 +26,7 @@ function buildCSSString(chunks, functs, props, shared) {
|
|
|
26
26
|
.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? functs[i]({ shared, theme: shared, ...props }) : functs[i]]))
|
|
27
27
|
.flat()
|
|
28
28
|
// Convert the objects to string if the result is not a primitive
|
|
29
|
-
.map(chunk => typeof chunk === 'object' ? (0, rnToCss_1.default)(chunk) : chunk)
|
|
29
|
+
.map(chunk => chunk && typeof chunk === 'object' ? (0, rnToCss_1.default)(chunk) : chunk)
|
|
30
30
|
.join('');
|
|
31
31
|
if (props.rnCSS)
|
|
32
32
|
computedString += props.rnCSS.replace(/=/gm, ':') + ';';
|
package/dist/useTheme.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export declare const ThemeProvider: ({ theme, children }: {
|
|
|
9
9
|
* Returns the Theme
|
|
10
10
|
* @returns The Theme object
|
|
11
11
|
*/
|
|
12
|
-
export declare const useTheme: () =>
|
|
12
|
+
export declare const useTheme: <T extends DefaultTheme = DefaultTheme>() => T;
|
|
13
13
|
/**
|
|
14
14
|
* Adds the theme prop to a non rn-css component
|
|
15
15
|
* @param Component A non rn-css component
|
|
16
16
|
* @returns A component with the theme prop
|
|
17
17
|
*/
|
|
18
|
-
export declare const withTheme: <T>(Component: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<T> & React.RefAttributes<React.Component<{}, {}, any>>>;
|
|
18
|
+
export declare const withTheme: <T extends DefaultTheme = DefaultTheme>(Component: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<T> & React.RefAttributes<React.Component<{}, {}, any>>>;
|
package/package.json
CHANGED
package/src/styleComponent.tsx
CHANGED
|
@@ -44,7 +44,7 @@ function buildCSSString<T extends { rnCSS?: string }> (chunks: TemplateStringsAr
|
|
|
44
44
|
.map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? (functs[i] as Functs<T>)({ shared, theme: (shared as DefaultTheme), ...props }) : functs[i]]))
|
|
45
45
|
.flat()
|
|
46
46
|
// Convert the objects to string if the result is not a primitive
|
|
47
|
-
.map(chunk => typeof chunk === 'object' ? rnToCSS(chunk as Partial<CompleteStyle>) : chunk)
|
|
47
|
+
.map(chunk => chunk && typeof chunk === 'object' ? rnToCSS(chunk as Partial<CompleteStyle>) : chunk)
|
|
48
48
|
.join('')
|
|
49
49
|
if (props.rnCSS) computedString += props.rnCSS.replace(/=/gm, ':') + ';'
|
|
50
50
|
return computedString
|
package/src/useTheme.tsx
CHANGED
|
@@ -12,16 +12,16 @@ export const ThemeProvider = ({ theme, children }: { theme: DefaultTheme; childr
|
|
|
12
12
|
* Returns the Theme
|
|
13
13
|
* @returns The Theme object
|
|
14
14
|
*/
|
|
15
|
-
export const useTheme = () => React.useContext(SharedValue)
|
|
15
|
+
export const useTheme = <T extends DefaultTheme = DefaultTheme>() => React.useContext(SharedValue) as T
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Adds the theme prop to a non rn-css component
|
|
19
19
|
* @param Component A non rn-css component
|
|
20
20
|
* @returns A component with the theme prop
|
|
21
21
|
*/
|
|
22
|
-
export const withTheme = <T, >(Component: React.ComponentType<T>) => {
|
|
22
|
+
export const withTheme = <T extends DefaultTheme = DefaultTheme, >(Component: React.ComponentType<T>) => {
|
|
23
23
|
const ThemedComponent = React.forwardRef<React.Component, T>((props, ref) => {
|
|
24
|
-
const theme = useTheme()
|
|
24
|
+
const theme = useTheme<T>()
|
|
25
25
|
return <Component ref={ref} theme={theme} {...(props as unknown as T)} />
|
|
26
26
|
})
|
|
27
27
|
ThemedComponent.displayName = 'ThemedComponent'
|