1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-07-05 20:53:12 +00:00
foris-js/src/bootstrap/Button.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-08-23 13:20:22 +00:00
/*
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
*/
2019-08-27 14:09:18 +00:00
import React from "react";
import PropTypes from "prop-types";
2019-08-23 13:20:22 +00:00
Button.propTypes = {
/** Additional class name. */
className: PropTypes.string,
/** Use foris form size and offset. */
forisFormSize: PropTypes.bool,
/** Show loading icon. */
loading: PropTypes.bool,
/** Button content. */
children: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
2019-08-27 14:09:18 +00:00
]).isRequired,
2019-08-23 13:20:22 +00:00
};
2019-08-27 15:46:45 +00:00
export function Button({
2020-08-18 13:39:00 +00:00
className,
loading,
forisFormSize,
children,
...props
2019-08-27 14:09:18 +00:00
}) {
2020-01-07 12:27:49 +00:00
let buttonClass = className ? `btn ${className}` : "btn btn-primary ";
if (forisFormSize) {
buttonClass = `${buttonClass} col-sm-12 col-md-3 col-lg-2`;
2020-01-07 12:27:49 +00:00
}
2019-08-23 13:20:22 +00:00
2020-08-18 13:39:00 +00:00
const span = loading ? (
<span
className="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"
/>
) : null;
2019-08-23 13:20:22 +00:00
2019-08-27 14:09:18 +00:00
return (
2020-01-07 12:27:49 +00:00
<button type="button" className={buttonClass} {...props}>
2019-08-27 14:09:18 +00:00
{span}
{span ? " " : null}
{children}
</button>
);
2019-08-23 13:20:22 +00:00
}