Skip to content

Commit 4705603

Browse files
committed
feat(MenuV2): add empty state on groups
1 parent 781be4f commit 4705603

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

.changeset/every-pianos-hide.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": minor
3+
---
4+
5+
Add prop `emptyState` on `<MenuV2.Group />` that can be usefull when searching

packages/ui/src/components/MenuV2/__stories__/Searchable.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const Searchable: StoryFn<typeof MenuV2> = () => (
1818
/>
1919
}
2020
>
21-
<MenuV2.Group label="Projects">
21+
<MenuV2.Group label="Projects" emptyState="No project">
2222
<MenuV2.Item sentiment="primary" active>
2323
<Stack direction="row" gap={1} alignItems="center">
2424
<AvatarV2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled from '@emotion/styled'
2-
import type { ReactNode } from 'react'
2+
import { Children, type ReactNode } from 'react'
33
import { Stack } from '../../Stack'
44
import { Text } from '../../Text'
55

@@ -12,23 +12,36 @@ type GroupProps = {
1212
label: string
1313
children: ReactNode
1414
labelDescription?: ReactNode
15+
/**
16+
* Empty state will be shown when there are no children
17+
*/
18+
emptyState?: ReactNode
1519
}
1620

17-
export const Group = ({ label, children, labelDescription }: GroupProps) => (
18-
<>
19-
<Container>
20-
<Stack gap={1} alignItems="center" direction="row">
21-
<Text
22-
variant="captionStrong"
23-
as="span"
24-
prominence="weak"
25-
sentiment="neutral"
26-
>
27-
{label}
28-
</Text>
29-
{labelDescription || null}
30-
</Stack>
31-
</Container>
32-
{children}
33-
</>
34-
)
21+
export const Group = ({
22+
label,
23+
children,
24+
labelDescription,
25+
emptyState,
26+
}: GroupProps) => {
27+
const isChildrenEmpty = Children.count(children) === 0
28+
29+
return (
30+
<>
31+
<Container>
32+
<Stack gap={1} alignItems="center" direction="row">
33+
<Text
34+
variant="captionStrong"
35+
as="span"
36+
prominence="weak"
37+
sentiment="neutral"
38+
>
39+
{label}
40+
</Text>
41+
{labelDescription || null}
42+
</Stack>
43+
</Container>
44+
{isChildrenEmpty && emptyState ? emptyState : children}
45+
</>
46+
)
47+
}

0 commit comments

Comments
 (0)