Skip to content

Commit

Permalink
Refactor of Matrix elements to make it reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Riabkov committed Mar 29, 2024
1 parent 54fecc4 commit 2874226
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/entities/activity/ui/items/ItemPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AudioPlayerItem } from './AudioPlayerItem';
import { CheckboxItem } from './CheckboxItem';
import { DateItem } from './DateItem';
import { MatrixCheckboxItem } from './MatrixCheckboxItem';
import { MatrixCheckboxItem } from './Matrix/MatrixMultiSelectItem';
import { RadioItem } from './RadioItem';
import { SelectorItem } from './SelectorItem';
import { SliderItem } from './SliderItem';
Expand Down Expand Up @@ -103,6 +103,9 @@ export const ItemPicker = ({ item, onValueChange, isDisabled, replaceText }: Ite
/>
);

case 'singleSelectRows':
return <div>boom</div>;

default:
return <></>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Box from '@mui/material/Box';

import { MatrixCell } from '../MatrixCell';

import { CheckboxItem, SelectBaseBox } from '~/shared/ui';

type Props = {
id: string;
isChecked: boolean;
text: string;

onChange: () => void;
};

export const CheckboxButton = ({ id, isChecked, text, onChange }: Props) => {
return (
<Box flex={1} key={id}>
<MatrixCell>
<SelectBaseBox
color={null}
onHandleChange={onChange}
checked={isChecked}
justifyContent="center"
>
<CheckboxItem
id={id}
name={text}
value={text}
disabled={false}
defaultChecked={isChecked}
/>
</SelectBaseBox>
</MatrixCell>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import Box from '@mui/material/Box';

import { MatrixCell } from './MatrixCell';
import { MatrixHeader } from './MatrixHeader';
import { MatrixRow } from './MatrixRow';
import { MatrixMultiSelectAnswer, MatrixSelectOption, MatrixSelectRow } from '../../../lib';

import { CheckboxItem, SelectBaseBox } from '~/shared/ui';
import { CheckboxButton } from './CheckboxButton';
import { MatrixMultiSelectAnswer, MatrixSelectOption, MatrixSelectRow } from '../../../../lib';
import { MatrixHeader } from '../MatrixHeader';
import { MatrixRow } from '../MatrixRow';

type Props = {
options: Array<MatrixSelectOption>;
Expand Down Expand Up @@ -33,24 +31,13 @@ export const StackedItemsGrid = ({ rows, options, onChange, values }: Props) =>
const isChecked = Boolean(values[rowI]?.[optionI]);

return (
<Box flex={1} key={option.id}>
<MatrixCell>
<SelectBaseBox
color={null}
onHandleChange={() => onChange(rowI, optionI, option.text)}
checked={isChecked}
justifyContent="center"
>
<CheckboxItem
id={option.id}
name={option.text}
value={option.text}
disabled={false}
defaultChecked={isChecked}
/>
</SelectBaseBox>
</MatrixCell>
</Box>
<CheckboxButton
key={option.id}
id={option.id}
text={option.text}
isChecked={isChecked}
onChange={() => onChange(rowI, optionI, option.text)}
/>
);
})}
</MatrixRow>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react';

import { StackedItemsGrid } from './StackedItemsGrid';
import { MatrixMultiSelectAnswer, MultiSelectionRowsItem } from '../../../lib';
import { MatrixMultiSelectAnswer, MultiSelectionRowsItem } from '../../../../lib';

type Props = {
item: MultiSelectionRowsItem;
Expand Down

0 comments on commit 2874226

Please sign in to comment.