mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
* Remove date-fns depedency from table datepicker * Revert Remove date-fns depedency from table datepicker * Fix Built with Tooljet" watermark and app mode switcher appear briefly before the correct login page loads. (#9545) * fix: headers and action button UI on table (#9626) * fix: delete all children and nested children on component delete (#9182) * fix: delete all children and nested children on component delete * refactor: removed duplicate logics * refactor: reuse functions and remove duplicate functions * fix: update parentid of kanban modal child on version creation * fix: add kanban modal children to delete list * Fix duplicate text appearing at the bottom from the previous page in PDF widget (#9567) * chore: fixed vulnerability issues on FE (#9561) Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> * chore: Removed unused packages in FE (#9161) * Removed unused packages * Remove date-fns dependency drom table date picker (#9585) --------- Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> Co-authored-by: Nakul Nagargade <133095394+nakulnagargade@users.noreply.github.com> * Fix Pagination and order of rows malfunction if default selected Id is not on page 1 (#9651) * Fix Pagination and order of rows malfunction if default selected Id is not on page 1 * remove console logs * Add support to add Manual date entry in Datepicker table column (#9631) * Removed unused packages * Add Manual date entry in Datepicker table column * Remove date-fns dependency drom table date picker (#9585) * fix date input issue * Remove consoles --------- Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com> Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> * Feature: pages sidebar collapsable and pin functionality in preview/release mode (#9650) * add: pin and collapsable functionality to pages sidebar * fix: review changes * fix: canvas auto update width on sidebar toggle * fix icon size * Add support to wrap table's column header (#9565) * Add support to wrap table's column header * Resolve code comments * commit * fix: resize page width on window resize (#9164) * feat: Button component revamp (#8361) * init textinput revamp * updated styles panel * bugfix * updates * fix :: accordion * fix :: styling * add box shadow , additional property,tooltip * fix conditional render for styles * feat :: fixed order of each property and styles * feat :: styling input * bugfix * feat :: add option to add icon * add option to add icon * adding option to toggle visibility * updated password input with new design * chnaging component location * bugfix * style fixes * fix :: added loader * updated :: few detailing * few bugfixes * fix :: for form widget label * fixes * added option to add icon color * including label field for password input * fix for label * fix * test fix backward compatibility for height * updates * revert * adding key for distinguishing older and newer widgets * testing * test * test * update * update * migration testing * limit vertical resizing in textinput * testing * throw test * test * adding check for label length * fixing edge cases * removing resize * backward compatibility height * backward compatibility * number input review fixes * added exposed items * fixing csa * ui fixes * fix height compatibility * feat :: csa for all inputs and exposed variables * backward compatibility fixes and validation fixes * fixes :: textinput positioning of loader and icon * fix :: password input * cleanup and fixes * fixes * cleanup * fixes * review fixes * review fixes * button component revamped * fix :: csa * typo fix * typo * fix :: styling * exposed variables * fix padding * review fixes styles component panel * fix naming * fix padding * default size * fix :: icons position * updates * cleanup * updates events , csa * cleanup * remove border * backward compatibility * clean * feat :: change validation from properties * ui fixes * icon name * disabled state * removed 'px' text from tooltip * fixes placeholder * few updates :: removing label in form * ui in form * update :: number input validation behaviour * testing fixes * added side handlers * removing unwanted fx * disabling fx for padding field * ordering change * fix * label issue + restricted side handler * fix :: box shadow bug * on change event doesnt propagate exposed vars correctly * adding debounce for slider value change * fix :: for modal ooen bug during onfocus event * test slider * fix :: bugs regarding state update in checbox , slider , slider bug * update slider with radix slider * bugfix * merge fixes * fix * updates * removing unwanted migrations * fix: box shadow * fix : import export issues * fix : colouring * cleanup * fixes * fix : design review comments * add border color * fix : review changes * fix * change display name to solid * fix label * fix : loader issue * fix : button icon position * fix : qa bugs * feat: Checkbox + Toggle revamp (#8519) * init textinput revamp * updated styles panel * bugfix * updates * fix :: accordion * fix :: styling * add box shadow , additional property,tooltip * fix conditional render for styles * feat :: fixed order of each property and styles * feat :: styling input * bugfix * feat :: add option to add icon * add option to add icon * adding option to toggle visibility * updated password input with new design * chnaging component location * bugfix * style fixes * fix :: added loader * updated :: few detailing * few bugfixes * fix :: for form widget label * fixes * added option to add icon color * including label field for password input * fix for label * fix * test fix backward compatibility for height * updates * revert * adding key for distinguishing older and newer widgets * testing * test * test * update * update * migration testing * limit vertical resizing in textinput * testing * throw test * test * adding check for label length * fixing edge cases * removing resize * backward compatibility height * backward compatibility * number input review fixes * added exposed items * fixing csa * ui fixes * fix height compatibility * feat :: csa for all inputs and exposed variables * backward compatibility fixes and validation fixes * fixes :: textinput positioning of loader and icon * fix :: password input * cleanup and fixes * fixes * cleanup * fixes * review fixes * review fixes * typo fix * fix padding * review fixes styles component panel * fix naming * fix padding * feat :: toggle switch revamp * init checkbox * fixes * fixes * switch fixes * validation fix * fixes * cleanup * height fix * fix height toggle * updates * fix :: icons position * updates * cleanup * updates events , csa * cleanup * backward compatibility * clean * backward compatibility fix * label fixed to one line * feat :: change validation from properties * ui fixes * icon name * removed 'px' text from tooltip * added onchange event for checkbox * fixes placeholder * few updates :: removing label in form * ui in form * fire onchange * update :: number input validation behaviour * testing fixes * added side handlers * removing unwanted fx * disabling fx for padding field * ordering change * fix * label issue + restricted side handler * fix :: box shadow bug * fix * on change event doesnt propagate exposed vars correctly * adding debounce for slider value change * fix :: for modal ooen bug during onfocus event * test slider * fix :: bugs regarding state update in checbox , slider , slider bug * update slider with radix slider * bugfix * update tooltip * fix toggle switch * fixes : inspector * fix : checkbox label * feat : checkbox completed * update checkbox review changes * feat : toggle component * feat : added new toggle component * fix : colors * updated review changes * update name for old and new version * update * case change * update * update icon * removed padding from checkbox and toggle * fix naming * product review and bugfixes : changes * fix : checkbox setvalue action * Update setvalue action in toggle * fixed: section for legacy and new components * fix : checkbox tick mark not showing on resizing * fix : icon in inspector * fix : box shadow * fix : ismandatory definition * configs update --------- Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> * fix : toggle switch import and switch component issues (#9874) * fix : filter order of toggle (#9879) * fix: appbuilder 1.7 integration testing bug fixes (#9880) * fix: add only ids in deleted components map for component delete functionality * Fix TableRowHeightInput in codehinter (#9881) * fix: disable drag on calender popup and unblock other input interactions * Bugfixes componentes 1.7 (#9892) * fix : filter order of toggle (#9879) * fix : Button alignment when label is empty * fix : box shadow added * fix : direction and default box shadow * fix : disable csa not working for checkbox * fix : button padding * added toggle for box shadow check * fixes : integration 1.7 (#9901) * fix : exposed vars not getting exposed on page change * fix : validation error font * fix : dynamic color for button * fix : loading placement during CSA * Move disabled, visibility, tooltip and box shadow to properties in Checkbox and Button (#9665) * init textinput revamp * updated styles panel * bugfix * updates * fix :: accordion * fix :: styling * add box shadow , additional property,tooltip * fix conditional render for styles * feat :: fixed order of each property and styles * feat :: styling input * bugfix * feat :: add option to add icon * add option to add icon * adding option to toggle visibility * updated password input with new design * chnaging component location * bugfix * style fixes * fix :: added loader * updated :: few detailing * few bugfixes * fix :: for form widget label * fixes * added option to add icon color * including label field for password input * fix for label * fix * test fix backward compatibility for height * updates * revert * adding key for distinguishing older and newer widgets * testing * test * test * update * update * migration testing * limit vertical resizing in textinput * testing * throw test * test * adding check for label length * fixing edge cases * removing resize * backward compatibility height * backward compatibility * number input review fixes * added exposed items * fixing csa * ui fixes * fix height compatibility * feat :: csa for all inputs and exposed variables * backward compatibility fixes and validation fixes * fixes :: textinput positioning of loader and icon * fix :: password input * cleanup and fixes * fixes * cleanup * fixes * review fixes * review fixes * typo fix * fix padding * review fixes styles component panel * fix naming * fix padding * feat :: toggle switch revamp * init checkbox * fixes * fixes * switch fixes * validation fix * fixes * cleanup * height fix * fix height toggle * updates * fix :: icons position * updates * cleanup * updates events , csa * cleanup * backward compatibility * clean * backward compatibility fix * label fixed to one line * feat :: change validation from properties * ui fixes * icon name * removed 'px' text from tooltip * added onchange event for checkbox * fixes placeholder * few updates :: removing label in form * ui in form * fire onchange * update :: number input validation behaviour * testing fixes * added side handlers * removing unwanted fx * disabling fx for padding field * ordering change * fix * label issue + restricted side handler * fix :: box shadow bug * fix * on change event doesnt propagate exposed vars correctly * adding debounce for slider value change * fix :: for modal ooen bug during onfocus event * test slider * fix :: bugs regarding state update in checbox , slider , slider bug * update slider with radix slider * bugfix * update tooltip * fix toggle switch * fixes : inspector * fix : checkbox label * Move disabled, visibility, tooltip and box shadow to properties * Remove toggleswitch and button * Add down rollbackUpdates * fix : filter order of toggle (#9879) * fix merge issue * fix --------- Co-authored-by: stepinfwd <stepinfwd@gmail.com> * fix: use onMouseOver and onMouseLeave together to fix hover event * fix : Validation message to be shown only when use toggles on and off , code refactor (#9905) * Fix naming logic for copying (#9909) --------- Co-authored-by: Nakul Nagargade <133095394+nakulnagargade@users.noreply.github.com> Co-authored-by: Kiran Ashok <stepinfwd@gmail.com> * fix: update animateTransform for cross browser compatibility (#9917) * fix: color transitions on sidebar pages in dark mode (#9920) * Fix table all column editable (#9921) * fix: add only ids in deleted components map for component delete functionality * Fix TableRowHeightInput in codehinter (#9881) * fix: disable drag on calender popup and unblock other input interactions * Fix allColumns editable in Table * Fix clientServer nor working in Table * In widget config, update the total records as 10 --------- Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> * chore: bump minor version --------- Co-authored-by: Nakul Nagargade <nakul@tooljet.com> Co-authored-by: Nakul Nagargade <133095394+nakulnagargade@users.noreply.github.com> Co-authored-by: vjaris42 <vjy239@gmail.com> Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com> Co-authored-by: Kiran Ashok <stepinfwd@gmail.com>
295 lines
8.7 KiB
JavaScript
295 lines
8.7 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { resolveWidgetFieldValue } from '@/_helpers/utils';
|
|
import Loader from '@/ToolJetUI/Loader/Loader';
|
|
import OverflowTooltip from '@/_components/OverflowTooltip';
|
|
|
|
export const Checkbox = ({
|
|
height,
|
|
properties,
|
|
styles,
|
|
fireEvent,
|
|
setExposedVariable,
|
|
setExposedVariables,
|
|
dataCy,
|
|
component,
|
|
validate,
|
|
width,
|
|
}) => {
|
|
const defaultValueFromProperties = properties.defaultValue ?? false;
|
|
const [defaultValue, setDefaultValue] = useState(defaultValueFromProperties);
|
|
const [checked, setChecked] = useState(defaultValueFromProperties);
|
|
const [value, setValue] = React.useState(defaultValueFromProperties);
|
|
const [userInteracted, setUserInteracted] = useState(false);
|
|
|
|
const { label } = properties;
|
|
const textColor = styles.textColor === '#1B1F24' ? 'var(--text-primary)' : styles.textColor;
|
|
const { loadingState, disabledState } = properties;
|
|
const { checkboxColor, boxShadow, alignment, uncheckedColor, borderColor, handleColor } = styles;
|
|
|
|
const [loading, setLoading] = useState(properties?.loadingState);
|
|
const [disable, setDisable] = useState(disabledState || loadingState);
|
|
const [visibility, setVisibility] = useState(properties.visibility);
|
|
const { isValid, validationError } = validate(checked);
|
|
|
|
const isMandatory = resolveWidgetFieldValue(component?.definition?.validation?.mandatory?.value);
|
|
|
|
const toggleValue = (e) => {
|
|
const isChecked = e.target.checked;
|
|
setChecked(isChecked);
|
|
setValue(isChecked);
|
|
|
|
setExposedVariable('value', isChecked);
|
|
if (isChecked) {
|
|
fireEvent('onCheck');
|
|
} else {
|
|
fireEvent('onUnCheck');
|
|
}
|
|
setUserInteracted(true);
|
|
};
|
|
|
|
useEffect(() => {
|
|
const setCheckedAndNotify = async (status) => {
|
|
await setExposedVariable('value', status);
|
|
if (status) {
|
|
fireEvent('onCheck');
|
|
} else {
|
|
fireEvent('onUnCheck');
|
|
}
|
|
setChecked(status);
|
|
setValue(status);
|
|
};
|
|
|
|
const exposedVariables = {
|
|
value: defaultValueFromProperties,
|
|
setChecked: setCheckedAndNotify,
|
|
setValue: setCheckedAndNotify,
|
|
};
|
|
|
|
setDefaultValue(defaultValueFromProperties);
|
|
setChecked(defaultValueFromProperties);
|
|
setValue(defaultValueFromProperties);
|
|
setExposedVariables(exposedVariables);
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [defaultValueFromProperties]);
|
|
|
|
useEffect(() => {
|
|
if (disable !== disabledState) setDisable(properties.disabledState);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.disabledState]);
|
|
|
|
useEffect(() => {
|
|
if (visibility !== properties.visibility) setVisibility(properties.visibility);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.visibility]);
|
|
|
|
useEffect(() => {
|
|
if (loading !== loadingState) setLoading(loadingState);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [loadingState]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('label', label);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [label]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('isMandatory', isMandatory);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [isMandatory]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('isLoading', loading);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [loading]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('isVisible', visibility);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [visibility]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('isDisabled', disable);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [disable]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('isValid', isValid);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [isValid]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('setLoading', async function (loading) {
|
|
setLoading(loading);
|
|
setExposedVariable('isLoading', loading);
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.loadingState]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('setVisibility', async function (state) {
|
|
setVisibility(state);
|
|
setExposedVariable('isVisible', state);
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.visibility]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('setDisable', async function (disable) {
|
|
setDisable(disable);
|
|
setExposedVariable('isDisabled', disable);
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [disable]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('toggle', async function () {
|
|
setExposedVariable('value', !checked);
|
|
fireEvent('onChange');
|
|
setChecked(!checked);
|
|
setValue(!checked);
|
|
setUserInteracted(true);
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [checked, value]);
|
|
|
|
const handleToggleChange = () => {
|
|
const newCheckedState = !checked;
|
|
setChecked(newCheckedState);
|
|
setValue(newCheckedState);
|
|
setExposedVariable('value', newCheckedState).then(() => {
|
|
fireEvent('onChange');
|
|
if (newCheckedState) {
|
|
fireEvent('onCheck');
|
|
} else {
|
|
fireEvent('onUnCheck');
|
|
}
|
|
});
|
|
setUserInteracted(true);
|
|
};
|
|
|
|
const renderCheckBox = () => (
|
|
<>
|
|
<div
|
|
data-disabled={disable}
|
|
className={`${alignment === 'left' ? 'flex-row-reverse' : 'flex-row'}`}
|
|
style={{
|
|
display: visibility ? 'flex' : 'none',
|
|
boxShadow,
|
|
alignItems: loading && 'center',
|
|
gap: '6px',
|
|
justifyContent: `${loading ? 'center' : alignment === 'left' ? 'space-between' : 'start'}`,
|
|
height,
|
|
whiteSpace: 'nowrap',
|
|
}}
|
|
data-cy={dataCy}
|
|
>
|
|
{loading ? (
|
|
<Loader width="16" />
|
|
) : (
|
|
<>
|
|
<div
|
|
onClick={handleToggleChange}
|
|
style={{
|
|
...checkboxStyle,
|
|
}}
|
|
>
|
|
<input
|
|
style={{ display: 'none' }}
|
|
className="form-check-input"
|
|
type="checkbox"
|
|
onClick={toggleValue}
|
|
defaultChecked={defaultValue}
|
|
checked={checked}
|
|
/>
|
|
<div style={checkmarkStyle}>
|
|
{checked && (
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
className="icon-tabler icon-tabler-check"
|
|
width={14}
|
|
height={14}
|
|
viewBox="0 0 24 24"
|
|
strokeWidth={2}
|
|
stroke={handleColor}
|
|
fill="none"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
>
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
<path d="M5 12l5 5l10 -10" />
|
|
</svg>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<OverflowTooltip
|
|
className="form-check-label"
|
|
style={{
|
|
lineHeight: '20px',
|
|
color: textColor,
|
|
fontWeight: 400,
|
|
fontSize: '14px',
|
|
}}
|
|
whiteSpace="normal"
|
|
width={width - 20}
|
|
>
|
|
{label}
|
|
{isMandatory && !checked && <span style={{ color: '#DB4324', marginLeft: '1px' }}>{'*'}</span>}
|
|
</OverflowTooltip>
|
|
</>
|
|
)}
|
|
</div>
|
|
{validationError && visibility && !checked && userInteracted && (
|
|
<div
|
|
data-cy={`${String(component.name).toLowerCase()}-invalid-feedback`}
|
|
style={{
|
|
color: 'var(--status-error-strong)',
|
|
fontSize: '11px',
|
|
fontWeight: '400',
|
|
lineHeight: '16px',
|
|
}}
|
|
>
|
|
{validationError}
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
const checkmarkStyle = {
|
|
position: 'absolute',
|
|
top: '1px',
|
|
right: '1px',
|
|
visibility: checked ? 'visible' : 'hidden',
|
|
height: '14px',
|
|
width: '14px',
|
|
display: 'flex',
|
|
};
|
|
|
|
const checkboxStyle = {
|
|
display: 'inline-block',
|
|
cursor: 'pointer',
|
|
padding: '2px',
|
|
border: `1px solid ${borderColor}`,
|
|
backgroundColor: checked ? checkboxColor : uncheckedColor,
|
|
borderRadius: '5px',
|
|
height: '18px',
|
|
width: '18px',
|
|
minHeight: '18px',
|
|
minWidth: '18px',
|
|
position: 'relative',
|
|
borderColor: borderColor === '#CCD1D5' ? (checked ? 'transparent' : 'var(--borders-default)') : borderColor,
|
|
};
|
|
|
|
return (
|
|
<div
|
|
className="checkbox-component"
|
|
style={{
|
|
justifyContent: `${loadingState ? 'center' : 'flex-start'}`,
|
|
paddingTop: '3px',
|
|
}}
|
|
>
|
|
{renderCheckBox()}
|
|
</div>
|
|
);
|
|
};
|