Polymer-based web components for D2L image-actions

[ This description is mirrored from README.md at github.com/BrightspaceUI/image-action on 2019-05-22 ]

Looking for SASS-based d2l-image-action? It's over here.

d2l-image-action

Published on webcomponents.org Bower version Build status

Polymer-based web component for D2L image actions, which are buttons or links associated with an image that perform an action when clicked.

screenshot of image actions

For further information on this and other Brightspace UI components, see the docs at ui.developers.brightspace.com.

Installation

d2l-image-action can be installed from Bower:

bower install d2l-image-action

Usage

Include the webcomponents.js "lite" polyfill (for browsers who don't natively support web components), then import d2l-image-action.html to get all three image-action web components:

<head>
  <script src="../webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="../d2l-image-action/d2l-image-action.html">
</head>

Button-based actions

Use <d2l-image-action-button> in cases where an action is being performed, and not a navigation. Actions are typically done using a click event handler. Think about times you'd use a native <button> element instead of an <a>.

<d2l-image-action-button icon="d2l-tier1:bookmark-hollow">Bookmark</d2l-image-action-button>

Link-based actions

Alternatively, if you wish to perform a browser navigation when the action is clicked, use <d2l-image-action-link>. Think of places you'd use a native <a> element instead of a <button>.

<d2l-image-action-link href="settings.html" icon="d2l-tier1:gear">
  Settings
</d2l-image-action-link>

Icons

As their name suggests, image-actions are intended to be used with an icon, specifically one which is 18px by 18px in size. To set the icon, use the icon attribute, which takes a reference to a Polymer iron-iconset-svg source.

The d2l-icons component exposes all of the D2L icons as iron-iconset-svg sources -- simply import them using the tier1 category (for 18x18 icons) and reference them by key:

<link rel="import" href="../d2l-icons/tier1-icons.html">
<button is="d2l-image-action" icon="d2l-tier1:print">Print</button>

You can also create your own custom icon set -- simply follow Polymer's documentation.

Groups of image-actions

Often, multiple image-actions will appear together as a group. In order to properly space the actions out, wrap them in a <d2l-image-action-group> custom element:

<d2l-image-action-group>
  <d2l-image-action-button icon="d2l-tier1:print">Print</d2l-image-action-button>
  <d2l-image-action-link icon="d2l-tier1:gear" href="http://www.google.ca">
    Settings
  </d2l-image-action-link>
  <d2l-image-action-button icon="d2l-tier1:help">Help</d2l-image-action-button>
</d2l-image-action-group>

Developing, Testing and Contributing

After cloning the repo, run npm install to install dependencies.

If you don't have it already, install the Polymer CLI globally:

npm install -g polymer-cli

To start a local web server that hosts the demo page and tests:

polymer serve

To lint (eslint and Polymer lint):

npm run lint

Install

Link to this version
ImportedReleased 27 April 2018Apache License 2.0
Framework Support
Polymer 2.0+
Also supported:
Polymer 1 (1.0.1)
Browser Compatibility
Install with
bower install --save BrightspaceUI/image-action"#2.1.0"
Run the above Bower command in your project folder. If you have any issues installing, please contact the author.
Release notes - Version 2.1.0

Dependencies

  • d2l-button#^4.0.2
  • d2l-colors#^3.1.2
  • d2l-icons#^4.5.1
  • d2l-link#^4.0.1
  • d2l-polymer-behaviors#^1.3.0
  • d2l-typography#^6.0.0
  • polymer#1.9 - 2