You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Component mixin provides methods as shorthand for all currently supported HTML5 tag names in the format tag_name(properties, content). Both properties and content are optional. Examples:
div('Hello, world!')# Properties omittedimg(src: 'https://example.com/logo.jpg')# Content omittedhr# Both properties and content omittedh1({class_name: 'title'},'Welcome to Clearwater')# Includes both properties and content
Notice in the last example that the class_name property is used instead of the HTML class attribute. Clearwater uses the DOM properties API rather than HTML attributes. This is because we are working with DOM nodes rather than strings of HTML text. You can still set properties as HTML attributes if you nest them within the attributes key. This is required for some attributes that do not have DOM-property counterparts. For example, aria-* and role attributes:
div({attributes: {role: 'alert'}},'Item is out of stock')
The content argument can be any of the following types:
String
Number
nil
Another component
An array containing any combination of the above
Example:
ul(articles.map{ |a| # Array content in this ulli([# Array content for this lih1(a.title),# Stringdiv(a.author_name),# String or nil if anonymousTimestamp.new(a.timestamp),# Componentdiv(a.comments.count),# Number])})
Component#tag(properties=nil, content=nil)
Returns a virtual-DOM node with the specified properties and content. Unlike the HTML5 tag methods above, properties cannot be omitted if the content argument is supplied.
Component#call
Re-renders all Clearwater apps in the registry. Due to Clearwater's asynchronous rendering, this method takes an optional block that will be invoked after the UI is updated.
Component#params
Routing targets can use this method to get the route params they care about from their router. For example:
classArticleDetailincludeClearwater::Component# ...defselected_article# Assumes a global Store object that knows about all of the articles loaded# and has them indexed by id.Store.articles[params[:article_id]]endend
The text was updated successfully, but these errors were encountered:
HTML5 tag names
The
Component
mixin provides methods as shorthand for all currently supported HTML5 tag names in the formattag_name(properties, content)
. Bothproperties
andcontent
are optional. Examples:Notice in the last example that the
class_name
property is used instead of the HTMLclass
attribute. Clearwater uses the DOM properties API rather than HTML attributes. This is because we are working with DOM nodes rather than strings of HTML text. You can still set properties as HTML attributes if you nest them within theattributes
key. This is required for some attributes that do not have DOM-property counterparts. For example,aria-*
androle
attributes:The
content
argument can be any of the following types:nil
Example:
Component#tag(properties=nil, content=nil)
Returns a virtual-DOM node with the specified properties and content. Unlike the HTML5 tag methods above,
properties
cannot be omitted if thecontent
argument is supplied.Component#call
Re-renders all Clearwater apps in the registry. Due to Clearwater's asynchronous rendering, this method takes an optional block that will be invoked after the UI is updated.
Component#params
Routing targets can use this method to get the route params they care about from their router. For example:
The text was updated successfully, but these errors were encountered: