add readonly mode for color swatches component

This commit is contained in:
Mads Rasmussen
2022-04-28 13:19:48 +02:00
parent 2235dd8e8a
commit 50b17ed262
3 changed files with 27 additions and 2 deletions

View File

@@ -27,7 +27,7 @@ Use this directive to generate color swatches to pick from.
function ColorSwatchesDirective() {
function link(scope, el, attr, ctrl) {
function link(scope, el, attrs, ctrl) {
// Set default to true if not defined
if (Utilities.isUndefined(scope.useColorClass)) {
@@ -40,6 +40,12 @@ Use this directive to generate color swatches to pick from.
}
scope.setColor = function (color, $index, $event) {
if (scope.readonly) {
$event.preventDefault();
$event.stopPropagation();
return;
}
if (scope.onSelect) {
// did the value change?
if (scope.selectedColor != null && scope.selectedColor.value === color.value) {
@@ -59,6 +65,10 @@ Use this directive to generate color swatches to pick from.
scope.isSelectedColor = function (color) {
return scope.selectedColor && color.value === scope.selectedColor.value;
}
attrs.$observe('readonly', (value) => {
scope.readonly = value !== undefined;
});
}
var directive = {

View File

@@ -98,3 +98,9 @@
}
}
}
.umb-color-swatches[readonly] {
.umb-color-box {
cursor: not-allowed;
}
}

View File

@@ -1,6 +1,15 @@
<div class="umb-color-swatches" ng-class="{ 'with-labels': useLabel }">
<button type="button" class="umb-color-box umb-color-box--{{size}} {{colorClassNamePrefix}}-{{color.value}}" ng-repeat="color in colors" title="{{useLabel || useColorClass ? (color.label || color.value) : ('#' + color.value)}}" hex-bg-inline="{{useColorClass === false}}" hex-bg-color="{{color.value}}" ng-class="{ 'active': isSelectedColor(color) }" ng-click="setColor(color, $index, $event)">
<button
type="button"
class="umb-color-box umb-color-box--{{size}} {{colorClassNamePrefix}}-{{color.value}}"
ng-repeat="color in colors"
title="{{useLabel || useColorClass ? (color.label || color.value) : ('#' + color.value)}}"
hex-bg-inline="{{useColorClass === false}}"
hex-bg-color="{{color.value}}"
ng-class="{ 'active': isSelectedColor(color) }"
ng-click="setColor(color, $index, $event)">
<div class="umb-color-box-inner">
<div class="check_circle">
<umb-icon icon="icon-check" class="icon small" ng-show="isSelectedColor(color)"></umb-icon>