Corex.Content (Corex v0.2.1)

View Source

Content items for components with trigger/content patterns to be used with:

Use Corex.Content.new/1 to build a list of items from maps or keyword lists.

What the items attr accepts

Accordion, DataList and Tabs accept Corex.Content.Item structs only, and this is the whole contract. A plain map raises with the new/1 call that would have built it, unlike Corex.List, which coerces: content panels are authored in a template rather than mapped from a query result, so a wrong shape is a developer mistake to surface rather than a bad row to skip.

Each item requires :value, :label and :content, with :disabled and :meta optional. Shared fields match list and tree items (:value, :label, :disabled, :meta).

Summary

Functions

Asserts that a component's :items assign holds Item structs.

Creates a list of Content.Item structs from a list of maps or keyword lists.

Functions

assert_content_items!(assigns, component, opts \\ [])

@spec assert_content_items!(map(), String.t(), keyword()) :: map()

Asserts that a component's :items assign holds Item structs.

Raises on a wrong shape (template authoring mistake) rather than coercing.

new(items)

@spec new(list()) :: [Corex.Content.Item.t()]

Creates a list of Content.Item structs from a list of maps or keyword lists.

Fields

  • :label - (required) Text shown in the trigger/header region
  • :content - (required) Content to display in the content area
  • :value - (optional) Unique identifier (item-1, item-2, … when omitted)
  • :disabled - (optional) Whether the item is disabled, defaults to false
  • :meta - (optional) Additional metadata map for the item

Examples

Corex.Content.new([
  %{label: "Lorem ipsum dolor sit amet", content: "Consectetur adipiscing elit."},
  %{value: "duis", label: "Duis", content: "Nullam eget vestibulum ligula."},
  %{value: "donec", label: "Donec", content: "Congue molestie ipsum gravida a.", disabled: true}
])

Raises ArgumentError if items is not a list of maps or keyword lists.