@starasia/theme 1.0.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 +143 -0
- package/dist/components/ThemeProvider.d.ts +12 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/default.json.d.ts +542 -0
- package/dist/helpers/brandcolor.d.ts +3 -0
- package/dist/helpers/colorpalette.d.ts +3 -0
- package/dist/helpers/components.d.ts +3 -0
- package/dist/helpers/createTheme.d.ts +3 -0
- package/dist/helpers/font.d.ts +8 -0
- package/dist/helpers/generator.d.ts +3 -0
- package/dist/helpers/index.d.ts +6 -0
- package/dist/helpers/injector.d.ts +2 -0
- package/dist/helpers/maincolor.d.ts +3 -0
- package/dist/helpers/metric.d.ts +3 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/use.d.ts +4 -0
- package/dist/hooks/useTheme.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +1418 -0
- package/dist/index.umd.js +54 -0
- package/dist/types/components/alert.d.ts +33 -0
- package/dist/types/components/badge.d.ts +43 -0
- package/dist/types/components/button.d.ts +18 -0
- package/dist/types/components/card.d.ts +18 -0
- package/dist/types/components/checkbox.d.ts +29 -0
- package/dist/types/components/date.d.ts +39 -0
- package/dist/types/components/input.d.ts +33 -0
- package/dist/types/components/menu.d.ts +21 -0
- package/dist/types/components/pagination.d.ts +32 -0
- package/dist/types/components/radio.d.ts +26 -0
- package/dist/types/components/tab.d.ts +25 -0
- package/dist/types/components/table.d.ts +35 -0
- package/dist/types/components/textarea.d.ts +37 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/theme.d.ts +236 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @starasia/theme
|
|
2
|
+
|
|
3
|
+
The `@starasia/theme` package provides theming capabilities for React applications. It allows you to define and apply custom themes to your components easily.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @starasia/theme
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Using yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @starasia/theme
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Using pnpm:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @starasia/theme
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### ThemeProvider
|
|
28
|
+
|
|
29
|
+
Wrap your application with the `ThemeProvider` component to provide the theme context to all child components.
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import React from "react";
|
|
33
|
+
import ReactDOM from "react-dom";
|
|
34
|
+
import {ThemeProvider} from "@starasia/theme";
|
|
35
|
+
|
|
36
|
+
const theme = {
|
|
37
|
+
colors: {
|
|
38
|
+
main: {
|
|
39
|
+
primary: {
|
|
40
|
+
"background-color": "red",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const App = () => {
|
|
47
|
+
return (
|
|
48
|
+
<ThemeProvider value={theme}>
|
|
49
|
+
{/* Your application content */}
|
|
50
|
+
</ThemeProvider>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
ReactDOM.render(<App />, document.getElementById("root"));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For full theme configuration please check https://github.com/starasia-solusi-digital/starasia-theme/blob/main/src/default.json
|
|
58
|
+
|
|
59
|
+
### useTheme Hook
|
|
60
|
+
|
|
61
|
+
Use the `useTheme` hook to access the current theme object and functions for updating the theme.
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import React from "react";
|
|
65
|
+
import {Button} from "@starasia/button";
|
|
66
|
+
import {useTheme} from "@starasia/theme";
|
|
67
|
+
|
|
68
|
+
const AppContent = () => {
|
|
69
|
+
const {theme, setTheme} = useTheme();
|
|
70
|
+
|
|
71
|
+
const handleThemeChange = () => {
|
|
72
|
+
const newTheme = {
|
|
73
|
+
colors: {
|
|
74
|
+
main: {
|
|
75
|
+
primary: {
|
|
76
|
+
"background-color": "green",
|
|
77
|
+
hover: {
|
|
78
|
+
"background-color": "green",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
setTheme(newTheme);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
<Button onClick={handleThemeChange}>Change Theme</Button>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default AppContent;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Example
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import React from "react";
|
|
101
|
+
import ReactDOM from "react-dom";
|
|
102
|
+
import {ThemeProvider} from "@starasia/theme";
|
|
103
|
+
import AppContent from "./AppContent";
|
|
104
|
+
|
|
105
|
+
const theme = {
|
|
106
|
+
colors: {
|
|
107
|
+
main: {
|
|
108
|
+
primary: {
|
|
109
|
+
"background-color": "red",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const App = () => {
|
|
116
|
+
return (
|
|
117
|
+
<ThemeProvider value={theme}>
|
|
118
|
+
<AppContent />
|
|
119
|
+
</ThemeProvider>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
ReactDOM.render(<App />, document.getElementById("root"));
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## API
|
|
127
|
+
|
|
128
|
+
### ThemeProvider
|
|
129
|
+
|
|
130
|
+
#### Props
|
|
131
|
+
|
|
132
|
+
- `value`: The theme object to be applied to the component tree.
|
|
133
|
+
|
|
134
|
+
### useTheme Hook
|
|
135
|
+
|
|
136
|
+
#### Returns
|
|
137
|
+
|
|
138
|
+
- `theme`: The current theme object.
|
|
139
|
+
- `setTheme`: A function to update the theme.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as React, PropsWithChildren } from 'react';
|
|
2
|
+
import { ThemeObject } from '../types/theme';
|
|
3
|
+
|
|
4
|
+
export interface ThemeContextProps {
|
|
5
|
+
theme?: ThemeObject;
|
|
6
|
+
setTheme: (theme?: ThemeObject) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const ThemeContext: React.Context<ThemeContextProps>;
|
|
9
|
+
export interface ThemeProviderProps extends PropsWithChildren {
|
|
10
|
+
value?: ThemeObject;
|
|
11
|
+
}
|
|
12
|
+
export declare function ThemeProvider({ value, children }: ThemeProviderProps): React.JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ThemeProvider';
|