Documentation navigation

Published API · 0.1.0-rc.1

foldkit-ui · fileDrop

Published foldkit-ui API declarations for fileDrop.

./fileDrop

@wsagency/wseffect-foldkit-ui · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES

This entry point is published in @wsagency/wseffect-foldkit-ui@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.

import * as Wseffect from '@wsagency/wseffect-foldkit-ui/fileDrop'

Exported declarations

FileDropAttributes

Attribute groups the file-drop component provides to the consumer's `toView` callback.

export type FileDropAttributes = Readonly<{
    /** Attributes for the outer drop zone element (typically a `<label>`):
     *  drag-and-drop handlers, `data-drag-over` while a drag hovers, and
     *  `data-disabled` when disabled. */
    root: ReadonlyArray<ChildAttribute>;
    /** Attributes for a hidden `<input type="file">` nested inside the
     *  root: file-change handler, `type`, `id`, `multiple`, `accept`, and
     *  `sr-only` class. */
    input: ReadonlyArray<ChildAttribute>;
}>;

init

Creates an initial file-drop model. Drag state starts cleared.

init: (config: InitConfig) => Model

InitConfig

Configuration for creating a file-drop model with `init`.

export type InitConfig = Readonly<{
    id: string;
}>;

Message

export type Message = typeof Message.Type;

Message

Union of all messages the file-drop component can produce.

Message: import("@wsagency/wseffect-foldkit/message").MessageUnion<{
    readonly EnteredDragZone: {};
    readonly LeftDragZone: {};
    readonly DroppedFiles: {
        files: Schema.NonEmptyArray<Schema.Schema<File>>;
    };
    readonly DroppedNonFiles: {};
}>

Model

export type Model = typeof Model.Type;

Model

Schema for the file-drop component's state. `isDragOver` controls the `data-drag-over` attribute on the root while a drag is hovering. The html layer's `OnDragEnter`/`OnDragLeave` handlers track the per-element active state internally so transitions between children of the zone do not flicker the boolean off-and-on.

Model: Schema.Struct<{
    readonly id: Schema.String;
    readonly isDragOver: Schema.Boolean;
}>

OutMessage

export type OutMessage = typeof OutMessage.Type;

OutMessage

The file-drop component's OutMessages: `ReceivedFiles` on the happy path and `RejectedNonFiles` when a drop event fires without files.

OutMessage: import("@wsagency/wseffect-foldkit/message").MessageUnion<{
    readonly ReceivedFiles: {
        files: Schema.NonEmptyArray<Schema.Schema<File>>;
    };
    readonly RejectedNonFiles: {};
}>

update

Processes a file-drop Message and returns the next Model, optional Commands, and an optional OutMessage.

update: (model: Model, message: Message) => Readonly<{
    model: {
        readonly id: string;
        readonly isDragOver: boolean;
    };
    commands?: Update.Commands<{
        readonly _tag: "DroppedFiles";
        readonly files: readonly [File, ...File[]];
    } | {
        readonly _tag: "DroppedNonFiles";
    } | {
        readonly _tag: "EnteredDragZone";
    } | {
        readonly _tag: "LeftDragZone";
    }, never>;
    outMessage?: {
        readonly _tag: "ReceivedFiles";
        readonly files: readonly [File, ...File[]];
    } | {
        readonly _tag: "RejectedNonFiles";
    };
}>

view

Renders an accessible file-drop zone by publishing attribute groups for a `<label>`-wrapped hidden file input.

view: import("@wsagency/wseffect-foldkit/submodel").View<{
    readonly id: string;
    readonly isDragOver: boolean;
}, {
    readonly _tag: "DroppedFiles";
    readonly files: readonly [File, ...File[]];
} | {
    readonly _tag: "DroppedNonFiles";
} | {
    readonly _tag: "EnteredDragZone";
} | {
    readonly _tag: "LeftDragZone";
}, Readonly<{
    toView: (attributes: FileDropAttributes) => Html;
    accept?: ReadonlyArray<string>;
    multiple?: boolean;
    isDisabled?: boolean;
}>>

ViewInputs

Per-render view inputs passed to `view` via `h.submodel`'s `viewInputs` field.

export type ViewInputs = Readonly<{
    toView: (attributes: FileDropAttributes) => Html;
    accept?: ReadonlyArray<string>;
    multiple?: boolean;
    isDisabled?: boolean;
}>;