-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow changing the palette with a colour picker 🎨.
- Loading branch information
Showing
6 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { | ||
Popover, | ||
PopoverButton, | ||
CloseButton, | ||
PopoverPanel, | ||
} from '@headlessui/react'; | ||
import ColourSwatch from './ColourSwatch'; | ||
import { digitalPrimeFbxPalette as colourPalette } from '../lib/palettes'; | ||
import { XMarkIcon } from '@heroicons/react/16/solid'; | ||
import { clsx } from 'clsx'; | ||
import { getLuminosity } from '../lib/paletteUtils'; | ||
|
||
// ColourPicker uses shades of `neutral` instead of the usual `slate`. | ||
// This is to avoid the frame to visually pollute the colours. | ||
|
||
const ColourPicker = ({ colourId, onPick, children }) => { | ||
const [selectedColour, setSelectedColour] = useState(colourId); | ||
|
||
useEffect(() => { | ||
setSelectedColour(colourId); | ||
}, [colourId]); | ||
|
||
return ( | ||
<Popover | ||
className="relative" | ||
as="span"> | ||
<PopoverButton className="h-6 w-8">{children}</PopoverButton> | ||
<PopoverPanel | ||
anchor={{ to: 'bottom', gap: '0.125rem' }} | ||
className="rounded bg-neutral-500 drop-shadow"> | ||
<div className="flex justify-between px-2"> | ||
<span className="text-sm font-medium leading-6 text-neutral-300 dark:text-neutral-700"></span> | ||
<CloseButton | ||
as="button" | ||
type="button" | ||
className="-m-2 rounded-md p-2 text-neutral-300 hover:text-neutral-100 dark:text-neutral-700 hover:dark:text-neutral-900"> | ||
<span className="sr-only">Close menu</span> | ||
<XMarkIcon | ||
strokeWidth="2" | ||
className="size-6" | ||
aria-hidden="true" | ||
/> | ||
</CloseButton> | ||
</div> | ||
|
||
<div className="grid-cols-14 mx-2 mb-2 grid"> | ||
{colourPalette.map((c, i) => | ||
i % 16 <= 13 ? ( | ||
<ColourSwatch | ||
key={i} | ||
colour={c} | ||
className={clsx( | ||
i === selectedColour | ||
? getLuminosity(c) < 127 | ||
? 'border-2 !border-neutral-100' | ||
: 'border-2 border-neutral-900' | ||
: 'rounded-none border-0', | ||
)} | ||
onClick={() => { | ||
setSelectedColour(i); | ||
onPick(i); | ||
}} | ||
/> | ||
) : null, | ||
)} | ||
</div> | ||
</PopoverPanel> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default ColourPicker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters