TextInput module

This commit is contained in:
Andrew Croce 2018-07-25 12:02:02 -04:00
parent 0cffa63b5d
commit a315aef576
2 changed files with 33 additions and 0 deletions

View File

@ -1,4 +1,6 @@
from tornado.web import UIModule from tornado.web import UIModule
# from tornado.template import raw
import re
class Alert(UIModule): class Alert(UIModule):
def render(self, title, message=None, actions=None, level='info'): def render(self, title, message=None, actions=None, level='info'):
@ -9,6 +11,16 @@ class Alert(UIModule):
actions=actions, actions=actions,
level=level) level=level)
class TextInput(UIModule):
def render(self, input, placeholder=''):
return self.render_string(
"components/text_input.html.to",
input=input,
label=re.sub('<[^<]+?>', '', str(input.label)),
errors=input.errors,
placeholder=placeholder,
description=input.description)
class Icon(UIModule): class Icon(UIModule):
def render(self, name, classes=''): def render(self, name, classes=''):
with open('static/icons/%s.svg' % name) as svg: with open('static/icons/%s.svg' % name) as svg:

View File

@ -0,0 +1,21 @@
<div class='usa-input {% if errors %}usa-input--error{% end %}'>
<label for={{input.name}}>
{{ label }}
{% if description %}
<span class='usa-input__help'>{% raw description %}</span>
{% end %}
{% if errors %}
{% module Icon('alert') %}
{% end %}
</label>
{% raw input(placeholder=placeholder) %}
{% if errors %}
{% for error in errors %}
<span class='usa-input__message'>{{ error }}</span>
{% end %}
{% end %}
</div>