Skip to content

Commit

Permalink
Merge branch 'improvement/epmty-state-api' into q/1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Jun 6, 2024
2 parents f81b9aa + 392377e commit 6ad28d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
19 changes: 7 additions & 12 deletions src/lib/components/emptystate/Emptystate.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import styled, { css } from 'styled-components';

import { spacing } from '../../spacing';
import { Button } from '../buttonv2/Buttonv2.component';
import { Icon, IconName } from '../icon/Icon.component';
import { LargeText } from '../text/Text.component';
import { CoreUITheme } from '../../style/theme';
type Props = {
import { useHistory } from 'react-router';

export type Props = {
listedResource: {
singular: string;
plural: string;
};
icon: IconName;
link?: string;
history?: Record<string, any>;
backgroundColor?: keyof CoreUITheme;
/**
* The resource to create before browsing the listed resource
Expand Down Expand Up @@ -46,14 +46,9 @@ export const ActionWrapper = styled.div`
`;

function EmptyState(props: Props) {
const {
icon,
listedResource,
link,
history,
resourceToCreate,
backgroundColor,
} = props;
const { icon, listedResource, link, resourceToCreate, backgroundColor } =
props;
const history = useHistory();
return (
<EmptystateContainer
className="sc-emptystate"
Expand All @@ -72,7 +67,7 @@ function EmptyState(props: Props) {
: `Before browsing your ${listedResource.plural}, create your first ${resourceToCreate}.`}
</LargeText>
</EmptyStateRow>
{history && (
{link && (
<ActionWrapper>
<Button
label={`Create ${resourceToCreate || listedResource.singular}`}
Expand Down
23 changes: 15 additions & 8 deletions stories/emptystate.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { EmptyState } from '../src/lib/components/emptystate/Emptystate.component';
import { Meta, StoryObj } from '@storybook/react';
import {
EmptyState,
Props,
} from '../src/lib/components/emptystate/Emptystate.component';
type Story = StoryObj<Props>;

export default {
const meta: Meta<Props> = {
title: 'Components/Data Display/EmptyState',
component: EmptyState,
args: {
icon: 'Node-backend',
label: 'Node',
listedResource: {
singular: 'resource',
plural: 'resources',
},
},
};

export const Default = {};
export default meta;

export const Default: Story = {};

export const WithLink = {
export const WithLink: Story = {
args: {
link: '',
history: {
push: () => {},
},
},
};

0 comments on commit 6ad28d4

Please sign in to comment.