Skip to content

Commit

Permalink
Fix math
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Oct 27, 2022
1 parent 6ef8d6e commit 5971042
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/components/src/theme/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,33 @@ const accentColor = ( { accent }: ThemeProps ) =>
`
: undefined;

// TODO: Add unit test so the result of this matches the default case (#fff to #1e1e1e)
function generateShades( background: string, foreground: string ) {
// Start from #fff (background)
const shades = {
// 0: 0,
100: 0.06,
200: 0.12,
200: 0.121,
300: 0.132,
400: 0.2,
600: 0.42,
700: 0.54,
800: 0.817,
// 900: 0.884,
700: 0.543,
800: 0.821,
};

// Darkness of COLORS.gray[ 900 ], relative to #fff
const limit = 0.884;

const direction = colord( background ).isDark() ? 'lighten' : 'darken';
const range =
Math.abs(
colord( background ).toHsl().l - colord( foreground ).toHsl().l
) / 100;

const result: Record< string, string > = {};

Object.entries( shades ).forEach( ( [ k, v ] ) => {
const range =
( colord( background ).toHsl().l -
colord( foreground ).toHsl().l ) /
100;
const dir = colord( background ).isDark() ? 'lighten' : 'darken';
result[ k ] = colord( background )
[ dir ]( v * range )
[ direction ]( ( v / limit ) * range )
.toHex();
} );

Expand Down

0 comments on commit 5971042

Please sign in to comment.