Mixins / foldkit-mixins-ui

Anchor

namespace · packages/mixins-ui/src/anchor.ts:34

export * as Anchor from './anchor.js'

@foldkit/ui's anchor positioning as a Mount and a Behavior, and the top layer around an anchored panel: the floating element is placed against the button whose id is given, with placement, gap, offset, padding, portal and flip handled by anchorSetup, which also releases on unmount. The Mount writes top and left on the element itself, imperatively (and position too under the fixed strategy); a Style on the same slot must leave those alone, and data-placement is written by @foldkit/ui for styling.

portal defaults to true upstream: the element is relocated into a portal root, so the runtime no longer patches it and a test sees it move. The panel is given the custom properties of the region it was drawn in, as it leaves it, so a region's density or compact step still reaches it. Pass portal: false to keep the node where the view drew it. Positioning without layout (jsdom's zero geometry) burns tens of seconds, portal or not — drive the config, not the clock, in tests.

topLayer draws an upstream-anchored, in-place panel in the browser's top layer instead: it shows the element as a manual popover around the wrapped Mount's own acquire, and hides it when that Mount releases. Use it only when the anchor keeps the panel in place (portal: false); moving a relocated panel hides its popover again. The node stays where the runtime drew it (no portal relocation), so no stacking context or ancestor overflow can reach it, while the anchor positions it as before. The panel carries popover="manual" in its view; light dismiss stays the application's Messages. Wrapping keeps the wrapped Mount's name, args and Messages, so Scene.Mount.resolve still matches it.

Where the anchor Mount is @foldkit/ui's own (Popover, Tooltip), the panel cannot take a second Mount, so layer is an element around it that shows in the top layer itself; and PlaceArrow points an arrow for an anchor that computes none.

In the guides

Members

Anchor.Anchor

const · packages/mixins-ui/src/anchor.ts:40

const Anchor: Mount.MountDefinitionWithArgs<
  'Anchor',
  {
    buttonId: Schema.String
    anchor: Schema.Struct<{
      readonly placement: Schema.optional<
        Schema.Literals<
          readonly [
            'top',
            'right',
            'bottom',
            'left',
            'top-start',
            'top-end',
            'right-start',
            'right-end',
            'bottom-start',
            'bottom-end',
            'left-start',
            'left-end',
          ]
        >
      >
      readonly gap: Schema.optional<Schema.Number>
      readonly offset: Schema.optional<Schema.Number>
      readonly padding: Schema.optional<
        Schema.Union<
          readonly [
            Schema.Number,
            Schema.Struct<{
              readonly top: Schema.optionalKey<Schema.Number>
              readonly right: Schema.optionalKey<Schema.Number>
              readonly bottom: Schema.optionalKey<Schema.Number>
              readonly left: Schema.optionalKey<Schema.Number>
            }>,
          ]
        >
      >
      readonly portal: Schema.optional<Schema.Boolean>
      readonly isPlacementLocked: Schema.optional<Schema.Boolean>
    }>
    interceptTab: Schema.optional<Schema.Boolean>
    focusAfterPosition: Schema.optional<Schema.Boolean>
    focusSelector: Schema.optional<Schema.String>
    arrowId: Schema.optional<Schema.String>
    arrowPadding: Schema.optional<Schema.Number>
  },
  never
>

Anchor.AnchorArgs

type · packages/mixins-ui/src/anchor.ts:78

type AnchorArgs = Parameters<typeof Anchor>[0]

Anchor.behavior

function · packages/mixins-ui/src/anchor.ts:375

function behavior<Slots, Input, ParentMessage>(
  bound: SlotView.Bound<Slots, Input, ParentMessage>,
): (
  options: BehaviorOptions<Input, Slots>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>
function behavior<Slots>(
  slots: SlotView.Unbound<Slots>,
): <Input, ParentMessage>(
  options: BehaviorOptions<Input, Slots>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>

Mounts the anchor on the floating slot with the config the input gives. Takes a SlotView.over binder, which types config's input, or the slots.

Anchor.BehaviorOptions

interface · packages/mixins-ui/src/anchor.ts:365

interface BehaviorOptions<Input, Slots> {
  readonly floating: keyof Slots & string
  readonly config: (input: Input) => AnchorArgs
}

Anchor.inheritRegion

function · packages/mixins-ui/src/anchor.ts:180

function inheritRegion<Message, E>(
  action: Mount.MountAction<Message, E>,
): Mount.MountAction<Message, E>

Wraps an anchor Mount that portals its panel (upstream's, which the portal of its config does not say no to) so the panel keeps the custom properties of the region it was drawn in: a region set compact, or a density, reaches it as it would an in-place panel. Where the panel is not relocated it does nothing. Wrapping keeps the wrapped Mount's name, args and Messages, as topLayer does.

Anchor.layer

function · packages/mixins-ui/src/anchor.ts:278

function layer<Message>(
  h: HtmlBuilder<Message>,
): ReadonlyArray<Attribute<Message>>

A box in the top layer, the viewport's width and no height, for a panel whose anchor Mount is @foldkit/ui's: an element holds one Mount, so the panel cannot also carry the one that shows it. Drawn around the panel, the layer takes the panel out of every stacking context and ancestor overflow, and the anchor places the panel inside it as on the page: the layer is fixed at the viewport's corner, so its coordinates are the viewport's, and as wide, so the panel's widths and 100% read as they would. With no height it covers nothing a press could land on. Its look is inline: the browser's popover border, padding and fill must not show around a panel, whatever a theme does.

Anchor.layerBox

function · packages/mixins-ui/src/anchor.ts:289

function layerBox<Message>(
  h: HtmlBuilder<Message>,
  style?: Readonly<Record<string, string>>,
): ReadonlyArray<Attribute<Message>>

The layer box without its Mount, for a box whose own Mount shows it (topLayer around one that sends Messages, which a Scene can resolve where TopLayer sends none). style joins the box's inline style, since a second h.Style on the element would replace it.

Anchor.PlaceArrow

const · packages/mixins-ui/src/anchor.ts:318

const PlaceArrow: Mount.MountDefinitionWithArgs<
  'PlaceArrow',
  { buttonId: Schema.String },
  never
>

Places an arrow drawn as a panel's child against the middle of the element whose id is given, for a panel whose anchor computes no arrow (@foldkit/ui's Tooltip). It writes --arrow-x (above or below) or --arrow-y (beside) on the arrow, the properties upstream's anchor writes on a panel, and the other initial, so one rule styles both. It follows the panel: the anchor writes the panel's style and data-placement on every move, its first showing included, and each write places the arrow.

Anchor.TopLayer

const · packages/mixins-ui/src/anchor.ts:261

const TopLayer: Mount.MountDefinitionNoArgs<'TopLayer', never>

Shows its element in the top layer while it is drawn: the layer bundle's Mount.

Anchor.topLayer

function · packages/mixins-ui/src/anchor.ts:252

function topLayer<Message, E>(
  action: Mount.MountAction<Message, E>,
): Mount.MountAction<Message, E>

Draw an upstream-anchored, in-place panel in the browser's top layer: show it as a manual popover, run the wrapped Mount's own acquire (which positions it), and hide it once that Mount releases. Use it only when the anchor keeps the panel in place (portal: false): upstream portal relocation moves the element after the Mount acquires, and moving a shown popover hides it again. The panel carries popover="manual" in its view. Where the popover API or the attribute is missing the wrapper is a no-op and the anchor positions in place.

The view sets inset: auto on the panel, since the anchor writes only left and top over the browser's inset: 0. The browser's popover border, padding and Canvas fill stay on an unstyled panel: any author rule replaces them, as every recipe's panel does, where an inline reset would beat the recipes.