added ability to add mulitple actions (#163)
* added ability to add mulitple actions * fixed format * changed to use secondaryActions
This commit is contained in:
parent
4fa325f45c
commit
09f09893a2
4 changed files with 41 additions and 5 deletions
|
@ -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>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -40,8 +40,22 @@ exports[`<ListEmptyState /> render 1`] = `
|
||||||
data-ouia-safe="true"
|
data-ouia-safe="true"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
Add a thing
|
Add it now!
|
||||||
</button>
|
</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
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DocumentFragment>
|
</DocumentFragment>
|
||||||
|
|
|
@ -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 }],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue