Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
react-themer.js
Advanced tools
Automatically switch between dark and light themes at sunset and sunrise using the user's location.
Spice up your app with themes. Themer.js features include:
prefers-color-scheme
# using yarn
$ yarn add react-themer.js
# using npm
$ npm install react-themer.js
import React, { Component } from "react";
import Themer from "react-themer.js";
const themes = {
light: {
"--app-background-color": "#f1f1f1",
"--primary-text-color": "#555"
},
dark: {
"--app-background-color": "#242835",
"--primary-text-color": "#f1f1f1"
}
}
export default class App extends Component {
render() {
return (
<main style="
background-color: var(--app-background-color);
color: var(--primary-text-color);
">
<Themer active="auto" themes={themes} />
</main>
)
}
}
# index.js
import React, { Component } from "react";
import Themer from "react-themer.js";
import light from "./light.json";
import dark from "./dark.json";
import './index.css';
export default class App extends Component {
state = {
active: "auto",
themes: { dark, light }
};
render() {
const { active, themes } = this.state;
const Button = (theme, name) => {
return (
<button onClick={() => this.setState({ active: theme })}>
{name}
</button>
);
};
return (
<main>
<Themer active={active} themes={themes} />
{Button("auto", "Auto")}
{Button("system", "System")}
{Button(light, "Light")}
{Button(dark, "Dark")}
</main>
)
}
}
# index.css
main {
background-color: --app-background-color;
color: --primary-text-color;
}
# light.json
{
"styles": {
"--app-background-color": "#f1f1f1",
"--primary-text-color": "#555",
}
}
# dark.json
{
"styles": {
"--app-background-color": "#242835",
"--primary-text-color": "#f1f1f1",
}
}
Prop | Type | Description |
---|---|---|
active | string or object | The active theme. |
themes | object | Available themes. |
{
"styles": {
"--app-background-color": "#242835",
"--primary-text-color": "#f1f1f1",
"--primary-accent-color": "#056fb6",
"--primary-link-color": "var(--primary-accent-color)",
"--header-background-color": "#2d303c",
"--button-border-color": "#464d5f",
"--button-background-color": "#393e4d",
"--button-text-color": "#f1f1f1",
"--button-active-border-color": "var(--primary-accent-color)",
"--table-pre-background-color": "#3a3b46",
"--table-zebra-background-color": "rgba(255, 255, 255, 0.04)",
"--code-background-color": "rgba(255, 255, 255, 0.1)"
},
"android": "#242835"
}
Note: The android
key is used to set the meta theme-color.
FAQs
Automatically switch between dark and light themes at sunset and sunrise using the user's location.
The npm package react-themer.js receives a total of 0 weekly downloads. As such, react-themer.js popularity was classified as not popular.
We found that react-themer.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.