1.0.26 • Published 1 month ago

@n3oltd/form-elements v1.0.26

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

form-elements

A N3O Package for use in client websites.

This package provides form elements that can be used in other N3O Lit projects.

Usage

As with all n3o frontend packages, install the package in the JS directory of the given client project.

npm install @n3o/form-elements

Require the elements you need:

import "@n3oltd/form-elements/src/components/FormLabel";
import "@n3oltd/form-elements/src/components/FormInput";
import "@n3oltd/form-elements/src/components/FormSelect";

Or require all elements:

import "@n3oltd/form-elements";

List of Elements

Form elements are designed to be used as Controlled Components, where the parent component keeps track of the state of the component and passed the current value down to the component as a property.

Label Element

In your Lit application code:

<form-element-label
      .primaryColor="${this.primaryColor}"
      .required="${true}"
      .helpText="${"This is required so we can...."}"
    >
      <span slot="labelText">Country</span>
</form-element-label>

NB helpText can either be provided as a prop to the label element, in which case it will be displayed as a ? icon beside the label name, or as a prop to the form element, in which case it will be shown as muted text beneath the form element.

form-element-label requires the below CSS variables to be set to control styling

In HTML file:

<style>
your-app-name {
    --label-font: Arial, sans-serif;
    --label-font-size: 16px;
    --label-text-transform: capitalize;
    --label-text-color: #A6A4A3;
    --label-font-weight: 600;
    
    /* Used for the help text label */
    --text-muted-color: #6c757d;
    --tooltip-background: rgba(79, 175, 70, 0.1);

    /* Used for error message text */
    --error-color: #e60730;


    /* Will be the asterisk color if label is required */
    --theme-color: #4FAF46;
}
</style>

Text Input Element

In your Lit application code:

<form-element-input
  .disabled="${true}"
  .required="${true}"
  .requiredMessage="${"Last Name is required"}"
  .helpText="${"This is required so we can...."}"
  .error="${this._error}"
  .capitalizationOption="${CapitalizationOption.Capitalize}"
  .value="${this._lastName}"
  .onChange="${(v: string) => {
      this._lastName = v;
  }}"
  .validateInput="${(target: HTMLInputElement) => {
      if (target.value?.length > 0 && target.value?.length <= 1)
        this._error = "Last Name is too short";
      else {
        this._error = undefined;
      }
   }}"
></form-element-input>

form-element-input requires the below CSS variables to be set to control styling

In HTML file:

<style>
your-app-name {
    --input-height: 28px;
    --input-font-size: 16px;
    --input-box-shadow: 0 0 0 0.2rem rgba(79, 175, 70, 0.5);
    --theme-color: #4FAF46;
    --text-color: rgb(33, 37, 41);
    --disabled-text-color: rgba(33, 37, 41, 0.6);
    --input-border-radius: 4px;
}
</style>

Select Element

In your Lit application code:

<form-element-select
  .options="${[
    {
      id: "GB",
      value: "United Kingdom",
    },
    {
      id: "ES",
      value: "Spain",
    },
    {
      id: "CA",
      value: "Canada",
    },
  ]}"
  .value="${this._country}"
  .disabled="${false}"
  .onChange="${(v: { id: string; value: string }) =>
    (this._country = v)}"
></form-element-select>

form-element-select requires the below CSS variables to be set to control styling

In HTML file:

<style>
your-app-name {
    --input-height: 28px;
    --input-font-size: 16px;
    --input-box-shadow: 0 0 0 0.2rem rgba(79, 175, 70, 0.5);
    --theme-color: #4FAF46;
    --text-color: rgb(33, 37, 41);
    --disabled-text-color: rgba(33, 37, 41, 0.6);
    --input-border-radius: 4px;

    /* NOTE: Hex colour here must begin with %23 not # as # character is considered a fragment identifier. */
    --select-dropdown-url: url("data:image/svg+xml;utf8,<svg fill='%234FAF46' height='26' viewBox='0 0 26 26' width='26' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
}
</style>
1.0.26

1 month ago

1.0.25

2 months ago

1.0.16

10 months ago

1.0.22

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.2

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0-beta.33

2 years ago

1.0.0-beta.32

2 years ago

1.0.0-beta-23

2 years ago

1.0.0-beta-24

2 years ago

1.0.0-beta.31

2 years ago

1.0.0-beta-21

2 years ago

1.0.0-beta-22

2 years ago

1.0.0-beta.30

2 years ago

1.0.0-beta-20

2 years ago

1.0.0-beta-29

2 years ago

1.0.0-beta-19

2 years ago

1.0.0-beta-27

2 years ago

1.0.0-beta-28

2 years ago

1.0.0-beta-25

2 years ago

1.0.0-beta-26

2 years ago

1.0.0-beta-18

2 years ago

1.0.0-beta-17

2 years ago

1.0.0-beta-16

2 years ago

1.0.0-beta-15

2 years ago

1.0.0-beta-14

2 years ago

1.0.0-beta-13

2 years ago

1.0.0-beta-12

2 years ago