### Install Dependencies and Start Server
Source: https://context7.com/coingaming/moon/llms.txt
Install project dependencies, npm packages for assets, and start the Phoenix LiveView server.
```bash
mix deps.get
cd assets && npm i && cd -
iex -S mix phx.server
```
--------------------------------
### Start Phoenix server
Source: https://github.com/coingaming/moon/blob/main/README.md
Starts the Phoenix development server. This command should be run after installing dependencies.
```bash
iex -S mix phx.server
```
--------------------------------
### Install Nodejs with asdf
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs a specific version of Nodejs using asdf.
```bash
asdf install nodejs
```
--------------------------------
### Datepicker Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Demonstrates the Datepicker component for selecting date ranges, including setup in LiveView, template usage, time selection, and event handling.
```elixir
alias Moon.Components.Datepicker
# In LiveView mount
def mount(_params, _session, socket) do
{:ok,
assign(socket,
start_date: Timex.beginning_of_month(Timex.today()),
end_date: Timex.today()
)}
end
```
```elixir
# In template
```
```elixir
# With time selection
```
```elixir
# Handle the submit event
def handle_event("apply_dates", %{"start_date" => start_date, "end_date" => end_date}, socket) do
{start_date, end_date} = Datepicker.validate(start_date, end_date)
{:noreply, assign(socket, start_date: start_date, end_date: end_date)}
end
```
```elixir
# Programmatically close the picker
Datepicker.close(id: "report-datepicker")
```
--------------------------------
### Install Elixir with asdf
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs a specific version of Elixir using asdf.
```bash
asdf install elixir
```
--------------------------------
### Table Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Provides examples for the Table component, highlighting its use with configurable columns and sortable headers.
```elixir
alias Moon.Components.Table
alias Moon.Components.Table.Column # defined via slot
```
--------------------------------
### Install asdf Erlang Plugin
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs the Erlang plugin for asdf version manager. May require specific configuration options if installation fails.
```bash
asdf plugin add erlang
```
--------------------------------
### Install all tool versions with asdf
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs all tool versions specified in the .tool-versions file using asdf. This is a prerequisite for local development.
```bash
asdf install
```
--------------------------------
### Install asdf Nodejs Plugin
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs the Nodejs plugin for asdf version manager.
```bash
asdf plugin add nodejs
```
--------------------------------
### Get project dependencies
Source: https://github.com/coingaming/moon/blob/main/README.md
Fetches and installs project dependencies using Mix, the Elixir build tool.
```bash
mix deps.get
```
--------------------------------
### Install assets dependencies
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs Node.js dependencies for the assets directory. Ensure you are in the 'assets' directory before running.
```bash
cd assets && npm i && cd -
```
--------------------------------
### Select Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Illustrates the Select component for creating dropdowns, showing standalone usage, integration with Phoenix forms, and disabled states.
```elixir
alias Moon.Components.Select
# Standalone select with label
```
```elixir
# Inside a Phoenix form
```
```elixir
# Disabled select
```
--------------------------------
### Install asdf Elixir Plugin
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs the Elixir plugin for asdf version manager.
```bash
asdf plugin add elixir
```
--------------------------------
### Install Erlang with asdf
Source: https://github.com/coingaming/moon/blob/main/README.md
Installs a specific version of Erlang using asdf. Refer to the asdf-erlang plugin documentation for troubleshooting.
```bash
asdf install erlang
```
--------------------------------
### Popover Component Setup
Source: https://context7.com/coingaming/moon/llms.txt
Initializes the Popover component in a LiveView. Requires a boolean assign to control its open state.
```elixir
alias Moon.Components.Popover
alias Moon.Components.Button
# In LiveView
def mount(_params, _session, socket) do
{:ok, assign(socket, popover_open: false)}
end
```
--------------------------------
### Avatar Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Demonstrates different configurations for the Avatar component, including image-based, initials-based, status indicators, and size variations.
```elixir
```
```elixir
```
```elixir
```
```elixir
```
```elixir
```
--------------------------------
### Breadcrumb Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Shows how to use the Breadcrumb component for navigation, illustrating both short and long trails that auto-collapse.
```elixir
alias Moon.Components.Breadcrumb
```
```elixir
alias Moon.Components.Breadcrumb
```
--------------------------------
### Moon Button Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Demonstrates various configurations for the Moon Button component, including variants, sizes, icons, and animations. Use `on_click` for LiveView events and `value` to pass data.
```elixir
defmodule MyAppWeb.DemoLive do
use MyAppWeb, :live_view
alias Moon.Components.Button
def render(assigns) do
~H"""
<%!-- Primary button (default) --%>
<%!-- Secondary button with left icon --%>
<%!-- Ghost button, full width --%>
<%!-- Button with loading animation --%>
<%!-- Button with success animation --%>
<%!-- Icon-only button --%>
<%!-- Button passing a value on click --%>
"""
end
def handle_event("handle_save", _params, socket), do: {:noreply, socket}
def handle_event("select_item", %{"item_id" => id}, socket) do
{:noreply, assign(socket, :selected_id, id)}
end
end
```
--------------------------------
### Moon Avatar Component Setup
Source: https://context7.com/coingaming/moon/llms.txt
Imports necessary components for the Moon Avatar component, including `Avatar` and `Avatar.StatusOrigin`.
```elixir
alias Moon.Components.Avatar
alias Moon.Components.Avatar.StatusOrigin
```
--------------------------------
### Chip Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Illustrates the usage of the Chip component for interactive filters or tags, including variations with icons, sizes, and variants.
```elixir
alias Moon.Components.Chip
Active
```
```elixir
alias Moon.Components.Chip
Date Range
```
```elixir
alias Moon.Components.Chip
```
```elixir
Selected
```
--------------------------------
### Example TextInput component with icons
Source: https://github.com/coingaming/moon/blob/main/README.md
Demonstrates the usage of the Moon TextInput component with left and right icons. The right icon includes an 'on_click' event handler.
```elixir
alias Moon.Components.TextInput
alias Moon.Assets.Icons.IconCloseRounded
alias Moon.Assets.Icons.IconZoom
<:left_icon>
<:right_icon>
```
--------------------------------
### Generated Component Template Structure
Source: https://context7.com/coingaming/moon/llms.txt
Example structure for a generated stateless component. Includes prop declarations, slot usage, and rendering logic.
```elixir
defmodule Moon.Design.Form.SomethingAwesome do
use Moon.StatelessComponent
# Declare typed props
prop(label, :string)
prop(class, :css_class)
slot(default)
def render(assigns) do
~F"""
<#slot />
"""
end
end
```
--------------------------------
### Loader Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Showcases different size and color variants of the Loader component, including its use within a conditional rendering block.
```elixir
alias Moon.Components.Loader
# Default medium loader in hit color
```
```elixir
# Small loader in piccolo (brand) color
```
```elixir
# Large loader in roshi (success) color
```
```elixir
# Loader inside a loading state panel
```
--------------------------------
### Moon Accordion Component Examples
Source: https://context7.com/coingaming/moon/llms.txt
Showcases the Moon Accordion component with different sizes, states (open/closed, disabled), and content structures. Uses client-side JS commands for toggling.
```elixir
alias Moon.Components.Accordion
# Basic accordion, closed by default
<:title>What is Moon Design System?
<:content>
Moon is a component-based design system built with Surface and Tailwind CSS.
# Pre-opened accordion with large size and extra header content
<:title>Advanced Settings
<:header_content>
3 items
<:content>
```
--------------------------------
### Run Test Suite
Source: https://github.com/coingaming/moon/blob/main/CONTRIBUTING.md
Execute the project's test suite using this command. Ensure all tests pass before submitting a pull request. New components should also include corresponding tests.
```sh
mix test
```
--------------------------------
### Generate New Component
Source: https://github.com/coingaming/moon/blob/main/CONTRIBUTING.md
Use this command to generate a new component, including its page and router/menu integration instructions. Ensure the component name follows the 'Namespace.SubNamespace.ComponentName' format.
```sh
mix moon.gen.component Form.SomethingAwesome
```
--------------------------------
### Popover Component Usage
Source: https://context7.com/coingaming/moon/llms.txt
Demonstrates how to use the Popover component with content and event handlers for toggling and closing.
```elixir
<:content>
```
```elixir
def handle_event("toggle_popover", _, socket) do
{:noreply, assign(socket, popover_open: !socket.assigns.popover_open)}
end
```
```elixir
def handle_event("close_popover", _, socket) do
{:noreply, assign(socket, popover_open: false)}
end
```
--------------------------------
### Basic Table Component
Source: https://context7.com/coingaming/moon/llms.txt
Renders a table with specified columns and handles row clicks and sorting. Requires item data and event handlers for sorting and selection.
```elixir
```
--------------------------------
### Add Moon to Project Dependencies
Source: https://context7.com/coingaming/moon/llms.txt
Add Moon, Surface, and Phoenix LiveView to your project's dependencies in `mix.exs`.
```elixir
defp deps do
[
{:moon, "~> 2.91"},
{:surface, "~> 0.11.0"},
{:phoenix_live_view, "~> 0.20"}
]
end
```
--------------------------------
### Register Moon Components with Surface
Source: https://context7.com/coingaming/moon/llms.txt
Register Moon components for use with Surface UI in `config/surface.exs`.
```elixir
import Config
config :surface, :components, []
```
--------------------------------
### Autolayout Components Imports
Source: https://context7.com/coingaming/moon/llms.txt
Imports for Moon's autolayout components, including TopToDown, LeftToRight, and PullAside.
```elixir
alias Moon.Autolayouts.TopToDown
alias Moon.Autolayouts.LeftToRight
alias Moon.Autolayouts.PullAside
```
--------------------------------
### Form Component for Registration
Source: https://context7.com/coingaming/moon/llms.txt
Demonstrates the Moon Form component wrapping Select and Checkbox inputs, with event handlers for validation and submission.
```elixir
alias Moon.Components.Form
alias Moon.Components.Select
alias Moon.Components.Checkbox
```
```elixir
def handle_event("validate_form", %{"user" => params}, socket) do
changeset = User.changeset(%User{}, params) |> Map.put(:action, :validate)
{:noreply, assign(socket, changeset: changeset)}
end
```
```elixir
def handle_event("submit_form", %{"user" => params}, socket) do
case Accounts.create_user(params) do
{:ok, _user} -> {:noreply, push_navigate(socket, to: "/dashboard")}
{:error, changeset} -> {:noreply, assign(socket, changeset: changeset)}
end
end
```
--------------------------------
### Drawer Component Usage
Source: https://context7.com/coingaming/moon/llms.txt
Implements a side-panel drawer using Moon.Components.Drawer. The Drawer.Dialog submodule structures the content within the drawer. Visibility is controlled by a boolean assign.
```elixir
alias Moon.Components.Drawer
alias Moon.Components.Drawer.Dialog
alias Moon.Components.Button
# In LiveView
def mount(_params, _session, socket) do
{:ok, assign(socket, show_drawer: false)}
end
# In template
```
--------------------------------
### Drawer Event Handlers
Source: https://context7.com/coingaming/moon/llms.txt
Handles opening and closing the drawer component. Updates the 'show_drawer' assign to control the drawer's visibility.
```elixir
def handle_event("open_drawer", _, socket), do: {:noreply, assign(socket, show_drawer: true)}
def handle_event("close_drawer", _, socket), do: {:noreply, assign(socket, show_drawer: false)}
```
--------------------------------
### ProgressLinear Component Usage
Source: https://context7.com/coingaming/moon/llms.txt
Illustrates the ProgressLinear component for displaying progress, including static values and dynamic binding to LiveView state.
```elixir
alias Moon.Components.ProgressLinear
# 60% progress
```
```elixir
# Dynamic progress bound to LiveView state
{@upload_progress}% uploaded
```
```elixir
# Handle progress updates
def handle_info({:upload_progress, pct}, socket) do
{:noreply, assign(socket, upload_progress: pct)}
end
```
--------------------------------
### Configure Tailwind CSS for Moon
Source: https://context7.com/coingaming/moon/llms.txt
Configure Tailwind CSS in `assets/tailwind.config.js` to include Moon's design tokens and presets.
```javascript
module.exports = {
content: ["../lib/**/*.ex", "../lib/**/*.heex"],
presets: [require("./ds-moon-preset")], // Moon design tokens
plugins: [require("@tailwindcss/forms")],
};
```
--------------------------------
### Checkbox Component Integration
Source: https://context7.com/coingaming/moon/llms.txt
Shows how to use the Checkbox component within a Surface Form for form context integration and standalone with click events.
```elixir
alias Moon.Components.Checkbox
alias Moon.Components.Form
# Inside a Surface Form
```
```elixir
# Standalone with click event
```
```elixir
def handle_event("toggle_remember", _params, socket) do
{:noreply, assign(socket, remember_me: !socket.assigns.remember_me)}
end
```
--------------------------------
### Pagination Component Usage
Source: https://context7.com/coingaming/moon/llms.txt
Integrates the Pagination component in a LiveView template. Requires current and total page numbers, and an event handler for page changes.
```elixir
alias Moon.Components.Pagination
# In LiveView mount
def mount(_params, _session, socket) do
{:ok, assign(socket, current_page: 1, total_pages: 20)}
end
# In template
```
--------------------------------
### Format code with Mix and Surface
Source: https://github.com/coingaming/moon/blob/main/README.md
Formats Elixir code using Mix and Surface formatters. This ensures consistent code style across the project.
```bash
mix format
```
```bash
mix surface.format
```
--------------------------------
### Modal Dialog Event Handlers
Source: https://context7.com/coingaming/moon/llms.txt
Manages the modal's visibility and actions. Handles opening, closing, and confirming deletion, updating the 'show_modal' assign accordingly.
```elixir
# Handle events
def handle_event("open_modal", _, socket), do: {:noreply, assign(socket, show_modal: true)}
def handle_event("close_modal", _, socket), do: {:noreply, assign(socket, show_modal: false)}
def handle_event("confirm_delete", _, socket) do
# perform delete...
{:noreply, assign(socket, show_modal: false)}
end
```
--------------------------------
### Pagination Event Handler
Source: https://context7.com/coingaming/moon/llms.txt
Handles the 'go_to_page' event from the Pagination component. Updates the current page number in the socket assigns.
```elixir
def handle_event("go_to_page", %{"page" => page}, socket) do
page = String.to_integer(page)
{:noreply, assign(socket, current_page: page)}
end
```
--------------------------------
### PullAside Two-Column Layout Component
Source: https://context7.com/coingaming/moon/llms.txt
Creates a two-column layout where the left column can grow to fill space. Accepts left_grow and class attributes.
```html
<:left>
Subscription Plan
<:right>
```
--------------------------------
### TopToDown Vertical Stack Component
Source: https://context7.com/coingaming/moon/llms.txt
Used for creating vertical stacks with configurable gaps. Accepts gap and class attributes.
```html
Dashboard
Your metrics at a glance.
```
--------------------------------
### Table Event Handlers
Source: https://context7.com/coingaming/moon/llms.txt
Handles 'sort_table' and 'select_user' events for the Table component. Updates socket assigns for sorting direction and selected user.
```elixir
def handle_event("sort_table", %{"sort-key" => key, "sort-dir" => dir}, socket) do
{:noreply, assign(socket, sort_key: key, sort_dir: dir)}
end
def handle_event("select_user", %{"selected" => id}, socket) do
{:noreply, assign(socket, selected_user_id: id)}
end
```
--------------------------------
### Modal Dialog Component Usage
Source: https://context7.com/coingaming/moon/llms.txt
Implements a modal dialog using Moon.Components.Dialog.Modal. Controls visibility via a boolean assign and uses named slots for title, content, and footer.
```elixir
alias Moon.Components.Dialog.Modal
alias Moon.Components.Button
# In LiveView
def mount(_params, _session, socket) do
{:ok, assign(socket, show_modal: false)}
end
# In template
<:title>Confirm Delete
<:content>
Are you sure you want to delete this item? This action cannot be undone.
<:footer>
```
--------------------------------
### LeftToRight Horizontal Row Component
Source: https://context7.com/coingaming/moon/llms.txt
Used for creating horizontal rows. Accepts class attributes for alignment.
```html
Alex Lee
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.