logo polydile dile-components

dile-input

Input text field Web Component, with customizable design.

<dile-input label="The label" placeholder="Write something..."></dile-input>

Derived components

There are some components in this package based on the dile-input functionality with different behaviours.

Install

npm install @dile/dile-input

Usage

Import the component.

import '@dile/dile-input/dile-input';

Use the component

<dile-input
  name="input_name"
  label="Text to the label"
  value="Text to the input"
  placeholder="Some text"
  disabled
  errored
></dile-input>

Properties

Useful Methods

Events

inputField.addEventListener('input', (e) => {
  console.log('input event named ', e.target.name, ' has value: ', e.target.value);
});
inputField.addEventListener('enter-pressed', (e) => {
  console.log('enter-pressed event, value: ', e.target.value);
});

Styling

Custom propertyDescriptionDefault
--dile-input-widthInput element width100%
--dile-input-border-widthInput element border width1px
--dile-input-border-colorInput element border color#888
--dile-input-border-radiusInput element border radius5px
--dile-input-error-border-colorInput element border on errored property = true#c00
--dile-input-focus-border-colorInput element border on focus#6af
--dile-input-disabled-border-colorInput element border when disabled#eee
--dile-input-font-sizeInput element font size1em
--dile-input-line-heightInput element line height1.5em
--dile-input-label-font-sizeFont size for the label1em
--dile-input-label-colorColor for the label text#59e
--dile-input-label-font-weightLabel text font weightnormal
--dile-input-label-margin-bottomLabel marging bottom4px
--dile-input-background-colorColor for the background input element#fff
--dile-input-paddingPadding for the input text5px
--dile-input-colorInput text color#303030
--dile-input-placeholder-colorPlaceholder color#ccc
--dile-input-text-alignInput text alignleft
--dile-input-message-padding-topSpace from input to message4px
--dile-input-message-font-sizeMessage font size0.875rem
--dile-input-message-colorMessage text color#888
--dile-input-message-error-colorMessage text color on errored state#c00
--dile-input-label-right-margin-leftSeparation betweeen input and text placed on its right side10px
--dile-input-label-right-font-sizeText placed on the right side size1.2em

dile-input demos

Default input

<dile-input 
  name="name" 
  label="Name" 
  placeholder="Write your name"
></dile-input>

Focus functionality

class MyComponent extends LitElement {
  
  render() {
    return html`
      <dile-input 
        id="address" 
        name="address" 
        label="Address" 
        disableAutocomplete 
        labelRight="..."
        message="This input has other properties..."
      ></dile-input>
      <button id="focus">Set focus on input</button>
    `
  }
  firstUpdated() {
    this.shadowRoot.getElementById('focus').addEventListener('click', () => {
      this.shadowRoot.getElementById('address').focus();
    });
  }
}
customElements.define('my-component', MyComponent);
export const JsStory = () => html`<my-component></my-component>`;

Errored input

<dile-input 
  name="name" 
  label="Name" 
  errored
  message="Errored message"
></dile-input>

Styled input

<style>
.styled {
  --dile-input-label-color: #6d3d6c;
  --dile-input-label-font-weight: bold;
  --dile-input-border-radius: 0;
  --dile-input-border-color: #6d3d6c;
  --dile-input-border-width: 2px;
  --dile-input-label-margin-bottom: 0.5rem;
  --dile-input-line-height: 2.5rem;
}
</style>
<dile-input class="styled" name="name" label="Name" placeholder="Write your name" disableAutocomplete></dile-input>