Packages
phoenix_duskmoon
9.0.0-rc.2
9.9.2
9.9.1
9.9.0
9.8.0
9.7.1
9.7.0
9.6.4
9.6.3
9.6.2
9.6.1
9.6.0
9.5.4
9.5.3
9.5.2
9.5.1
9.5.0
9.4.3
9.4.2
9.4.1
9.4.0
9.3.0
9.2.0
9.1.4
9.1.3
9.1.1
9.1.1-rc.1
retired
9.0.1
9.0.0-rc.3
9.0.0-rc.2
9.0.0-rc.1
8.0.0
7.2.1
7.2.0
7.1.3
7.1.2
7.1.1
6.3.2
6.3.1
6.3.0
6.2.0
6.1.3
6.1.2
6.1.1
6.1.0
6.0.10
6.0.9
6.0.8
6.0.7
6.0.6
6.0.5
6.0.4
6.0.3
6.0.2
6.0.1
6.0.0
5.2.0-beta.5
5.2.0-beta.4
5.2.0-beta.3
5.2.0-beta.2
5.2.0-beta.1
5.1.0
5.0.6
5.0.5
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.2
4.5.1
4.5.0
4.4.4
4.4.3
4.4.2
4.4.1
4.4.0
4.3.2
4.3.1
4.3.0
4.2.0
4.1.1
4.1.0
4.0.0
Duskmoon UI component library for Phoenix LiveView
Current section
Files
Jump to
Current section
Files
lib/phoenix_duskmoon/css_art/eclipse.ex
defmodule PhoenixDuskmoon.CssArt.Eclipse do
@moduledoc """
Animated eclipse visual effect component.
## Examples
<.dm_art_eclipse
id="eclipse-1"
size="medium"
bg_color="#09090b"
class="mx-auto"
/>
<.dm_art_eclipse
id="eclipse-2"
size="large"
bg_color="#000000"
animation_speed="slow"
/>
## Attributes
* `id` - Component ID (required)
* `size` - Size preset: small (400px), medium (600px), large (800px) (default: medium)
* `bg_color` - Background color of the eclipse (default: "#09090b")
* `animation_speed` - Animation speed multiplier (default: 1.0)
* `class` - Additional CSS classes
## Styling
This component uses the `dm-art-eclipse` CSS class from the eclipse.css file.
It creates a beautiful animated eclipse effect with multiple rotating layers
that create a celestial eclipse visualization.
The animation consists of 6 layers with different rotation speeds and directions:
- Layer 1: Fast forward rotation (30s base)
- Layer 2: Medium reverse rotation (20s base)
- Layer 3: Medium forward rotation (20s base)
- Layer 4: Slow reverse rotation (40s base)
- Layer 5: Slow forward rotation (40s base)
- Layer 6: Static background layer with gradient effects
"""
use Phoenix.Component
@doc """
Renders an animated eclipse visual effect with multiple rotating layers.
## Examples
<.dm_art_eclipse id="eclipse" size="medium" />
"""
@doc type: :component
attr(:id, :string, required: true)
attr(:size, :string, default: "medium", values: ["small", "medium", "large"])
attr(:bg_color, :string, default: "#09090b")
attr(:animation_speed, :float, default: 1.0)
attr(:class, :any, default: nil)
attr(:rest, :global)
def dm_art_eclipse(assigns) do
speed = assigns.animation_speed |> to_float() |> max(0.01)
assigns
|> assign(size_px: size_to_pixels(assigns.size))
|> assign(
layer_1_duration: round(30 / speed),
layer_2_duration: round(20 / speed),
layer_3_duration: round(20 / speed),
layer_4_duration: round(40 / speed),
layer_5_duration: round(40 / speed)
)
|> render_eclipse()
end
defp render_eclipse(assigns) do
~H"""
<div
id={@id}
class={[
"dm-art-eclipse",
@class
]}
style={"--size: #{@size_px}px; --bg-color: #{@bg_color};"}
aria-hidden="true"
{@rest}
>
<!-- Layer 1: Fast rotating layer -->
<div
class="layer layer-1"
style={"animation-duration: #{@layer_1_duration}s"}
></div>
<!-- Layer 2: Medium reverse rotating layer -->
<div
class="layer layer-2"
style={"animation-duration: #{@layer_2_duration}s"}
></div>
<!-- Layer 3: Medium forward rotating layer -->
<div
class="layer layer-3"
style={"animation-duration: #{@layer_3_duration}s"}
></div>
<!-- Layer 4: Slow reverse rotating layer -->
<div
class="layer layer-4"
style={"animation-duration: #{@layer_4_duration}s"}
></div>
<!-- Layer 5: Slow forward rotating layer -->
<div
class="layer layer-5"
style={"animation-duration: #{@layer_5_duration}s"}
></div>
<!-- Layer 6: Static background layer with complex gradients -->
<div class="layer layer-6"></div>
</div>
"""
end
defp size_to_pixels("small"), do: 400
defp size_to_pixels("medium"), do: 600
defp size_to_pixels("large"), do: 800
defp to_float(v) when is_float(v), do: v
defp to_float(v) when is_integer(v), do: v * 1.0
defp to_float(v) when is_binary(v) do
case Float.parse(v) do
{f, _} -> f
:error -> 1.0
end
end
end