ToolJet/frontend/src/AppBuilder/Widgets/RadioButton.jsx

101 lines
2.8 KiB
React
Raw Normal View History

import React, { useEffect, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';
export const RadioButton = function RadioButton({
id,
height,
properties,
styles,
fireEvent,
setExposedVariable,
setExposedVariables,
darkMode,
dataCy,
}) {
const { label, value, values, display_values } = properties;
const { visibility, disabledState, activeColor, boxShadow } = styles;
const textColor = darkMode && styles.textColor === '#000' ? '#fff' : styles.textColor;
const [checkedValue, setValue] = useState(() => value);
useEffect(() => setValue(value), [value]);
let selectOptions = [];
try {
selectOptions = [
...values.map((value, index) => {
return { name: display_values[index], value: value };
}),
];
} catch (err) {
console.log(err);
}
function onSelect(selection) {
setValue(selection);
Feature :: Exposing CSA for child widgets of form and listview (#7142) * feat :: exposing child widget of form and listview , removing register action * feat :: exposing only components and not child items * fix :: removing value of funcation info * lint fixes * reverted * test commit :: lint fix * fix :: initial render showing all components * fix :: data and children values are same * kanban breaking fix * fix for exposed variable not being accessible in initial render * comments * fix :: all components showing up in inspector during initial render for form and listview widget * reduce rerenders in button due to exposed vars * combining useeffects for lesser rerenders * fix showing of child widgets of list and form in inspector during intial render * fix :: ui break * combining useeffects in form * test commit :: reducing rerenders fromsetexposed variable called multipole time * fix :: reduce rerenders by combining multiple setExosedvariable calls * Revert "fix :: reduce rerenders by combining multiple setExosedvariable calls" This reverts commit 78c9e469444843fbbb7b0632632d54f30254c4ee. * bugfix * bugfix :: events not firing * fixes and revertions * fix :: perf checking for parent in box in case of form and listview * fix :: initial render bug * fix :: removed csa functions from listview data key * fix bugs , actions not working * fix :: dependencies * fix :: testing bugs * tabs:: event firing bug * fix :: multiselect not firing event * bugfix :: multiselect csa not triggering * fix :: kanban csa * fix :: table csa , kanban move card * fix :: bug filepicker csa
2023-09-01 08:25:03 +00:00
setExposedVariable('value', selection);
fireEvent('onSelectionChange');
}
useEffect(() => {
const exposedVariables = {
value: value,
selectOption: async function (option) {
onSelect(option);
},
};
setExposedVariables(exposedVariables);
Feature :: Exposing CSA for child widgets of form and listview (#7142) * feat :: exposing child widget of form and listview , removing register action * feat :: exposing only components and not child items * fix :: removing value of funcation info * lint fixes * reverted * test commit :: lint fix * fix :: initial render showing all components * fix :: data and children values are same * kanban breaking fix * fix for exposed variable not being accessible in initial render * comments * fix :: all components showing up in inspector during initial render for form and listview widget * reduce rerenders in button due to exposed vars * combining useeffects for lesser rerenders * fix showing of child widgets of list and form in inspector during intial render * fix :: ui break * combining useeffects in form * test commit :: reducing rerenders fromsetexposed variable called multipole time * fix :: reduce rerenders by combining multiple setExosedvariable calls * Revert "fix :: reduce rerenders by combining multiple setExosedvariable calls" This reverts commit 78c9e469444843fbbb7b0632632d54f30254c4ee. * bugfix * bugfix :: events not firing * fixes and revertions * fix :: perf checking for parent in box in case of form and listview * fix :: initial render bug * fix :: removed csa functions from listview data key * fix bugs , actions not working * fix :: dependencies * fix :: testing bugs * tabs:: event firing bug * fix :: multiselect not firing event * bugfix :: multiselect csa not triggering * fix :: kanban csa * fix :: table csa , kanban move card * fix :: bug filepicker csa
2023-09-01 08:25:03 +00:00
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);
return (
<div
data-disabled={disabledState}
className="row py-1"
style={{ height, display: visibility ? '' : 'none', boxShadow }}
2025-09-11 04:07:18 +00:00
id={`component-${id}`}
role="radiogroup"
aria-labelledby={`${id}-label`}
>
Enhance TypeScript support in frontend configuration (#15576) * test: verify pre-commit hook * fix: clean up code formatting and improve readability across multiple components * chore: update subproject commit reference in frontend/ee * chore: update eslint to version 9.26.0 and remove unused dependencies from package.json fix: update submodule reference in server/ee * chore: refactor ESLint configuration and add quiet linting script; update components to disable specific ESLint rules * chore: add GitHub Copilot review instructions for App Builder team Covers backward compatibility rules, styling conventions, state management, resolution system, widget definitions, and common review flags. * chore: add review instructions for App Builder, Data Migrations, Server Widget Config, Widget Components, and Widget Config * Enhance TypeScript support in frontend configuration - Added TypeScript parser and linting rules to ESLint configuration. - Updated Babel configuration to include TypeScript preset. - Modified package.json and package-lock.json to include TypeScript and related dependencies. - Introduced tsconfig.json for TypeScript compiler options. - Updated Webpack configuration to support .ts and .tsx file extensions. - Adjusted linting and formatting scripts to include TypeScript files. * chore: update TypeScript ESLint packages and subproject commits --------- Co-authored-by: kavinvenkatachalam <kavin.saratha@gmail.com> Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com>
2026-03-19 07:11:32 +00:00
<span
className="form-check-label col-auto py-0"
style={{ color: textColor }}
id={`${id}-label`}
data-cy={`${dataCy}-label`}
>
{label}
</span>
<div className="col px-1 py-0 mt-0">
{selectOptions.map((option, index) => (
<label key={index} className="form-check form-check-inline">
<input
data-cy={`${dataCy}-option-input-${index}`}
style={{
marginTop: '1px',
Custom themes (#13064) * feat: Add CSA and functionalities for managing loading, visibility, and disable states for full tab component. (#11267) * feat: tab draggble option and popover menu (#11267) * feat: tab scrollable arrows and tabItem logic(#11267) * feat: remove logs(#11267) * feat: Tabslayout name change(#11267) * fix: component update on Tabs * fix: tab text color update * feat: setTabDisable CSA added(#11267) * feat: added CSA for tab specific changes(#11267) * feat: added handle function for tab specific changes(#11267) * feat: shimmer for tab nav and icon chooser (#11267) * feat: icon for each tab in TabNav items (#11267) * feat: equal split width fix for each tab in TabNav items (#11267) * feat: styles for Tab Nav (#11267) * feat: slide options(#11267) * feat: fix radius (#11267) * feat: slider (#11267) * feat: fix slide direction (#11267) * feat: fix slide direction 2 (#11267) * feat: fix styles right side inspector view (#11267) * feat: nav ellipsis ... (#11267) * feat: children different for dynamic and non-dynamic (#11267) * feat:[tabsLayout] change default values in config (#11267) * feat:[tabsLayout] split and auto fix (#11267) * feat: fix styles accent and text (#11267) * feat: fix styles divider and more 2(#11267) * feat: fix styles divider and more 3(#11267) * feat: fix styles 4(#11267) * feat: fix styles 5(#11267) * feat: fix tab icon visibility 6 (#11267) * feat: modify name of property from id to Tab 7(#11267) * fixes and changes * fix: csa for tabs * new changes and fixes * fix: dynamic options sytling * v2 changes * add: new properties and styles to inspector for range slider * fixes of range slider * fix: styling * fix: styling of icons * fixed endvalue and startvalue problem * ColorSwatches for table * fix: styling * transition effect fix * fix: properties and migration * fix: slider functionality * fixed transition * new changes * visible,disable,loading,width * feat: merge appbuilder/sprint-11 with main * fix: styling * style: extend tabpane background to whole pane * [Issue 12503] Update input's with type as color to colorSwatches and also change accent color value to primary brand css variable' -m 'Changes done for: Currency, Email, Phone Number & ModalV2 component * review changes * fix: tinycolor import * [Issue 12503] Update input's with type as color to colorSwatches and also change accent color value to primary brand css variable Changes done for: Date, Time, DateTime & Date Range Picker components * [Issue 12503] Update input's with type as color to colorSwatches and also change accent color value to primary brand css variable Changes done for: Form, Textarea & Horizontal Divider component * Fix: Add default selected value config for Header & Footer Background Color input field for Form component so that its shows correct color demo & its value * Fix: Resolved custom theming issues in different components * feat: Revamps file uploader widget * Fixes added * Custom theme extra code for extra components * Submodule commit change * Submodule commit change * Textinput theming added * Number input theming added * Email & Password Theming added * Textarea theming added * Error system status added along with rating theming * ToggleV2 theming added * Toggle, RadioButton & Error related theming added * Checkbox Theming added * Dropdown V2 and legacy theming added * Multiselect V2 theming added * Adding ux friendly error messages * Misc1 and Misc 2 theming added * Multiselect legacy theming added * Form components theming added * Subcontainer related issues * Subcontainers theming added * Tabs theming added * Filepicker theming added * Range slider theming added * Steps theming added * Submodule update * Package update * Added Header text, background and container background color * Submodule Update * Submodule update * Submodule update * Submodule update * Hover effect added * feat: Revamps file uploader widget * Adding ux friendly error messages * Adds style tab * Adds min file validation * Reset vs code * Adds support for theme * Base theme added * Base theme added * Base theme added * initial commit * fix * Fixes * Submodule update * Added auto color assign feature for multiselect/select in table * Table column popover going out of bounds fix * Changed layout of component manager * DropdownV2 added to selectInputs * HTML column data type added * Table column icons added * Fix dropping widget width while dragging * Changed datepicker icon and added icons to table dropdown * Style: Update Accordion Component UI * Temp changes * Fix group selection in form * fix when dropping a component, shadow is coming on top of component manager. * improve performace on useGroupedTargetsScrollHandler * Fix * Review fixes * Minor changes * chore: update submodule references * Color swatches added icon/default and added disabled/loading state * Submodule update * Bugs solved * Fixes for Component sidebar * Custom theme related bug fixes * App Background Switch added * Submodule update * Submodule update * HTML fixes * Submodule update * Query breaking on Symbol fix * Import export property migration for Rangepicker & Textarea * Auto color pills not working for table select fix * Custom themes minor bugs * Submodule update * Minor fixes * Revamp pages in editor and viewer * bug fixes * merge base * fix conflicts * fix conflicts * bug fixes * Added swatches to page menu * Submodule update * Submodule update * Submodule update * Styling fixes * Changed few page styles * bug fixes * fix: pages icon and layout for right sidebar * fix: styling for pages menu * fix base styling * merge base * bug fixes * Bug fixes * Submodule update * Submodules updated * bug fixes * fix top styling of nav bar * Sass loader error fix * styles: correct styles to match the dsigns * Accordion design added with some minor styling fixes * fix: update default supported file of filepicker to any * fix: update styles mismatches * fix: hide min and max file count if multi file select is disabled * TJ Default changed to Tooljet Migration * Multiline code editor suggestions now close when out of view * add border to canvas * Dark theme link color fix for html column type * Spinner color fix * bug fixes * bug fixes * Submodules updated * update reference * Submodule update --------- Co-authored-by: Raman Kumar <k.raman1998@yahoo.in> Co-authored-by: Vijaykant Yadav <vjy239@gmail.com> Co-authored-by: TaruunMalik <taruunrmalik09@gmail.com> Co-authored-by: johnsoncherian <johnsonc.dev@gmail.com> Co-authored-by: NishidhJain11 <nishidh@tooljet.com> Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Nakul Nagargade <nakul@tooljet.com>
2025-06-27 12:42:34 +00:00
backgroundColor: checkedValue === option.value ? `${activeColor}` : 'var(--cc-surface1-surface)',
}}
className="form-check-input"
checked={checkedValue === option.value}
type="radio"
value={option.value}
name={`${id}-${uuidv4()}`}
onChange={() => onSelect(option.value)}
2025-09-11 04:07:18 +00:00
aria-disabled={disabledState}
aria-hidden={!visibility}
aria-labelledby={`${id}-option-${index}-label`}
/>
Enhance TypeScript support in frontend configuration (#15576) * test: verify pre-commit hook * fix: clean up code formatting and improve readability across multiple components * chore: update subproject commit reference in frontend/ee * chore: update eslint to version 9.26.0 and remove unused dependencies from package.json fix: update submodule reference in server/ee * chore: refactor ESLint configuration and add quiet linting script; update components to disable specific ESLint rules * chore: add GitHub Copilot review instructions for App Builder team Covers backward compatibility rules, styling conventions, state management, resolution system, widget definitions, and common review flags. * chore: add review instructions for App Builder, Data Migrations, Server Widget Config, Widget Components, and Widget Config * Enhance TypeScript support in frontend configuration - Added TypeScript parser and linting rules to ESLint configuration. - Updated Babel configuration to include TypeScript preset. - Modified package.json and package-lock.json to include TypeScript and related dependencies. - Introduced tsconfig.json for TypeScript compiler options. - Updated Webpack configuration to support .ts and .tsx file extensions. - Adjusted linting and formatting scripts to include TypeScript files. * chore: update TypeScript ESLint packages and subproject commits --------- Co-authored-by: kavinvenkatachalam <kavin.saratha@gmail.com> Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com>
2026-03-19 07:11:32 +00:00
<span
className="form-check-label"
style={{ color: textColor }}
id={`${id}-option-${index}-label`}
data-cy={`${dataCy}-option-label-${index}`}
>
{option.name}
</span>
</label>
))}
</div>
</div>
);
};