Mixins / foldkit-mixins-ui

DatePicker

namespace · packages/mixins-ui/src/datePicker.ts:1

export * as DatePicker from './datePicker.js'

In the guides

Members

DatePicker.Args

const · packages/mixins-ui/src/datePicker/state.ts:54

const Args: Schema.Struct<{ readonly id: Schema.String; readonly today: Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>; readonly selection: Schema.optionalKey<TaggedUnion<{ readonly Single: { readonly date: Schema.OptionFromNullOr<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; }; readonly Range: { readonly start: Schema.OptionFromNullOr<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; readonly end: Schema.OptionFromNullOr<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; }; readonly Multiple: { readonly dates: Schema.$Array<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; }; }>>; readonly closes: Schema.optionalKey<Schema.Literals<readonly ["complete", "manual"]>>; readonly animated: Schema.optionalKey<Schema.Boolean>; readonly minDate: Schema.optionalKey<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; readonly maxDate: Schema.optionalKey<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; readonly disabledDaysOfWeek: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]>>>; readonly disabledDates: Schema.optionalKey<Schema.$Array<Schema.Struc …;

What a DatePicker starts from: init's options, and Bundles.DatePicker's args.

DatePicker.Closes

const · packages/mixins-ui/src/datePicker/state.ts:21

const Closes: Schema.Literals<readonly ['complete', 'manual']>

When a pick closes the popover: once the selection is whole, or never.

DatePicker.configure

function · packages/mixins-ui/src/datePicker/view.ts:178

