Mixins / foldkit-mixins-ui

Rating

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

export * as Rating from './rating.js'

In the guides

Members

Rating.configure

function · packages/mixins-ui/src/rating.ts:210

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

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

Rating.RatingDisplay

interface · packages/mixins-ui/src/rating.ts:87

interface RatingDisplay<Message> extends RatingCommon<Message> {
  readonly readOnly: true
  readonly onChange?: never
  readonly onClear?: never
  readonly precision?: never
  readonly disabled?: never
}

A rating shown and not taken: it sends nothing, so it takes no Messages.

Rating.RatingInput

interface · packages/mixins-ui/src/rating.ts:75

interface RatingInput<Message> extends RatingCommon<Message> {
  readonly readOnly?: false | undefined
  readonly onChange: (value: number) => NoInfer<Message>
  readonly onClear?: (() => NoInfer<Message>) | undefined
  readonly precision?: 1 | 0.5 | undefined
  readonly disabled?: boolean | undefined
}

A rating that takes a choice.

Rating.RatingPreset

type · packages/mixins-ui/src/rating.ts:199

type RatingPreset = Pick<
  RatingInput<never>,
  'max' | 'precision' | 'showValue' | 'words' | 'labels' | 'style'
> & {
  readonly mixins?: MixinList<never>
}

What a Rating is given once: its look, words and size. The value, the Messages and what is rated are each use's.

Rating.RatingSlots

const · packages/mixins-ui/src/rating.ts:36

const RatingSlots: Slots.Contract<{
  readonly root: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly Slot.EventName[],
    readonly [
      Attr.AttrToken<'role'>,
      Attr.AttrToken<'aria-label'>,
      Attr.AttrToken<'aria-labelledby'>,
    ],
    readonly Slot.RequirementName[],
    boolean
  >
  readonly label: 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 star: Slot.UnnamedSlot<
    Capability.Capability<
      'Interactive',
      readonly [Capability.Capability<'Base', readonly []>]
    >,
    readonly [Event.EventToken<'change'>, Event.EventToken<'keydown'>],
    readonly [
      Attr.AttrToken<'aria-label'>,
      Attr.AttrToken<'disabled'>,
      Attr.AttrToken<'value'>,
    ],
    readonly Slot.RequirementName[],
    boolean
  >
  readonly value: 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 star rating, the APG's radio group of native radios: a root with role="radiogroup" named by its label, and a star per value, an input type="radio" sharing one name, so the browser moves the focus and the choice with the arrows and a form submits the value; Home and End, which a native group lacks, go to the ends through a key route on each star. The rating is the application's: the view draws value (none before anyone rates) and sends onChange with the star chosen, and onClear when the star already chosen is pressed again. With precision: 0.5 each star is two radios, its halves. Each star carries data-filled; the recipe draws the glyph in CSS.

Read-only, the root is one image whose name says the rating, the stars are plain marks, and a fractional value (4.3) fills the last star as far as it goes: each mark's share is --fk-rating-fill, 0 to 1.

Rating.RatingView

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

type RatingView<Message> = RatingInput<Message> | RatingDisplay<Message>

Rating.RatingWords

interface · packages/mixins-ui/src/rating/words.ts:2

interface RatingWords {
  readonly one: string
  readonly other: string
  readonly rated: string
  readonly notRated: string
}

The fixed text a Rating says. {value} is a number of stars, {label} what is rated, {stars} the rating as one or other says it, {max} the most stars.

Rating.view

function · packages/mixins-ui/src/rating.ts:100

function view<Message>(
  options: RatingView<Message>,
  h: HtmlBuilder<Message>,
): Html

Rating.words

const · packages/mixins-ui/src/rating/words.ts:14

const words = { one, other, rated, notRated }

The words a Rating uses when none are given.