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" />
),
};
117 changes: 61 additions & 56 deletions app/client/packages/design-system/ads/src/List/List.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,11 @@ const Sizes = {
`,
};

export const StyledList = styled.div`
width: 100%;
height: 100%;
overflow: auto;
padding: var(--ads-v2-spaces-1);
display: flex;
flex-direction: column;
gap: var(--ads-v2-spaces-2);
`;

export const Wrapper = styled.div`
display: flex;
width: 100%;
align-items: center;
gap: var(--ads-v2-spaces-3);
cursor: pointer;
box-sizing: border-box;
position: relative;
`;

export const TooltipTextWrapper = styled.div`
display: flex;
min-width: 0;
`;

export const ContentWrapper = styled.div`
display: flex;
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 @@ -74,34 +42,24 @@ export const InlineDescriptionWrapper = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
min-width: 0;
gap: var(--ads-v2-spaces-3);
flex: 1;
min-width: 0;
`;

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

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

export const ContentTextWrapper = styled.div`
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;`}}

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

gap: var(--ads-v2-spaces-3);
overflow: hidden;
flex: 1;
min-width: 0;

& .${ListItemTextOverflowClassName} {
overflow: hidden;
Expand All @@ -115,7 +73,7 @@ export const StyledListItem = styled.div<{
}

& .${ListItemBDescClassName} {
-webkit-line-clamp: 2;
-webkit-line-clamp: 1;
display: -webkit-box;
-webkit-box-orient: vertical;
text-overflow: initial;
Expand All @@ -126,14 +84,52 @@ export const StyledListItem = styled.div<{

& .${ListItemIDescClassName} {
font-size: var(--listitem-idescription-font-size);
line-height: 16px;
}
`;

&:hover {
background-color: var(--ads-v2-colors-content-surface-hover-bg);
export const StyledList = styled.div`
width: 100%;
height: 100%;
overflow: auto;
padding: var(--ads-v2-spaces-1);
display: flex;
flex-direction: column;
gap: var(--ads-v2-spaces-2);
`;

export const StyledListItem = styled.div<{
size: ListSizes;
}>`
${Variables};

display: flex;
width: 100%;
align-items: center;
cursor: pointer;
box-sizing: border-box;
position: relative;
border-radius: var(--ads-v2-border-radius);
padding: var(--ads-v2-spaces-2);
padding-left: var(--ads-v2-spaces-3);

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

&[data-isblockdescription="true"] {
height: 54px;
}

&:active {
background-color: var(--ads-v2-colors-content-surface-active-bg);
&[data-isblockdescription="false"] {
height: 32px;
}

&[data-rightcontrolvisibility="hover"] {
${RightControlWrapper} {
display: none;
}
&:hover ${RightControlWrapper} {
display: block;
}
}

&[data-selected="true"] {
Expand All @@ -144,6 +140,15 @@ export const StyledListItem = styled.div<{
&[data-disabled="true"] {
cursor: not-allowed;
opacity: var(--ads-v2-opacity-disabled);
background-color: var(--ads-v2-colors-content-surface-default-bg);
}

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

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

/* Focus styles */
Expand Down
72 changes: 22 additions & 50 deletions app/client/packages/design-system/ads/src/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ 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)}>
<StyledListItem
<StyledListItem
className={clsx(ListItemWrapperClassName, props.wrapperClassName)}
data-disabled={props.isDisabled || false}
data-isblockdescription={isBlockDescription}
data-rightcontrolvisibility={rightControlVisibility}
data-selected={props.isSelected}
size={size}
tabIndex={props.isDisabled ? -1 : 0}
>
<ContentTextWrapper
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,22 +157,12 @@ 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>
)}
</ContentTextWrapper>
{rightControl && (
<RightControlWrapper>{rightControl}</RightControlWrapper>
)}
</Wrapper>
</StyledListItem>
);
}

Expand Down
Loading
Loading