tesk9 / palette

Define, blend, and generate Colors and Palettes in Elm.
https://package.elm-lang.org/packages/tesk9/palette/latest
BSD 3-Clause "New" or "Revised" License
28 stars 2 forks source link

Add Color.black, Color.white? #25

Open ianmackenzie opened 4 years ago

ianmackenzie commented 4 years ago

Would it make sense to add Color.black and Color.white as convenient alternatives to Color.fromRGB ( 0, 0, 0 ) and Color.fromRGB ( 255, 255, 255 )? I realize that they exist in the X11 palette but it seems a bit awkward to import Palette.X11 and then write X11.black/X11.white. I've run into this a little bit when updating my elm-3d-scene examples to use the Color type from this package, and I think it would come up even more often for things like 2D drawings.

Happy to make a PR if you'd like!

tesk9 commented 4 years ago

I'm a little torn on this! It would be convenient, a lot of the time, but I worry it would be inconvenient some of the time too.

If I wanted to define a custom palette for my application, say, I might do something like this, where I'm defining less-stark blacks and whites.

module Palette exposing (black, white)

import Color exposing (..) -- <- my impulse is to expose everything from Color if I'm defining a color stylesheet type thing for my application

black : Color
black =
    fromRGB ( 20, 20, 20 )

white : Color
white =
    fromRGB ( 253, 253, 250 )

https://ellie-app.com/7H9BgFzcpLja1

I wouldn't worry about this if I hadn't seen color design recommendations to avoid using pure black and pure white (people seem to think that it can lead to eyestrain?)

ianmackenzie commented 4 years ago

Hmm, that is a bit tricky! What about something like Color.pureBlack and Color.pureWhite? Still more convenient than calling fromRGB, but less likely to cause naming collisions, and the name gently reminds the user that perhaps they should consider using something a bit less harsh.

tesk9 commented 4 years ago

Hmm yeah! That sounds convenient & useful! I wonder if having pureRed, pureGreen, and pureBlue would be handy too? 🤔Or if that would pollute the purpose of the Color namespace too much.

There's also the Color.Transparent module -- should that have pureColors too?

ianmackenzie commented 4 years ago

I personally don't see a real need for pureRed etc., and especially if you're worried about Color namespace pollution then I would be inclined to leave them out for now. Easy enough to add them in later, harder to go the other way!

For Color.Transparent, were you thinking of functions like

pureBlack : Opacity -> Color
pureWhite : Opacity -> Color

? I guess that would be useful for consistency...

tesk9 commented 4 years ago

Yeah, exactly! Although, like you said, it's easier to not add than it is to try to take out. 🤔

ianmackenzie commented 4 years ago

I guess I can see something like Color.Transparent.pureWhite (Color.Transparent.customOpacity 0.2) being useful for stuff like a partially-transparent overlay behind a modal. But I don't have strong thoughts either way.