rn-css 1.4.4 → 1.5.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.
- package/README.md +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/useTheme.d.ts +7 -0
- package/dist/useTheme.js +21 -0
- package/package.json +1 -1
- package/src/index.tsx +1 -0
- package/src/useTheme.tsx +17 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This is basically [styled-components](https://github.com/styled-components/styled-components) with a much better support for React-Native, and some awesome additional features. You can check the docs of [styled-components](https://github.com/styled-components/styled-components) for more details about the basic API. I'll focus here on the differences.
|
|
4
4
|
|
|
5
|
+
**Current version: 1.5** [See the Changelog](./CHANGELOG.md)
|
|
6
|
+
|
|
5
7
|
---
|
|
6
8
|
|
|
7
9
|
## Purpose
|
|
@@ -331,6 +333,14 @@ const View = styled.View`
|
|
|
331
333
|
|
|
332
334
|
---
|
|
333
335
|
|
|
336
|
+
## Theming:
|
|
337
|
+
|
|
338
|
+
To match the API of styled-components, we offer the same abilities for theming [See the documentation](https://styled-components.com/docs/advanced).
|
|
339
|
+
|
|
340
|
+
This relies on the [SharedValue](#shared-value) context. This means that you cannot use the Shared Value system **and** this theming système. Pick the one that best suits your needs.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
334
344
|
## Coming later:
|
|
335
345
|
|
|
336
346
|
linear-gradient, background-repeat, transitions, animations
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as RN from 'react-native';
|
|
|
3
3
|
export { cssToRNStyle } from './cssToRN';
|
|
4
4
|
export { FontSizeContext } from './features';
|
|
5
5
|
export { SharedValue } from './styleComponent';
|
|
6
|
+
export * from './useTheme';
|
|
6
7
|
declare const styled: {
|
|
7
8
|
<T>(Component: React.ComponentType<T>): {
|
|
8
9
|
<S>(chunks: TemplateStringsArray, ...functs: ((string | number | boolean | null | undefined) | ((arg: S & T & {
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
21
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
25
|
exports.SharedValue = exports.FontSizeContext = exports.cssToRNStyle = void 0;
|
|
23
26
|
const RN = __importStar(require("react-native"));
|
|
@@ -28,6 +31,7 @@ var features_1 = require("./features");
|
|
|
28
31
|
Object.defineProperty(exports, "FontSizeContext", { enumerable: true, get: function () { return features_1.FontSizeContext; } });
|
|
29
32
|
var styleComponent_2 = require("./styleComponent");
|
|
30
33
|
Object.defineProperty(exports, "SharedValue", { enumerable: true, get: function () { return styleComponent_2.SharedValue; } });
|
|
34
|
+
__exportStar(require("./useTheme"), exports);
|
|
31
35
|
const styled = (Component) => styleComponent_1.default(Component);
|
|
32
36
|
styled.ActivityIndicator = styled(RN.ActivityIndicator);
|
|
33
37
|
styled.Button = styled(RN.Button);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const ThemeProvider: ({ theme, children }: {
|
|
3
|
+
theme: unknown;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}) => JSX.Element;
|
|
6
|
+
export declare const useTheme: () => unknown;
|
|
7
|
+
export declare const withTheme: <T>(Component: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<T> & React.RefAttributes<React.Component<{}, {}, any>>>;
|
package/dist/useTheme.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withTheme = exports.useTheme = exports.ThemeProvider = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styleComponent_1 = require("./styleComponent");
|
|
9
|
+
const ThemeProvider = ({ theme, children }) => {
|
|
10
|
+
return react_1.default.createElement(styleComponent_1.SharedValue.Provider, { value: theme }, children);
|
|
11
|
+
};
|
|
12
|
+
exports.ThemeProvider = ThemeProvider;
|
|
13
|
+
const useTheme = () => react_1.default.useContext(styleComponent_1.SharedValue);
|
|
14
|
+
exports.useTheme = useTheme;
|
|
15
|
+
const withTheme = (Component) => {
|
|
16
|
+
const theme = exports.useTheme();
|
|
17
|
+
const ThemedComponent = react_1.default.forwardRef((props, ref) => react_1.default.createElement(Component, { ref: ref, theme: theme, ...props }));
|
|
18
|
+
ThemedComponent.displayName = 'ThemedComponent';
|
|
19
|
+
return ThemedComponent;
|
|
20
|
+
};
|
|
21
|
+
exports.withTheme = withTheme;
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import styledComponent, { styledFlatList, styledSectionList, styledVirtualizedLi
|
|
|
4
4
|
export { cssToRNStyle } from './cssToRN'
|
|
5
5
|
export { FontSizeContext } from './features'
|
|
6
6
|
export { SharedValue } from './styleComponent'
|
|
7
|
+
export * from './useTheme'
|
|
7
8
|
|
|
8
9
|
const styled = <T, >(Component: React.ComponentType<T>) => styledComponent<T>(Component)
|
|
9
10
|
|
package/src/useTheme.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { SharedValue } from './styleComponent'
|
|
3
|
+
|
|
4
|
+
export const ThemeProvider = ({ theme, children }: { theme: unknown; children: React.ReactNode }) => {
|
|
5
|
+
return <SharedValue.Provider value={theme}>
|
|
6
|
+
{children}
|
|
7
|
+
</SharedValue.Provider>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useTheme = () => React.useContext(SharedValue)
|
|
11
|
+
|
|
12
|
+
export const withTheme = <T, >(Component: React.ComponentType<T>) => {
|
|
13
|
+
const theme = useTheme()
|
|
14
|
+
const ThemedComponent = React.forwardRef<React.Component, T>((props: T, ref) => <Component ref={ref} theme={theme} {...props} />)
|
|
15
|
+
ThemedComponent.displayName = 'ThemedComponent'
|
|
16
|
+
return ThemedComponent
|
|
17
|
+
}
|