ui: updated usage of checkbox in all related components

This commit is contained in:
Nishchit14
2023-08-17 18:42:39 +05:30
parent cde5f99032
commit f6ac7575fd
19 changed files with 91 additions and 191 deletions

View File

@@ -123,7 +123,7 @@ const AgentItem: FC<IAgentItem> = ({
className={cx(className, 'text-base text-app-foreground flex items-start')} className={cx(className, 'text-base text-app-foreground flex items-start')}
> >
<div className="pt-half" onClick={onSelect}> <div className="pt-half" onClick={onSelect}>
<Checkbox isChecked={isSelected} id={name} disabled={disabled} /> <Checkbox checked={isSelected} id={name} disabled={disabled} classNames={{root: 'mr-2'}}/>
</div> </div>
<div className="font-semibold ml-2"> <div className="font-semibold ml-2">
<label className="cursor-pointer" htmlFor={name}> <label className="cursor-pointer" htmlFor={name}>

View File

@@ -8,23 +8,4 @@
align-items: center; align-items: center;
padding-bottom: 12px !important; padding-bottom: 12px !important;
} }
.fc-custom-checkbox input:checked ~ svg {
display: block !important;
}
.fc-custom-checkbox>.primary input:checked ~ svg {
color: var(--app-primary) !important;
}
.fc-custom-checkbox>.secondary input:checked ~ svg {
color: var(--app-secondary) !important;
}
.fc-custom-checkbox>.primary input:checked ~ span {
border-color: var(--app-primary) !important;
}
.fc-custom-checkbox>.secondary input:checked ~ span {
border-color: var(--app-primary) !important;
}
.fc-form.with-padding label.fc-custom-checkbox>span {
min-width: 72px;
}

View File