function configure<const Names extends string = never>(
  config: Presets<DatePickerPreset, Names>,
): {
  readonly view: <Outer>(
    options: DatePickerView<Outer> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own DatePicker: base for every use, presets chosen at a use with preset, and the call over both. words merge word by word; any other option given at the call replaces the preset's.

DatePicker.DatePickerPreset

type · packages/mixins-ui/src/datePicker/view.ts:159

type DatePickerPreset = Pick<
  DatePickerView<never>,
  | 'anchor'
  | 'weekNumbers'
  | 'caption'
  | 'paging'
  | 'today'
  | 'presets'
  | 'detail'
  | 'words'
  | 'style'
  | 'calendarStyle'
>

What a DatePicker is given once: its looks and each option that holds no Message and no drawing. The trigger's text is one field's, so it stays at the call.

DatePicker.DatePickerSlots

const · packages/mixins-ui/src/datePicker.ts:25

const DatePickerSlots: Slots.Contract<{
  readonly wrapper: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly Slot.EventName[],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
  readonly trigger: Slot.UnnamedSlot<
    Capability.Capability<
      'Interactive',
      readonly [Capability.Capability<'Base', readonly []>]
    >,
    readonly [Event.EventToken<'click'>],
    readonly [Attr.AttrToken<'aria-expanded'>],
    readonly Slot.RequirementName[],
    boolean
  >
  readonly panel: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly Slot.EventName[],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
  readonly backdrop: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly [Event.EventToken<'click'>],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
}>

DatePicker is a small composed Submodel: a trigger button plus a panel/backdrop pair around the embedded calendar. The resolver runs once per bundle and each base attribute passes through by identity. The wrapper and hidden form inputs are drawn outside the popover assembly and pass through untouched.

The trigger owns click while enabled. A Behavior adding its own handler is a conflict, not a second silent owner. The backdrop owns click while the popover shows it.

DatePicker.DatePickerView

interface · packages/mixins-ui/src/datePicker/view.ts:39

interface DatePickerView<Outer> {
  readonly model: Model
  readonly onMessage: (message: Message) => Outer
  readonly label: string
  readonly trigger: (selection: Selection) => string
  readonly name?: string | undefined
  readonly disabled?: boolean | undefined
  readonly anchor?: AnchorConfig | undefined
  readonly weekNumbers?: boolean | undefined
  readonly caption?: Caption | undefined
  readonly paging?: 'both' | 'previous' | 'next' | 'none' | 'end' | undefined
  readonly today?: TodayButton | undefined
  readonly presets?: ReadonlyArray<Preset> | undefined
  readonly detail?:
    ((date: Dates.CalendarDate) => Option.Option<string>) | undefined
  readonly aside?: Html | undefined
  readonly footer?: Html | undefined
  readonly words?: Partial<CalendarWords> | undefined
  readonly style?: NamedStyle<typeof DatePickerSlots> | undefined
  readonly calendarStyle?: NamedStyle<typeof CalendarSlots> | undefined
  readonly calendarMixins?: MixinList<Outer> | undefined
}

DatePicker.fold

function · packages/mixins-ui/src/datePicker/state.ts:176

function fold(model: Model, message: Message): Return

DatePicker.init

function · packages/mixins-ui/src/datePicker/state.ts:78

function init(args: Args): Model

DatePicker.Message

const · packages/mixins-ui/src/datePicker/state.ts:34

const Message: MessageUnion<{ readonly GotPickerMessage: { readonly message: MessageUnion<{ readonly GotCalendarMessage: { message: import("foldkit/message").MessageUnion<{ readonly ClickedDay: { date: Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>; }; readonly PressedKeyOnGrid: { key: Schema.String; isShift: Schema.Boolean; }; readonly ClickedPreviousMonthButton: {}; readonly ClickedNextMonthButton: {}; readonly ClickedHeading: {}; readonly SelectedMonth: { month: Schema.Int; }; readonly SelectedYear: { year: Schema.Int; }; readonly PagedYears: { direction: Schema.Literals<readonly [1, -1]>; }; readonly FocusedGrid: {}; readonly BlurredGrid: {}; readonly RefreshedToday: { today: Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>; }; readonly CompletedFocusGrid: {}; }>; }; readonly GotPopoverMessage: { message: import("foldkit/message").MessageUnion<{ readonly RequestedOpen: {}; readonly RequestedClose: {}; readonly BlurredPanel: {}; readonly PressedPointerOnButton: { pointerType: Schema.String; button: Schema.Number; }; readonly CompletedFocusPanel: {}; readonly CompletedFocusButton: {}; readonly CompletedLockScroll: {}; readonly CompletedUnlockScroll: {}; readonly CompletedInertOthers: {}; readonly CompletedRestoreInert: {}; readonly ClickedButton: {}; readonly IgnoredMouseClick: {}; readonly SuppressedSpaceScroll: {}; readonly CompletedAnchorPopover: {}; readonly CompletedPortalPopoverBa …;

DatePicker.Model

const · packages/mixins-ui/src/datePicker/state.ts:24

const Model: Schema.Struct<{ readonly picker: Schema.Struct<{ readonly id: Schema.String; readonly calendar: Schema.Struct<{ readonly id: Schema.String; readonly today: Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>; readonly viewYear: Schema.Int; readonly viewMonth: Schema.Int; readonly viewMode: Schema.Literals<readonly ["Days", "Months", "Years"]>; readonly maybeFocusedDate: Schema.Option<Schema.Struct<{ readonly year: Schema.Int; readonly month: Schema.Int; readonly day: Schema.Int; }>>; readonly isGridFocused: Schema.Boolean; readonly locale: Schema.Struct<{ readonly firstDayOfWeek: Schema.Literals<readonly ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]>; readonly monthNames: Schema.Tuple<readonly [Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String]>; readonly shortMonthNames: Schema.Tuple<readonly [Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String]>; readonly dayNames: Schema.Tuple<readonly [Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String]>; readonly shortDayNames: Schema.Tuple<readonly [Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String, Schema.String]>; …;

DatePicker.OutMessage

const · packages/mixins-ui/src/datePicker/state.ts:47

const OutMessage: MessageUnion<{
  readonly Changed: {
    readonly selection: TaggedUnion<{
      readonly Single: {
        readonly date: Schema.OptionFromNullOr<
          Schema.Struct<{
            readonly year: Schema.Int
            readonly month: Schema.Int
            readonly day: Schema.Int
          }>
        >
      }
      readonly Range: {
        readonly start: Schema.OptionFromNullOr<
          Schema.Struct<{
            readonly year: Schema.Int
            readonly month: Schema.Int
            readonly day: Schema.Int
          }>
        >
        readonly end: Schema.OptionFromNullOr<
          Schema.Struct<{
            readonly year: Schema.Int
            readonly month: Schema.Int
            readonly day: Schema.Int
          }>
        >
      }
      readonly Multiple: {
        readonly dates: Schema.$Array<
          Schema.Struct<{
            readonly year: Schema.Int
            readonly month: Schema.Int
            readonly day: Schema.Int
          }>
        >
      }
    }>
  }
}>

DatePicker.resolve

function · packages/mixins-ui/src/datePicker.ts:51

function resolve<Input>(
  render: DatePickerRenderInfo,
  mixins: MixinList<Message>,
  context: ResolveContext<Input, Message>,
): ResolvedDatePicker

Resolves the date picker's popover bundles. Concrete over the date picker's own Message: unlike the wrapped forks, these bundles mix the popover's pre-bound groups with plain date-picker attributes, so they cannot promise any other universe. Message-free Mixins (the styling case) and date-picker-message Behaviors attach unchanged.

DatePicker.ResolvedDatePicker

type · packages/mixins-ui/src/datePicker.ts:37

type ResolvedDatePicker = Omit<
  DatePickerRenderInfo,
  'trigger' | 'panel' | 'backdrop'
> & {
  readonly wrapper: SlotAttributes<Message>
  readonly trigger: SlotAttributes<Message>
  readonly panel: SlotAttributes<Message> | undefined
  readonly backdrop: SlotAttributes<Message> | undefined
}

DatePicker.set

function · packages/mixins-ui/src/datePicker/state.ts:169

function set(model: Model, selection: Selection): Model

model holding selection, its month turned to the selection's first day: for a parent that sets the selection itself. Nothing is reported, and the popover stays as it is.

DatePicker.toView

function · packages/mixins-ui/src/datePicker.ts:74

function toView(
  mixins: MixinList<Message>,
  draw?: (resolved: ResolvedDatePicker, h: HtmlBuilder<Message>) => Html,
): (render: DatePickerRenderInfo, h: HtmlBuilder<Message>) => Html

The date picker's toView: draw receives its bundles with mixins applied, and the date picker's builder to draw them with; without one, they are drawn as upstream draws them. Unlike the other adapters' it takes no builder of the application's, which could not draw these bundles.

DatePicker.update

function · packages/mixins-ui/src/datePicker.ts:94

function update(
  selection: Selection,
  closes?: 'complete' | 'manual',
): (
  model: Model,
  message: Message,
) => Update.ReturnWithOutMessage<Model, Message, OutMessage>

The date picker's update for the application's selection, read when the Message arrives. Upstream closes the popover on every day picked; this keeps it open while the day leaves the selection unfinished (a range's first end, any day of a Multiple selection), and is upstream's update otherwise. Either way it reports SelectedDate, which the application folds through Calendar.picked. Escape, a press outside and the trigger still close it, leaving whatever was picked so far. With closes: 'manual' no pick closes it, as a picker with a time beside its days needs.

DatePicker.view

function · packages/mixins-ui/src/datePicker/view.ts:78

function view<Outer>(
  options: DatePickerView<Outer>,
  h: HtmlBuilder<Outer>,
): Html

A DatePicker: a trigger showing the selection, and a popover holding a Calendar. Every press goes to onMessage; the selection is model.selection. The popover closes on the pick that makes the selection whole, unless the state was made with closes: 'manual'.