GithubHelp home page GithubHelp logo

react-native-oh-library / platform-colors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from klarna-incubator/platform-colors

0.0 0.0 1.0 972 KB

Generate platform native colors for iOS, Android & Web

License: Apache License 2.0

JavaScript 47.56% Ruby 7.43% TypeScript 45.01%

platform-colors's Introduction

platform-colors Logo

platform-colors

Generate platform native colors for iOS, Android & Web

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

Screenshot in dark mode Screenshot in dark mode

How to contribute

See our changelog.

Deployment

Update version in package.json and merge to master. This will publish the package to NPM, create a draft release on GitHub and a version tag. Edit the release with additional information and publish it.

Copyright ยฉ 2021 Klarna Bank AB

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

platform-colors's People

Contributors

asherlzr avatar danilobuerger avatar moquez avatar oblador avatar ottosichert avatar pontusab avatar starheh avatar

Forkers

starheh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.