-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make value behavior consistent #1154
- Loading branch information
Showing
17 changed files
with
346 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Nav | ||
# Use nav cards to display #sidebar #navigation. | ||
# --- | ||
from h2o_wave import main, app, Q, ui | ||
|
||
|
||
persona = 'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&h=750&w=1260' | ||
|
||
choices = [ | ||
ui.choice('A', 'Option A'), | ||
ui.choice('B', 'Option B'), | ||
ui.choice('C', 'Option C', disabled=True), | ||
ui.choice('D', 'Option D'), | ||
] | ||
|
||
combobox_choices = ['Cyan', 'Magenta', 'Yellow', 'Black'] | ||
|
||
tabs = [ | ||
ui.tab(name='email', label='Mail', icon='Mail'), | ||
ui.tab(name='events', label='Events', icon='Calendar'), | ||
ui.tab(name='spam', label='Spam'), | ||
] | ||
|
||
|
||
@app('/demo') | ||
async def serve(q: Q): | ||
|
||
content = 'Welcome to our store!' | ||
location = q.args['#'] | ||
if location: | ||
if location == 'menu/spam': | ||
content = "Sorry, we're out of spam!" | ||
elif location == 'menu/ham': | ||
content = "Sorry, we're out of ham!" | ||
elif location == 'menu/eggs': | ||
content = "Sorry, we're out of eggs!" | ||
elif location == 'about': | ||
content = 'Everything here is gluten-free!' | ||
|
||
if not q.client.initialized: | ||
q.page['example'] = ui.form_card(box='3 4 4 10', items=[ | ||
ui.checkbox(name='checkbox', label='Checkbox', value=False), | ||
ui.dropdown(name='dropdown', label='Choices', value='', | ||
choices=[ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']]), | ||
ui.dropdown(name='dropdown2', label='Choices', values=[], | ||
choices=[ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']]), | ||
ui.dropdown(name='dropdown3', label='Choices', popup='always', value='', | ||
choices=[ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']]), | ||
ui.dropdown(name='dropdown4', label='Choices', popup='always', values=[], | ||
choices=[ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']]), | ||
ui.checklist(name='checklist', values=['Egg', 'Spam'], label='Choices', | ||
choices=[ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']]), | ||
ui.choice_group(name='choice_group', label='Pick one', value='B', required=True, choices=choices), | ||
ui.color_picker(name='color', label='Pick a color', value='#F25F5C'), | ||
ui.combobox(name='combobox', label='Enter or choose a color', placeholder='Color...', value='Blue', | ||
choices=combobox_choices), | ||
ui.copyable_text(label='Copyable text', value='foo'), | ||
ui.date_picker(name='date', label='Standard date picker', value='2017-10-19'), | ||
ui.picker(name='picker', label='Place an order (try Spam, Eggs or Ham):', choices=[ | ||
ui.choice(name='spam', label='Spam'), | ||
ui.choice(name='eggs', label='Eggs'), | ||
ui.choice(name='ham', label='Ham'), | ||
ui.choice(name='cheese', label='Cheese'), | ||
ui.choice(name='beans', label='Beans'), | ||
ui.choice(name='toast', label='Toast'), | ||
], values=['eggs']), | ||
ui.progress(label='Indeterminate Progress', caption='Goes on forever', value=0.5), | ||
ui.slider(name='slider', label='Standard slider', min=0, max=100, step=10, value=30), | ||
ui.spinbox(name='spinbox', label='Standard spinbox', min=0, max=100, step=10, value=30), | ||
ui.tabs(name='menu', value='spam', items=tabs), | ||
ui.toggle(name='toggle', label='Not checked'), | ||
ui.button(name='change', label='Change', primary=True), | ||
]) | ||
|
||
q.page['tab'] = ui.tab_card( | ||
box='3 1 4 1', | ||
items=[ | ||
ui.tab(name='#menu/spam', label='Spam'), | ||
ui.tab(name='#menu/ham', label='Ham'), | ||
ui.tab(name='#menu/eggs', label='Eggs'), | ||
ui.tab(name='#about', label='About'), | ||
], | ||
value='#menu/ham', | ||
) | ||
|
||
q.page['nav'] = ui.nav_card( | ||
box='1 1 2 -1', | ||
value='#menu/spam', | ||
title='H2O Wave', | ||
subtitle='And now for something completely different!', | ||
items=[ | ||
ui.nav_group('Menu', items=[ | ||
ui.nav_item(name='#menu/spam', label='Spam'), | ||
ui.nav_item(name='#menu/ham', label='Ham'), | ||
ui.nav_item(name='#menu/eggs', label='Eggs', tooltip='Make me a scrambled egg.'), | ||
ui.nav_item(name='#menu/toast', label='Toast'), | ||
]) | ||
], | ||
) | ||
|
||
q.page['blurb'] = ui.markdown_card( | ||
box='3 2 4 2', | ||
title='Store', | ||
content=content, | ||
) | ||
|
||
q.client.initialized = True | ||
|
||
if q.args.change: | ||
q.page['example'].items[0].checkbox.value = True | ||
q.page['example'].items[0].checkbox.value = True | ||
q.page['example'].items[1].dropdown.value = 'Bacon' | ||
q.page['example'].items[2].dropdown.values = ['Spam', 'Bacon'] | ||
q.page['example'].items[3].dropdown.value = 'Bacon' | ||
q.page['example'].items[4].dropdown.values = ['Spam', 'Bacon'] | ||
q.page['example'].items[5].checklist.values = ['Bacon'] | ||
q.page['example'].items[6].choice_group.value = 'A' | ||
q.page['example'].items[7].color_picker.value = '#FFFFF8' | ||
q.page['example'].items[8].combobox.value = 'Yellow' | ||
q.page['example'].items[9].copyable_text.value = 'bar' | ||
q.page['example'].items[10].date_picker.value = '2022-03-22' | ||
q.page['example'].items[11].picker.values = ['ham', 'toast'] | ||
q.page['example'].items[12].progress.value = 0.75 | ||
q.page['example'].items[13].slider.value = 50 | ||
q.page['example'].items[14].spinbox.value = 50 | ||
q.page['example'].items[15].tabs.value = 'events' | ||
q.page['example'].items[16].toggle.value = True | ||
|
||
q.page['tab'].value = '#menu/spam' | ||
q.page['nav'].value = '#menu/spam' | ||
if location: | ||
blurb = q.page['blurb'] | ||
blurb.content = content | ||
|
||
await q.page.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.