<template>
  <div class="kole-sheet-mask" :class="{ 'is-open': visible }" @click="emit('close')"></div>
  <div class="kole-sheet" :class="{ 'is-open': visible }"
       @pointerdown="onDown" @pointerup="onUp">
    <div class="kole-sheet-handle"></div>
    <div class="kole-sheet-header" v-if="title">{{ title }}</div>
    <div class="kole-sheet-body"><slot>默认内容</slot></div>
    <div class="kole-sheet-footer" v-if="$slots.footer"><slot name="footer" /></div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
const props = defineProps({ visible: { type: Boolean, default: false }, title: { type: String, default: '' } });
const emit = defineEmits(['close']);
const startY = ref(0);
function onDown(e) { startY.value = e.clientY; }
function onUp(e) { if (startY.value - e.clientY < -80) emit('close'); }
</script>

<style src="./BottomSheet.css"></style>
