building-components | Sandbox project for process of building components | Frontend Framework library
kandi X-RAY | building-components Summary
kandi X-RAY | building-components Summary
You will find all working files within the /src folder. This project was built with Twig, which is a PHP templating system, but it can also be built with plain html, jekyll or handlebars. Reason for using Twig was that this is the platform I use for buiding drupal themes. All code changes get compiled into /dist by using gulp. See commands below for compiling Sass, JS, Styleguide.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of building-components
building-components Key Features
building-components Examples and Code Snippets
Community Discussions
Trending Discussions on building-components
QUESTION
Background: We run dozens of sites for clients; all use an identical code base (ASP.NET WebForms) but completely different designs. Page structure is generated programmatically from SQL Server meta-data, using controls such as Panel
, which are added to the ASP.NET page's Controls
collection, and become DIVs
in the rendered HTML.
Objective: We want to migrate eventually to ASP.NET CORE. However, there seems to be no equivalent to the page's controls collection. The closest thing I can find is the RenderTreeBuilder to add a Blazor component.
Question: Is it possible use BuildRenderTree
to add a component which contains our home-baked HTML (for instance, to contain everything between and
?
I've read articles such as:
https://chrissainty.com/building-components-via-rendertreebuilder/
... and experimented with adding HTML elements, but it's extremely cumbersome, and I'd like to programmatically generate the HTML for pretty much the whole page, and add it as one RenderFragment
(is that the right term?).
Is this possible? Is there an alternative?
Edit:
@Henk's answer, using the MarkupString
struct, and mine, using RenderTreeBuilder.AddMarkupContent
seem similar in terms of effort and plumbing required.
Are there any pros and cons of the two approaches I should consider?
...ANSWER
Answered 2020-Apr-19 at 17:25If you just want HTML (plain, dead) then you don't need a rendertree:
QUESTION
With Blazor we can generate the component's Html elements using Razor syntax or overriding BuildRenderTree(RenderTreeBuilder builder)
.
I've noticed that who writes libraries usually prefer to create a single .cs file per component defining the Html elements inside the BuilderRenderTree method. Instead, who writes a project prefer to create two files per component (Html in .razor and logic .cs) or a single .razor file (Html and logic in one place).
I've already read
- https://chrissainty.com/building-components-via-rendertreebuilder/
- https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.1#manual-rendertreebuilder-logic
So, my question is
...Why (and when) should I override BuilderRenderTree?
ANSWER
Answered 2020-Feb-05 at 15:49My general guide is that if you can do it using .razor
syntax it's always easier to create, edit, read and maintain.
However there are some cases where it's not possible to do this. One example is a demo I did last year for dynamic components: I need to render a component but I only have the System.Type
value - this allows me to render different components via code.
QUESTION
This is actually more a question about the object-orientation model in ES6. However I am going to use the creation of a new custom element as an example.
So the new and shiny (as of today) method to create a new custom element is via customElements.define()
which take in a tag name
, a constructor
, and options
(which is optional) according to MDN, Google, and of course the spec. All the documentation listed uses a variation of the new class
keyword for constructor
.
Assuming I don't like the new class
syntax, and considering for most part class
is a syntatic sugar (according to this tutorial). The spec even specifically state that
A parameter-less call to
super()
must be the first statement in the constructor body, to establish the correct prototype chain and this value before any further code is run.
By reading the tutorial I came out with this to try if it is possible (also to revise and re-learn Javascript's object model).
...ANSWER
Answered 2017-Sep-06 at 17:37In some simple situations it is possible to define a custom element without the class
keyword.
The trick is to use Reflect.construct()
to replace the super()
call.
QUESTION
In my app, I do an html import from A
to a file B
which has this. But it alerts null. If I open B
directly in the browser, it alerts the template HTML dom element. How can this happen, which this same code pretty much is from google own documents for web components https://developers.google.com/web/fundamentals/architecture/building-components/customelements.
ANSWER
Answered 2019-Oct-27 at 21:13Two factors to take into consideration when importing a file that contains a script
, and a template
:
- The
script
will execute at import time, while markup and other resources need to be added to the main page explicitly- As pointed out in this article on imports (by Eric Bidelman, same author as Google documentation linked in question):
An import link doesn't mean "#include the content here". It means "parser, go off an fetch this document so I can use it later". While scripts execute at import time, stylesheets, markup, and other resources need to be added to the main page explicitly.
- A script in an import is executed in the context of the window that contains the imported document. So
window.document
refers to the main page document, not the template document.
This should explain why your script alerts null
. Because the script is executed immediately, while the template hasn't been added to the main page yet.
You can create a reference to the import document itself where the template
can be found.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install building-components
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page