| 1 |
import { magic } from '@agent/icons'; |
| 2 |
import { useGlobalStore } from '@agent/state/global'; |
| 3 |
import { Icon } from '@wordpress/components'; |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
import classNames from 'classnames'; |
| 6 |
import { motion } from 'framer-motion'; |
| 7 |
|
| 8 |
// TODO: this isnt great if we allow the user to "pop out" the sidebar |
| 9 |
const isSidebarDocked = window.extAgentData.agentPosition !== 'floating'; |
| 10 |
|
| 11 |
export const AdminBar = () => { |
| 12 |
const { toggleOpen, open, isMobile } = useGlobalStore(); |
| 13 |
|
| 14 |
if (isMobile) return null; |
| 15 |
|
| 16 |
return ( |
| 17 |
<motion.button |
| 18 |
type="button" |
| 19 |
initial={false} |
| 20 |
animate={{ |
| 21 |
width: isSidebarDocked ? (open ? 0 : 'auto') : 'auto', |
| 22 |
opacity: isSidebarDocked ? (open ? 0 : 100) : 100, |
| 23 |
}} |
| 24 |
transition={{ |
| 25 |
width: { duration: 0.3, ease: 'easeInOut' }, |
| 26 |
opacity: { duration: 0.1, ease: 'easeInOut' }, |
| 27 |
}} |
| 28 |
className={classNames( |
| 29 |
'items-center justify-center gap-1 border-0 leading-extra-tight text-white md:inline-flex whitespace-nowrap', |
| 30 |
{ 'opacity-60': open && !isSidebarDocked }, |
| 31 |
// Open, docked sidebar (keeps the spacing) |
| 32 |
{ 'h-full mr-1 rtl:ml-1 rtl:mr-0': open && isSidebarDocked }, |
| 33 |
{ |
| 34 |
// Styles for when docked sidebar is open |
| 35 |
// Useful to put things here you don't want to animate out |
| 36 |
// Pill sizing matches the simple toolbar's .ext-tb-ai-agent |
| 37 |
'my-1 ml-1 mr-2 rtl:ml-2 rtl:mr-1 h-6 rounded px-[10px] bg-[#3858e9] hover:bg-[#2145e6]': |
| 38 |
!isSidebarDocked || (isSidebarDocked && !open), |
| 39 |
}, |
| 40 |
)} |
| 41 |
onClick={() => toggleOpen()} |
| 42 |
aria-label={__('Open Agent', 'extendify-local')} |
| 43 |
> |
| 44 |
<Icon className="shrink-0" icon={magic} width={20} height={20} /> |
| 45 |
<span className="leading-none">{__('AI Agent', 'extendify-local')}</span> |
| 46 |
</motion.button> |
| 47 |
); |
| 48 |
}; |
| 49 |
|