1.1.1 • Published 5 years ago

md-rainbow v1.1.1

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

md-rainbow

This is a fork of the awesome md-color-picker project by Brian Kelley.

Angular-Material based color picker with no jQuery or other DOM/utility library dependencies.

preview

Install

NPM

  1. Download tinycolor.js 1.2.1 or higher. Other versions may work, though 1.2.1 was used to develop this.
  2. Install md-rainbow.
npm install md-rainbow

Angular dependencies

Other dependencies

The only other dependency is tinycolor.js which is an exceptional color manipulation library.

Usage

  • Include the css.
<link href="path/to/md-rainbow/dist/mdRainbow.min.css" rel="stylesheet" />
  • Include the javascript.
<script src="path/to/tinycolor/dist/tinycolor-min.js"></script>
<script src="path/to/md-rainbow/dist/mdRainbow.min.js"></script>
  • Add dependencies to your application (ngCookies is optional)
var app = angular.module('myApp', ['ngMaterial','ngCookies', 'mdRainbow']);
  • Place the directive wherever it is needed. note: this breaks the old version 0.1 as it now uses ng-model instead of value
<div md-rainbow ng-model="valueObj"></div>

Options

Options may be set either by an options object on the md-rainbow attribute and/or using attributes. If an option is present on both the options object and as an attribute, the attribute will take precedence.

Setting options by scope object

// Controller
$scope.scopeVariable.options = {
    label: "Choose a color",
    icon: "brush",
    default: "#f00",
    genericPalette: false,
    history: false
};
<div md-rainbow="scopeVariable.options" ng-model="scopeVariable.color"></div>

Setting options by attribute

<div
    md-rainbow
    ng-model="scopeVariable.color"
    label="Choose a color"
    icon="brush"
    default="#f00"
    md-color-generic-palette="false"
    md-color-history="false"
></div>
Option Object nameAttribute Option nameTypeDefaultDescription
typetypeInt0Default output type. 0: hex, 1: rgb, 2: hsl
labellabelString""The lable for the input.
iconiconString""Material Icon name. https://design.google.com/icons/
randomrandomBooleanfalseSelect a random color on open
defaultdefaultColor"rgb(255,255,255)"Default color
openOnInputopen-on-inputBooleantrueOpen color picker when user clicks on the input field. If disabled, color picker will only open when clicking on the preview.
hasBackdrophas-backdropBooleantrueDialog Backdrop. https://material.angularjs.org/latest/api/service/$mdDialog
clickOutsideToCloseclick-outside-to-closeBooleantrueDialog click outside to close. https://material.angularjs.org/latest/api/service/$mdDialog
skipHideskip-hideBooleantrueAllows for opening multiple dialogs. https://github.com/angular/material/issues/7262
preserveScopepreserve-scopeBooleantrueDialog preserveScope. https://material.angularjs.org/latest/api/service/$mdDialog
okTextok-textStringSelectLabel for ok button.
cancelTextcancel-textStringCancelLabel for cancel button.
clearButtonmd-color-clear-buttonBooleantrueShow the "clear" button inside of the input.
previewmd-color-previewBooleantrueShow the color preview circle next to the input.
alphaChannelmd-color-alpha-channelBooleantrueEnable alpha channel.
spectrummd-color-spectrumBooleantrueShow the spectrum tab.
slidersmd-color-slidersBooleantrueShow the sliders tab.
genericPalettemd-color-generic-paletteBooleantrueShow the generic palette tab.
materialPalettemd-color-material-paletteBooleantrueShow the material colors palette tab.
historymd-color-historyBooleantrueShow the history tab.
hexmd-color-hexBooleantrueShow the HEX values tab.
rgbmd-color-rgbBooleantrueShow the RGB values tab.
hslmd-color-hslBooleantrueShow the HSL values tab.
defaultTabmd-color-default-tabString, Int"spectrum"Which tab should be selected when opening. Can either be a string or index. If the value is an index, do not count hidden/disabled tabs. spectrumslidersgenericPalettematerialPalettehistory