Confinity Documentation
  • Latest Version
  • Latest Version
  • Getting Started

    • Introduction
    • Core Concepts
    • Create an Application
    • Glossary
  • Essentials

    • Authentication & SSO
    • Breaking Changes
    • Roslyn Source Analyzers
    • Changelog
    • ConfinityContent
    • ConfinitySelectable
    • Confinity Schedules
    • Data Seeding
    • Development guidelines [WIP]
    • Entity App
    • Entity Form
    • Entity Permissions
    • Frontend Configuration
    • Images
    • Known Issues
    • Localization
    • Migrations
    • Modules [WIP]
    • On-Site Editing
    • Settings
    • Cascade Delete
    • Replication
    • Infrastructure
  • Modules

    • Analytics Module
    • Assets Module
    • Blog Module
    • Cookie Consent Module
    • Forms Module
    • Friendly Captcha (Forms Module )
    • GeoIP Module
    • Htmx
    • Mail Module
    • Mailing Module
    • MediaPlayer Module
    • GoogleMyBusiness Module
    • OpenTelemetry Module
    • Pages Module [WIP]
    • Pattern Library Module
    • SIX Saferpay (worldline) Module
    • Products Module
    • Search Module
    • Wizard Module
  • Guides

    • Create a Custom Entity App Form Element
    • Date and Time
    • Entity Change Listener
    • File Upload / Temp File
    • HTTP security headers
    • conventions [WIP]
    • How to use Confinity with nginx
    • Notifications
    • Nullability
    • Rename Entity
    • Schedules
    • Useful snippets
    • Content Localization
  • Design Guidelines

    • Introduction
    • Page Components
    • Forms Module

Pattern Library Module

The pattern library module allows developers to test different configurations of a component. This is similar to the well known storybook tool.

It is advised to add the module only for development configurations for example like:


if (builder.Environment.IsDevelopment())
{
    moduleBuilder.AddModule<PatternLibraryModule>();
}

When the module is added, the pattern library is available as page component or can be reached at /.mod/api/confinity-pattern-library.

In order to see your components you must provide a valid configuration. This can be done by implementing IConfinityContentConfiguration<T> which has the attribute [PatternLibraryArea()]. In addition, a placeholder page must be configured for this component. To test all possible layouts. This should be done for each layout.

Configuration


services.Configure<PatternLibraryOptions>(options =>
{
    // the link to the idea ide sometimes needs path fixing when the project is in a sub-folder.
    options.ViewPrefix = (assembly) => "src/DocsDemo/" + assembly?.GetName().Name;

    // maps the Pattern Library controller
    options.MapRoute = true;

    // Add startup actions wich run once on startup. This can be used to generate links to each configuration.
    // This is often used for automated accessibility testing or ui regression tests.
    options.StartupActions.Add((tests) =>
    {
        // File.WriteAllText("...");
    });
});

Example

Component


[ConfinityLabel("Image Component")]
public sealed class TitleComponentModel : PageComponentModel, IConfinityContentConfiguration<TitleComponentModel>
{
    public required string Title { get; set; } = "";

    public void Configure(IConfinityContentBuilder<TitleComponentModel> builder)
    {
        builder
            .Description("An example title component")
            .Icon(Icon.H1)
            .Editor(e =>
            {
                e.AddTab(tab =>
                {
                    tab.AddInput(x => x.Title)
                        .Label("Heading")
                        .Comment("Some helpful text to this property.")
                        .Validate(v => v.NotEmpty());
                });
            });
    }
}

Pattern Library Configuration


[PatternLibraryArea("My Layout")]
public class TitleComponentModelPatternLibrary : IPatternLibraryComponent
{
    public string Label() => "Title";

    public IEnumerable<Item> ComponentConfigurations()
    {
        yield return new ConfinityContentItem("short title", new TitleComponentModel() { Title = "Welcome!" });
        yield return new ConfinityContentItem("long title",
            new TitleComponentModel()
            {
                Title =
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut " +
                    "labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
                    "laboris nisi ut aliquip ex ea commodo consequat. "
            });
    }
}

Prev
Pages Module [WIP]
Next
SIX Saferpay (worldline) Module