@edvisor/product-language 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +480 -31
- package/lib/components/checkbox/checkbox.d.ts +1 -0
- package/lib/components/checkbox/helpers.d.ts +4 -4
- package/lib/components/index.d.ts +1 -0
- package/lib/components/molecules/input-checkbox/input-checkbox.d.ts +0 -1
- package/lib/components/select/index.d.ts +1 -0
- package/lib/components/tree-view/components/tree-node.d.ts +3 -0
- package/lib/components/tree-view/helper.d.ts +12 -0
- package/lib/components/tree-view/index.d.ts +2 -0
- package/lib/components/tree-view/tree-view.d.ts +3 -0
- package/lib/components/tree-view/types.d.ts +62 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4531,20 +4531,18 @@ const LeftRightCard = props => {
|
|
|
4531
4531
|
LeftRightCard.Right = Right;
|
|
4532
4532
|
LeftRightCard.Controls = Controls$1;
|
|
4533
4533
|
|
|
4534
|
-
const
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
*/
|
|
4539
|
-
|
|
4540
|
-
const svg = `
|
|
4541
|
-
<svg xmlns='http://www.w3.org/2000/svg' width='${WIDTH}' height='${HEIGHT}' viewBox='0 0 10 8'>
|
|
4542
|
-
<path d='M4.50846 7.37941C4.0689 7.81898 3.35108 7.81898 2.91151 7.37941L0.330581 4.79848C-0.110194 4.35892 -0.110194 3.64109 0.330581 3.20153C0.770146 2.76196 1.48797 2.76196 1.92753 3.20153L3.70999 4.98399L8.07338 0.620598C8.51294 0.181033 9.23076 0.181033 9.67033 0.620598C10.1099 1.06016 10.1099 1.77798 9.67033 2.21755L4.50846 7.37941Z' fill='white'/>
|
|
4543
|
-
</svg>
|
|
4534
|
+
const indeterminateSvg = `
|
|
4535
|
+
<svg xmlns='http://www.w3.org/2000/svg' width='12' height='10' viewBox='0 0 10 8'>
|
|
4536
|
+
<rect fill='white' width='10' height='2' rx='1'/>
|
|
4537
|
+
</svg>
|
|
4544
4538
|
`;
|
|
4539
|
+
const checkSvg = `
|
|
4540
|
+
<svg xmlns='http://www.w3.org/2000/svg' width='10' height='12' viewBox='0 0 10 8'>
|
|
4541
|
+
<path d='M4.50846 7.37941C4.0689 7.81898 3.35108 7.81898 2.91151 7.37941L0.330581 4.79848C-0.110194 4.35892 -0.110194 3.64109 0.330581 3.20153C0.770146 2.76196 1.48797 2.76196 1.92753 3.20153L3.70999 4.98399L8.07338 0.620598C8.51294 0.181033 9.23076 0.181033 9.67033 0.620598C10.1099 1.06016 10.1099 1.77798 9.67033 2.21755L4.50846 7.37941Z' fill='white'/>
|
|
4542
|
+
</svg>`;
|
|
4545
4543
|
|
|
4546
|
-
function getCheckMark() {
|
|
4547
|
-
return css(["::before{position:absolute;content:url(\"data:image/svg+xml,", "\");
|
|
4544
|
+
function getCheckMark(indeterminate) {
|
|
4545
|
+
return css(["::before{position:absolute;content:url(\"data:image/svg+xml,", "\");left:", "px;top:", "px;}"], indeterminate ? indeterminateSvg : checkSvg, indeterminate ? 3 : 4, indeterminate ? 6 : 3);
|
|
4548
4546
|
}
|
|
4549
4547
|
/** the reason I have this isNil to test
|
|
4550
4548
|
* whether `checked` was passes is this:
|
|
@@ -4559,41 +4557,49 @@ function getCheckMark() {
|
|
|
4559
4557
|
*/
|
|
4560
4558
|
|
|
4561
4559
|
|
|
4562
|
-
function getCheckedStyles(color) {
|
|
4560
|
+
function getCheckedStyles(indeterminate, color) {
|
|
4563
4561
|
return css(["", ""], ({
|
|
4564
4562
|
checked
|
|
4565
|
-
}) => isNil(checked) ? css([":checked{background:", ";border:2px solid ", ";", "}"], color, color, getCheckMark()) : checked ? css(["background:", ";border:2px solid ", ";", ""], color, color, getCheckMark()) : '');
|
|
4563
|
+
}) => isNil(checked) ? css([":checked{background:", ";border:2px solid ", ";", "}"], color, color, getCheckMark(indeterminate)) : is(checked) || is(indeterminate) ? css(["background:", ";border:2px solid ", ";", ""], color, color, getCheckMark(indeterminate)) : '');
|
|
4566
4564
|
}
|
|
4567
4565
|
|
|
4568
|
-
const getHoverStyles =
|
|
4569
|
-
const getDisabledStyles =
|
|
4570
|
-
const getDefaultStyles =
|
|
4571
|
-
const getInvalidStyles =
|
|
4566
|
+
const getHoverStyles = indeterminate => css(["background:", ";", ""], Surface.Default.Hover, getCheckedStyles(indeterminate, Interactive.Default.Hover));
|
|
4567
|
+
const getDisabledStyles = indeterminate => css(["pointer-events:none;background:", ";border:2px solid ", ";", ""], props => is(props.checked) || is(indeterminate) ? `${Borders.Default.Default}` : `${Surface.Default.Subdued}`, Borders.Default.Default, getCheckedStyles(indeterminate, Icons.Disabled));
|
|
4568
|
+
const getDefaultStyles = indeterminate => css(["background:", ";border:2px solid ", ";", ":hover{", "}"], Surface.Default.Default, Interactive.Default.Disabled, getCheckedStyles(indeterminate, Interactive.Default.Default), getHoverStyles(indeterminate));
|
|
4569
|
+
const getInvalidStyles = indeterminate => css(["background:", ";border:2px solid ", ";", ""], props => is(props.checked) || is(indeterminate) ? `${Actions.Critical.Default}` : `${Surface.Critical.Subdued}`, Borders.Critical.Default, getCheckedStyles(indeterminate, Icons.Critical));
|
|
4572
4570
|
|
|
4573
4571
|
const CustomizedCheckbox = /*#__PURE__*/styled.input.withConfig({
|
|
4574
4572
|
displayName: "checkbox__CustomizedCheckbox",
|
|
4575
4573
|
componentId: "gcfss3-0"
|
|
4576
4574
|
})(["appearance:none;position:relative;box-sizing:content-box;width:18px;height:18px;margin:", ";padding:", ";border-radius:4px;user-select:none;vertical-align:bottom;display:inline-block;", ":focus-visible{outline:2px solid ", ";outline-offset:1px;}"], Margin.none, Padding.none, ({
|
|
4577
4575
|
disabled,
|
|
4576
|
+
indeterminate,
|
|
4578
4577
|
error
|
|
4579
4578
|
}) => {
|
|
4580
4579
|
if (is(disabled)) {
|
|
4581
|
-
return getDisabledStyles();
|
|
4580
|
+
return getDisabledStyles(indeterminate);
|
|
4582
4581
|
} else if (is(error)) {
|
|
4583
|
-
return getInvalidStyles();
|
|
4582
|
+
return getInvalidStyles(indeterminate);
|
|
4584
4583
|
} else {
|
|
4585
|
-
return getDefaultStyles();
|
|
4584
|
+
return getDefaultStyles(indeterminate);
|
|
4586
4585
|
}
|
|
4587
4586
|
}, Focused.Default);
|
|
4588
4587
|
const Checkbox = props => {
|
|
4589
4588
|
const {
|
|
4590
|
-
error
|
|
4589
|
+
error,
|
|
4590
|
+
indeterminate
|
|
4591
4591
|
} = props,
|
|
4592
|
-
htmlProps = __rest(props, ["error"]);
|
|
4592
|
+
htmlProps = __rest(props, ["error", "indeterminate"]);
|
|
4593
4593
|
|
|
4594
4594
|
return jsx(CustomizedCheckbox, Object.assign({}, htmlProps, {
|
|
4595
4595
|
type: 'checkbox',
|
|
4596
|
-
error: error
|
|
4596
|
+
error: error,
|
|
4597
|
+
indeterminate: is(indeterminate),
|
|
4598
|
+
ref: input => {
|
|
4599
|
+
if (isDefined(input)) {
|
|
4600
|
+
input.indeterminate = is(props.indeterminate);
|
|
4601
|
+
}
|
|
4602
|
+
}
|
|
4597
4603
|
}));
|
|
4598
4604
|
};
|
|
4599
4605
|
|
|
@@ -9319,6 +9325,455 @@ fixRegExpWellKnownSymbolLogic('split', function (SPLIT, nativeSplit, maybeCallNa
|
|
|
9319
9325
|
];
|
|
9320
9326
|
}, !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC, UNSUPPORTED_Y);
|
|
9321
9327
|
|
|
9328
|
+
var CheckboxState;
|
|
9329
|
+
|
|
9330
|
+
(function (CheckboxState) {
|
|
9331
|
+
CheckboxState[CheckboxState["UNCHECKED"] = 0] = "UNCHECKED";
|
|
9332
|
+
CheckboxState[CheckboxState["CHECKED"] = 1] = "CHECKED";
|
|
9333
|
+
CheckboxState[CheckboxState["INDETERMINATE"] = 2] = "INDETERMINATE";
|
|
9334
|
+
})(CheckboxState || (CheckboxState = {}));
|
|
9335
|
+
|
|
9336
|
+
const ListItem = /*#__PURE__*/styled.li.withConfig({
|
|
9337
|
+
displayName: "tree-node__ListItem",
|
|
9338
|
+
componentId: "sc-1wjf7p9-0"
|
|
9339
|
+
})(["& ol{margin-top:", ";}", ""], Margin.xs, ({
|
|
9340
|
+
disabled
|
|
9341
|
+
}) => is(disabled) && css(["opacity:.75;cursor:not-allowed;"]));
|
|
9342
|
+
const ItemWrapper = /*#__PURE__*/styled(Flex).withConfig({
|
|
9343
|
+
displayName: "tree-node__ItemWrapper",
|
|
9344
|
+
componentId: "sc-1wjf7p9-1"
|
|
9345
|
+
})(["align-items:center;padding:", " ", ";gap:8px;flex:none;order:0;align-self:stretch;flex-grow:0;"], Padding.xxxs, Padding.none);
|
|
9346
|
+
const ClickableLabel = /*#__PURE__*/styled(Label).withConfig({
|
|
9347
|
+
displayName: "tree-node__ClickableLabel",
|
|
9348
|
+
componentId: "sc-1wjf7p9-2"
|
|
9349
|
+
})(["cursor:pointer;&:hover{background:", ";}&:focus{outline:0;background:", ";}"], Surface.Default.Default, Surface.Default.Default);
|
|
9350
|
+
const CollapseButton = /*#__PURE__*/styled(Button).withConfig({
|
|
9351
|
+
displayName: "tree-node__CollapseButton",
|
|
9352
|
+
componentId: "sc-1wjf7p9-3"
|
|
9353
|
+
})(["align-self:baseline;top:10px;border:0;cursor:pointer;padding:", ";gap:0;width:8px;margin-left:auto;right:8px;&:active{outline:none;}"], Padding.none);
|
|
9354
|
+
const InputWrapper = /*#__PURE__*/styled(Flex).withConfig({
|
|
9355
|
+
displayName: "tree-node__InputWrapper",
|
|
9356
|
+
componentId: "sc-1wjf7p9-4"
|
|
9357
|
+
})(["gap:8px;"]);
|
|
9358
|
+
const HelpfulMessage$1 = /*#__PURE__*/styled(Label).withConfig({
|
|
9359
|
+
displayName: "tree-node__HelpfulMessage",
|
|
9360
|
+
componentId: "sc-1wjf7p9-5"
|
|
9361
|
+
})(["margin-left:", ";user-select:none;"], Margin.xl);
|
|
9362
|
+
const TreeNode = props => {
|
|
9363
|
+
const {
|
|
9364
|
+
value,
|
|
9365
|
+
label,
|
|
9366
|
+
expanded
|
|
9367
|
+
} = props;
|
|
9368
|
+
|
|
9369
|
+
const handleCheck = () => {
|
|
9370
|
+
const {
|
|
9371
|
+
onCheck
|
|
9372
|
+
} = props;
|
|
9373
|
+
onCheck({
|
|
9374
|
+
label,
|
|
9375
|
+
value,
|
|
9376
|
+
checked: getCheckState({
|
|
9377
|
+
toggle: true
|
|
9378
|
+
})
|
|
9379
|
+
});
|
|
9380
|
+
};
|
|
9381
|
+
|
|
9382
|
+
const handleClick = () => {
|
|
9383
|
+
const {
|
|
9384
|
+
onClick,
|
|
9385
|
+
isParent,
|
|
9386
|
+
expandDisabled
|
|
9387
|
+
} = props;
|
|
9388
|
+
|
|
9389
|
+
if (isParent && !expandDisabled) {
|
|
9390
|
+
handleOnExpand();
|
|
9391
|
+
}
|
|
9392
|
+
|
|
9393
|
+
onClick({
|
|
9394
|
+
label,
|
|
9395
|
+
value,
|
|
9396
|
+
checked: getCheckState({
|
|
9397
|
+
toggle: false
|
|
9398
|
+
})
|
|
9399
|
+
});
|
|
9400
|
+
};
|
|
9401
|
+
|
|
9402
|
+
const handleOnExpand = () => {
|
|
9403
|
+
const {
|
|
9404
|
+
onExpand
|
|
9405
|
+
} = props;
|
|
9406
|
+
onExpand({
|
|
9407
|
+
value,
|
|
9408
|
+
label,
|
|
9409
|
+
expanded: !is(expanded)
|
|
9410
|
+
});
|
|
9411
|
+
};
|
|
9412
|
+
|
|
9413
|
+
const getCheckState = ({
|
|
9414
|
+
toggle
|
|
9415
|
+
}) => {
|
|
9416
|
+
const {
|
|
9417
|
+
checkState
|
|
9418
|
+
} = props;
|
|
9419
|
+
|
|
9420
|
+
if (checkState === CheckboxState.UNCHECKED && toggle) {
|
|
9421
|
+
return true;
|
|
9422
|
+
}
|
|
9423
|
+
|
|
9424
|
+
if (checkState === CheckboxState.CHECKED && !toggle) {
|
|
9425
|
+
return true;
|
|
9426
|
+
}
|
|
9427
|
+
|
|
9428
|
+
if (checkState === CheckboxState.INDETERMINATE) {
|
|
9429
|
+
return true;
|
|
9430
|
+
}
|
|
9431
|
+
|
|
9432
|
+
return false;
|
|
9433
|
+
};
|
|
9434
|
+
|
|
9435
|
+
const renderCollapseButton = () => {
|
|
9436
|
+
const {
|
|
9437
|
+
expandDisabled,
|
|
9438
|
+
isParent
|
|
9439
|
+
} = props;
|
|
9440
|
+
return maybeRender(isParent, jsx(CollapseButton, {
|
|
9441
|
+
subtle: true,
|
|
9442
|
+
disabled: expandDisabled,
|
|
9443
|
+
onClick: handleOnExpand,
|
|
9444
|
+
IconSuffix: expanded ? IconMinor.ChevronUpSolid : IconMinor.ChevronDownSolid
|
|
9445
|
+
}));
|
|
9446
|
+
};
|
|
9447
|
+
|
|
9448
|
+
const renderCheckboxLabel = () => {
|
|
9449
|
+
const {
|
|
9450
|
+
checkState,
|
|
9451
|
+
disabled,
|
|
9452
|
+
treeId,
|
|
9453
|
+
childCount,
|
|
9454
|
+
isParent,
|
|
9455
|
+
invalid,
|
|
9456
|
+
showChildCount,
|
|
9457
|
+
helpfulMessage
|
|
9458
|
+
} = props;
|
|
9459
|
+
const inputId = `${treeId}-${String(value).split(' ').join('_')}`;
|
|
9460
|
+
const displayText = showChildCount && isParent ? `${label} (${childCount})` : label;
|
|
9461
|
+
return jsxs(React.Fragment, {
|
|
9462
|
+
children: [jsxs("div", {
|
|
9463
|
+
children: [jsxs(InputWrapper, Object.assign({
|
|
9464
|
+
center: true
|
|
9465
|
+
}, {
|
|
9466
|
+
children: [jsx(Checkbox, {
|
|
9467
|
+
checked: checkState === CheckboxState.CHECKED,
|
|
9468
|
+
indeterminate: checkState === CheckboxState.INDETERMINATE,
|
|
9469
|
+
disabled: disabled,
|
|
9470
|
+
error: invalid,
|
|
9471
|
+
id: `input-${inputId}`,
|
|
9472
|
+
onClick: handleCheck,
|
|
9473
|
+
onChange: () => void 0
|
|
9474
|
+
}), jsx(ClickableLabel, Object.assign({
|
|
9475
|
+
onClick: handleClick,
|
|
9476
|
+
role: "link",
|
|
9477
|
+
tabIndex: 0
|
|
9478
|
+
}, {
|
|
9479
|
+
children: displayText
|
|
9480
|
+
}), 1)]
|
|
9481
|
+
})), maybeRender(helpfulMessage, jsx(HelpfulMessage$1, Object.assign({
|
|
9482
|
+
subdued: true,
|
|
9483
|
+
id: `error-${inputId}`
|
|
9484
|
+
}, {
|
|
9485
|
+
children: helpfulMessage
|
|
9486
|
+
})))]
|
|
9487
|
+
}), renderCollapseButton()]
|
|
9488
|
+
});
|
|
9489
|
+
};
|
|
9490
|
+
|
|
9491
|
+
const {
|
|
9492
|
+
disabled
|
|
9493
|
+
} = props;
|
|
9494
|
+
return jsxs(ListItem, Object.assign({
|
|
9495
|
+
role: "treeitem",
|
|
9496
|
+
disabled: disabled
|
|
9497
|
+
}, {
|
|
9498
|
+
children: [jsx(ItemWrapper, Object.assign({
|
|
9499
|
+
center: true
|
|
9500
|
+
}, {
|
|
9501
|
+
children: renderCheckboxLabel()
|
|
9502
|
+
})), expanded && props.children]
|
|
9503
|
+
}));
|
|
9504
|
+
};
|
|
9505
|
+
|
|
9506
|
+
const flattenNodes = (flattenList, nodes, parent, depth = 0) => {
|
|
9507
|
+
safeArray(nodes).forEach((node, index) => {
|
|
9508
|
+
const isParent = nodeHasChildren(node);
|
|
9509
|
+
flattenList.push({
|
|
9510
|
+
label: node.label,
|
|
9511
|
+
value: node.value,
|
|
9512
|
+
children: node.children,
|
|
9513
|
+
parent,
|
|
9514
|
+
isChild: isDefined(parent) && isDefined(parent.value),
|
|
9515
|
+
isParent,
|
|
9516
|
+
isLeaf: !isParent,
|
|
9517
|
+
disabled: getDisabledState(node, parent),
|
|
9518
|
+
treeDepth: depth,
|
|
9519
|
+
index,
|
|
9520
|
+
checked: false,
|
|
9521
|
+
checkState: 0,
|
|
9522
|
+
expanded: false
|
|
9523
|
+
});
|
|
9524
|
+
flattenNodes(flattenList, safeArray(node.children), node, depth + 1);
|
|
9525
|
+
});
|
|
9526
|
+
};
|
|
9527
|
+
const getNode = (nodes, value) => {
|
|
9528
|
+
return nodes.find(node => node.value === value);
|
|
9529
|
+
};
|
|
9530
|
+
|
|
9531
|
+
const nodeHasChildren = node => {
|
|
9532
|
+
return isDefined(node.children) && Array.isArray(node.children);
|
|
9533
|
+
};
|
|
9534
|
+
|
|
9535
|
+
const getDisabledState = (node, parent) => {
|
|
9536
|
+
if (isDefined(parent) && is(parent.disabled)) {
|
|
9537
|
+
return true;
|
|
9538
|
+
}
|
|
9539
|
+
|
|
9540
|
+
return is(node.disabled);
|
|
9541
|
+
};
|
|
9542
|
+
|
|
9543
|
+
const deserializeList = (flatNodes, lists) => {
|
|
9544
|
+
flatNodes.forEach(flatNode => {
|
|
9545
|
+
if (lists.checked.includes(flatNode.value)) {
|
|
9546
|
+
flatNode.checked = true;
|
|
9547
|
+
|
|
9548
|
+
if (flatNode.isParent) {
|
|
9549
|
+
checkAllChildren(flatNodes, flatNode);
|
|
9550
|
+
}
|
|
9551
|
+
}
|
|
9552
|
+
|
|
9553
|
+
if (lists.expanded.includes(flatNode.value)) {
|
|
9554
|
+
flatNode.expanded = true;
|
|
9555
|
+
}
|
|
9556
|
+
});
|
|
9557
|
+
};
|
|
9558
|
+
|
|
9559
|
+
const checkAllChildren = (flatNodes, flatNode) => {
|
|
9560
|
+
defaultTo(flatNode.children, []).forEach(node => {
|
|
9561
|
+
const _flatoNode = getNode(flatNodes, node.value);
|
|
9562
|
+
|
|
9563
|
+
if (isDefined(_flatoNode)) {
|
|
9564
|
+
_flatoNode.checked = true;
|
|
9565
|
+
}
|
|
9566
|
+
});
|
|
9567
|
+
};
|
|
9568
|
+
|
|
9569
|
+
const serializeList = (flatNodes, key) => {
|
|
9570
|
+
const list = [];
|
|
9571
|
+
flatNodes.forEach(node => {
|
|
9572
|
+
if (key === 'expanded') {
|
|
9573
|
+
if (node.expanded) {
|
|
9574
|
+
list.push(node.value);
|
|
9575
|
+
}
|
|
9576
|
+
}
|
|
9577
|
+
|
|
9578
|
+
if (key === 'checked') {
|
|
9579
|
+
if (node.checked) {
|
|
9580
|
+
list.push(node.value);
|
|
9581
|
+
}
|
|
9582
|
+
}
|
|
9583
|
+
});
|
|
9584
|
+
return list;
|
|
9585
|
+
};
|
|
9586
|
+
const toggleChecked = (flatNodes, node, isChecked) => {
|
|
9587
|
+
const flatNode = getNode(flatNodes, node.value);
|
|
9588
|
+
|
|
9589
|
+
if (isNil(flatNode)) {
|
|
9590
|
+
return;
|
|
9591
|
+
}
|
|
9592
|
+
|
|
9593
|
+
if (flatNode.isLeaf) {
|
|
9594
|
+
if (is(node.disabled)) {
|
|
9595
|
+
return;
|
|
9596
|
+
}
|
|
9597
|
+
|
|
9598
|
+
toggleNode(flatNodes, node.value, 'checked', isChecked);
|
|
9599
|
+
} else {
|
|
9600
|
+
if (isDefined(flatNode.children) && flatNode.children.length === 0) {
|
|
9601
|
+
toggleNode(flatNodes, node.value, 'checked', isChecked);
|
|
9602
|
+
}
|
|
9603
|
+
|
|
9604
|
+
safeArray(flatNode.children).forEach(child => {
|
|
9605
|
+
toggleChecked(flatNodes, child, isChecked);
|
|
9606
|
+
});
|
|
9607
|
+
}
|
|
9608
|
+
};
|
|
9609
|
+
const toggleNode = (flatNodes, nodeValue, key, toggleValue) => {
|
|
9610
|
+
const node = flatNodes.find(_node => _node.value === nodeValue);
|
|
9611
|
+
|
|
9612
|
+
if (isDefined(node)) {
|
|
9613
|
+
key === 'checked' ? node.checked = toggleValue : node.expanded = toggleValue;
|
|
9614
|
+
}
|
|
9615
|
+
};
|
|
9616
|
+
const getNodeCheckState = (flattenNodeList, node) => {
|
|
9617
|
+
const flatNode = getNode(flattenNodeList, node.value);
|
|
9618
|
+
|
|
9619
|
+
if (is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isLeaf) || isDefined(node.children) && node.children.length === 0) {
|
|
9620
|
+
return is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.checked) ? CheckboxState.CHECKED : CheckboxState.UNCHECKED;
|
|
9621
|
+
}
|
|
9622
|
+
|
|
9623
|
+
if (is(isEveryChildChecked(flattenNodeList, node))) {
|
|
9624
|
+
return CheckboxState.CHECKED;
|
|
9625
|
+
}
|
|
9626
|
+
|
|
9627
|
+
if (is(isSomeChildChecked(flattenNodeList, node))) {
|
|
9628
|
+
return CheckboxState.INDETERMINATE;
|
|
9629
|
+
}
|
|
9630
|
+
|
|
9631
|
+
return CheckboxState.UNCHECKED;
|
|
9632
|
+
};
|
|
9633
|
+
|
|
9634
|
+
const isEveryChildChecked = (flattenNodeList, node) => {
|
|
9635
|
+
return safeArray(node.children).every(child => {
|
|
9636
|
+
const _node = getNode(flattenNodeList, child.value);
|
|
9637
|
+
|
|
9638
|
+
return isDefined(_node) && _node.checkState === 1;
|
|
9639
|
+
});
|
|
9640
|
+
};
|
|
9641
|
+
|
|
9642
|
+
const isSomeChildChecked = (flattenNodeList, node) => {
|
|
9643
|
+
return safeArray(node.children).some(child => {
|
|
9644
|
+
const _node = getNode(flattenNodeList, child.value);
|
|
9645
|
+
|
|
9646
|
+
return isDefined(_node) && _node.checkState > 0;
|
|
9647
|
+
});
|
|
9648
|
+
};
|
|
9649
|
+
|
|
9650
|
+
const ParentNode = /*#__PURE__*/styled.ol.withConfig({
|
|
9651
|
+
displayName: "tree-view__ParentNode",
|
|
9652
|
+
componentId: "sc-4bkb59-0"
|
|
9653
|
+
})(["display:flex;flex-direction:column;gap:8px;margin:", ";padding-left:", ";list-style-type:none;& ol{padding-left:", ";}"], Margin.none, Padding.none, Padding.l);
|
|
9654
|
+
const Container$1 = /*#__PURE__*/styled.div.withConfig({
|
|
9655
|
+
displayName: "tree-view__Container",
|
|
9656
|
+
componentId: "sc-4bkb59-1"
|
|
9657
|
+
})(["display:block;margin:", ";padding:", ";"], Margin.none, Padding.none);
|
|
9658
|
+
const TreeView = props => {
|
|
9659
|
+
const {
|
|
9660
|
+
checkedList = [],
|
|
9661
|
+
expanded = [],
|
|
9662
|
+
title,
|
|
9663
|
+
nodes,
|
|
9664
|
+
className,
|
|
9665
|
+
showChildCount = false
|
|
9666
|
+
} = props;
|
|
9667
|
+
const [expandedList, setExpandedList] = useState(expanded);
|
|
9668
|
+
const treeId = new Date().getTime().toString();
|
|
9669
|
+
const flattenNodeList = useMemo(() => {
|
|
9670
|
+
const _nodeList = [];
|
|
9671
|
+
flattenNodes(_nodeList, nodes);
|
|
9672
|
+
deserializeList(_nodeList, {
|
|
9673
|
+
checked: checkedList,
|
|
9674
|
+
expanded: expandedList
|
|
9675
|
+
});
|
|
9676
|
+
return _nodeList;
|
|
9677
|
+
}, [nodes]);
|
|
9678
|
+
|
|
9679
|
+
const handleOnCheck = nodeInfo => {
|
|
9680
|
+
const {
|
|
9681
|
+
onCheck
|
|
9682
|
+
} = props;
|
|
9683
|
+
toggleChecked(flattenNodeList, nodeInfo, nodeInfo.checked);
|
|
9684
|
+
|
|
9685
|
+
if (isDefined(onCheck)) {
|
|
9686
|
+
onCheck(serializeList(flattenNodeList, 'checked'), Object.assign({}, nodeInfo));
|
|
9687
|
+
}
|
|
9688
|
+
};
|
|
9689
|
+
|
|
9690
|
+
const handleOnExpand = nodeInfo => {
|
|
9691
|
+
const {
|
|
9692
|
+
onExpand
|
|
9693
|
+
} = props;
|
|
9694
|
+
toggleNode(flattenNodeList, nodeInfo.value, 'expanded', nodeInfo.expanded);
|
|
9695
|
+
|
|
9696
|
+
if (isDefined(onExpand)) {
|
|
9697
|
+
onExpand(serializeList(flattenNodeList, 'expanded'), Object.assign({}, nodeInfo));
|
|
9698
|
+
}
|
|
9699
|
+
|
|
9700
|
+
setExpandedList(serializeList(flattenNodeList, 'expanded'));
|
|
9701
|
+
};
|
|
9702
|
+
|
|
9703
|
+
const onNodeClick = nodeInfo => {
|
|
9704
|
+
const {
|
|
9705
|
+
onClick
|
|
9706
|
+
} = props;
|
|
9707
|
+
const node = getNode(flattenNodeList, nodeInfo.value);
|
|
9708
|
+
|
|
9709
|
+
if (isDefined(onClick)) {
|
|
9710
|
+
onClick(Object.assign(Object.assign({}, node), nodeInfo));
|
|
9711
|
+
}
|
|
9712
|
+
};
|
|
9713
|
+
|
|
9714
|
+
const renderTreeNodes = (nodeList, parent) => {
|
|
9715
|
+
const {
|
|
9716
|
+
expandDisabled = false
|
|
9717
|
+
} = props;
|
|
9718
|
+
const treeNodes = nodeList.map(node => {
|
|
9719
|
+
var _a, _b;
|
|
9720
|
+
|
|
9721
|
+
const flatNode = getNode(flattenNodeList, node.value);
|
|
9722
|
+
const children = is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isParent) ? renderTreeNodes(defaultTo(node.children, []), node) : jsx(Nothing, {}, node.value);
|
|
9723
|
+
|
|
9724
|
+
if (isDefined(flatNode)) {
|
|
9725
|
+
flatNode.checkState = getNodeCheckState(flattenNodeList, node);
|
|
9726
|
+
}
|
|
9727
|
+
|
|
9728
|
+
const parentExpanded = isDefined(parent) && isDefined(parent.value) ? (_a = getNode(flattenNodeList, parent.value)) === null || _a === void 0 ? void 0 : _a.expanded : true;
|
|
9729
|
+
|
|
9730
|
+
if (!is(parentExpanded)) {
|
|
9731
|
+
return jsx(Nothing, {}, node.value);
|
|
9732
|
+
}
|
|
9733
|
+
|
|
9734
|
+
return jsx(TreeNode, Object.assign({
|
|
9735
|
+
checkState: defaultTo(flatNode === null || flatNode === void 0 ? void 0 : flatNode.checkState, 0),
|
|
9736
|
+
disabled: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.disabled),
|
|
9737
|
+
expandDisabled: expandDisabled,
|
|
9738
|
+
expanded: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.expanded),
|
|
9739
|
+
label: node.label,
|
|
9740
|
+
isLeaf: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isLeaf),
|
|
9741
|
+
isParent: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isParent),
|
|
9742
|
+
treeId: treeId,
|
|
9743
|
+
invalid: defaultTo(node.invalid, false),
|
|
9744
|
+
value: node.value,
|
|
9745
|
+
showChildCount: showChildCount,
|
|
9746
|
+
childCount: defaultTo((_b = flatNode === null || flatNode === void 0 ? void 0 : flatNode.children) === null || _b === void 0 ? void 0 : _b.length, 0),
|
|
9747
|
+
helpfulMessage: node.helpfulMessage,
|
|
9748
|
+
onClick: onNodeClick,
|
|
9749
|
+
onCheck: handleOnCheck,
|
|
9750
|
+
onExpand: handleOnExpand
|
|
9751
|
+
}, {
|
|
9752
|
+
children: children
|
|
9753
|
+
}), node.value);
|
|
9754
|
+
});
|
|
9755
|
+
return jsx(ParentNode, Object.assign({
|
|
9756
|
+
role: "tree",
|
|
9757
|
+
className: 'tree-view'
|
|
9758
|
+
}, {
|
|
9759
|
+
children: treeNodes
|
|
9760
|
+
}));
|
|
9761
|
+
};
|
|
9762
|
+
|
|
9763
|
+
return maybeRender(!isEmpty(nodes), jsx(Card, Object.assign({
|
|
9764
|
+
heading: title
|
|
9765
|
+
}, {
|
|
9766
|
+
children: jsx(Card.Section, {
|
|
9767
|
+
children: jsx(Container$1, Object.assign({
|
|
9768
|
+
className: className,
|
|
9769
|
+
id: treeId
|
|
9770
|
+
}, {
|
|
9771
|
+
children: renderTreeNodes(nodes)
|
|
9772
|
+
}))
|
|
9773
|
+
})
|
|
9774
|
+
})));
|
|
9775
|
+
};
|
|
9776
|
+
|
|
9322
9777
|
// this file was generated, but it is safe to modify
|
|
9323
9778
|
|
|
9324
9779
|
function toAvatarSize(n) {
|
|
@@ -9453,7 +9908,6 @@ const Wrapper = /*#__PURE__*/styled.label.withConfig({
|
|
|
9453
9908
|
})(["display:flex;width:100%;align-items:center;"]);
|
|
9454
9909
|
const InputCheckbox = props => {
|
|
9455
9910
|
const {
|
|
9456
|
-
onChange,
|
|
9457
9911
|
label = ''
|
|
9458
9912
|
} = props;
|
|
9459
9913
|
|
|
@@ -9463,11 +9917,6 @@ const InputCheckbox = props => {
|
|
|
9463
9917
|
|
|
9464
9918
|
return jsxs(Wrapper, {
|
|
9465
9919
|
children: [jsx(Checkbox, Object.assign({}, props, {
|
|
9466
|
-
onChange: e => {
|
|
9467
|
-
if (isDefined(onChange)) {
|
|
9468
|
-
onChange(e.target.checked);
|
|
9469
|
-
}
|
|
9470
|
-
},
|
|
9471
9920
|
name: isDefined(props.name) ? props.name : label
|
|
9472
9921
|
})), jsx(Text, {
|
|
9473
9922
|
children: label
|
|
@@ -9508,4 +9957,4 @@ const MultiChoiceList = props => {
|
|
|
9508
9957
|
}));
|
|
9509
9958
|
};
|
|
9510
9959
|
|
|
9511
|
-
export { Actions, AlertBanner, Avatar, BODY, BODY_LARGE, Background, Badge, Body, BodyLarge, Borders, Button, CAPTION, Caption, Card, Center, Checkbox, Display, Divider, Flag, Flex, Focused, HTMLAnchor, HTMLInput, Heading1, Heading2, Heading3, Heading4, Icon, IconMinor, Icons, InputCheckbox, InputField, InputNumber, InputText, Interactive, LABEL, Label, LeftRightCard, Link, Margin, MenuList, MultiChoiceList, Padding, Select, SpaceAround, SpaceBetween, Spinner, Surface, Tab$1 as Tab, Tabs, Tag, Text$1 as Text, Thumbnail, Typography, _Typography, gridLayoutGenerator, leftRightLayoutGenerator, shadow, shadow2Xl, shadowInner, shadowLg, shadowMd, shadowSm, shadowXl };
|
|
9960
|
+
export { Actions, AlertBanner, Avatar, BODY, BODY_LARGE, Background, Badge, Body, BodyLarge, Borders, Button, CAPTION, Caption, Card, Center, Checkbox, Display, Divider, Flag, Flex, Focused, HTMLAnchor, HTMLInput, Heading1, Heading2, Heading3, Heading4, Icon, IconMinor, Icons, InputCheckbox, InputField, InputNumber, InputText, Interactive, LABEL, Label, LeftRightCard, Link, Margin, MenuList, MultiChoiceList, Padding, Select, SpaceAround, SpaceBetween, Spinner, Surface, Tab$1 as Tab, Tabs, Tag, Text$1 as Text, Thumbnail, TreeView, Typography, _Typography, gridLayoutGenerator, leftRightLayoutGenerator, shadow, shadow2Xl, shadowInner, shadowLg, shadowMd, shadowSm, shadowXl };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const getHoverStyles: () => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
1
|
+
export declare const getHoverStyles: (indeterminate: boolean) => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
2
2
|
checked?: boolean | undefined;
|
|
3
3
|
}, any>>;
|
|
4
|
-
export declare const getDisabledStyles: () => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
4
|
+
export declare const getDisabledStyles: (indeterminate: boolean) => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
5
5
|
checked?: boolean | undefined;
|
|
6
6
|
}, any>>;
|
|
7
|
-
export declare const getDefaultStyles: () => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
7
|
+
export declare const getDefaultStyles: (indeterminate: boolean) => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
8
8
|
checked?: boolean | undefined;
|
|
9
9
|
}, any>>;
|
|
10
|
-
export declare const getInvalidStyles: () => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
10
|
+
export declare const getInvalidStyles: (indeterminate: boolean) => import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
|
|
11
11
|
checked?: boolean | undefined;
|
|
12
12
|
}, any>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { INode, IFlattenNode, CheckboxState } from './types';
|
|
2
|
+
export declare const flattenNodes: (flattenList: IFlattenNode[], nodes: INode[], parent?: INode, depth?: number) => void;
|
|
3
|
+
export declare const getNode: (nodes: IFlattenNode[], value: string) => IFlattenNode | undefined;
|
|
4
|
+
export declare const deserializeList: (flatNodes: IFlattenNode[], lists: {
|
|
5
|
+
checked: string[];
|
|
6
|
+
expanded: string[];
|
|
7
|
+
}) => void;
|
|
8
|
+
export declare const serializeList: (flatNodes: IFlattenNode[], key: string) => string[];
|
|
9
|
+
export declare const expandAllNodes: (flatNodes: IFlattenNode[], expand: boolean) => void;
|
|
10
|
+
export declare const toggleChecked: (flatNodes: IFlattenNode[], node: INode, isChecked: boolean) => void;
|
|
11
|
+
export declare const toggleNode: (flatNodes: IFlattenNode[], nodeValue: string, key: string, toggleValue: boolean) => void;
|
|
12
|
+
export declare const getNodeCheckState: (flattenNodeList: IFlattenNode[], node: INode) => CheckboxState;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface INode {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
helpfulMessage?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
invalid?: boolean;
|
|
8
|
+
children?: INode[];
|
|
9
|
+
}
|
|
10
|
+
export interface IFlattenNode extends INode {
|
|
11
|
+
parent?: INode;
|
|
12
|
+
isChild: boolean;
|
|
13
|
+
isParent: boolean;
|
|
14
|
+
isLeaf: boolean;
|
|
15
|
+
treeDepth: number;
|
|
16
|
+
index: number;
|
|
17
|
+
checked: boolean;
|
|
18
|
+
checkState: number;
|
|
19
|
+
expanded: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ITreeViewProps {
|
|
22
|
+
checkedList: string[];
|
|
23
|
+
nodes: INode[];
|
|
24
|
+
expanded?: string[];
|
|
25
|
+
className?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
showChildCount?: boolean;
|
|
28
|
+
expandDisabled?: boolean;
|
|
29
|
+
onCheck: (checked: string[], node?: ICheckNode) => void;
|
|
30
|
+
onClick?: (node: ICheckNode) => void;
|
|
31
|
+
onExpand?: (expanded: string[], node?: IExpandNode) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface ITreeNode {
|
|
34
|
+
checkState: number;
|
|
35
|
+
disabled: boolean;
|
|
36
|
+
expanded: boolean;
|
|
37
|
+
isParent: boolean;
|
|
38
|
+
isLeaf: boolean;
|
|
39
|
+
expandDisabled: boolean;
|
|
40
|
+
label: string;
|
|
41
|
+
value: string;
|
|
42
|
+
children: ReactNode;
|
|
43
|
+
treeId: string;
|
|
44
|
+
invalid: boolean;
|
|
45
|
+
childCount: number;
|
|
46
|
+
showChildCount: boolean;
|
|
47
|
+
helpfulMessage?: string;
|
|
48
|
+
onCheck: (node: ICheckNode) => void;
|
|
49
|
+
onClick: (node: ICheckNode) => void;
|
|
50
|
+
onExpand: (node: IExpandNode) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface ICheckNode extends INode {
|
|
53
|
+
checked: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface IExpandNode extends INode {
|
|
56
|
+
expanded: boolean;
|
|
57
|
+
}
|
|
58
|
+
export declare enum CheckboxState {
|
|
59
|
+
UNCHECKED = 0,
|
|
60
|
+
CHECKED = 1,
|
|
61
|
+
INDETERMINATE = 2
|
|
62
|
+
}
|