-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
49 lines (47 loc) · 1.37 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useCallback } from "react"
import type { ActionProps } from "~getComponent/types"
import { publish } from "~services/pubsub"
import concatenateCssClasses from "~utilities/concatenateCssClasses"
import generateShortId from "~utilities/generateShortId"
import snakeCaseToSentenceCase from "~utilities/snakeCaseToSentenceCase"
import makeDataAttributes from "../utilities/makeDataAttributes"
import css from "./index.module.css"
export default function Action({
actionType = "SUBMIT_ACTION",
dataset = {},
id = generateShortId(),
isReadOnly,
label,
machineConfig,
mutationId,
buttonVariant = "DEFAULT",
...props
}: ActionProps): JSX.Element {
const handleClick = useCallback(() =>
publish({
eventName: actionType,
data: {
id,
},
}, { topic: mutationId }), [])
return (
<button
className={concatenateCssClasses({
[css.button]: true,
[css.outline]: buttonVariant === "OUTLINE",
[css.link]: buttonVariant === "LINK",
[css.primary]: ["TRIGGER_ACTION", "SUBMIT_ACTION"].includes(actionType),
[css.secondary]: actionType === "SUBMIT_ACTION" || actionType === "REDIRECT_ACTION",
[css.danger]: ["DELETE_ACTION"].includes(actionType),
})}
{...makeDataAttributes(dataset)}
disabled={isReadOnly}
form={mutationId}
id={id}
onClick={handleClick}
type="button"
>
{label || snakeCaseToSentenceCase(actionType)}
</button>
)
}