Skip to content

Commit

Permalink
feat(entity-list-item): added isSelected prop to entity list item, an…
Browse files Browse the repository at this point in the history
…d it's corresponding style

feat contentful#2077
  • Loading branch information
mgueyraud committed Jun 21, 2022
1 parent f94572d commit 133d1f3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/components/entity-list/src/EntityList.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ export const getEntityListStyles = () => ({
borderBottom: 'none',
borderRadius: tokens.borderRadiusMedium,
overflow: 'hidden',
'& li:first-child': {
borderTopLeftRadius: tokens.borderRadiusMedium,
borderTopRightRadius: tokens.borderRadiusMedium,
},
'& li:last-child': {
borderBottomLeftRadius: tokens.borderRadiusMedium,
borderBottomRightRadius: tokens.borderRadiusMedium,
},
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tokens from '@contentful/f36-tokens';
import { EntityListItemProps } from './EntityListItem';

export const getEntityListItemStyles = () => ({
root: (props: Pick<EntityListItemProps, 'isDragActive'>) =>
root: (props: Pick<EntityListItemProps, 'isDragActive' | 'isSelected'>) =>
css({
display: 'flex',
boxShadow: `inset 0 -1px 0 ${tokens.gray200}`,
Expand All @@ -18,8 +18,16 @@ export const getEntityListItemStyles = () => ({
: {}),

'&:hover': {
backgroundColor: tokens.gray100,
backgroundColor: props.isSelected ? tokens.blue100 : tokens.gray100,
},
...(props.isSelected
? {
backgroundColor: tokens.blue100,
borderStyle: 'solid',
borderColor: tokens.colorPrimary,
borderWidth: 1,
}
: {}),
}),
card: css({
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export interface EntityListItemProps extends CommonProps {
* A boolean used to disable the CardActions
*/
isActionsDisabled?: boolean;
/**
* Applies selected styles to the element
*/
isSelected?: boolean;
}

export const EntityListItem = ({
Expand All @@ -134,6 +138,7 @@ export const EntityListItem = ({
cardDragHandleProps,
cardDragHandleComponent,
isActionsDisabled = false,
isSelected = false,
...otherProps
}: EntityListItemProps): React.ReactElement => {
const styles = getEntityListItemStyles();
Expand Down Expand Up @@ -165,7 +170,7 @@ export const EntityListItem = ({
return (
<li
{...otherProps}
className={cx(styles.root({ isDragActive }), className)}
className={cx(styles.root({ isDragActive, isSelected }), className)}
data-test-id={testId}
>
{renderCardDragHandle()}
Expand Down
37 changes: 36 additions & 1 deletion packages/components/entity-list/stories/EntityList.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import type { Meta, Story } from '@storybook/react/types-6-0';

import { EntityList } from '../src';
Expand Down Expand Up @@ -36,6 +36,41 @@ export const Basic: Story<EntityListProps> = () => (
</EntityList>
);

export const SelectableEntryListItems: Story<EntityListProps> = () => {
const [firstEntry, setFirstEntry] = useState(false);
const [secondEntry, setSecondEntry] = useState(false);
const [thirdEntry, setThirdEntry] = useState(false);

return (
<EntityList>
<EntityList.Item
title="Entry 1"
description="Description"
contentType="My content type"
status="published"
isSelected={firstEntry}
onClick={() => setFirstEntry(!firstEntry)}
/>
<EntityList.Item
title="Entry 2"
description="Description"
contentType="My content type"
status="draft"
isSelected={secondEntry}
onClick={() => setSecondEntry(!secondEntry)}
/>
<EntityList.Item
title="Entry 3"
description="Description"
contentType="My content type"
status="archived"
isSelected={thirdEntry}
onClick={() => setThirdEntry(!thirdEntry)}
/>
</EntityList>
);
};

export const withDragHandle = () => (
<EntityList>
<EntityList.Item
Expand Down

0 comments on commit 133d1f3

Please sign in to comment.