MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / darkenColor

Function darkenColor

src/tailwind/Components/Folder/Folder.jsx:3–19  ·  view source on GitHub ↗
(hex, percent)

Source from the content-addressed store, hash-verified

1import { useState } from 'react';
2
3const darkenColor = (hex, percent) => {
4 let color = hex.startsWith('#') ? hex.slice(1) : hex;
5 if (color.length === 3) {
6 color = color
7 .split('')
8 .map(c => c + c)
9 .join('');
10 }
11 const num = parseInt(color, 16);
12 let r = (num >> 16) & 0xff;
13 let g = (num >> 8) & 0xff;
14 let b = num & 0xff;
15 r = Math.max(0, Math.min(255, Math.floor(r * (1 - percent))));
16 g = Math.max(0, Math.min(255, Math.floor(g * (1 - percent))));
17 b = Math.max(0, Math.min(255, Math.floor(b * (1 - percent))));
18 return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();
19};
20
21const Folder = ({ color = '#5227FF', size = 1, items = [], className = '' }) => {
22 const maxItems = 3;

Callers 1

FolderFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected