문서 콘텐츠와 미디어

UIMediaGesture

미디어에 적용할 드래그와 핀치 입력을 읽습니다.

기본 사용법

끌거나 방향키로 자르기 위치 변경

표시선을 좌우로 끌어 이동합니다. 키보드에서는 영역에 포커스한 뒤 방향키, Home, End로 위치를 조절합니다.

가로 위치 50%
<script setup lang="ts">
import { UIMediaGesture, type UIMediaGestureInput } from "@connextable/ui";
import { ref } from "vue";

const position = ref(50);
function nudge(distance: number) {
  position.value = Math.round(
    Math.min(100, Math.max(0, position.value + distance)),
  );
}
function move(input: UIMediaGestureInput) {
  if (input.kind === "drag") nudge((input.after.x - input.before.x) / 2);
}
</script>

<template>
  <UIMediaGesture
    as-child
    :start="() => true"
    :admit-pointer="() => true"
    @move="move"
  >
    <div
      class="crop-position__surface"
      role="slider"
      tabindex="0"
      aria-label="이미지 자르기 위치"
      :aria-valuenow="position"
      aria-valuemin="0"
      aria-valuemax="100"
      @keydown.left.prevent="nudge(-5)"
      @keydown.right.prevent="nudge(5)"
      @keydown.home.prevent="position = 0"
      @keydown.end.prevent="position = 100"
      @keydown.up.prevent="nudge(5)"
      @keydown.down.prevent="nudge(-5)"
    >
      <div
        class="crop-position__marker"
        aria-hidden="true"
        :style="{ left: `${position}%` }"
      />
    </div>
  </UIMediaGesture>
</template>

<style scoped>
.crop-position__surface {
  position: relative;
  inline-size: min(100%, 21rem);
  height: 6rem;
  overflow: hidden;
  border: 1px solid var(--ui-color-border);
  border-radius: var(--ui-radius-md);
  background: repeating-linear-gradient(
    90deg,
    var(--ui-color-surface),
    var(--ui-color-surface) calc(25% - 1px),
    var(--ui-color-border) 25%
  );
  touch-action: pan-y;
  cursor: ew-resize;
}
.crop-position__marker {
  position: absolute;
  inset-block: 0;
  border-inline-start: 3px solid var(--ui-color-accent);
}
</style>

주요 API

속성과 모델

as / as-child

제스처를 받을 요소를 정합니다. as-child는 이미 배치한 요소 한 개에 동작을 연결합니다.

끌거나 방향키로 자르기 위치 변경 예제
start타입(input: { readonly pointerType: string; readonly point: Point; }) => boolean

포인터의 시작 위치를 받습니다. true를 반환하면 제스처에 참여합니다.

끌거나 방향키로 자르기 위치 변경 예제
admit-pointer / drag-threshold

대상과 포인터 유형에 따라 입력을 허용합니다. 기본 동작은 링크와 입력 등 자체 조작이 있는 요소를 보호합니다. 기본 드래그 감지 거리는 4px입니다.

끌거나 방향키로 자르기 위치 변경 예제

슬롯

#default타입(state: Pick<UseMediaGestureReturn, "cancel" | "measure"> & { error: MediaGestureErrorCode | undefined; }) => unknown

진행 중인 제스처를 취소하는 cancel, 대상과 좌표를 측정하는 measure, 연결 오류 error를 받습니다.

이벤트와 명령

@move / @end

드래그와 핀치의 이전 좌표와 현재 좌표, 종료 이유를 전달합니다. 요소 이동이나 확대 배율은 호출부에서 정합니다.

끌거나 방향키로 자르기 위치 변경 예제

컴포저블

useMediaGesture

직접 관리하는 요소 ref에 같은 Sectile 제스처 컨트롤러를 연결합니다.

전체 속성, 이벤트와 슬롯

UIMediaGesture

as
PrimitiveAs | undefined
as-child
boolean | undefined
disabled
boolean | undefined
start필수
(input: { readonly pointerType: string; readonly point: Point; }) => boolean
admit-pointer
((input: MediaPointerAdmission) => boolean) | undefined
drag-threshold
number | undefined
@end
(reason: MediaGestureEnd) => any
@move
(input: MediaGestureInput) => any
#default
(state: Pick<UseMediaGestureReturn, "cancel" | "measure"> & { error: MediaGestureErrorCode | undefined; }) => unknown