Skip to main content

Themes

PThemeProvider

PThemeProvider is the component to pass your theme colors and state. Maintains own theme state with boolean state : darkTheme and handler:handleTheme and defaults to light theme. Access darkTheme, handleTheme via useTheme()

//for providing darkTheme state and handler globally
import { PThemeProvider } from "react-khatra-placeholder";

return (
<PThemeProvider
lightModeBackground="orange"
lightModeColor="brown"
darkModeBackground="lightgreen"
darkModeColor="green"
darkModeShine="lightblue"
>
<YourTopParentComponentPage />
</PThemeProvider>
);
PropertyTypeRequiredDefault valueDescription
lightModeColorStringnoDEFAULT_LIGHTMODE_LINE_COLORlight mode color of placeholder lines and blocks.
darkModeColorStringnoDEFAULT_DARKMODE_LINE_COLORdark mode color of placeholder lines and blocks.
lightModeBackgroundStringnoDEFAULT_LIGHTMODE_BG_COLORlight mode background color of placeholder cards.
darkModeBackgroundStringnoDEFAULT_DARKMODE_BG_COLORlight mode background color of placeholder cards.
lightModeShineStringnoDEFAULT_LIGTHMODE_SHINElight mode shine color of placeholder lines and blocks.
darkModeShineStringnoDEFAULT_DARKMODE_SHINElight mode shine color of placeholder lines and blocks.

DEFAULT_LIGHTMODE_LINE_COLOR = "#d7d7d7"
DEFAULT_DARKMODE_LINE_COLOR = "#383838"
DEFAULT_LIGHTMODE_BG_COLOR = "#ffffff"
DEFAULT_DARKMODE_BG_COLOR = "#121212"
DEFAULT_LIGTHMODE_SHINE = "#eeeeee"
DEFAULT_DARKMODE_SHINE = "#6d6c6c"

useTheme()

For accessing useTheme() hook:

import { useTheme } from "react-khatra-placeholder";

//example for toggle theme button
const ToggleTheme = () => {
const { darkTheme, handleTheme } = useTheme();
return <button onClick={() => handleTheme(!darkTheme)}>Toggle Theme</button>;
};

Theming in action:

Here is quick example of how you can use theming options on your projects.

//for providing darkTheme state and handler globally
import { PThemeProvider } from "react-khatra-placeholder";

return (
<PThemeProvider
lightModeBackground="orange"
lightModeColor="brown"
darkModeBackground="lightgreen"
darkModeColor="green"
darkModeShine="lightblue"
>
<KhatraPlaceholder
isLoading={true}
type="ProductPlaceholder"
animateWave
style={{
border: "1px solid brown",
padding: "0.75rem",
borderRadius: "0.75rem",
}}
>
<div>Your Real Product</div>
</KhatraPlaceholder>
<ToggleTheme />
</PThemeProvider>
);