Material Design Inspired Form Controls – Material-input

Category: Form , Javascript | October 21, 2016
Authornuclei
Last UpdateOctober 21, 2016
LicenseMIT
Views1,056 views
Material Design Inspired Form Controls – Material-input

Material-input is a lightweight, dependency-free web component that lets you create Google Material Design inspired form fields using vanilla JavaScript and HTML / CSS.

How to use it:

Load the needed webcomponents.js and the Material-input’s files in the webpage.

<script src="webcomponentsjs/webcomponents.js"></script>
<script src="material-input.js"></script>

Create form fields as follows:

<material-input name="name" label="name" autovalidate required></material-input>
<material-input name="username" label="Username" type="text" valid autovalidate required pattern=".{3,}"></material-input>
<material-input name="email" label="Email" placeholder="Your Email" type="email"></material-input>
<material-input name="password" type="password" placeholder="Placeholder" pattern=".{8,}"></material-input>
<material-input name="phone" label="Phone Number" placeholder="Your Phone Number" value="+49 12 345 678"></material-input>
<material-input name="address" label="Address" value="Baker Street" invalid  message="Are you Sherlock Holmes? Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."></material-input>

Style the form fields whatever you like:

material-input[name=name] { font-size: 26px;  --accent-color: yellow;
 --material-input-text-color: orange;
 --material-input-highlight-color: indigo;
 --material-input-invalid-color: red;
 --material-input-valid-color: green;
 --material-input-border-color: gray;
 --material-input-line-height: 3px;
 --material-input-highlight-line-height: 8px;
}
material-input[name=password] {
 --accent-color: teal;
 --material-input-placeholder-color: gray; width: 200px; }

You Might Be Interested In:


Leave a Reply