Giter Club home page Giter Club logo

md-color-picker's Introduction

md-color-picker

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

NPM version BOWER version Build Status

preview

Demo

Try out the demo here: GitHub Page

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-color-picker.
npm install md-color-picker

Bower (includes tinycolor.js):

bower install md-color-picker

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-color-picker/dist/mdColorPicker.min.css" rel="stylesheet" />
  • Include the javascript.
<script src="path/to/tinycolor/dist/tinycolor-min.js"></script>
<script src="path/to/md-color-picker/dist/mdColorPicker.min.js"></script>
  • Add dependencies to your application (ngCookies is optional)
var app = angular.module('myApp', ['ngMaterial','ngCookies', 'mdColorPicker']);
  • 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-color-picker ng-model="valueObj"></div>

Options

Options may be set either by an options object on the md-color-picker 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-color-picker="scopeVariable.options" ng-model="scopeVariable.color"></div>

Setting options by attribute

<div
    md-color-picker
    ng-model="scopeVariable.color"
    label="Choose a color"
    icon="brush"
    default="#f00"
    md-color-generic-palette="false"
    md-color-history="false"
></div>
Option Object name Attribute Option name Type Default Description
type type Int 0 Default output type. 0: hex, 1: rgb, 2: hsl
label label String "" The lable for the input.
icon icon String "" Material Icon name. https://design.google.com/icons/
random random Boolean false Select a random color on open
default default Color "rgb(255,255,255)" Default color
openOnInput open-on-input Boolean true Open color picker when user clicks on the input field. If disabled, color picker will only open when clicking on the preview.
hasBackdrop has-backdrop Boolean true Dialog Backdrop. https://material.angularjs.org/latest/api/service/$mdDialog
clickOutsideToClose click-outside-to-close Boolean true Dialog click outside to close. https://material.angularjs.org/latest/api/service/$mdDialog
skipHide skip-hide Boolean true Allows for opening multiple dialogs. angular/material#7262
preserveScope preserve-scope Boolean true Dialog preserveScope. https://material.angularjs.org/latest/api/service/$mdDialog
clearButton md-color-clear-button Boolean true Show the "clear" button inside of the input.
preview md-color-preview Boolean true Show the color preview circle next to the input.
alphaChannel md-color-alpha-channel Boolean true Enable alpha channel.
spectrum md-color-spectrum Boolean true Show the spectrum tab.
sliders md-color-sliders Boolean true Show the sliders tab.
genericPalette md-color-generic-palette Boolean true Show the generic palette tab.
materialPalette md-color-material-palette Boolean true Show the material colors palette tab.
history md-color-history Boolean true Show the history tab.
hex md-color-hex Boolean true Show the HEX values tab.
rgb md-color-rgb Boolean true Show the RGB values tab.
hsl md-color-hsl Boolean true Show the HSL values tab.
defaultTab md-color-default-tab String, 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.
  • spectrum
  • sliders
  • genericPalette
  • materialPalette
  • history

Disclaimer

This is still in a very early beta, and is rapidly changing (3 versions before initial commit). I am open to any and all help anyone is willing to put in. Will update as we go.

Known issues / TODO

[ ] Break apart md-color-picker into other directives, md-color-picker-preview , input, etc. [ ] Add i18n support. [ ] Refactor LESS [ ] Add optional SASS file [ ] IE 11 Issues [ ] Inline dropdown mode [ ] Validation

md-color-picker's People

Contributors

alerosa avatar brianpkelley avatar chris0550 avatar frank3k avatar fxding avatar groetzi avatar idonteatsoap avatar janvandenberg avatar jglanz avatar josefromsanjose avatar langan avatar mustafahlvc avatar thom-x avatar volodymyrlut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

md-color-picker's Issues

Not selecting in modal

Good day!
This colorpicker is inactive when I put md-color-input into the modal?
It opens and seems fine, but I am not able to select any of colors, but when I close the modal it is able to select colors. Need help.
Do anyone have some suggestions?

Regards, Vadim.

Directive boolean attributes not evaluating

When passing a boolean to the directive it is interpenetrated as a string. mdDialog is treating "false" as true. Need to cast the value to boolean when "true" or "false"

image

colorpicker in ionic

Hi! color picker not selecting properly in ionic framework on the tablet. Any help?
Thanks!!!

installation problem

I installed latest version tinycolor and imported(included) this in my app. All worked fine.
then I was installing md-color-picker and tried include md-color-picker, but got the error. 'tinycolor is not defined'. I am tried download tinycolor with bower and npm. nothing changed...

Console logging

Hi,

Great directive.

Can anything be done about all the logging to console? Especially in the minified version..?

Opening colour picker from another modal dialog

We are launching the colour picker from another modal "md-dialog"
This causes the calling dialog to be closed and we can't return to it once the colour picker has been closed

Is there any way to configure or set up the colour picker in order to work together with other modal dialogs ?

Thanks

Strange error: 'mdColorPicker' is non-assignable!

The color picker was working perfectly, then one day the little color icon disappeared. Then today we got a report from a user and here's the message that we're seeing:

vendor.js:25 Error: [$compile:nonassign] Expression 'undefined' in attribute 'mdColorPreview' used with directive 'mdColorPicker' is non-assignable!

Any idea what that might mean?

md-color validation problem

I can't validate md-color in a form because is missing the name attribute in the input filed.
Also i can't put inside ng-messages and add a custom validation (By directive) on input field.

Es.
<md-input-container class="md-block" > <label>Label</label> <input type="email" ** name="name"** ng-model="model" **custom-validator** /> **<ng-messages> <ng-message><ng-message> </ng-messages>** </md-input-container>

