-
-
Notifications
You must be signed in to change notification settings - Fork 473
/
flex.py
102 lines (82 loc) · 3.94 KB
/
flex.py
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
from pathlib import Path
import param
from param.parameterized import iscoroutinefunction, resolve_ref
from ..reactive import ReactiveHTML
from .base import ListLike
class FlexBox(ListLike, ReactiveHTML):
"""
The `FlexBox` is a list-like layout (unlike `GridSpec`) that wraps objects
into a CSS flex container.
It has a list-like API with methods to `append`, `extend`, `clear`,
`insert`, `pop`, `remove` and `__setitem__`, which makes it possible to
interactively update and modify the layout. It exposes all the CSS options
for controlling the behavior and layout of the flex box.
Reference: https://panel.holoviz.org/reference/layouts/FlexBox.html
:Example:
>>> pn.FlexBox(
... some_python_object, another_python_object, ...,
... the_last_python_object
... )
"""
align_content = param.Selector(default='flex-start', objects=[
'normal', 'flex-start', 'flex-end', 'center', 'space-between',
'space-around', 'space-evenly', 'stretch', 'start', 'end',
'baseline', 'first baseline', 'last baseline'], doc="""
Defines how a flex container's lines align when there is extra
space in the cross-axis.""")
align_items = param.Selector(default='flex-start', objects=[
'stretch', 'flex-start', 'flex-end', 'center', 'baseline',
'first baseline', 'last baseline', 'start', 'end',
'self-start', 'self-end'], doc="""
Defines the default behavior for how flex items are laid
out along the cross axis on the current line.""")
flex_direction = param.Selector(default='row', objects=[
'row', 'row-reverse', 'column', 'column-reverse'], doc="""
This establishes the main-axis, thus defining the direction
flex items are placed in the flex container.""")
flex_wrap = param.Selector(default='wrap', objects=[
'nowrap', 'wrap', 'wrap-reverse'], doc="""
Whether and how to wrap items in the flex container.""")
justify_content = param.Selector(default='flex-start', objects=[
'flex-start', 'flex-end', 'center', 'space-between', 'space-around',
'space-evenly', 'start', 'end', 'left', 'right'], doc="""
Defines the alignment along the main axis.""")
gap = param.String(default='', doc="""
Defines the spacing between flex items, supporting various units (px, em, rem, %, vw/vh).""")
_template = (Path(__file__).parent / 'flexbox.html').read_text('utf-8')
def __init__(self, *objects, **params):
from ..pane.base import panel
if 'sizing_mode' not in params:
direction = params.get('flex_direction', self.flex_direction)
if direction.startswith('row'):
params['sizing_mode'] = 'stretch_width'
else:
params['sizing_mode'] = 'stretch_height'
if objects:
if 'objects' in params:
raise ValueError("A %s's objects should be supplied either "
"as positional arguments or as a keyword, "
"not both." % type(self).__name__)
params['objects'] = [panel(pane) for pane in objects]
elif 'objects' in params:
objects = params['objects']
if not resolve_ref(objects) or iscoroutinefunction(objects):
params['objects'] = [panel(pane) for pane in objects]
super().__init__(**params)
def select(self, selector=None):
"""
Iterates over the Viewable and any potential children in the
applying the Selector.
Arguments
---------
selector: type or callable or None
The selector allows selecting a subset of Viewables by
declaring a type or callable function to filter by.
Returns
-------
viewables: list(Viewable)
"""
objects = super().select(selector)
for obj in self:
objects += obj.select(selector)
return objects