Add some checked state to component picker

This commit is contained in:
soupette 2019-12-19 11:54:57 +01:00
parent a1da290d42
commit 3a9b64df6a
2 changed files with 16 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import UpperFirst from '../UpperFirst';
import SubUl from './SubUl'; import SubUl from './SubUl';
import Ul from './Ul'; import Ul from './Ul';
import hasSubArray from './utils/hasSubArray'; import hasSubArray from './utils/hasSubArray';
import hasSomeSubArray from './utils/HasSomeSubArray';
const MultipleMenuList = ({ const MultipleMenuList = ({
selectProps: { name, addComponentsToDynamicZone, /*refState, */ value }, selectProps: { name, addComponentsToDynamicZone, /*refState, */ value },
@ -52,6 +53,12 @@ const MultipleMenuList = ({
return hasSubArray(value.value, componentsCategory); return hasSubArray(value.value, componentsCategory);
}; };
const doesCategoryHasSomeElements = categoryName => {
const componentsCategory = allComponentsCategory[categoryName];
return hasSomeSubArray(value.value, componentsCategory);
};
const handleChangeCategory = ({ target }) => { const handleChangeCategory = ({ target }) => {
// refState.current.select.blur(); // refState.current.select.blur();
const dataTarget = { const dataTarget = {
@ -81,6 +88,8 @@ const MultipleMenuList = ({
> >
{Object.keys(componentsGroupedByCategory).map(categoryName => { {Object.keys(componentsGroupedByCategory).map(categoryName => {
const isChecked = getCategoryValue(categoryName); const isChecked = getCategoryValue(categoryName);
const someChecked =
!isChecked && doesCategoryHasSomeElements(categoryName);
const target = { name: categoryName, value: !isChecked }; const target = { name: categoryName, value: !isChecked };
return ( return (
@ -95,9 +104,10 @@ const MultipleMenuList = ({
> >
<Checkbox <Checkbox
id="checkCategory" id="checkCategory"
checked={isChecked}
name={categoryName} name={categoryName}
onChange={() => {}} onChange={() => {}}
checked={getCategoryValue(categoryName)} someChecked={someChecked}
style={{ marginRight: 10 }} style={{ marginRight: 10 }}
/> />
<UpperFirst content={categoryName} /> <UpperFirst content={categoryName} />

View File

@ -0,0 +1,5 @@
const hasSomeSubArray = (master, sub) => {
return sub.some(v => master.indexOf(v) !== -1);
};
export default hasSomeSubArray;