1.0.0-rc.1 • Published 7 years ago

polythene-list-tile v1.0.0-rc.1

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

List Tile

Displays a list element as part of a list.

Usage

import m from "mithril";
import listTile from "polythene-list-tile";

const myListTile = m(listTile, {
  title: "My title"
});

To show the subtitle on 1 line:

const myListTile = m(listTile, {
  title: "My title",
  subtitle: "My subtitle"
});

To show a long subtitle running on 2 lines:

const myListTile = m(listTile, {
  title: "My title",
  highSubtitle: "My loooooooooooong subtitle"
});

To show an icon:

import m from "mithril";
import listTile from "polythene-list-tile";
import icon from "polythene-icon";

const myListTile = m(listTile, {
  title: "My title",
  front: m(icon, {
    type: "large",
    avatar: true,
    src: "app/images/1.png"
  })
});

Or use an SVG as icon:

import m from "mithril";
import listTile from "polythene-list-tile";
import icon from "polythene-icon";
import iconStarOutline from "mmsvg/templarian/msvg/star-outline";

const myListTile = m(listTile, {
  title: "My title",
  front: m(icon, {
    msvg: iconStarOutline
  })
});

To make the primary content a link:

const myListTile = m(listTile, {
  title: "My title",
  front: m(icon, {
    type: "large",
    avatar: true,
    src: "app/images/1.png"
  }),
  url: {
    href: "/toolbar"
    oncreate: m.route.link
  }
});

To show secondary content at the right, including a link:

import icon from "polythene-icon";
import iconStarOutline from "mmsvg/templarian/msvg/star-outline";

const myListTile = m(listTile, {
  title: "My title",
  front: m(icon, {
    type: "large",
    avatar: true,
    src: "app/images/1.png"
  }),
  secondary: {
    icon: {
      type: "small",
      msvg: iconStarOutline
    },
    url: {
      href: "/favs",
      oncreate: m.route.link
    }
  })
});

Variations

  • A list tile can have 1 to 3 lines:
    • title: titel on a single line
    • subtitle: subtitle on a single line
    • highSubtitle: subtitle runs over 2 lines
    • Use class list-tile--compact to reduce the vertical padding.
  • A list tile can optionally have an icon.
  • Text and icon are taken together as primary content. Primary content can optionally have a link.
  • A list tile can optionally have secondary content, displayed to the right. Secondary content can contain any content, and conditionally have a link.

Options

Common component options

ParameterMandatoryTypeDefaultDescription
elementoptionalString"div"HTML element tag
classoptionalStringExtra CSS class appended to "pe-list-tile"
styleoptionalObjectFor setting simple style attributes
idoptionalStringHTML element id
eventsoptionalObjectOptions object containing one or more standard events such as onclick
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

List tile content options

ParameterMandatoryTypeDefaultDescription
content--See below
secondaryoptionalObjectOptions for secondary content, see below

List tile appearance options

ParameterMandatoryTypeDefaultDescription
indentoptionalBooleanSet to true to indent the content
selectedoptionalBooleanfalseSet to true to show a selected state; adds class "selected"
disabledoptionalBooleanfalseSet to true to deactivate the url and hover state (in case of list with setting hoverable) and show a disabled state; adds class "disabled"
inkoptionalBooleanfalseSet to true to show a ripple effect when the tile is tapped
rippleoptional (valid if ink is true)Options objectPass ripple options to define ripple behavior
hoverableoptionalBooleanfalseSet to true to show a hover effect (non-touch devices)
selectableoptionalBooleanfalseSet to true to show a mouse pointer (non-touch devices)
stickyoptionalBooleanMake list tile sticky when scrolling; this is normally set in the list component as header.sticky; does not work in Chrome or IE/Edge; adds class "sticky"
compactoptionalBooleanSet to true to reduce vertical padding

List tile primary content options

ParameterMandatoryTypeDefaultDescription
contentoptionalMithril elementAny primary content; replaces vnode.children and ignores title, subTitle and highSubtitle
titleoptionalStringThe text content
subtitleoptionalStringSecondary text content (1 line high)
highSubtitleoptionalStringSecondary text content (2 lines high)
frontoptionalMithril element or componentContent to show at the left of the primary content
urloptionalObject with href, optionally oncreateURL location; for in-app route linking set oncreate : m.route.link

List tile secondary content options

ParameterMandatoryTypeDefaultDescription
secondary.elementoptionalStringSee "Layout of secondary content" belowHTML element for secondary content
secondary.iconoptionalObjecticon options object for icon in secondary content; will be placed above secondary.content
secondary.urloptionalObject with href, optionally oncreateURL for secondary content; for in-app route linking set oncreate : m.route.link
secondary.contentoptionalMithril elementSecondary content

Composition

List Tile is composed from:

  • Ripple (when option ink is used)
  • Icon (when option secondary.icon is used)

CSS classes

ElementKeyClass
Componentcomponentpe-list-tile
Primary elementprimarype-list-tile__primary
Secondary elementsecondarype-list-tile__secondary
Contentcontentpe-list-tile__content
Front contentcontentFrontpe-list-tile__content--front
Titletitlepe-list-tile__title
Subtitlesubtitlepe-list-tile__subtitle
High subtitlehighSubtitlepe-list-tile__high-subtitle
StateKeyClass
Selectedselectedpe-list-tile--selected
Disableddisabledpe-list-tile--disabled
Stickystickype-list-tile--sticky
Has subtitlehasSubtitlepe-list-tile--subtitle
Has high subtitlehasHighSubtitlepe-list-tile--high-subtitle
Has front contenthasFrontpe-list-tile--front
Compactcompactpe-list-tile--compact
Hoverablehoverablepe-list-tile--hoverable
Selectableselectablepe-list-tile--selectable