Skip to content

Commit 31ee6ee

Browse files
committed
refactor: add mirror classes
1 parent 959da32 commit 31ee6ee

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/Draggable/Plugins/Mirror/Mirror.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default class Mirror extends AbstractPlugin {
275275
* @private
276276
*/
277277
[onMirrorCreated]({mirror, source, sensorEvent}) {
278-
const mirrorClass = this.draggable.getClassNamesFor('mirror');
278+
const mirrorClasses = this.draggable.getClassNamesFor('mirror');
279279

280280
const setState = ({mirrorOffset, initialX, initialY, ...args}) => {
281281
this.mirrorOffset = mirrorOffset;
@@ -292,7 +292,7 @@ export default class Mirror extends AbstractPlugin {
292292
mirror,
293293
source,
294294
sensorEvent,
295-
mirrorClass,
295+
mirrorClasses,
296296
scrollOffset: this.scrollOffset,
297297
options: this.options,
298298
passedThreshX: true,
@@ -446,18 +446,14 @@ function resetMirror({mirror, source, options, ...args}) {
446446
* Applys mirror class on mirror element
447447
* @param {Object} state
448448
* @param {HTMLElement} state.mirror
449-
* @param {String|String[]} state.mirrorClass
449+
* @param {String[]} state.mirrorClasses
450450
* @return {Promise}
451451
* @private
452452
*/
453-
function addMirrorClasses({mirror, mirrorClass, ...args}) {
453+
function addMirrorClasses({mirror, mirrorClasses, ...args}) {
454454
return withPromise((resolve) => {
455-
if (mirrorClass instanceof Array) {
456-
mirror.classList.add(...mirrorClass);
457-
} else {
458-
mirror.classList.add(mirrorClass);
459-
}
460-
resolve({mirror, mirrorClass, ...args});
455+
mirror.classList.add(...mirrorClasses);
456+
resolve({mirror, mirrorClasses, ...args});
461457
});
462458
}
463459

src/Draggable/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ By default draggable includes the `MouseSensor` & `TouchSensor`. Default: `[]`
124124
Draggable adds classes to elements to indicate state. These classes can be used to add styling
125125
on elements in certain states. Accept String or Array of strings.
126126

127-
**NOTE**: When specifying multiple classes to an indicate state, the first class MUST be unique for that state to avoid duplicate classes for other states.
127+
**NOTE**: When specifying multiple classes to an indicate state, the first class MUST be unique for that state to avoid duplicate classes for other states. IE doesn't support add or remove multiple classes. If you want to use multiple classes in IE, you need to add a classList polyfill to your project first.
128128

129129
**`exclude {plugins: Plugin[], sensors: Sensor[]}`**
130130
Allow excluding default plugins and default sensors. Use with caution as it may create strange behavior.
@@ -209,7 +209,7 @@ import { Draggable } from '@shopify/draggable';
209209
const draggable = new Draggable(document.querySelectorAll('ul'), {
210210
draggable: 'li',
211211
classes: {
212-
'draggable:over': ['draggable--over', '.bg-red-200', 'bg-opacity-25'],
212+
'draggable:over': ['draggable--over', 'bg-red-200', 'bg-opacity-25'],
213213
},
214214
});
215215
```

0 commit comments

Comments
 (0)