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

@cutls/platform-colors

v0.4.0

Published

Generate platform native colors for iOS, Android & Web

Downloads

3

Readme

Build Status NPM Package License Developed at Klarna

Using colors from the underlying platform primitives is powerful, but maintaining it when targeting multiple platforms is quite cumbersome. With this CLI you can generate colors and entrypoint for both iOS, Android, and Web with ease.

Under the hood we are using PlatformColor on React Native and CSS custom properties on web.

Features

Easy to use

Type/JavaScript constants are generated automatically – using it with React/Native is as simple as importing the color name.

Fast

Using platform colors enables you to change from light/dark mode instantly and without any additional rerenders.

Accessible

By utilizing the underlying platforms high contrast colors are supported out of the box.

Usage

npx @klarna/platform-colors

The first time you run the command it will prompt you which platforms you want to generate files for which will create a file with the following format:

// platform-colors.config.js
module.exports = {
  "colors": {
    "background": {
      "light": "#ffffff",
      "dark": "#000000"
    },
    "accent": "pink"
  },
  "javascript": {
    "typescript": true,
    "outputDirectory": "src/colors/"
  },
  "ios": {
    "outputDirectory": "ios/YourApp/Images.xcassets/"
  },
  "android": {
    "outputDirectory": "android/app/src/main/res/"
  },
  "css": {
    "outputDirectory": "static/css/"
  }
};

NOTE: You need to re-run the command after each change to the config to update the generated files.

Now go ahead and inspect your android, ios and web folders. You should have your color definitions on each platform.

Configuration

colors

An object where the key is the color name, and the value is either a string or an object containing light and optionally highContrastLight, dark & highContrastDark properties.

Example:

{
  colors: {
    contrasted: {
      light: '#ccc',
      highContrastLight: '#fff',
      dark: '#333',
      highContrastDark: '#000',
    }
  }
}

ios

An object containing outputDirectory which should be an .xcassets directory.

Example:

{
  ios: {
    outputDirectory: 'ios/YourProject/Assets.xcassets/'
  }
}

android

An object containing outputDirectory which should be an Android res directory.

Example:

{
  android: {
    outputDirectory: 'android/app/src/main/res/'
  }
}

css

An object containing outputDirectory and filename which should be a directory where you store CSS files and if you want to change the default filename from colors.css.

Example:

{
  css: {
    filename: 'example.css',
    outputDirectory: 'static/css/'
  }
}

javascript

An object containing outputDirectory which should be a directory where you store your Type/JavaScript files and typescript which is set to true if you want the output in TypeScript.

Example:

{
  "javascript": {
    "typescript": true,
    "outputDirectory": "src/colors/"
  }
}

Getting hex value from dynamic color

Note: You must first make sure you've added @klarna/platform-colors as a dependency and recompiled the app.

import { PlatformColor } from 'react-native';
import { resolveColorSync } from '@klarna/platform-colors';

const hexColor = resolveColorSync(PlatformColor('colorName'));

prefix

We prefix all colors with rnpc_ by default, you can override that with this option.

Example:

{
  prefix: 'custom_',
  // colors...
}

Development Setup

Install dependencies and make sure the tests are working

yarn install
yarn test

Example App

There's an example React Native App available to test under the examples app.

cd examples/ColorViewerApp
yarn
pod install --project-directory=ios

Running it either on ios or android by:

yarn ios

or

yarn android

Screenshots

How to contribute

See our changelog.

Copyright © 2021 Klarna Bank AB

For license details, see the LICENSE file in the root of this project.