Reputation: 2827
Say I have Component <MyText />
. How can I style it differently based on different places it is implemented?
For instance, this is what I would want to do (using bootstrap classes for ease):
MyDocument.razor
<div> This text below will be red.</div>
<MyText class="text-danger" />
<div> This text below will be blue.</div>
<MyText class="text-info" />
Which would output the following
Upvotes: 1
Views: 553
Reputation: 14523
Take a look at Attribute splatting and arbitrary parameters
MyText.razor
<div @attributes="AdditionalAttributes">Some Cool Text</div>
@code {
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> AdditionalAttributes { get; set; }
}
MyDocument.razor
<div> This text below will be red.</div>
<MyText class="text-danger" />
<div> This text below will be blue.</div>
<MyText class="text-info" />
Upvotes: 2