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

feat(MenuV2): add empty state on groups #4895

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/every-pianos-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/ui": minor
---

Add prop `emptyState` on `<MenuV2.Group />` that can be usefull when searching
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Searchable: StoryFn<typeof MenuV2> = () => (
/>
}
>
<MenuV2.Group label="Projects">
<MenuV2.Group label="Projects" emptyState="No project">
<MenuV2.Item sentiment="primary" active>
<Stack direction="row" gap={1} alignItems="center">
<AvatarV2
Expand Down
51 changes: 32 additions & 19 deletions packages/ui/src/components/MenuV2/components/Group.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from '@emotion/styled'
import type { ReactNode } from 'react'
import { Children, type ReactNode } from 'react'
import { Stack } from '../../Stack'
import { Text } from '../../Text'

Expand All @@ -12,23 +12,36 @@ type GroupProps = {
label: string
children: ReactNode
labelDescription?: ReactNode
/**
* Empty state will be shown when there are no children
*/
emptyState?: ReactNode
}

export const Group = ({ label, children, labelDescription }: GroupProps) => (
<>
<Container>
<Stack gap={1} alignItems="center" direction="row">
<Text
variant="captionStrong"
as="span"
prominence="weak"
sentiment="neutral"
>
{label}
</Text>
{labelDescription || null}
</Stack>
</Container>
{children}
</>
)
export const Group = ({
label,
children,
labelDescription,
emptyState,
}: GroupProps) => {
const isChildrenEmpty = Children.count(children) === 0

return (
<>
<Container>
<Stack gap={1} alignItems="center" direction="row">
<Text
variant="captionStrong"
as="span"
prominence="weak"
sentiment="neutral"
>
{label}
</Text>
{labelDescription || null}
</Stack>
</Container>
{isChildrenEmpty && emptyState ? emptyState : children}
</>
)
}
Loading