Skip to content
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

feat: ui.checkbox_group #813

Merged
merged 25 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f28225c
feat: ui.checkbox_group
AkshatJawne Sep 6, 2024
9182a55
typo fix
AkshatJawne Sep 10, 2024
ee11254
add ui docs
AkshatJawne Sep 13, 2024
dac4978
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 16, 2024
e60de42
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 16, 2024
ae4852b
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 16, 2024
1d4e5e7
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 16, 2024
c3ae933
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 16, 2024
1f75fb2
fix docstring
AkshatJawne Sep 16, 2024
61a9ec2
Merge branch '620_checkbox_group' of https://github.com/AkshatJawne/d…
AkshatJawne Sep 16, 2024
99e6b6f
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
a0c1644
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
f8d8cd0
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
986f6fe
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
8bfd6ec
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
a40b185
add blank line
AkshatJawne Sep 18, 2024
d7b4ab1
Merge branch '620_checkbox_group' of https://github.com/AkshatJawne/d…
AkshatJawne Sep 18, 2024
c919b95
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
1b9320a
Update plugins/ui/docs/components/checkbox_group.md
AkshatJawne Sep 18, 2024
145e72a
fix prop name
AkshatJawne Sep 18, 2024
01ccb0e
Merge branch '620_checkbox_group' of https://github.com/AkshatJawne/d…
AkshatJawne Sep 18, 2024
ee67ea1
Merge branch 'main' into 620_checkbox_group
AkshatJawne Sep 26, 2024
03bb51c
modify examples
AkshatJawne Oct 1, 2024
abe31fd
fix examples
AkshatJawne Oct 2, 2024
4d9bd78
add unsaved change
AkshatJawne Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
353 changes: 353 additions & 0 deletions plugins/ui/docs/components/checkbox_group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,353 @@
# Checkbox Group

Checkbox group areas allow the selection of one or more items from a list of choices, represented by checkboxes.

## Example

```python
from deephaven import ui


my_checkbox_group_basic = ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favourite Sports",
)
```

## UI Recommendations

Recommendations for creating checkbox groups:

1. Every checkbox group should have a [label](#labeling) specified. Without one, the checkbox group is ambiguous. In the rare case that context is sufficient, the label is unnecessary; you must still include an aria-label via the `aria_label` prop.
2. While labels can be placed either on top or on the side of the checkbox groups, top labels are the default recommendation. Top labels work better with longer copy, localization, and responsive layouts. Side labels are more useful when vertical space is limited.
3. Checkbox groups can be either horizontal or vertical. By default, they are vertical; the orientation should only be horizontal if vertical space is limited.
4. Checkbox groups can be marked as optional or required, with required groups indicated by either a “(required)” label or an asterisk icon, which should be accompanied by help text.
5. Checkbox groups should use help text for error messaging and descriptions, providing context for why a selection is required or clarifying the options.


Consider using [`checkbox_group`](./checkbox_group.md) to select or mark a single item as selected.

## Content

Checkbox groups accept checkboxes and primitive types as children. Checkboxes accept a child, which is rendered as the label of the checkbox.
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved

```python
from deephaven import ui


my_checkbox_group_content_example = ui.checkbox_group(
"Soccer",
ui.checkbox("Basketball"),
label="Favourite Sports",
)
```


## Value

Checkbox groups allow selecting zero or more items, with initial values set via `default_value` or controlled values via `value`.

```python
from deephaven import ui


@ui.component
def ui_checkbox_group_value_examples():
value, set_value = ui.use_state(["Soccer"])
return [
ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favourite Sports (uncontrolled)",
default_value=["Soccer", "Baseball"],
),
ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favourite Sports (controlled)",
value=value,
on_change=set_value,
),
]


my_checkbox_group_value_examples = ui_checkbox_group_value_examples()
```


## HTML Forms

Checkbox groups 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.checkbox_group(ui.checkbox("Sample Label"), name="Sample Name")
)
```


## Labeling

The checkbox group can be labeled using the `label` prop, and 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_checkbox_group_label_examples():
return [
ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
label="Favorite avatars",
),
ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
aria_label="Favorite avatars",
),
]


my_checkbox_group_label_examples = ui_checkbox_group_label_examples()
```


The `is_required` prop and the `necessity_indicator` props can be used to show whether selecting an option in the checked group is required or optional.

When the `necessity_indicator` prop is set to "label", a localized string will be generated for "(required)" or "(optional)" automatically.

```python
from deephaven import ui


@ui.component
def ui_checkbox_group_required_examples():
return [
ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
label="Favorite avatars",
is_required=True,
),
ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
label="Favorite avatars",
is_required=True,
necessity_indicator="label",
),
ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
label="Favorite avatars",
necessity_indicator="label",
),
]


my_checkbox_group_required_examples = ui_checkbox_group_required_examples()
```

## Events

Checkbox groups accept an `on_change` prop, triggered whenever a checkbox within the group is clicked.

```python
from deephaven import ui


@ui.component
def ui_checkbox_group_event_example():
selected, set_selected = ui.use_state(["Soccer"])
return ui.flex(
ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favourite Sports (controlled)",
value=selected,
on_change=set_selected,
),
ui.text(value=f"You have selected: {selected}!"),
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
direction="column",
)


my_checkbox_group_event_example = ui_checkbox_group_event_example()
```

To require specific checkboxes to be checked, set the `is_required` prop at the Checkbox level, not the CheckboxGroup.
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved

```python
from deephaven import ui


my_checkbox_group_individual_validation_example = ui.form(
ui.checkbox_group(
ui.checkbox("Terms and conditions", is_required=True),
ui.checkbox("Privacy policy", is_required=True),
),
validation_behavior="native",
)
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
```


## Orientation

While aligned vertically by default, the axis with which the checkboxes align can be changed via the `orientation` prop.

```python
from deephaven import ui


my_checkbox_group_orientation_example = ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
label="Favorite avatars",
orientation="horizontal",
)
```

## Label position

By default, the position of a checkbox group's label is above the checkbox group, but it can be changed to the side using the `label_position` prop.
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved

```python
from deephaven import ui


my_checkbox_group_label_position_example = ui.checkbox_group(
ui.checkbox("Wizard", value="wizard"),
ui.checkbox("Dragon", value="dragon"),
label="Favorite avatars",
label_position="side",
)
```


## Help text

A checkbox group can have both a `description` and an `error_message`. The error message should offer specific guidance on how to correct the input.

The `is_invalid` prop can be used to set whether the current checkbox group state is valid or invalid.

```python
from deephaven import ui


@ui.component
def ui_checkbox_group_help_text_examples():
return [
ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favourite sports",
description="Select an avatar from the two options.",
value=selected,
on_change=set_selected,
),
ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favourite sports",
description="Select favourite sports from the two options.",
error_message="Sample invalid error message.",
is_invalid=True,
),
]


my_checkbox_group_help_text_examples = ui_checkbox_group_help_text_examples()
```


## Contextual Help

Using the `contextual_help` prop, a `ui.contextual_help` can be placed next to the label to provide additional information about the checkbox group.

```python
from deephaven import ui


my_checkbox_group_contextual_help_example = ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favorite sports",
contextual_help=ui.contextual_help(ui.heading("Content tips")),
)
```


## Disabled state

The `is_disabled` prop disables a checkbox group to prevent user interaction. This is useful when the checkbox group should be visible but not available for selection.

```python
from deephaven import ui


my_checkbox_group_is_disabled_example = ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favorite sports",
is_disabled=True,
)
```


## Read only

The `is_read_only` prop makes checkbox groups read-only to prevent user interaction. This is different from setting the `is_disabled` prop since the checkbox group remains focusable and its options remain visible.

```python
from deephaven import ui


my_checkbox_group_is_read_only_example = ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favorite sports",
is_read_only=True,
)
```

## Emphasized

The `is_emphasized` prop makes the selected checkbox the user's accent color, adding a visual prominence to the selection.


```python
from deephaven import ui


my_checkbox_group_is_emphasized_example = ui.checkbox_group(
"Soccer",
"Basketball",
"Baseball",
label="Favorite sports",
is_emphasized=True,
)
```



## API Reference

```{eval-rst}
.. dhautofunction:: deephaven.ui.checkbox_group
```

2 changes: 2 additions & 0 deletions plugins/ui/src/deephaven/ui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .button import button
from .button_group import button_group
from .checkbox import checkbox
from .checkbox_group import checkbox_group
from .column import column
from .combo_box import combo_box
from .content import content
Expand Down Expand Up @@ -61,6 +62,7 @@
"button",
"button_group",
"checkbox",
"checkbox_group",
"column",
"combo_box",
"component",
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/deephaven/ui/components/action_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def action_group(
"""
An action grouping of action items that are related to each other.
Args:
*children: The children of the contextual help popover.
*children: The children of the action group.
is_emphasized: Whether the action buttons should be displayed with emphasized style.
density: Sets the amount of space between buttons.
is_justified: Whether the ActionButtons should be justified in their container.
Expand Down
Loading
Loading