# Components

The majority of components come from our open-source package "[Petal Components](https://github.com/petalframework/petal_components)". However, there are some only in Petal Pro. Ultimately, petal.build will house all docs related to components, and these guides will more tailored to Petal Pro core functionality.

### Layouts

[Docs](https://petal.build/components/layouts) are on petal.build.

### Brand

See the [Branding section](https://docs.petal.build/petal-pro-documentation/v2.2.0/fundamentals/branding).

### Color scheme switch

```markup
<.color_scheme_switch />
```

The switch to switch between light and dark mode.&#x20;

Note that for this to work you also need to add this to your `<head>` . This is installed by default in Petal Pro.

```phoenix-heex
# in your <head>:
<.color_scheme_switch_js />
```

### Email helpers

A set of components for email templates. Kind of like Petal Components, but for emails.

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/FHOT0iUMQPHnB1UOQx6J/image.png)

Example usage:

```markup
<h1>Let's verify your account</h1>

<p>Touch the button below to verify your account</p>

<EmailComponents.button_centered to={@url}>
  Verify account
</EmailComponents.button_centered>

<EmailComponents.small_text>
  If you didn't create an account with us, please ignore this.
</EmailComponents.small_text>
```

If you want to add your own components, you can edit the following file:

```bash
/lib/petal_pro_web/components/email_components.ex
```

Then add your components:

```elixir
defmodule PetalPro.Components.EmailComponents do
  use Phoenix.Component
  
  def my_new_component(assigns) do
    ~H"""
    Your component HTML goes here
    """
  end
end
```

Now it'll be available in your email templates!

```markup
<h1>Let's verify your account</h1>

<.my_new_component />
```

### Landing page

A set of landing page related components. For example:

```
<LandingPage.features
  title={gettext("Features")}
  description={gettext("Here are some features you can use to get started with your web app.")}
  features={
    [
      %{
        title: "Authentication",
        description: Faker.Lorem.sentence(10..20),
        icon: :lightning_bolt
      },
      %{
        title: "HTML Emails",
        description: Faker.Lorem.sentence(10..20),
        icon: :puzzle
      },
      %{
        title: "Wallaby testing",
        description: Faker.Lorem.sentence(10..20),
        icon: :at_symbol
      }
    ]
  }
/>
```

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/joO9k6LUReTrX4aAjiwl/CleanShot%202022-05-26%20at%2013.40.33.png)

### Language select

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/7f3Tr2uMJZkFyaVdGFCz/image.png)

A dropdown for setting your language.

```markup
<.language_select
  current_locale={Gettext.get_locale(PetalProWeb.Gettext)}
  language_options={PetalPro.config(:language_options)}
/>
```

This is a Petal Pro component. If you want to see how it's coded or modify it to your own needs you can edit this file:

```bash
/lib/petal_pro_web/components/pro_components/language_select.ex
```

Language options are set in your config.exs:

```elixir
config :petal_pro, :language_options, [
  %{locale: "en", flag: "🇬🇧", label: "English"},
  %{locale: "fr", flag: "🇫🇷", label: "French"}
]
```

See [translations](https://docs.petal.build/petal-pro-documentation/v2.2.0/fundamentals/translations) for more info.

### Notification

A flash notification component defined in Petal Pro. See [docs](https://petal.build/components/flash).

![The top dark bit is an animated bar that progresses to the right hand corner, then the box disappears](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/LrEbl3hEHi66VcVI12oa/image.png)

This comes from `flash_group/1` set in your layout:

{% code title="app.htm.heex" %}

```phoenix-heex
<.flash_group flash={@flash} />
```

{% endcode %}

To see the implementation:

```bash
/lib/petal_pro_web/components/pro_components/flash.ex
```

### Page components

A set of generic page components to help with building pages. To see a list of them:

```bash
/lib/petal_pro_web/components/pro_components/page_components.ex
```

#### Box

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/xVkhko2vizlFQsAJnX5w/CleanShot%202022-05-26%20at%2013.58.45.png)

```markup
<.box padded>
  <%= live_component(PetalProWeb.OrgFormComponent, [...]) %>
</.box>
```

#### Page header

Shows a heading and optional slot for buttons on the right hand side.

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/28HtK8D1YJpRGkJv3PqJ/CleanShot%202022-05-26%20at%2014.06.30.png)

```markup
<.page_header title="Listing Discounts">
  <.button
    link_type="live_patch"
    label="New Discount"
    to={Routes.discount_index_path(@socket, :new)}
  />
</.page_header>
```

#### Sidebar tabs container

A panel with a sidebar for a menu, and a slot for content on the right.

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/A8GgxijWiM4Fs2f3sSBl/CleanShot%202022-05-26%20at%2014.10.41.png)

```markup
<.sidebar_tabs_container current_page={:edit_profile} menu_items={[
  %{
    name: :edit_profile,
    label: gettext("Edit profile"),
    path: Routes.live_path(Endpoint, PetalProWeb.EditProfileLive),
    icon: :user_circle
  },
  ...
]}>
  <%= render_slot(@inner_block) %>
</.sidebar_tabs_container>
```

### User dropdown menu

A Petal Pro component. Displays the user's avatar and will show a dropdown menu upon being clicked. Used in the navbar. Displays a list of menu items (see the [Menus section](https://docs.petal.build/petal-pro-documentation/v2.2.0/layouts-and-menus#menus)).

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/YrusAmnpHkBKRtnK80Z7/image.png)

```markup
<.user_menu_dropdown
  user_menu_items={@user_menu_items}
  avatar_src={@avatar_src}
  current_user_name={if @current_user, do: user_name(@current_user), else: nil}
/>
```

To see the implementation:

```bash
/lib/petal_pro_web/components/pro_components/user_dropdown_menu.ex
```

### Markdown

#### Pretty markdown

Renders the markdown as HTML and uses the [Tailwind Typography](https://tailwindcss.com/docs/typography-plugin) classes to prettify it.

```markup
<.pretty_markdown content={some_markdown} class="mx-auto" />
```

To see the implementation:

```bash
/lib/petal_pro_web/components/pro_components/markdown.ex
```

#### Markdown

Simple renders pure HTML from markdown.

```markup
<.markdown content={some_markdown} />
```

### Social Button

![](https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/TDyBno17pSYoAvmmo1RJ/CleanShot%202022-05-26%20at%2014.20.19.png)

```markup
<.social_button
  link_type="a"
  to={Routes.user_ueberauth_path(@conn_or_socket, :request, "google")}
  variant="outline"
  logo="google"
  class="w-full"
/>

<.social_button
  link_type="a"
  to={Routes.user_ueberauth_path(@conn_or_socket, :request, "github")}
  variant="outline"
  logo="github"
  class="w-full"
/>
```

This is a Petal Pro component. To see its implementation:

```bash
/lib/petal_pro_web/components/pro_components/social_button.ex
```
