Understanding Component Contract Html Basics and Best Practices

Author

Reads 939

Focused view of a person highlighting text in a contract document on a wooden office desk.
Credit: pexels.com, Focused view of a person highlighting text in a contract document on a wooden office desk.

Component Contract HTML is a crucial aspect of building robust and maintainable front-end code. It ensures that components are self-contained and communicate effectively with their surroundings.

A component contract defines the expected input and output of a component, making it easier to reuse and maintain. This includes the props, events, and state that a component relies on.

By establishing clear boundaries, component contracts prevent components from making assumptions about their environment. This leads to fewer bugs and easier debugging.

A well-defined component contract also enables better collaboration among developers, as it provides a clear understanding of how components interact.

Contract Basics

A UI component must follow the component contract to be exposed through the Visual Builder user interface. This contract has four aspects: properties, events, child slots, and methods.

The component contract ensures that all components, whether shipped by Visual Builder, provided by a partner, or created by you, can be used consistently. By following this contract, you can add functionality to a component and express the new functionality in its interface.

Credit: youtube.com, Contract Basics (Part 1) | Real Estate Exam Prep Videos

A component has properties that can be bound to variables or expressions through the Visual Builder user interface. These properties can affect the state of a component or its rendering. There are two kinds of properties: one-way and two-way.

Here are the key differences between one-way and two-way properties:

The Contract

The Contract is the foundation of building UI components in Visual Builder. It's a set of rules that ensures components can be easily integrated and used within the Visual Builder user interface.

A UI component must follow the same contract, whether it's shipped by Visual Builder, provided by a partner, or created by you. This contract has four key aspects: properties, events, child slots, and methods.

Properties are a crucial part of the contract, and they can be bound to variables or expressions using the Visual Builder user interface. A component property has a specific type, which matches the types available for a variable.

For another approach, see: Html Component Library

Credit: youtube.com, Elements of a Contract

There are two kinds of properties: one-way and two-way. One-way properties are read-only, meaning the component reads the value of this property. Two-way properties, on the other hand, can be read and written to, and if the variable is modified externally, the component will be notified of this change.

Here are the key differences between one-way and two-way properties:

Methods are another important aspect of the contract, and they can be used to perform actions on a component, such as calling a method to flip a card. These methods may have parameters that are defined as part of the component interface.

Test

Testing is a crucial part of any development process, and it's essential to understand the basics of contract testing.

Ideally, your test results should be verifiable via code coverage numbers. This means that you should be able to measure the percentage of your code that's being executed during testing.

A different take: Html Tag B

Credit: youtube.com, Contract Basics (Part 4) NonPerfomance of Parties | Real Estate Exam Prep Videos

To ensure your tests are comprehensive, make sure to fully exercise the Web Component's ViewModel. This includes testing all its properties and property values.

You should also test the HTML view, including any DOM branches that might be conditionally rendered, and test all slots with and without default content.

In addition to testing the ViewModel and HTML view, you should also test the Web Component's properties and property values, events, methods, accessibility, and security.

Take a look at this: Html Value Property

Component Structure

The component structure is made up of several key parts. These include the component itself, which is the main unit of code that makes up the component, and the template, which is the HTML structure that defines the component's layout.

The component contract is a set of rules that defines how the component should be used and interacted with. This contract is typically defined through a set of attributes and properties that are exposed by the component.

A component's structure is defined by its root element, which is the top-level HTML element that contains all the other elements that make up the component. This root element is typically defined in the template.

Child Slots

Credit: youtube.com, #6 - Scoped Slots | Vue 2 Components, Beginners tutorial

A slot is a placeholder inside a web component that you can fill with your own markup.

You can have zero or more slots in a component, and each slot can hold one or more children. Any children not assigned to a specific slot are assigned to the default slot.

Slots are used as placeholders in a web component that users can fill in with their own markup.

In the example of the demo-columns web component, an oj-bind-slot named columnA is defined.

Curious to learn more? Check out: Html Slot

IDs and Styles

IDs and Styles play a crucial role in making your components more flexible and customizable.

A component can have a configurable ID to allow it to be referenced from an action, giving you more control over how they interact with each other.

This means you can easily access and manipulate components based on their unique IDs.

In addition to IDs, you can also bind component style classes to an expression, allowing you to dynamically change the appearance of your components based on specific conditions.

Expand your knowledge: Html Based on Ux Design

Create

Credit: youtube.com, Godot Components - how to structure a game into manageable parts (Beginner/Intermediate)

To create custom Web Components, you can use Oracle JET. Oracle JET supports a variety of custom Web Component component types.

Before diving in, make sure you're familiar with installing the Oracle JET CLI, which you can learn about in the "Install Oracle JET Tooling" section. You should also be familiar with adding a Web Component to an Oracle JET app using the Oracle JET CLI, which is explained in the "Understand the Web App Workflow" section.

Oracle JET has a list of reserved names for Web Components that are not available for use. You can find this list in the "valid custom element name" section.

When creating Web Components, you'll want to be aware of the list of existing Web Component properties, events, and methods. This information can be found in the "HTMLElement properties, event listeners, and methods" section.

To create a set of Web Components that can be used together, you can create a JET Pack. JET Packs allow you to assemble sets of Web Components.

Take a look at this: Visual Studio Code Preview Html

Schema Versioning

