{"id":20324159,"url":"https://github.com/klarna-incubator/platform-colors","last_synced_at":"2025-04-09T20:12:53.563Z","repository":{"id":43038254,"uuid":"346990846","full_name":"klarna-incubator/platform-colors","owner":"klarna-incubator","description":"Generate platform native colors for iOS, Android \u0026 Web","archived":false,"fork":false,"pushed_at":"2022-10-28T09:23:19.000Z","size":960,"stargazers_count":108,"open_issues_count":2,"forks_count":10,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-09T20:12:47.096Z","etag":null,"topics":["android","css","ios","klarna-featured","react","react-native","web"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klarna-incubator.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-12T08:15:08.000Z","updated_at":"2025-03-07T06:42:50.000Z","dependencies_parsed_at":"2023-01-20T03:02:05.446Z","dependency_job_id":null,"html_url":"https://github.com/klarna-incubator/platform-colors","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna-incubator%2Fplatform-colors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna-incubator%2Fplatform-colors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna-incubator%2Fplatform-colors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna-incubator%2Fplatform-colors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klarna-incubator","download_url":"https://codeload.github.com/klarna-incubator/platform-colors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103872,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","css","ios","klarna-featured","react","react-native","web"],"created_at":"2024-11-14T19:32:42.735Z","updated_at":"2025-04-09T20:12:53.531Z","avatar_url":"https://github.com/klarna-incubator.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://user-images.githubusercontent.com/26433/110946195-e2ba4000-833e-11eb-986f-58992913aa27.png\" alt=\"platform-colors Logo\" width=\"500\"\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003eplatform-colors\u003c/h1\u003e\n  \u003ch3 align=\"center\"\u003eGenerate platform native colors for iOS, Android \u0026 Web\u003c/h3\u003e\n\u003c/p\u003e\n\n[![Build Status][ci-image]][ci-url]\n[![NPM Package][npm-image]][npm-url]\n[![License][license-image]][license-url]\n[![Developed at Klarna][klarna-image]][klarna-url]\n\nUsing 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.\n\nUnder the hood we are using [`PlatformColor`](https://reactnative.dev/docs/platformcolor) on React Native and [CSS custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) on web.\n\n## Features\n\n### Easy to use\n\nType/JavaScript constants are generated automatically – using it with React/Native is as simple as importing the color name.\n\n### Fast\n\nUsing platform colors enables you to change from light/dark mode instantly and without any additional rerenders.\n\n### Accessible\n\nBy utilizing the underlying platforms high contrast colors are supported out of the box.\n\n## Usage\n\n```sh\nnpx @klarna/platform-colors\n```\n\nThe 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:\n\n```js\n// platform-colors.config.js\nmodule.exports = {\n  colors: {\n    background: {\n      light: '#ffffff',\n      dark: '#000000',\n    },\n    accent: 'pink',\n  },\n  javascript: {\n    typescript: true,\n    outputDirectory: 'src/colors/',\n  },\n  ios: {\n    outputDirectory: 'ios/YourApp/Images.xcassets/',\n  },\n  android: {\n    outputDirectory: 'android/app/src/main/res/',\n  },\n  css: {\n    outputDirectory: 'static/css/',\n  },\n};\n```\n\n**NOTE:** You need to re-run the command after each change to the config to update the generated files.\n\nNow go ahead and inspect your android, ios and web folders. You should have your color definitions on each platform.\n\n### Configuration\n\n#### `colors`\n\nAn object where the key is the color name, and the value is either a string or an object containing `light` and optionally `highContrastLight`, `dark` \u0026 `highContrastDark` properties.\n\nExample:\n\n```js\n{\n  colors: {\n    contrasted: {\n      light: '#ccc',\n      highContrastLight: '#fff',\n      dark: '#333',\n      highContrastDark: '#000',\n    }\n  }\n}\n```\n\n#### `ios`\n\nAn object containing `outputDirectory` which should be an `.xcassets` directory.\n\nExample:\n\n```js\n{\n  ios: {\n    outputDirectory: 'ios/YourProject/Assets.xcassets/'\n  }\n}\n```\n\n#### `android`\n\nAn object containing `outputDirectory` which should be an Android `res` directory.\n\nExample:\n\n```js\n{\n  android: {\n    outputDirectory: 'android/app/src/main/res/'\n  }\n}\n```\n\n#### `css`\n\nAn 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`.\n\nExample:\n\n```js\n{\n  css: {\n    filename: 'example.css',\n    outputDirectory: 'static/css/'\n  }\n}\n```\n\n#### `javascript`\n\nAn 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.\n\nExample:\n\n```js\n{\n  \"javascript\": {\n    \"typescript\": true,\n    \"outputDirectory\": \"src/colors/\"\n  }\n}\n```\n\n### Getting hex value from dynamic color\n\n\u003e Note: You must first make sure you've added `@klarna/platform-colors` as a dependency and recompiled the app.\n\n```js\nimport { PlatformColor } from 'react-native';\nimport { resolveColorSync } from '@klarna/platform-colors';\n\nconst hexColor = resolveColorSync(PlatformColor('colorName'));\n```\n\n#### `prefix`\n\nWe prefix all colors with `rnpc_` by default, you can override that with this option.\n\nExample:\n\n```js\n{\n  prefix: 'custom_',\n  // colors...\n}\n```\n\n## Development Setup\n\nInstall dependencies and make sure the tests are working\n\n```sh\nyarn install\nyarn test\n```\n\n### Example App\n\nThere's an example React Native App available to test under the examples app.\n\n```sh\ncd examples/ColorViewerApp\nyarn\npod install --project-directory=ios\n```\n\nRunning it either on ios or android by:\n\n```sh\nyarn ios\n```\n\nor\n\n```sh\nyarn android\n```\n\n#### Screenshots\n\n\u003cimg src=\"https://user-images.githubusercontent.com/378279/110977509-8a953500-8362-11eb-9b79-edfed85e6408.png\" width=\"200\" height=\"433\" alt=\"Screenshot in dark mode\" /\u003e \u003cimg src=\"https://user-images.githubusercontent.com/378279/110977517-8cf78f00-8362-11eb-98c2-9b0b634ee327.png\" width=\"200\" height=\"433\" alt=\"Screenshot in dark mode\" /\u003e\n\n## How to contribute\n\nSee our [changelog](CHANGELOG.md).\n\n## Deployment\n\nUpdate 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.\n\nCopyright © 2021 Klarna Bank AB\n\nFor license details, see the [LICENSE](LICENSE) file in the root of this project.\n\n\u003c!-- Markdown link \u0026 img dfn's --\u003e\n\n[ci-image]: https://img.shields.io/github/workflow/status/klarna-incubator/platform-colors/Tests?style=flat-square\n[ci-url]: https://github.com/klarna-incubator/platform-colors/actions/workflows/tests.yml\n[npm-image]: https://img.shields.io/npm/v/@klarna/platform-colors?style=flat-square\n[npm-url]: https://www.npmjs.com/package/@klarna/platform-colors\n[license-image]: https://img.shields.io/badge/license-Apache%202-blue?style=flat-square\n[license-url]: http://www.apache.org/licenses/LICENSE-2.0\n[klarna-image]: https://img.shields.io/badge/%20-Developed%20at%20Klarna-black?labelColor=ffb3c7\u0026style=flat-square\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAYAAAAmL5yKAAAAAXNSR0IArs4c6QAAAIRlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAALQAAAAAQAAAtAAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAABCgAwAEAAAAAQAAAA4AAAAA0LMKiwAAAAlwSFlzAABuugAAbroB1t6xFwAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAVBJREFUKBVtkz0vREEUhsdXgo5qJXohkUgQ0fgFNFpR2V5ClP6CQu9PiB6lEL1I7B9A4/treZ47c252s97k2ffMmZkz5869m1JKL/AFbzAHaiRbmsIf4BdaMAZqMFsOXNxXkroKbxCPV5l8yHOJLVipn9/vEreLa7FguSN3S2ynA/ATeQuI8tTY6OOY34DQaQnq9mPCDtxoBwuRxPfAvPMWnARlB12KAi6eLTPruOOP4gcl33O6+Sjgc83DJkRH+h2MgorLzaPy68W48BG2S+xYnmAa1L+nOxEduMH3fgjGFvZeVkANZau68B6CrgJxWosFFpF7iG+h5wKZqwt42qIJtARu/ix+gqsosEq8D35o6R3c7OL4lAnTDljEe9B3Qa2BYzmHemDCt6Diwo6JY7E+A82OnN9HuoBruAQvUQ1nSxP4GVzBDRyBfygf6RW2/gD3NmEv+K/DZgAAAABJRU5ErkJggg==\n[klarna-url]: https://klarna.github.io\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklarna-incubator%2Fplatform-colors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklarna-incubator%2Fplatform-colors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklarna-incubator%2Fplatform-colors/lists"}