lion/packages/input-email
github-actions[bot] 6a83263a0c Version Packages
2020-08-10 11:11:46 +00:00
..
src chore: move icon intro to icon package so it can be extended 2020-06-08 11:27:26 +02:00
test feat: merge field/validate/choice-input/form-group into @lion/form-core 2020-05-29 17:01:15 +02:00
CHANGELOG.md Version Packages 2020-08-10 11:11:46 +00:00
index.js feat: release inital public lion version 2019-04-26 10:37:57 +02:00
lion-input-email.js feat: release inital public lion version 2019-04-26 10:37:57 +02:00
package.json Version Packages 2020-08-10 11:11:46 +00:00
README.md chore: fix more links for storybook 2020-06-04 19:05:25 +02:00

Input Email

lion-input-email component is based on the generic text input field. Its purpose is to provide a way for users to fill in an email.

import { html } from 'lit-html';
import { Validator } from '@lion/form-core';
import { loadDefaultFeedbackMessages } from '@lion/validate-messages';

import './lion-input-email.js';

export default {
  title: 'Forms/Input Email',
};
loadDefaultFeedbackMessages();
export const main = () => {
  return html` <lion-input-email label="Email" name="email"></lion-input-email> `;
};

Features

  • Based on lion-input
  • Makes use of email validators with corresponding error messages in different languages
    • IsEmail (default)

How to use

Installation

npm i --save @lion/input-email
import { LionInputEmail } from '@lion/input-email';
// or
import '@lion/input-email/lion-input-email.js';

Examples

Faulty Prefilled

When prefilling with a faulty input, an error feedback message will show.

Use loadDefaultFeedbackMessages to get our default feedback messages displayed on it.

export const faultyPrefilled = () => html`
  <lion-input-email .modelValue=${'foo'} label="Email"></lion-input-email>
`;

Custom Validator

export const customValidator = () => {
  class GmailOnly extends Validator {
    static get validatorName() {
      return 'GmailOnly';
    }
    execute(value) {
      let hasError = false;
      if (!(value.indexOf('gmail.com') !== -1)) {
        hasError = true;
      }
      return hasError;
    }
    static async getMessage() {
      return 'You can only use gmail.com email addresses.';
    }
  }
  return html`
    <lion-input-email
      .modelValue=${'foo@bar.com'}
      .validators=${[new GmailOnly()]}
      label="Email"
    ></lion-input-email>
  `;
};