Credit: youtube.com, Schema Versioning

Schema versioning is a crucial aspect of component structure, and it's essential to get it right to avoid coupling problems.

The WC3 Technical Architecture Group (TAG) has identified several versioning strategies, ranging from the overly liberal "none" to the exceedingly conservative "big bang".

Both extremes have problems that inhibit business value delivery and increase system costs.

Explicit and implicit "no versioning" strategies result in unpredictable, fragile, and costly systems.

Big bang strategies, on the other hand, lead to tightly coupled service landscapes that disrupt uptime, hinder evolution, and reduce revenue opportunities.

Our example service community implements a big bang strategy, which isn't ideal for delivering business value and reducing costs.

A more flexible versioning strategy, called a compatible strategy, provides for backwards- and forwards-compatible schemas.

Backwards-compatible schemas enable consumers to accept older schema instances, while forwards-compatible schemas allow consumers to process newer schema instances.

If the search result schema had been made forwards-compatible when first put into production, the consumers would be able to handle instances of the new version without breaking or requiring modification.

This approach would have greatly benefited the existing ProductSearch consumers, allowing them to handle instances of the new search result version without issues.

Customization

Credit: youtube.com, The New selectedcontent HTML Element Changes Selects Forever

Customization is key to making your component contract HTML truly shine. This can be achieved by adjusting the template to fit your specific needs.

The HTML template can be customized to include or exclude certain elements, such as the header, footer, or navigation menu. For example, you can remove the navigation menu if you don't need it.

Customization also extends to the layout and design of the contract. By using CSS, you can change the colors, fonts, and spacing to match your brand's style.

Related reading: Html Navigation

Design Custom

Design Custom is all about tailoring your products to your unique needs and preferences. This can be done through various means such as choosing from a wide range of colors and materials.

A great example of design custom is seen in furniture making, where customers can select the type of wood, finish, and style to create a one-of-a-kind piece. This level of control allows for a perfect blend of form and function.

On a similar theme: Custom Html Elements

Credit: youtube.com, Custom product - Product Customization Designer Module

In the world of fashion, design custom is also a popular trend, where individuals can design their own clothing and accessories from scratch. This includes selecting fabrics, patterns, and embellishments to create a truly personalized look.

By choosing custom design options, customers can ensure that their products meet their specific requirements and tastes.

If this caught your attention, see: Html Install Font

Version Numbering Standards

Version Numbering Standards are crucial for customizing services without disrupting them.

The WC3 Technical Architecture Group (TAG) has identified various versioning strategies, ranging from none to big bang.

A compatible strategy, as recommended by the TAG, is a more flexible approach that provides for backwards- and forwards-compatible schemas.

Backwards-compatible schemas allow consumers of newer schemas to accept instances of an older schema.

Forwards-compatible schemas enable consumers of older schemas to process an instance of a newer schema.

If a search result schema had been made forwards-compatible, existing consumers could handle new versions without breaking or requiring modification.

In the context of evolving services, it's essential to implement a compatible strategy to mitigate coupling problems and deliver business value.

For another approach, see: Html Ul No Bullet

Events and Behavior

Credit: youtube.com, Custom Web Component Behaviours and Events

Web Components can fire automatic property changed events that are mapped to the properties defined in the component metadata.

These components will also fire custom events for the events declared in the component metadata.

A propertyChanged event is fired when a property is updated, containing properties such as the name of the property that changed, its current value, previous value, location from where it was updated, and information about the subproperty that changed.

You can declaratively define a custom event for a Web Component by declaring the event in the component's metadata file.

The app can listen to these events by declaring the event listener attributes and property setters, which can be added declaratively or programmatically.

To specify event listeners declaratively, use the on-[event-name] syntax for the attributes, such as on-click, on-value-changed, and so on.

The propertyChanged lifecycle method can be used to internally listen to the automatically generated propertyChanged events that are mapped to the properties in the component metadata.

Here is a list of the properties contained in a propertyChanged event:

  • property: Name of the property that changed.
  • value: Current value of the property.
  • previousValue: Previous value of the property that changed.
  • updatedFrom: The location from where the property was updated.
  • Subproperty: An object holding information about the subproperty that changed.

Best Practices

Credit: youtube.com, HTML Best Practices Tutorial 2021

When defining a component contract in HTML, it's essential to include a clear and concise description of the component's purpose and functionality.

Use a consistent naming convention to avoid confusion and make the code more readable. For example, use a descriptive name like "header-component" instead of "header".

A well-structured component contract should include a list of props, which are short for properties. This helps developers understand what data the component expects to receive.

Use a consistent format for listing props, such as using a table or a list with clear headings. This makes it easier for developers to scan and understand the component's requirements.

A component contract should also specify the component's expected behavior, including any events or callbacks that the component will trigger.

Use clear and concise language when describing the component's behavior, avoiding ambiguity and ensuring that developers understand what to expect.

Gilbert Deckow

Senior Writer

Gilbert Deckow is a seasoned writer with a knack for breaking down complex technical topics into engaging and accessible content. With a focus on the ever-evolving world of cloud computing, Gilbert has established himself as a go-to expert on Azure Storage Options and related topics. Gilbert's writing style is characterized by clarity, precision, and a dash of humor, making even the most intricate concepts feel approachable and enjoyable to read.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.