Skip to content

Instantly share code, notes, and snippets.

@mmazzarolo
Created December 1, 2019 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmazzarolo/53c246d122514c1cb17ffa418165aac9 to your computer and use it in GitHub Desktop.
Save mmazzarolo/53c246d122514c1cb17ffa418165aac9 to your computer and use it in GitHub Desktop.
Ordinary Puzzles grayscale palette
import tinycolor from "tinycolor2";
import { useColorScheme } from "react-native-appearance";
const primaryColor = "#171520";
const palette = new Array(10).fill(primaryColor).map((color, index) =>
tinycolor(color)
.brighten(index * 10)
.toString()
);
const lightColors = palette;
const darkColors = palette.slice().reverse();
export const useColors = function() {
const colorScheme = useColorScheme();
const colors = {
primary: colorScheme === "dark" ? darkColors : lightColors
};
return colors;
};
@mmazzarolo
Copy link
Author

mmazzarolo commented Dec 1, 2019

Usage:

import { View } from "react-native";
import { useColors } from "./colors";

const ExampleView = function() {
  const colors = useColors();
  const style = {
    backgroundColor: colors[3], // "colors" return the grayscale palette
    width: 50,
    height: 50
  };
  return <View style={style} />
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment