Skip to content

Commit a6765fb

Browse files
committed
Add a short mode to the color picker
1 parent 1fae3e3 commit a6765fb

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

ipywidgets/static/widgets/js/widget_color.js

+16
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ define([
3131

3232
this.listenTo(this.model, "change:value", this._update_value, this);
3333
this.listenTo(this.model, "change:description", this._update_description, this);
34+
this.listenTo(this.model, "change:short", this._update_short, this);
3435
this.$colorpicker.on("change", this._picker_change.bind(this));
3536
this.$textbox.on("change", this._text_change.bind(this));
3637

38+
this._update_short();
3739
this._update_value();
3840
this._update_description();
3941
},
@@ -46,11 +48,25 @@ define([
4648
var description = this.model.get('description');
4749
if (description.length === 0) {
4850
this.$label.hide();
51+
this.$color_container.css("justify-content", "auto");
4952
} else {
5053
this.typeset(this.$label, description);
54+
this.$color_container.css("justify-content", "flex-end");
5155
this.$label.show();
5256
}
5357
},
58+
_update_short: function() {
59+
var short = this.model.get('short');
60+
if (short) {
61+
this.$el.addClass('short');
62+
this.$colorpicker.removeClass("input-group-addon");
63+
this.$textbox.hide();
64+
} else {
65+
this.$el.removeClass('short');
66+
this.$colorpicker.addClass("input-group-addon");
67+
this.$textbox.show();
68+
}
69+
},
5470
_picker_change: function() {
5571
this.model.set("value", this.$colorpicker.val());
5672
this.touch();

ipywidgets/static/widgets/less/widgets.less

+7-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,13 @@
182182

183183
.widget-colorpicker {
184184
/* Button */
185-
width : @widget-width;
185+
& {
186+
width : @widget-width;
187+
}
188+
&.short {
189+
width : @widget-width-short;
190+
}
191+
186192
display: flex;
187193

188194
.input-group {

ipywidgets/widgets/widget_color.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
from .widget import DOMWidget, register
1010
from .trait_types import Color
11-
from traitlets import Unicode
11+
from traitlets import Unicode, Bool
1212

1313

1414
@register('IPython.ColorPicker')
1515
class ColorPicker(DOMWidget):
1616
value = Color('black', sync=True)
17+
short = Bool(sync=True)
1718
description = Unicode(sync=True)
1819

1920
_view_name = Unicode('ColorPicker', sync=True)

0 commit comments

Comments
 (0)