0.44.1 • Published 5 years ago

@shortcm/notched-outline v0.44.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Notched Outline

The notched outline is a border around all sides of either a Text Field or Select component. This is used for the Outlined variant of either a Text Field or Select.

Design & API Documentation

Installation

npm install @material/notched-outline

Basic Usage

HTML Structure

<div class="mdc-notched-outline">
  <div class="mdc-notched-outline__leading"></div>
  <div class="mdc-notched-outline__notch">
    <label class="mdc-floating-label">Label</label>
  </div>
  <div class="mdc-notched-outline__trailing"></div>
</div>

Note that the MDC Floating Label component is placed inside the notch element when used together with MDC Notched Outline.

See the MDC Text Field and MDC Select documentation for information on using Notched Outline in the context of those components.

Styles

@import "@material/notched-outline/mdc-notched-outline";

JavaScript Instantiation

import {MDCNotchedOutline} from '@material/notched-outline';

const notchedOutline = new MDCNotchedOutline(document.querySelector('.mdc-notched-outline'));

See Importing the JS component for more information on how to import JavaScript.

Style Customization

CSS Classes

CSS ClassDescription
mdc-notched-outlineMandatory. Container for the outline's sides and notch.
mdc-notched-outline--notchedModifier class to open the notched outline.
mdc-notched-outline__leadingMandatory. Element representing the leading side of the notched outline (before the notch).
mdc-notched-outline__notchMandatory. Element representing the notch.
mdc-notched-outline__trailingMandatory. Element representing the trailing side of the notched outline (after the notch).

Sass Mixins

MixinDescription
mdc-notched-outline-color($color)Customizes the border color of the notched outline.
mdc-notched-outline-stroke-width($width)Changes notched outline width to a specified pixel value.
mdc-notched-outline-shape-radius($radius, $rtl-reflexive)Sets the rounded shape to notched outline element with given radius size. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to false.
mdc-notched-outline-floating-label-float-position($positionY, $positionX, $scale)Sets the position and scale of the floating label inside the notched outline.

MDCNotchedOutline Properties and Methods

Method SignatureDescription
notch(notchWidth: number) => voidOpens the notch with the specified width.
closeNotch() => voidCloses the notch, rendering a full outline.

Usage Within Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Notched Outline for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.

MDCNotchedOutlineAdapter

Method SignatureDescription
addClass(className: string) => voidAdds a class to the notched outline element.
removeClass(className: string) => voidRemoves a class from the notched outline element.
setNotchWidthProperty(width: number) => voidSets the width of the notch in pixels.
removeNotchWidthProperty() => voidRemoves the width property from the notch element.

MDCNotchedOutlineFoundation

Method SignatureDescription
notch(notchWidth: number) => voidAdds the mdc-notched-outline--notched class and updates the notch element's style based on notchWidth.
closeNotch() => voidRemoves the mdc-notched-outline--notched class.