-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from codex-team/popover
feat(ui): popover
- Loading branch information
Showing
10 changed files
with
382 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
@import './dimensions.pcss'; | ||
@import './typography.pcss'; | ||
@import './mixins.pcss'; | ||
@import './z-axis.pcss'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:root { | ||
--z-popover: 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Component } from 'vue'; | ||
|
||
/** | ||
* Popover content: component and props | ||
*/ | ||
export interface PopoverContent { | ||
/** | ||
* Component to render in the popover | ||
*/ | ||
component: Component; | ||
|
||
/** | ||
* Props to pass to the component | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
props: Record<string, any>; | ||
} | ||
|
||
/** | ||
* Popover showing configuration | ||
*/ | ||
export interface PopoverShowParams { | ||
/** | ||
* Element to move popover to | ||
*/ | ||
targetEl: HTMLElement; | ||
|
||
/** | ||
* Popover content: component and props | ||
*/ | ||
with: PopoverContent; | ||
|
||
/** | ||
* Vertical and horizontal alignment | ||
*/ | ||
align: { | ||
vertically: 'above' | 'below'; | ||
horizontally: 'left' | 'right'; | ||
}; | ||
|
||
/** | ||
* Allows to stretch popover to the target element width | ||
*/ | ||
width?: 'fit-target' | 'auto'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<template> | ||
<div | ||
v-show="isOpen" | ||
ref="popoverEl" | ||
:class="$style.popover" | ||
> | ||
<component | ||
:is="content.component" | ||
v-if="content" | ||
v-bind="content.props" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import { usePopover } from './usePopover'; | ||
import { onClickOutside } from '@vueuse/core'; | ||
/** | ||
* Reference to the popover element | ||
* Used to bind click-outside event | ||
*/ | ||
const popoverEl = ref<HTMLDivElement | null>(null); | ||
const { | ||
isOpen, | ||
position, | ||
hide, | ||
content, | ||
width, | ||
} = usePopover(); | ||
/** | ||
* Close the popover when clicking outside of it | ||
*/ | ||
onClickOutside(popoverEl, hide); | ||
</script> | ||
|
||
<style module> | ||
.popover { | ||
position: absolute; | ||
z-index: var(--z-popover); | ||
background-color: var(--base--bg-secondary); | ||
border-radius: var(--radius-field); | ||
border: 1px solid var(--base--border); | ||
padding: var(--h-padding); | ||
left: v-bind('position.left'); | ||
top: v-bind('position.top'); | ||
transform: v-bind('position.transform'); | ||
width: v-bind('width'); | ||
box-sizing: border-box; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Popover from './Popover.vue'; | ||
|
||
export * from './usePopover'; | ||
export * from './Popover.types'; | ||
export { Popover }; |
Oops, something went wrong.