docbrown/app/javascript/article-form/components/EditorActions.jsx
ludwiczakpawel ea28093bbb
Implementing new buttons (#15843)
* buttons

* view archive link block

* revert font weight change

* save draft title

* revert

* fix

* specs

* specs

* spec

* spec

* for fcks  sake

* Change spec for unarchive/archive button from .find to .findByRole

* fix help icon

* improve a11y on close.jsx

* bring back the focus

* .

* Update cypress/integration/seededFlows/publishingFlows/uploadImage.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* drop icons.jsx

Co-authored-by: Nick Taylor <nick@dev.to>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2022-01-14 10:28:31 +01:00

85 lines
2.1 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
import { Options } from './Options';
import { ButtonNew as Button } from '@crayons';
export const EditorActions = ({
onSaveDraft,
onPublish,
onClearChanges,
published,
edited,
version,
passedData,
onConfigChange,
submitting,
}) => {
const isVersion1 = version === 'v1';
const isVersion2 = version === 'v2';
if (submitting) {
return (
<div className="crayons-article-form__footer">
<Button
variant="primary"
className="mr-2 whitespace-nowrap"
onClick={onPublish}
disabled
>
{published && isVersion2
? 'Publishing...'
: `Saving ${isVersion2 ? 'draft' : ''}...`}
</Button>
</div>
);
}
return (
<div className="crayons-article-form__footer">
<Button
variant="primary"
className="mr-2 whitespace-nowrap"
onClick={onPublish}
>
{published || isVersion1 ? 'Save changes' : 'Publish'}
</Button>
{!(published || isVersion1) && (
<Button className="mr-2 whitespace-nowrap" onClick={onSaveDraft}>
Save <span className="hidden s:inline">draft</span>
</Button>
)}
{isVersion2 && (
<Options
passedData={passedData}
onConfigChange={onConfigChange}
onSaveDraft={onSaveDraft}
/>
)}
{edited && (
<Button
onClick={onClearChanges}
className="whitespace-nowrap fw-normal fs-s"
>
Revert <span className="hidden s:inline">new changes</span>
</Button>
)}
</div>
);
};
EditorActions.propTypes = {
onSaveDraft: PropTypes.func.isRequired,
onPublish: PropTypes.func.isRequired,
published: PropTypes.bool.isRequired,
edited: PropTypes.bool.isRequired,
version: PropTypes.string.isRequired,
onClearChanges: PropTypes.func.isRequired,
passedData: PropTypes.object.isRequired,
onConfigChange: PropTypes.func.isRequired,
submitting: PropTypes.bool.isRequired,
};
EditorActions.displayName = 'EditorActions';