Skip to content

Commit 3b6f22f

Browse files
Merge pull request #2757 from zerline/borders3
Borders independently: `border_top`, `border_right`, `border_bottom`, `border_left`
2 parents 3cfe5ac + f703670 commit 3b6f22f

File tree

5 files changed

+188
-162
lines changed

5 files changed

+188
-162
lines changed

ipywidgets/widgets/widget_layout.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ class Layout(Widget):
3737
'baseline', 'stretch'] + CSS_PROPERTIES, allow_none=True, help="The align-items CSS attribute.").tag(sync=True)
3838
align_self = CaselessStrEnum(['auto', 'flex-start', 'flex-end',
3939
'center', 'baseline', 'stretch'] + CSS_PROPERTIES, allow_none=True, help="The align-self CSS attribute.").tag(sync=True)
40+
border_top = Unicode(None, allow_none=True, help="The border top CSS attribute.").tag(sync=True)
41+
border_right = Unicode(None, allow_none=True, help="The border right CSS attribute.").tag(sync=True)
42+
border_bottom = Unicode(None, allow_none=True, help="The border bottom CSS attribute.").tag(sync=True)
43+
border_left = Unicode(None, allow_none=True, help="The border left CSS attribute.").tag(sync=True)
4044
bottom = Unicode(None, allow_none=True, help="The bottom CSS attribute.").tag(sync=True)
41-
border = Unicode(None, allow_none=True, help="The border CSS attribute.").tag(sync=True)
4245
display = Unicode(None, allow_none=True, help="The display CSS attribute.").tag(sync=True)
4346
flex = Unicode(None, allow_none=True, help="The flex CSS attribute.").tag(sync=True)
4447
flex_flow = Unicode(None, allow_none=True, help="The flex-flow CSS attribute.").tag(sync=True)
@@ -75,6 +78,30 @@ class Layout(Widget):
7578
grid_column = Unicode(None, allow_none=True, help="The grid-column CSS attribute.").tag(sync=True)
7679
grid_area = Unicode(None, allow_none=True, help="The grid-area CSS attribute.").tag(sync=True)
7780

81+
def _get_border(self):
82+
"""
83+
`border` property getter. Return the common value of all side
84+
borders if they are identical. Otherwise return None.
85+
86+
"""
87+
found = None
88+
for side in ['top', 'right', 'bottom', 'left']:
89+
if not hasattr(self, "border_" + side):
90+
return
91+
old, found = found, getattr(self, "border_" + side)
92+
if found is None or (old is not None and found != old):
93+
return
94+
return found
95+
96+
def _set_border(self, border):
97+
"""
98+
`border` property setter. Set all 4 sides to `border` string.
99+
"""
100+
for side in ['top', 'right', 'bottom', 'left']:
101+
setattr(self, "border_" + side, border)
102+
103+
border = property(_get_border, _set_border)
104+
78105

79106
class LayoutTraitType(Instance):
80107

packages/base/src/widget_layout.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const css_properties: Dict<string | null> = {
1212
align_content: null,
1313
align_items: null,
1414
align_self: null,
15-
border: null,
15+
border_top: null,
16+
border_right: null,
17+
border_bottom: null,
18+
border_left: null,
1619
bottom: null,
1720
display: null,
1821
flex: null,

0 commit comments

Comments
 (0)