Skip to content

Commit

Permalink
chore: update Vue components and references (oku-ui#500)
Browse files Browse the repository at this point in the history
* chore: update Vue components

* chore: update component references and expose current element

* chore: remove unused import in AvatarImage.vue
  • Loading branch information
productdevbook authored Jan 15, 2024
1 parent eee68a6 commit aa1d04d
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 26 deletions.
6 changes: 5 additions & 1 deletion packages/vue/src/arrow/Arrow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const props = withDefaults(
},
)
const { componentRef } = useComponentRef<HTMLDivElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLDivElement | null>()
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
6 changes: 5 additions & 1 deletion packages/vue/src/aspect-ratio/AspectRatio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const props = withDefaults(defineProps<AspectRatioProps>(), {
ratio: 1 / 1,
})
const { componentRef } = useComponentRef<HTMLDivElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLDivElement | null>()
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
7 changes: 6 additions & 1 deletion packages/vue/src/avatar/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ const props = withDefaults(defineProps<AvatarProps>(), {
const imageLoadingStatus = ref<ImageLoadingStatus>('idle')
const { componentRef } = useComponentRef<HTMLLabelElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLLabelElement | null>()
useProvider({
scope: props.scopeOkuAvatar,
imageLoadingStatus,
onImageLoadingStatusChange: (status: ImageLoadingStatus) => imageLoadingStatus.value = status,
})
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
6 changes: 5 additions & 1 deletion packages/vue/src/avatar/AvatarFallback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const props = withDefaults(defineProps<AvatarFallbackProps>(), {
is: 'span',
})
const { componentRef } = useComponentRef<HTMLLabelElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLLabelElement | null>()
let timerId: number
Expand All @@ -36,6 +36,10 @@ function setupTimer() {
onMounted(() => setupTimer())
onBeforeUnmount(() => window.clearTimeout(timerId))
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
8 changes: 6 additions & 2 deletions packages/vue/src/avatar/AvatarImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type AvatarImageEmits = {
</script>

<script setup lang="ts">
import { defineEmits, defineOptions, defineProps, watchEffect, withDefaults } from 'vue'
import { defineOptions, watchEffect, withDefaults } from 'vue'
import { useComponentRef } from '@oku-ui/use-composable'
import { Primitive } from '@oku-ui/primitive'
import { useAvatarInject } from './Avatar.vue'
Expand All @@ -30,7 +30,7 @@ const props = withDefaults(defineProps<AvatarImageProps>(), {
const emits = defineEmits<AvatarImageEmits>()
const { componentRef } = useComponentRef<HTMLLabelElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLLabelElement | null>()
const inject = useAvatarInject('OkuAvatar', props.scopeOkuAvatar)
Expand All @@ -45,6 +45,10 @@ watchEffect(() => {
if (imageLoadingStatus.value !== 'idle')
handleLoadingStatusChange(imageLoadingStatus.value)
})
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
5 changes: 4 additions & 1 deletion packages/vue/src/checkbox/BubbleInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface BubbleInputProps {
</script>

<script setup lang="ts">
import { computed, defineOptions, defineProps, toRefs, watchEffect, withDefaults } from 'vue'
import { computed, defineOptions, toRefs, watchEffect, withDefaults } from 'vue'
import { useComponentRef, usePrevious, useSize } from '@oku-ui/use-composable'
import { isIndeterminate } from './utils'
Expand Down Expand Up @@ -44,6 +44,9 @@ watchEffect(() => {
}
})
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
5 changes: 4 additions & 1 deletion packages/vue/src/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const { useInject, useProvider }

<script setup lang="ts">
import type { Ref } from 'vue'
import { computed, defineOptions, defineProps, onMounted, ref, toRef, watchEffect, withDefaults } from 'vue'
import { computed, defineOptions, onMounted, ref, toRef, watchEffect, withDefaults } from 'vue'
import { useComponentRef, useControllable, useVModel } from '@oku-ui/use-composable'
import { Primitive } from '@oku-ui/primitive'
import { composeEventHandlers } from '@oku-ui/utils'
Expand Down Expand Up @@ -106,6 +106,9 @@ useProvider({
disabled: toRef(props, 'disabled'),
})
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
7 changes: 5 additions & 2 deletions packages/vue/src/checkbox/CheckboxIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CheckboxIndicatorProps extends PrimitiveProps {
</script>

<script setup lang="ts">
import { defineOptions, defineProps, withDefaults } from 'vue'
import { defineOptions, withDefaults } from 'vue'
import { useComponentRef } from '@oku-ui/use-composable'
import { getState, isIndeterminate } from './utils'
import { OkuPresence } from '@oku-ui/presence'
Expand All @@ -28,10 +28,13 @@ const props = withDefaults(defineProps<CheckboxIndicatorProps>(), {
forceMount: undefined,
})
const { componentRef } = useComponentRef<HTMLInputElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLInputElement | null>()
const inject = useInject('OkuCheckbox', props.scopeOkuCheckbox)
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/dismissable-layer/DismissableLayer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { computed, defineExpose, defineOptions, nextTick, reactive, useAttrs, watchEffect } from 'vue'
import { computed, defineOptions, nextTick, reactive, useAttrs, watchEffect } from 'vue'
import type { DismissableLayerBranchElement, DismissableLayerElement, FocusBlurCaptureEvent, FocusCaptureEvent, FocusOutsideEvent, PointerdownCaptureEvent, PointerdownOutsideEvent } from './props'
export const context = reactive({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { PrimitiveProps } from '@oku-ui/primitive'
import { Primitive } from '@oku-ui/primitive'
import { defineExpose, defineOptions, defineProps, onMounted, onUnmounted } from 'vue'
import { defineOptions, onMounted, onUnmounted } from 'vue'
import { useComponentRef } from '@oku-ui/use-composable'
import type { DismissableLayerBranchElement } from './props'
import { context } from './DismissableLayer.vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { defineEmits, defineProps, ref, withDefaults } from 'vue'
import { defineProps, ref, withDefaults } from 'vue'
import { OkuPopper, OkuPopperAnchor, OkuPopperArrow, OkuPopperContent } from '@oku-ui/popper'
import { OkuFocusGuards } from '@oku-ui/focus-guards'
import { OkuPortal } from '@oku-ui/portal'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/focus-scope/FocusScope.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { Primitive } from '@oku-ui/primitive'
import type { PrimitiveProps } from '@oku-ui/primitive'
import { defineExpose, defineOptions, nextTick, reactive, ref, watchEffect } from 'vue'
import { defineOptions, nextTick, reactive, ref, watchEffect } from 'vue'
import { useComponentRef } from '@oku-ui/use-composable'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/label/Label.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { defineExpose, mergeProps, useAttrs } from 'vue'
import { mergeProps, useAttrs } from 'vue'
import { useComponentRef, useListeners } from '@oku-ui/use-composable'
import type { PrimitiveProps } from '@oku-ui/primitive'
import { Primitive } from '@oku-ui/primitive'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/popper/PopperAnchor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface PopperAnchorProps extends PrimitiveProps {
</script>

<script setup lang="ts">
import { defineExpose, defineOptions, watchEffect, withDefaults } from 'vue'
import { defineOptions, watchEffect, withDefaults } from 'vue'
import { usePopperInject } from './Popper.vue'
import { Primitive } from '@oku-ui/primitive'
import { useComponentRef } from '@oku-ui/use-composable'
Expand Down
11 changes: 6 additions & 5 deletions packages/vue/src/popper/PopperArrow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const OPPOSITE_SIDE: Record<Side, Side> = {
</script>

<script setup lang="ts">
import { computed, defineExpose, defineOptions, defineProps } from 'vue'
import { computed, defineOptions } from 'vue'
import { useComponentRef } from '@oku-ui/use-composable'
import { OkuArrow } from '@oku-ui/arrow'
Expand All @@ -30,14 +30,15 @@ const props = defineProps<PopperArrowProps>()
const { componentRef, currentElement } = useComponentRef()
defineExpose({
$el: currentElement,
})
const contentInject = usePopperContentInject('OkuPopperContent', props.scopeOkuPopper)
const baseSide = computed(() => {
return contentInject?.placedSide.value ? OPPOSITE_SIDE[contentInject.placedSide.value] : ''
})
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/popper/PopperContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const { useInject: usePopperContentInject, useProvider: usePopperContentP

<script lang="ts" setup>
import type { Ref } from 'vue'
import { computed, defineEmits, defineExpose, defineOptions, defineProps, ref, watch, watchEffect, withDefaults } from 'vue'
import { computed, defineOptions, ref, watch, watchEffect, withDefaults } from 'vue'
import type { PrimitiveProps } from '@oku-ui/primitive'
import { Primitive } from '@oku-ui/primitive'
import { useComponentRef, useSize } from '@oku-ui/use-composable'
Expand Down
5 changes: 3 additions & 2 deletions packages/vue/src/portal/Portal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { defineExpose, defineOptions, mergeProps, useAttrs } from 'vue'
import { defineOptions, mergeProps, useAttrs } from 'vue'
import { Primitive } from '@oku-ui/primitive'
import type { PrimitiveProps } from '@oku-ui/primitive'
import { useComponentRef } from '@oku-ui/use-composable'
Expand All @@ -20,12 +20,13 @@ const props = withDefaults(defineProps<PortalProps>(), {
container: globalThis?.document?.body ?? null,
})
const attrs = useAttrs()
const { componentRef, currentElement } = useComponentRef<HTMLDivElement | null>()
defineExpose({
$el: currentElement,
})
const attrs = useAttrs()
</script>

<template>
Expand Down
4 changes: 4 additions & 0 deletions packages/vue/src/presence/Presence.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function Comp() {
})
: null
}
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
7 changes: 6 additions & 1 deletion packages/vue/src/toggle/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ToggleEmits = {
pressedChange: [pressed: boolean]
click: [event: MouseEvent]
}
</script>

<script setup lang="ts">
Expand All @@ -43,7 +44,7 @@ const props = withDefaults(defineProps<ToggleProps>(), {
const emits = defineEmits<ToggleEmits>()
const { componentRef } = useComponentRef<HTMLButtonElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLButtonElement | null>()
const modelValue = useVModel(props, 'pressed', emits)
Expand All @@ -56,6 +57,10 @@ const [pressed, setPressed] = useControllable({
},
initialValue: false,
})
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down
7 changes: 6 additions & 1 deletion packages/vue/src/visually-hidden/VisuallyHidden.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const props = withDefaults(defineProps<VisuallyHiddenProps>(), {
is: 'span',
})
const { componentRef } = useComponentRef<HTMLSpanElement | null>()
const { componentRef, currentElement } = useComponentRef<HTMLSpanElement | null>()
defineExpose({
$el: currentElement,
})
</script>

<template>
Expand Down

0 comments on commit aa1d04d

Please sign in to comment.