@@ -1,102 +1,18 @@
import { FC } from 'react'; import { FC } from 'react';
import cx from 'classnames'; import { Checkbox, ICheckbox } from '@firecamp/ui';
import { Check } from 'lucide-react';
import { ICheckbox } from './interfaces/Checkbox.interfaces';
import './Checkbox.scss'; import './Checkbox.scss';
const Checkbox: FC<ICheckbox> = ({
id = '',
onToggleCheck = (l, v) => {},
isChecked = false,
label = '',
tabIndex = 0,
labelPlacing = 'right',
className = '',
disabled = false,
note = '',
color = 'primary',
showLabel = true,
}) => {
return (
<div className={cx(className, 'flex')} tabIndex={tabIndex}>
<label
className={cx('fc-custom-checkbox !flex items-center mb-0 ', {
'w-4': !showLabel,
})}
onClick={(e) => {
if (e) {
e.preventDefault();
}
if (!disabled) {
onToggleCheck(label, !isChecked);
}
}}
tabIndex={-1}
>
{showLabel && labelPlacing === 'left' ? (
<span className="text-sm mr-2"> {label}</span>
) : (
''
)}
<div
className={cx(
'flex justify-center items-center cursor-pointer relative',
color,
{'opacity-50 cursor-default': disabled}
)}
tabIndex={-1}
>
<input
type="checkbox"
role="checkbox"
className="hidden"
checked={isChecked}
readOnly={true}
id={id}
/>
<span className={cx("border w-4 h-4",{'border-primaryColor': isChecked},{'border-app-foreground': !isChecked})}></span>
{isChecked ? (
<Check
size={12}
className="text-primaryColor absolute"
data-testid="check-icon"
/>
) : (
''
)}
</div>
{showLabel && labelPlacing === 'right' ? (
<span className="text-sm ml-2 cursor-pointer"> {label}</span>
) : (
''
)}
</label>
{!!note ? (
<div className="fc-input-note">
<span className="icv2-info-icon" />
{note}
</div>
) : (
''
)}
</div>
);
};
export default Checkbox;
/** /**
* Checkbox in table formate (grid) * Checkbox in table formate (grid)
*/ */
const CheckboxInGrid: FC<ICheckbox> = ({ const CheckboxInGrid: FC<ICheckbox> = ({
id = '', id = '',
onToggleCheck = (l, v) => {}, onToggleCheck = (l, v) => {},
isChecked = false, checked = false,
label = '', label = '',
tabIndex = 0, //-1 tabIndex = 0, //-1
className = '', className = '',
disabled = false, disabled = false,
note = '',
color = 'primary', color = 'primary',
}) => { }) => {
return ( return (
@@ -108,11 +24,10 @@ const CheckboxInGrid: FC<ICheckbox> = ({
key={`checkbox-in-grid-${id}`} key={`checkbox-in-grid-${id}`}
id={id} id={id}
onToggleCheck={onToggleCheck} onToggleCheck={onToggleCheck}
isChecked={isChecked} checked={checked}
tabIndex={tabIndex} tabIndex={tabIndex}
className={className} classNames={{root: className}}
disabled={disabled} disabled={disabled}
note={note}
color={color} color={color}
/> />
</div> </div>

View File

@@ -23,47 +23,60 @@ export interface ICheckbox extends CheckboxProps {
showLabel?: boolean; showLabel?: boolean;
} }
const useStyles = createStyles((theme, { primary }: Partial<ICheckbox>) => ({ const useStyles = createStyles(
disabled: { (theme, { primary, labelPosition }: Partial<ICheckbox>) => ({
opacity: '50% !important', disabled: {
'&:checked': { opacity: '50% !important',
borderColor: primary '&:checked': {
? theme.colors[theme.primaryColor][theme.colorScheme === 'dark' ? 8 : 6] borderColor: primary
: 'initial', ? theme.colors[theme.primaryColor][
},
borderColor: 'initial',
},
input: {
borderRadius: '0px',
borderColor:
theme.colorScheme === 'dark'
? theme.colors.gray[4]
: theme.colors.dark[5],
backgroundColor: 'transparent !important',
},
icon: {
...(primary
? {
color: `${
theme.colors[theme.primaryColor][
theme.colorScheme === 'dark' ? 8 : 6 theme.colorScheme === 'dark' ? 8 : 6
] ]
} !important`, : 'initial',
} },
: { borderColor: 'initial !important',
color: `${ },
theme.colorScheme === 'dark' input: {
? theme.colors.gray[4] borderRadius: '0px',
: theme.colors.dark[5] borderColor:
} !important`, theme.colorScheme === 'dark'
}), ? theme.colors.gray[4]
}, : theme.colors.dark[5],
label: { backgroundColor: 'transparent !important',
color: `${ },
theme.colorScheme === 'dark' ? theme.colors.gray[4] : theme.colors.dark[5] icon: {
} !important`, ...(primary
}, ? {
})); color: `${
theme.colors[theme.primaryColor][
theme.colorScheme === 'dark' ? 8 : 6
]
} !important`,
}
: {
color: `${
theme.colorScheme === 'dark'
? theme.colors.gray[4]
: theme.colors.dark[5]
} !important`,
}),
},
label: {
...(labelPosition === 'left'
? {
paddingRight: '0.5rem',
}
: {
paddingLeft: '0.5rem',
}),
color: `${
theme.colorScheme === 'dark'
? theme.colors.gray[4]
: theme.colors.dark[5]
} !important`,
},
})
);
const Checkbox: FC<ICheckbox> = ({ const Checkbox: FC<ICheckbox> = ({
color, color,
@@ -74,9 +87,10 @@ const Checkbox: FC<ICheckbox> = ({
disabled = false, disabled = false,
onToggleCheck = (l, v) => {}, onToggleCheck = (l, v) => {},
showLabel = true, showLabel = true,
labelPosition,
...props ...props
}) => { }) => {
const { classes, cx, theme } = useStyles({ primary: primary }); const { classes, cx, theme } = useStyles({ primary, labelPosition });
const customColor = primary const customColor = primary
? 'primaryColor' ? 'primaryColor'
: theme.colorScheme === 'dark' : theme.colorScheme === 'dark'
@@ -91,6 +105,7 @@ const Checkbox: FC<ICheckbox> = ({
label={showLabel ? label : ''} label={showLabel ? label : ''}
disabled={disabled} disabled={disabled}
checked={checked} checked={checked}
labelPosition={labelPosition}
classNames={{ classNames={{
...classNames, ...classNames,
input: cx(classes.input, classNames.input, { input: cx(classes.input, classNames.input, {

View File

@@ -1,4 +1,4 @@
import Checkbox from './Checkbox'; import {Checkbox} from '@firecamp/ui';
const CheckboxGroup = ({ const CheckboxGroup = ({
onToggleCheck = (v: {[k: string]: any}) => {}, onToggleCheck = (v: {[k: string]: any}) => {},
@@ -15,14 +15,14 @@ const CheckboxGroup = ({
return ( return (
<Checkbox <Checkbox
key={index} key={index}
isChecked={checkbox.isChecked || false} checked={checkbox.isChecked || false}
label={checkbox.label || ''} label={checkbox.label || ''}
showLabel={checkbox.showLabel || false} showLabel={checkbox.showLabel || false}
disabled={checkbox.disabled || false} disabled={checkbox.disabled || false}
onToggleCheck={() => onToggleCheck={() =>
onToggleCheck({ [checkbox.id]: !checkbox.isChecked }) onToggleCheck({ [checkbox.id]: !checkbox.isChecked })
} }
className="mr-2" classNames={{root:"mr-2"}}
/> />
); );
})} })}

View File

@@ -103,16 +103,16 @@ export function FormWithCheckBox() {
label={'Namespace'} label={'Namespace'}
{...getInputProps('namespace')} {...getInputProps('namespace')}
/> />
<Checkbox <div>
isChecked={checkBoxItem.isChecked || false} <label>{checkBoxItem.label || ''}</label>
label={checkBoxItem.label || ''} <Checkbox
showLabel={checkBoxItem.showLabel || false} checked={checkBoxItem.isChecked || false}
disabled={checkBoxItem.disabled || false} disabled={checkBoxItem.disabled || false}
onToggleCheck={_handleCheckBoxAction} onToggleCheck={_handleCheckBoxAction}
className="mr-2 mb-2" classNames={{ root: 'mr-2 mb-2' }}
labelPlacing="left" labelPosition="left"
/> />
</div>
<div className="form-control"> <div className="form-control">
<Button <Button
type="submit" type="submit"

View File

@@ -3,8 +3,7 @@ import cx from 'classnames';
import { GripVertical, Plus, Trash2 } from 'lucide-react'; import { GripVertical, Plus, Trash2 } from 'lucide-react';
import { _array } from '@firecamp/utils'; import { _array } from '@firecamp/utils';
import { EEditorLanguage } from '@firecamp/types'; import { EEditorLanguage } from '@firecamp/types';
import { Input, Button } from '@firecamp/ui'; import { Button, Checkbox, Input } from '@firecamp/ui';
import Checkbox from '../../checkbox/Checkbox';
import SingleLineEditor from '../../editors/monaco-v2/SingleLineEditor'; import SingleLineEditor from '../../editors/monaco-v2/SingleLineEditor';
import Table from '../primitive/Table'; import Table from '../primitive/Table';
import { import {
@@ -70,10 +69,11 @@ const BasicTable = ({
)} )}
<Checkbox <Checkbox
isChecked={!cellValue} checked={!cellValue}
onToggleCheck={(label, val: boolean) => { onToggleCheck={(label, val: boolean) => {
onChange(column.key, !val); onChange(column.key, !val);
}} }}
classNames={{ root: 'pr-2' }}
disabled={options.disabledColumns.includes(column.key)} disabled={options.disabledColumns.includes(column.key)}
/> />
</div> </div>

View File

@@ -4,9 +4,8 @@ import { File, GripVertical, Plus, Trash2 } from 'lucide-react';
import { _array } from '@firecamp/utils'; import { _array } from '@firecamp/utils';
import { VscTextSize } from '@react-icons/all-files/vsc/VscTextSize'; import { VscTextSize } from '@react-icons/all-files/vsc/VscTextSize';
import { EEditorLanguage } from '@firecamp/types'; import { EEditorLanguage } from '@firecamp/types';
import { Input, Button } from '@firecamp/ui'; import { Button, Checkbox, Input } from '@firecamp/ui';
import Checkbox from '../../checkbox/Checkbox';
import SingleLineEditor from '../../editors/monaco-v2/SingleLineEditor'; import SingleLineEditor from '../../editors/monaco-v2/SingleLineEditor';
import Table from '../primitive/Table'; import Table from '../primitive/Table';
import { import {
@@ -68,7 +67,7 @@ const MultipartTable = ({
</span> </span>
<Checkbox <Checkbox
isChecked={!cellValue} checked={!cellValue}
onToggleCheck={(label, val: boolean) => { onToggleCheck={(label, val: boolean) => {
onChange(column.key, !val); onChange(column.key, !val);
}} }}

View File

@@ -4,9 +4,6 @@
width: calc(100% - 24px) width: calc(100% - 24px)
margin: 12px margin: 12px
.primary-table td:first-child svg
width: 100%
.primary-table th .primary-table th
position: relative position: relative

View File

@@ -222,9 +222,6 @@ body {
.theme-dark .drag-icon { .theme-dark .drag-icon {
filter: invert(1); filter: invert(1);
} }
.icon {
font-family: 'icomoon' !important;
}
a, a,
a:hover { a:hover {
@@ -427,7 +424,7 @@ tr:focus-visible {
white-space: nowrap !important; white-space: nowrap !important;
} }
.fc-form input, .fc-form input:not([type="checkbox"]),
.fc-form select { .fc-form select {
border-radius: 0px !important; border-radius: 0px !important;
resize: none; resize: none;

View File

@@ -2191,9 +2191,6 @@ body {
.theme-dark .drag-icon { .theme-dark .drag-icon {
filter: invert(1); filter: invert(1);
} }
.icon {
font-family: 'icomoon' !important;
}
a, a,
a:hover { a:hover {
@@ -2402,7 +2399,7 @@ tr:focus-visible {
white-space: nowrap !important; white-space: nowrap !important;
} }
.fc-form input, .fc-form input:not([type="checkbox"]),
.fc-form select { .fc-form select {
border-radius: 0px !important; border-radius: 0px !important;
resize: none; resize: none;

View File

@@ -11,7 +11,6 @@ import { Meta, ColorPalette, ColorItem } from '@storybook/addon-docs';
| ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| .theme-light.primary-green,.theme-dark.primary-green | to update the app primary color | | .theme-light.primary-green,.theme-dark.primary-green | to update the app primary color |
| .theme-dark .drag-icon | to invert the icon color in dark theme | | .theme-dark .drag-icon | to invert the icon color in dark theme |
| .icon | to add font family `icomoon` |
| a,a:hover | to inherit the text color | | a,a:hover | to inherit the text color |
| button:disabled,button[disabled] | to update opacity for all disabled button using pseudo class selector | | button:disabled,button[disabled] | to update opacity for all disabled button using pseudo class selector |
| hr | to update the app border color in horizontal line | | hr | to update the app border color in horizontal line |

View File

@@ -1,8 +1,8 @@
export { default as Button } from './components/buttons/Button'; export { default as Button } from './components/buttons/Button';
export { default as CopyButton } from './components/buttons/CopyButton'; export { default as CopyButton } from './components/buttons/CopyButton';
export { default as Checkbox } from './components/checkbox/Checkbox'; export { default as Checkbox } from './components/checkbox/Checkbox2';
export { default as Checkbox2 } from './components/checkbox/Checkbox2'; export type { ICheckbox } from './components/checkbox/Checkbox2';
export { default as CheckboxGroup } from './components/checkbox/CheckboxGroup'; export { default as CheckboxGroup } from './components/checkbox/CheckboxGroup';
export { default as Dropdown } from './components/dropdown/Dropdown'; export { default as Dropdown } from './components/dropdown/Dropdown';

View File

@@ -73,13 +73,13 @@ const ConfigTab = () => {
</div> </div>
<CheckboxInGrid <CheckboxInGrid
className="fc-input-wrapper" className="fc-input-wrapper"
isChecked={config[RejectUnauthorized]} checked={config[RejectUnauthorized]}
label="Reject Unauthorized" label="Reject Unauthorized"
onToggleCheck={() => _onToggleCheckBox(RejectUnauthorized)} onToggleCheck={() => _onToggleCheckBox(RejectUnauthorized)}
/> />
<CheckboxInGrid <CheckboxInGrid
className="fc-input-wrapper" className="fc-input-wrapper"
isChecked={ checked={
config[FollowLocation] === undefined config[FollowLocation] === undefined
? true ? true
: config[FollowLocation] : config[FollowLocation]

View File

@@ -157,7 +157,7 @@ const ConfigTab = ({ id = '' }) => {
return ( return (
<CheckboxInGrid <CheckboxInGrid
key={`${name}-${index}`} key={`${name}-${index}`}
isChecked={connection[name] || false} checked={connection[name] || false}
label={label} label={label}
className="fc-input-wrapper" className="fc-input-wrapper"
onToggleCheck={(_) => _onChange(name, !connection[name])} onToggleCheck={(_) => _onChange(name, !connection[name])}

View File

@@ -74,7 +74,7 @@ const EmitterPlayground = () => {
</TabHeader.Left> </TabHeader.Left>
<TabHeader.Right> <TabHeader.Right>
<Checkbox <Checkbox
isChecked={plgEmitter.__meta.ack} checked={plgEmitter.__meta.ack}
label="Ack" label="Ack"
onToggleCheck={(label, val) => changePlgEmitterAck(val)} onToggleCheck={(label, val) => changePlgEmitterAck(val)}
/> />

View File

@@ -148,16 +148,16 @@ const EmitterBody = ({
// ); // );
case EArgumentBodyType.Boolean: case EArgumentBodyType.Boolean:
return ( return (
<div className="flex p-2"> <div className="flex p-2 gap-2">
<Checkbox <Checkbox
isChecked={argument.body === true} checked={argument.body === true}
label="True" label="True"
onToggleCheck={(_) => { onToggleCheck={(_) => {
changeArgValue(true); changeArgValue(true);
}} }}
/> />
<Checkbox <Checkbox
isChecked={argument.body === false} checked={argument.body === false}
label="False" label="False"
onToggleCheck={(_) => { onToggleCheck={(_) => {
changeArgValue(false); changeArgValue(false);

View File

@@ -212,7 +212,7 @@ const Config = ({ config = {} }) => {
<CheckboxInGrid <CheckboxInGrid
key={`${name}-${index}`} key={`${name}-${index}`}
label={label} label={label}
isChecked={config[name] || false} checked={config[name] || false}
className="fc-input-wrapper" className="fc-input-wrapper"
onToggleCheck={() => _onChange(name, !config[name])} onToggleCheck={() => _onChange(name, !config[name])}
/> />

View File

@@ -95,7 +95,7 @@ const Config = ({ config = {}, onUpdate }) => {
return ( return (
<CheckboxInGrid <CheckboxInGrid
key={`${name}-${index}`} key={`${name}-${index}`}
isChecked={config[name] || false} checked={config[name] || false}
label={label} label={label}
className="fc-input-wrapper" className="fc-input-wrapper"
onToggleCheck={() => _onChange(name, !config[name])} onToggleCheck={() => _onChange(name, !config[name])}