1.1.8 • Published 9 months ago

@front-app-react/theme v1.1.8

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

React Themeing

This package is a powerful tool for designing and managing the style and language of react applications, which helps developers to easily and with minimal effort create custom designs and user interfaces.
Using this package, you will be able to easily manage different styles such as colors, fonts, sizes, color combinations and other appearance elements in your application.
support type ThemeDefault styled-components

Demo

demo for using demo-front-app-react

Installing

npm i @front-app-react/theme

Default configuration if fetch was not specified

First, create the following folders and files in the server asset path
For example, it is created in the path of public folders

  • public
    • langs
      • {langName}.json
      • en-US.json
    • theme
      • sizing.json
      • colors
        • {colorName}.json
        • light.json
  • src
  • package.json

The name of the langs, theme, colors folder and the sizing.json file should be the same
The extension of the data file must be json

If you use a special method to receive information, it is not necessary for the path of the files to be this way, but the file extension and name should be the same.

The Gist

They use React context to hook into the parent state/methods.

import { ThemeProvider } from "@front-app-react/theme";
    <ThemeProvider prefix="app" defaultLang="en-US" defaultColor="light">
        ...otherCode
    </ThemeProvider>

ThemeProvider Props

propstypedescription
prefixstringprefix for storage, default = app storage
defaultLangstring or LangDataThe name you chose for the language in the assets path  or LangData has Similar to language json file
defaultColorstring or ColorDataThe name you chose for the color in the assets path or ColorData has Similar to color json file
defaultSizingSizingDataSizingData has Similar to sizing json file = default undefined
storageStorageYou can use browser memory type objects such as localstorage, sessionStorage, cookie and dedicated memory = default undefined
fetchLang ((code:string)=> Promise<LangData>)A method that takes the input of the name of the language data file and returns the language data as async
fetchColor((code:string)=> Promise<ColorData>)A method that takes the input of the name of the color data file and returns the color data as async
fetchSizing(()=> Promise<SizingData>)A method that gives SizingData without input and response in async

LangData

Values for language data must follow this format

propertytypedescription
theme.dir*"ltr" or "rtl"Should be rtl or ltr
theme.locale*stringThe name you chose for the language in the assets path
theme.language*stringanything
theme.langLabel*stringanything
other key selectorstringAnother value you want to use in the theme

ColorData

Values for color data must follow this format

propertytypedescription
namestringThe name you chose for the color in the assets path
data{property : value}List of colors

SizingData

Values for sizing data must follow this format

propertytypedescription
btn{property : value}List button element of sizes
input{property : value}List input element of sizes
propertyvalueOther sizes

hook context theme

You can use React Context hook to get theme values

import { useTheme } from "@front-app-react/theme";

  const { lang, style } = useTheme();

lang

propertytypedescription
dictionaryLangDataLangData has Similar to language json file
loadingbooleanCheck the data received
onChange(code or LangData)=> PromiseIt can change the language with two input types - The name of the language file - Language data

style

propertytypedescription
colorColorDataColorData has Similar to color json file
sizingSizingDataSizingData has Similar to sizing json file
loadingbooleanCheck the two data received
loadingColorbooleanCheck the data color received
loadingSizingbooleanCheck the data sizing received
onChange(code or SizingData)=> PromiseIt can change the color with two input types - The name of the color file - color data
getColorname,mood,opacityGet color value from color name in 5 levels 0,1,2,3,4 and opacity

Type Color

propertyvalue
namestring
opacitybetween 0,1
mood-2,-1,0,1,2

Type ThemeColor

propertyvalue
variant *Type Color
hoverType Color
activeType Color

Packages

List of packages used:

  • checkSizing - Getting the defined sizes of the theme
  • getColorWithKeyCss - Make css color style from the theme
  • colorHandler - Making theme coloring styles element

checkSizing

Description

Sizes such as padding and radius are defined in the @front-app-react/theme package.
We can create normal, small, and large sizes with the style name
Sample using in https://github.com/front-app-react/elements (coming)

Usage

dev

const Typography = styled("p")`
    color : ${themeProps=> themeProps.theme.style.getColor("red")};
    ${themeProps=> {
        return checkSizing({ keyCss : "font-size", props : themeProps,keyJson : "btn.font-size" }) + ";";
    }
`
export default ()=> {
    return (
        <Typography $sizing="lg">Hello world</Typography>
    )
}

result

const Typography = styled("p")`
    color : #E16262;
    ${themeProps=> {
        return "font-size : 1.25rem;";
    }
`

Argument 1

type object

propertydescription
keyCssproperty css
propstheme props
keyJsonkey reference sizing theme example sizing.json

Value

The output value is property: value in css

getColorWithKeyCss

Description

Make css color style from the theme

Usage

dev

const Button = styled("button")`
    ${themeProps=> {
        return getColorWithKeyCss({ name : "background-color",color : "red", props : themeProps }) + ";";
    }
`

result

const Button = styled("button")`
     color : #E16262;
    ${themeProps=> {
        return "color : #E16262;";
    }
`

Argument 1

type object

propertydescription
nameproperty css
colortheme color property name
propstheme props

Value

The output value is property: value in css

colorHandler

Description

Creates an element with color style, background color and border color with handle of mouse hover and active modes.
It is necessary to talk about the configuration color of the package @front-app-react/elements

Usage

dev

const Button = styled("button")`
    ${themeProps=> {
        return colorHandler(props, true) + ";";
    }
`
const ButtonWithoutStyleActions = styled("button")`
    ${themeProps=> {
        return colorHandler(props, false) + ";";
    }
`
export default ()=> {
    return (
        <Button $textColor={{
              variant: {
                name: "white",
              },
        }} $bgColor={{
              variant: {
                name: "primary",
              },
              active: {
                name: "red",
              },
        }} $borderColor={{
              variant: {
                name: "primary",
              },
        }}>Hello world</Button>
         <ButtonWithoutStyleActions $textColor={{
              variant: {
                name: "white",
              },
        }} $bgColor={{
              variant: {
                name: "primary",
              },
        }} $borderColor={{
              variant: {
                name: "primary",
              },
        }}>Hello world</Button>
    )
}

result

const Button = styled("button")`
    &:disabled{
         color: #5D5D5D;
        background-color: #f0f0f0;
        border-color: #f0f0f0;
  }

    &:not(:disabled) {
    color: rgb(255, 255, 255);
    background-color: rgb(58, 150, 121);
    border-color: rgb(58, 150, 121);
     &:hover {
        color: rgb(255, 255, 255);
        background-color: rgb(58, 150, 121);
        border-color: rgb(58, 150, 121);
    }
     &:active {
        color: rgb(255, 255, 255);
        background-color: rgb(225, 98, 98);
        border-color: rgb(225, 98, 98);
    }
    }
`
const ButtonWithoutStyleActions = styled("button")`
    &:not(:disabled) {
    color: rgb(255, 255, 255);
    background-color: rgb(58, 150, 121);
    border-color: transparent;
    }
`

Argument 1

type object

propertydescription
$textColorThemeColor
$bgColorThemeColor
$borderColorThemeColor
$isActivetype boolean, handle active mode

Argument 2

type boolean
handle of mouse hover and active modes

Value

The output value is multi property: value in css

1.1.8

9 months ago

1.1.7

9 months ago

1.1.6

10 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.0

11 months ago

1.0.5

11 months ago

1.0.3

12 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago