1.0.2 • Published 7 years ago

polythene-button v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Button

Displays a text button with a ripple effect.

See also: Raised Button, Icon Button and Floating Action Button

Usage

import m from "mithril";
import { button } from "polythene-button";

const myButton = m(button, {
  label: "Button"
});

Add a URL:

const myButton = m(button, {
  label: "Button",
  url: {
    href: "/index",
    oncreate: m.route.link
  }
});

Add an onclick event:

const myButton = m(button, {
  label: "Button",
  events: {
    onclick: () => console.log("click")
  }
});

Variations

  • The hover effect can be hidden with wash: false.
  • The ripple effect on click can be hidden with ink: false.
  • Button contains no icon as this is not part of the Material Design guidelines; use icon Button instead

Mobile and tap delay

To remove the tap delay on mobile devices it is advisable to use a library like Fastclick. But because Fastclick has an unresolved issue with tap events while scrolling on iOS, it is better to use the convenience wrapper provided in "polythene-fastclick". This temporarily removes the Fastclick event when an element is being scrolled.

import "polythene-fastclick";

Options

Common component options

ParameterMandatoryTypeDefaultDescription
elementoptionalString"a"HTML element tag; may also be "button"
classoptionalStringExtra CSS class appended to pe-button
idoptionalStringHTML element id
contentuse label or contentMithril elementAlternative content; replaces vnode.children and ignores label
beforeoptionalMithril elementExtra content before main content; note that this content is placed left of subsequent elements with a lower stacking depth
afteroptionalMithril elementExtra content after main content; note that this content is placed right of preceding elements with a higher stacking depth
eventsoptionalObjectOptions object containing one or more standard events such as onclick
tabindexoptionalInteger0Tab index

Button specific options

ParameterMandatoryTypeDefaultDescription
labeluse label or contentStringThe button label
urloptionalObject with href, optionally oncreateURL location; for in-app route linking set oncreate : m.route.link
disabledoptionalBooleanfalseDisables the button
selectedoptionalBooleanfalseSet to true to show the button as selected
formactionoptionalString"The URI of a program that processes the information submitted by the button. If specified, it overrides the action attribute of the button"s form owner." source:MDN
animateOnTapoptionalBooleantrueSet to false to remove z-animation and subsequent redraw
inactiveoptionalBooleanSet to true to disable button events and ripple/wash effects
inactivateoptionalNumberThe number of seconds after tap/click when the button is inactive; useful to prevent double clicks

Button appearance options

ParameterMandatoryTypeDefaultDescription
washoptionalBooleantrueSet to false to hide the effect on hover
inkoptionalBooleantrueSet to false to disable the ripple effect on click/tap
rippleoptional (valid if ink is true)Options objectPass ripple options to define ripple behavior
increaseoptionalNumber1The z-index increment/decrement on tap; note that the maximum z value is 5
bordersoptionalBooleanfalseSet to true to add a border; by default the border has no color - set border color to class pe-button__content to see the border

Composition

Button is composed from:

  • Ripple (when option ink is not false)

CSS classes

ElementKeyClass
Componentcomponentpe-button pe-button--text
Contentcontentpe-button__content
Labellabelpe-button__label
Wash elementwashpe-button__wash
Focus elementfocuspe-button__focus
StateKeyClass
Selectedselectedpe-button--selected
Disableddisabledpe-button--disabled
Has bordersborderspe-button--borders
Inactiveinactivepe-button--inactive
Focusfocusedpe-button--focus

Future

  • Option to wait for ripple to finish before url/event is followed