Skip to content

Commit

Permalink
feat(ActionList): add ActionListItemAvatar component for leading prop (
Browse files Browse the repository at this point in the history
…#2341)

* feat: add ActionListItemAvatar

* Create swift-cougars-attend.md

* fix: build

* fix: buil
  • Loading branch information
saurabhdaware authored Aug 29, 2024
1 parent 122476e commit eaa75c6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-cougars-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/blade": minor
---

feat(ActionList): add ActionListItemAvatar component for leading prop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ActionListProps } from './ActionList';
import { ActionList as ActionListComponent } from './ActionList';
import {
ActionListItem,
ActionListItemAvatar,
ActionListItemBadge,
ActionListItemBadgeGroup,
ActionListItemIcon,
Expand Down Expand Up @@ -241,7 +242,9 @@ const ActionListWithCustomItemsExample: StoryFn<typeof ActionListComponent> = ()
<ActionListItem
title="Profile"
value="profile"
leading={<ActionListItemIcon icon={UserIcon} />}
leading={
<ActionListItemAvatar icon={UserIcon} color="primary" name="Saurabh Daware" />
}
/>
<ActionListItem
title="Credit"
Expand Down
11 changes: 11 additions & 0 deletions packages/blade/src/components/ActionList/ActionListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { Box } from '~components/Box';
import { dropdownComponentIds } from '~components/Dropdown/dropdownComponentIds';
import { BaseMenuItem, useBaseMenuItem } from '~components/BaseMenu';
import { Checkbox } from '~components/Checkbox';
import type { AvatarProps } from '~components/Avatar/types';
import { Avatar } from '~components/Avatar';

type ActionListItemProps = {
title: string;
Expand Down Expand Up @@ -210,6 +212,14 @@ const ActionListItemBadgeGroup = assignWithoutSideEffects(_ActionListItemBadgeGr
componentId: componentIds.ActionListItemBadgeGroup,
});

const _ActionListItemAvatar = (avatarProps: Omit<AvatarProps, 'size' | ''>): React.ReactElement => {
return <Avatar size="xsmall" {...avatarProps} />;
};

const ActionListItemAvatar = assignWithoutSideEffects(_ActionListItemAvatar, {
componentId: componentIds.ActionListItemAvatar,
});

const _ActionListItemBadge = (props: BadgeProps): React.ReactElement => {
return <Badge size="medium" marginLeft="spacing.3" {...props} />;
};
Expand Down Expand Up @@ -406,6 +416,7 @@ export {
ActionListItem,
ActionListItemIcon,
ActionListItemText,
ActionListItemAvatar,
ActionListItemBadge,
ActionListItemBadgeGroup,
ActionListSection,
Expand Down
5 changes: 3 additions & 2 deletions packages/blade/src/components/ActionList/actionListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@ const validateActionListItemProps = ({
if (
!isValidAllowedChildren(child, componentIds.ActionListItemIcon) &&
!isValidAllowedChildren(child, componentIds.ActionListItemText) &&
!isValidAllowedChildren(child, componentIds.ActionListItemAsset)
!isValidAllowedChildren(child, componentIds.ActionListItemAsset) &&
!isValidAllowedChildren(child, componentIds.ActionListItemAvatar)
) {
throwBladeError({
message: `Only ${componentIds.ActionListItemIcon}, ${componentIds.ActionListItemAsset}, and ${componentIds.ActionListItemText} are allowed in leading prop`,
message: `Only ${componentIds.ActionListItemIcon}, ${componentIds.ActionListItemAvatar}, ${componentIds.ActionListItemAsset}, and ${componentIds.ActionListItemText} are allowed in leading prop`,
moduleName: 'ActionListItem',
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/blade/src/components/ActionList/componentIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const componentIds = {
ActionListItemBadgeGroup: 'ActionListItemBadgeGroup',
ActionListItemAsset: 'ActionListItemAsset',
ActionListItemIcon: 'ActionListItemIcon',
ActionListItemAvatar: 'ActionListItemAvatar',
ActionListItemText: 'ActionListItemText',
ActionListSection: 'ActionListSection',
};

0 comments on commit eaa75c6

Please sign in to comment.