@anmiles/theme-switcher 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/.eslintignore +2 -0
- package/.eslintrc.js +10 -0
- package/.vscode/settings.json +6 -0
- package/CHANGELOG.md +14 -0
- package/LICENSE.md +21 -0
- package/README.md +88 -0
- package/coverage.config.js +8 -0
- package/dev/index.html +35 -0
- package/dist/theme-switcher-0.1.0.js +2194 -0
- package/dist/theme-switcher-0.1.0.min.js +2 -0
- package/dist/theme-switcher-0.1.0.min.js.LICENSE.txt +9 -0
- package/jest.config.js +26 -0
- package/package.json +71 -0
- package/src/__mocks__/css.ts +1 -0
- package/src/__tests__/index.test.tsx +25 -0
- package/src/__tests__/theme.test.ts +23 -0
- package/src/components/App.tsx +55 -0
- package/src/components/Icon.tsx +19 -0
- package/src/components/ThemeSelector.tsx +34 -0
- package/src/components/__tests__/App.test.tsx +350 -0
- package/src/components/__tests__/__snapshots__/App.test.tsx.snap +153 -0
- package/src/components/icons/Checked.tsx +24 -0
- package/src/components/icons/Dark.tsx +13 -0
- package/src/components/icons/Light.tsx +21 -0
- package/src/components/icons/System.tsx +18 -0
- package/src/index.tsx +20 -0
- package/src/lib/__tests__/eventEmitter.test.ts +109 -0
- package/src/lib/eventEmitter.ts +32 -0
- package/src/lib/theme.ts +21 -0
- package/src/providers/__tests__/systemProvider.test.ts +102 -0
- package/src/providers/__tests__/userProvider.test.ts +60 -0
- package/src/providers/systemProvider.ts +40 -0
- package/src/providers/userProvider.ts +24 -0
- package/src/styles/style.css +52 -0
- package/tsconfig.build.json +7 -0
- package/tsconfig.json +16 -0
- package/tsconfig.test.json +7 -0
- package/webpack.config.js +67 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root : true,
|
|
3
|
+
|
|
4
|
+
extends : [
|
|
5
|
+
'./node_modules/@anmiles/eslint-config/src/base.preset.js',
|
|
6
|
+
'./node_modules/@anmiles/eslint-config/src/ts.preset.js',
|
|
7
|
+
'./node_modules/@anmiles/eslint-config/src/jest.preset.js',
|
|
8
|
+
'./node_modules/@anmiles/eslint-config/src/react.preset.js',
|
|
9
|
+
],
|
|
10
|
+
};
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0](../../tags/v1.0.0) - 2024-12-15
|
|
9
|
+
### Changed
|
|
10
|
+
- First official release
|
|
11
|
+
|
|
12
|
+
## [0.1.0] - 2024-11-30
|
|
13
|
+
### Added
|
|
14
|
+
- First version (not covered by unit tests; not released on NPM for now)
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) {YEAR} Anatoliy Oblaukhov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @anmiles/theme-switcher
|
|
2
|
+
|
|
3
|
+
Theme switcher for websites
|
|
4
|
+
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### For React+TS project
|
|
10
|
+
|
|
11
|
+
1. Install package:
|
|
12
|
+
```bash
|
|
13
|
+
npm install @anmiles/theme-switcher
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
2. Import component:
|
|
17
|
+
```ts
|
|
18
|
+
import { ThemeSwitcher } from '@anmiles/theme-switcher';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
3. Use component:
|
|
22
|
+
```ts
|
|
23
|
+
<ThemeSwitcher float="right" />
|
|
24
|
+
```
|
|
25
|
+
where
|
|
26
|
+
- `float` _(optional)_ - position of icon and dropdown box
|
|
27
|
+
|
|
28
|
+
### For static HTML website
|
|
29
|
+
|
|
30
|
+
1. Clone repository:
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/anmiles/theme-switcher.git
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Copy all files from `dist` into the target website.
|
|
36
|
+
|
|
37
|
+
4. Create HTML container for theme switcher:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<div class="my-selector"></div>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
5. Include React library and theme switcher:
|
|
44
|
+
|
|
45
|
+
### Development
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<script type="text/javascript" src="https://unpkg.com/react@18.3.1/umd/react.development.js"></script>
|
|
49
|
+
<script type="text/javascript" src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js"></script>
|
|
50
|
+
<script type="text/javascript" src="./theme-switcher-1.0.0.js"></script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Production
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<script type="text/javascript" src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"></script>
|
|
57
|
+
<script type="text/javascript" src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"></script>
|
|
58
|
+
<script type="text/javascript" src="./theme-switcher-1.0.0.min.js"></script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
6. Place theme switcher into container:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<script type="text/javascript">
|
|
65
|
+
new ThemeSwitcher({ float: 'right' })
|
|
66
|
+
.render(document.querySelector('.my-selector'));
|
|
67
|
+
</script>
|
|
68
|
+
```
|
|
69
|
+
where
|
|
70
|
+
- `float` _(optional)_ - position of icon and dropdown box
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
Use selectors to write theme-specific styles:
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
body[data-theme="light"] .selector {
|
|
78
|
+
/* css rules */
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```css
|
|
83
|
+
body[data-theme="dark"] .selector {
|
|
84
|
+
/* css rules */
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or you can just write default styles for light theme and override them for dark theme using `body[data-theme="dark"]`.
|
package/dev/index.html
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Debug</title>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<link rel="stylesheet" href="https://dev.anmiles.net/index.css" type="text/css">
|
|
7
|
+
<link rel="icon" href="https://dev.anmiles.net/favicon.ico" type="image/x-icon">
|
|
8
|
+
<style type="text/css">
|
|
9
|
+
.theme {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
float: right;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
|
|
17
|
+
<div class="top">
|
|
18
|
+
<div class="theme"></div>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="box">
|
|
22
|
+
|
|
23
|
+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper pretium nunc vel fermentum. Morbi egestas dictum maximus. Sed convallis vulputate nibh nec elementum. Nunc maximus posuere ipsum sit amet sollicitudin. In ullamcorper sagittis neque non tristique. Phasellus ac purus sit amet enim cursus aliquet et quis enim. Suspendisse sit amet tincidunt ante, at interdum tellus. Proin mauris nulla, porttitor a neque nec, lacinia tristique turpis. Aenean ac commodo turpis.</p>
|
|
24
|
+
|
|
25
|
+
<p>Nulla consectetur magna eget felis dignissim, ut pellentesque libero venenatis. Suspendisse tempus blandit dui, ut volutpat nisl. Nam laoreet sit amet dui eu pretium. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan nisi blandit, volutpat sem sed, placerat eros. Duis dignissim id velit eu placerat. Sed a magna efficitur diam ultrices pulvinar. Suspendisse placerat massa orci. Ut a facilisis nisi. Morbi imperdiet neque id orci luctus facilisis. Suspendisse sit amet consectetur tortor, a elementum ipsum.</p>
|
|
26
|
+
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-18.3.1.js"></script>
|
|
30
|
+
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-dom-18.3.1.js"></script>
|
|
31
|
+
<script type="text/javascript" src="./theme-switcher-1.0.0.js"></script>
|
|
32
|
+
<script type="text/javascript">new ThemeSwitcherElement({ float: 'right' }).render(document.querySelector('.theme'));</script>
|
|
33
|
+
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|