npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-pretext

v1.0.8

Published

Style text components using String-prefixes

Downloads

12

Readme

Pretext

Style your Text components using prefixes!

Pretext handles your styles inside the string itself, by adding styles based on a given string of 'prefixes'.

Checkout this link for a Live Demo.

Clone my test repo if you are having trouble using.

$ git clone https://github.com/ouoru/react-native-pretext-tests.git

Description

react-native-pretext allows you to intricately style Text Components.

This is NOT what you are looking for if:

  • You want to manage a StyleSheet for your whole app

This may be what you are looking for if:

  • You need to store and read styled Text components from a database
  • You need different text styles in an individual string
  • You use complex strings with variable text positions

Install

Install with npm:

$ npm i react-native-pretext

Usage

  • Configure Context
import { Context } from 'react-native-pretext'

const defaultStyle = {
    fontFamily: 'MyFont',
    fontSize: 12,
    color: '#FFFFFF'
}

const context = {
    p: {
        color: 'purple'
    }
    r: {
        color: 'red'
    },
}

const config = {}

Context.give(defaultStyle, context, config)
  • Use Pretext Component as you would use a Text Component, but add the styles you want as a Prefix.
import { Pretext } from 'react-native-pretext'

<Pretext>[p]Hello World!</Pretext>
  • Pretext will style your text according to the context you initialized! In this case, defaultStyle is applied to the Text as well as the style of p in our context, color: 'purple'.
<Text style={{ fontFamily: 'MyFont', fontSize: 12, color: 'purple' }}>Hello World!</Text>

##Advanced Usage

  • You can pass context props to a Pretext component to override your default settings.
<Pretext
    style={extraStyle}
    config={extraConfig}
>[p]Hello World!</Pretext>

API

defaultStyle

This is the style given to the parent Text Component

context

Your StyleSheet, Pretext will check if prefix exists in your context

  • We recommend you to use the following guidelines when creating your StyleSheet for ease of use. Note that these are just recommendations, you may need different guidelines depending on what styles you are using. Our recommendations are just to make life easier.

| Styling | Type | Example | Why | | :------: | :------: | :-----: | :--- | | color | letter | a | Associating a color with a letter is simply the easiest to remember. | | backgroundColor, borderColor | capital letter | A | Same reasoning as colors. | | fontSize/lineHeight, opacity, letterSpacing | number | 1 | Associating value with proportional numbers. You probably won't need 10 (0-9) different styles for each property, so you could use something like 0-4 for fontSize, and 5-9 for opacity. | | fontFamily, textAlign, ... | symbol | @, #, ... | This is only recommended for styling props that either won't change often, or will only be set to one or two other values. |

config

| Name | Type | default | Description | | :---- | :------: | :------: | :--- | | styleStart | string | [ | we perform a .split() using the given character to separate the string | | styleEnd | string | ] | tells us when to stop looking for prefixes |