0.5.1 • Published 2 years ago

rn-styler v0.5.1

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Get started

Getting started with rn-styler

What's New?

0.4.0: -Updated useStyler hook: syntax changed, now accepts and returns an array.

0.3.4: -Updated react native version (0.68.0)

0.3.3: -Added out of the box stylized components using useStyler hook

0.3.2:
-Added position class: enum'absolute', 'relative'.
-Added display class: enum'flex', 'none'.
-Added overflow class: enum'visible', 'hidden', 'scroll'.
-Added zIndex computed property: accepts number.
-Added left, right, top, bottom computed properties: accepts number, string(percents),wp(number), hp(number).

0.2.8:
-Introducing useColors hook.

Installation

Install this library with npm:

npm i rn-styler

or using yarn:

yarn add rn-styler

Usage

useStyler hook

Use useStyler hook into your application, to give styles to your components.

Argument must be a single array, with inside arrays of a React Component plus a string with the desired style. It also return an array with the same number array length provided as first and unique argument.

import { View, Text, Pressable } from 'react-native';

const App = () => {
  const [MainView, BlueButton, TextButton] = useStyler([
    [View, 'bg-#c22 flex-1 justify-center items-center'],
    [Pressable, 'rounded-hp(3) w-wp(60) h-wp(20) bg-#22c items-center justify-center',],
    [Text, 'text-white font-bold font-size-hp(1.7) text-center'],
  ]);

  return (
    <MainView>
      <BlueButton>
        <TextButton>I'm a styled pressable button</TextButton>
      </BlueButton>
    </MainView>
  );
}

Example

Theme

Import ThemeProvider wrapper and define some options by passing an object to theme prop.

import {ThemeProvider} from 'rn-styler';

...

<ThemeProvider
    theme={options}
  >
    <App />
  </ThemeProvider>
  • See how to configure your theme options here below

Options

Colors

Pass an object with the custom colors you will need use along your application:

import {ThemeProvider} from 'rn-styler';

const options = {
    colors: {
        navyBlue: '#000080',
    }
}

...

<ThemeProvider
    theme={options}
  >
    <App />
</ThemeProvider>

And use with useStyler hook in your components:

const App = () => {
    const [ViewNavyBlue] = useStyler([
        [View, 'bg-navyBlue',]
    ])

    return (
        <ViewNavyBlue>
            ....
        </ViewNavyBlue>
    )
};
useColors hook

Use useColors hook to get all colors configured in your ThemeProvider.

import { useColors } from 'rn-styler';

const App = () => {
    const colors = useColors();

    return (
        <CustomText color={colors.navyBlue}>
            ....
        </CustomText>
    )
};
Custom Properties

Pass an object with the custom properties you will re-use along your application:

import {ThemeProvider} from 'rn-styler';

const options = {
    properties: {
        customShadow: {
          shadowColor: "#000",
          shadowOffset: {
            width: 0,
            height: 12,
          },
          shadowOpacity: 0.58,
          shadowRadius: 16.00,
          elevation: 24,
        },
        'background-red-fontSize-big-custom-class': {
          backgroundColor: 'red',
          fontSize: 20,
        }
    }
}

...

<ThemeProvider
    theme={options}
  >
    <App />
</ThemeProvider>

And use with useStyler hook in your components:

const App = () => {
    const [CustomView] = useStyler([
        [View, 'customShadow background-red-fontSize-big-custom-class']
    ]);

    return (
        <CustomView>
            ....
        </CustomView>
    )
};

Available Computed Properties

Available computed properties needs a dash following by the desired value

NOTE: wp(number) and hp(number) will calculate the window's width and height. Example: If your device width is 390px, wp(50) will return 195. Also hp(number) its based on device height.

Margin

ClassAffected PropertiesAccepted Values
mmarginnumber, string, wp(number), hp(number)
mtmarginTopnumber, string, wp(number), hp(number)
mrmarginRightnumber, string, wp(number), hp(number)
mbmarginBottomnumber, string, wp(number), hp(number)
mlmarginLeftnumber, string, wp(number), hp(number)
mxmarginLeft, marginRightnumber, string, wp(number), hp(number)
mymarginTop, marginBottomnumber, string, wp(number), hp(number)

Padding

