Search documentation of phoenix_kit

# PhoenixKitWeb.Components.Dashboard.ContextSelector (phoenix_kit v1.7.87)

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

- `context_selector/1` - Header dropdown (for `position: :header` with `sub_position: :start` or `:end`)
- `sidebar_context_selector/1` - Sidebar dropdown (for `position: :sidebar`)
- `mobile_context_selector/1` - Mobile menu variant

## 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

context_selector(assigns)

Renders the context selector dropdown.

context_selector_if_enabled(assigns)

Conditionally renders the context selector based on visibility flag.

mobile_context_selector(assigns)

Renders a mobile-friendly context selector for mobile menus.

mobile_context_selector_if_enabled(assigns)

Conditionally renders the mobile context selector.

sidebar_context_selector(assigns)

Renders a context selector for the sidebar.

sidebar_context_selector_if_enabled(assigns)

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)

# sidebar_context_selector(assigns)

Renders a context selector for the sidebar.

Displays as a dropdown at the top of the sidebar navigation.

## 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 `""`.

# sidebar_context_selector_if_enabled(assigns)

Conditionally renders the sidebar context selector.

## Attributes

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