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.avatar #1027

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
96 changes: 96 additions & 0 deletions plugins/ui/docs/components/avatar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Avatar

An avatar is a small image or icon representing a user or organization.

## Example

```python
from deephaven import ui


my_avatar_basic = ui.avatar(src="https://i.imgur.com/kJOwAdv.png", alt="default avatar")
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
```


## Disabled State

The `is_disabled` prop disables avatars to prevent user interaction, and gives it a silenced style.
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved

```python
from deephaven import ui


my_avatar_is_disabled_example = ui.avatar(
src="https://i.imgur.com/kJOwAdv.png", alt="default avatar", is_disabled=True
)
```


## Size

The `size` of an avatar can be set to one of the preset sizes, or a custom pixel value.

```python
from deephaven import ui


@ui.component
def ui_avatar_sizing_examples():
return [
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-50",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-75",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-100",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-200",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-300",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-400",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-500",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-600",
),
ui.avatar(
src="https://i.imgur.com/kJOwAdv.png",
alt="default avatar",
size="avatar-size-700",
),
ui.avatar(src="https://i.imgur.com/kJOwAdv.png", alt="default avatar", size=80),
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
]


my_avatar_sizing_examples = ui_avatar_sizing_examples()
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
```

## API Reference

```{eval-rst}
.. dhautofunction:: deephaven.ui.avatar
```
4 changes: 4 additions & 0 deletions plugins/ui/docs/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"label": "action_menu",
"path": "components/action_menu.md"
},
{
"label": "avatar",
"path": "components/avatar.md"
},
{
"label": "badge",
"path": "components/badge.md"
Expand Down
2 changes: 2 additions & 0 deletions plugins/ui/src/deephaven/ui/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .action_button import action_button
from .action_group import action_group
from .action_menu import action_menu
from .avatar import avatar
from .basic import (
component_element,
)
Expand Down Expand Up @@ -69,6 +70,7 @@
"action_button",
"action_group",
"action_menu",
"avatar",
"component_element",
"badge",
"button",
Expand Down
170 changes: 170 additions & 0 deletions plugins/ui/src/deephaven/ui/components/avatar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
from __future__ import annotations
from .types import (
# Layout
AlignSelf,
CSSProperties,
DimensionValue,
JustifySelf,
LayoutFlex,
Position,
)
from ..types import AvatarSize
from .basic import component_element
from ..elements import Element


def avatar(
src: str,
is_disabled: bool | None = None,
size: AvatarSize | DimensionValue | None = "avatar-size-100",
alt: str | None = None,
flex: LayoutFlex | None = None,
flex_grow: float | None = None,
flex_shrink: float | None = None,
flex_basis: DimensionValue | None = None,
align_self: AlignSelf | None = None,
justify_self: JustifySelf | None = None,
order: int | None = None,
grid_area: str | None = None,
grid_row: str | None = None,
grid_column: str | None = None,
grid_row_start: str | None = None,
grid_row_end: str | None = None,
grid_column_start: str | None = None,
grid_column_end: str | None = None,
margin: DimensionValue | None = None,
margin_top: DimensionValue | None = None,
margin_bottom: DimensionValue | None = None,
margin_start: DimensionValue | None = None,
margin_end: DimensionValue | None = None,
margin_x: DimensionValue | None = None,
margin_y: DimensionValue | None = None,
width: DimensionValue | None = None,
height: DimensionValue | None = None,
min_width: DimensionValue | None = None,
min_height: DimensionValue | None = None,
max_width: DimensionValue | None = None,
max_height: DimensionValue | None = None,
position: Position | None = None,
top: DimensionValue | None = None,
bottom: DimensionValue | None = None,
left: DimensionValue | None = None,
right: DimensionValue | None = None,
start: DimensionValue | None = None,
end: DimensionValue | None = None,
z_index: int | None = None,
is_hidden: bool | None = None,
id: str | None = None,
aria_label: str | None = None,
aria_labelledby: str | None = None,
aria_describedby: str | None = None,
aria_details: str | None = None,
UNSAFE_class_name: str | None = None,
UNSAFE_style: CSSProperties | None = None,
) -> Element:
"""
An avatar is a thumbnail representation of an entity, such as a user or an organization.

Args:
src: The image URL for the avatar.
is_disabled: Whether the avatar is disabled or not.
size: The size of the avatar. It affects both height and width.
alt: Description of the avatar.
flex: When used in a flex layout, specifies how the element will grow or shrink to fit the space available.
flex_grow: When used in a flex layout, specifies how the element will grow to fit the space available.
flex_shrink: When used in a flex layout, specifies how the element will shrink to fit the space available.
flex_basis: When used in a flex layout, specifies the initial main size of the element.
align_self: Overrides the alignItems property of a flex or grid container.
justify_self: Species how the element is justified inside a flex or grid container.
order: The layout order for the element within a flex or grid container.
grid_area: When used in a grid layout specifies, specifies the named grid area that the element should be placed in within the grid.
grid_row: When used in a grid layout, specifies the row the element should be placed in within the grid.
grid_column: When used in a grid layout, specifies the column the element should be placed in within the grid.
grid_row_start: When used in a grid layout, specifies the starting row to span within the grid.
grid_row_end: When used in a grid layout, specifies the ending row to span within the grid.
grid_column_start: When used in a grid layout, specifies the starting column to span within the grid.
grid_column_end: When used in a grid layout, specifies the ending column to span within the grid.
margin: The margin for all four sides of the element.
margin_top: The margin for the top side of the element.
margin_bottom: The margin for the bottom side of the element.
margin_start: The margin for the logical start side of the element, depending on layout direction.
margin_end: The margin for the logical end side of the element, depending on layout direction.
margin_x: The margin for the left and right sides of the element.
margin_y: The margin for the top and bottom sides of the element.
width: The width of the element.
height: The height of the element.
min_width: The minimum width of the element.
min_height: The minimum height of the element.
max_width: The maximum width of the element.
max_height: The maximum height of the element.
position: Specifies how the element is position.
top: The top position of the element.
bottom: The bottom position of the element.
left: The left position of the element.
right: The right position of the element.
start: The logical start position of the element, depending on layout direction.
end: The logical end position of the element, depending on layout direction.
z_index: The stacking order for the element
is_hidden: Hides the element.
id: The unique identifier of the element.
aria_label: Defines a string value that labels the current element.
aria_labelledby: Identifies the element (or elements) that labels the current element.
aria_describedby: Identifies the element (or elements) that describes the object.
aria_details: Identifies the element (or elements) that provide a detailed, extended description for the object.
UNSAFE_class_name: Set the CSS className for the element. Only use as a last resort. Use style props instead.
UNSAFE_style: Set the inline style for the element. Only use as a last resort. Use style props instead.

Returns:
The rendered avatar element.

"""
return component_element(
"Avatar",
src=src,
is_disabled=is_disabled,
size=size,
alt=alt,
flex=flex,
flex_grow=flex_grow,
flex_shrink=flex_shrink,
flex_basis=flex_basis,
align_self=align_self,
justify_self=justify_self,
order=order,
grid_area=grid_area,
grid_row=grid_row,
grid_column=grid_column,
grid_row_start=grid_row_start,
grid_row_end=grid_row_end,
grid_column_start=grid_column_start,
grid_column_end=grid_column_end,
margin=margin,
margin_top=margin_top,
margin_bottom=margin_bottom,
margin_start=margin_start,
margin_end=margin_end,
margin_x=margin_x,
margin_y=margin_y,
width=width,
height=height,
min_width=min_width,
min_height=min_height,
max_width=max_width,
max_height=max_height,
position=position,
top=top,
bottom=bottom,
left=left,
right=right,
start=start,
end=end,
z_index=z_index,
is_hidden=is_hidden,
id=id,
aria_label=aria_label,
aria_labelledby=aria_labelledby,
aria_describedby=aria_describedby,
aria_details=aria_details,
UNSAFE_class_name=UNSAFE_class_name,
UNSAFE_style=UNSAFE_style,
)
10 changes: 10 additions & 0 deletions plugins/ui/src/deephaven/ui/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@ class SliderChange(TypedDict):
ActionGroupDensity = Literal["compact", "regular"]
TabDensity = Literal["compact", "regular"]
LinkVariant = Literal["primary", "secondary", "over_background"]
AvatarSize = Literal[
"avatar-size-50",
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
"avatar-sie-100",
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
"avatar-size-200",
"avatar-size-300",
"avatar-size-400",
"avatar-size-500",
"avatar-size-600",
"avatar-size-600",
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
]
BadgeVariant = Literal[
"neutral",
"info",
Expand Down
1 change: 1 addition & 0 deletions plugins/ui/src/js/src/elements/model/ElementConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const ELEMENT_NAME = {
actionButton: uiComponentName('ActionButton'),
actionGroup: uiComponentName('ActionGroup'),
actionMenu: uiComponentName('ActionMenu'),
avatar: uiComponentName('Avatar'),
badge: uiComponentName('Badge'),
button: uiComponentName('Button'),
buttonGroup: uiComponentName('ButtonGroup'),
Expand Down
2 changes: 2 additions & 0 deletions plugins/ui/src/js/src/widget/WidgetUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { JSONRPCServerAndClient } from 'json-rpc-2.0';
// wrapped due to how Spectrum collection components consume them.
import {
ActionMenu,
Avatar,
ButtonGroup,
SpectrumCheckbox as Checkbox,
CheckboxGroup,
Expand Down Expand Up @@ -112,6 +113,7 @@ export const elementComponentMap = {
[ELEMENT_NAME.actionButton]: ActionButton,
[ELEMENT_NAME.actionGroup]: ActionGroup,
[ELEMENT_NAME.actionMenu]: ActionMenu,
[ELEMENT_NAME.avatar]: Avatar,
[ELEMENT_NAME.badge]: Badge,
[ELEMENT_NAME.button]: Button,
[ELEMENT_NAME.buttonGroup]: ButtonGroup,
Expand Down
Loading