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 to start using it in Entity explorer #38344

Merged
merged 10 commits into from
Dec 30, 2024
37 changes: 23 additions & 14 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",
},
},
},
rightControlVisibility: {
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",
},
description: {
control: "text",
description: "Description text to be shown alongside the title",
Expand Down Expand Up @@ -140,11 +146,12 @@ const ListItemArgTypes = {
},
},
},
onEndIconClick: {
description: "callback for when the end icon is clicked",
customTitleComponent: {
description:
"A custom title component for the list item to use input component for name editing",
table: {
type: {
summary: "() => void",
summary: "ReactNode",
},
},
},
Expand All @@ -163,7 +170,7 @@ ListItemLargeStory.args = {
description: "inline",
descriptionType: "inline",
size: "lg",
endIcon: "add-more",
rightControl: <Icon name="add-more" size={"md"} />,
};

export const ListItemErrorStory = ListItemTemplate.bind({}) as StoryObj;
Expand Down Expand Up @@ -215,10 +222,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;
}
`;
62 changes: 17 additions & 45 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,48 +103,31 @@ 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}
{startIcon}
{props.customTitleComponent ? (
props.customTitleComponent
) : (
<InlineDescriptionWrapper>
<DescriptionWrapper>
<TextWithTooltip
Expand Down Expand Up @@ -175,20 +157,10 @@ function ListItem(props: ListItemProps) {
</TextWithTooltip>
)}
</InlineDescriptionWrapper>
</ContentTextWrapper>
)}
</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
14 changes: 8 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,17 +23,19 @@ 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 */
wrapperClassName?: string;
/** id for the list item */
id?: string;
/** customTitleComponent for the list item to use input component for name editing */
customTitleComponent?: ReactNode | ReactNode[];
}

export interface ListProps {
Expand Down
Loading
Loading