-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathform-action-buttons.jsx
More file actions
55 lines (52 loc) · 1.87 KB
/
form-action-buttons.jsx
File metadata and controls
55 lines (52 loc) · 1.87 KB
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
50
51
52
53
54
55
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import PropTypes from 'prop-types'
import {FormattedMessage} from 'react-intl'
import {Button, Stack} from '@chakra-ui/react'
import {MESSAGE_PROPTYPE} from '../../utils/locale.js'
/**
* Renders a form submit button and a cancel button with configurable labels and callbacks
* in a responsive layout. Used primarily in forms that can be toggled opened/closed.
*/
const FormActionButtons = ({
saveButtonProps = {},
cancelButtonProps = {},
saveButtonLabel,
cancelButtonLabel,
onCancel = () => {}
}) => {
return (
<Stack direction={{base: 'column', lg: 'row-reverse'}} gap={4}>
<Button type="submit" minWidth={28} {...saveButtonProps}>
{saveButtonLabel ? (
<FormattedMessage {...saveButtonLabel} />
) : (
<FormattedMessage defaultMessage="Save" id="form_action_buttons.button.save" />
)}
</Button>
<Button variant="outline" minWidth={28} onClick={onCancel} {...cancelButtonProps}>
{cancelButtonLabel ? (
<FormattedMessage {...cancelButtonLabel} />
) : (
<FormattedMessage
id="form_action_buttons.button.cancel"
defaultMessage="Cancel"
/>
)}
</Button>
</Stack>
)
}
FormActionButtons.propTypes = {
saveButtonProps: PropTypes.object,
cancelButtonProps: PropTypes.object,
saveButtonLabel: MESSAGE_PROPTYPE,
cancelButtonLabel: MESSAGE_PROPTYPE,
onCancel: PropTypes.func
}
export default FormActionButtons