Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RGB codes as an option #32

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/OverlayKnobs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

<ControlGroup title="Overlay">
<Checkbox label="HEX code" bind:checked="{$settings.overlayHex}" />
<Checkbox label="RGB code" bind:checked="{$settings.overlayRgb}" />
<Checkbox label="WCAG Contrast" bind:checked="{$settings.overlayContrast}" />
</ControlGroup>
1 change: 1 addition & 0 deletions src/Palettes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
fillHeight
isLight="{isLightColor(color.luminance)}"
hexCode="{color.hex}"
rgbCode="{color.rgb}"
whiteContrast="{color.whiteContrast}"
blackContrast="{color.blackContrast}"
refColor="{$nearestRefColors[color.hex]}"
Expand Down
46 changes: 32 additions & 14 deletions src/Swatch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
}

.hex-code,
.w-contrast,
.b-contrast,
.rgb-code,
.refColor {
@apply px-4 font-mono;
@apply pl-4 font-mono;
}

.refColor {
@apply absolute bottom-0 right-0;
}

.hex-code,
.w-contrast,
.b-contrast {
@apply pr-4;
}

.codes,
.w-contrast,
.b-contrast {
@apply relative;
Expand All @@ -45,7 +53,7 @@
@apply text-black;
}

.hex-code {
.codes {
@apply mr-auto;
}
</style>
Expand All @@ -56,6 +64,7 @@
import CopyOnClick from "./CopyOnClick.svelte";

export let hexCode = "#000";
export let rgbCode = "0, 0, 0";
export let fillHeight = false;
export let isLight = false;
export let whiteContrast = 0;
Expand All @@ -72,18 +81,27 @@
<a class="click-area" href="#{hexCode}" on:click>
<span class="sr-only">Select</span>
</a>
{#if $settings.overlayHex}
<span class="hex-code">
<CopyOnClick text="{hexCode}">{hexCode}</CopyOnClick>
</span>
{/if}
<div class="codes">
{#if $settings.overlayHex}
<div class="hex-code">
<CopyOnClick text="{hexCode}">{hexCode}</CopyOnClick>
</div>
{/if}
{#if $settings.overlayRgb}
<div class="rgb-code">
<CopyOnClick text="{rgbCode}">{rgbCode}</CopyOnClick>
</div>
{/if}
</div>
{#if refColor}
<div class="refColor">
<TinySwatch color="{refColor}" />
</div>
{/if}
{#if $settings.overlayContrast}
<span class="b-contrast">{blackContrast.toFixed(2)}b</span>
<span class="w-contrast">{whiteContrast.toFixed(2)}w</span>
{/if}
<div>
{#if $settings.overlayContrast}
<div class="b-contrast">{blackContrast.toFixed(2)}b</div>
<div class="w-contrast">{whiteContrast.toFixed(2)}w</div>
{/if}
</div>
</div>
2 changes: 1 addition & 1 deletion src/TinySwatch.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style lang="postcss">
.tiny-swatch {
@apply block w-6 h-6 rounded;
@apply block w-6 h-6 m-1 rounded;
box-shadow: inset 0px -1px 0 rgba(0, 0, 0, 0.35),
inset 0px 1px 0 0 rgba(255, 255, 255, 0.55);
}
Expand Down
6 changes: 6 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { randomInt } from "./lib/math";
import { jsonToSvg } from "./lib/svg";
import { getStateFromUrl, getStatefulUrl } from "./lib/url";
import { to as convert } from "colorjs.io/fn";

const defaults = {
steps: 9,
Expand Down Expand Up @@ -66,6 +67,7 @@ export const settings = writable(
{
overlayContrast: false,
overlayHex: true,
overlayRgb: false,
refColorsRaw: "",
colorSpace: "okhsl",
},
Expand Down Expand Up @@ -255,6 +257,9 @@ export const palettes = derived(
const id = (i + 1) * (steps > 9 ? 10 : 100);
const _color = createColorByHSL(h, s, l, $settings.colorSpace);
const hex = colorToString(_color, "hex", "srgb");
const rgb = convert(_color, "srgb", { inGamut: true }).coords
.map(c => Math.floor(c * 255))
.join(", ");
const chroma = getChroma(_color);
const luminance = getLuminance(_color);
const whiteContrast = contrast(_color, staticColors.white);
Expand All @@ -268,6 +273,7 @@ export const palettes = derived(
s,
l,
hex,
rgb,
chroma,
luminance,
whiteContrast,
Expand Down