lion/packages/input-date
CircleCI bb4190d521 chore: release new versions
- @lion/checkbox-group@0.11.7
 - @lion/collapsible@0.1.0
 - @lion/fieldset@0.14.0
 - @lion/form-core@0.3.0
 - @lion/form-integrations@0.2.0
 - @lion/form@0.6.14
 - @lion/input-amount@0.7.14
 - @lion/input-date@0.7.14
 - @lion/input-datepicker@0.14.18
 - @lion/input-email@0.8.14
 - @lion/input-iban@0.9.14
 - @lion/input-range@0.4.14
 - @lion/input@0.8.0
 - @lion/radio-group@0.11.7
 - @lion/select-rich@0.19.0
 - @lion/select@0.7.14
 - @lion/switch@0.10.15
 - @lion/textarea@0.7.14
 - @lion/validate-messages@0.2.6
2020-07-27 15:03:03 +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 chore: release new versions 2020-07-27 15:03:03 +00:00
index.js feat: release inital public lion version 2019-04-26 10:37:57 +02:00
lion-input-date.js feat: release inital public lion version 2019-04-26 10:37:57 +02:00
package.json chore: release new versions 2020-07-27 15:03:03 +00:00
README.md chore: fix more links for storybook 2020-06-04 19:05:25 +02:00

Input Date

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

import { html } from 'lit-html';
import { MinDate, MinMaxDate, MaxDate } from '@lion/form-core';
import { loadDefaultFeedbackMessages } from '@lion/validate-messages';

import { formatDate } from '@lion/localize';

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

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

Features

  • Based on lion-input
  • Makes use of formatDate for formatting and parsing.
  • Option to override locale to change the formatting and parsing
  • Default label in different languages
  • Can make use of date specific validators with corresponding error messages in different languages
    • IsDate (default)
    • MinDate
    • MaxDate
    • MinMaxDate

How to use

Installation

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

Examples

Is a date

export const isADate = () => html`
  <lion-input-date label="IsDate" .modelValue=${new Date('foo')}> </lion-input-date>
`;

With minimum date

export const withMinimumDate = () => html`
  <lion-input-date
    label="MinDate"
    help-text="Enter a date greater than or equal to today."
    .modelValue=${new Date('2018/05/30')}
    .validators=${[new MinDate(new Date())]}
  >
  </lion-input-date>
`;

With maximum date

export const withMaximumDate = () => html`
  <lion-input-date
    label="MaxDate"
    help-text="Enter a date smaller than or equal to today."
    .modelValue=${new Date('2100/05/30')}
    .validators=${[new MaxDate(new Date())]}
  ></lion-input-date>
`;

With minimum and maximum date

export const withMinimumAndMaximumDate = () => html`
  <lion-input-date
    label="MinMaxDate"
    .modelValue=${new Date('2018/05/30')}
    .validators=${[new MinMaxDate({ min: new Date('2018/05/24'), max: new Date('2018/06/24') })]}
  >
    <div slot="help-text">
      Enter a date between ${formatDate(new Date('2018/05/24'))} and ${formatDate(
        new Date('2018/06/24'),
      )}.
    </div>
  </lion-input-date>
`;

Faulty prefilled

export const faultyPrefilled = () => html`
  <lion-input-date
    label="Date"
    help-text="Faulty prefilled input will be cleared"
    .modelValue=${'foo'}
  ></lion-input-date>
`;