mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
* Better canvas * Better canvas * Better canvas * Fix for resize * Fix for drag * Fix for drag * Fix for drag * Adjust width of components by # of grid lines * Adjust components to comply with gridline based width * Fix the width of rigth sidebar * Fix for subcontainer resize issue * Fix for dropped widget width (sc) * Fix subcontainer drag width * Fix grid for sub container * Fix viewer * Fix * Fix * Use RnD for dragging within canvas * bounds for subcontainers * fix for subcontainers * Fix for mouseover issue * Fix * Fix widget widths * Fixes chart * Fixes qr scanner and divider * Remove scaleValue * Mmerge fix * Mmerge fix * Fix for ormconfig * Fixes for comments * Add comment where the user clicked * Disable dragging on viewer * Max width for canvas * Fix for widget click events * Fix for radio button * Rebase widget width and left offset for responsive canvas * Fix * Fix the width of file picker * Fix for calendar widget * Disable zoom selector * Fixes comment positions * css fixes * Fix * Recompute width and offset of subcontainer widgets based on its parent's width * Calculate container width separately for modal children while migrating to responsive * Refactor migration to responsive canvas whereinwhich all mutations are done only after all required changes are computed Co-authored-by: Sherfin Shamsudeen <sherfin94@gmail.com>
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
import React from 'react';
|
|
import { resolveReferences, resolveWidgetFieldValue } from '@/_helpers/utils';
|
|
|
|
export const Checkbox = function Checkbox({
|
|
id,
|
|
height,
|
|
component,
|
|
onComponentClick,
|
|
currentState,
|
|
onComponentOptionChanged,
|
|
onEvent,
|
|
}) {
|
|
const [checked, setChecked] = React.useState(false);
|
|
const label = component.definition.properties.label.value;
|
|
const textColorProperty = component.definition.styles.textColor;
|
|
const textColor = textColorProperty ? textColorProperty.value : '#000';
|
|
const checkboxColorProperty = component.definition.styles.checkboxColor;
|
|
const checkboxColor = checkboxColorProperty ? checkboxColorProperty.value : '#3c92dc';
|
|
const widgetVisibility = component.definition.styles?.visibility?.value ?? true;
|
|
const disabledState = component.definition.styles?.disabledState?.value ?? false;
|
|
|
|
const parsedDisabledState =
|
|
typeof disabledState !== 'boolean' ? resolveWidgetFieldValue(disabledState, currentState) : disabledState;
|
|
|
|
let parsedWidgetVisibility = widgetVisibility;
|
|
|
|
try {
|
|
parsedWidgetVisibility = resolveReferences(parsedWidgetVisibility, currentState, []);
|
|
} catch (err) {
|
|
console.log(err);
|
|
}
|
|
|
|
function toggleValue(e) {
|
|
const isChecked = e.target.checked;
|
|
setChecked(isChecked);
|
|
onComponentOptionChanged(component, 'value', isChecked);
|
|
if (isChecked) {
|
|
onEvent('onCheck', { component });
|
|
} else {
|
|
onEvent('onUnCheck', { component });
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div
|
|
data-disabled={parsedDisabledState}
|
|
className="row py-1"
|
|
style={{ height, display: parsedWidgetVisibility ? '' : 'none' }}
|
|
onClick={(event) => {
|
|
event.stopPropagation();
|
|
onComponentClick(id, component, event);
|
|
}}
|
|
>
|
|
<div className="col px-1 py-0 mt-0">
|
|
<label className="mx-1 form-check form-check-inline">
|
|
<input
|
|
className="form-check-input"
|
|
type="checkbox"
|
|
onClick={(e) => {
|
|
toggleValue(e);
|
|
}}
|
|
style={{ backgroundColor: checked ? `${checkboxColor}` : 'white', marginTop: '1px' }}
|
|
/>
|
|
<span className="form-check-label" style={{ color: textColor }}>
|
|
{label}
|
|
</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|