Skip to content

Commit

Permalink
palette.transparent (#2406)
Browse files Browse the repository at this point in the history
* Update palette.ts

* updates storybook

* Create three-jobs-behave.md

* typo
  • Loading branch information
TheSonOfThomp authored Jun 25, 2024
1 parent 667496f commit d70758d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-jobs-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/palette': minor
---

Adds `transparent` key to `palette`. Ensures a consistent `transparent` color across browsers
14 changes: 10 additions & 4 deletions packages/palette/src/Palette.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { MouseEventHandler, useState } from 'react';
import { StoryMetaType } from '@lg-tools/storybook-utils';
import isUndefined from 'lodash/isUndefined';
import { darken, lighten, readableColor, transparentize } from 'polished';

import { css, cx } from '@leafygreen-ui/emotion';
Expand All @@ -9,6 +8,11 @@ import { HTMLElementProps } from '@leafygreen-ui/lib';
import palette from './palette';

type HueName = keyof typeof palette;
const baseHues: Array<HueName> = ['white', 'black', 'transparent'];

const isBaseHue = (hue: HueName): hue is 'white' | 'black' | 'transparent' => {
return baseHues.includes(hue);
};

const ShadeNames = [
'dark4',
Expand Down Expand Up @@ -99,9 +103,10 @@ function ColorBlock({ hue, shade, ...rest }: ColorBlockProps) {

let color: string;

if (isUndefined(shade) || hue === 'white' || hue === 'black') {
color = palette[hue as 'white' | 'black'];
if (isBaseHue(hue)) {
color = palette[hue];
} else {
shade = shade ?? 'base';
color = (palette[hue] as Record<ShadeName, string>)[shade];
}

Expand Down Expand Up @@ -175,7 +180,7 @@ export default meta;
export function AllColors() {
const allColors = Object.keys(palette);
const hues = (allColors as Array<keyof typeof palette>).slice(
2,
baseHues.length,
allColors.length,
); // remove black and white

Expand All @@ -184,6 +189,7 @@ export function AllColors() {
<div className={colorRowStyle}>
<ColorBlock hue="white" name="white" />
<ColorBlock hue="black" name="black" />
<ColorBlock hue="transparent" name="transparent" />
</div>
{hues.map(hue => {
const hueValues = palette[hue];
Expand Down
2 changes: 2 additions & 0 deletions packages/palette/src/palette.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const white = '#FFFFFF' as const;
export const black = '#001E2B' as const;
export const transparent = '#FFFFFF00' as const;

export const gray = {
dark4: '#112733',
Expand Down Expand Up @@ -68,6 +69,7 @@ export const red = {
const palette = {
white,
black,
transparent,
gray,
green,
purple,
Expand Down

0 comments on commit d70758d

Please sign in to comment.