SwipeCommandsMixin

Reveals commands behind list items when the user swipes left or right

Overview

Purpose: adds template elements to a list-like component, exposing commands that act on list items when the user swipes to the left or right.

This mixin does most of its work at the beginning of the Elix render pipeline:

eventsmethods → setState → render DOM → post-render

Expects the component to provide:

  • swipeFraction state member and swipeStart, swipeLeft, and swipeRight methods, typically via TouchSwipeMixin and TrackpadSwipeMixin.
  • enableEffects optional state member, typically via EffectMixin. If present, the component uses that member to ensure animations are suppressed on initial page load.

Provides the component with:

  • internal.template getter that adds the template elements to contain and position the elements (typically some form of buttons) for the commands.

Usage

import SwipeCommandsMixin from "elix/src/base/SwipeCommandsMixin.js";
class MyElement extends SwipeCommandsMixin(HTMLElement) {}

Example

A typical usage of this mixin in the context of an email application might look like:

We would love to host you out here in the Sonoma Valley. The guest house is done on our Sonoma farm and we would love to see you. Dear Members, We're looking for a "top-notch" administrative assistant. Any leads you can give us would certainly be appreciated. I met with Peter Veruki at the Jones School of Administration at Rice last week and we had a great meeting. Our timing is a little off (they want someone next spring and I want a position by Jan), but we are still talking. Thank you for your presentation yesterday. As always, you handled very well some tough questions Well done. I want you to know that I am on board and 100% committed to do my best for the company. We'll get pointed questions related to Europe and broadband. Suggest we answer that we feel confident that the first mover advantage will give us superior returns in the long run. I would be happy to participate in the conference and workshop. Could we arrange a time to discuss the details later this week? Flowers have been ordered and will be delivered to Sharon's office on Tuesday morning. I spent a week on the project and my subcontractor was out his mobilization cost, and after more than a year, they finally paid a part of our cost. Per your request, I have attached a photo of the ornament. Please see attached revised travel advisory. I think it does a better job of balancing the competing interests. Below is an organization chart which displays the changes described here. We are confident this new organization will focus our talent and capital appropriately. Please join me in supporting this management team as it strives to maximize return. Stan will call in. I am emailing in the hopes of having an opportunity to talk if you are interested in the following possibility If there's anything you'd like to talk about, at any point, please do get in touch. Today I am receiving my 15 Years of Service Award and having my Anniversary lunch. Would you like to attend? Don't forget... Our Board of Trustees Meeting has been cancelled. (Please call me if you have questions regarding this matter.) With your permission, Harry and I will plan to bring our golf clubs on the airplane on Tuesday. I plan to buy one of those little traveling golf bags (very small) and carry only about 5 or 6 of my clubs with me. Attached is the second part of the email for the Development Committee. Please note that these documents should be opened in Word. Please call if you should have questions. The NYSE has standard criteria for listing stocks, which can be found on their website at www.nyse.com.
Demo: SwipeCommandsMixin reveals Mark Read/Unread and Delete commands when you swipe

In the above demo, you can swipe with touch on a mobile device or with a trackpad on a desktop. The above demo also provides keyboard support (Space key toggles a message's read/unread state; the Delete key deletes a message) to show how you can also support both keyboard and touch/trackpad use.

Defining commands

This mixin gives your component the ability to provide commands on a list item swipe to the left or right; your component must define the specific command visualization and behavior.

To define the UI for the commands, define a button-like element and slot it into leftCommandSlot (via slot="leftCommandSlot") for a command that should be revealed on a swipe to the right. Conversely, slot a command into rightCommandSlot that should be revealed on a swipe to the left.

The associated swipe mixins TouchSwipeMixin and TrackpadSwipeMixin will invoke the methods internal.swipeLeft and internal.swipeRight when the user completes a swipe in the desired direction. You can implement those methods to perform work at that point. In some cases, you may wish to defer work until SwipeCommandMixin has finished animating the commands and list item follow the swipe. For that, implement the method internal.swipeLeftComplete or internal.swipeRightComplete instead.

API

The element defines the following shadow parts:

  • command-container: the left and right containers for the, default type is div element
  • left-command-container: left container for commands, default type is div element
  • right-command-container: right container for commands, default type is div element