Published API · 0.1.0-rc.1
foldkit-ui · checkbox
Published foldkit-ui API declarations for checkbox.
./checkbox
@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/checkbox'
Exported declarations
CheckboxAttributes
Attribute groups the checkbox provides to the consumer's `toView`
callback. Each group is a `ReadonlyArray<Attribute<Message>>` the
consumer spreads directly into its own element attribute arrays:
```ts
toView: attributes =>
h.div(
[...attributes.checkbox, h.Class('my-class')],
[...],
)
```
The `checkbox` and `label` bundles carry the click and Space handlers that
dispatch the configured `onToggle` Message.
The `checkbox` bundle sets `type="button"` so that rendering the control as a
`button` element inside a `form` element toggles without also submitting the
form. Setting it is harmless on the other elements a control might use, such
as a `div` or a `span`, because the builder assigns a DOM property rather
than an HTML attribute. Spread a later `h.Type` to override it.
export type CheckboxAttributes<Message> = Readonly<{
checkbox: ReadonlyArray<Attribute<Message>>;
label: ReadonlyArray<Attribute<Message>>;
description: ReadonlyArray<Attribute<Message>>;
hiddenInput: ReadonlyArray<Attribute<Message>>;
}>;
descriptionId
Returns the description element id, derived from the checkbox's base id.
descriptionId: (id: string) => string
labelId
Returns the label element id, derived from the checkbox's base id.
labelId: (id: string) => string
view
Renders an accessible checkbox as a stateless controlled component. The
parent owns the checked state (`isChecked`) and receives the new state via
`onToggle` when the user toggles it.
```ts
// In view:
Checkbox.view(
{
id: 'accept-terms',
isChecked: model.acceptedTerms,
onToggle: isChecked => ToggledTerms({ isChecked }),
toView: attributes => ...,
},
h,
)
// In update:
ToggledTerms: ({ isChecked }) => ({
model: modifyFields(model, { acceptedTerms: () => isChecked }),
}),
```
view: <Message>(config: ViewConfig<Message>, h: HtmlBuilder<Message>) => Html
ViewConfig
export type ViewConfig<Message> = Readonly<{
id: string;
isChecked: boolean;
onToggle: (isChecked: boolean) => Message;
toView: (attributes: CheckboxAttributes<Message>) => Html;
isDisabled?: boolean;
isReadOnly?: boolean;
isIndeterminate?: boolean;
hasDescription?: boolean;
name?: string;
value?: string;
}>;