mood-ui 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/data-display/calendar/AgendaView.cjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.mjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.cjs +11 -6
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.mjs +18 -13
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/Calendar.vue_vue_type_script_setup_true_lang.mjs +4 -4
- package/dist/components/data-display/calendar/Calendar.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.cjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.mjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.cjs +14 -9
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.mjs +22 -17
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.cjs +1 -1
- package/dist/components/data-display/calendar/MonthView.cjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.mjs +1 -1
- package/dist/components/data-display/calendar/MonthView.mjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.cjs +15 -17
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.mjs +18 -20
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.cjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.mjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.cjs +14 -9
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.mjs +22 -17
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.cjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.mjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.cjs +14 -9
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.mjs +22 -17
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.mjs +3 -3
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.mjs +3 -3
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Banner.vue_vue_type_script_setup_true_lang.mjs +4 -4
- package/dist/components/feedback/Banner.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Drawer.cjs.map +1 -1
- package/dist/components/feedback/Drawer.mjs.map +1 -1
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.cjs +4 -9
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.mjs +9 -14
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Modal.cjs.map +1 -1
- package/dist/components/feedback/Modal.mjs.map +1 -1
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.cjs +4 -9
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.mjs +9 -14
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs +44 -17
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs +44 -17
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Combobox.cjs.map +1 -1
- package/dist/components/forms/Combobox.mjs.map +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/PhoneInput.cjs.map +1 -1
- package/dist/components/forms/PhoneInput.mjs.map +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs +6 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs +6 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/SearchInput.cjs.map +1 -1
- package/dist/components/forms/SearchInput.mjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs +8 -6
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs +8 -6
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.cjs +1 -1
- package/dist/components/layout/PopoverPanel.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.mjs +1 -1
- package/dist/components/layout/PopoverPanel.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/Switcher.cjs.map +1 -1
- package/dist/components/navigation/Switcher.mjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs +38 -40
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs +38 -40
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/composables/eventColors.cjs +51 -27
- package/dist/composables/eventColors.cjs.map +1 -1
- package/dist/composables/eventColors.mjs +51 -27
- package/dist/composables/eventColors.mjs.map +1 -1
- package/dist/composables/useBodyScrollLock.cjs +44 -0
- package/dist/composables/useBodyScrollLock.cjs.map +1 -0
- package/dist/composables/useBodyScrollLock.mjs +43 -0
- package/dist/composables/useBodyScrollLock.mjs.map +1 -0
- package/dist/composables/useCalendarTheme.cjs +29 -8
- package/dist/composables/useCalendarTheme.cjs.map +1 -1
- package/dist/composables/useCalendarTheme.mjs +29 -8
- package/dist/composables/useCalendarTheme.mjs.map +1 -1
- package/dist/composables/usePopover.cjs +44 -12
- package/dist/composables/usePopover.cjs.map +1 -1
- package/dist/composables/usePopover.mjs +44 -12
- package/dist/composables/usePopover.mjs.map +1 -1
- package/dist/mood-ui.css +9 -9
- package/dist/types/composables/eventColors.d.ts +2 -2
- package/dist/types/composables/useBodyScrollLock.d.ts +19 -0
- package/dist/types/composables/useCalendarTheme.d.ts +2 -0
- package/dist/types/interfaces/data-display/calendar/AgendaView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/DayView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/MonthView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/Scheduler.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/WeekView.interface.d.ts +5 -0
- package/dist/types/utils/calendarTooltip.d.ts +13 -0
- package/dist/types/utils/cssLength.d.ts +5 -0
- package/dist/types/utils/tooltipArrow.d.ts +34 -0
- package/dist/utils/calendarTooltip.cjs +18 -0
- package/dist/utils/calendarTooltip.cjs.map +1 -0
- package/dist/utils/calendarTooltip.mjs +18 -0
- package/dist/utils/calendarTooltip.mjs.map +1 -0
- package/dist/utils/cssLength.cjs +13 -0
- package/dist/utils/cssLength.cjs.map +1 -0
- package/dist/utils/cssLength.mjs +13 -0
- package/dist/utils/cssLength.mjs.map +1 -0
- package/dist/utils/tooltipArrow.cjs +37 -0
- package/dist/utils/tooltipArrow.cjs.map +1 -0
- package/dist/utils/tooltipArrow.mjs +36 -0
- package/dist/utils/tooltipArrow.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ const require__plugin_vue_export_helper = require("../../_virtual/_plugin-vue_ex
|
|
|
2
2
|
const require_PopoverPanel_vue_vue_type_script_setup_true_lang = require("./PopoverPanel.vue_vue_type_script_setup_true_lang.cjs");
|
|
3
3
|
;/* empty css */
|
|
4
4
|
//#region src/components/layout/PopoverPanel.vue
|
|
5
|
-
var PopoverPanel_default = /* @__PURE__ */ require__plugin_vue_export_helper.default(require_PopoverPanel_vue_vue_type_script_setup_true_lang.default, [["__scopeId", "data-v-
|
|
5
|
+
var PopoverPanel_default = /* @__PURE__ */ require__plugin_vue_export_helper.default(require_PopoverPanel_vue_vue_type_script_setup_true_lang.default, [["__scopeId", "data-v-8bb79aba"]]);
|
|
6
6
|
//#endregion
|
|
7
7
|
exports.default = PopoverPanel_default;
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopoverPanel.cjs","names":[],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"
|
|
1
|
+
{"version":3,"file":"PopoverPanel.cjs","names":[],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover flex flex-col overflow-hidden bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"\n :data-modo-theme=\"scopedTheme || undefined\"\n >\n <!--\n `min-h-0` is what makes the panel's max-height actually bite:\n as a flex child this wrapper defaults to min-height:auto and\n refuses to shrink below its content, so it would render past\n the capped panel instead of scrolling inside it.\n -->\n <div :class=\"['modo-popover-inner min-h-0 flex-1 overflow-x-hidden overflow-y-auto', radiusClass]\">\n <slot />\n </div>\n </div> \n </Transition> \n </Teleport> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch } from 'vue'; \nimport { useResolvedRadius, useResolvedTheme, useModoConfig } from '../../composables/useModoConfig'; \nimport { resolveColorMode } from '../../composables/useColorMode'; \nimport { palettesToCssVars, semanticTokensFromPalettes } from '../../config/palettes'; \nimport { hexToOklchString, pickForegroundOklch } from '../../config/colorPrimitives'; \nimport { surfacesToCssVars } from '../../config/surfaces'; \n \ndefineOptions({ inheritAttrs: false }); \n \nconst props = defineProps<{ \n /** Controla la visibilidad. */ \n open: boolean; \n /** Estilo (top/left/width/zIndex) calculado por `usePopover`. */ \n style?: Record<string, string>; \n /** Radio de esquinas. Si no se pasa, toma el del provider. */ \n radius?: 'none' | 'small' | 'medium' | 'large' | 'full'; \n /** ARIA role. @default 'dialog' */ \n role?: string; \n /** Id del elemento que nombra al panel. */ \n labelledBy?: string; \n}>(); \n \nconst emit = defineEmits<{ 'update:panelRef': [el: HTMLElement | null] }>(); \n \nconst panelEl = ref<HTMLElement | null>(null); \nwatch(panelEl, (el) => emit('update:panelRef', el)); \n \nconst radius = useResolvedRadius(() => props.radius); \nconst theme = useResolvedTheme(); \nconst cfg = useModoConfig(); \n// When the popover is portal'd to <body>, the data-modo-theme attribute on \n// the parent provider is out of scope. Forward it so dark mode works. \nconst scopedTheme = computed(() => resolveColorMode(theme.value)); \n \n// Forward the provider's palette CSS vars (`--primary`, `--primary-foreground`, \n// etc.) to the teleported panel so `bg-primary` / `text-primary` stay in sync \n// with whatever palette the provider set. Also forward surface vars so tinted \n// surfaces (base intensity) are visible inside the popover. \nconst mergedStyle = computed(() => { \n const providerVars = cfg?.value.palettes \n ? { \n ...palettesToCssVars(cfg.value.palettes), \n ...semanticTokensFromPalettes(cfg.value.palettes, hexToOklchString, pickForegroundOklch), \n } \n : {};\n const surfaceVars = cfg?.value.surfaces\n ? surfacesToCssVars(cfg.value.surfaces)\n : {};\n const darkSurfaceVars = (scopedTheme.value === 'dark' && cfg?.value.darkSurfaces)\n ? surfacesToCssVars(cfg.value.darkSurfaces)\n : {};\n return { ...providerVars, ...surfaceVars, ...darkSurfaceVars, ...(props.style ?? {}) }; \n}); \n \nconst radiusClass = computed(() => { \n switch (radius.value) { \n case 'none': return 'rounded-none'; \n case 'small': return 'rounded-sm'; \n case 'large': return 'rounded-xl'; \n case 'full': return 'rounded-2xl'; \n case 'medium': \n default: return 'rounded-md'; \n } \n}); \n</script> \n \n<style scoped> \n.modo-popover { \n transform-origin: top center; \n will-change: transform, opacity; \n} \n.modo-popover-enter { \n animation: modo-popover-in 140ms cubic-bezier(0.2, 0, 0, 1); \n} \n.modo-popover-leave { \n animation: modo-popover-out 80ms cubic-bezier(0.3, 0, 1, 1); \n} \n@keyframes modo-popover-in { \n from { opacity: 0; transform: translateY(-4px) scale(0.98); } \n to { opacity: 1; transform: translateY(0) scale(1); } \n} \n@keyframes modo-popover-out { \n from { opacity: 1; transform: translateY(0); } \n to { opacity: 0; transform: translateY(-2px); } \n} \n@media (prefers-reduced-motion: reduce) { \n .modo-popover-enter, .modo-popover-leave { animation: none; } \n} \n</style>\n"],"mappings":""}
|
|
@@ -2,7 +2,7 @@ import _plugin_vue_export_helper_default from "../../_virtual/_plugin-vue_export
|
|
|
2
2
|
import PopoverPanel_vue_vue_type_script_setup_true_lang_default from "./PopoverPanel.vue_vue_type_script_setup_true_lang.mjs";
|
|
3
3
|
/* empty css */
|
|
4
4
|
//#region src/components/layout/PopoverPanel.vue
|
|
5
|
-
var PopoverPanel_default = /* @__PURE__ */ _plugin_vue_export_helper_default(PopoverPanel_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-
|
|
5
|
+
var PopoverPanel_default = /* @__PURE__ */ _plugin_vue_export_helper_default(PopoverPanel_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-8bb79aba"]]);
|
|
6
6
|
//#endregion
|
|
7
7
|
export { PopoverPanel_default as default };
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopoverPanel.mjs","names":[],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"
|
|
1
|
+
{"version":3,"file":"PopoverPanel.mjs","names":[],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover flex flex-col overflow-hidden bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"\n :data-modo-theme=\"scopedTheme || undefined\"\n >\n <!--\n `min-h-0` is what makes the panel's max-height actually bite:\n as a flex child this wrapper defaults to min-height:auto and\n refuses to shrink below its content, so it would render past\n the capped panel instead of scrolling inside it.\n -->\n <div :class=\"['modo-popover-inner min-h-0 flex-1 overflow-x-hidden overflow-y-auto', radiusClass]\">\n <slot />\n </div>\n </div> \n </Transition> \n </Teleport> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch } from 'vue'; \nimport { useResolvedRadius, useResolvedTheme, useModoConfig } from '../../composables/useModoConfig'; \nimport { resolveColorMode } from '../../composables/useColorMode'; \nimport { palettesToCssVars, semanticTokensFromPalettes } from '../../config/palettes'; \nimport { hexToOklchString, pickForegroundOklch } from '../../config/colorPrimitives'; \nimport { surfacesToCssVars } from '../../config/surfaces'; \n \ndefineOptions({ inheritAttrs: false }); \n \nconst props = defineProps<{ \n /** Controla la visibilidad. */ \n open: boolean; \n /** Estilo (top/left/width/zIndex) calculado por `usePopover`. */ \n style?: Record<string, string>; \n /** Radio de esquinas. Si no se pasa, toma el del provider. */ \n radius?: 'none' | 'small' | 'medium' | 'large' | 'full'; \n /** ARIA role. @default 'dialog' */ \n role?: string; \n /** Id del elemento que nombra al panel. */ \n labelledBy?: string; \n}>(); \n \nconst emit = defineEmits<{ 'update:panelRef': [el: HTMLElement | null] }>(); \n \nconst panelEl = ref<HTMLElement | null>(null); \nwatch(panelEl, (el) => emit('update:panelRef', el)); \n \nconst radius = useResolvedRadius(() => props.radius); \nconst theme = useResolvedTheme(); \nconst cfg = useModoConfig(); \n// When the popover is portal'd to <body>, the data-modo-theme attribute on \n// the parent provider is out of scope. Forward it so dark mode works. \nconst scopedTheme = computed(() => resolveColorMode(theme.value)); \n \n// Forward the provider's palette CSS vars (`--primary`, `--primary-foreground`, \n// etc.) to the teleported panel so `bg-primary` / `text-primary` stay in sync \n// with whatever palette the provider set. Also forward surface vars so tinted \n// surfaces (base intensity) are visible inside the popover. \nconst mergedStyle = computed(() => { \n const providerVars = cfg?.value.palettes \n ? { \n ...palettesToCssVars(cfg.value.palettes), \n ...semanticTokensFromPalettes(cfg.value.palettes, hexToOklchString, pickForegroundOklch), \n } \n : {};\n const surfaceVars = cfg?.value.surfaces\n ? surfacesToCssVars(cfg.value.surfaces)\n : {};\n const darkSurfaceVars = (scopedTheme.value === 'dark' && cfg?.value.darkSurfaces)\n ? surfacesToCssVars(cfg.value.darkSurfaces)\n : {};\n return { ...providerVars, ...surfaceVars, ...darkSurfaceVars, ...(props.style ?? {}) }; \n}); \n \nconst radiusClass = computed(() => { \n switch (radius.value) { \n case 'none': return 'rounded-none'; \n case 'small': return 'rounded-sm'; \n case 'large': return 'rounded-xl'; \n case 'full': return 'rounded-2xl'; \n case 'medium': \n default: return 'rounded-md'; \n } \n}); \n</script> \n \n<style scoped> \n.modo-popover { \n transform-origin: top center; \n will-change: transform, opacity; \n} \n.modo-popover-enter { \n animation: modo-popover-in 140ms cubic-bezier(0.2, 0, 0, 1); \n} \n.modo-popover-leave { \n animation: modo-popover-out 80ms cubic-bezier(0.3, 0, 1, 1); \n} \n@keyframes modo-popover-in { \n from { opacity: 0; transform: translateY(-4px) scale(0.98); } \n to { opacity: 1; transform: translateY(0) scale(1); } \n} \n@keyframes modo-popover-out { \n from { opacity: 1; transform: translateY(0); } \n to { opacity: 0; transform: translateY(-2px); } \n} \n@media (prefers-reduced-motion: reduce) { \n .modo-popover-enter, .modo-popover-leave { animation: none; } \n} \n</style>\n"],"mappings":""}
|
|
@@ -67,12 +67,12 @@ var PopoverPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (
|
|
|
67
67
|
"aria-labelledby": __props.labelledBy,
|
|
68
68
|
style: (0, vue.normalizeStyle)(mergedStyle.value),
|
|
69
69
|
class: (0, vue.normalizeClass)([
|
|
70
|
-
"modo-popover bg-popover text-popover-foreground border border-border shadow-lg",
|
|
70
|
+
"modo-popover flex flex-col overflow-hidden bg-popover text-popover-foreground border border-border shadow-lg",
|
|
71
71
|
radiusClass.value,
|
|
72
72
|
_ctx.$attrs.class
|
|
73
73
|
]),
|
|
74
74
|
"data-modo-theme": scopedTheme.value || void 0
|
|
75
|
-
}, [(0, vue.createElementVNode)("div", { class: (0, vue.normalizeClass)(["modo-popover-inner overflow-x-hidden overflow-y-auto", radiusClass.value]) }, [(0, vue.renderSlot)(_ctx.$slots, "default", {}, void 0, true)], 2)], 14, _hoisted_1)) : (0, vue.createCommentVNode)("", true)]),
|
|
75
|
+
}, [(0, vue.createElementVNode)("div", { class: (0, vue.normalizeClass)(["modo-popover-inner min-h-0 flex-1 overflow-x-hidden overflow-y-auto", radiusClass.value]) }, [(0, vue.renderSlot)(_ctx.$slots, "default", {}, void 0, true)], 2)], 14, _hoisted_1)) : (0, vue.createCommentVNode)("", true)]),
|
|
76
76
|
_: 3
|
|
77
77
|
})]);
|
|
78
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopoverPanel.vue_vue_type_script_setup_true_lang.cjs","names":["$attrs"],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"
|
|
1
|
+
{"version":3,"file":"PopoverPanel.vue_vue_type_script_setup_true_lang.cjs","names":["$attrs"],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover flex flex-col overflow-hidden bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"\n :data-modo-theme=\"scopedTheme || undefined\"\n >\n <!--\n `min-h-0` is what makes the panel's max-height actually bite:\n as a flex child this wrapper defaults to min-height:auto and\n refuses to shrink below its content, so it would render past\n the capped panel instead of scrolling inside it.\n -->\n <div :class=\"['modo-popover-inner min-h-0 flex-1 overflow-x-hidden overflow-y-auto', radiusClass]\">\n <slot />\n </div>\n </div> \n </Transition> \n </Teleport> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch } from 'vue'; \nimport { useResolvedRadius, useResolvedTheme, useModoConfig } from '../../composables/useModoConfig'; \nimport { resolveColorMode } from '../../composables/useColorMode'; \nimport { palettesToCssVars, semanticTokensFromPalettes } from '../../config/palettes'; \nimport { hexToOklchString, pickForegroundOklch } from '../../config/colorPrimitives'; \nimport { surfacesToCssVars } from '../../config/surfaces'; \n \ndefineOptions({ inheritAttrs: false }); \n \nconst props = defineProps<{ \n /** Controla la visibilidad. */ \n open: boolean; \n /** Estilo (top/left/width/zIndex) calculado por `usePopover`. */ \n style?: Record<string, string>; \n /** Radio de esquinas. Si no se pasa, toma el del provider. */ \n radius?: 'none' | 'small' | 'medium' | 'large' | 'full'; \n /** ARIA role. @default 'dialog' */ \n role?: string; \n /** Id del elemento que nombra al panel. */ \n labelledBy?: string; \n}>(); \n \nconst emit = defineEmits<{ 'update:panelRef': [el: HTMLElement | null] }>(); \n \nconst panelEl = ref<HTMLElement | null>(null); \nwatch(panelEl, (el) => emit('update:panelRef', el)); \n \nconst radius = useResolvedRadius(() => props.radius); \nconst theme = useResolvedTheme(); \nconst cfg = useModoConfig(); \n// When the popover is portal'd to <body>, the data-modo-theme attribute on \n// the parent provider is out of scope. Forward it so dark mode works. \nconst scopedTheme = computed(() => resolveColorMode(theme.value)); \n \n// Forward the provider's palette CSS vars (`--primary`, `--primary-foreground`, \n// etc.) to the teleported panel so `bg-primary` / `text-primary` stay in sync \n// with whatever palette the provider set. Also forward surface vars so tinted \n// surfaces (base intensity) are visible inside the popover. \nconst mergedStyle = computed(() => { \n const providerVars = cfg?.value.palettes \n ? { \n ...palettesToCssVars(cfg.value.palettes), \n ...semanticTokensFromPalettes(cfg.value.palettes, hexToOklchString, pickForegroundOklch), \n } \n : {};\n const surfaceVars = cfg?.value.surfaces\n ? surfacesToCssVars(cfg.value.surfaces)\n : {};\n const darkSurfaceVars = (scopedTheme.value === 'dark' && cfg?.value.darkSurfaces)\n ? surfacesToCssVars(cfg.value.darkSurfaces)\n : {};\n return { ...providerVars, ...surfaceVars, ...darkSurfaceVars, ...(props.style ?? {}) }; \n}); \n \nconst radiusClass = computed(() => { \n switch (radius.value) { \n case 'none': return 'rounded-none'; \n case 'small': return 'rounded-sm'; \n case 'large': return 'rounded-xl'; \n case 'full': return 'rounded-2xl'; \n case 'medium': \n default: return 'rounded-md'; \n } \n}); \n</script> \n \n<style scoped> \n.modo-popover { \n transform-origin: top center; \n will-change: transform, opacity; \n} \n.modo-popover-enter { \n animation: modo-popover-in 140ms cubic-bezier(0.2, 0, 0, 1); \n} \n.modo-popover-leave { \n animation: modo-popover-out 80ms cubic-bezier(0.3, 0, 1, 1); \n} \n@keyframes modo-popover-in { \n from { opacity: 0; transform: translateY(-4px) scale(0.98); } \n to { opacity: 1; transform: translateY(0) scale(1); } \n} \n@keyframes modo-popover-out { \n from { opacity: 1; transform: translateY(0); } \n to { opacity: 0; transform: translateY(-2px); } \n} \n@media (prefers-reduced-motion: reduce) { \n .modo-popover-enter, .modo-popover-leave { animation: none; } \n} \n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EA2CA,MAAM,QAAQ;EAad,MAAM,OAAO;EAEb,MAAM,WAAA,GAAA,IAAA,KAAkC,KAAK;EAC7C,CAAA,GAAA,IAAA,OAAM,UAAU,OAAO,KAAK,mBAAmB,GAAG,CAAC;EAEnD,MAAM,SAAS,sBAAA,wBAAwB,MAAM,OAAO;EACpD,MAAM,QAAQ,sBAAA,kBAAkB;EAChC,MAAM,MAAM,sBAAA,eAAe;EAG3B,MAAM,eAAA,GAAA,IAAA,gBAA6B,qBAAA,iBAAiB,MAAM,MAAM,CAAC;EAMjE,MAAM,eAAA,GAAA,IAAA,gBAA6B;GAC/B,MAAM,eAAe,KAAK,MAAM,WAC1B;IACI,GAAG,iBAAA,kBAAkB,IAAI,MAAM,SAAS;IACxC,GAAG,iBAAA,2BAA2B,IAAI,MAAM,UAAU,wBAAA,kBAAkB,wBAAA,oBAAoB;IAC3F,GACD,EAAE;GACR,MAAM,cAAc,KAAK,MAAM,WACzB,iBAAA,kBAAkB,IAAI,MAAM,SAAQ,GACpC,EAAE;GACR,MAAM,kBAAmB,YAAY,UAAU,UAAU,KAAK,MAAM,eAC9D,iBAAA,kBAAkB,IAAI,MAAM,aAAY,GACxC,EAAE;GACR,OAAO;IAAE,GAAG;IAAc,GAAG;IAAa,GAAG;IAAiB,GAAI,MAAM,SAAS,EAAE;IAAG;IACxF;EAEF,MAAM,eAAA,GAAA,IAAA,gBAA6B;GAC/B,QAAQ,OAAO,OAAf;IACI,KAAK,QAAQ,OAAO;IACpB,KAAK,SAAS,OAAO;IACrB,KAAK,SAAS,OAAO;IACrB,KAAK,QAAQ,OAAO;IAEpB,SAAS,OAAO;;IAEtB;;qDAnEa,IAAA,UAAA,EA7BD,IAAG,QAAM,EAAA,EAAA,GAAA,IAAA,aA4BF,IAAA,YAAA;IA1BT,sBAAmB;IACnB,sBAAmB;;oCAwBb,CArBI,QAAA,SAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,oBAqBJ,OAAA;;cApBE;KAAJ,KAAI;KACH,MAAM,QAAA;KACN,mBAAiB,QAAA;KACjB,QAAA,GAAA,IAAA,gBAAO,YAAA,MAAW;KAClB,QAAA,GAAA,IAAA,gBAAK;;MAA4J,YAAA;MAAiCA,KAAAA,OAAO;;KAKzM,mBAAiB,YAAA,SAAe,KAAA;oCAU3B,OAAA,EAFA,QAAA,GAAA,IAAA,gBAAK,CAAA,uEAA0E,YAAA,MAAW,CAAA,EAAA,EAAA,EAAA,GAAA,IAAA,YACpF,KAAA,QAAA,WAAA,EAAA,EAAA,KAAA,GAAA,KAAA,CAAA,EAAA,EAAA,CAAA,EAAA,IAAA,WAAA,KAAA,GAAA,IAAA,oBAAA,IAAA,KAAA,CAAA,CAAA"}
|
|
@@ -66,12 +66,12 @@ var PopoverPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ d
|
|
|
66
66
|
"aria-labelledby": __props.labelledBy,
|
|
67
67
|
style: normalizeStyle(mergedStyle.value),
|
|
68
68
|
class: normalizeClass([
|
|
69
|
-
"modo-popover bg-popover text-popover-foreground border border-border shadow-lg",
|
|
69
|
+
"modo-popover flex flex-col overflow-hidden bg-popover text-popover-foreground border border-border shadow-lg",
|
|
70
70
|
radiusClass.value,
|
|
71
71
|
_ctx.$attrs.class
|
|
72
72
|
]),
|
|
73
73
|
"data-modo-theme": scopedTheme.value || void 0
|
|
74
|
-
}, [createElementVNode("div", { class: normalizeClass(["modo-popover-inner overflow-x-hidden overflow-y-auto", radiusClass.value]) }, [renderSlot(_ctx.$slots, "default", {}, void 0, true)], 2)], 14, _hoisted_1)) : createCommentVNode("", true)]),
|
|
74
|
+
}, [createElementVNode("div", { class: normalizeClass(["modo-popover-inner min-h-0 flex-1 overflow-x-hidden overflow-y-auto", radiusClass.value]) }, [renderSlot(_ctx.$slots, "default", {}, void 0, true)], 2)], 14, _hoisted_1)) : createCommentVNode("", true)]),
|
|
75
75
|
_: 3
|
|
76
76
|
})]);
|
|
77
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopoverPanel.vue_vue_type_script_setup_true_lang.mjs","names":["$attrs"],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"
|
|
1
|
+
{"version":3,"file":"PopoverPanel.vue_vue_type_script_setup_true_lang.mjs","names":["$attrs"],"sources":["../../../src/components/layout/PopoverPanel.vue"],"sourcesContent":["<template> \n <Teleport to=\"body\"> \n <Transition \n enter-active-class=\"modo-popover-enter\" \n leave-active-class=\"modo-popover-leave\" \n > \n <div \n v-if=\"open\" \n ref=\"panelEl\" \n :role=\"role\" \n :aria-labelledby=\"labelledBy\" \n :style=\"mergedStyle\" \n :class=\"[\n 'modo-popover flex flex-col overflow-hidden bg-popover text-popover-foreground border border-border shadow-lg',\n radiusClass,\n $attrs.class,\n ]\"\n :data-modo-theme=\"scopedTheme || undefined\"\n >\n <!--\n `min-h-0` is what makes the panel's max-height actually bite:\n as a flex child this wrapper defaults to min-height:auto and\n refuses to shrink below its content, so it would render past\n the capped panel instead of scrolling inside it.\n -->\n <div :class=\"['modo-popover-inner min-h-0 flex-1 overflow-x-hidden overflow-y-auto', radiusClass]\">\n <slot />\n </div>\n </div> \n </Transition> \n </Teleport> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch } from 'vue'; \nimport { useResolvedRadius, useResolvedTheme, useModoConfig } from '../../composables/useModoConfig'; \nimport { resolveColorMode } from '../../composables/useColorMode'; \nimport { palettesToCssVars, semanticTokensFromPalettes } from '../../config/palettes'; \nimport { hexToOklchString, pickForegroundOklch } from '../../config/colorPrimitives'; \nimport { surfacesToCssVars } from '../../config/surfaces'; \n \ndefineOptions({ inheritAttrs: false }); \n \nconst props = defineProps<{ \n /** Controla la visibilidad. */ \n open: boolean; \n /** Estilo (top/left/width/zIndex) calculado por `usePopover`. */ \n style?: Record<string, string>; \n /** Radio de esquinas. Si no se pasa, toma el del provider. */ \n radius?: 'none' | 'small' | 'medium' | 'large' | 'full'; \n /** ARIA role. @default 'dialog' */ \n role?: string; \n /** Id del elemento que nombra al panel. */ \n labelledBy?: string; \n}>(); \n \nconst emit = defineEmits<{ 'update:panelRef': [el: HTMLElement | null] }>(); \n \nconst panelEl = ref<HTMLElement | null>(null); \nwatch(panelEl, (el) => emit('update:panelRef', el)); \n \nconst radius = useResolvedRadius(() => props.radius); \nconst theme = useResolvedTheme(); \nconst cfg = useModoConfig(); \n// When the popover is portal'd to <body>, the data-modo-theme attribute on \n// the parent provider is out of scope. Forward it so dark mode works. \nconst scopedTheme = computed(() => resolveColorMode(theme.value)); \n \n// Forward the provider's palette CSS vars (`--primary`, `--primary-foreground`, \n// etc.) to the teleported panel so `bg-primary` / `text-primary` stay in sync \n// with whatever palette the provider set. Also forward surface vars so tinted \n// surfaces (base intensity) are visible inside the popover. \nconst mergedStyle = computed(() => { \n const providerVars = cfg?.value.palettes \n ? { \n ...palettesToCssVars(cfg.value.palettes), \n ...semanticTokensFromPalettes(cfg.value.palettes, hexToOklchString, pickForegroundOklch), \n } \n : {};\n const surfaceVars = cfg?.value.surfaces\n ? surfacesToCssVars(cfg.value.surfaces)\n : {};\n const darkSurfaceVars = (scopedTheme.value === 'dark' && cfg?.value.darkSurfaces)\n ? surfacesToCssVars(cfg.value.darkSurfaces)\n : {};\n return { ...providerVars, ...surfaceVars, ...darkSurfaceVars, ...(props.style ?? {}) }; \n}); \n \nconst radiusClass = computed(() => { \n switch (radius.value) { \n case 'none': return 'rounded-none'; \n case 'small': return 'rounded-sm'; \n case 'large': return 'rounded-xl'; \n case 'full': return 'rounded-2xl'; \n case 'medium': \n default: return 'rounded-md'; \n } \n}); \n</script> \n \n<style scoped> \n.modo-popover { \n transform-origin: top center; \n will-change: transform, opacity; \n} \n.modo-popover-enter { \n animation: modo-popover-in 140ms cubic-bezier(0.2, 0, 0, 1); \n} \n.modo-popover-leave { \n animation: modo-popover-out 80ms cubic-bezier(0.3, 0, 1, 1); \n} \n@keyframes modo-popover-in { \n from { opacity: 0; transform: translateY(-4px) scale(0.98); } \n to { opacity: 1; transform: translateY(0) scale(1); } \n} \n@keyframes modo-popover-out { \n from { opacity: 1; transform: translateY(0); } \n to { opacity: 0; transform: translateY(-2px); } \n} \n@media (prefers-reduced-motion: reduce) { \n .modo-popover-enter, .modo-popover-leave { animation: none; } \n} \n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EA2CA,MAAM,QAAQ;EAad,MAAM,OAAO;EAEb,MAAM,UAAU,IAAwB,KAAK;EAC7C,MAAM,UAAU,OAAO,KAAK,mBAAmB,GAAG,CAAC;EAEnD,MAAM,SAAS,wBAAwB,MAAM,OAAO;EACpD,MAAM,QAAQ,kBAAkB;EAChC,MAAM,MAAM,eAAe;EAG3B,MAAM,cAAc,eAAe,iBAAiB,MAAM,MAAM,CAAC;EAMjE,MAAM,cAAc,eAAe;GAC/B,MAAM,eAAe,KAAK,MAAM,WAC1B;IACI,GAAG,kBAAkB,IAAI,MAAM,SAAS;IACxC,GAAG,2BAA2B,IAAI,MAAM,UAAU,kBAAkB,oBAAoB;IAC3F,GACD,EAAE;GACR,MAAM,cAAc,KAAK,MAAM,WACzB,kBAAkB,IAAI,MAAM,SAAQ,GACpC,EAAE;GACR,MAAM,kBAAmB,YAAY,UAAU,UAAU,KAAK,MAAM,eAC9D,kBAAkB,IAAI,MAAM,aAAY,GACxC,EAAE;GACR,OAAO;IAAE,GAAG;IAAc,GAAG;IAAa,GAAG;IAAiB,GAAI,MAAM,SAAS,EAAE;IAAG;IACxF;EAEF,MAAM,cAAc,eAAe;GAC/B,QAAQ,OAAO,OAAf;IACI,KAAK,QAAQ,OAAO;IACpB,KAAK,SAAS,OAAO;IACrB,KAAK,SAAS,OAAO;IACrB,KAAK,QAAQ,OAAO;IAEpB,SAAS,OAAO;;IAEtB;;uBAhGE,YA6BW,UAAA,EA7BD,IAAG,QAAM,EAAA,CACf,YA2Ba,YAAA;IA1BT,sBAAmB;IACnB,sBAAmB;;2BAwBb,CArBI,QAAA,QAAA,WAAA,EADV,mBAsBM,OAAA;;cApBE;KAAJ,KAAI;KACH,MAAM,QAAA;KACN,mBAAiB,QAAA;KACjB,OAAK,eAAE,YAAA,MAAW;KAClB,OAAK,eAAA;;MAA4J,YAAA;MAAiCA,KAAAA,OAAO;;KAKzM,mBAAiB,YAAA,SAAe,KAAA;QAQjC,mBAEM,OAAA,EAFA,OAAK,eAAA,CAAA,uEAA0E,YAAA,MAAW,CAAA,EAAA,EAAA,CAC5F,WAAQ,KAAA,QAAA,WAAA,EAAA,EAAA,KAAA,GAAA,KAAA,CAAA,EAAA,EAAA,CAAA,EAAA,IAAA,WAAA,IAAA,mBAAA,IAAA,KAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switcher.cjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center gap-3 px-3 py-2 text-left transition-colors',\n 'border bg-card text-card-foreground border-border',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span v-if=\"activeItem?.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n class=\"shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-md bg-accent/60 text-foreground\"\n >\n <component :is=\"activeItem.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n class=\"shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-md bg-accent/60 text-foreground\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Switcher.cjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center gap-3 px-3 py-2 text-left transition-colors',\n 'border bg-card text-card-foreground border-border',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span v-if=\"activeItem?.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"activeItem.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switcher.mjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center gap-3 px-3 py-2 text-left transition-colors',\n 'border bg-card text-card-foreground border-border',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span v-if=\"activeItem?.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n class=\"shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-md bg-accent/60 text-foreground\"\n >\n <component :is=\"activeItem.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n class=\"shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-md bg-accent/60 text-foreground\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Switcher.mjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center gap-3 px-3 py-2 text-left transition-colors',\n 'border bg-card text-card-foreground border-border',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span v-if=\"activeItem?.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"activeItem.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
|
|
@@ -16,37 +16,33 @@ var _hoisted_2 = {
|
|
|
16
16
|
key: 0,
|
|
17
17
|
class: "shrink-0"
|
|
18
18
|
};
|
|
19
|
-
var _hoisted_3 = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
var _hoisted_4 = { class: "flex flex-col min-w-0 flex-1" };
|
|
24
|
-
var _hoisted_5 = { class: "truncate text-body font-medium" };
|
|
25
|
-
var _hoisted_6 = {
|
|
19
|
+
var _hoisted_3 = { class: "flex flex-col min-w-0 flex-1" };
|
|
20
|
+
var _hoisted_4 = { class: "truncate text-body font-medium" };
|
|
21
|
+
var _hoisted_5 = {
|
|
26
22
|
key: 0,
|
|
27
23
|
class: "truncate text-caption text-muted-foreground"
|
|
28
24
|
};
|
|
29
|
-
var
|
|
25
|
+
var _hoisted_6 = {
|
|
30
26
|
key: 0,
|
|
31
27
|
class: "px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider"
|
|
32
28
|
};
|
|
33
|
-
var
|
|
29
|
+
var _hoisted_7 = {
|
|
34
30
|
key: 1,
|
|
35
31
|
class: "px-2 pt-2 pb-1"
|
|
36
32
|
};
|
|
37
|
-
var
|
|
33
|
+
var _hoisted_8 = [
|
|
38
34
|
"placeholder",
|
|
39
35
|
"aria-controls",
|
|
40
36
|
"aria-activedescendant"
|
|
41
37
|
];
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
38
|
+
var _hoisted_9 = { class: "p-2 flex flex-col gap-1" };
|
|
39
|
+
var _hoisted_10 = { class: "px-3 py-6 text-center text-muted-foreground text-body" };
|
|
40
|
+
var _hoisted_11 = {
|
|
45
41
|
key: 4,
|
|
46
42
|
class: "px-3 py-6 text-center text-muted-foreground text-body"
|
|
47
43
|
};
|
|
48
|
-
var
|
|
49
|
-
var
|
|
44
|
+
var _hoisted_12 = ["id"];
|
|
45
|
+
var _hoisted_13 = [
|
|
50
46
|
"id",
|
|
51
47
|
"aria-selected",
|
|
52
48
|
"aria-current",
|
|
@@ -55,22 +51,17 @@ var _hoisted_14 = [
|
|
|
55
51
|
"onClick",
|
|
56
52
|
"onMouseenter"
|
|
57
53
|
];
|
|
58
|
-
var
|
|
54
|
+
var _hoisted_14 = {
|
|
59
55
|
key: 0,
|
|
60
56
|
class: "shrink-0"
|
|
61
57
|
};
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class: "shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-md bg-accent/60 text-foreground"
|
|
66
|
-
};
|
|
67
|
-
var _hoisted_17 = { class: "flex flex-col min-w-0 flex-1" };
|
|
68
|
-
var _hoisted_18 = { class: "truncate text-body font-medium" };
|
|
69
|
-
var _hoisted_19 = {
|
|
58
|
+
var _hoisted_15 = { class: "flex flex-col min-w-0 flex-1" };
|
|
59
|
+
var _hoisted_16 = { class: "truncate text-body font-medium" };
|
|
60
|
+
var _hoisted_17 = {
|
|
70
61
|
key: 0,
|
|
71
62
|
class: "truncate text-caption text-muted-foreground"
|
|
72
63
|
};
|
|
73
|
-
var
|
|
64
|
+
var _hoisted_18 = { class: "p-1" };
|
|
74
65
|
var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
75
66
|
__name: "Switcher",
|
|
76
67
|
props: {
|
|
@@ -382,11 +373,14 @@ var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, v
|
|
|
382
373
|
"src",
|
|
383
374
|
"initials",
|
|
384
375
|
"name"
|
|
385
|
-
])])) : activeItem.value?.icon ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span",
|
|
376
|
+
])])) : activeItem.value?.icon ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
|
|
377
|
+
key: 1,
|
|
378
|
+
class: (0, vue.normalizeClass)(["shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground", radiusClass.value])
|
|
379
|
+
}, [((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(activeItem.value.icon), {
|
|
386
380
|
class: "w-5 h-5",
|
|
387
381
|
"aria-hidden": "true"
|
|
388
|
-
}))])) : (0, vue.createCommentVNode)("", true),
|
|
389
|
-
(0, vue.createElementVNode)("span",
|
|
382
|
+
}))], 2)) : (0, vue.createCommentVNode)("", true),
|
|
383
|
+
(0, vue.createElementVNode)("span", _hoisted_3, [(0, vue.createElementVNode)("span", _hoisted_4, (0, vue.toDisplayString)(activeItem.value ? activeItem.value.title : resolvedPlaceholder.value), 1), !__props.compactTrigger && activeItem.value?.subtitle ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", _hoisted_5, (0, vue.toDisplayString)(activeItem.value.subtitle), 1)) : (0, vue.createCommentVNode)("", true)]),
|
|
390
384
|
__props.chevron === "updown" ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_heroicons_vue_24_outline.ChevronUpDownIcon), {
|
|
391
385
|
key: 2,
|
|
392
386
|
class: "w-4 h-4 shrink-0 text-muted-foreground",
|
|
@@ -409,8 +403,8 @@ var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, v
|
|
|
409
403
|
class: "modo-switcher-panel overflow-y-auto",
|
|
410
404
|
style: (0, vue.normalizeStyle)({ maxHeight: panelMaxHeightStyle.value })
|
|
411
405
|
}, [
|
|
412
|
-
__props.panelTitle ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div",
|
|
413
|
-
__props.searchable ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div",
|
|
406
|
+
__props.panelTitle ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_6, (0, vue.toDisplayString)(__props.panelTitle), 1)) : (0, vue.createCommentVNode)("", true),
|
|
407
|
+
__props.searchable ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_7, [(0, vue.withDirectives)((0, vue.createElementVNode)("input", {
|
|
414
408
|
ref_key: "searchInputEl",
|
|
415
409
|
ref: searchInputEl,
|
|
416
410
|
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchQuery.value = $event),
|
|
@@ -421,13 +415,13 @@ var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, v
|
|
|
421
415
|
"aria-activedescendant": activeDescendantId.value,
|
|
422
416
|
class: "w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
|
423
417
|
onKeydown: onSearchKeydown
|
|
424
|
-
}, null, 40,
|
|
425
|
-
__props.loading ? (0, vue.renderSlot)(_ctx.$slots, "loading", { key: 2 }, () => [(0, vue.createElementVNode)("div",
|
|
418
|
+
}, null, 40, _hoisted_8), [[vue.vModelText, searchQuery.value]])])) : (0, vue.createCommentVNode)("", true),
|
|
419
|
+
__props.loading ? (0, vue.renderSlot)(_ctx.$slots, "loading", { key: 2 }, () => [(0, vue.createElementVNode)("div", _hoisted_9, [((0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, null, (0, vue.renderList)(3, (i) => {
|
|
426
420
|
return (0, vue.createElementVNode)("div", {
|
|
427
421
|
key: i,
|
|
428
422
|
"data-modo-switcher-skeleton": ""
|
|
429
423
|
}, [(0, vue.createVNode)(require_Skeleton.default, { height: "44px" })]);
|
|
430
|
-
}), 64))])]) : __props.items.length === 0 ? (0, vue.renderSlot)(_ctx.$slots, "empty", { key: 3 }, () => [(0, vue.createElementVNode)("div",
|
|
424
|
+
}), 64))])]) : __props.items.length === 0 ? (0, vue.renderSlot)(_ctx.$slots, "empty", { key: 3 }, () => [(0, vue.createElementVNode)("div", _hoisted_10, (0, vue.toDisplayString)(resolvedEmptyText.value), 1)]) : displayedItems.value.length === 0 ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_11, (0, vue.toDisplayString)(resolvedNoResults.value), 1)) : ((0, vue.openBlock)(), (0, vue.createElementBlock)("ul", {
|
|
431
425
|
key: 5,
|
|
432
426
|
role: "listbox",
|
|
433
427
|
id: (0, vue.unref)(listboxId),
|
|
@@ -453,7 +447,7 @@ var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, v
|
|
|
453
447
|
onClick: ($event) => selectItem(item),
|
|
454
448
|
onMouseenter: ($event) => __props.searchable ? highlightedIdx.value = idx : null
|
|
455
449
|
}, [
|
|
456
|
-
item.avatar ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span",
|
|
450
|
+
item.avatar ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", _hoisted_14, [(0, vue.createVNode)(require_Avatar.default, {
|
|
457
451
|
src: item.avatar.src,
|
|
458
452
|
initials: item.avatar.initials,
|
|
459
453
|
name: item.title,
|
|
@@ -462,11 +456,15 @@ var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, v
|
|
|
462
456
|
"src",
|
|
463
457
|
"initials",
|
|
464
458
|
"name"
|
|
465
|
-
])])) : item.icon ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span",
|
|
459
|
+
])])) : item.icon ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
|
|
460
|
+
key: 1,
|
|
461
|
+
"data-modo-switcher-iconwrap": "",
|
|
462
|
+
class: (0, vue.normalizeClass)(["shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground", radiusClass.value])
|
|
463
|
+
}, [((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(item.icon), {
|
|
466
464
|
class: "w-5 h-5",
|
|
467
465
|
"aria-hidden": "true"
|
|
468
|
-
}))])) : (0, vue.createCommentVNode)("", true),
|
|
469
|
-
(0, vue.createElementVNode)("span",
|
|
466
|
+
}))], 2)) : (0, vue.createCommentVNode)("", true),
|
|
467
|
+
(0, vue.createElementVNode)("span", _hoisted_15, [(0, vue.createElementVNode)("span", _hoisted_16, (0, vue.toDisplayString)(item.title), 1), item.subtitle ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", _hoisted_17, (0, vue.toDisplayString)(item.subtitle), 1)) : (0, vue.createCommentVNode)("", true)]),
|
|
470
468
|
(0, vue.renderSlot)(_ctx.$slots, "item-trailing", {
|
|
471
469
|
item,
|
|
472
470
|
active: item.value === __props.modelValue,
|
|
@@ -476,13 +474,13 @@ var Switcher_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0, v
|
|
|
476
474
|
class: "w-4 h-4 shrink-0",
|
|
477
475
|
"aria-hidden": "true"
|
|
478
476
|
})) : (0, vue.createCommentVNode)("", true)])
|
|
479
|
-
], 42,
|
|
480
|
-
}), 128))], 40,
|
|
477
|
+
], 42, _hoisted_13);
|
|
478
|
+
}), 128))], 40, _hoisted_12)),
|
|
481
479
|
_ctx.$slots.footer ? ((0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, { key: 6 }, [_cache[2] || (_cache[2] = (0, vue.createElementVNode)("hr", {
|
|
482
480
|
"data-modo-switcher-footer-sep": "",
|
|
483
481
|
role: "separator",
|
|
484
482
|
class: "my-1 border-t border-border"
|
|
485
|
-
}, null, -1)), (0, vue.createElementVNode)("div",
|
|
483
|
+
}, null, -1)), (0, vue.createElementVNode)("div", _hoisted_18, [(0, vue.renderSlot)(_ctx.$slots, "footer", { close: (0, vue.unref)(close) })])], 64)) : (0, vue.createCommentVNode)("", true)
|
|
486
484
|
], 4)]),
|
|
487
485
|
_: 3
|
|
488
486
|
}, 8, [
|