Skip to content

Commit 2d09f14

Browse files
author
Jannik Weise
committed
✨ Adds option to force bottom line in list item
Adds a `shouldForceBottomLine` prop to the List Item component. This allows forcing the bottom line to be displayed even if the item is the last in the list or under other conditions where it would normally be hidden.
1 parent ea5a967 commit 2d09f14

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

packages/core/src/components/list/list-item/ListItem.styles.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider'
44

55
type StyledListItemProps = WithTheme<{
66
$isClickable: boolean;
7-
$isOpen: boolean;
87
$isInAccordion: boolean;
8+
$isOpen: boolean;
99
$isWrapped: boolean;
10-
$shouldHideIndicator: boolean;
1110
$shouldForceBackground?: boolean;
12-
$shouldShowSeparatorBelow: boolean;
11+
$shouldForceBottomLine?: boolean;
1312
$shouldHideBottomLine: boolean;
13+
$shouldHideIndicator: boolean;
14+
$shouldShowSeparatorBelow: boolean;
1415
}>;
1516

1617
export const StyledMotionListItem = styled(motion.div)<StyledListItemProps>`
@@ -38,18 +39,27 @@ export const StyledMotionListItem = styled(motion.div)<StyledListItemProps>`
3839
}
3940
`}
4041
42+
${({ $shouldForceBottomLine, $shouldShowSeparatorBelow, theme }: StyledListItemProps) =>
43+
$shouldForceBottomLine &&
44+
css`
45+
border-bottom: ${$shouldShowSeparatorBelow ? '4px' : '1px'} solid
46+
rgba(${theme['headline-rgb']}, 0.5);
47+
`}
48+
4149
${({
42-
$isOpen,
4350
$isInAccordion,
51+
$isOpen,
4452
$isWrapped,
45-
$shouldShowSeparatorBelow,
4653
$shouldHideBottomLine,
54+
$shouldForceBottomLine,
55+
$shouldShowSeparatorBelow,
4756
theme,
4857
}: StyledListItemProps) =>
4958
($shouldShowSeparatorBelow ||
5059
((!$isOpen || $isWrapped || $isInAccordion) &&
5160
theme.accordionLines &&
52-
!$shouldHideBottomLine)) &&
61+
!$shouldHideBottomLine &&
62+
!$shouldForceBottomLine)) &&
5363
css`
5464
&&:not(:last-child) {
5565
border-bottom: ${$shouldShowSeparatorBelow ? '4px' : '1px'} solid

packages/core/src/components/list/list-item/ListItem.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export type ListItemProps = {
9595
* This will force the background color of the ListItem to be used even if it is closed and not hovered.
9696
*/
9797
shouldForceBackground?: boolean;
98+
/**
99+
* Whether the line should be forced, e.g., so that it is also displayed if the item is the last element in the list.
100+
*/
101+
shouldForceBottomLine?: boolean;
98102
/**
99103
* Whether the hover item should be forced.
100104
*/
@@ -129,7 +133,7 @@ export type ListItemProps = {
129133
*/
130134
shouldRenderClosed?: boolean;
131135
/**
132-
* Whether the image or icon should be displayed in a round shape. This should be always used for images of persons.
136+
* Whether the image or icon should be displayed in a round shape. This should always be used for images of persons.
133137
*/
134138
shouldShowRoundImageOrIcon?: boolean;
135139
/**
@@ -167,15 +171,16 @@ const ListItem: FC<ListItemProps> = ({
167171
onOpen,
168172
rightElements,
169173
shouldForceBackground = false,
174+
shouldForceBottomLine = false,
175+
shouldForceHover = false,
170176
shouldHideBottomLine = false,
177+
shouldOpenImageOnClick = false,
171178
shouldHideImageOrIconBackground,
172179
shouldHideIndicator = false,
173-
shouldOpenImageOnClick = false,
174180
shouldPreventLayoutAnimation = false,
181+
shouldRenderClosed = false,
175182
shouldShowRoundImageOrIcon,
176183
shouldShowSeparatorBelow = false,
177-
shouldForceHover = false,
178-
shouldRenderClosed = false,
179184
subtitle,
180185
title,
181186
titleElement,
@@ -261,6 +266,7 @@ const ListItem: FC<ListItemProps> = ({
261266
$isOpen={isItemOpen}
262267
$isWrapped={isWrapped}
263268
$shouldForceBackground={shouldForceBackground}
269+
$shouldForceBottomLine={shouldForceBottomLine}
264270
$shouldHideBottomLine={shouldHideBottomLine}
265271
$shouldHideIndicator={shouldHideIndicator}
266272
$shouldShowSeparatorBelow={shouldShowSeparatorBelow}

0 commit comments

Comments
 (0)