added ability to add mulitple actions (#163)

* added ability to add mulitple actions

* fixed format

* changed to use secondaryActions
This commit is contained in:
Erik Jan de Wit 2020-10-12 20:02:17 +02:00 committed by GitHub
parent 4fa325f45c
commit 09f09893a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 5 deletions

View file

@ -5,21 +5,31 @@ import {
EmptyStateBody, EmptyStateBody,
Title, Title,
Button, Button,
ButtonVariant,
EmptyStateSecondaryActions,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { PlusCircleIcon } from "@patternfly/react-icons"; import { PlusCircleIcon } from "@patternfly/react-icons";
export type Action = {
text: string;
type?: ButtonVariant;
onClick: MouseEventHandler<HTMLButtonElement>;
};
export type ListEmptyStateProps = { export type ListEmptyStateProps = {
message: string; message: string;
instructions: string; instructions: string;
primaryActionText: string; primaryActionText: string;
onPrimaryAction: MouseEventHandler<HTMLButtonElement>; onPrimaryAction: MouseEventHandler<HTMLButtonElement>;
secondaryActions: Action[];
}; };
export const ListEmptyState = ({ export const ListEmptyState = ({
message, message,
instructions, instructions,
primaryActionText,
onPrimaryAction, onPrimaryAction,
primaryActionText,
secondaryActions,
}: ListEmptyStateProps) => { }: ListEmptyStateProps) => {
return ( return (
<> <>
@ -32,6 +42,17 @@ export const ListEmptyState = ({
<Button variant="primary" onClick={onPrimaryAction}> <Button variant="primary" onClick={onPrimaryAction}>
{primaryActionText} {primaryActionText}
</Button> </Button>
<EmptyStateSecondaryActions>
{secondaryActions.map((action) => (
<Button
key={action.text}
variant={action.type || ButtonVariant.primary}
onClick={action.onClick}
>
{action.text}
</Button>
))}
</EmptyStateSecondaryActions>
</EmptyState> </EmptyState>
</> </>
); );

View file

@ -8,8 +8,9 @@ describe("<ListEmptyState />", () => {
<ListEmptyState <ListEmptyState
message="No things" message="No things"
instructions="You haven't created any things for this list." instructions="You haven't created any things for this list."
primaryActionText="Add a thing" primaryActionText="Add it now!"
onPrimaryAction={() => {}} onPrimaryAction={() => {}}
secondaryActions={[{ text: "Add a thing", onClick: () => {} }]}
/> />
); );
expect(comp.asFragment()).toMatchSnapshot(); expect(comp.asFragment()).toMatchSnapshot();

View file

@ -39,10 +39,24 @@ exports[`<ListEmptyState /> render 1`] = `
data-ouia-component-type="PF4/Button" data-ouia-component-type="PF4/Button"
data-ouia-safe="true" data-ouia-safe="true"
type="button" type="button"
>
Add it now!
</button>
<div
class="pf-c-empty-state__secondary"
>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary"
data-ouia-component-id="OUIA-Generated-Button-primary-2"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
> >
Add a thing Add a thing
</button> </button>
</div> </div>
</div> </div>
</div>
</DocumentFragment> </DocumentFragment>
`; `;

View file

@ -22,6 +22,6 @@ export const View = Template.bind({});
View.args = { View.args = {
message: "No things", message: "No things",
instructions: "You haven't created any things for this list.", instructions: "You haven't created any things for this list.",
primaryActionText: "Add a thing", primaryActionText: "Add it now!",
onPrimaryAction: handleClick, secondaryActions: [{ text: "Add a thing", onClick: handleClick }],
}; };