ClassAffected PropertiesAccepted Values
ppaddingnumber, string, wp(number), hp(number)
ptpaddingTopnumber, string, wp(number), hp(number)
prpaddingRightnumber, string, wp(number), hp(number)
pbpaddingBottomnumber, string, wp(number), hp(number)
plpaddingLeftnumber, string, wp(number), hp(number)
pxpaddingLeft, paddingRightnumber, string, wp(number), hp(number)
pypaddingTop, paddingBottomnumber, string, wp(number), hp(number)

Height

ClassAffected PropertiesAccepted Values
hheightnumber, string, wp(number), hp(number)

Min Height

ClassAffected PropertiesAccepted Values
min-hminHeightnumber, string, wp(number), hp(number)

Max Height

ClassAffected PropertiesAccepted Values
max-hmaxHeightnumber, string, wp(number), hp(number)

Width

ClassAffected PropertiesAccepted Values
wwidthnumber, string, wp(number), hp(number)

Min Width

ClassAffected PropertiesAccepted Values
min-wminWidthnumber, string, wp(number), hp(number)

Max Width

ClassAffected PropertiesAccepted Values
max-wmaxWidthnumber, string, wp(number), hp(number)

Left

ClassAffected PropertiesAccepted Values
lleftnumber, string, wp(number), hp(number)

Right

ClassAffected PropertiesAccepted Values
rrightnumber, string, wp(number), hp(number)

Top

ClassAffected PropertiesAccepted Values
ttopnumber, string, wp(number), hp(number)

Bottom

ClassAffected PropertiesAccepted Values
bbottomnumber, string, wp(number), hp(number)

Border Radius

ClassAffected PropertiesAccepted Values
roundedborderRadiusnumber, wp(number), hp(number)
rounded-tlborderTopLeftRadiusnumber, wp(number), hp(number)
rounded-trborderTopRightRadiusnumber, wp(number), hp(number)
rounded-brborderBottomRightRadiusnumber, wp(number), hp(number)
rounded-blborderBottomLeftRadiusnumber, wp(number), hp(number)

Border Width

ClassAffected PropertiesAccepted Values
border-bborderBottomWidthnumber, wp(number), hp(number)
border-eborderEndWidthnumber, wp(number), hp(number)
border-lborderLeftWidthnumber, wp(number), hp(number)
border-rborderRightWidthnumber, wp(number), hp(number)
border-sborderStartWidthnumber, wp(number), hp(number)
border-tborderTopWidthnumber, wp(number), hp(number)
border-wborderWidthnumber, wp(number), hp(number)

Background Color

ClassAffected PropertiesAccepted Values
bgbackgroundColorColor (See Constants Section), Hexadecimal color

Color

ClassAffected PropertiesAccepted Values
color (text also might work)colorColor (See Constants Section), Hexadecimal color

Font Size

ClassAffected PropertiesAccepted Values
font-sizefontSizenumber, wp(number), hp(number)

Flex

ClassAffected PropertiesAccepted Values
flexflexnumber

Flex Shrink

ClassAffected PropertiesAccepted Values
flex-shrinkflexShrinknumber

Flex Grow

ClassAffected PropertiesAccepted Values
flex-growflexGrownumber

Aspect Ratio

ClassAffected PropertiesAccepted Values
aspectaspectRationumber

Z Index

ClassAffected PropertiesAccepted Values
zzIndexnumber

Available predefined properties

Direction

Direction

ClassProperties
dir-inheritdirection: 'inherit'
dir-ltrdirection: 'ltr'
dir-rtldirection: 'rtl'

Display

Display

ClassProperties
d-flexdisplay: 'flex'
d-nonedisplay: 'none'

Flex

Align Content
ClassProperties
content-startalignContent: 'flex-start'
content-endalignContent: 'flex-end'
content-stretchalignContent: 'stretch'
content-centeralignContent: 'center'
content-betweenalignContent: 'space-between'
content-aroundalignContent: 'space-around'
Align Items
ClassProperties
items-startalignItems: 'flex-start'
items-endalignItems: 'flex-end'
items-centeralignItems: 'center'
items-baselinealignItems: 'baseline'
items-stretchalignItems: 'stretch'
Align Self
ClassProperties
self-startalignSelf: 'flex-start'
self-endalignSelf: 'flex-end'
self-centeralignSelf: 'center'
self-baselinealignSelf: 'baseline'
self-stretchalignSelf: 'stretch'
Flex Direction
ClassProperties
flex-colflexDirection: 'column'
flex-rowflexDirection: 'row'
flex-col-reverseflexDirection: 'column-reverse'
flex-row-reverseflexDirection: 'row-reverse'
Flex Wrap
ClassProperties
flex-wrapflexWrap: 'wrap'
flex-nowrapflexWrap: 'nowrap'
flex-wrap-reverseflexWrap: 'wrap-reverse'
Justify Content
ClassProperties
justify-startjustifyContent: 'flex-start'
justify-endjustifyContent: 'flex-end'
justify-centerjustifyContent: 'center'
justify-betweenjustifyContent: 'space-between'
justify-aroundjustifyContent: 'space-around'
justify-evenlyjustifyContent: 'space-evenly'

