IContentRenderHook
A content render hook (or a Component modifier as it's called in the Veva interface) is an "action" can be applied to components. It can be used to alter the look and behaviour of components. Veva includes a handful of Content render hooks that do anything from hiding components, adding padding/margins to components, applying animations to even modifying the actual content of components like adding soft hyphens in the right places. You can create your own content render hook by implementing the IContentRenderHook interface.
Interface declaration
public interface IContentRenderHook { void Invoke(RenderContext context, RenderTreeBuilder builder, Action<RenderTreeBuilder> next); }
Example
This example shows the implementation of the "CSS Class" component modifier which basically allows users to add any arbitrary CSS class names to components. You just need to implement the "Invoke" method and make sure you call next(builder) if you want the component to be rendered out.
[DisplayName("Css Class")] [Description("Allows you to apply custom CSS classes to the component")] public class ContainerClassHook : IContentRenderHook { [EditorBrowsable] [DisplayName("Css Classes")] [Parameter] [Editor(PropertyEditors.CssClassEditor, "")] public string ClassName { get; set; } public void Invoke(RenderContext context, RenderTreeBuilder builder, Action<RenderTreeBuilder> next) { if (!String.IsNullOrWhiteSpace(ClassName)) { context.CssClass.Add(ClassName); } next(builder); } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddNamed<IContentRenderHook, DisabledHook>(ServiceLifetime.Transient); }