Files
redash/client/app/components/visualizations/editor/Switch.jsx
Arik Fraimovich 56d3be2248 Prettier all the Javascript code & GitHub Action (#4433)
* Prettier all the JS files

* Add GitHub Action to autoformat code pushed to master

* Fix eslint violation due to formatting.

* Remove GitHub actions for styling

* Add restyled.io config
2019-12-11 17:05:38 +02:00

41 lines
929 B
JavaScript

import React, { useMemo } from "react";
import PropTypes from "prop-types";
import AntSwitch from "antd/lib/switch";
import Typography from "antd/lib/typography";
export default function Switch({ id, children, disabled, ...props }) {
const fallbackId = useMemo(
() =>
`visualization-editor-control-${Math.random()
.toString(36)
.substr(2, 10)}`,
[]
);
id = id || fallbackId;
if (children) {
return (
<label htmlFor={id} className="d-flex align-items-center">
<AntSwitch id={id} disabled={disabled} {...props} />
<Typography.Text className="m-l-10" disabled={disabled}>
{children}
</Typography.Text>
</label>
);
}
return <AntSwitch {...props} />;
}
Switch.propTypes = {
id: PropTypes.string,
disabled: PropTypes.bool,
children: PropTypes.node,
};
Switch.defaultProps = {
id: null,
disabled: false,
children: null,
};