Font

Font Weight

ClassProperties
font-thinfontWeight: '100'
font-extralightfontWeight: '200'
font-lightfontWeight: '300'
font-normalfontWeight: '400'
font-mediumfontWeight: '500'
font-semiboldfontWeight: '600'
font-boldfontWeight: '700'
font-extraboldfontWeight: '800'
font-blackfontWeight: '900'

Position

Position

ClassProperties
relativeposition: 'relative'
absoluteposition: 'absolute'

Overflow

Overflow

ClassProperties
overflow-visibleoverflow: 'visible'
overflow-hiddenoverflow: 'hidden'
overflow-scrolloverflow: 'scroll'

Text

Text Align

ClassProperties
text-autotextAlign: 'auto'
text-lefttextAlign: 'left'
text-centertextAlign: 'center'
text-righttextAlign: 'right'
text-justifytextAlign: 'justify'

Constants

Colors

CodeValue
blue-50'#EFF6FF'
blue-100'#DBEAFE'
blue-200'#BFDBFE'
blue-300'#93C5FD'
blue-400'#60A5FA'
blue-500'#3B82F6'
blue-600'#2563EB'
blue-700'#1D4ED8'
blue-800'#1E40AF'
blue-900'#1E3A8A'
yellow-50'#FFFBEB'
yellow-100'#FEF3C7'
yellow-200'#FDE68A'
yellow-300'#FCD34D'
yellow-400'#FBBF24'
yellow-500'#F59E0B'
yellow-600'#D97706'
yellow-700'#B45309'
yellow-800'#92400E'
yellow-900'#78350F'
red-50'#FEF2F2'
red-100'#FEE2E2'
red-200'#FECACA'
red-300'#FCA5A5'
red-400'#F87171'
red-500'#EF4444'
red-600'#DC2626'
red-700'#B91C1C'
red-800'#991B1B'
red-900'#7F1D1D'
purple-50'#F5F3FF'
purple-100'#EDE9FE'
purple-200'#DDD6FE'
purple-300'#C4B5FD'
purple-400'#A78BFA'
purple-500'#8B5CF6'
purple-600'#7C3AED'
purple-700'#6D28D9'
purple-800'#5B21B6'
purple-900'#4C1D95'
pink-50'#FDF2F8'
pink-100'#FCE7F3'
pink-200'#FBCFE8'
pink-300'#F9A8D4'
pink-400'#F472B6'
pink-500'#EC4899'
pink-600'#DB2777'
pink-700'#BE185D'
pink-800'#9D174D'
pink-900'#831843'
indigo-50'#EEF2FF'
indigo-100'#E0E7FF'
indigo-200'#C7D2FE'
indigo-300'#A5B4FC'
indigo-400'#818CF8'
indigo-500'#6366F1'
indigo-600'#4F46E5'
indigo-700'#4338CA'
indigo-800'#3730A3'
indigo-900'#312E81'
green-50'#ECFDF5'
green-100'#D1FAE5'
green-200'#A7F3D0'
green-300'#6EE7B7'
green-400'#34D399'
green-500'#10B981'
green-600'#059669'
green-700'#047857'
green-800'#065F46'
green-900'#064E3B'
gray-50'#F9FAFB'
gray-100'#F3F4F6'
gray-200'#E5E7EB'
gray-300'#D1D5DB'
gray-400'#9CA3AF'
gray-500'#6B7280'
gray-600'#4B5563'
gray-700'#374151'
gray-800'#1F2937'
gray-900'#111827'
0.5.1

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.7

3 years ago

0.1.8

3 years ago

0.2.6

3 years ago

0.1.7

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.1.9

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.1.6

3 years ago

0.2.4

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago