Skip to content

Commit fa1ba0c

Browse files
authored
LG-4511: add badgeProps to BasicEmptyState (#2497)
* Add @leafygreen-ui/badge package * Add badgeProps to BasicEmptyState * Changeset * Update to tokens
1 parent 09a9667 commit fa1ba0c

10 files changed

+63
-53
lines changed

Diff for: .changeset/nine-pillows-decide.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@leafygreen-ui/empty-state': minor
3+
---
4+
5+
[LG-4511](https://jira.mongodb.org/browse/LG-4511): Add optional `badgeProps` to `BasicEmptyState` component

Diff for: packages/empty-state/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { BasicEmptyState } from '@leafygreen-ui/empty-state';
3333
title="No Results Found"
3434
description="Try adjusting your filters or search terms"
3535
graphic={<SvgOrImgComponent />}
36+
badgeProps={{ variant: 'blue', children: 'Optional' }}
3637
primaryButton={<Button />}
3738
secondaryButton={<Button />}
3839
externalLink={<Link />}
@@ -45,6 +46,7 @@ A basic empty state component to be used with MongoDB marketing-approved graphic
4546
| Prop | Type | Description | Default |
4647
| ----------------- | -------------- | ------------------------------------------------------------------------------------------------------------------ | ----------- |
4748
| `graphic` | `ReactElement` | Graphic shown left of text content. The component is designed to be used with MongoDB marketing-approved graphics. | `undefined` |
49+
| `badgeProps` | `BadgeProps` | Optional props to conditionally render a badge. | `undefined` |
4850
| `title`\* | `string` | Heading text. | |
4951
| `description`\* | `ReactChild` | Secondary text. | |
5052
| `primaryButton` | `ReactElement` | Optional primary call-to-action button. | `undefined` |

Diff for: packages/empty-state/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"access": "public"
3131
},
3232
"dependencies": {
33+
"@leafygreen-ui/badge": "^8.1.3",
3334
"@leafygreen-ui/button": "^21.2.1",
3435
"@leafygreen-ui/emotion": "^4.0.8",
3536
"@leafygreen-ui/lib": "^13.3.0",

Diff for: packages/empty-state/src/BasicEmptyState/BasicEmptyState.stories.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '@lg-tools/storybook-utils';
77
import { StoryFn } from '@storybook/react';
88

9+
import { Variant } from '@leafygreen-ui/badge';
910
import Button from '@leafygreen-ui/button';
1011
import { Theme } from '@leafygreen-ui/lib';
1112
import { Link } from '@leafygreen-ui/typography';
@@ -27,6 +28,7 @@ const meta: StoryMetaType<typeof BasicEmptyState> = {
2728
},
2829
argTypes: {
2930
graphic: { control: 'none' },
31+
badgeProps: { control: 'none' },
3032
description: { control: 'text' },
3133
externalLink: { control: 'none' },
3234
primaryButton: { control: 'none' },
@@ -52,6 +54,10 @@ const meta: StoryMetaType<typeof BasicEmptyState> = {
5254
viewBox="0 0 198 131"
5355
/>,
5456
],
57+
badgeProps: [
58+
undefined,
59+
{ variant: Variant.Blue, children: 'Optional' },
60+
],
5561
primaryButton: [
5662
undefined,
5763
<Button key="generated-button">Add Dependency</Button>,
@@ -123,9 +129,10 @@ WithSmallGraphic.args = {
123129
graphicSize: 'small',
124130
};
125131

126-
export const WithActionsAndLink = Template.bind({});
127-
WithActionsAndLink.args = {
132+
export const WithBadgeAndActionsAndLink = Template.bind({});
133+
WithBadgeAndActionsAndLink.args = {
128134
graphic: <LightModeGraphic viewBox="0 0 298 198" />,
135+
badgeProps: { variant: Variant.Blue, children: 'Optional' },
129136
primaryButton: <Button>Add Dependency</Button>,
130137
secondaryButton: <Button>Upload Module</Button>,
131138
externalLink: <Link href="https://www.mongodb.com">Test external link</Link>,
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { css } from '@leafygreen-ui/emotion';
1+
import { css, cx } from '@leafygreen-ui/emotion';
22
import { Theme } from '@leafygreen-ui/lib';
3-
import { palette } from '@leafygreen-ui/palette';
4-
import { spacing } from '@leafygreen-ui/tokens';
3+
import { color, spacing } from '@leafygreen-ui/tokens';
54

65
export const rootStyles = css`
7-
padding: 40px;
6+
padding: ${spacing[1000]}px;
87
display: flex;
9-
gap: ${spacing[3]}px;
8+
gap: ${spacing[400]}px;
109
align-items: center;
1110
justify-content: center;
1211
`;
@@ -15,25 +14,28 @@ export const textContainerStyles = css`
1514
max-width: 432px;
1615
`;
1716

17+
export const getBadgeStyles = (className?: string) =>
18+
cx(
19+
css`
20+
margin-bottom: ${spacing[300]}px;
21+
`,
22+
className,
23+
);
24+
1825
export const titleStyles = css`
19-
margin-bottom: 12px;
26+
margin-bottom: ${spacing[300]}px;
2027
`;
2128

22-
export const descriptionStyles: Record<Theme, string> = {
23-
[Theme.Dark]: css`
24-
color: ${palette.gray.light1};
25-
`,
26-
[Theme.Light]: css`
27-
color: ${palette.gray.dark1};
28-
`,
29-
};
29+
export const getDescriptionStyles = (theme: Theme) => css`
30+
color: ${color[theme].text.secondary.default};
31+
`;
3032

3133
export const buttonContainerStyles = css`
3234
display: flex;
33-
gap: 12px;
34-
margin-top: ${spacing[4]}px;
35+
gap: ${spacing[300]}px;
36+
margin-top: ${spacing[600]}px;
3537
`;
3638

3739
export const externalLinkStyles = css`
38-
margin-top: ${spacing[3]}px;
40+
margin-top: ${spacing[300]}px;
3941
`;

Diff for: packages/empty-state/src/BasicEmptyState/BasicEmptyState.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { forwardRef, Ref } from 'react';
22
import PropTypes from 'prop-types';
33

4+
import Badge from '@leafygreen-ui/badge';
45
import Button from '@leafygreen-ui/button';
56
import LeafyGreenProvider from '@leafygreen-ui/leafygreen-provider';
67
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
@@ -9,8 +10,9 @@ import { Body, H3, Link } from '@leafygreen-ui/typography';
910

1011
import {
1112
buttonContainerStyles,
12-
descriptionStyles,
1313
externalLinkStyles,
14+
getBadgeStyles,
15+
getDescriptionStyles,
1416
rootStyles,
1517
textContainerStyles,
1618
titleStyles,
@@ -21,6 +23,7 @@ export const BasicEmptyState = forwardRef(
2123
(
2224
{
2325
graphic,
26+
badgeProps,
2427
title,
2528
description,
2629
primaryButton,
@@ -55,8 +58,14 @@ export const BasicEmptyState = forwardRef(
5558
<div className={rootStyles} ref={ref}>
5659
{!!graphic && <div>{graphic}</div>}
5760
<div className={textContainerStyles}>
61+
{badgeProps && (
62+
<Badge
63+
{...badgeProps}
64+
className={getBadgeStyles(badgeProps.className)}
65+
/>
66+
)}
5867
<H3 className={titleStyles}>{title}</H3>
59-
<Body className={descriptionStyles[theme]}>{description}</Body>
68+
<Body className={getDescriptionStyles(theme)}>{description}</Body>
6069
{!!primaryButton && (
6170
<div className={buttonContainerStyles}>
6271
<Button {...primaryButton.props} variant="primary" />

Diff for: packages/empty-state/src/BasicEmptyState/BasicEmptyState.types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ReactChild, ReactElement } from 'react';
22

3+
import { BadgeProps } from '@leafygreen-ui/badge';
34
import { DarkModeProps } from '@leafygreen-ui/lib';
45

56
interface EmptyStateWithCTAProps {
@@ -31,6 +32,11 @@ type BasicEmptyStateBaseProps = DarkModeProps & {
3132
*/
3233
graphic?: ReactElement;
3334

35+
/**
36+
* Optional badge props to render a badge component
37+
*/
38+
badgeProps?: BadgeProps;
39+
3440
/**
3541
* Heading text
3642
*/

Diff for: packages/empty-state/src/EmptyState.stories.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { StoryFn } from '@storybook/react';
55
import { css } from '@leafygreen-ui/emotion';
66

77
import BasicEmptyStateStoryMeta, {
8-
WithActionsAndLink,
8+
WithBadgeAndActionsAndLink,
99
WithSmallGraphic,
1010
} from './BasicEmptyState/BasicEmptyState.stories';
1111
import FeaturesEmptyStateStoryMeta, {
@@ -56,15 +56,15 @@ export const LiveExample: StoryFn<StoryProps> = ({
5656
...rest
5757
}: StoryProps) => {
5858
let StoryComponent: StoryFn<BasicEmptyStateProps | FeaturesEmptyStateProps> =
59-
WithActionsAndLink;
59+
WithBadgeAndActionsAndLink;
6060
let storyComponentProps: BasicEmptyStateProps | FeaturesEmptyStateProps =
6161
{} as BasicEmptyStateProps | FeaturesEmptyStateProps;
6262

6363
if (variant === StoryVariant.Basic) {
64-
StoryComponent = WithActionsAndLink;
64+
StoryComponent = WithBadgeAndActionsAndLink;
6565
storyComponentProps = {
6666
...BasicEmptyStateStoryMeta.args,
67-
...WithActionsAndLink.args,
67+
...WithBadgeAndActionsAndLink.args,
6868
} as BasicEmptyStateProps;
6969
} else if (variant === StoryVariant.BasicWithSmallAsset) {
7070
StoryComponent = WithSmallGraphic;

Diff for: packages/empty-state/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
],
1717
"exclude": ["**/*.spec.*", "**/*.stories.*"],
1818
"references": [
19+
{
20+
"path": "../badge"
21+
},
1922
{
2023
"path": "../button"
2124
},

Diff for: yarn.lock

+3-28
Original file line numberDiff line numberDiff line change
@@ -14647,16 +14647,7 @@ string-length@^4.0.1:
1464714647
char-regex "^1.0.2"
1464814648
strip-ansi "^6.0.0"
1464914649

14650-
"string-width-cjs@npm:string-width@^4.2.0":
14651-
version "4.2.3"
14652-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
14653-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
14654-
dependencies:
14655-
emoji-regex "^8.0.0"
14656-
is-fullwidth-code-point "^3.0.0"
14657-
strip-ansi "^6.0.1"
14658-
14659-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
14650+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1466014651
version "4.2.3"
1466114652
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1466214653
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -14743,14 +14734,7 @@ string_decoder@~1.1.1:
1474314734
dependencies:
1474414735
safe-buffer "~5.1.0"
1474514736

14746-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
14747-
version "6.0.1"
14748-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
14749-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
14750-
dependencies:
14751-
ansi-regex "^5.0.1"
14752-
14753-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
14737+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1475414738
version "6.0.1"
1475514739
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1475614740
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -15957,7 +15941,7 @@ wordwrap@^1.0.0:
1595715941
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
1595815942
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
1595915943

15960-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
15944+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1596115945
version "7.0.0"
1596215946
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1596315947
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -15975,15 +15959,6 @@ wrap-ansi@^6.2.0:
1597515959
string-width "^4.1.0"
1597615960
strip-ansi "^6.0.0"
1597715961

15978-
wrap-ansi@^7.0.0:
15979-
version "7.0.0"
15980-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
15981-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
15982-
dependencies:
15983-
ansi-styles "^4.0.0"
15984-
string-width "^4.1.0"
15985-
strip-ansi "^6.0.0"
15986-
1598715962
wrap-ansi@^8.1.0:
1598815963
version "8.1.0"
1598915964
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)