-
Couldn't load subscription status.
- Fork 0
added new sections to the element-composite article. #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| ::: | ||
|
|
||
| In the demonstration below, a click event has been created and then added to the QR code component. This event, when fired, will display the "X" coordinate of the mouse at the time of clicking the component, which is provided to the Java event as data. A method is then implemented to allow the user to access this data, which is how it is displayed in the application. | ||
| In the demonstration below, a click event has been created and then added to the QR code component. This event, when fired, will display the "X" coordinate of the mouse at the time of clicking the component, which is provided to the Java event as data. A method is then implemented to allow the user to access this data, which is how it is displayed in the app. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [vale] reported by reviewdog 🐶
[Google.Contractions] Use 'it's' instead of 'it is'.
|
|
||
| The `ElementComposite` class serves as a versatile foundation for managing composite elements in webforJ applications. Its primary purpose is to facilitate the interaction with HTML elements, represented by the `Element` class, by providing a structured approach to handle properties, attributes, and event listeners. It allows for implementation and reuse of elements in an application. Use the `ElementComposite` class when implementing Web Components for use in webforJ applications. | ||
|
|
||
| The `ElementComposite` class serves as a versatile foundation for managing composite elements in webforJ apps. Its primary purpose is to facilitate the interaction with HTML elements, represented by the `Element` class, by providing a structured approach to handle properties, attributes, and event listeners. It allows for implementation and reuse of elements in an app. Use the `ElementComposite` class when implementing Web Components for use in webforJ apps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rework to be more meaningful with less filler
| ## Event registration | ||
|
|
||
| Events are a crucial part of web components, allowing communication between different parts of an application. The `ElementComposite` class simplifies event registration and handling. To register an event listener, use the `addEventListener()` method to register event listeners for specific event types. Specify the event class, the listener, and optional event options. | ||
| Events are a crucial part of web components, allowing communication between different parts of an app. The `ElementComposite` class simplifies event registration and handling. To register an event listener, use the `addEventListener()` method to register event listeners for specific event types. Specify the event class, the listener, and optional event options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this sentence could use a bit of a rewrite to say more with fewer words.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to handle any conflicts, but otherwise looks good!
|
|
||
| ## `ElementCompositeContainer` for components with slots | ||
|
|
||
| For components that need to manage child components in named slots (such as headers, footers, or content areas), extend <JavadocLink type="foundation" location="com/webforj/component/element/ElementCompositeContainer" code='true' >ElementCompositeContainer</JavadocLink> instead of `ElementComposite`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| For components that need to manage child components in named slots (such as headers, footers, or content areas), extend <JavadocLink type="foundation" location="com/webforj/component/element/ElementCompositeContainer" code='true' >ElementCompositeContainer</JavadocLink> instead of `ElementComposite`. | |
| For web components that have slots (such as headers, footers, or content areas), extend <JavadocLink type="foundation" location="com/webforj/component/element/ElementCompositeContainer" code='true' >ElementCompositeContainer</JavadocLink> instead of `ElementComposite` to manage the child components within the named slots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EHandtkeBasis I've made some edits, and left some suggestions for the ElementCompositeContainer section.
| ## Interacting with slots | ||
|
|
||
| Web components often use slots to allow developers to define the structure of a component from the outside. A slot is a placeholder inside a web component that can be filled with content when using the component. In the context of the `ElementComposite` class, slots provide a way to customize the content within a component. The following methods are provided to allow developers to interact with and manipulate slots: | ||
|
|
||
| 1. **`findComponentSlot()`**: This method is used to search for a specific component across all slots in a component system. It returns the name of the slot where the component is located. If the component is not found in any slot, an empty string is returned. | ||
| 1. **`findComponentSlot()`**: This method is used to search for a specific component across all slots in a component system. It returns the name of the slot where the component is located. If the component isn't found in any slot, an empty string is returned. | ||
|
|
||
| 2. **`getComponentsInSlot()`**: This method retrieves the list of components assigned to a given slot in a component system. Optionally, pass a specific class type to filter the results of the method. | ||
|
|
||
| 3. **`getFirstComponentInSlot()`**: This method is designed to fetch the first component assigned to the slot. Optionally pass a specific class type to filter the results of this method. | ||
|
|
||
| It is also possible to use the `add()` method with a `String` parameter to specify the desired slot in which to add the passed component. | ||
| It's also possible to use the `add()` method with a `String` parameter to specify the desired slot in which to add the passed component. | ||
|
|
||
| These interactions allow developers to harness the power of web components by providing a clean and straightforward API for manipulating slots, properties, and handling events within the `ElementComposite` class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're suppose to use the ElementCompositeContainer class for components with slots, does this section need to be updated to reference ElementCompositeContainer instead of ElementComposite?
|
|
||
| ## `ElementCompositeContainer` for components with slots | ||
|
|
||
| For components that need to manage child components in named slots (such as headers, footers, or content areas), extend <JavadocLink type="foundation" location="com/webforj/component/element/ElementCompositeContainer" code='true' >ElementCompositeContainer</JavadocLink> instead of `ElementComposite`. | ||
|
|
||
| `ElementCompositeContainer` provides a structured way to add, remove, and manage components in specific slots: | ||
|
|
||
| ```java | ||
| @NodeName("my-container") | ||
| public final class MyContainer extends ElementCompositeContainer | ||
| implements HasClassName<MyContainer>, HasStyle<MyContainer> { | ||
| private static final String HEADER_SLOT = "header"; | ||
| private static final String CONTENT_SLOT = "content"; | ||
| private static final String FOOTER_SLOT = "footer"; | ||
|
|
||
| public MyContainer() { | ||
| super(); | ||
| } | ||
|
|
||
| public MyContainer addToHeader(Component... components) { | ||
| getElement().add(HEADER_SLOT, components); | ||
| return this; | ||
| } | ||
|
|
||
| public MyContainer addToContent(Component... components) { | ||
| add(components); // Default slot | ||
| return this; | ||
| } | ||
|
|
||
| public MyContainer addToFooter(Component... components) { | ||
| getElement().add(FOOTER_SLOT, components); | ||
| return this; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Use `ElementCompositeContainer` whenever your component needs to support multiple content areas or slots, such as layouts, dialogs, or toolbars. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Move this section to later in the article, right before Interacting with slots. If this section won't be moved, include a link/reference to Interacting with slots.
|
@EHandtkeBasis Fix conflicts please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EHandtkeBasis In general, this is a good start. But it still feels patched together and a bit rushed. I would expect to read this document and learn everything I need to start working with ElementComposite. Right now, that is not the case. The content does not follow a logical order and the sections do not build on each other yet.
| The `ElementComposite` class provides a structured base for building reusable web components in webforJ. It allows you to easily define properties, attributes, and event listeners of the underlying HTML elements in a type-safe, maintainable way. Use `ElementComposite` to encapsulate and integrate custom elements or third-party web components within your app. | ||
|
|
||
|
|
||
| While using the `ElementComposite` class, using the `getElement()` method will give you access to the underlying `Element` component. Similarly, the `getNodeName()` method gives you the name of that node in the DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section seems a bit out of place.
| ::: | ||
|
|
||
| This guide demonstrates how to implement the [Shoelace QR code web component](https://shoelace.style/components/qr-code) using the `ElementComposite` class. | ||
| :::info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tip seems out of place too.
| - **@StyleSheet**: Loads external CSS files for your component: | ||
|
|
||
| ```java | ||
| @StyleSheet(url = "https://cdn.example.com/library.css") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The url param is not supported , it should be value
| /> | ||
|
|
||
| ## Concern Interfaces | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also doesn't feel like a logical next learning step. The concern interfaces should probably be a separate article, because they apply to building UI in webforJ in general, not specifically to ElementComposite.
| String title = get(TITLE, false, String.class); | ||
| ``` | ||
|
|
||
| ### Best practices for validating properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it please
| ``` | ||
| This approach helps prevent an invalid state. | ||
|
|
||
| ### Enum-style properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you only explaining enum properties and not other object property types and how they are converted? There should be a dedicated section that goes in depth on both basic and complex types, such as enums, maps, and lists and explains how webforJ serializes them when sending data to the client, and how it deserializes the values on the way back.
| height='250px' | ||
| /> | ||
|
|
||
| ## Event registration {#event-registration} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section feels a bit shallow. There is a lot more you can explain here. For example, you haven't covered how to create custom events for your components or how to wrap them in classes or how to deal with payloads..
| The `ElementComposite` events are different from `Element` events, in that this doesn't allow any class, but only specified `Event` classes. | ||
| ::: | ||
|
|
||
| ### Built-in event classes {#built-in-event-classes} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This section doesn't really add much value
- ElementDefinedEvent is internal, it cannot be used directly anyway
| ElementEventOptions merged = baseOptions.mergeWith(specificOptions); | ||
| ``` | ||
|
|
||
| ## Interacting with slots {#interacting-with-slots} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section needs a bit more explanation about what slots are. You can refer to the MDN documentation for more details.
| It's also possible to use the `add()` method with a `String` parameter to specify the desired slot in which to add the passed component. | ||
|
|
||
| These interactions allow developers to harness the power of web components by providing a clean and straightforward API for manipulating slots, properties, and handling events within the `ElementComposite` class. | ||
| ```java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sample doesn't add much value. Can we come up with something runnable and more useful?
#378
#376