maz-ui 5.0.0 → 5.1.0-beta.0
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/assets/{MazDropzone.DJ8au25t.css → MazDropzone.BW2grpTi.css} +1 -1
- package/dist/chunks/{MazDrawer.DANxKYxJ.js → MazDrawer.CC8zomfx.js} +2 -2
- package/dist/chunks/{MazDropzone.POH3pmfi.js → MazDropzone.Dez5j0WP.js} +2 -2
- package/dist/components/MazDrawer.js +1 -1
- package/dist/components/MazDropzone.js +1 -1
- package/dist/components/MazDropzone.vue.d.ts +2 -2
- package/dist/components/MazInputPrice.vue.d.ts +1 -1
- package/dist/components/index.js +2 -2
- package/docs/README.md +207 -0
- package/docs/agents/agents-md.md +52 -0
- package/docs/agents/claude-rule.md +52 -0
- package/docs/components/maz-accordion.md +76 -0
- package/docs/components/maz-alert.md +241 -0
- package/docs/components/maz-animated-counter.md +87 -0
- package/docs/components/maz-animated-element.md +46 -0
- package/docs/components/maz-animated-text.md +53 -0
- package/docs/components/maz-avatar.md +193 -0
- package/docs/components/maz-backdrop.md +178 -0
- package/docs/components/maz-badge.md +167 -0
- package/docs/components/maz-bottom-sheet.md +257 -0
- package/docs/components/maz-btn-group.md +316 -0
- package/docs/components/maz-btn.md +423 -0
- package/docs/components/maz-card-spotlight.md +84 -0
- package/docs/components/maz-card.md +321 -0
- package/docs/components/maz-carousel.md +153 -0
- package/docs/components/maz-chart.md +206 -0
- package/docs/components/maz-checkbox.md +138 -0
- package/docs/components/maz-checklist.md +251 -0
- package/docs/components/maz-circular-progress-bar.md +109 -0
- package/docs/components/maz-code-highlight.md +155 -0
- package/docs/components/maz-container.md +241 -0
- package/docs/components/maz-date-picker.md +791 -0
- package/docs/components/maz-dialog-confirm.md +215 -0
- package/docs/components/maz-dialog.md +143 -0
- package/docs/components/maz-drawer.md +106 -0
- package/docs/components/maz-dropdown.md +419 -0
- package/docs/components/maz-dropzone.md +387 -0
- package/docs/components/maz-expand-animation.md +82 -0
- package/docs/components/maz-fullscreen-loader.md +58 -0
- package/docs/components/maz-gallery.md +79 -0
- package/docs/components/maz-icon.md +203 -0
- package/docs/components/maz-input-code.md +73 -0
- package/docs/components/maz-input-number.md +79 -0
- package/docs/components/maz-input-phone-number.md +536 -0
- package/docs/components/maz-input-price.md +68 -0
- package/docs/components/maz-input-tags.md +112 -0
- package/docs/components/maz-input.md +334 -0
- package/docs/components/maz-lazy-img.md +113 -0
- package/docs/components/maz-link.md +146 -0
- package/docs/components/maz-loading-bar.md +38 -0
- package/docs/components/maz-markdown-editor.md +320 -0
- package/docs/components/maz-pagination.md +82 -0
- package/docs/components/maz-popover.md +794 -0
- package/docs/components/maz-pull-to-refresh.md +222 -0
- package/docs/components/maz-radio-buttons.md +313 -0
- package/docs/components/maz-radio.md +119 -0
- package/docs/components/maz-read-more.md +209 -0
- package/docs/components/maz-reading-progress-bar.md +96 -0
- package/docs/components/maz-select-country.md +513 -0
- package/docs/components/maz-select.md +318 -0
- package/docs/components/maz-sidebar-content.md +25 -0
- package/docs/components/maz-sidebar-footer.md +25 -0
- package/docs/components/maz-sidebar-group.md +27 -0
- package/docs/components/maz-sidebar-header.md +25 -0
- package/docs/components/maz-sidebar-menu-button.md +41 -0
- package/docs/components/maz-sidebar-menu-item.md +25 -0
- package/docs/components/maz-sidebar-menu-sub.md +32 -0
- package/docs/components/maz-sidebar-menu.md +25 -0
- package/docs/components/maz-sidebar-separator.md +21 -0
- package/docs/components/maz-sidebar-trigger.md +25 -0
- package/docs/components/maz-sidebar.md +507 -0
- package/docs/components/maz-skeleton.md +226 -0
- package/docs/components/maz-slider.md +165 -0
- package/docs/components/maz-spinner.md +84 -0
- package/docs/components/maz-stepper.md +301 -0
- package/docs/components/maz-switch.md +86 -0
- package/docs/components/maz-table-cell.md +27 -0
- package/docs/components/maz-table-row.md +28 -0
- package/docs/components/maz-table-title.md +27 -0
- package/docs/components/maz-table-virtualizer.md +31 -0
- package/docs/components/maz-table.md +426 -0
- package/docs/components/maz-tabs-bar.md +43 -0
- package/docs/components/maz-tabs-content-item.md +27 -0
- package/docs/components/maz-tabs-content.md +27 -0
- package/docs/components/maz-tabs.md +308 -0
- package/docs/components/maz-textarea.md +255 -0
- package/docs/components/maz-ticker.md +427 -0
- package/docs/components/maz-timeline.md +304 -0
- package/docs/components/maz-ui-provider.md +26 -0
- package/docs/components/maz-window-mockup.md +182 -0
- package/docs/composables/use-aos.md +41 -0
- package/docs/composables/use-breakpoints.md +42 -0
- package/docs/composables/use-dialog.md +58 -0
- package/docs/composables/use-display-names.md +130 -0
- package/docs/composables/use-drag.md +185 -0
- package/docs/composables/use-form-validator.md +1123 -0
- package/docs/composables/use-idle-timeout.md +172 -0
- package/docs/composables/use-pull-to-refresh.md +86 -0
- package/docs/composables/use-reading-time.md +132 -0
- package/docs/composables/use-string-matching.md +41 -0
- package/docs/composables/use-swipe.md +171 -0
- package/docs/composables/use-timer.md +104 -0
- package/docs/composables/use-toast.md +50 -0
- package/docs/composables/use-user-visibility.md +127 -0
- package/docs/composables/use-wait.md +50 -0
- package/docs/composables/use-window-size.md +25 -0
- package/docs/directives/click-outside.md +182 -0
- package/docs/directives/fullscreen-img.md +83 -0
- package/docs/directives/lazy-img.md +182 -0
- package/docs/directives/tooltip.md +298 -0
- package/docs/directives/zoom-img.md +100 -0
- package/docs/ecosystem/eslint-config.md +289 -0
- package/docs/ecosystem/icons/icon-set.md +25 -0
- package/docs/ecosystem/icons/index.md +584 -0
- package/docs/ecosystem/mcp.md +165 -0
- package/docs/ecosystem/node/exec-promise.md +93 -0
- package/docs/ecosystem/node/index.md +53 -0
- package/docs/ecosystem/node/logger.md +152 -0
- package/docs/ecosystem/node/print-banner.md +101 -0
- package/docs/ecosystem/node/setup-agents.md +102 -0
- package/docs/ecosystem/nuxt.md +551 -0
- package/docs/ecosystem/stylelint-config.md +310 -0
- package/docs/ecosystem/themes.md +966 -0
- package/docs/ecosystem/translations.md +1173 -0
- package/docs/ecosystem/utils/camel-case.md +37 -0
- package/docs/ecosystem/utils/capitalize.md +37 -0
- package/docs/ecosystem/utils/check-availability.md +85 -0
- package/docs/ecosystem/utils/cookie.md +86 -0
- package/docs/ecosystem/utils/country-code-to-unicode-flag.md +128 -0
- package/docs/ecosystem/utils/currency.md +53 -0
- package/docs/ecosystem/utils/date.md +53 -0
- package/docs/ecosystem/utils/debounce-callback.md +44 -0
- package/docs/ecosystem/utils/debounce-id.md +75 -0
- package/docs/ecosystem/utils/debounce.md +71 -0
- package/docs/ecosystem/utils/fetch-locale-ip.md +39 -0
- package/docs/ecosystem/utils/format-json.md +39 -0
- package/docs/ecosystem/utils/format-phone-number.md +43 -0
- package/docs/ecosystem/utils/get-browser-locale.md +35 -0
- package/docs/ecosystem/utils/get-country-flag-url.md +67 -0
- package/docs/ecosystem/utils/get-error-message.md +45 -0
- package/docs/ecosystem/utils/idle-timeout.md +96 -0
- package/docs/ecosystem/utils/index.md +57 -0
- package/docs/ecosystem/utils/is-client.md +38 -0
- package/docs/ecosystem/utils/is-equal.md +44 -0
- package/docs/ecosystem/utils/is-ios.md +43 -0
- package/docs/ecosystem/utils/is-server.md +37 -0
- package/docs/ecosystem/utils/is-standalone-mode.md +49 -0
- package/docs/ecosystem/utils/kebab-case.md +42 -0
- package/docs/ecosystem/utils/normalize-string.md +83 -0
- package/docs/ecosystem/utils/number.md +51 -0
- package/docs/ecosystem/utils/pascal-case.md +41 -0
- package/docs/ecosystem/utils/prevent-ios-input-zoom.md +72 -0
- package/docs/ecosystem/utils/script-loader.md +85 -0
- package/docs/ecosystem/utils/sleep.md +65 -0
- package/docs/ecosystem/utils/snake-case.md +42 -0
- package/docs/ecosystem/utils/swipe-handler.md +97 -0
- package/docs/ecosystem/utils/textarea-autogrow.md +47 -0
- package/docs/ecosystem/utils/throttle-id.md +54 -0
- package/docs/ecosystem/utils/throttle.md +63 -0
- package/docs/ecosystem/utils/truthy-filter.md +37 -0
- package/docs/ecosystem/utils/types/deep-key-of.md +54 -0
- package/docs/ecosystem/utils/types/deep-partial.md +48 -0
- package/docs/ecosystem/utils/types/deep-required.md +45 -0
- package/docs/ecosystem/utils/types/flatten-object-keys.md +50 -0
- package/docs/ecosystem/utils/types/generic-instance-type.md +48 -0
- package/docs/ecosystem/utils/types/infer-maybe-ref.md +41 -0
- package/docs/ecosystem/utils/upper-first.md +38 -0
- package/docs/ecosystem/utils/user-visibility.md +75 -0
- package/docs/guide/ai-agents.md +237 -0
- package/docs/guide/browser-support.md +88 -0
- package/docs/guide/getting-started.md +191 -0
- package/docs/guide/global-defaults.md +103 -0
- package/docs/guide/maz-ui-provider.md +231 -0
- package/docs/guide/migration-v5.md +871 -0
- package/docs/guide/resolvers.md +650 -0
- package/docs/guide/tailwind.md +483 -0
- package/docs/guide/vue.md +286 -0
- package/docs/manifest.json +1 -0
- package/docs/plugins/aos.md +312 -0
- package/docs/plugins/dialog.md +269 -0
- package/docs/plugins/toast.md +221 -0
- package/docs/plugins/wait.md +78 -0
- package/docs/reference/icons.md +46 -0
- package/docs/reference/tailwind-tokens.md +191 -0
- package/docs/rules.md +57 -0
- package/package.json +31 -4
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "useDisplayNames"
|
|
3
|
+
description: "useDisplayNames is a Vue composable specialized in displaying localized country names (regions) and language names. It supports various code formats including ISO 639-1 (language codes), ISO 3166-1 (country codes), and BCP 47 (language tags), using the Intl.DisplayNames API for internationalization."
|
|
4
|
+
package: "maz-ui"
|
|
5
|
+
url: "https://maz-ui.com/composables/use-display-names"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# useDisplayNames
|
|
9
|
+
|
|
10
|
+
> useDisplayNames is a Vue composable specialized in displaying localized country names (regions) and language names. It supports various code formats including ISO 639-1 (language codes), ISO 3166-1 (country codes), and BCP 47 (language tags), using the Intl.DisplayNames API for internationalization.
|
|
11
|
+
|
|
12
|
+
- Package: `maz-ui`
|
|
13
|
+
- Import: `import { useDisplayNames } from 'maz-ui/composables/useDisplayNames'`
|
|
14
|
+
- Nuxt: auto-imported by `@maz-ui/nuxt`, no import needed in a Nuxt app
|
|
15
|
+
- Web: https://maz-ui.com/composables/use-display-names
|
|
16
|
+
|
|
17
|
+
## Introduction
|
|
18
|
+
|
|
19
|
+
`useDisplayNames` allows you to fetch and format localized country names and language names using the `Intl.DisplayNames` API. It supports multiple code formats (ISO 639-1, ISO 3166-1, BCP 47) and is particularly useful for applications that need to display human-readable country or language names based on different locales.
|
|
20
|
+
|
|
21
|
+
**Warning:**
|
|
22
|
+
|
|
23
|
+
Depending on your environment (client or node server) and the browser you are using, the `Intl.DisplayNames` results can be differents (e.g, Firefox and Chrome can return different results).
|
|
24
|
+
|
|
25
|
+
## Key Features
|
|
26
|
+
|
|
27
|
+
- Displays localized country names (regions) and language names
|
|
28
|
+
- Supports multiple code formats: ISO 639-1 (language codes), ISO 3166-1 (country codes), and BCP 47 (language tags)
|
|
29
|
+
- Works with any locale supported by the browser's Intl.DisplayNames API
|
|
30
|
+
- Provides functions to get individual names or bulk retrieve all available names
|
|
31
|
+
- Handles errors gracefully with fallback values
|
|
32
|
+
- Smart filtering and sorting options for comprehensive lists
|
|
33
|
+
|
|
34
|
+
## Basic Usage
|
|
35
|
+
|
|
36
|
+
To see `useDisplayNames` in action, you can try out the following demo. This demo showcases how to use the composable to fetch and display localized language names dynamically based on user input.
|
|
37
|
+
|
|
38
|
+
```vue
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
import { useDisplayNames } from 'maz-ui/composables/useDisplayNames'
|
|
41
|
+
import { computed, ref } from 'vue'
|
|
42
|
+
|
|
43
|
+
const selectedLocale = ref('en-US')
|
|
44
|
+
const code = ref('')
|
|
45
|
+
|
|
46
|
+
const { getDisplayName, getAllDisplayNames } = useDisplayNames(selectedLocale)
|
|
47
|
+
|
|
48
|
+
const languageDisplayName = getDisplayName(code, { type: 'language' })
|
|
49
|
+
|
|
50
|
+
const localeOptions = getAllDisplayNames({ type: 'language' })
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<MazSelect
|
|
55
|
+
v-model="selectedLocale"
|
|
56
|
+
label="Select a locale"
|
|
57
|
+
:max-list-height="350"
|
|
58
|
+
:options="[
|
|
59
|
+
{ value: 'en-US', label: 'English (en-US)' },
|
|
60
|
+
{ value: 'fr-FR', label: 'French (fr-FR)' },
|
|
61
|
+
{ value: 'es-ES', label: 'Spanish (es-ES)' },
|
|
62
|
+
{ value: 'zh-CN', label: 'Chinese (zh-CN)' },
|
|
63
|
+
{ value: 'de-DE', label: 'German (de-DE)' },
|
|
64
|
+
{ value: 'it-IT', label: 'Italian (it-IT)' },
|
|
65
|
+
{ value: 'ja-JP', label: 'Japanese (ja-JP)' },
|
|
66
|
+
{ value: 'ko-KR', label: 'Korean (ko-KR)' },
|
|
67
|
+
{ value: 'pt-BR', label: 'Portuguese (pt-BR)' },
|
|
68
|
+
{ value: 'ru-RU', label: 'Russian (ru-RU)' },
|
|
69
|
+
]"
|
|
70
|
+
search
|
|
71
|
+
/>
|
|
72
|
+
<MazSelect
|
|
73
|
+
v-model="code"
|
|
74
|
+
label="Select a language"
|
|
75
|
+
:options="localeOptions?.map(({ name, code }) => ({
|
|
76
|
+
label: `${name} (${code})`,
|
|
77
|
+
value: code
|
|
78
|
+
}))"
|
|
79
|
+
search
|
|
80
|
+
/>
|
|
81
|
+
<p>Translated Language: {{ languageDisplayName || 'undefined' }}</p>
|
|
82
|
+
</template>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
In this example, the `useDisplayNames` composable is used to fetch and display the language name based on the selected locale and language code (ISO 639-1 or BCP 47 format).
|
|
86
|
+
|
|
87
|
+
The returned value is reactive and will update automatically when the locale or language code changes if arguments are reactive (use ref or computed).
|
|
88
|
+
|
|
89
|
+
## Functions
|
|
90
|
+
|
|
91
|
+
`useDisplayNames` can take a locale as argument to avoid passing this value each time you call the functions. This is useful when you need to fetch multiple country or language names based on the same locale.
|
|
92
|
+
|
|
93
|
+
It provides the following functions:
|
|
94
|
+
|
|
95
|
+
### `getDisplayName`
|
|
96
|
+
|
|
97
|
+
Fetches the localized display name of a country (region) or language based on the provided locale and code (supports ISO 639-1, ISO 3166-1, and BCP 47 formats).
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
function getDisplayName(code: MaybeRefOrGetter<string>, options: {
|
|
101
|
+
type: MaybeRefOrGetter<Intl.DisplayNamesOptions['type']>,
|
|
102
|
+
locale?: MaybeRefOrGetter<string>
|
|
103
|
+
}): ComputedRef<string | undefined>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `getAllDisplayNames`
|
|
107
|
+
|
|
108
|
+
Fetches the localized display names for all available countries (regions) or languages for a given locale. Supports filtering by code type (ISO 639-1, ISO 3166-1, BCP 47, or all).
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
function getAllDisplayNames(options: {
|
|
112
|
+
type: MaybeRefOrGetter<Intl.DisplayNamesOptions['type']>,
|
|
113
|
+
locale?: MaybeRefOrGetter<string>,
|
|
114
|
+
codes?: MaybeRefOrGetter<string[]>,
|
|
115
|
+
exclude?: MaybeRefOrGetter<string[]>,
|
|
116
|
+
preferred?: MaybeRefOrGetter<string[]>,
|
|
117
|
+
onlyIso?: MaybeRefOrGetter<boolean>,
|
|
118
|
+
onlyBcp?: MaybeRefOrGetter<boolean>,
|
|
119
|
+
}): ComputedRef<{ name: string, code: string }[]>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Notes
|
|
123
|
+
|
|
124
|
+
- The `useDisplayNames` composable is designed to be used with Vue.
|
|
125
|
+
- The composable functions return `ComputedRef` values, which are reactive and will update automatically when their dependencies change.
|
|
126
|
+
- Handle errors gracefully by providing fallback values when the display name cannot be fetched.
|
|
127
|
+
- The `Intl.DisplayNames` API is used internally to fetch and format the display names based on the provided locale and code.
|
|
128
|
+
- The composable supports multiple locales, allowing you to fetch country and language names in different languages.
|
|
129
|
+
- Use the `getAllDisplayNames` function to fetch comprehensive lists of countries or languages with advanced filtering options.
|
|
130
|
+
- Supports various code formats: ISO 639-1 (language codes like 'en', 'fr'), ISO 3166-1 (country codes like 'US', 'FR'), and BCP 47 (language tags like 'en-US', 'fr-FR').
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "useDrag"
|
|
3
|
+
description: "useDrag is a Vue composable that tracks a pointer drag gesture (touch, mouse and pen) in real time, exposing the live offset, distance and direction."
|
|
4
|
+
package: "maz-ui"
|
|
5
|
+
url: "https://maz-ui.com/composables/use-drag"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# useDrag
|
|
9
|
+
|
|
10
|
+
> useDrag is a Vue composable that tracks a pointer drag gesture (touch, mouse and pen) in real time, exposing the live offset, distance and direction.
|
|
11
|
+
|
|
12
|
+
- Package: `maz-ui`
|
|
13
|
+
- Import: `import { useDrag } from 'maz-ui/composables/useDrag'`
|
|
14
|
+
- Nuxt: auto-imported by `@maz-ui/nuxt`, no import needed in a Nuxt app
|
|
15
|
+
- Web: https://maz-ui.com/composables/use-drag
|
|
16
|
+
|
|
17
|
+
## Introduction
|
|
18
|
+
|
|
19
|
+
`useDrag` follows a pointer drag on an element and gives you the **live** offset, distance and direction, plus `onStart` / `onMove` / `onEnd` callbacks. It is the low-level gesture primitive behind components like [MazBottomSheet](../components/maz-bottom-sheet.md) (drag-to-dismiss), and it's useful to build sliders, sortable handles, swipeable cards, bottom sheets, custom carousels, etc.
|
|
20
|
+
|
|
21
|
+
It is built on top of [Pointer Events](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events), so it works with **touch, mouse and pen**.
|
|
22
|
+
|
|
23
|
+
**Tip:**
|
|
24
|
+
|
|
25
|
+
For discrete directional swipe detection (left / right / up / down with a threshold) rather than real-time tracking, use [useSwipe](./use-swipe.md).
|
|
26
|
+
|
|
27
|
+
## Key Features
|
|
28
|
+
|
|
29
|
+
- Real-time pointer tracking (touch, mouse and pen)
|
|
30
|
+
- Live reactive state: `isDragging`, `offsetX`, `offsetY`, `distance`, `direction`
|
|
31
|
+
- `onStart` / `onMove` / `onEnd` callbacks with a full state snapshot
|
|
32
|
+
- Axis locking (`x`, `y` or `both`)
|
|
33
|
+
- Activation threshold, pointer-type filtering and reactive `disabled`
|
|
34
|
+
- Listeners are followed on the document, so the drag keeps working when the pointer leaves the element
|
|
35
|
+
- Automatically attaches/detaches when the target appears/disappears, and cleans up on unmount
|
|
36
|
+
|
|
37
|
+
## Basic Usage
|
|
38
|
+
|
|
39
|
+
Drag the card down: it follows your pointer and snaps back on release.
|
|
40
|
+
|
|
41
|
+
```vue
|
|
42
|
+
<script lang="ts" setup>
|
|
43
|
+
import { useDrag } from 'maz-ui/composables'
|
|
44
|
+
import { ref } from 'vue'
|
|
45
|
+
|
|
46
|
+
const dragHandle = ref<HTMLElement>()
|
|
47
|
+
const dragOffset = ref(0)
|
|
48
|
+
|
|
49
|
+
const { isDragging: dragging, direction: dragDirection } = useDrag(dragHandle, {
|
|
50
|
+
axis: 'y',
|
|
51
|
+
onMove: ({ offsetY }) => {
|
|
52
|
+
dragOffset.value = Math.max(0, offsetY)
|
|
53
|
+
},
|
|
54
|
+
onEnd: ({ offsetY }) => {
|
|
55
|
+
if (offsetY > 150) {
|
|
56
|
+
// trigger an action when dragged far enough
|
|
57
|
+
}
|
|
58
|
+
dragOffset.value = 0
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<template>
|
|
64
|
+
<div
|
|
65
|
+
ref="dragHandle"
|
|
66
|
+
class="drag-card"
|
|
67
|
+
:class="{ '--dragging': dragging }"
|
|
68
|
+
:style="{ transform: dragOffset ? `translateY(${dragOffset}px)` : undefined }"
|
|
69
|
+
>
|
|
70
|
+
{{ dragging ? `Dragging - ${Math.round(dragOffset)}px ${dragDirection ?? ''}` : 'Drag me down' }}
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<style>
|
|
75
|
+
.drag-card {
|
|
76
|
+
touch-action: none;
|
|
77
|
+
cursor: grab;
|
|
78
|
+
user-select: none;
|
|
79
|
+
}
|
|
80
|
+
.drag-card:not(.--dragging) {
|
|
81
|
+
transition: transform 0.25s ease;
|
|
82
|
+
}
|
|
83
|
+
</style>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Options
|
|
87
|
+
|
|
88
|
+
`useDrag(target, options)` - the `target` is a `MaybeRefOrGetter<HTMLElement | string | null | undefined>` and `options` accepts:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
interface UseDragOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Restrict the tracking to a single axis. Off-axis movement is ignored.
|
|
94
|
+
* @default 'both'
|
|
95
|
+
*/
|
|
96
|
+
axis?: 'x' | 'y' | 'both'
|
|
97
|
+
/**
|
|
98
|
+
* Minimum distance (px) the pointer must travel before the drag becomes active.
|
|
99
|
+
* @default 0
|
|
100
|
+
*/
|
|
101
|
+
threshold?: number
|
|
102
|
+
/**
|
|
103
|
+
* Pointer types allowed to initiate the drag.
|
|
104
|
+
* @default ['mouse', 'touch', 'pen']
|
|
105
|
+
*/
|
|
106
|
+
pointerTypes?: ('mouse' | 'touch' | 'pen')[]
|
|
107
|
+
/**
|
|
108
|
+
* Reactively disable the gesture.
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
disabled?: MaybeRefOrGetter<boolean>
|
|
112
|
+
/**
|
|
113
|
+
* Call `event.preventDefault()` on each pointer move while dragging.
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
preventDefault?: boolean
|
|
117
|
+
/**
|
|
118
|
+
* Call `event.stopPropagation()` on the pointer events.
|
|
119
|
+
* @default false
|
|
120
|
+
*/
|
|
121
|
+
stopPropagation?: boolean
|
|
122
|
+
/**
|
|
123
|
+
* Attach the listeners as soon as the target is available. When `false`, call `start()` manually.
|
|
124
|
+
* @default true
|
|
125
|
+
*/
|
|
126
|
+
immediate?: boolean
|
|
127
|
+
/** Called once when the drag becomes active (threshold reached). */
|
|
128
|
+
onStart?: (state: DragState) => void
|
|
129
|
+
/** Called on every pointer move while dragging. */
|
|
130
|
+
onMove?: (state: DragState) => void
|
|
131
|
+
/** Called when the drag ends (pointer up or cancel). */
|
|
132
|
+
onEnd?: (state: DragState) => void
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Each callback receives a `DragState` snapshot:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
interface DragState {
|
|
140
|
+
/** Pointer offset from the drag start on the X axis (`0` when axis is `'y'`). */
|
|
141
|
+
offsetX: number
|
|
142
|
+
/** Pointer offset from the drag start on the Y axis (`0` when axis is `'x'`). */
|
|
143
|
+
offsetY: number
|
|
144
|
+
/** Absolute distance dragged from the start. */
|
|
145
|
+
distance: number
|
|
146
|
+
/** Dominant direction of the drag. */
|
|
147
|
+
direction: 'up' | 'down' | 'left' | 'right' | undefined
|
|
148
|
+
/** Pointer position when the drag started. */
|
|
149
|
+
startX: number
|
|
150
|
+
startY: number
|
|
151
|
+
/** Current pointer position. */
|
|
152
|
+
x: number
|
|
153
|
+
y: number
|
|
154
|
+
/** The underlying pointer event. */
|
|
155
|
+
event: PointerEvent
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Composable Return
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
interface UseDragReturn {
|
|
163
|
+
/** Whether a drag is currently active (threshold reached). */
|
|
164
|
+
isDragging: Readonly<Ref<boolean>>
|
|
165
|
+
/** Reactive pointer offset from the drag start on the X axis. */
|
|
166
|
+
offsetX: Readonly<Ref<number>>
|
|
167
|
+
/** Reactive pointer offset from the drag start on the Y axis. */
|
|
168
|
+
offsetY: Readonly<Ref<number>>
|
|
169
|
+
/** Reactive absolute distance dragged from the start. */
|
|
170
|
+
distance: Readonly<Ref<number>>
|
|
171
|
+
/** Reactive dominant direction of the drag. */
|
|
172
|
+
direction: Readonly<Ref<'up' | 'down' | 'left' | 'right' | undefined>>
|
|
173
|
+
/** Manually attach the listeners. */
|
|
174
|
+
start: () => void
|
|
175
|
+
/** Manually detach the listeners (also cancels an ongoing drag). */
|
|
176
|
+
stop: () => void
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Notes
|
|
181
|
+
|
|
182
|
+
- Add `touch-action: none` on the draggable element to prevent the browser from scrolling while dragging.
|
|
183
|
+
- The composable attaches automatically on mount (`immediate: true` by default) and cleans up on unmount; use `start()` / `stop()` for manual control.
|
|
184
|
+
- `onEnd` only fires when an actual drag happened (the threshold was reached), so a simple tap will not trigger it.
|
|
185
|
+
- The target can be a ref, a getter or a CSS selector string, and the listeners re-attach automatically when it changes.
|