-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
491 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
packages/core/src/components/AvatarGroup/__stories__/AvatarGroup.stories.module.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/core/src/components/BaseListItem/BaseListItem.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.wrapper { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--spacing-xs); | ||
border-radius: var(--border-radius-small); | ||
color: var(--primary-text-color); | ||
|
||
&:hover:not(.disabled), &.highlighted { | ||
background-color: var(--primary-background-hover-color); | ||
} | ||
|
||
&.disabled { | ||
color: var(--disabled-text-color); | ||
} | ||
|
||
&.selected { | ||
background-color: var(--primary-selected-color); | ||
|
||
&:hover, &.highlighted { | ||
background-color: var(--primary-selected-hover-color); | ||
} | ||
} | ||
|
||
&.small { | ||
padding: 6px 8px; | ||
} | ||
|
||
&.medium { | ||
padding: 10px 12px; | ||
} | ||
|
||
&.large { | ||
padding: 14px 12px; | ||
} | ||
|
||
.avatar, | ||
.icon{ | ||
flex-shrink: 0; | ||
} | ||
|
||
.indent { | ||
width: 20px; | ||
} | ||
|
||
.endElement { | ||
padding-inline-start: var(--spacing-small); | ||
margin-inline-start: auto; | ||
display: flex; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/core/src/components/BaseListItem/BaseListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { forwardRef, useMemo } from "react"; | ||
import cx from "classnames"; | ||
import styles from "./BaseListItem.module.scss"; | ||
import { getStyle } from "../../helpers/typesciptCssModulesHelper"; | ||
import Text from "../Text/Text"; | ||
import { BaseListItemProps } from "./BaseListItem.types"; | ||
import { VibeComponent } from "../../types"; | ||
import { Tooltip } from "../Tooltip"; | ||
import { TextType } from "../Text"; | ||
import { renderSideElement } from "./utils"; | ||
|
||
const BaseListItem: VibeComponent<BaseListItemProps, HTMLLIElement> = forwardRef( | ||
( | ||
{ | ||
label, | ||
size = "medium", | ||
selected, | ||
disabled, | ||
startElement, | ||
endElement, | ||
highlighted, | ||
tooltipProps = {}, | ||
className, | ||
rtl = false, | ||
id, | ||
role = "option", | ||
...rest | ||
}: BaseListItemProps, | ||
ref | ||
) => { | ||
const listItemClassNames = useMemo( | ||
() => | ||
cx( | ||
styles.wrapper, | ||
{ | ||
[styles.selected]: selected, | ||
[styles.disabled]: disabled, | ||
[styles.highlighted]: highlighted | ||
}, | ||
getStyle(styles, size), | ||
className | ||
), | ||
[selected, disabled, highlighted, size, className] | ||
); | ||
|
||
const textVariant: TextType = size === "small" ? "text2" : "text1"; | ||
|
||
return ( | ||
<Tooltip {...tooltipProps} content={tooltipProps?.content} position={rtl ? "left" : "right"}> | ||
<li id={id} ref={ref} className={listItemClassNames} role={role} {...rest}> | ||
{startElement && renderSideElement(startElement, disabled, textVariant)} | ||
<Text type={textVariant} color="inherit"> | ||
{label} | ||
</Text> | ||
{endElement && ( | ||
<div className={styles.endElement}>{renderSideElement(endElement, disabled, textVariant)}</div> | ||
)} | ||
</li> | ||
</Tooltip> | ||
); | ||
} | ||
); | ||
|
||
export default BaseListItem; |
63 changes: 63 additions & 0 deletions
63
packages/core/src/components/BaseListItem/BaseListItem.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { ReactNode, AriaRole } from "react"; | ||
import { SubIcon, VibeComponentProps } from "../../types"; | ||
import { TooltipProps } from "../Tooltip"; | ||
|
||
export interface BaseListItemProps extends React.LiHTMLAttributes<HTMLLIElement>, VibeComponentProps { | ||
value?: string; | ||
/** | ||
* Primary text content of the list item | ||
*/ | ||
label: string; | ||
/** | ||
* Size of the list item. Will influence the padding and font size. | ||
*/ | ||
size?: BaseListItemSizes; | ||
/** | ||
* Indicates whether the list item is selected. | ||
*/ | ||
selected?: boolean; | ||
/** | ||
* Indicates whether the list item is disabled. | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* Element to render at the start of the list item. | ||
* Can be an avatar, icon, inset or a custom rendered element. | ||
*/ | ||
startElement?: StartElement; | ||
/** | ||
* Element to render at the end of the list item. | ||
* Can be an icon, suffix, or a custom rendered element. | ||
*/ | ||
endElement?: EndElement; | ||
/** | ||
* Whether item should have highlight styling | ||
*/ | ||
highlighted?: boolean; | ||
/** | ||
* Use when there's a need to display a tooltip on the list item (e.g., explain why disabled). | ||
*/ | ||
tooltipProps?: Partial<TooltipProps>; | ||
/** | ||
* determines the position of the tooltip according to the direction. | ||
*/ | ||
rtl?: boolean; | ||
/** | ||
* ARIA role for the list item. | ||
*/ | ||
role?: AriaRole; | ||
index?: number; | ||
} | ||
|
||
export type BaseListItemSizes = "small" | "medium" | "large"; | ||
|
||
export type SideElement = | ||
| { type: "avatar"; value: string; square?: boolean } | ||
| { type: "icon"; value: SubIcon } | ||
| { type: "indent" } | ||
| { type: "suffix"; value: string } | ||
| { type: "custom"; render: () => ReactNode }; | ||
|
||
export type StartElement = Extract<SideElement, { type: "avatar" | "icon" | "indent" | "custom" }>; | ||
|
||
export type EndElement = Extract<SideElement, { type: "icon" | "suffix" | "custom" }>; |
32 changes: 32 additions & 0 deletions
32
packages/core/src/components/BaseListItem/__stories__/BaseListItem.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createStoryMetaSettingsDecorator } from "../../../storybook"; | ||
import { createComponentTemplate } from "vibe-storybook-components"; | ||
import BaseListItem from "../BaseListItem"; | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
type Story = StoryObj<typeof BaseListItem>; | ||
|
||
const metaSettings = createStoryMetaSettingsDecorator({ | ||
component: BaseListItem | ||
}); | ||
|
||
export default { | ||
title: "Internal/BaseListItem", | ||
component: BaseListItem, | ||
argTypes: metaSettings.argTypes, | ||
decorators: metaSettings.decorators, | ||
tags: ["internal"] | ||
} satisfies Meta<typeof BaseListItem>; | ||
|
||
const baseListItemTemplate = createComponentTemplate(BaseListItem); | ||
import { Email } from "@vibe/icons"; | ||
import person1 from "./person1.png"; | ||
|
||
export const Overview: Story = { | ||
render: baseListItemTemplate.bind({}), | ||
args: { | ||
label: "This is a list item", | ||
startElement: { type: "avatar", value: person1 }, | ||
endElement: { type: "icon", value: Email }, | ||
tooltipProps: { content: "tooltip content" } | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.