* wip logic for indeterminate icon * wip remove unused imports * fix cutted off checkbox ripples * refactor & cleanup
This commit is contained in:
parent
a311583647
commit
06f0697438
3 changed files with 20 additions and 10 deletions
|
@ -6,8 +6,6 @@ import {
|
||||||
Typography
|
Typography
|
||||||
} from "@material-ui/core";
|
} from "@material-ui/core";
|
||||||
import { ChannelData } from "@saleor/channels/utils";
|
import { ChannelData } from "@saleor/channels/utils";
|
||||||
import IconCheckboxChecked from "@saleor/icons/CheckboxChecked";
|
|
||||||
import IconCheckboxSemiChecked from "@saleor/icons/CheckboxSemiChecked";
|
|
||||||
import IconChevronDown from "@saleor/icons/ChevronDown";
|
import IconChevronDown from "@saleor/icons/ChevronDown";
|
||||||
import { makeStyles } from "@saleor/macaw-ui";
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
import Label from "@saleor/orders/components/OrderHistory/Label";
|
import Label from "@saleor/orders/components/OrderHistory/Label";
|
||||||
|
@ -126,15 +124,19 @@ const ChannelsWithVariantsAvailabilityDialogContent: React.FC<ChannelsWithVarian
|
||||||
? addVariantToChannel(channelId, variantId)
|
? addVariantToChannel(channelId, variantId)
|
||||||
: removeVariantFromChannel(channelId, variantId);
|
: removeVariantFromChannel(channelId, variantId);
|
||||||
|
|
||||||
const selectChannelIcon = (channelId: string) =>
|
const isChannelPartiallySelected = (channelId: string) => {
|
||||||
areAllChannelVariantsSelected(
|
const selectedVariants = channelVariantListingDiffToDict(
|
||||||
|
channelsWithVariants
|
||||||
|
)[channelId];
|
||||||
|
|
||||||
|
if (selectedVariants.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !areAllChannelVariantsSelected(
|
||||||
allVariants?.map(variant => variant.id),
|
allVariants?.map(variant => variant.id),
|
||||||
channelVariantListingDiffToDict(channelsWithVariants)[channelId]
|
selectedVariants
|
||||||
) ? (
|
|
||||||
<IconCheckboxChecked />
|
|
||||||
) : (
|
|
||||||
<IconCheckboxSemiChecked />
|
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -172,7 +174,7 @@ const ChannelsWithVariantsAvailabilityDialogContent: React.FC<ChannelsWithVarian
|
||||||
<div className={classes.channelCheckboxContainer}>
|
<div className={classes.channelCheckboxContainer}>
|
||||||
<ControlledCheckbox
|
<ControlledCheckbox
|
||||||
checked={isChannelSelected(channelId)}
|
checked={isChannelSelected(channelId)}
|
||||||
checkedIcon={selectChannelIcon(channelId)}
|
indeterminate={isChannelPartiallySelected(channelId)}
|
||||||
name={name}
|
name={name}
|
||||||
label={
|
label={
|
||||||
<div className={classes.channelTitleContainer}>
|
<div className={classes.channelTitleContainer}>
|
||||||
|
|
|
@ -38,6 +38,11 @@ export const useStyles = makeStyles(
|
||||||
},
|
},
|
||||||
overflowY: "scroll",
|
overflowY: "scroll",
|
||||||
overflowX: "hidden",
|
overflowX: "hidden",
|
||||||
|
// overflowX can't be "visible" when overflowY is "scroll"
|
||||||
|
// workaround for visible button ripples:
|
||||||
|
marginLeft: -15,
|
||||||
|
paddingLeft: 15,
|
||||||
|
|
||||||
marginBottom: theme.spacing(3)
|
marginBottom: theme.spacing(3)
|
||||||
},
|
},
|
||||||
text: {
|
text: {
|
||||||
|
|
|
@ -6,6 +6,7 @@ interface ControlledCheckboxProps {
|
||||||
name: string;
|
name: string;
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
|
indeterminate?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
checkedIcon?: React.ReactNode;
|
checkedIcon?: React.ReactNode;
|
||||||
onChange(event: any);
|
onChange(event: any);
|
||||||
|
@ -18,6 +19,7 @@ export const ControlledCheckbox: React.FC<ControlledCheckboxProps> = ({
|
||||||
label,
|
label,
|
||||||
onChange,
|
onChange,
|
||||||
checkedIcon,
|
checkedIcon,
|
||||||
|
indeterminate,
|
||||||
...props
|
...props
|
||||||
}) => (
|
}) => (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
|
@ -26,6 +28,7 @@ export const ControlledCheckbox: React.FC<ControlledCheckboxProps> = ({
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checkedIcon={checkedIcon}
|
checkedIcon={checkedIcon}
|
||||||
checked={!!checked}
|
checked={!!checked}
|
||||||
|
indeterminate={indeterminate}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
name={name}
|
name={name}
|
||||||
onChange={() => onChange({ target: { name, value: !checked } })}
|
onChange={() => onChange({ target: { name, value: !checked } })}
|
||||||
|
|
Loading…
Reference in a new issue