-
Notifications
You must be signed in to change notification settings - Fork 0
Data Builders
Jamie Pollock edited this page Jan 16, 2024
·
5 revisions
Rhythm Drops comes with a collection of fluent data builders. These provide common data building tasks which can also be extended for specific use cases.
The use of these data builders is completely optional and not required for rendering common models using Tag Helpers.
Each builder can be injected by DI.
Builder: IImageBuilder
An image with dimensions
var image = _imageBuilder
.WithAltText("My Image")
.AndUrl("/my-image.jpg")
.AddDimensions(600, 400)
.Build();An image with sources
List<IImageSource> imageSources =
[
new ImageSource("/my-image-xs.jpg", new MinMaxWidthRangeImageSourceMediaQuery(default, 575)),
new ImageSource("/my-image-s.jpg", new MinMaxWidthRangeImageSourceMediaQuery(576, 767)),
new ImageSource("/my-image-m.jpg", new MinMaxWidthRangeImageSourceMediaQuery(768, 991)),
new ImageSource("/my-image-l.jpg", new MinMaxWidthRangeImageSourceMediaQuery(992, default))
];
var image = _imageBuilder
.WithAltText("My Image")
.AndUrl("/my-image-fallback.jpg")
.AddDimensions(600, 400)
.AddSources(imageSources)
.Build();Builder: ILinkBuilder
An anchor link
var link = _linkBuilder
.WithUrl("/my-link")
.AndLabel("Click Here")
.Build();An anchor with additional attributes
var link = _linkBuilder
.WithUrl("https://some.other/link")
.AndLabel("Click Here")
.SetAttribute("target", "_blank")
.SetAttribute("rel", "noopener")
.Build();
A modal link
IModal modal = CreateModalContent();
var link = _linkBuilder
.WithModal(modal)
.AndLabel("Click Here")
.Build();
A modal link with attributes
IModal modal = CreateModalContent();
var link = _linkBuilder
.WithModal(modal)
.AndLabel("Click Here")
.SetAttribute("data-link-type", "modal")
.Build();