1.0.10-a • Published 8 months ago

pluto-theme-mode v1.0.10-a

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Pluto Theme Mode tag - 1.0.10a

pluto-theme-mode is a lightweight and versatile theme provider library for React, designed to make switching between light and dark modes smooth and effortless. Built with TypeScript, styled-components, and Context Hook, it supports multiple styling approaches—including inline class, Tailwind CSS, and styled-components—offering flexible options for theme-based designs. Ideal for developers looking to add dark mode functionality seamlessly, pluto-theme-mode provides a modern, intuitive solution for managing theme states and creating customizable user experiences. 🌃🌇

style: styled-components style: Tailwind CSS React

Quickstart

1. Install

npm install pluto-theme-mode

2. Add Provider

import { PlutoProvider } from 'pluto-theme-mode'; // import the PlutoProvider

// wrap the App with PlutoProvider
<PlutoProvider>
  <App />
</PlutoProvider>

You can also add props to the provider, including props to set the meta tag for theme-color. Here is an example of how to use it: ☀️🌙

<PlutoProvider dark='#000' light='#FFF'>
  <App />
</PlutoProvider>

You can also add props to the provider, including props to set the meta tag for theme-color, with values specified in either HEX or RGB format, as shown in the example abov. 🖌️

3. Add Toggle

import { ToggleButton } from 'pluto-theme-mode'; // import ToggleButton

// call the ToggleButton as appropriate
<ToggleButton />

📄 Additionally, you can also call props, and the details will be explained below.

PropsDetailsValuesType
lightModeLabelLabel for light mode.Light , Specifiedstring, undefined
darkModeLabelLabel for dark mode.Dark , Specifiedstring, undefined
systemModeLabelLabel for system mode.System , Specifiedstring, undefined
lightModeIconIcon for light mode. Can be an SVG or image.SVG, <img />ReactNode
darkModeIconIcon for dark mode. Can be an SVG or image.SVG, <img />ReactNode
systemModeIconIcon for system mode. Can be an SVG or image.SVG, <img />ReactNode
backgroundColorDarkBackground color for dark mode.#000, rgb(0,0,0), blackstring, undefined
backgroundColorLightBackground color for light mode.#FFF, rgb(255,255,255), whitestring, undefined
colorDarkText color for dark mode.#000, rgb(0,0,0) , blackstring, undefined
colorLightText color for light mode.#FFF, rgb(255,255,255), whitestring, undefined
borderColorDarkBorder color for dark mode.#222, rgb(34,34,34), greystring, undefined
borderColorLightBorder color for light mode.#222, rgb(34,34,34), greystring, undefined
activeColorColor for active state.#6495ED, rgb(100, 149, 237), cornflowerbluestring, undefined
cardBorderRadiusBorder radius for the card.24px, 1.5remstring, undefined
menuBorderRadiusBorder radius for the menu.16px, 1remstring, undefined
fontSizeFont size for the text.16px, 1.0000emstring, undefined
iconSizeFont size for icons.24px, 1.5emstring, undefined
heightHeight of the card.155px, max-contentstring, undefined
widthWidth of the card.180px, max-contentstring, undefined
paddingPadding inside the card.11.2px, 0.7remstring, undefined
gapGap between elements inside the menu.8px, 0.5remstring, undefined
transitionTransition of the card.true, falseboolean
positionXHorizontal position of the card.20pxstring, undefined
positionYVertical position of the card.40pxstring, undefined
zIndexZ-index for stacking order.1, 100, Specifiednumber, undefined

🎨 You can decorate it as desired.

4. Usage

import { useTheme } from 'pluto-theme-mode'; // import useTheme

const { theme } = useTheme() // destructure theme from useTheme hook

Inline Style CSS

// This code renders a <div> and a <span> element, applying dynamic styling based on the current theme mode (either 'dark' or 'light').
// In the first <div> and <span> block, the background and text colors are set directly using color codes.
// In the second <div> and <span> block, the classes 'backgroundDark', 'backgroundLight', 'colorLight', and 'colorDark' are used 
// instead, allowing for centralized styling through CSS classes.
// When the theme mode is 'dark':
// - The first <div> has a background of '#333' (dark gray) and the text color of the <span> is '#fff' (white).
// - The second <div> and <span> apply 'backgroundDark' and 'colorLight' classes, using styles defined in CSS.
// When the theme mode is 'light':
// - The first <div> has a background of '#fff' (white) and the text color of the <span> is '#333' (dark gray).
// - The second <div> and <span> apply 'backgroundLight' and 'colorDark' classes.

<div style={{ backgroundColor: theme.mode === 'dark' ? '#333' : '#fff' }}>
  <span style={{ color: theme.mode === 'dark' ? '#fff' : '#333' }}>Inline CSS</span>
</div>

<div className={theme.mode === 'dark' ? 'backgroundDark' : 'backgroundLight'}>
  <span className={theme.mode === 'dark' ? 'colorLight' : 'colorDark'}>Inline CSS</span>
</div>

Tailwind CSS

// This code applies dynamic styling to a <div> and a <span> element based on the current theme mode (dark or light) using TailwindCSS classes.

// If the theme mode is 'dark', the background of the <div> will be 'bg-gray-800' (dark gray) and the text color of the <span> will be 'text-white' (white).
// If the theme mode is 'light', the background of the <div> will be 'bg-white' (white) and the text color of the <span> will be 'text-gray-800' (dark gray).

<div className={`${theme.mode === 'dark' ? 'bg-gray-800' : 'bg-white'}`}>
  <span className={`${theme.mode === 'dark' ? 'text-white' : 'text-gray-800'}`}>Tailwind CSS</span>
</div>

Styled Components

import { useTheme } from 'pluto-theme-mode' // import useTheme
import { ThemeProvider } from 'styled-components' // import provider from styled components

const App = () => {
  const { theme } = useTheme() // destructure theme from useTheme hook

  return (
    // wrap Component with ThemeProvider
    // use theme prop set mode with theme.mode
    <ThemeProvider theme={{ mode: theme.mode }}>
      {Component}
    </ThemeProvider>
  )
}

export default App
import styled from 'styled-components';

// Styled components for <div> and <span>
const StyledDiv = styled.div`
  background-color: ${(props) => (props.theme.mode === 'dark' ? '#333' : '#fff')};
`;

const StyledSpan = styled.span`
  color: ${(props) => (props.theme.mode === 'dark' ? '#fff' : '#333')};
`;

// call the StyledDiv and StyledSpan
<StyledDiv>
  <StyledSpan>Styled components</StyledSpan>
</StyledDiv>

Example image

  • Toggle
    • Light
    • Dark
    • System

License

Licensed under the MIT License, Copyright © 2024-present Chakkrit Laolit.

See LICENSE for more information.

1.0.10-a

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

9 months ago