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

Function darkenColor

src/content/Components/Folder/Folder.jsx:4–20  ·  view source on GitHub ↗
(hex, percent)

Source from the content-addressed store, hash-verified

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

Callers 1

FolderFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected