Mixins / foldkit-mixins-ui

Avatar

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

export * as Avatar from './avatar.js'

In the guides

Members

Avatar.AvatarBadge

interface · packages/mixins-ui/src/avatar.ts:88

interface AvatarBadge {
  readonly content: Html
  readonly place: AvatarBadgePlace
  readonly label?: string | undefined
}

A small mark on a corner: an icon, a count, a Badge. label is read with the name, since the avatar is one image and its badges are not announced on their own.

Avatar.AvatarBadgePlace

type · packages/mixins-ui/src/avatar.ts:81

type AvatarBadgePlace = 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end'

The corner of the avatar a badge sits on; the status dot takes the bottom end.

Avatar.AvatarGroupSlots

const · packages/mixins-ui/src/avatar.ts:210

const AvatarGroupSlots: Slots.Contract<{
  readonly root: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly Slot.EventName[],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
}>

A group publishes its frame; each avatar in it is an AvatarSlots avatar, and the count of those left out is one more, so it takes the same size and shape. The +N's root carries data-rest, so a style can keep it out of a colour by name.

Avatar.AvatarGroupView

interface · packages/mixins-ui/src/avatar.ts:215

interface AvatarGroupView<Message = never> {
  readonly people: ReadonlyArray<AvatarPerson>
  readonly max?: number | undefined
  readonly label?: string | undefined
  readonly words?: Partial<AvatarWords> | undefined
  readonly rest?: ((count: number) => Html) | undefined
  readonly wrap?: ((avatar: Html, person: AvatarPerson) => Html) | undefined
  readonly style?: NamedStyle<typeof AvatarGroupSlots> | undefined
  readonly avatarStyle?: NamedStyle<typeof AvatarSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
}

Avatars overlapping in a row, at most max of them and a +N for the rest.

Avatar.AvatarPerson

type · packages/mixins-ui/src/avatar.ts:95

type AvatarPerson = {
  readonly name: string
  readonly initials?: string | undefined
  readonly status?: AvatarStatus | undefined
  readonly badges?: ReadonlyArray<AvatarBadge> | undefined
} & AvatarSource

What an avatar shows of one person, apart from how it is styled.

Avatar.AvatarPicture

interface · packages/mixins-ui/src/avatar.ts:69

interface AvatarPicture {
  readonly attributes: <Message>(
    h: HtmlBuilder<Message>,
  ) => Option.Option<ReadonlyArray<Attribute<Message>>>
}

A picture the application passes in place of a URL: it writes the img's attributes, or none when it has no URL (the initials then stand alone). Avatar.picture({ asset, provider, width }) makes one from foldkit-media; it lives in a file of its own, so a page that passes src as text ships no picture code. Implement it to draw pictures any other way.

Avatar.AvatarPreset

type · packages/mixins-ui/src/avatar.ts:280

type AvatarPreset = Pick<AvatarView<never>, 'style' | 'words'> & {
  readonly groupStyle?: NamedStyle<typeof AvatarGroupSlots> | undefined
  readonly mixins?: MixinList<never>
}

What an Avatar is given once: its look, its words, and the look of a group around it.

Avatar.AvatarSize

type · packages/mixins-ui/src/avatar.ts:30

type AvatarSize = keyof typeof sizes

Avatar.AvatarSlots

const · packages/mixins-ui/src/avatar.ts:20

const AvatarSlots: Slots.Contract<{
  readonly root: 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 fallback: 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 image: 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 status: 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 badge: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly Slot.EventName[],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
}>

An avatar publishes its regions as slots; it owns no state, messages, or bundles. The picture stacks over the fallback initials, so the initials show while it loads and where it fails; the browser owns loading. The root is one image named by the person (and their status), so a screen reader hears the name once, not the initials. It carries the name's hue as --fk-avatar-hue (0 to 359, the same for the same name everywhere), for a style that colours the initials by who they are. The status dot carries data-status; a badge carries data-place, its corner.

Avatar.AvatarSource

type · packages/mixins-ui/src/avatar.ts:76

type AvatarSource =
  | {
      readonly src?: string | undefined
      readonly picture?: undefined
    }
  | {
      readonly picture: AvatarPicture
      readonly src?: undefined
    }

Where the picture comes from: a URL, or an AvatarPicture; never both.

Avatar.AvatarStatus

type · packages/mixins-ui/src/avatar.ts:40

type AvatarStatus = 'online' | 'away' | 'busy' | 'offline'

Whether someone is there, shown as a dot at the avatar's lower end.

Avatar.AvatarView

type · packages/mixins-ui/src/avatar.ts:109

type AvatarView<Message = never> = AvatarPerson & {
  readonly words?: Partial<AvatarWords> | undefined
  readonly style?: NamedStyle<typeof AvatarSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
}

An avatar in one call: who it pictures, the picture if there is one, a style for its slots, and mixins beside the style. No upstream component stands behind it. Without a picture the initials stand alone.

Avatar.AvatarWords

interface · packages/mixins-ui/src/avatar.ts:46

interface AvatarWords {
  readonly online: string
  readonly away: string
  readonly busy: string
  readonly offline: string
  readonly more: string
}

The words an avatar and its group draw: each status as read aloud, and the group's count of those left out ({count} is filled).

Avatar.configure

function · packages/mixins-ui/src/avatar.ts:297

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

The application's own Avatar: base for every use, presets chosen at a use with preset, and the call over both. A preset's style and words reach a group's avatars too; its groupStyle is the group's own.

Avatar.group

function · packages/mixins-ui/src/avatar.ts:235

function group<Message = never>(
  options: AvatarGroupView<Message>,
  h: HtmlBuilder<Message>,
): Html

Avatar.picture

function · packages/mixins-ui/src/avatar/picture.ts:13

function picture<Asset extends ImageAsset>(options: {
  readonly asset: Asset
  readonly provider: Provider.Provider<NoInfer<Asset>>
  readonly width: number
}): AvatarPicture

A picture foldkit-media writes the candidates of, as the avatar's picture: the asset, the provider of its variants, and how wide the avatar is drawn in CSS pixels (Avatar.widthOf(size)), so a 24px avatar fetches a 48px variant, not the original. With a provider that has no URL for the asset the initials stand alone. An application that passes src as text never imports this.

Avatar.sizes

const · packages/mixins-ui/src/avatar.ts:29

const sizes = { xs, sm, md, lg, xl }

An avatar's sizes, in rem: the recipe's size axis draws them, and widthOf reads them.

Avatar.view

function · packages/mixins-ui/src/avatar.ts:199

function view<Message = never>(
  options: AvatarView<Message>,
  h: HtmlBuilder<Message>,
): Html

Avatar.widthOf

function · packages/mixins-ui/src/avatar.ts:37

function widthOf(size: AvatarSize): number

How wide an avatar of size is drawn, in CSS pixels at the browser's default 16px rem: the width an AvatarPicture asks its candidates for, so the recipe's size is written once.

Avatar.words

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

const words = { online, away, busy, offline, more }