import { defineComponent, type PropType } from 'vue'; import { BCMSIcon } from '../..'; import { DefaultComponentProps } from '../../_default'; const component = defineComponent({ props: { ...DefaultComponentProps, tag: { type: String as PropType<'button' | 'a' | 'div'>, default: 'button', }, icon: { type: String, default: '', }, title: { type: [String, Function], default: '', }, level: { type: Number, default: 1, }, action: { type: String || undefined, default: undefined, }, url: { type: String || undefined, }, isMac: { type: Boolean, default: false, }, }, emits: { click: () => { return true; }, }, setup(props, ctx) { return () => { const Tag = props.url ? 'a' : props.tag; function toggleDarkMode() { if (document.documentElement.classList.contains('dark')) { window.bcms.sdk.storage.set('theme', 'light'); } else { window.bcms.sdk.storage.set('theme', 'dark'); } document.documentElement.classList.toggle('dark'); } const handleClick = () => { switch (props.action) { case 'dark-mode': toggleDarkMode(); break; case 'global-search': window.bcms.globalSearch.show(); break; default: break; } }; return (
  • { handleClick(); ctx.emit('click'); }} > {ctx.slots.default ? ( ctx.slots.default() ) : ( <> {props.icon && ( )} {typeof props.title === 'function' ? props.title(window.bcms.sdk.storage.get('theme')) : props.title} {props.action === 'global-search' ? ( {props.isMac ? 'CMD' : 'CTRL'} + K ) : ( '' )} )}
  • ); }; }, }); export default component;