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>
253 lines
8.1 KiB
JavaScript
253 lines
8.1 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import cx from 'classnames';
|
|
const tinycolor = require('tinycolor2');
|
|
import * as Icons from '@tabler/icons-react';
|
|
import Loader from '@/ToolJetUI/Loader/Loader';
|
|
|
|
export const Button = function Button(props) {
|
|
const { height, properties, styles, fireEvent, id, dataCy, setExposedVariable, setExposedVariables } = props;
|
|
const {
|
|
backgroundColor,
|
|
textColor,
|
|
borderRadius,
|
|
loaderColor,
|
|
borderColor,
|
|
boxShadow,
|
|
iconColor,
|
|
direction,
|
|
type,
|
|
padding,
|
|
iconVisibility,
|
|
} = styles;
|
|
|
|
const { loadingState, disabledState } = properties;
|
|
const [label, setLabel] = useState(typeof properties.text === 'string' ? properties.text : '');
|
|
const [disable, setDisable] = useState(disabledState || loadingState);
|
|
const [visibility, setVisibility] = useState(properties.visibility);
|
|
const [loading, setLoading] = useState(loadingState);
|
|
const [hovered, setHovered] = useState(false);
|
|
const iconName = styles.icon; // Replace with the name of the icon you want
|
|
// eslint-disable-next-line import/namespace
|
|
const IconElement = Icons[iconName] == undefined ? Icons['IconHome2'] : Icons[iconName];
|
|
|
|
useEffect(() => {
|
|
if (typeof properties.text === 'string') {
|
|
setLabel(properties.text);
|
|
setExposedVariable('buttonText', properties.text);
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.text]);
|
|
|
|
useEffect(() => {
|
|
disable !== disabledState && setDisable(disabledState);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [disabledState]);
|
|
|
|
useEffect(() => {
|
|
visibility !== properties.visibility && setVisibility(properties.visibility);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.visibility]);
|
|
|
|
useEffect(() => {
|
|
loading !== properties.loadingState && setLoading(properties.loadingState);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [properties.loadingState]);
|
|
|
|
const computedIconColor =
|
|
'#FFFFFF' === iconColor ? (type === 'primary' ? iconColor : 'var(--icons-strong)') : iconColor;
|
|
|
|
const computedBorderColor =
|
|
borderColor === '#4368E3' ? (type === 'primary' ? '#4368E3' : 'var(--borders-strong)') : borderColor;
|
|
|
|
const computedTextColor =
|
|
'#FFFFFF' === textColor ? (type === 'primary' ? 'var(--text-on-solid)' : 'var(--text-primary)') : textColor;
|
|
const computedLoaderColor =
|
|
'#FFFFFF' === loaderColor ? (type === 'primary' ? loaderColor : 'var(--primary-brand)') : loaderColor;
|
|
|
|
const computedBgColor =
|
|
'#4368E3' === backgroundColor
|
|
? type === 'primary'
|
|
? 'var(--primary-brand)'
|
|
: 'transparent'
|
|
: type === 'primary'
|
|
? backgroundColor
|
|
: 'transparent';
|
|
|
|
const computedStyles = {
|
|
backgroundColor: computedBgColor,
|
|
color: computedTextColor,
|
|
width: '100%',
|
|
borderRadius: `${borderRadius}px`,
|
|
height: height == 36 ? (padding == 'default' ? '36px' : '40px') : padding == 'default' ? height : height + 4,
|
|
'--tblr-btn-color-darker': tinycolor(computedBgColor).darken(8).toString(),
|
|
'--tblr-btn-color-clicked': tinycolor(computedBgColor).darken(15).toString(),
|
|
'--loader-color': tinycolor(computedLoaderColor ?? 'var(--icons-on-solid)').toString(),
|
|
borderColor: computedBorderColor,
|
|
boxShadow: type == 'primary' && boxShadow,
|
|
padding: '0px 12px',
|
|
// cursor: 'pointer',
|
|
opacity: disable && '50%',
|
|
display: visibility ? (loading ? 'flex' : '') : 'none',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
};
|
|
|
|
useEffect(() => {
|
|
const exposedVariables = {
|
|
click: async function () {
|
|
if (!disable) {
|
|
fireEvent('onClick');
|
|
}
|
|
},
|
|
setText: async function (text) {
|
|
setLabel(text);
|
|
setExposedVariable('buttonText', text);
|
|
},
|
|
disable: async function (value) {
|
|
setDisable(value);
|
|
},
|
|
visibility: async function (value) {
|
|
setVisibility(value);
|
|
},
|
|
loading: async function (value) {
|
|
setLoading(value);
|
|
},
|
|
};
|
|
|
|
setExposedVariables(exposedVariables);
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [disable]);
|
|
|
|
useEffect(() => {
|
|
setExposedVariable('setLoading', async function (loading) {
|
|
setLoading(loading);
|
|
setExposedVariable('isLoading', loading);
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [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
|
|
}, [disabledState]);
|
|
|
|
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(() => {
|
|
if (hovered) {
|
|
fireEvent('onHover');
|
|
}
|
|
}, [hovered]);
|
|
|
|
const hasCustomBackground = computedBgColor?.charAt() === '#';
|
|
if (hasCustomBackground) {
|
|
computedStyles['--tblr-btn-color-darker'] = tinycolor(computedBgColor).darken(8).toString();
|
|
computedStyles['--tblr-btn-color-clicked'] = tinycolor(computedBgColor).darken(15).toString();
|
|
}
|
|
const handleClick = () => {
|
|
const event1 = new CustomEvent('submitForm', { detail: { buttonComponentId: id } });
|
|
document.dispatchEvent(event1);
|
|
fireEvent('onClick');
|
|
};
|
|
const renderButton = () => (
|
|
<div
|
|
className={`widget-button d-flex align-items-center`}
|
|
style={{
|
|
position: 'relative',
|
|
// height,
|
|
}}
|
|
disabled={disable || loading}
|
|
>
|
|
<button
|
|
className={cx('overflow-hidden', {
|
|
'btn-custom': hasCustomBackground,
|
|
'jet-button ': type == 'primary',
|
|
'jet-outline-button ': type == 'outline',
|
|
})}
|
|
style={computedStyles}
|
|
onClick={handleClick}
|
|
data-cy={dataCy}
|
|
type="default"
|
|
onMouseOver={() => {
|
|
//cannot use mouseEnter here since mouse enter does not trigger consistently. Mouseover gets triggered for all child components
|
|
setHovered(true);
|
|
}}
|
|
onMouseLeave={() => {
|
|
setHovered(false);
|
|
}}
|
|
>
|
|
{!loading ? (
|
|
<div
|
|
style={{
|
|
height: '100%',
|
|
width: '100%',
|
|
display: !loading ? 'flex' : 'none',
|
|
alignItems: 'center',
|
|
flexDirection: direction == 'left' ? 'row-reverse' : 'row',
|
|
justifyContent: 'center',
|
|
gap: label?.length > 0 && '6px',
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
<span style={{ maxWidth: ' 100%', minWidth: '0' }}>
|
|
<p
|
|
className="tj-text-sm"
|
|
style={{ fontWeight: '500', margin: '0px', padding: '0px', color: computedTextColor }}
|
|
>
|
|
{label}
|
|
</p>
|
|
</span>
|
|
</div>
|
|
{iconVisibility && (
|
|
<div className="d-flex">
|
|
{!props.isResizing && !loading && (
|
|
<IconElement
|
|
style={{
|
|
width: '16px',
|
|
height: '16px',
|
|
color: computedIconColor,
|
|
}}
|
|
stroke={1.5}
|
|
/>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<Loader color={computedLoaderColor} width="16" />
|
|
)}
|
|
</button>
|
|
</div>
|
|
);
|
|
|
|
return <>{renderButton()}</>;
|
|
};
|