Primitives / foldkit-primitives/interaction

SwipeActions

namespace · packages/primitives/src/interaction/swipe-actions.ts:11

export * as SwipeActions from './swipe-actions.js'

Swipe-to-reveal actions behind a row, with a way in that needs no pointer: which row side is open, what a release of a Swipe means (open, close, or run the first action at once), and the keys that do the same (an arrow opens the side it reveals, the opposite arrow or Escape closes). The row's offset while a finger moves it is the parent's draft from Swiped; this holds the resting state and decides the end. The actions behind a closed row should be inert, so Tab skips them: data-swipe is for the stylist, inert for the browser, both from open.

In the guides

Members

SwipeActions.Args

const · packages/primitives/src/interaction/swipe-actions.ts:52

const Args: Schema.Struct<{
  readonly fullSwipe: Schema.Number
  readonly flick: Schema.Number
  readonly full: Schema.Boolean
}>

SwipeActions.bundle

const · packages/primitives/src/interaction/swipe-actions.ts:109

const bundle: Bundle.Bundle<
  'SwipeActions',
  {
    readonly fullSwipe: number
    readonly flick: number
    readonly full: boolean
  },
  { readonly open: Option.Option<'start' | 'end'> },
  | { readonly _tag: 'Closed' }
  | { readonly _tag: 'Opened'; readonly side: 'start' | 'end' }
  | {
      readonly _tag: 'Released'
      readonly deltaX: number
      readonly velocityX: number
      readonly rowWidth: number
      readonly startWidth: number
      readonly endWidth: number
      readonly rtl: boolean
    },
  { readonly _tag: 'FullSwiped'; readonly side: 'start' | 'end' },
  never,
  never,
  NoView,
  {},
  {}
>

SwipeActions.decide

function · packages/primitives/src/interaction/swipe-actions.ts:80

function decide(model: Model, release: Release, args: Args): Decision

What letting go means. The row stands where it rested (open on a side, or closed) plus deltaX. A flick opens the side it points to, or closes the row when it points back; otherwise past half of a side's actions opens it, less closes, and past fullSwipe of the row runs its first action when full. A side with no actions never opens.

SwipeActions.Decision

type · packages/primitives/src/interaction/swipe-actions.ts:65

type Decision =
  | {
      readonly _tag: 'Open'
      readonly side: Side
    }
  | {
      readonly _tag: 'Close'
    }
  | {
      readonly _tag: 'Full'
      readonly side: Side
    }

SwipeActions.FullSwiped

const · packages/primitives/src/interaction/swipe-actions.ts:49

const FullSwiped: Schema.TaggedStruct<
  'FullSwiped',
  { readonly side: Schema.Literals<readonly ['start', 'end']> }
>

A swipe that ran past fullSwipe of the row: the parent runs that side's first action.

SwipeActions.KeyOptions

interface · packages/primitives/src/interaction/swipe-actions.ts:131

interface KeyOptions<Input, ParentMessage> {
  readonly open: (input: Input) => Option.Option<Side>
  readonly rtl: boolean
  readonly toMessage: (message: Message) => ParentMessage
}

SwipeActions.keys

function · packages/primitives/src/interaction/swipe-actions.ts:147

function keys<Input, ParentMessage>(
  options: KeyOptions<Input, ParentMessage>,
): Behaviors.Keys.Route<Input, ParentMessage>

The keyboard's swipe, as a Behaviors.Keys route for the row's keydown owner: the arrow toward the end of the row reveals the start side's actions (the other arrow, the end side's), the opposite arrow closes an open side, and Escape closes. A press that would change nothing is declined, so Escape on a closed row reaches whatever closes the page around it.

SwipeActions.Message

const · packages/primitives/src/interaction/swipe-actions.ts:40

const Message: MessageUnion<{
  readonly Opened: { readonly side: Schema.Literals<readonly ['start', 'end']> }
  readonly Closed: {}
  readonly Released: {
    deltaX: Schema.Number
    velocityX: Schema.Number
    rowWidth: Schema.Number
    startWidth: Schema.Number
    endWidth: Schema.Number
    rtl: Schema.Boolean
  }
}>

SwipeActions.Model

const · packages/primitives/src/interaction/swipe-actions.ts:21

const Model: Schema.Struct<{
  readonly open: Schema.OptionFromNullOr<
    Schema.Literals<readonly ['start', 'end']>
  >
}>

SwipeActions.Release

const · packages/primitives/src/interaction/swipe-actions.ts:37

const Release: Schema.Struct<{
  deltaX: Schema.Number
  velocityX: Schema.Number
  rowWidth: Schema.Number
  startWidth: Schema.Number
  endWidth: Schema.Number
  rtl: Schema.Boolean
}>

SwipeActions.Side

const · packages/primitives/src/interaction/swipe-actions.ts:18

const Side: Schema.Literals<readonly ['start', 'end']>

The side of the row its actions sit on: start is revealed by moving the row toward the end (right, in English).