MithrilUI.AI.ComponentSelector (Mithril UI v0.1.2)

View Source

AI-friendly interface for component selection and documentation.

This module provides structured data and functions for AI agents to:

  • List all available components
  • Get component metadata and schemas
  • Suggest appropriate components based on context
  • Generate usage examples

Usage

List all components:

MithrilUI.AI.ComponentSelector.list_components()

Get component schema:

MithrilUI.AI.ComponentSelector.get_schema(:button)

Suggest components for a use case:

MithrilUI.AI.ComponentSelector.suggest_components("form submission")

Summary

Functions

Returns all component schemas as a map.

Exports all component metadata to JSON format.

Returns related components for a given component.

Returns the JSON schema for a component.

Returns usage examples for a component.

Returns all component categories with descriptions.

Returns a list of all components with their metadata.

Suggests components based on a natural language description or context.

Functions

all_schemas()

Returns all component schemas as a map.

Useful for generating documentation or exporting to JSON.

export_json(opts \\ [])

Exports all component metadata to JSON format.

Options

  • :pretty - Format JSON with indentation (default: true)

get_related(component_name)

Returns related components for a given component.

Useful for suggesting alternatives or complementary components.

get_schema(component_name)

Returns the JSON schema for a component.

The schema includes:

  • Component metadata (name, description, category)
  • Available props with types and defaults
  • Variants and sizes
  • Accessibility information
  • Usage guidance

Examples

iex> get_schema(:button)
%{
  "$schema" => "https://mithrilui.dev/schemas/component/v1",
  "component" => "button",
  ...
}

get_usage_examples(component_name)

Returns usage examples for a component.

Examples

iex> get_usage_examples(:button)
[
  %{
    name: "Basic button",
    code: "<.button>Click me</.button>"
  },
  ...
]

list_categories()

Returns all component categories with descriptions.

list_components(opts \\ [])

Returns a list of all components with their metadata.

Options

  • :category - Filter by category (e.g., :forms, :feedback)
  • :format - Output format (:full, :summary, :names_only)

Examples

iex> list_components()
[%{name: :button, category: :actions, ...}, ...]

iex> list_components(category: :forms)
[%{name: :input, ...}, %{name: :select, ...}, ...]

iex> list_components(format: :names_only)
[:button, :input, :select, ...]

suggest_components(context)

Suggests components based on a natural language description or context.

Returns components sorted by relevance to the given context.

Examples

iex> suggest_components("submit form")
[%{name: :button, relevance: :high, reason: "Button for form submission"}, ...]

iex> suggest_components("display user list")
[%{name: :table, ...}, %{name: :list_group, ...}]

iex> suggest_components("loading indicator")
[%{name: :spinner, ...}, %{name: :skeleton, ...}]