How we can create a color picker with material design? Solution: See this Material Color Picker With Copy To Clipboard Feature, Color Palette with Material design.
Previously I have shared a gradient generator program, where you can pick a color. But this is a color picker with material design, where you can pick or choose a color from the palette. Basically, a color picker helps you to choose a color and you can select the versions of color like light and dark. And the material design is a grid-based layout where animation, light and dark shadows create the design. Mostly a material color picker contains a bunch of colors with their light and dark variants.
Today you will learn to create Color Palette with material design. Basically, there are 19 different colors and each has 10 variants. All colors have 10 different shades that go light to dark and darker. Each color box has the color code and % percentage values of the color which make color light and dark. After choosing a color you can simply copy the color code by clicking above the box, because there is a copy to the clipboard feature.
So, Today I am sharing Material Color Picker With Copy To Clipboard Feature. There I have used some JS libraries to creating the program like knockout JS and clipboard JS. There knockout JS for change colors without loading or reloading, and clipboard js for copy in a single click. This is a responsive design, it will fit on every screen size. You can use this program on your website, it can be placed on the backend in the customize section or in frontend for users.
If you are thinking now how this material color palette actually is, then see the preview given below.
Preview Of Color Palette With Light and Dark Variants
See this video preview to getting an idea of how this color pick program looks like.
Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
Material Color Picker With Copy To Clipboard Feature Source Code
Before sharing source code, let’s talk about it. First I have created the main div named container and placed all items inside it. There are two div sections, and each section contains many divs. There I have created input and div and place values using the data-bind attribute, which is powered by knockout JS. Inside all tags, I have placed values and commands using the Data-* attribute. Also in the HTML file, I have linked other files like CSS, JS, and JS libraries CDN.
Now using CSS I have placed all the elements in the right place, as you can see in the preview. With CSS first I gave basic values like size, position, margin, padding, etc to all the elements. There I have used flex display command to create the layout responsive. I used transition command for smooth animation effects, and transform command for transformation.
JavaScript file handling here the copy to clipboard and color palette feature in the program. There all codes are pre-functioned by the library which I have used. There put commands for copy according to clipboard JS library. And placed color values and names like JSON structured data types. Left all other things you will understand after getting the codes.
For creating this program you have to create 3 files. First file for HTML, second for CSS, and the third file for JavaScript. Follow the steps to creating this program without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>Material Color Picker | Webdevtrick.com</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="./style.css"> </head> <body> <div class="container"> <div class="material-color-picker"> <div class="material-color-picker__left-panel"> <ol class="color-selector" data-bind="foreach: materialColors"> <li> <input name="material-color" type="radio" data-bind="attr: { id: 'materialColor' + $index() }, checked: selectedColor, value: color" > <label data-bind="attr: { for: 'materialColor' + $index(), title: color }, style: { 'color': $data.variations[4].hex }"></label> </li> </ol> </div> <div class="material-color-picker__right-panel" data-bind="foreach: materialColors"> <div class="color-palette-wrapper" data-bind="css: { 'js-active': selectedColor() === color }"> <h2 class="color-palette-header" data-bind="text: color"></h2> <ol class="color-palette" data-bind="foreach: variations"> <li id="clipboardItem" class="color-palette__item" data-bind="attr: { 'data-clipboard-text': hex }, style: { 'background-color': hex }"> <span data-bind="text: weight"></span> <span data-bind="text: hex"></span> <span class="copied-indicator" data-bind="css: { 'js-copied': copiedHex() === hex }">Color copied!</span> </li> </ol> </div> </div> </div> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.10/clipboard.min.js'></script> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ @import url(https://fonts.googleapis.com/css?family=Roboto:400,500|Roboto+Mono:500); html { box-sizing: border-box; height: 100%; } *, *:before, *:after { box-sizing: inherit; } @media (prefers-reduced-motion: reduce) { *, *:before, *:after { -webkit-animation-duration: 0ms !important; animation-duration: 0ms !important; -webkit-transition-duration: 0ms !important; transition-duration: 0ms !important; } } body { height: 100%; } img { max-width: 100%; height: auto; } html { background-color: #b0bec5; font-family: "Roboto", sans-serif; font-weight: 500; } .container { padding: 1em; } .material-color-picker { display: -webkit-box; display: flex; width: 32em; max-width: 100%; margin: 0 auto; background-color: white; border: 1px solid #78909c; border-radius: 0.5em; box-shadow: 0 1em 8em rgba(0, 0, 0, 0.35); } .material-color-picker__left-panel { z-index: 1; } .material-color-picker__right-panel { position: relative; -webkit-box-flex: 1; flex-grow: 1; overflow: hidden; } .color-selector { margin: 0; padding: 0; list-style: none; display: -webkit-box; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; flex-direction: column; padding: 1em 0; border-right: 0.25em solid #E0E0E0; } .color-selector input[type='radio'] { display: none; } .color-selector label { position: relative; display: inline-block; padding: 0.5em 1.5em; cursor: pointer; } .color-selector label:before { content: ''; display: inline-block; vertical-align: middle; padding: 0.75em; background-color: currentColor; border-radius: 50%; } .color-selector label:after { content: ''; position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); padding: 0.5em; border: 0.25em solid; border-radius: 50%; -webkit-transition: padding 250ms; transition: padding 250ms; } .color-selector input[type='radio']:checked + label:after { padding: 1em; } .color-palette-wrapper { position: absolute; top: 0; right: 0; bottom: 0; left: 0; -webkit-transform: translateX(-100%); transform: translateX(-100%); display: -webkit-box; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; flex-direction: column; padding: 1.5em; } .color-palette-wrapper.js-active { -webkit-transform: translateX(0); transform: translateX(0); } .color-palette-header { display: -webkit-box; display: flex; -webkit-box-pack: justify; justify-content: space-between; margin: 0; margin-bottom: 1em; font-weight: 400; color: #757575; } .color-palette { margin: 0; padding: 0; list-style: none; display: -webkit-box; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; flex-direction: column; -webkit-box-flex: 1; flex-grow: 1; } .color-palette__item { position: relative; display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: justify; justify-content: space-between; -webkit-box-flex: 1; flex-grow: 1; margin: 0.25em 0; padding: 0 1em; border-radius: 0.25em; font-family: "Roboto Mono", monospace; -webkit-transition: -webkit-transform 250ms; transition: -webkit-transform 250ms; transition: transform 250ms; transition: transform 250ms, -webkit-transform 250ms; cursor: pointer; } .color-palette__item:hover { -webkit-transform: scale(1.05); transform: scale(1.05); } .copied-indicator { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, 0); transform: translate(-50%, 0); opacity: 0; -webkit-transition: all 250ms; transition: all 250ms; } .copied-indicator.js-copied { -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); opacity: 0.75; } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
// Code By Webdevtrick ( https://webdevtrick.com ) var copiedHex = ko.observable(); var clipboard = new Clipboard('#clipboardItem'); clipboard.on('success', function(el) { console.clear(); console.info('Action:', el.action); console.info('Text:', el.text); console.info('Trigger:', el.trigger); el.clearSelection(); copiedHex(el.text); }); /// var selectedColor = ko.observable("Red"); // lazy ko.applyBindings({ materialColors: [ { color: "Red", variations: [ { weight: 50, hex: "#FFEBEE" }, { weight: 100, hex: "#FFCDD2" }, { weight: 200, hex: "#EF9A9A" }, { weight: 300, hex: "#E57373" }, { weight: 400, hex: "#EF5350" }, { weight: 500, hex: "#F44336" }, { weight: 600, hex: "#E53935" }, { weight: 700, hex: "#D32F2F" }, { weight: 800, hex: "#C62828" }, { weight: 900, hex: "#B71C1C" } ] }, { color: "Pink", variations: [ { weight: 50, hex: "#FCE4EC" }, { weight: 100, hex: "#F8BBD0" }, { weight: 200, hex: "#F48FB1" }, { weight: 300, hex: "#F06292" }, { weight: 400, hex: "#EC407A" }, { weight: 500, hex: "#E91E63" }, { weight: 600, hex: "#D81B60" }, { weight: 700, hex: "#C2185B" }, { weight: 800, hex: "#AD1457" }, { weight: 900, hex: "#880E4F" } ] }, { color: "Purple", variations: [ { weight: 50, hex: "#F3E5F5" }, { weight: 100, hex: "#E1BEE7" }, { weight: 200, hex: "#CE93D8" }, { weight: 300, hex: "#BA68C8" }, { weight: 400, hex: "#AB47BC" }, { weight: 500, hex: "#9C27B0" }, { weight: 600, hex: "#8E24AA" }, { weight: 700, hex: "#7B1FA2" }, { weight: 800, hex: "#6A1B9A" }, { weight: 900, hex: "#4A148C" } ] }, { color: "Deep Purple", variations: [ { weight: 50, hex: "#EDE7F6" }, { weight: 100, hex: "#D1C4E9" }, { weight: 200, hex: "#B39DDB" }, { weight: 300, hex: "#9575CD" }, { weight: 400, hex: "#7E57C2" }, { weight: 500, hex: "#673AB7" }, { weight: 600, hex: "#5E35B1" }, { weight: 700, hex: "#512DA8" }, { weight: 800, hex: "#4527A0" }, { weight: 900, hex: "#311B92" } ] }, { color: "Indigo", variations: [ { weight: 50, hex: "#E8EAF6" }, { weight: 100, hex: "#C5CAE9" }, { weight: 200, hex: "#9FA8DA" }, { weight: 300, hex: "#7986CB" }, { weight: 400, hex: "#5C6BC0" }, { weight: 500, hex: "#3F51B5" }, { weight: 600, hex: "#3949AB" }, { weight: 700, hex: "#303F9F" }, { weight: 800, hex: "#283593" }, { weight: 900, hex: "#1A237E" } ] }, { color: "Blue", variations: [ { weight: 50, hex: "#E3F2FD" }, { weight: 100, hex: "#BBDEFB" }, { weight: 200, hex: "#90CAF9" }, { weight: 300, hex: "#64B5F6" }, { weight: 400, hex: "#42A5F5" }, { weight: 500, hex: "#2196F3" }, { weight: 600, hex: "#1E88E5" }, { weight: 700, hex: "#1976D2" }, { weight: 800, hex: "#1565C0" }, { weight: 900, hex: "#0D47A1" } ] }, { color: "Light Blue", variations: [ { weight: 50, hex: "#E1F5FE" }, { weight: 100, hex: "#B3E5FC" }, { weight: 200, hex: "#81D4FA" }, { weight: 300, hex: "#4FC3F7" }, { weight: 400, hex: "#29B6F6" }, { weight: 500, hex: "#03A9F4" }, { weight: 600, hex: "#039BE5" }, { weight: 700, hex: "#0288D1" }, { weight: 800, hex: "#0277BD" }, { weight: 900, hex: "#01579B" } ] }, { color: "Cyan", variations: [ { weight: 50, hex: "#E0F7FA" }, { weight: 100, hex: "#B2EBF2" }, { weight: 200, hex: "#80DEEA" }, { weight: 300, hex: "#4DD0E1" }, { weight: 400, hex: "#26C6DA" }, { weight: 500, hex: "#00BCD4" }, { weight: 600, hex: "#00ACC1" }, { weight: 700, hex: "#0097A7" }, { weight: 800, hex: "#00838F" }, { weight: 900, hex: "#006064" } ] }, { color: "Teal", variations: [ { weight: 50, hex: "#E0F2F1" }, { weight: 100, hex: "#B2DFDB" }, { weight: 200, hex: "#80CBC4" }, { weight: 300, hex: "#4DB6AC" }, { weight: 400, hex: "#26A69A" }, { weight: 500, hex: "#009688" }, { weight: 600, hex: "#00897B" }, { weight: 700, hex: "#00796B" }, { weight: 800, hex: "#00695C" }, { weight: 900, hex: "#004D40" } ] }, { color: "Green", variations: [ { weight: 50, hex: "#E8F5E9" }, { weight: 100, hex: "#C8E6C9" }, { weight: 200, hex: "#A5D6A7" }, { weight: 300, hex: "#81C784" }, { weight: 400, hex: "#66BB6A" }, { weight: 500, hex: "#4CAF50" }, { weight: 600, hex: "#43A047" }, { weight: 700, hex: "#388E3C" }, { weight: 800, hex: "#2E7D32" }, { weight: 900, hex: "#1B5E20" } ] }, { color: "Light Green", variations: [ { weight: 50, hex: "#F1F8E9" }, { weight: 100, hex: "#DCEDC8" }, { weight: 200, hex: "#C5E1A5" }, { weight: 300, hex: "#AED581" }, { weight: 400, hex: "#9CCC65" }, { weight: 500, hex: "#8BC34A" }, { weight: 600, hex: "#7CB342" }, { weight: 700, hex: "#689F38" }, { weight: 800, hex: "#558B2F" }, { weight: 900, hex: "#33691E" } ] }, { color: "Lime", variations: [ { weight: 50, hex: "#F9FBE7" }, { weight: 100, hex: "#F0F4C3" }, { weight: 200, hex: "#E6EE9C" }, { weight: 300, hex: "#DCE775" }, { weight: 400, hex: "#D4E157" }, { weight: 500, hex: "#CDDC39" }, { weight: 600, hex: "#C0CA33" }, { weight: 700, hex: "#AFB42B" }, { weight: 800, hex: "#9E9D24" }, { weight: 900, hex: "#827717" } ] }, { color: "Yellow", variations: [ { weight: 50, hex: "#FFFDE7" }, { weight: 100, hex: "#FFF9C4" }, { weight: 200, hex: "#FFF59D" }, { weight: 300, hex: "#FFF176" }, { weight: 400, hex: "#FFEE58" }, { weight: 500, hex: "#FFEB3B" }, { weight: 600, hex: "#FDD835" }, { weight: 700, hex: "#FBC02D" }, { weight: 800, hex: "#F9A825" }, { weight: 900, hex: "#F57F17" } ] }, { color: "Amber", variations: [ { weight: 50, hex: "#FFF8E1" }, { weight: 100, hex: "#FFECB3" }, { weight: 200, hex: "#FFE082" }, { weight: 300, hex: "#FFD54F" }, { weight: 400, hex: "#FFCA28" }, { weight: 500, hex: "#FFC107" }, { weight: 600, hex: "#FFB300" }, { weight: 700, hex: "#FFA000" }, { weight: 800, hex: "#FF8F00" }, { weight: 900, hex: "#FF6F00" } ] }, { color: "Orange", variations: [ { weight: 50, hex: "#FFF3E0" }, { weight: 100, hex: "#FFE0B2" }, { weight: 200, hex: "#FFCC80" }, { weight: 300, hex: "#FFB74D" }, { weight: 400, hex: "#FFA726" }, { weight: 500, hex: "#FF9800" }, { weight: 600, hex: "#FB8C00" }, { weight: 700, hex: "#F57C00" }, { weight: 800, hex: "#EF6C00" }, { weight: 900, hex: "#E65100" } ] }, { color: "Deep Orange", variations: [ { weight: 50, hex: "#FBE9E7" }, { weight: 100, hex: "#FFCCBC" }, { weight: 200, hex: "#FFAB91" }, { weight: 300, hex: "#FF8A65" }, { weight: 400, hex: "#FF7043" }, { weight: 500, hex: "#FF5722" }, { weight: 600, hex: "#F4511E" }, { weight: 700, hex: "#E64A19" }, { weight: 800, hex: "#D84315" }, { weight: 900, hex: "#BF360C" } ] }, { color: "Brown", variations: [ { weight: 50, hex: "#EFEBE9" }, { weight: 100, hex: "#D7CCC8" }, { weight: 200, hex: "#BCAAA4" }, { weight: 300, hex: "#A1887F" }, { weight: 400, hex: "#8D6E63" }, { weight: 500, hex: "#795548" }, { weight: 600, hex: "#6D4C41" }, { weight: 700, hex: "#5D4037" }, { weight: 800, hex: "#4E342E" }, { weight: 900, hex: "#3E2723" } ] }, { color: "Grey", variations: [ { weight: 50, hex: "#FAFAFA" }, { weight: 100, hex: "#F5F5F5" }, { weight: 200, hex: "#EEEEEE" }, { weight: 300, hex: "#E0E0E0" }, { weight: 400, hex: "#BDBDBD" }, { weight: 500, hex: "#9E9E9E" }, { weight: 600, hex: "#757575" }, { weight: 700, hex: "#616161" }, { weight: 800, hex: "#424242" }, { weight: 900, hex: "#212121" } ] }, { color: "Blue Grey", variations: [ { weight: 50, hex: "#ECEFF1" }, { weight: 100, hex: "#CFD8DC" }, { weight: 200, hex: "#B0BEC5" }, { weight: 300, hex: "#90A4AE" }, { weight: 400, hex: "#78909C" }, { weight: 500, hex: "#607D8B" }, { weight: 600, hex: "#546E7A" }, { weight: 700, hex: "#455A64" }, { weight: 800, hex: "#37474F" }, { weight: 900, hex: "#263238" } ] } ] }); |
That’s It. Now you will successfully create Material Color Picker With Copy To Clipboard Feature, a Color Palette program with material design. If you have any doubt or questions comment down below.
Thanks For Visiting, Keep Visiting.