hydrostack / hydro

Hydro brings stateful and reactive components to ASP.NET Core without writing JavaScript
https://usehydro.dev
MIT License
716 stars 17 forks source link

child content RenderFragments? #53

Closed adamfoneil closed 3 months ago

adamfoneil commented 3 months ago

This is just a question. I don't see this in the documentation. I have a Blazor component like this:

<div class="card m-4 p-2">
    <div class="card-body">
        <h5 class="card-title fw-bold">@Title</h5>
        @ChildContent
    </div>
</div>

@code {
    [Parameter]
    public string Title { get; set; } = string.Empty;

    [Parameter, EditorRequired]
    public RenderFragment ChildContent { get; set; } = default!;
}

Is there a way to pass markup as an argument to hydro component?

kjeske commented 3 months ago

Hi! If it's purely a presentational component (without interactions), then Hydro View could help:

@model Card 

<div class="card m-4 p-2">
    <div class="card-body">
        <h5 class="card-title fw-bold">@Model.Title</h5>
        @Model.Slot()
    </div>
</div>
public class Card : HydroView
{
    public string Title { get; set; } = string.Empty;
}

And usage:

<card title="My title">
  <p>
    Content of my card
  </p>
</card>

Does this solve your use case, or you need to pass the markup to Hydro Component instead of Hydro View?

adamfoneil commented 3 months ago

wow! yes that works for me!