feat: add IconPicker component and utility library for Lucide icon selection and color management

This commit is contained in:
Michael committed 2026-04-10 11:03:02 +02:00
1 parent 485aba96fd
commit c3d141402f
5 files changed
+272 -66

No files matched your search

+23 -17
View File
@@ -2,22 +2,25 @@
import React, { useState } from 'react';
import { addButton } from '@/app/actions/admin';
import { EmojiPicker } from '@/components/EmojiPicker';
import { IconPicker } from '@/components/IconPicker';
import { serializeIcon } from '@/lib/lucideIcons';
import { PlusCircle } from 'lucide-react';
export function AddButtonForm() {
const [icon, setIcon] = useState('🔗');
const [iconName, setIconName] = useState('Globe');
const [iconColor, setIconColor] = useState('#22d3ee');
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setLoading(true);
const formData = new FormData(e.currentTarget);
formData.set('icon', icon);
formData.set('icon', serializeIcon(iconName, iconColor));
try {
await addButton(formData);
(e.target as HTMLFormElement).reset();
setIcon('🔗');
setIconName('Globe');
setIconColor('#22d3ee');
} finally {
setLoading(false);
}
@@ -34,30 +37,35 @@ export function AddButtonForm() {
marginBottom: '2rem',
}}>
<h2 style={{
fontSize: '0.85rem',
fontSize: '0.78rem',
fontWeight: 700,
color: 'rgba(255,255,255,0.5)',
color: 'rgba(255,255,255,0.4)',
marginBottom: '1.25rem',
letterSpacing: '0.08em',
display: 'flex',
alignItems: 'center',
gap: '0.5rem',
}}>
<PlusCircle size={15} /> AJOUTER UNE APPLICATION
<PlusCircle size={14} /> AJOUTER UNE APPLICATION
</h2>
<form onSubmit={handleSubmit} style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap', alignItems: 'flex-end' }}>
{/* Emoji picker */}
{/* Icon picker */}
<div>
<label style={{ display: 'block', fontSize: '0.75rem', fontWeight: 600, color: 'rgba(255,255,255,0.45)', marginBottom: '0.45rem' }}>
<label style={{ display: 'block', fontSize: '0.72rem', fontWeight: 700, color: 'rgba(255,255,255,0.4)', marginBottom: '0.45rem', letterSpacing: '0.06em' }}>
ICÔNE
</label>
<EmojiPicker value={icon} onChange={setIcon} />
<IconPicker
iconName={iconName}
color={iconColor}
onIconChange={setIconName}
onColorChange={setIconColor}
/>
</div>
{/* Name */}
<div style={{ flex: '1 1 140px' }}>
<label style={{ display: 'block', fontSize: '0.75rem', fontWeight: 600, color: 'rgba(255,255,255,0.45)', marginBottom: '0.45rem' }}>
<label style={{ display: 'block', fontSize: '0.72rem', fontWeight: 700, color: 'rgba(255,255,255,0.4)', marginBottom: '0.45rem', letterSpacing: '0.06em' }}>
NOM
</label>
<input name="name" type="text" placeholder="Ex: Slack, Notion…" required />
@@ -65,22 +73,20 @@ export function AddButtonForm() {
{/* URL */}
<div style={{ flex: '2 1 240px' }}>
<label style={{ display: 'block', fontSize: '0.75rem', fontWeight: 600, color: 'rgba(255,255,255,0.45)', marginBottom: '0.45rem' }}>
<label style={{ display: 'block', fontSize: '0.72rem', fontWeight: 700, color: 'rgba(255,255,255,0.4)', marginBottom: '0.45rem', letterSpacing: '0.06em' }}>
URL
</label>
<input name="url" type="url" placeholder="https://…" required />
</div>
{/* Submit */}
<button
type="submit"
disabled={loading}
style={{
background: 'rgba(255,255,255,0.16)',
backdropFilter: 'blur(12px)',
border: '1px solid rgba(255,255,255,0.22)',
background: 'rgba(255,255,255,0.14)',
border: '1px solid rgba(255,255,255,0.2)',
color: '#fff',
padding: '0.75rem 1.25rem',
padding: '0.78rem 1.25rem',
borderRadius: '12px',
fontWeight: 600,
fontSize: '0.88rem',
+155
View File
@@ -0,0 +1,155 @@
'use client';
import React, { useState, useMemo } from 'react';
import { ICON_MAP, ICON_NAMES, ICON_COLORS } from '@/lib/lucideIcons';
import { Search } from 'lucide-react';
interface IconPickerProps {
iconName: string;
color: string;
onIconChange: (name: string) => void;
onColorChange: (color: string) => void;
}
export function IconPicker({ iconName, color, onIconChange, onColorChange }: IconPickerProps) {
const [open, setOpen] = useState(false);
const [query, setQuery] = useState('');
const filteredIcons = useMemo(
() => ICON_NAMES.filter((n) => n.toLowerCase().includes(query.toLowerCase())),
[query]
);
const SelectedIcon = ICON_MAP[iconName] || ICON_MAP['Globe'];
return (
<div style={{ position: 'relative' }}>
{/* Trigger */}
<button
type="button"
onClick={() => setOpen(!open)}
title="Choisir une icône"
style={{
width: '56px', height: '56px',
borderRadius: '14px',
background: 'rgba(255,255,255,0.08)',
border: '1px solid rgba(255,255,255,0.15)',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
transition: 'background 200ms ease',
}}
>
<SelectedIcon size={28} color={color} strokeWidth={1.8} />
</button>
{/* Picker panel */}
{open && (
<>
{/* Backdrop */}
<div
style={{ position: 'fixed', inset: 0, zIndex: 99 }}
onClick={() => setOpen(false)}
/>
<div style={{
position: 'absolute',
top: '64px',
left: 0,
zIndex: 100,
width: '320px',
background: 'rgba(25, 5, 35, 0.95)',
backdropFilter: 'blur(30px)',
WebkitBackdropFilter: 'blur(30px)',
border: '1px solid rgba(255,255,255,0.12)',
borderRadius: '18px',
padding: '1.1rem',
boxShadow: '0 20px 60px rgba(0,0,0,0.6)',
}}>
{/* Search */}
<div style={{ position: 'relative', marginBottom: '0.85rem' }}>
<Search size={14} color="rgba(255,255,255,0.4)" style={{ position: 'absolute', left: '10px', top: '50%', transform: 'translateY(-50%)' }} />
<input
type="text"
placeholder="Rechercher…"
value={query}
onChange={(e) => setQuery(e.target.value)}
style={{ paddingLeft: '30px', fontSize: '0.85rem' }}
onClick={(e) => e.stopPropagation()}
/>
</div>
{/* Icon grid */}
<div style={{
display: 'grid',
gridTemplateColumns: 'repeat(7, 1fr)',
gap: '4px',
maxHeight: '220px',
overflowY: 'auto',
marginBottom: '0.85rem',
}}>
{filteredIcons.map((name) => {
const Icon = ICON_MAP[name];
const isSelected = name === iconName;
return (
<button
key={name}
type="button"
title={name}
onClick={() => { onIconChange(name); }}
style={{
background: isSelected ? 'rgba(255,255,255,0.18)' : 'transparent',
border: isSelected ? '1px solid rgba(255,255,255,0.3)' : '1px solid transparent',
borderRadius: '8px',
padding: '6px',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
transition: 'background 120ms',
}}
onMouseEnter={(e) => { if (!isSelected) e.currentTarget.style.background = 'rgba(255,255,255,0.1)'; }}
onMouseLeave={(e) => { if (!isSelected) e.currentTarget.style.background = 'transparent'; }}
>
<Icon size={18} color={isSelected ? color : 'rgba(255,255,255,0.65)'} strokeWidth={1.7} />
</button>
);
})}
</div>
{/* Color palette */}
<div style={{ borderTop: '1px solid rgba(255,255,255,0.08)', paddingTop: '0.85rem' }}>
<p style={{ fontSize: '0.7rem', color: 'rgba(255,255,255,0.35)', fontWeight: 700, letterSpacing: '0.06em', marginBottom: '0.6rem' }}>
COULEUR
</p>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '6px' }}>
{ICON_COLORS.map((c) => (
<button
key={c.value}
type="button"
title={c.label}
onClick={() => onColorChange(c.value)}
style={{
width: '26px', height: '26px',
borderRadius: '50%',
background: c.value,
border: color === c.value
? '2px solid white'
: '2px solid transparent',
boxShadow: color === c.value ? '0 0 0 2px rgba(255,255,255,0.3)' : 'none',
cursor: 'pointer',
transition: 'transform 150ms',
}}
onMouseEnter={(e) => (e.currentTarget.style.transform = 'scale(1.15)')}
onMouseLeave={(e) => (e.currentTarget.style.transform = 'scale(1)')}
/>
))}
</div>
</div>
</div>
</>
)}
</div>
);
}
+7 -29
View File
@@ -1,9 +1,9 @@
'use client';
import React, { useState } from 'react';
import React from 'react';
import Link from 'next/link';
import Image from 'next/image';
import { Globe } from 'lucide-react';
import { ICON_MAP, parseIcon } from '@/lib/lucideIcons';
import styles from './MenuButton.module.css';
interface MenuButtonProps {
@@ -12,40 +12,18 @@ interface MenuButtonProps {
icon?: string | null;
}
function getDomain(url: string): string {
try { return new URL(url).hostname; } catch { return url; }
}
/**
* MenuButton — displays emoji icon if set, falls back to Google favicon.
* MenuButton — renders a Lucide icon (with color) if set,
* otherwise falls back to the Globe icon.
*/
export const MenuButton: React.FC<MenuButtonProps> = ({ name, url, icon }) => {
const domain = getDomain(url);
const faviconUrl = `https://www.google.com/s2/favicons?domain=${domain}&sz=64`;
const [faviconError, setFaviconError] = useState(false);
const { name: iconName, color } = parseIcon(icon);
const IconComponent = ICON_MAP[iconName] || Globe;
return (
<Link href={url} target="_blank" rel="noopener noreferrer" className={styles.menuButton}>
<div className={styles.faviconWrapper}>
{icon ? (
// Custom emoji icon
<span style={{ fontSize: '2.2rem', lineHeight: 1 }}>{icon}</span>
) : !faviconError ? (
// Auto favicon from Google CDN
<Image
src={faviconUrl}
alt={`${name} favicon`}
width={48}
height={48}
className={styles.favicon}
onError={() => setFaviconError(true)}
unoptimized
/>
) : (
<div className={styles.faviconFallback}>
<Globe size={32} />
</div>
)}
<IconComponent size={44} color={color} strokeWidth={1.6} />
</div>
<span className={styles.label}>{name}</span>
</Link>