mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
* 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>
100 lines
2.8 KiB
JavaScript
100 lines
2.8 KiB
JavaScript
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);
|
|
setExposedVariable('value', selection);
|
|
fireEvent('onSelectionChange');
|
|
}
|
|
|
|
useEffect(() => {
|
|
const exposedVariables = {
|
|
value: value,
|
|
selectOption: async function (option) {
|
|
onSelect(option);
|
|
},
|
|
};
|
|
setExposedVariables(exposedVariables);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [value]);
|
|
|
|
return (
|
|
<div
|
|
data-disabled={disabledState}
|
|
className="row py-1"
|
|
style={{ height, display: visibility ? '' : 'none', boxShadow }}
|
|
id={`component-${id}`}
|
|
role="radiogroup"
|
|
aria-labelledby={`${id}-label`}
|
|
>
|
|
<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',
|
|
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)}
|
|
aria-disabled={disabledState}
|
|
aria-hidden={!visibility}
|
|
aria-labelledby={`${id}-option-${index}-label`}
|
|
/>
|
|
<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>
|
|
);
|
|
};
|