feat: implement sort by hue for named colors using pastel-wasm
This commit is contained in:
@@ -6,6 +6,7 @@ import { Input } from '@/components/ui/Input';
|
||||
import { Select } from '@/components/ui/Select';
|
||||
import { useNamedColors } from '@/lib/pastel/api/queries';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { parse_color } from '@valknarthing/pastel-wasm';
|
||||
|
||||
export default function NamedColorsPage() {
|
||||
const [search, setSearch] = useState('');
|
||||
@@ -24,9 +25,13 @@ export default function NamedColorsPage() {
|
||||
|
||||
if (sortBy === 'name') {
|
||||
colors.sort((a, b) => a.name.localeCompare(b.name));
|
||||
} else if (sortBy === 'hue') {
|
||||
colors.sort((a, b) => {
|
||||
const infoA = parse_color(a.hex);
|
||||
const infoB = parse_color(b.hex);
|
||||
return infoA.hsl[0] - infoB.hsl[0];
|
||||
});
|
||||
}
|
||||
// For hue sorting, we'd need to convert to HSL which requires the API
|
||||
// For now, just keep alphabetical as default
|
||||
|
||||
return colors;
|
||||
}, [data, search, sortBy]);
|
||||
|
||||
Reference in New Issue
Block a user