Skip to content

Commit 78e510f

Browse files
committed
Introduce a ToggleButtons button_width style attribute
Fixes #1189
1 parent 4362d09 commit 78e510f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ipywidgets/widgets/widget_selection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from .widget_description import DescriptionWidget
1717
from .valuewidget import ValueWidget
1818
from .widget_core import CoreWidget
19-
from .widget import register
19+
from .widget_style import Style
20+
from .trait_types import InstanceDict
21+
from .widget import register, widget_serialization
2022
from traitlets import (Unicode, Bool, Int, Any, Dict, TraitError, CaselessStrEnum,
2123
Tuple, List, Union, observe, validate)
2224
from ipython_genutils.py3compat import unicode_type
@@ -272,6 +274,11 @@ def _repr_keys(self):
272274
for key in sorted(chain(keys, ('options',))):
273275
yield key
274276

277+
@register
278+
class ToggleButtonsStyle(Style, CoreWidget):
279+
"""Button style widget."""
280+
_model_name = Unicode('ToggleButtonsStyleModel').tag(sync=True)
281+
button_width = Unicode(help="The width of each button.").tag(sync=True)
275282

276283
@register
277284
class ToggleButtons(_Selection):
@@ -284,6 +291,7 @@ class ToggleButtons(_Selection):
284291

285292
tooltips = List(Unicode(), help="Tooltips for each button.").tag(sync=True)
286293
icons = List(Unicode(), help="Icons names for each button (FontAwesome names without the fa- prefix).").tag(sync=True)
294+
style = InstanceDict(ToggleButtonsStyle).tag(sync=True, **widget_serialization)
287295

288296
button_style = CaselessStrEnum(
289297
values=['primary', 'success', 'info', 'warning', 'danger', ''],

packages/controls/src/widget_selection.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4+
import {
5+
StyleModel
6+
} from '@jupyter-widgets/base';
7+
48
import {
59
CoreDescriptionModel,
610
} from './widget_core';
@@ -356,7 +360,24 @@ class RadioButtonsView extends DescriptionView {
356360
}
357361

358362
export
359-
class ToggleButtonsModel extends SelectionModel {
363+
class ToggleButtonsStyleModel extends StyleModel {
364+
defaults() {
365+
return _.extend(super.defaults(), {
366+
_model_name: 'ToggleButtonsStyleModel',
367+
});
368+
}
369+
370+
public static styleProperties = {
371+
button_width: {
372+
selector: '.widget-toggle-button',
373+
attribute: 'width',
374+
default: null
375+
}
376+
};
377+
}
378+
379+
export
380+
class ToggleButtonsModel extends SelectionModel {
360381
defaults() {
361382
return {...super.defaults(),
362383
_model_name: 'ToggleButtonsModel',
@@ -463,6 +484,11 @@ class ToggleButtonsView extends DescriptionView {
463484
}
464485
});
465486

487+
this.stylePromise.then(function(style) {
488+
if (style) {
489+
style.style();
490+
}
491+
});
466492
return super.update(options);
467493
}
468494

0 commit comments

Comments
 (0)