@@ -5,9 +5,12 @@ import { StoryFn } from '@storybook/vue3'
5
5
import { expect } from '@storybook/jest'
6
6
import { userEvent } from '../../../.storybook/interaction-utils/userEvent'
7
7
8
+ import VaIcon from '../va-icon/VaIcon.vue'
9
+
8
10
export default {
9
11
title : 'VaModal' ,
10
12
component : VaModal ,
13
+ tags : [ 'autodocs' ] ,
11
14
}
12
15
13
16
export const OldDemos : StoryFn = ( ) => ( {
@@ -98,3 +101,201 @@ export const childProps: StoryFn = () => ({
98
101
</VaModal>
99
102
` ,
100
103
} )
104
+
105
+ // TODO: add tests
106
+ type PositionType = number | `${number } %`
107
+ type initialPositionType = { x ?: PositionType ; y ?: PositionType }
108
+ export const DraggableAndAttachElement : StoryFn = ( ) => ( {
109
+ components : { VaModal, VaIcon } ,
110
+ setup ( ) {
111
+ const iconsList : {
112
+ title : string ;
113
+ name : string ;
114
+ flip ?: string ;
115
+ position : initialPositionType ;
116
+ } [ ] = [
117
+ { title : 'Top Left' , name : 'arrow_outward' , flip : 'vertical' , position : { x : 0 , y : 0 } } ,
118
+ { title : 'Top Center' , name : 'arrow_upward' , position : { x : '50%' , y : 0 } } ,
119
+ { title : 'Top Right' , name : 'arrow_outward' , position : { x : '100%' , y : 0 } } ,
120
+ { title : 'Center Left' , name : 'arrow_back' , position : { x : 0 , y : '50%' } } ,
121
+ { title : 'Center Center' , name : 'circle' , position : { x : '50%' , y : '50%' } } ,
122
+ { title : 'Center Right' , name : 'arrow_forward' , position : { x : '100%' , y : '50%' } } ,
123
+ { title : 'Bottom Left' , name : 'arrow_outward' , flip : 'both' , position : { x : 0 , y : '100%' } } ,
124
+ { title : 'Bottom Center' , name : 'arrow_downward' , position : { x : '50%' , y : '100%' } } ,
125
+ { title : 'Bottom Right' , name : 'arrow_outward' , flip : 'horizontal' , position : { x : '100%' , y : '100%' } } ,
126
+ ]
127
+
128
+ const showModal = ref ( false )
129
+ const title = ref < string | null > ( null )
130
+ const initialPosition = ref < initialPositionType | null > ( null )
131
+
132
+ const handleIconClick = ( currentTitle : string , position : initialPositionType ) => {
133
+ title . value = currentTitle
134
+ initialPosition . value = position
135
+ showModal . value = true
136
+ }
137
+
138
+ const iconsStyle = {
139
+ display : 'flex' ,
140
+ flexWrap : 'wrap' ,
141
+ width : '80px' ,
142
+ gap : '4px' ,
143
+ alignItems : 'Center' ,
144
+ }
145
+
146
+ const attachElementStyle = {
147
+ width : '300px' ,
148
+ height : '300px' ,
149
+ border : '2px solid black' ,
150
+ }
151
+
152
+ return { iconsList, showModal, title, initialPosition, handleIconClick, iconsStyle, attachElementStyle }
153
+ } ,
154
+ template : `
155
+ <div :style="iconsStyle">
156
+ <VaIcon
157
+ v-for="({ title, name, flip, position }, index) in iconsList"
158
+ :key="index"
159
+ :name="name"
160
+ :flip="flip"
161
+ size="large"
162
+ @click="() => handleIconClick(title, position)"
163
+ />
164
+ </div>
165
+ <div class="modal-attach-element" :style="attachElementStyle"/>
166
+ <VaModal
167
+ v-model="showModal"
168
+ draggable
169
+ :draggable-position="initialPosition"
170
+ :title="title"
171
+ attach-element=".modal-attach-element"
172
+ >
173
+ Lorem ipsum dolor sit amet.
174
+ </VaModal>
175
+ ` ,
176
+ } )
177
+
178
+ export const DraggableSlots : StoryFn = ( ) => ( {
179
+ components : { VaModal, VaIcon } ,
180
+ template : `
181
+ <VaModal
182
+ model-value="true"
183
+ draggable
184
+ :draggable-position="{ x: 0, y: 0 }"
185
+ title='Top Left position / "#Draggable" slot for drag'
186
+ >
187
+ <template #draggable={startDrag}>
188
+ <span>
189
+ <VaIcon
190
+ name="drag_indicator"
191
+ @mousedown="startDrag"
192
+ :style="{cursor: 'move'}"
193
+ />
194
+ </span>
195
+ </template>
196
+ </VaModal>
197
+ <VaModal
198
+ model-value="true"
199
+ draggable
200
+ :draggable-position="{ x: '50%', y: 0 }"
201
+ >
202
+ Top Center position / "#Header" slot for drag
203
+ <template #header={startDrag}>
204
+ <VaIcon
205
+ name="drag_indicator"
206
+ @mousedown="startDrag"
207
+ :style="{cursor: 'move'}"
208
+ />
209
+ </template>
210
+ </VaModal>
211
+ <VaModal
212
+ model-value="true"
213
+ draggable
214
+ :draggable-position="{ x: '100%', y: 0 }"
215
+ title="Top Right position / Full window drag"
216
+ >
217
+ <template #footer>
218
+ Footer slot
219
+ </template>
220
+ </VaModal>
221
+ <VaModal
222
+ model-value="true"
223
+ draggable
224
+ :draggable-position="{ x: 0, y: '50%' }"
225
+ >
226
+ <template #header>
227
+ Center Left position / Header slot / Full window drag
228
+ </template>
229
+ </VaModal>
230
+ <VaModal
231
+ model-value="true"
232
+ draggable
233
+ :draggable-position="{ x: '50%', y: '50%' }"
234
+ title='Center Center position / "#Default" slot for drag'
235
+ >
236
+ <template #default={startDrag}>
237
+ <VaIcon
238
+ name="drag_indicator"
239
+ @mousedown="startDrag"
240
+ :style="{cursor: 'move'}"
241
+ />
242
+ </template>
243
+ </VaModal>
244
+ <VaModal
245
+ model-value="true"
246
+ draggable
247
+ :draggable-position="{ x: '100%', y: '50%' }"
248
+ >
249
+ <template #content={startDrag}>
250
+ Center Right position / "#Content" slot for drag
251
+ <VaIcon
252
+ name="drag_indicator"
253
+ @mousedown="startDrag"
254
+ :style="{cursor: 'move'}"
255
+ />
256
+ </template>
257
+ </VaModal>
258
+ <VaModal
259
+ model-value="true"
260
+ draggable
261
+ :draggable-position="{ x: 0, y: '100%' }"
262
+ title="Bottom Left position / Full window drag"
263
+ >
264
+ </VaModal>
265
+ <VaModal
266
+ model-value="true"
267
+ draggable
268
+ :draggable-position="{ x: '50%', y: '100%' }"
269
+ >
270
+ Bottom Center position / "#Header" & "#Footer" slots for drag
271
+ <template #header={startDrag}>
272
+ <VaIcon
273
+ name="drag_indicator"
274
+ @mousedown="startDrag"
275
+ :style="{cursor: 'move'}"
276
+ />
277
+ </template>
278
+ <template #footer={startDrag}>
279
+ <VaIcon
280
+ name="drag_indicator"
281
+ @mousedown="startDrag"
282
+ :style="{cursor: 'move'}"
283
+ />
284
+ </template>
285
+ </VaModal>
286
+ <VaModal
287
+ model-value="true"
288
+ draggable
289
+ :draggable-position="{ x: '100%', y: '100%' }"
290
+ title='Bottom Right position / "#Footer" slot for drag'
291
+ >
292
+ <template #footer={startDrag}>
293
+ <VaIcon
294
+ name="drag_indicator"
295
+ @mousedown="startDrag"
296
+ :style="{cursor: 'move'}"
297
+ />
298
+ </template>
299
+ </VaModal>
300
+ ` ,
301
+ } )
0 commit comments