-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathform-save-buttons.js
34 lines (31 loc) · 1.61 KB
/
form-save-buttons.js
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
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
/**
* @module FormSaveButtons
* `FormSaveButtons` displays a button save and a cancel button at the bottom of a form.
* To show an overall inline error message, use the :error yielded block like shown below.
*
* @example
* <FormSaveButtons @saveButtonText="Save" @isSaving={{false}} @cancelLinkParams={{array "vault"}}>
* <:error>This is an error</:error>
* </FormSaveButtons>
*
* @param {string} [saveButtonText=Save] - The text that will be rendered on the Save button.
* @param {string} [cancelButtonText=Cancel] - The text that will be rendered on the Cancel button.
* @param {boolean} [isSaving=false] - If the form is saving, this should be true. This will disable the save button and render a spinner on it;
* @param {array} [cancelLinkParams] - An array of arguments used to construct a link to navigate back to when the Cancel button is clicked.
* @param {function} [onCancel=null] - If the form should call an action on cancel instead of route somewhere, the function can be passed using onCancel instead of passing an array to cancelLinkParams.
* @param {boolean} [includeBox=true] - By default we include padding around the form with underlines. Passing this value as false will remove that padding.
*
*/
export default class FormSaveButtons extends Component {
get cancelLink() {
const { cancelLinkParams } = this.args;
if (!Array.isArray(cancelLinkParams) || !cancelLinkParams.length) return null;
const [route, ...models] = cancelLinkParams;
return { route, models };
}
}