Skip to content

Commit bab6e5d

Browse files
committed
introduce display_class widget property, update docs
1 parent 6decdc8 commit bab6e5d

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changes
44
1.0 (unreleased)
55
----------------
66

7+
- Introduce ``display_class`` widget property.
8+
[lenadax]
9+
710
- Update jQuery to version ``4.0.0-beta.2``.
811
[lenadax]
912

src/yafowil/widget/tiptap/example.py

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,83 @@ def colors_example():
144144
}
145145

146146

147+
DOC_DISPLAY_TIPTAP = """
148+
Display Mode
149+
------------
150+
151+
In Display Mode, the widget is not editable and Actions will not be rendered.
152+
The ``display_class`` widget property can be used to style the div containing the
153+
widget value.
154+
155+
.. code-block:: python
156+
157+
tiptap = factory(
158+
'tiptap',
159+
value=(
160+
'<p>'
161+
'This widget is in '
162+
'<strong style="color: rgb(66,209,245)">display mode</strong>, '
163+
'but it will still show <strong>custom formatting</strong>.'
164+
'<br />'
165+
'Its border was adding with the <strong>display_class</strong> property.'
166+
'</p>'
167+
),
168+
props={
169+
'label': 'Tiptap Widget in display mode',
170+
'actions': ['color'],
171+
'colors': [
172+
{'name': 'Purple', 'color': 'rgb(161,66,245)'},
173+
{'name': 'Blue', 'color': 'rgb(66,111,245)'},
174+
{'name': 'Turqoise', 'color': 'rgb(66,209,245)'},
175+
{'name': 'Green', 'color': 'rgb(105,245,66)'},
176+
{'name': 'Yellow', 'color': 'rgb(245,236,66)'},
177+
{'name': 'Orange', 'color': 'rgb(245,167,66'},
178+
{'name': 'Red', 'color': 'rgb(245,66,66)'}
179+
],
180+
'display_class': 'form-control border-2 border-info'
181+
},
182+
mode='display')
183+
"""
184+
185+
186+
def display_example():
187+
part = factory(u'fieldset', name='yafowil.widget.tiptap')
188+
part['tiptap'] = factory(
189+
'tiptap',
190+
value=(
191+
'<p>'
192+
'This widget is in '
193+
'<strong style="color: rgb(66,209,245)">display mode</strong>, '
194+
'but it will still show <strong>custom formatting</strong>.'
195+
'<br />'
196+
'Its border was adding with the <strong>display_class</strong> property.'
197+
'</p>'
198+
),
199+
props={
200+
'label': 'Tiptap Widget in display mode',
201+
'actions': ['color'],
202+
'colors': [
203+
{'name': 'Purple', 'color': 'rgb(161,66,245)'},
204+
{'name': 'Blue', 'color': 'rgb(66,111,245)'},
205+
{'name': 'Turqoise', 'color': 'rgb(66,209,245)'},
206+
{'name': 'Green', 'color': 'rgb(105,245,66)'},
207+
{'name': 'Yellow', 'color': 'rgb(245,236,66)'},
208+
{'name': 'Orange', 'color': 'rgb(245,167,66'},
209+
{'name': 'Red', 'color': 'rgb(245,66,66)'}
210+
],
211+
'display_class': 'form-control border-2 border-info'
212+
}, mode='display')
213+
return {
214+
'widget': part,
215+
'doc': DOC_DISPLAY_TIPTAP,
216+
'title': 'Tiptap Widget in display mode',
217+
}
218+
219+
147220
def get_example():
148221
return [
149222
default_example(),
150223
actions_example(),
151-
colors_example()
224+
colors_example(),
225+
display_example()
152226
]

src/yafowil/widget/tiptap/widget.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from yafowil.common import generic_required_extractor
66
from yafowil.datatypes import generic_emptyvalue_extractor
77
from yafowil.textarea import textarea_renderer
8+
from yafowil.utils import attr_value
89
from yafowil.utils import cssclasses
910
from yafowil.utils import data_attrs_helper
1011
from yafowil.utils import managedprops
@@ -34,7 +35,10 @@ def tiptap_display_renderer(widget, data):
3435
value = fetch_value(widget, data)
3536
if not value:
3637
value = ''
37-
return data.tag('div', value, **{'class': 'display-tiptap'})
38+
display_class = attr_value("display_class", widget, data)
39+
return data.tag('div', value, **{
40+
'class': 'display-tiptap' + f' {display_class}' if display_class is not None else ''
41+
})
3842

3943

4044
factory.register(

0 commit comments

Comments
 (0)