0.0.3 • Published 8 months ago

@poncegl/theme v0.0.3

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

@poncegl/theme

A simple React Native library, to keep your color palette organized.

Demo

demo-@poncegl-theme

Installation

  npm i @poncegl/theme
  yarn add @poncegl/theme

Usage/Examples

Wrap your application with the ThemeProvider component. Enable DarkMode Android and iOS support.

import {ThemeProvider} from '@poncegl/theme';

export default function App(): JSX.Element {
  return (
    <ThemeProvider>
      <Main />
    </ThemeProvider>
  );
}

Hook

Access the color palette from any component with the custom hook useTheme.

import {useTheme} from '@poncegl/theme';

export default function Main(): JSX.Element {
  const {colors} = useTheme();

  return (
    <SafeAreaView
      style={[
        styles.content,
        {
          backgroundColor: colors.background,
        },
      ]}>
      <View style={styles.content}>
        <Text
          style={{
            color: colors.text,
          }}>
          Main
        </Text>
      </View>
    </SafeAreaView>
  );
}

Convert hexadecimal to RGBA colors

The function 'hexToRGBA' receives two parameters, a hexadecimal color and a number representing the opacity you want it to have.

The function returns the same color converted to RGBA with the indicated opacity.

import {hexToRGBA} from '@poncegl/theme';

Custom color palette

The ThemeProvider component receives the options prop is an object of type OptionsTheme.

import {hexToRGBA, OptionsTheme, ThemeProvider} from '@poncegl/theme';

import Main from './src/content/main';

const myCustomTheme: OptionsTheme = {
  colors: {
    primary: hexToRGBA('#1e40af', 1),
    accent: hexToRGBA('#1e3a8a', 1),
    text: hexToRGBA('#ffffff', 1),
    background: hexToRGBA('#9ca3af', 1),
    surface: hexToRGBA('#60a5fa', 1),
    info: hexToRGBA('#1d4ed8', 1),
    error: hexToRGBA('#dc2626', 1),
    success: hexToRGBA('#4ade80', 1),
    onSurface: hexToRGBA('#ffffff', 1),
    white: hexToRGBA('#ffffff', 1),
    black: hexToRGBA('#000000', 1),
    disabled: hexToRGBA('#1e3a8a', 0.5),
    placeholder: hexToRGBA('#ffffff', 0.7),
    backdrop: hexToRGBA('#000000', 0.5),
    notification: hexToRGBA('#000000', 0.5),
    tooltip: hexToRGBA('#f97316', 1),
  },v
};

export default function App(): JSX.Element {
  return (
    <ThemeProvider options={myCustomTheme}>
      <Main />
    </ThemeProvider>
  );
}

ColorsTheme

property: the name inside the object colors initial value: is the initial color of the available colors rgba: is the color created via hexToRGBA type: is the data type, ColorValue comes from React Native

propertyinitial valuergbasampletype
primaryblue[800]rgba(30, 64, 175, 1)#1e40afColorValue
accentblue[900]rgba(30, 58, 138, 1)#1e3a8aColorValue
textwhitergba(255, 255, 255, 1)#ffffffColorValue
backgroundgray[400]rgba(156, 163, 175, 1)#9ca3afColorValue
surfaceblue[400]rgba(96, 165, 250, 1)#60a5faColorValue
infoblue[700]rgba(29, 78, 216, 1)#1d4ed8ColorValue
errorred[600]rgba(220, 38, 38, 1)#dc2626ColorValue
successgreen[400]rgba(74, 222, 128, 1)#4ade80ColorValue
onSurfacewhitergba(255, 255, 255, 1)#ffffffColorValue
whitewhitergba(255, 255, 255, 1)#ffffffColorValue
blackblackrgba(0, 0, 0, 1)#000000ColorValue
disabledblue[900]rgba(30, 58, 138, 0.5)#1e3b8a80ColorValue
placeholderwhitergba(255, 255, 255, 1)#ffffffb3ColorValue
backdropblackrgba(0, 0, 0, 1)#00000080ColorValue
notificationblackrgba(0, 0, 0, 1)#00000080ColorValue
tooltiporange[500]rgba(249, 115, 22, 1)#f97316ColorValue

Colors

More colors available

import {blue, green, pink} from '@poncegl/theme';

Authors

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago