Skip to content

Commit d78c0d4

Browse files
4.0.6 (#43)
- Palette icon displays again on front-end when active - Palette now closes when clicking outside the modal boundary
1 parent 1408e8e commit d78c0d4

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release Notes for Palette
22

3+
## 4.0.6 - 2024-03-27
4+
5+
### Added
6+
- Palette icon displays again on front-end when active
7+
- Palette now closes when clicking outside the modal boundary
8+
39
## 4.0.5 - 2024-03-18
410

511
### Fixed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "trendyminds/craft-palette",
33
"description": "A command palette to easily jump to specific areas within Craft",
44
"type": "craft-plugin",
5-
"version": "4.0.5",
5+
"version": "4.0.6",
66
"keywords": ["palette", "craft", "craft cms", "cmdk", "spotlight", "craft plugin"],
77
"license": "MIT",
88
"authors": [

scripts/Modal.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import clsx from 'clsx'
22
import { useHotkeys } from 'react-hotkeys-hook'
33
import useOpen from './hooks/useOpen'
44
import useContext from './hooks/useContext'
5+
import useOutsideClick from './hooks/useClickOutside'
56
import Actions from './contexts/Actions'
67
import Entries from './contexts/Entries'
78
import SearchBar from './SearchBar'
9+
import { CommandLineIcon } from '@heroicons/react/24/outline'
810

911
export default function Modal() {
1012
const [open, setOpen] = useOpen()
1113
const [context, setContext] = useContext()
14+
const modal = useOutsideClick(() => setOpen(false))
1215

1316
// prettier-ignore
1417
useHotkeys(['ctrl+k, meta+k'], () => {
@@ -28,6 +31,7 @@ export default function Modal() {
2831
<div className="p-fixed p-inset-0 p-z-[9999] p-size-full p-flex p-justify-center p-antialiased">
2932
<div className="p-w-full p-max-w-2xl">
3033
<div
34+
ref={modal}
3135
className={clsx([
3236
'p-bg-white/70 dark:p-bg-zinc-950/90',
3337
'p-outline-zinc-300 dark:p-outline-zinc-900 p-outline p-outline-1',
@@ -44,6 +48,24 @@ export default function Modal() {
4448
</div>
4549
</div>
4650
)}
51+
52+
<button
53+
className={clsx([
54+
'p-fixed p-bottom-5 p-left-5 p-z-[100]',
55+
'p-flex p-items-center p-justify-center',
56+
'p-backdrop-blur-md p-shadow p-rounded-full',
57+
'p-bg-zinc-50/70 dark:p-bg-neutral-800/90',
58+
'dark:p-text-neutral-300',
59+
'p-size-8',
60+
'p-cursor-pointer',
61+
'p-border-0',
62+
'p-transition-transform hover:p-scale-110 active:p-scale-90',
63+
])}
64+
onClick={() => setOpen(true)}
65+
aria-label="Open Palette"
66+
>
67+
<CommandLineIcon className="p-size-5" />
68+
</button>
4769
</>
4870
)
4971
}

scripts/hooks/useClickOutside.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useRef, useEffect } from 'react'
2+
3+
export default function useOutsideClick(callback) {
4+
const ref = useRef()
5+
6+
useEffect(() => {
7+
const handleClick = (event) => {
8+
if (ref.current && !ref.current.contains(event.target)) {
9+
callback()
10+
}
11+
}
12+
13+
document.addEventListener('click', handleClick, true)
14+
15+
return () => {
16+
document.removeEventListener('click', handleClick, true)
17+
}
18+
}, [ref])
19+
20+
return ref
21+
}

0 commit comments

Comments
 (0)