-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add useDraggable composable #4486
Open
TFX-98
wants to merge
1
commit into
epicmaxco:develop
Choose a base branch
from
TFX-98:feature/draggable-composable
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
64 changes: 64 additions & 0 deletions
64
packages/docs/page-config/ui-elements/modal/examples/DraggableModals.vue
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,64 @@ | ||
<template> | ||
<div class="icons"> | ||
<VaIcon | ||
v-for="({ name, flip, position }, index) in iconsList" | ||
:key="index" | ||
:name="name" | ||
:flip="flip" | ||
size="large" | ||
@click="() => handleIconClick(position)" | ||
/> | ||
</div> | ||
<VaModal | ||
v-model="showModal" | ||
draggable | ||
:draggable-position="initialPosition" | ||
:title="initialPosition" | ||
> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ut lobortis | ||
dui. | ||
</VaModal> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from "vue"; | ||
|
||
const iconsList = [ | ||
{ name: 'arrow_outward', flip: 'vertical', position: { x: 0, y: 0 } }, | ||
{ name: 'arrow_upward', position: { x: '50%', y: 0 } }, | ||
{ name: 'arrow_outward', position: { x: '100%', y: 0 } }, | ||
{ name: 'arrow_back', position: { x: 0, y: '50%' } }, | ||
{ name: 'circle', position: { x: '50%', y: '50%' } }, | ||
{ name: 'arrow_forward', position: { x: '100%', y: '50%' } }, | ||
{ name: 'arrow_outward', flip: 'both', position: { x: 0, y: '100%' } }, | ||
{ name: 'arrow_downward', position: { x: '50%', y: '100%' } }, | ||
{ name: 'arrow_outward', flip: 'horizontal', position: { x: '100%', y: '100%' } }, | ||
] | ||
|
||
const showModal = ref(false) | ||
const initialPosition = ref(iconsList[0].position) | ||
|
||
const handleIconClick = (position) => { | ||
initialPosition.value = position | ||
showModal.value = true | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.icons { | ||
display: flex; | ||
flex-wrap: wrap; | ||
width: 80px; | ||
gap: 4px; | ||
align-items: center; | ||
|
||
* { | ||
flex: 0 0 24px; | ||
transition: color 0.25s ease-in-out; | ||
|
||
&:hover { | ||
color: var(--va-primary); | ||
} | ||
} | ||
} | ||
</style> |
59 changes: 59 additions & 0 deletions
59
packages/docs/page-config/ui-elements/modal/examples/DraggableSlots.vue
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,59 @@ | ||
<template> | ||
<div class="buttons"> | ||
<VaButton @click="showModalIconDraggable = true"> | ||
Open modal with draggable icon | ||
</VaButton> | ||
<VaButton @click="showModalHeaderDraggable = true"> | ||
Open modal with draggable header | ||
</VaButton> | ||
<VaButton @click="showModalFooterDraggable = true"> | ||
Open modal with draggable footer | ||
</VaButton> | ||
</div> | ||
<VaModal | ||
v-model="showModalIconDraggable" | ||
draggable | ||
title="With draggable icon" | ||
> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
<template #draggable="{startDrag}"> | ||
<VaIcon name="drag_indicator" :style="{ cursor: 'move', position: 'absolute', top: '10px', right: '10px' }" @mousedown="startDrag" /> | ||
</template> | ||
</VaModal> | ||
<VaModal | ||
v-model="showModalHeaderDraggable" | ||
draggable | ||
> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
<template #header="{startDrag}"> | ||
<h3 class="va-h3" :style="{ cursor: 'move' }" @mousedown="startDrag"> | ||
<VaIcon name="drag_indicator" :style="{ cursor: 'move' }" @mousedown="startDrag" /> Draggable Header | ||
</h3> | ||
</template> | ||
</VaModal> | ||
<VaModal | ||
v-model="showModalFooterDraggable" | ||
draggable | ||
title="With draggable footer" | ||
> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
<template #footer="{startDrag}"> | ||
<VaIcon name="drag_indicator" :style="{ cursor: 'move', position: 'absolute' ,left: '10px', bottom: '10px' }" @mousedown="startDrag" /> | ||
</template> | ||
</VaModal> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from "vue"; | ||
|
||
const showModalIconDraggable = ref(false) | ||
const showModalHeaderDraggable = ref(false) | ||
const showModalFooterDraggable = ref(false) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.buttons { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
</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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -5,9 +5,12 @@ import { StoryFn } from '@storybook/vue3' | |||||
import { expect } from '@storybook/jest' | ||||||
import { userEvent } from '../../../.storybook/interaction-utils/userEvent' | ||||||
|
||||||
import VaIcon from '../va-icon/VaIcon.vue' | ||||||
|
||||||
export default { | ||||||
title: 'VaModal', | ||||||
component: VaModal, | ||||||
tags: ['autodocs'], | ||||||
} | ||||||
|
||||||
export const OldDemos: StoryFn = () => ({ | ||||||
|
@@ -98,3 +101,201 @@ export const childProps: StoryFn = () => ({ | |||||
</VaModal> | ||||||
`, | ||||||
}) | ||||||
|
||||||
// TODO: add tests | ||||||
type PositionType = number | `${number}%` | ||||||
type initialPositionType = { x?: PositionType; y?: PositionType } | ||||||
export const DraggableAndAttachElement: StoryFn = () => ({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
components: { VaModal, VaIcon }, | ||||||
setup () { | ||||||
const iconsList: { | ||||||
title: string; | ||||||
name: string; | ||||||
flip?: string; | ||||||
position: initialPositionType; | ||||||
}[] = [ | ||||||
{ title: 'Top Left', name: 'arrow_outward', flip: 'vertical', position: { x: 0, y: 0 } }, | ||||||
{ title: 'Top Center', name: 'arrow_upward', position: { x: '50%', y: 0 } }, | ||||||
{ title: 'Top Right', name: 'arrow_outward', position: { x: '100%', y: 0 } }, | ||||||
{ title: 'Center Left', name: 'arrow_back', position: { x: 0, y: '50%' } }, | ||||||
{ title: 'Center Center', name: 'circle', position: { x: '50%', y: '50%' } }, | ||||||
{ title: 'Center Right', name: 'arrow_forward', position: { x: '100%', y: '50%' } }, | ||||||
{ title: 'Bottom Left', name: 'arrow_outward', flip: 'both', position: { x: 0, y: '100%' } }, | ||||||
{ title: 'Bottom Center', name: 'arrow_downward', position: { x: '50%', y: '100%' } }, | ||||||
{ title: 'Bottom Right', name: 'arrow_outward', flip: 'horizontal', position: { x: '100%', y: '100%' } }, | ||||||
] | ||||||
|
||||||
const showModal = ref(false) | ||||||
const title = ref<string | null>(null) | ||||||
const initialPosition = ref<initialPositionType | null>(null) | ||||||
|
||||||
const handleIconClick = (currentTitle: string, position: initialPositionType) => { | ||||||
title.value = currentTitle | ||||||
initialPosition.value = position | ||||||
showModal.value = true | ||||||
} | ||||||
|
||||||
const iconsStyle = { | ||||||
display: 'flex', | ||||||
flexWrap: 'wrap', | ||||||
width: '80px', | ||||||
gap: '4px', | ||||||
alignItems: 'Center', | ||||||
} | ||||||
|
||||||
const attachElementStyle = { | ||||||
width: '300px', | ||||||
height: '300px', | ||||||
border: '2px solid black', | ||||||
} | ||||||
|
||||||
return { iconsList, showModal, title, initialPosition, handleIconClick, iconsStyle, attachElementStyle } | ||||||
}, | ||||||
template: ` | ||||||
<div :style="iconsStyle"> | ||||||
<VaIcon | ||||||
v-for="({ title, name, flip, position }, index) in iconsList" | ||||||
:key="index" | ||||||
:name="name" | ||||||
:flip="flip" | ||||||
size="large" | ||||||
@click="() => handleIconClick(title, position)" | ||||||
/> | ||||||
</div> | ||||||
<div class="modal-attach-element" :style="attachElementStyle"/> | ||||||
<VaModal | ||||||
v-model="showModal" | ||||||
draggable | ||||||
:draggable-position="initialPosition" | ||||||
:title="title" | ||||||
attach-element=".modal-attach-element" | ||||||
> | ||||||
Lorem ipsum dolor sit amet. | ||||||
</VaModal> | ||||||
`, | ||||||
}) | ||||||
|
||||||
export const DraggableSlots: StoryFn = () => ({ | ||||||
components: { VaModal, VaIcon }, | ||||||
template: ` | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: 0, y: 0 }" | ||||||
title='Top Left position / "#Draggable" slot for drag' | ||||||
> | ||||||
<template #draggable={startDrag}> | ||||||
<span> | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</span> | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: '50%', y: 0 }" | ||||||
> | ||||||
Top Center position / "#Header" slot for drag | ||||||
<template #header={startDrag}> | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: '100%', y: 0 }" | ||||||
title="Top Right position / Full window drag" | ||||||
> | ||||||
<template #footer> | ||||||
Footer slot | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: 0, y: '50%' }" | ||||||
> | ||||||
<template #header> | ||||||
Center Left position / Header slot / Full window drag | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: '50%', y: '50%' }" | ||||||
title='Center Center position / "#Default" slot for drag' | ||||||
> | ||||||
<template #default={startDrag}> | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: '100%', y: '50%' }" | ||||||
> | ||||||
<template #content={startDrag}> | ||||||
Center Right position / "#Content" slot for drag | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: 0, y: '100%' }" | ||||||
title="Bottom Left position / Full window drag" | ||||||
> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: '50%', y: '100%' }" | ||||||
> | ||||||
Bottom Center position / "#Header" & "#Footer" slots for drag | ||||||
<template #header={startDrag}> | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</template> | ||||||
<template #footer={startDrag}> | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</template> | ||||||
</VaModal> | ||||||
<VaModal | ||||||
model-value="true" | ||||||
draggable | ||||||
:draggable-position="{ x: '100%', y: '100%' }" | ||||||
title='Bottom Right position / "#Footer" slot for drag' | ||||||
> | ||||||
<template #footer={startDrag}> | ||||||
<VaIcon | ||||||
name="drag_indicator" | ||||||
@mousedown="startDrag" | ||||||
:style="{cursor: 'move'}" | ||||||
/> | ||||||
</template> | ||||||
</VaModal> | ||||||
`, | ||||||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be better to set type like
number | '${number}%'
?