-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: ui.checkbox #722
Merged
+136
−0
Merged
docs: ui.checkbox #722
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3ea6f7a
docs: ui.checkbox
AkshatJawne 75b96db
fix typo
AkshatJawne 0ada584
add section of when to use what
AkshatJawne 046f9b2
make changes based on review
AkshatJawne cc0c628
Merge branch 'main' into 720_checkbox_docs
AkshatJawne 7958f4b
fix returns statement
AkshatJawne 1b5ab5c
make change according to review
AkshatJawne 9fef154
change text field to text
AkshatJawne eef3347
make changes based on review
AkshatJawne f1a6643
Apply suggestions from code review
margaretkennedy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
# Checkbox | ||
|
||
Checkbox allows users to select or mark a single item as selected. | ||
|
||
If wanting to use multiple checkboxes, use `checkbox_group`. | ||
|
||
## Example | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
cb = ui.checkbox("Unsubscribe") | ||
``` | ||
|
||
## UI recommendations | ||
|
||
Recommendations for creating checkboxes: | ||
|
||
1. Use emphasized checkboxes for forms, settings, or to highlight selected items like cards or table rows. Use non-emphasized checkboxes in application panels with monochrome components to keep the focus on the main content. | ||
2. Use standalone checkboxes when the context is clear without a text label, such as when a checkbox is associated with other controls within a panel. | ||
3. Checkboxes and radio buttons should not be used interchangably. Use checkboxes to allow multiple selections (or none) from a list. Use radio buttons to select only one option from a list of mutually exclusive choices. | ||
4. Checkboxes should be used when selecting (ie. multiple table rows), whereas, switches should be used for activation (ie. on/off states). | ||
margaretkennedy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
Consider using a [`checkbox`](./checkbox.md) for individual selections or when marking a single item as selected. For a set of related checkboxes, use a [`checkbox_group`](./checkbox_group.md) to manage multiple selections within a group. If you need to display a list of checkboxes driven by a Deephaven table, use a [`list_view`](./list_view.md) to dynamically generate the checkboxes. | ||
|
||
## Content | ||
|
||
Checkbox's accept a child, which is rendered as the label of the checkbox. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
my_checkbox_basic = ui.checkbox("Basic Checkbox") | ||
``` | ||
|
||
## Value | ||
|
||
Checkboxes are not selected by default. Use the `default_selected` prop to set the initial state (uncontrolled) or the `is_selected` prop to control the selected state. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
@ui.component | ||
def ui_checkbox_content_examples(): | ||
selected, set_selected = ui.use_state(False) | ||
return ui.flex( | ||
ui.checkbox("Subscribe (uncontrolled)", default_selected=True), | ||
ui.checkbox( | ||
"Subscribe (uncontrolled)", is_selected=selected, on_change=set_selected | ||
), | ||
direction="column", | ||
) | ||
|
||
|
||
my_checkbox_content_examples = ui_checkbox_content_examples() | ||
``` | ||
|
||
|
||
## Indeterminate state | ||
|
||
A Checkbox can be set to an indeterminate state using the `is_indeterminate` prop, which overrides its appearance. The Checkbox remains visually indeterminate until prop is set to false, regardless of user interaction. | ||
margaretkennedy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
my_checkbox_is_indeterminate_example = ui.checkbox( | ||
"Indeterminate State", is_indeterminate=True | ||
) | ||
``` | ||
|
||
## HTML Forms | ||
|
||
Checkbox's can support a `name` prop for integration with HTML forms, allowing for easy identification of a value on form submission. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
my_checkbox_name_example = ui.form( | ||
ui.flex(ui.checkbox("Sample Label", name="Sample Name")) | ||
) | ||
AkshatJawne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
## Events | ||
|
||
Checkboxes accept an `on_change` prop, which is triggered whenever the Checkbox is clicked | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
@ui.component | ||
def ui_checkbox_event_example(): | ||
selected, set_selected = ui.use_state(False) | ||
return ui.flex( | ||
ui.checkbox("Subscribe", is_selected=selected, on_change=set_selected), | ||
ui.text_field(value="Subscribed!" if selected else "Not subscribed!"), | ||
AkshatJawne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
direction="column", | ||
) | ||
|
||
|
||
my_checkbox_event_example = ui_checkbox_event_example() | ||
``` | ||
## Validation | ||
|
||
Checkboxes can indicate a validation state to show if the current value is invalid, via the `is_invalid` prop. Since the invalid state is only shown through a color change, ensure the validation error is also communicated in another accessible way. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
@ui.component | ||
def ui_checkbox_validation_example(): | ||
invalid, set_invalid = ui.use_state(False) | ||
return [ | ||
ui.button( | ||
"Make checkbox valid" if invalid else "Make checkbox invalid", | ||
on_press=lambda: set_invalid(not invalid), | ||
), | ||
ui.checkbox("I accept the terms and conditions", is_invalid=invalid), | ||
] | ||
|
||
|
||
my_checkbox_validation_example = ui_checkbox_validation_example() | ||
``` | ||
|
||
## API reference | ||
|
||
```{eval-rst} | ||
.. dhautofunction:: deephaven.ui.checkbox | ||
``` |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should come back and link this when we have the checkbox group component