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

chore: updating list item and list components in ADS #38344

Open
wants to merge 4 commits into
base: release
Choose a base branch
from
Open
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
39 changes: 20 additions & 19 deletions app/client/packages/design-system/ads/src/List/List.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { List, ListItem, Icon } from "@appsmith/ads";
import { List, ListItem, Icon, Button } from "@appsmith/ads";
import type { StoryObj } from "@storybook/react";
import type { ListItemProps, ListProps } from "@appsmith/ads";

Expand Down Expand Up @@ -79,15 +79,21 @@ const ListItemArgTypes = {
},
},
},
endIcon: {
control: "text",
description: "The icon to display at the end of the list item",
rightControl: {
description: "The control to display at the end of the list item",
table: {
type: {
summary: "string",
summary: "ReactNode",
},
},
},
rightContolVisibility: {
description:
"`always` type will show the right control always. `hover` type will show the right control only when the list item is hovered.",
control: "radio",
options: ["always", "hover"],
defaultValue: "always",
},
ankitakinger marked this conversation as resolved.
Show resolved Hide resolved
description: {
control: "text",
description: "Description text to be shown alongside the title",
Expand Down Expand Up @@ -140,14 +146,6 @@ const ListItemArgTypes = {
},
},
},
onEndIconClick: {
description: "callback for when the end icon is clicked",
table: {
type: {
summary: "() => void",
},
},
},
};

