File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,16 +8,11 @@ export function buildRandomColor(): string {
88 return `#${ rangeOf ( HEX_COLOR_LENGTH , ( ) => HEX_DIGITS [ Math . floor ( Math . random ( ) * HEX_DIGITS . length ) ] ) . join ( '' ) } ` ;
99}
1010
11- /**
12- * Returns the perceived lightness of an RGB color, as a number from 0 to 256.
13- * The lower the number, the darker is the color perceived.
14- *
15- * HSP by Darel Rex Finley https://alienryderflex.com/hsp.html
16- */
1711function perceivedLightness ( r : number , g : number , b : number ) : number {
1812 return Math . round ( Math . sqrt ( 0.299 * r ** 2 + 0.587 * g ** 2 + 0.114 * b ** 2 ) ) ;
1913}
2014
15+ /** @deprecated . Use same symbol from @shlinkio/shlink-frontend-kit */
2116export function isLightColor ( colorHex : string ) : boolean {
2217 const [ r , g , b ] = ( colorHex . match ( / ../ g) ?? [ ] ) . map ( ( hex ) => parseInt ( hex , 16 ) || 0 ) ;
2318 return perceivedLightness ( r , g , b ) >= LIGHTNESS_BREAKPOINT ;
Original file line number Diff line number Diff line change 11import { range } from '@shlinkio/data-manipulation' ;
2- import type { SyntheticEvent } from 'react' ;
3- import { useCallback } from 'react' ;
42
53export type OptionalString = string | null | undefined ;
64
7- /**
8- * Wraps an event handler so that it calls e.preventDefault() before invoking the event handler
9- */
10- export const usePreventDefault = < Event extends SyntheticEvent = SyntheticEvent > ( handler : ( e : Event ) => void ) =>
11- useCallback ( ( e : Event ) => {
12- e . preventDefault ( ) ;
13- handler ( e ) ;
14- } , [ handler ] ) ;
15-
165export const rangeOf = < T > ( size : number , mappingFn : ( value : number ) => T , startAt = 1 ) : T [ ] =>
176 range ( startAt , size + 1 ) . map ( mappingFn ) ;
187
You can’t perform that action at this time.
0 commit comments