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

@radicalcondor/react-native-background-readable-color

v0.1.0

Published

A react native component that sets the text color to a readable color given a background color

Downloads

162

Readme

@radicalcondor/react-native-background-readable-color

A React Native package that provides:

  • A component that takes a backgroundColor and returns a readable color through a render prop
  • A text component that takes a backgroundColor and changes its color to a readable color
  • A hook that returns a readable color given another color
  • Memoized versions of the above
  • Mechanism for getting/setting preset colors

Background

I wanted a text component that was background color aware. Initially, I thought I could get a reference to the parent component and retrieve the background color, but I couldn't find a way to reliably achieve that. So I came up with the next best thing I could think of, a wrapper component that receives a backgroundColor and renders any text inside it with a readable color.

Installation

yarn add @radicalcondor/react-native-background-readable-color

Example

You can run the example project by doing

yarn

It will exit 1 here, but that's okay. and then

cd example
yarn
yarn pods

then

yarn ios

or

yarn android

Usage

useBackgroundReadableColor / useBackgroundReadableColorMemo hook

    backgroundColor?: string;
    presetName?: string;
import { Text } from 'react-native' 
import { useBackgroundReadableColorMemo } from "@radicalcondor/react-native-background-readable-color";

const props = {
  backgroundColor: '#000',
  presetName: undefined,
};

const color = useBackgroundReadableColorMemo(props);

BackgroundReadableColorText component

    backgroundColor?: string;
    children: string;
    presetName?: string;
    render: any;
    useMemo?: boolean;
import { Text } from 'react-native' 
import BackgroundReadableColorText from "@radicalcondor/react-native-background-readable-color";

const bgColor = 'black';

<BackgroundReadableColorText backgroundColor={bgColor} render={Text}>
    A readable color text in white
</BackgroundReadableColorText>

BackgroundReadableColor component

    backgroundColor?: string;
    presetName?: string;
    render: (color?: string) => React.ReactNode;
    useMemo?: boolean;
import { Text } from 'react-native' 
import { BackgroundReadableColor } from "@radicalcondor/react-native-background-readable-color";

const bgColor = 'white';

<ReadableBackgroundColor
    backgroundColor={bgColor}
    render={(color?: string) => <Text style={{color: color || 'cyan'}}>A readable color text in black</Text>}
/>

using ReadablePresets

You can create presets for your readable colors, it takes a name and an object with a dark color, that will try to be used on a dark background and a light color for light backgrounds. ReadablePresets is a singleton and the configuration can be done anywhere in your project.

    dark?: string;
    light?: string;
import { Text } from 'react-native' 
import BackgroundReadableColorText, { ReadablePresets } from "@radicalcondor/react-native-background-readable-color";

ReadablePresets.setPreset('RED', {
    dark: '#ff9c9c', // color to be used if its a dark background
    light: '#6d0000', // color to be used if its a light background
});

const bgColor = 'black';

<BackgroundReadableColorText backgroundColor={bgColor} render={Text}>
    A readable color text in #ff9c9c
</BackgroundReadableColorText>

This package uses readableColor function from polished lib to compute the colors. If you would like to read more check here.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT