1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-26 00:21:36 +01:00

Add Switch component

This commit is contained in:
Aleksandr Gumroian 2020-08-18 10:13:57 +02:00
parent e422acc92f
commit c1b1d8c079
No known key found for this signature in database
GPG Key ID: 9E77849C64F0A733
2 changed files with 63 additions and 13 deletions

45
src/bootstrap/Switch.js Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2020 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.
*/
import React from "react";
import PropTypes from "prop-types";
import { useUID } from "react-uid";
Switch.propTypes = {
label: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]).isRequired,
id: PropTypes.string.isRequired,
helpText: PropTypes.string,
switchHeading: PropTypes.string,
};
export function Switch({
label, id, helpText, switchHeading, ...props
}) {
const uid = useUID();
return (
<div className="form-group">
<div className={`custom-control custom-switch ${!helpText ? "custom-control-inline" : ""} ${switchHeading ? "switch-heading" : ""}`.trim()}>
<input
type="checkbox"
className="custom-control-input"
id={uid}
{...props}
/>
<label className="custom-control-label" htmlFor={uid}>
{label}
</label>
{helpText && <small className="form-text text-muted mt-0 mb-3">{helpText}</small>}
</div>
</div>
);
}

View File

@ -31,17 +31,10 @@ export { Radio, RadioSet } from "./bootstrap/RadioSet";
export { Select } from "./bootstrap/Select";
export { TextInput } from "./bootstrap/TextInput";
export { formFieldsSize, buttonFormFieldSize } from "./bootstrap/constants";
export { Switch } from "./bootstrap/Switch";
export {
Spinner,
SpinnerElement,
} from "./bootstrap/Spinner";
export {
Modal,
ModalBody,
ModalFooter,
ModalHeader,
} from "./bootstrap/Modal";
export { Spinner, SpinnerElement } from "./bootstrap/Spinner";
export { Modal, ModalBody, ModalFooter, ModalHeader } from "./bootstrap/Modal";
// Common
export { RebootButton } from "./common/RebootButton";
@ -49,7 +42,10 @@ export { WiFiSettings } from "./common/WiFiSettings/WiFiSettings";
// Form
export { ForisForm } from "./form/components/ForisForm";
export { SubmitButton, STATES as SUBMIT_BUTTON_STATES } from "./form/components/SubmitButton";
export {
SubmitButton,
STATES as SUBMIT_BUTTON_STATES,
} from "./form/components/SubmitButton";
export { useForisModule, useForm } from "./form/hooks";
// WebSockets
@ -58,9 +54,18 @@ export { WebSockets } from "./webSockets/WebSockets";
// Utils
export { Portal } from "./utils/Portal";
export { undefinedIfEmpty, withoutUndefinedKeys, onlySpecifiedKeys } from "./utils/objectHelpers";
export {
withEither, withSpinner, withSending, withSpinnerOnSending, withError, withErrorMessage,
undefinedIfEmpty,
withoutUndefinedKeys,
onlySpecifiedKeys,
} from "./utils/objectHelpers";
export {
withEither,
withSpinner,
withSending,
withSpinnerOnSending,
withError,
withErrorMessage,
} from "./utils/conditionalHOCs";
export { ErrorMessage } from "./utils/ErrorMessage";
export { useClickOutside } from "./utils/hooks";