mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
27 lines
668 B
JavaScript
27 lines
668 B
JavaScript
import React, { useState } from 'react';
|
|
|
|
export const Toggle = ({ readOnly, value, onChange, activeColor }) => {
|
|
const [on, setOn] = useState(() => value);
|
|
|
|
const toggle = () => {
|
|
setOn((prev) => !prev);
|
|
onChange(!on);
|
|
};
|
|
|
|
return (
|
|
<div className="radio row g-0">
|
|
<label className="form-check form-switch form-check-inline">
|
|
<input
|
|
className="form-check-input"
|
|
type="checkbox"
|
|
checked={on}
|
|
style={on ? { backgroundColor: activeColor } : {}}
|
|
onClick={() => {
|
|
if (!readOnly) toggle();
|
|
}}
|
|
disabled={readOnly}
|
|
/>
|
|
</label>
|
|
</div>
|
|
);
|
|
};
|