Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@miraidesigns/textfield

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miraidesigns/textfield

Mirai Designs Framework: Textfield module

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Textfields

Text fields allow for text based inputs.


HTML

<div class="mdf-textfield">
    <label for="textfield" class="mdf-textfield__label">Label</label>
    <input id="textfield" class="mdf-textfield__input" type="text">
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/textfield/styles';
// Configure appearance
@use '@miraidesigns/textfield' with (
    $variable: value
);

@include textfield.styles();

TypeScript

import { MDFTextfield } from '@miraidesigns/textfield';

new MDFTextfield(document.querySelector('.mdf-textfield'));

Examples

Some basic examples on how the module can be used.

Icons

Icons are a great way to add visual information to your input, like a search icon for example.

<!-- Leading icon -->
<div class="mdf-textfield mdf-textfield--icon-leading">
    <label for="textfield" class="mdf-textfield__label">Label</label>
    <input id="textfield" class="mdf-textfield__input" type="text">
    <svg class="mdf-textfield__icon">
        <use href="icons.svg#search"></use>
    </svg>
</div>

<!-- Trailing icon -->
<div class="mdf-textfield mdf-textfield--icon-trailing">
    <label for="textfield" class="mdf-textfield__label">Label</label>
    <input id="textfield" class="mdf-textfield__input" type="text">
    <svg class="mdf-textfield__icon">
        <use href="icons.svg#lock"></use>
    </svg>
</div>

Counters

Display the current character count and character limit.

<div class="mdf-textfield mdf-textfield--has-helper">
    <label for="textfield-counter" class="mdf-textfield__label">Text field</label>
    <input id="textfield-counter" class="mdf-textfield__input" type="text" maxlength="30">
    <div class="mdf-textfield__helper-line">
        <span class="mdf-textfield__helper mdf-textfield__helper--counter"></span>
    </div>
</div>

Textareas

Textareas automatically grow in size to accommodate their content.

<div class="mdf-textfield mdf-textfield--textarea">
    <label for="textarea" class="mdf-textfield__label">Textarea</label>
    <textarea id="textarea" class="mdf-textfield__input" rows="1"></textarea>
</div>

Passwords

Password fields allow to toggle between hidden and plain text.

<div class="mdf-textfield mdf-textfield--has-helper mdf-textfield--icon-trailing">
    <label for="password-field" class="mdf-textfield__label">Password</label>
    <input id="password-field" class="mdf-textfield__input" type="password" minlength="8" maxlength="12" pattern="[a-zA-Z0-9]+">
    <div class="mdf-textfield__helper-line">
        <span class="mdf-textfield__helper"></span>
    </div>

    <button class="mdf-textfield__button mdf-textfield__button--toggle">
        <svg class="mdf-textfield__icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#visibility"></use>
            <use class="mdf-hidden" href="icons.svg#visibility-off"></use>
        </svg>
    </button>
</div>

Implementation

Classes

NameTypeDescription
mdf-textfieldParentContains the input elements
mdf-textfield--condensedModifierReduce the input's height
mdf-textfield--stretchModifierStretches the input to the width of its parent
mdf-textfield--disabledModifierGreys out the input, stops all interaction with the element
mdf-textfield--state-successModifierUsed in input validation, changes input colors to green
mdf-textfield--state-warningModifierUsed in input validation, changes input colors to yellow
mdf-textfield--state-errorModifierUsed in input validation, changes input colors to red
mdf-textfield--textareaModifierFor textarea elements
mdf-textfield--numberModifierFor number input elements
mdf-textfield--has-helperModifierPrepare the input for helper text (also used for error messages)
mdf-textfield--icon-leadingModifierPrepare the input for a leading icon
mdf-textfield--icon-trailingModifierPrepare the input for a trailing icon
mdf-textfield__labelChildLabel element, child to .mdf-textfield
mdf-textfield__label--floatingModifierMoves the label above the input
mdf-textfield__label--focusModifierFocus styles for the label
mdf-textfield__label--shakeModifierPlay the shake animation
mdf-textfield__inputChildInput element. Child to .mdf-textfield
mdf-textfield__iconChildIcon element. Child to .mdf-textfield
mdf-textfield__buttonChildButton element. Child to .mdf-textfield
mdf-textfield__helper-lineParent / ChildContains the helper text and text counter. Child to .mdf-textfield
mdf-textfield__helperChildHelper text, used to display useful information and errors. Child to .mdf-textfield__helper-line
mdf-textfield__helper--counterModifierUsed for the character counter

Properties

NameTypeDescription
.counterHTMLElementReturns the counter element
.helperHTMLElementReturns the helper element
.inputHTMLInputElementReturns the input element
.labelHTMLElementReturns the label element
.leadingIconHTMLElementReturns the leading icon element
.toggleHTMLElementReturns the password toggle element
.trailingIconHTMLElementReturns the trailing icon element
.typestringGet or set the input's type
.valuestringGet or set the input's value
.lengthnumberGet the value's current length
.minLengthnumberGet or set the input's minLength
.maxLengthnumberGet or set the input's maxLength
.minstringGet or set the input's min
.maxstringGet or set the input's max
.stepstringGet or set the input's step
.patternstringGet or set the input's pattern
.requiredbooleanGet or set the input's required state
.disabledbooleanGet or set the input's disabled state
.prefixstringGet or set the prefix text
.suffixstringGet or set the suffix text
.messagestringGet or set the helper message
.validatebooleanGet or set if the input should use validation (defaults to true)
.statestringGet the current input state
.setState(state)(string): voidSet the current input state. Valid value are Success Warning Error
.clearState()(): voidClear the current input state
.setError(error)(string): voidSet Error state and display the given error message
.clearError()(): voidClear input state and remove message
.floatLabel(float)(boolean): voidFloat the label or restore the default position
.focusLabel(focus)(boolean): voidFocus the label or remove focus from it
.shakeLabel()(): voidShake the label to indicate an invalid input

Keywords

FAQs

Package last updated on 27 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc