WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 32519a6

Browse files
committed
Rename lib as future home for other colour utils
1 parent a0310ea commit 32519a6

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

dotcom-rendering/src/components/Distribution.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css } from '@emotion/react';
22
import { headlineBold34, text } from '@guardian/source/foundations';
3-
import { isLight } from '../lib/isLight';
3+
import { isLight } from '../lib/colour';
44

55
type Props = {
66
left: BarType;

dotcom-rendering/src/components/Doughnut.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
text,
66
textSans15,
77
} from '@guardian/source/foundations';
8-
import { isLight } from '../lib/isLight';
8+
import { isLight } from '../lib/colour';
99

1010
type Props = {
1111
sections: SectionType[];

dotcom-rendering/src/components/GoalAttempts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
palette as sourcePalette,
55
textSans15,
66
} from '@guardian/source/foundations';
7-
import { isLight } from '../lib/isLight';
7+
import { isLight } from '../lib/colour';
88
import { transparentColour } from '../lib/transparentColour';
99
import { palette as themePalette } from '../palette';
1010
import type { ColourName } from '../paletteDeclarations';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isLight } from './isLight';
1+
import { isLight } from './colour';
22

33
describe('isLight', () => {
44
it('should return the correct response for dark hex colours', () => {
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// https://stackoverflow.com/a/5624139
2-
function hexToRgb(hex: string): {
2+
const hexToRgb = (
3+
hex: string,
4+
): {
35
r: number;
46
g: number;
57
b: number;
6-
} | null {
8+
} | null => {
79
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
810
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
911
const fullHex = hex.replace(shorthandRegex, ([, r, g, b]) => {
@@ -19,13 +21,13 @@ function hexToRgb(hex: string): {
1921
b: parseInt(b, 16),
2022
}
2123
: null;
22-
}
24+
};
2325

24-
function getBrightness(colour: string): number {
26+
const getBrightness = (colour: string): number => {
2527
// http://www.w3.org/TR/AERT#color-contrast
2628
const rgb = hexToRgb(colour);
2729
return rgb ? (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000 : 0;
28-
}
30+
};
2931

3032
// Based on https://github.com/bgrins/TinyColor
3133
export const isLight = (colour: string): boolean => {

0 commit comments

Comments
 (0)