I am developing a UI application using Angular and I can choose one or more of the following CSS frameworks:
Bootstrap 4
Foundation
Angular Material
ng-bootstrap or ngx-bootstrap.
A pre built template that I can purchase.
Many others or new ones...
Is there a best practice to design the Angular application, so that it will be easy to switch to a different CSS framework further down the line ?
One option, I think, is to define a new Feature module, which will import all the controls of a particular CSS Framework, and then, I write a wrapper on that and use it in my application.
For example, I can wrap a md-button with my custom-button in a component template of my module and use it in my application.
Will this approach work or is there a standard design practice that I should follow ?
You could do that, but in my opinion you're wasting your time. How many times in the past have you switched out the design framework? Probably never.
The view of a component is comprised much more than the low level components, like buttons and inputs. There's layout and responsiveness that all play into the composition of the view. For example, lets say you went with material design and wrapped the md-button in my-custom-button. As the application matures you undoubtedly will being adding padding or margin around containers the hold these controls that makes it look and feel more Material. The day comes to switch to the new design pattern on the block, and guess what? Even though you can quickly swap out those buttons for a new look, you're still going to be editing all your views to follow the new look. That said, views are much more than the low level components that make up them, and it's not worth the overhead of wrapping each component with your own.
What makes more sense is to create separate templates for each component.
Lets say you did you entire application in Material, and now you want to switch to New Hotness. You first would go through and rename all your templates:
login.component.html > login.component.material.html
And then create new templates specifically targeting the new framework:
login.component.newhotness.html
Next, create a build process that would swap the templateUrl at build time based on some configuration. Using this strategy, you will be able to easily integrate technologies like Ionic or NativeScript which do not use HTML for their views, but a completely different XML based syntax.
Key takeaways:
Don't wrap existing library components with your own variation
Create component templates in a separate file
When the day comes to switch to a new framework, create new templates for each component and define the older templates with a name that describes the framework that comprises it
Get paid! :)
The issue is not so much the CSS class names, but the HTML structure. I started wondering about it a while ago, and did an attempt to create an intermediate language that would produce either Bulma compliant HTML or Bootstrap compliant HTML, depending on the CSS framework I would pick. It relied on Pug mixins that had specific implementations per framework. As a consequence, I could write this for a form field:
form
+m-input#name(m-label="Name" type="text")
+m-input#password(m-label="Password" type="password" placeholder="Password")
And in the Bootstrap case, it would generate this:
<form>
<div class="form-group">
<label for="name">Name</label>
<input id="name" m-label="Name" type="text" class="form-control">
</div>
<div class="form-group">
<label for="password">Password</label>
<input id="password" m-label="Password" type="password" placeholder="Password" class="form-control">
</div>
</form>
… but for the Bulma case, it would generate this:
<form>
<div class="field">
<label for="name" class="label">Name</label>
<div class="control">
<input id="name" m-label="Name" type="text" class="input">
</div>
</div>
<div class="field">
<label for="password" class="label">Password</label>
<div class="control">
<input id="password" m-label="Password" type="password" placeholder="Password" class="input">
</div>
</div>
</form>
This post covers a more in depth discussion and also has pointers to other examples.
Related
I am building my web razor view and have an issue with the Label Tag Helper.
This is my markup:
<label asp-for="customer.FirstName" class="col-sm-2 col-form-label">First Name</label>
The problem is the First and Name are being show on separate lines and I want them on one line. Apologies if this is a simple question; I am a novice at this.
Many thanks for any help,
You need to play with column size(class properties) eg :
<label asp-for="customer.FirstName" class="col-md-4 col-form-label">First Name</label>
It may be useful for you to get along with how the Grid System of bootstrap works:
https://getbootstrap.com/docs/4.0/layout/grid/
and
https://www.c-sharpcorner.com/article/bootstrap-for-beginners-part-threebootstrap-grids/
I'm creating a from that has validation errors show below the related inputs. To make the form more accessible I have added aria-lives to div that will hold the error message. With having more than one aria-live will this make it worse for the users?
<div
id="awesome-id">
<label for="awesome-id--input">
This is a label
</label>
<input
type="tel"
id="awesome-id--input"
required>
<div
role="region"
aria-live="polite"
id="awesome-id--error-message">
</div>
</div>
<div
id="another-id">
<label for="another-id--input">
This is another label
</label>
<input
type="tel"
id="another-id--input"
required>
<div
role="region"
aria-live="polite"
id="another-id--error-message">
</div>
</div>
You can have multiple aria-live containers - especially since they are “polite”, they should wait until it’s quiet to give you the feedback. Whether this is also a good experience for your users, you should simply test with a screen-reader (or, preferably, conduct user-tests).
However, I would remove the role=“region”. This is the specification of the Region element at MDN Web Docs:
The region role should be reserved for sections of content sufficiently important that users will likely want to navigate to the section easily and to have it listed in a summary of the page.
Landmarks like Region allow the user to quickly navigate to them. But adding all error messages to that list of landmarks would just muddy it in my opinion. Instead you should consider adding role=“alert”.
Also, make sure that the error container having aria-live is present at the page on load - even though it is empty. Otherwise some browsers will not know to listen for changes in it.
Lastly, remember to also toggle aria-invalid=“true/false” on the input to provide the screen-reader with proper feedback.
I am writing a simple redux app and one of the components looks like this
const LoginComponent = ({onLoginClick, onRegisterClick}) => (
<div className={styles.loginDiv}>
<p className={standardStyles.pageTitleText}>SyncSpace</p>
<input type="text" placeholder="Username"/>
<input type="password" placeholder="Password"/>
<div className={styles.loginRegisterDiv}>
<button className={styles.loginButton} onClick={onLoginClick}>Login</button>
<button className={styles.registerButton} onClick={onRegisterClick}>Register</button>
</div>
</div>
);
On the click events I want to read the values typed into the username and password fields and pass them as parameters to the onLoginClick event. What is the proper way to read this value in Redux?
Redux-Form is overkill. You definitely don't need any kind of library to read from forms.
This is actually not a Redux question, specifically - it's a React question. There's two ways to handle form values in React: "controlled" inputs, and "uncontrolled" inputs. When you ask "how can I read the values on click", the answer is "read them from the inputs themselves using refs" for uncontrolled inputs, and "read the values from your component's state" for controlled inputs.
Gosha Arinich has several articles that explain the basics of how to use forms in React, and I highly recommend you read through those first: https://goshakkk.name/on-forms-react/ . They explain the ideas of "controlled" and "uncontrolled" inputs, and how to use them. (Gosha also just released an excellent book on forms and React, which I also recommend. It goes into greater detail than the blog posts: https://goshakkk.name/the-missing-forms-handbook-of-react/ ).
I would suggest taking a look at redux-form.
It is a very active project with a great community to answer any questions.
Here is an example of how to attach a form to the redux store.
Using redux-form, you can change your form to something like this:
import React from 'react';
import { Field, reduxForm } from 'redux-form';
const LoginComponent = ({onRegisterClick, onLoginClick}) => (
<form onSubmit={onRegisterClick} className={styles.loginDiv}>
<p className={standardStyles.pageTitleText}>SyncSpace</p>
<Field name="userName" component="input" type="text" placeholder="Username"/>
<Field name="password" component="input" type="password" placeholder="Password"/>
<div className={styles.loginRegisterDiv}>
<button type="submit" className={styles.loginButton}>Login</button>
</div>
</form>
);
I personally prefer to have the registration and login actions happen on two separate views, but if you do choose to have two buttons in your redux-form, there are multiple ways to do so. This is a good answer on attaching the action to the onClick handlers as you do, but a modification to the action so that it takes in a parameter.
Hi everyone, I'm going to start with a new experience with dotnet core using the MVC pattern.
Which are the new helpers for checkbox, textarea and other?
In this moment the relative page is empty : https://learn.microsoft.com/en-us/aspnet/core/mvc/views/html-helpers
I've tried this :
<input asp-for="myField" class="form-control" type="checkbox" value="False"/> but doesn't work!
Thanks in advance.
<div class="form-group">
<label asp-for="myField" class="col-md-2 control-label"></label>
<div class="col-md-10">
#*<input asp-for="myField" class="form-control" type="checkbox" value="False"/>*#
<span asp-validation-for="myField" class="text-danger"></span>
</div>
</div>
First check if you got reference to Microsoft.AspNet.Mvc.TagHelpers package in your project.json
Secondly remember about #addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers at the beginning of your view.
If you want use HTML Helpers you can still do the same like in .Net Framework but MS want to change a bit HTML Helpers to Tag Helpers. Tag Helpers are new feature with .Net Core
I've been got error in the browser, because the field which I set is Nullable.
I've did the migration, update the database and now work!
I newbie in drupal 7. I am writing new theme and I don't know how to add my class to form in drupal 7. I install ubercart to setup e-commerce website. I added new attribute for product (Size). I want to redesign in product page. In this page, It has size field but I don't know how to add my CSS. E.g:
<form action="/drupal-7.34/node/6" method="post" id="uc-product-add-to-cart-form-6" accept-charset="UTF-8"><div><div id="uc_product_add_to_cart_form-6-attributes" class="attributes"><div class="attribute attribute-1 odd"><div class="form-item form-type-select form-item-attributes-1">
<label for="edit-attributes-1">Size <span class="form-required" title="This field is required.">*</span></label>
<select id="edit-attributes-1" name="attributes[1]" class="form-select required"><option value="" selected="selected">- Select -</option><option value="1">39</option><option value="2">40</option><option value="3">41</option></select>
</div>
</div></div><input type="hidden" name="qty" value="1">
<input type="hidden" name="form_build_id" value="form-w06CKx7aNBiYShqfg8LiP98CaFLpEb8mgWzFYQWqnQ4">
<input type="hidden" name="form_token" value="JtZIrcKeIfXiVpwX43K6KqHPlZazR1klS1ht3W7PI9I">
<input type="hidden" name="form_id" value="uc_product_add_to_cart_form_6">
<div class="form-actions form-wrapper" id="edit-actions"><input class="node-add-to-cart form-submit" type="submit" id="edit-submit-6" name="op" value="Add to cart"></div></div></form>
I want to add my class to the select element. How can I do that?
In your theme directory there is file named theme_name.info . Inside of it there should be (or you can create it) array that defines css file which will be included on page. Check out explanation here:
https://www.drupal.org/node/171205
https://www.drupal.org/node/171209
So, you basically have to add path of your css file to that list and it will be included on every site page. Your html.php template must print out stylesheets variable (which will contain paths to css files). If you are not sure how to do it check how it's done on some standard drupal theme that comes with drupal installation.
After adding your css to theme info file don't forget to clear the cache!
Other way would be to include it manually, from page.tpl.php file. Just add there common CSS include line, like you would that in plain HTML file.
You can add CSS even from code with drupal_add_css() function, but that's a bit more advanced.
And you can use form id attribute to "aim" it and all inner elements with css.