Skip to content

dejakob/react-native-component-styler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Native Component Styler

NPM

Lib to create UI components in React Native

Based on React Native Styler. Don't forget to include import { StylerProvider } from 'react-native-styler'; into your project!

createStyledComponent method

The createStyledComponent method expects three parameters:

  • variants (collection of strings)
  • style definition (object)
  • component function

Describe the component

    import { createStyledComponent } from 'react-native-component-styler';
    import MyComponentView from './View';
    import style from './style.json';

    const VARIANTS = [
        'DEFAULT',
        'PRIMARY',
        'FOCUS'
    ]

    export default createStyledComponent(
        VARIANTS,
        style,
        MyComponentView
    );

Style definition (can be json)

The style definition needs three levels:

  • Element name
    • Variant
      • Style property

All functionality of React Native Styler can be used inside this definition.

    {
        "Container": {
            "DEFAULT": {
                "backgroundColor": "theme:sheet"
            }
        },
        "TextInput": {
            "DEFAULT": {
                "width": "100%"
            },
            "FOCUS": {
                "borderBottomColor": "theme:accent"
            }
        }
    }

Component function (stateless component)

    function MyComponentView(props, s) {
        return (
            <View
                style={s('Container')}
            >
                <TextInput
                    style={s('TextInput')}
                />
            </View>
        );
    }

    export default MyComponentView;

addGlobalContainerVariants method

Add variants to all elements named Container. One use case can be spacing

    addGlobalContainerVariants({
        SPACE: {
            marginBottom: '4h4s'
        }
    })

About

React Native Component Styler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published