Angular Icon Input Box Components - Font Awesome and Material Design Input Boxes
This module contains a couple of Angular Input box components that allow to add an icon inside a text input, which helps better identify common input fields like for example email, etc.
This small module contains only the HTML and CSS necessary to implement this very common HTML pattern.
The default theme of the input is designed to look just like a plain HTML input, including the focus blue border (tab and shift-tab are supported).
Any icon available on either the Font Awesome or the Google Material Design Icon libraries can be used.
Here is what the inputs with the icons look like on screen:
This is how to install the components:
npm install au-input
or
yarn add au-input
And on your application module:
import {AuInputModule} from 'au-input';
@NgModule({
declarations: [ ...],
imports: [
BrowserModule,
....,
AuInputModule
],
})
export class AppModule { }
See below for SystemJs / UMD installation.
We will need to add first a version of Font Awesome to our page, for example:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
Then we can use the Font Awesome Input like this:
<au-fa-input icon="envelope">
<input auInput type="email" name="email" placeholder="Email" autocomplete="off"
class="some-class" data-stripe="email">
</au-fa-input>
<au-fa-input id="password-field" icon="lock" >
<input auInput placeholder="Password" class="test-class">
</au-fa-input>
<au-fa-input icon="cc-stripe">
<input auInput placeholder="Stripe">
</au-fa-input>
<au-fa-input icon="paypal">
<input auInput placeholder="Paypal">
</au-fa-input>
The inputs receive an input property named icon
that identifies which Font Awesome icon we want to apply.
The value envelope
will add the email icon by adding the CSS class fa-envelope
to the icon, etc.
The input that you pass inside the component is just a plain HTML input that will be projected inside the component, so all the standard HTML properties of an input apply.
To make sure that the focus functionality is working correctly, make sure to apply the attribute directive auInput
like in the examples.
We will need to add first a version of the Google Material Design icons to our page, for example:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Then we can use the Material Design Input like this:
<au-md-input icon="search">
<input auInput type="email" name="email" placeholder="E-mail">
</au-md-input>
<au-md-input icon="perm_identity">
<input auInput name="identity" placeholder="Identity Number">
</au-md-input>
<au-md-input icon="receipt">
<input auInput name="receipt" placeholder="Receipt">
</au-md-input>
This command will build and start the demo application:
npm start
First let’s build the library using this command:
npm run build
Then let’s link it:
cd dist
npm link
On another folder on the same machine where we have for example a running Angular CLI, we then do:
npm link au-input
The tests can be executed with the following commands:
npm test
npm integration
Make sure to add this to your map
configuration, if you need the module served from a CDN:
map: {
...
'au-input': 'https://unpkg.com/au-input@<version number>/au-input.umd.min.js'
}
Otherwise if serving from node_modules
directly:
map: {
...
'au-input': 'node_modules/au-input/bundles/au-input.umd.min.js'
}
And in our packages property:
packages: {
...
'au-input': {
main: 'index.js',
defaultExtension: 'js'
}
}