-
Notifications
You must be signed in to change notification settings - Fork 16
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.switch #793
Merged
Merged
docs: ui.switch #793
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73a4af6
docs: ui.switch
AkshatJawne 0e3b5ef
docs:ui.switch
AkshatJawne d2d9d0b
add missing line
AkshatJawne de0827e
add returns comment to pydoc
AkshatJawne 9994491
modify ui reccomendations
AkshatJawne 5b40383
Update plugins/ui/docs/components/switch.md
AkshatJawne f9dc2a6
Update plugins/ui/docs/components/switch.md
AkshatJawne a276bfb
Update plugins/ui/docs/components/switch.md
AkshatJawne a57987e
Update switch.md
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
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,140 @@ | ||
# Switch | ||
|
||
Switches allow users to turn a single option on or off. | ||
|
||
## Example | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
my_switch_basic = ui.switch("Low power mode") | ||
``` | ||
|
||
## UI recommendations | ||
|
||
Recommendations for creating switches: | ||
|
||
1. Emphasized switches are ideal for forms and settings where the switch being noticed is crucial, while non-emphasized switches suit monochrome application panels to maintain focus on the content. | ||
2. Use a standalone switch when the context is clear without a text label, such as next to a panel's title, to enable or disable panel options. | ||
3. Use switches for activation and checkboxes for selection; unlike checkboxes, switches cannot have an error state. | ||
4. When a switch represents multiple values from other switches, it should initially appear unselected; clicking it will select and unify all values, while a subsequent click will deselect and reset them. | ||
5. Switches can only be on or off; for partial states, use a checkbox, as indeterminate switches are not accessible. | ||
|
||
Consider using a [`checkbox`](./checkbox.md) for individual selections or when marking a single item as selected. | ||
|
||
## Value | ||
|
||
Switches 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_switch_value_examples(): | ||
selected, set_selected = ui.use_state(False) | ||
return [ | ||
ui.switch("Low power mode (uncontrolled)", default_selected=True), | ||
ui.switch( | ||
"Low power mode (controlled)", is_selected=selected, on_change=set_selected | ||
), | ||
] | ||
|
||
|
||
my_switch_value_examples = ui_switch_value_examples() | ||
``` | ||
|
||
|
||
## HTML Forms | ||
|
||
Switches 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_switch_name_example = ui.form(ui.switch("Low Power Mode", name="power", value="low")) | ||
``` | ||
|
||
## Labeling | ||
|
||
The switch can be labeled by passing in a child. If no label is provided, an `aria_label` must be provided to identify the control for accessibility purposes. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
@ui.component | ||
def ui_switch_label_examples(): | ||
return [ | ||
ui.switch("Switch Label", name="value"), | ||
ui.switch(aria_label="Switch Label", name="value"), | ||
] | ||
|
||
|
||
my_switch_label_examples = ui_switch_label_examples() | ||
``` | ||
|
||
|
||
## Events | ||
|
||
The `on_change` property is triggered whenever the switch is pressed. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
@ui.component | ||
def ui_switch_on_change_example(): | ||
selected, set_selected = ui.use_state(False) | ||
return [ | ||
ui.switch("Switch Label", on_change=set_selected, is_selected=selected), | ||
ui.text(f"The switch is {'on' if selected else 'off'}."), | ||
] | ||
|
||
|
||
my_switch_on_change_example = ui_switch_on_change_example() | ||
``` | ||
|
||
|
||
## Disabled | ||
|
||
Setting the `is_disabled` prop disables the switch. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
my_switch_is_disabled_example = ui.switch("Switch Label", is_disabled=True) | ||
``` | ||
|
||
|
||
## Emphasized | ||
|
||
The `is_emphasized` prop makes the switch's fill color the user's accent color, adding visual prominence to the selection. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
my_switch_is_emphasized_example = ui.switch("Switch Label", is_emphasized=True) | ||
``` | ||
|
||
|
||
## Read only | ||
|
||
The `is_read_only` prop makes the switch read-only to prevent user interaction. This differs from setting the `is_disabled` prop since the switch remains focusable. | ||
|
||
```python | ||
from deephaven import ui | ||
|
||
|
||
my_switch_is_read_only_example = ui.switch( | ||
"Switch Label", is_read_only=True, default_selected=True | ||
) | ||
``` | ||
## API Reference | ||
|
||
```{eval-rst} | ||
.. dhautofunction:: deephaven.ui.switch | ||
``` |
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.
why is this change in this review?
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.
Just noticed that there was an empty line missing, so thought I could add it here, since it isn't that major of a change.