I'm trying to solve this by using another version of template mdColorPicker.tpl.html in order to put inside the the missing elements, but is not a good solution.

Do you have a suggestion?

Thanks

customisations....

Any chance we can add some options to allow customisation of the UI?
For example

  1. hide elements of the UI we dont want to make available..
  2. limit the colors to a specific pallet
  3. hide the heading, tabs etc

That sort of thing....

Palette not shown in dialog

Hi.
When dialog is loaded is seems to be everything ok, but when browsing through tabs, the palette tab seems to be empty. Debug shows that palette is created correctly from template but cell containing de colors have a 0px width value (value rendered by browser from css configuration):
palette
If template forces a width value as does with heigh it works, line 879:
<div ng-repeat="col in row track by $index" flex="10" style="height: 25.5px;width: 25.5px;" ng-style="{\'background\': col};" ng-click="setPaletteColor($event)"></div>' +
But this is probably not the most elegant way to do it. It seems that flex is not working. Please, could you give some instructions to solve the problem?

Thanks.

Usage with Meteor

Hi there,

I was wondering if there is a way to import the package using ES6 module loaders, I am attempting to use it with Meteor with no success.

Thanks in advance

Launch from a click

Is there any way to launch the color picker from a button instead of the input/preview?

Set min and max attributes on number input

The number input should have set the following min and max attributes and optional the step attribute (default is 1). Furthermore for better mobile support set the pattern attribute: http://bradfrost.com/blog/mobile/better-numerical-inputs-for-mobile-forms/

R: <input type="number" min="0" max="255" pattern="[0-9]*">
G: <input type="number" min="0" max="255" pattern="[0-9]*">
B: <input type="number" min="0" max="255" pattern="[0-9]*">

A: <input type="number" min="0" max="1" step="0.05" pattern="[0-9]*">
(step increase/decrease by 5%).

image

Translations

Currently translations are not working.

label="{{LABEL | translate}}"

Does not work yet.

Slow dialog opening

It's takes about a second to open the dialog. What's wrong with it?
How can I speed it up?
feb 12 2016 16 00

Color picker not working on IE11

When running the plunker demo example you will already see that some tabs (second and third tab) are not rendered well in IE 11.
Seems some styling/css issues?
ie11colorpicker

CMYK support

Your component is amazing! But I'm currently working in a project from a printing company and they use CMYK color pattern, I know I can convert hex to CMYK after the user picks a color, but I want to know if it's possible to show the CMYK value directly in the component input area.

Can not select pure white / black.

I am trying the demo, and using the spectrum I can't seem to be able to select pure white or pure black. The upper left corner is something like "#fffefe" instead of "#ffffff".

I've tried using Firefox, Chrome and IE11 on Win7.

Clear button out of line

When you set a predefined value the clear button goes below the input container, but when you clear and select another color it looks fine.

icons not showing

O am running the latest angular material and I included angular material icons for safe measure why do I then get text and not the icons.

option for hide clear button

it is a small wish.
of course, you can write

.md-color-picker-clear{
    display: none;
}

but it's a little crutch.
ps. great thanks

Feedback / suggestions

Hi Brian,

Great work on this directive. I just wanted to give some general thoughts as it's still at a (relatively) early stage.

Remove/separate the history functionality

It seems beyond the scope of the directive to manage history and a tough ask to fit every users needs.

Simplify input template

The key part(s) of the directive is the dialog. The preview/icon/clear button could be separated to allow more flexible implementations and customisation. For instance removing the floating label etc.

Consolidate generic/material pallete tabs

Eventually an option for specifying your own palettes here would be good, optionally defaulting to the generic/material palettes.

Switch from LESS to SCSS

SCSS is used in the Angular Material project so it'd be easier to integrate into projects and allow for use of their variables.

I'd be great to get your thoughts then perhaps I can contribute some.

Thanks,
James

npm installation v0.2.6

I have installed md-color-picker through npm. My .js file does not contain all the features you have in v0.2.6. I noticed that files in your master branch are not the same with your develop branch. Could you fix npm installation so it will have all the features?

P.S. Specifically, I am interested in hiding RGB and HSL tabs, but code for this functionality is not included in npm installation.

l.getObject is not a function

I have installed color picker and have been following your instructions on the main page. However, I was keep getting the same error for your options, more to the point at the history.

$scope.navbarBgColor.options = {
        label: "Choose a color",
        icon: "brush",
        default: "#f00",
        genericPalette: false,
        history: false
      }

with <div md-color-picker="navbarBgColor.options" ng-model="navbarBColor.color"></div>.

The error also occurs when I implement the options as an attribute of the div.

Disable autoselection of the value on open

When the popup opens, it auto selects the value at the top. This brings up the keyboard when you are doing it on mobile. Is there anyway to disable this auto selection?

If Material Palette is not configured correctly then directive throws an error.

This obviously isn't a bug with this directive but on line 768 you are looping through the app's material palette and have the backgroundColor set to the 3 RGB values via value['500'].value[0,1,2]. If the app has a custom palette defined that is not configured per the angular spec (as mine is I think. I just use the hex not RGB values) then there is only a single value['500'].value[0] which eventually will throw an error when the 2nd value is not there.

e.g

var green = $mdThemingProvider.extendPalette('green', { '500' : '#028015'});
$mdThemingProvider.definePalette('green', 'green'); //was overriding but is not configured correctly.

Love the work you have done so far!

ng-model not updating by click on clear button

mdColorPicker.js line 482
if (newVal !== '' && typeof newVal !== 'undefined' && newVal && newVal !== oldVal) {
Why did you use this in condition? This means I could never return to default background

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.