function ListItemTemplate(args: JSX.IntrinsicAttributes & ListItemProps) {
Expand All @@ -163,7 +161,8 @@ ListItemLargeStory.args = {
description: "inline",
descriptionType: "inline",
size: "lg",
endIcon: "add-more",
rightControl: <Icon name="add-more" size={"md"} />,
rightControlVisibility: "hover",
};

export const ListItemErrorStory = ListItemTemplate.bind({}) as StoryObj;
Expand Down Expand Up @@ -215,10 +214,12 @@ ListItemOverflowStory.args = {
title: "Action item 1 Action item 1 Action item 1 Action item 1",
};

export const ListItemEndIconStory = ListItemTemplate.bind({}) as StoryObj;
ListItemEndIconStory.storyName = "List item end icon";
ListItemEndIconStory.argTypes = ListItemArgTypes;
ListItemEndIconStory.args = {
export const ListItemRightControlStory = ListItemTemplate.bind({}) as StoryObj;
ListItemRightControlStory.storyName = "List item right control";
ListItemRightControlStory.argTypes = ListItemArgTypes;
ListItemRightControlStory.args = {
title: "Action item 1",
endIcon: "add-more",
rightControl: (
<Button isIconButton kind="tertiary" size={"sm"} startIcon="add-more" />
),
};
92 changes: 49 additions & 43 deletions app/client/packages/design-system/ads/src/List/List.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,49 @@ export const StyledList = styled.div`
gap: var(--ads-v2-spaces-2);
`;

export const Wrapper = styled.div`
export const Wrapper = styled.div<{
rightControlVisibility?: "hover" | "always";
}>`
display: flex;
width: 100%;
align-items: center;
gap: var(--ads-v2-spaces-3);
cursor: pointer;
box-sizing: border-box;
position: relative;
border-radius: var(--ads-v2-border-radius);
min-height: 32px;

${(props) =>
props.rightControlVisibility === "hover" &&
`
${RightControlWrapper} { display: none; }
&:hover ${RightControlWrapper} { display: block; }`}

&:hover {
background-color: var(--ads-v2-colors-content-surface-hover-bg);
}

&:active {
background-color: var(--ads-v2-colors-content-surface-active-bg);
}

&[data-selected="true"] {
background-color: var(--ads-v2-colors-content-surface-active-bg);
}

/* disabled style */
&[data-disabled="true"] {
cursor: not-allowed;
opacity: var(--ads-v2-opacity-disabled);
background-color: var(--ads-v2-colors-content-surface-default-bg);
}

/* Focus styles */
&:focus-visible {
outline: var(--ads-v2-border-width-outline) solid
var(--ads-v2-color-outline);
outline-offset: var(--ads-v2-offset-outline);
}
`;

export const TooltipTextWrapper = styled.div`
Expand All @@ -56,13 +91,6 @@ export const ContentWrapper = styled.div`
gap: var(--ads-v2-spaces-3);
`;

export const ContentTextWrapper = styled.div`
display: flex;
gap: var(--ads-v2-spaces-3);
flex: 1;
min-width: 0;
`;

export const DescriptionWrapper = styled.div`
flex-direction: column;
min-width: 0;
Expand All @@ -79,30 +107,32 @@ export const InlineDescriptionWrapper = styled.div`
flex: 1;
`;

export const EndIconWrapper = styled.div`
position: absolute;
right: var(--ads-v2-spaces-3);
export const RightControlWrapper = styled.div`
height: 100%;

button {
height: 100% !important;
width: 32px;
}
`;

export const StyledListItem = styled.div<{
size: ListSizes;
endIcon?: string;
isBlockDescription: boolean;
}>`
${Variables};

display: flex;
width: 100%;
align-items: center;
border-radius: var(--ads-v2-border-radius);
padding: var(--ads-v2-spaces-3);
box-sizing: border-box;
// 40px is the offset to make it look like the end icon is part of this div
${(props) => !!props.endIcon && `padding: 8px 40px 8px 8px;`}}
padding: var(--ads-v2-spaces-2) var(--ads-v2-spaces-2) var(--ads-v2-spaces-2)
var(--ads-v2-spaces-3);
gap: var(--ads-v2-spaces-3);
overflow: hidden;

${({ size }) => Sizes[size]}


& .${ListItemTextOverflowClassName} {
overflow: hidden;
white-space: nowrap;
Expand All @@ -126,30 +156,6 @@ export const StyledListItem = styled.div<{

& .${ListItemIDescClassName} {
font-size: var(--listitem-idescription-font-size);
}

&:hover {
background-color: var(--ads-v2-colors-content-surface-hover-bg);
}

&:active {
background-color: var(--ads-v2-colors-content-surface-active-bg);
}

&[data-selected="true"] {
background-color: var(--ads-v2-colors-content-surface-active-bg);
}

/* disabled style */
&[data-disabled="true"] {
cursor: not-allowed;
opacity: var(--ads-v2-opacity-disabled);
}

/* Focus styles */
&:focus-visible {
outline: var(--ads-v2-border-width-outline) solid
var(--ads-v2-color-outline);
outline-offset: var(--ads-v2-offset-outline);
line-height: 16px;
}
`;
102 changes: 35 additions & 67 deletions app/client/packages/design-system/ads/src/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import clsx from "classnames";

import type { ListItemProps, ListProps } from "./List.types";
import {
ContentTextWrapper,
DescriptionWrapper,
EndIconWrapper,
InlineDescriptionWrapper,
RightControlWrapper,
StyledList,
StyledListItem,
TooltipTextWrapper,
Wrapper,
} from "./List.styles";
import type { TextProps } from "../Text";
import { Text } from "../Text";
import { Button } from "../Button";
import { Tooltip } from "../Tooltip";
import {
ListClassName,
Expand Down Expand Up @@ -85,8 +83,9 @@ function ListItem(props: ListItemProps) {
const {
description,
descriptionType = "inline",
endIcon,
hasError,
rightControl,
rightControlVisibility = "always",
size = "md",
startIcon,
title,
Expand All @@ -104,91 +103,60 @@ function ListItem(props: ListItemProps) {
}
};

const endIconhandleKeyDown = (e: React.KeyboardEvent) => {
e.stopPropagation();

if (!props.isDisabled && props.onEndIconClick) {
switch (e.key) {
case "Enter":
case " ":
props.onEndIconClick();
break;
}
}
};

const endIconOnClick = (e: React.MouseEvent) => {
e.stopPropagation();

if (!props.isDisabled && props.onEndIconClick) {
props.onEndIconClick();
}
};

const handleOnClick = () => {
if (!props.isDisabled && props.onClick) {
props.onClick();
}
};

return (
<Wrapper className={clsx(ListItemWrapperClassName, props.wrapperClassName)}>
<Wrapper
className={clsx(ListItemWrapperClassName, props.wrapperClassName)}
data-disabled={props.isDisabled || false}
data-selected={props.isSelected}
rightControlVisibility={rightControlVisibility}
tabIndex={props.isDisabled ? -1 : 0}
>
<StyledListItem
className={clsx(ListItemClassName, props.className)}
data-disabled={props.isDisabled || false}
data-selected={props.isSelected}
endIcon={props.endIcon}
isBlockDescription={isBlockDescription}
onClick={handleOnClick}
onKeyDown={listItemhandleKeyDown}
size={size}
tabIndex={props.isDisabled ? -1 : 0}
>
<ContentTextWrapper>
{startIcon}
<InlineDescriptionWrapper>
<DescriptionWrapper>
<TextWithTooltip
className={ListItemTitleClassName}
color={hasError ? "var(--ads-v2-color-fg-error)" : undefined}
>
{title}
</TextWithTooltip>
{isBlockDescription && description && (
<TextWithTooltip
className={ListItemBDescClassName}
color="var(--ads-v2-color-fg-muted)"
isMultiline
kind="body-s"
>
{description}
</TextWithTooltip>
)}
</DescriptionWrapper>
{!isBlockDescription && description && (
{startIcon}
<InlineDescriptionWrapper>
<DescriptionWrapper>
<TextWithTooltip
className={ListItemTitleClassName}
color={hasError ? "var(--ads-v2-color-fg-error)" : undefined}
>
{title}
</TextWithTooltip>
{isBlockDescription && description && (
<TextWithTooltip
className={ListItemIDescClassName}
className={ListItemBDescClassName}
color="var(--ads-v2-color-fg-muted)"
isMultiline
kind="body-s"
>
{description}
</TextWithTooltip>
)}
</InlineDescriptionWrapper>
</ContentTextWrapper>
</DescriptionWrapper>
{!isBlockDescription && description && (
<TextWithTooltip
className={ListItemIDescClassName}
color="var(--ads-v2-color-fg-muted)"
kind="body-s"
>
{description}
</TextWithTooltip>
)}
</InlineDescriptionWrapper>
</StyledListItem>
{endIcon && (
<EndIconWrapper>
<Button
isDisabled={props.isDisabled}
isIconButton
kind="tertiary"
onClick={endIconOnClick}
onKeyDown={endIconhandleKeyDown}
size={"sm"}
startIcon={endIcon}
/>
</EndIconWrapper>
{rightControl && (
<RightControlWrapper>{rightControl}</RightControlWrapper>
)}
</Wrapper>
);
Expand Down
12 changes: 6 additions & 6 deletions app/client/packages/design-system/ads/src/List/List.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export type ListSizes = Extract<Sizes, "md" | "lg">;
export interface ListItemProps {
/** The icon to display before the list item title. */
startIcon?: ReactNode;
/** The icon to display at the end. Pass name of the icon from remix-icon library(eg: home-2-line) or an svg icon. */
endIcon?: string;
/** callback for when the endIcon is clicked */
onEndIconClick?: () => void;
/** The control to display at the end. */
rightControl?: ReactNode;
/** */
rightControlVisibility?: "hover" | "always";
/** callback for when the list item is clicked */
onClick: () => void;
/** Whether the list item is disabled. */
Expand All @@ -23,11 +23,11 @@ export interface ListItemProps {
/** The title/label of the list item */
title: string;
/** Description text to be shown alongside the title */
description: string;
description?: string;
/** `inline` type will show the description beside the title. `block` type will show the description
* below the title.
*/
descriptionType: "inline" | "block";
descriptionType?: "inline" | "block";
/** class names for the list item */
className?: string;
/** class names for the wrapper */
Expand Down
Loading
Loading