| 1 | import { useState } from 'react'; |
| 2 | |
| 3 | const 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 | |
| 21 | const Folder = ({ color = '#5227FF', size = 1, items = [], className = '' }) => { |
| 22 | const maxItems = 3; |