PhoenixKitWeb.Components.Dashboard.ContextSelector (phoenix_kit v1.7.42)

Copy Markdown View Source

Context selector dropdown component for dashboard navigation.

Allows users with multiple contexts (organizations, farms, teams, etc.) to switch between them. Only renders when the user has 2+ contexts.

Components

Usage

Header position (default):

<.context_selector
  contexts={@dashboard_contexts}
  current={@current_context}
  config={@context_selector_config}
/>

Sidebar position:

<.sidebar_context_selector
  contexts={@dashboard_contexts}
  current={@current_context}
  config={@context_selector_config}
/>

Or use the convenience wrappers that check visibility:

<.context_selector_if_enabled
  show={@show_context_selector}
  contexts={@dashboard_contexts}
  current={@current_context}
  config={@context_selector_config}
/>

<.sidebar_context_selector_if_enabled
  show={@show_context_selector}
  contexts={@dashboard_contexts}
  current={@current_context}
  config={@context_selector_config}
/>

Summary

Functions

Renders the context selector dropdown.

Conditionally renders the context selector based on visibility flag.

Renders a mobile-friendly context selector for mobile menus.

Conditionally renders the mobile context selector.

Renders a context selector for the sidebar.

Conditionally renders the sidebar context selector.

Functions

context_selector(assigns)

Renders the context selector dropdown.

Only renders if there are contexts to display.

Attributes

  • contexts - List of context items
  • current - The currently selected context
  • config - The ContextSelector config struct
  • class - Additional CSS classes

Attributes

  • contexts (:list) (required)
  • current (:any) - Defaults to nil.
  • config (:any) (required)
  • class (:string) - Defaults to "".

context_selector_if_enabled(assigns)

Conditionally renders the context selector based on visibility flag.

Use this wrapper to avoid checking @show_context_selector manually.

Attributes

  • show - Boolean flag from @show_context_selector
  • All other attributes are passed to context_selector/1

Attributes

  • show (:boolean) - Defaults to false.
  • contexts (:list) (required)
  • current (:any) - Defaults to nil.
  • config (:any) (required)
  • class (:string) - Defaults to "".

mobile_context_selector(assigns)

Renders a mobile-friendly context selector for mobile menus.

Shows as a list section at the top of mobile navigation.

Attributes

  • contexts - List of context items
  • current - The currently selected context
  • config - The ContextSelector config struct

Attributes

  • contexts (:list) (required)
  • current (:any) - Defaults to nil.
  • config (:any) (required)

mobile_context_selector_if_enabled(assigns)

Conditionally renders the mobile context selector.

Attributes

  • show (:boolean) - Defaults to false.
  • contexts (:list) (required)
  • current (:any) - Defaults to nil.
  • config (:any) (required)