@edvisor/product-language 0.4.3 → 0.5.1

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 CHANGED
@@ -4531,20 +4531,18 @@ const LeftRightCard = props => {
4531
4531
  LeftRightCard.Right = Right;
4532
4532
  LeftRightCard.Controls = Controls$1;
4533
4533
 
4534
- const WIDTH = 12;
4535
- const HEIGHT = 10;
4536
- /** no magic here, just copy/pasted the svg from the mockup
4537
- * I had to tweak the width and height though
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,", "\");top:3px;left:3px;}"], svg);
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 = () => css(["background:", ";", ""], Surface.Default.Hover, getCheckedStyles(Interactive.Default.Hover));
4569
- const getDisabledStyles = () => css(["pointer-events:none;background:", ";border:2px solid ", ";", ""], props => props.checked === true ? `${Borders.Default.Default}` : `${Surface.Default.Subdued}`, Borders.Default.Default, getCheckedStyles(Icons.Disabled));
4570
- const getDefaultStyles = () => css(["background:", ";border:2px solid ", ";", ":hover{", "}"], Surface.Default.Default, Interactive.Default.Disabled, getCheckedStyles(Interactive.Default.Default), getHoverStyles);
4571
- const getInvalidStyles = () => css(["background:", ";border:2px solid ", ";", ""], props => props.checked === true ? `${Actions.Critical.Default}` : `${Surface.Critical.Subdued}`, Borders.Critical.Default, getCheckedStyles(Icons.Critical));
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 = false
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,469 @@ 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) && !isEmpty(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, ({
9658
+ useCardContainer
9659
+ }) => useCardContainer ? Padding.none : Padding.xs);
9660
+ const TreeView = props => {
9661
+ const {
9662
+ checkedList = [],
9663
+ expanded = [],
9664
+ title,
9665
+ nodes,
9666
+ className,
9667
+ showChildCount = false,
9668
+ useCardContainer = true
9669
+ } = props;
9670
+ const [expandedList, setExpandedList] = useState(expanded);
9671
+ const treeId = new Date().getTime().toString();
9672
+ const flattenNodeList = useMemo(() => {
9673
+ const _nodeList = [];
9674
+ flattenNodes(_nodeList, nodes);
9675
+ deserializeList(_nodeList, {
9676
+ checked: checkedList,
9677
+ expanded: expandedList
9678
+ });
9679
+ return _nodeList;
9680
+ }, [nodes]);
9681
+
9682
+ const handleOnCheck = nodeInfo => {
9683
+ const {
9684
+ onCheck
9685
+ } = props;
9686
+ toggleChecked(flattenNodeList, nodeInfo, nodeInfo.checked);
9687
+
9688
+ if (isDefined(onCheck)) {
9689
+ onCheck(serializeList(flattenNodeList, 'checked'), Object.assign({}, nodeInfo));
9690
+ }
9691
+ };
9692
+
9693
+ const handleOnExpand = nodeInfo => {
9694
+ const {
9695
+ onExpand
9696
+ } = props;
9697
+ toggleNode(flattenNodeList, nodeInfo.value, 'expanded', nodeInfo.expanded);
9698
+
9699
+ if (isDefined(onExpand)) {
9700
+ onExpand(serializeList(flattenNodeList, 'expanded'), Object.assign({}, nodeInfo));
9701
+ }
9702
+
9703
+ setExpandedList(serializeList(flattenNodeList, 'expanded'));
9704
+ };
9705
+
9706
+ const onNodeClick = nodeInfo => {
9707
+ const {
9708
+ onClick
9709
+ } = props;
9710
+ const node = getNode(flattenNodeList, nodeInfo.value);
9711
+
9712
+ if (isDefined(onClick)) {
9713
+ onClick(Object.assign(Object.assign({}, node), nodeInfo));
9714
+ }
9715
+ };
9716
+
9717
+ const renderTreeNodes = (nodeList, parent) => {
9718
+ const {
9719
+ expandDisabled = false
9720
+ } = props;
9721
+ const treeNodes = nodeList.map(node => {
9722
+ var _a, _b;
9723
+
9724
+ const flatNode = getNode(flattenNodeList, node.value);
9725
+ const children = is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isParent) ? renderTreeNodes(defaultTo(node.children, []), node) : jsx(Nothing, {}, node.value);
9726
+
9727
+ if (isDefined(flatNode)) {
9728
+ flatNode.checkState = getNodeCheckState(flattenNodeList, node);
9729
+ }
9730
+
9731
+ const parentExpanded = isDefined(parent) && isDefined(parent.value) ? (_a = getNode(flattenNodeList, parent.value)) === null || _a === void 0 ? void 0 : _a.expanded : true;
9732
+
9733
+ if (!is(parentExpanded)) {
9734
+ return jsx(Nothing, {}, node.value);
9735
+ }
9736
+
9737
+ return jsx(TreeNode, Object.assign({
9738
+ checkState: defaultTo(flatNode === null || flatNode === void 0 ? void 0 : flatNode.checkState, 0),
9739
+ disabled: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.disabled),
9740
+ expandDisabled: expandDisabled,
9741
+ expanded: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.expanded),
9742
+ label: node.label,
9743
+ isLeaf: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isLeaf),
9744
+ isParent: is(flatNode === null || flatNode === void 0 ? void 0 : flatNode.isParent),
9745
+ treeId: treeId,
9746
+ invalid: defaultTo(node.invalid, false),
9747
+ value: node.value,
9748
+ showChildCount: showChildCount,
9749
+ childCount: defaultTo((_b = flatNode === null || flatNode === void 0 ? void 0 : flatNode.children) === null || _b === void 0 ? void 0 : _b.length, 0),
9750
+ helpfulMessage: node.helpfulMessage,
9751
+ onClick: onNodeClick,
9752
+ onCheck: handleOnCheck,
9753
+ onExpand: handleOnExpand
9754
+ }, {
9755
+ children: children
9756
+ }), node.value);
9757
+ });
9758
+ return jsx(ParentNode, Object.assign({
9759
+ role: "tree",
9760
+ className: 'tree-view'
9761
+ }, {
9762
+ children: treeNodes
9763
+ }));
9764
+ };
9765
+
9766
+ const renderTree = () => {
9767
+ return useCardContainer ? jsx(Card, Object.assign({
9768
+ heading: title
9769
+ }, {
9770
+ children: jsx(Card.Section, {
9771
+ children: jsx(Container$1, Object.assign({
9772
+ className: className,
9773
+ id: treeId,
9774
+ useCardContainer: true
9775
+ }, {
9776
+ children: renderTreeNodes(nodes)
9777
+ }))
9778
+ })
9779
+ })) : jsx(Container$1, Object.assign({
9780
+ className: className,
9781
+ id: treeId,
9782
+ useCardContainer: false
9783
+ }, {
9784
+ children: renderTreeNodes(nodes)
9785
+ }));
9786
+ };
9787
+
9788
+ return maybeRender(!isEmpty(nodes), renderTree());
9789
+ };
9790
+
9322
9791
  // this file was generated, but it is safe to modify
9323
9792
 
9324
9793
  function toAvatarSize(n) {
@@ -9453,8 +9922,8 @@ const Wrapper = /*#__PURE__*/styled.label.withConfig({
9453
9922
  })(["display:flex;width:100%;align-items:center;"]);
9454
9923
  const InputCheckbox = props => {
9455
9924
  const {
9456
- onChange,
9457
- label = ''
9925
+ label = '',
9926
+ onChange
9458
9927
  } = props;
9459
9928
 
9460
9929
  if (isEmpty(label)) {
@@ -9463,12 +9932,12 @@ const InputCheckbox = props => {
9463
9932
 
9464
9933
  return jsxs(Wrapper, {
9465
9934
  children: [jsx(Checkbox, Object.assign({}, props, {
9935
+ name: isDefined(props.name) ? props.name : label,
9466
9936
  onChange: e => {
9467
9937
  if (isDefined(onChange)) {
9468
9938
  onChange(e.target.checked);
9469
9939
  }
9470
- },
9471
- name: isDefined(props.name) ? props.name : label
9940
+ }
9472
9941
  })), jsx(Text, {
9473
9942
  children: label
9474
9943
  })]
@@ -9508,4 +9977,4 @@ const MultiChoiceList = props => {
9508
9977
  }));
9509
9978
  };
9510
9979
 
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 };
9980
+ 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 };
@@ -3,6 +3,7 @@ import { FC } from '@helpers';
3
3
  export interface ICheckboxProps {
4
4
  disabled?: boolean;
5
5
  checked?: boolean;
6
+ indeterminate?: boolean;
6
7
  error?: boolean;
7
8
  className?: string;
8
9
  }
@@ -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>>;
@@ -14,5 +14,6 @@ export * from './icon';
14
14
  export * from './flag';
15
15
  export * from './spinner';
16
16
  export * from './select';
17
+ export * from './tree-view';
17
18
  export * from './molecules';
18
19
  export * from './organisms';
@@ -1,2 +1,3 @@
1
1
  export * from './select';
2
2
  export * from './components/menu-list';
3
+ export { IOption } from './types';
@@ -0,0 +1,3 @@
1
+ import { FC, PropsWithChildren } from '@helpers';
2
+ import { ITreeNode } from '../types';
3
+ export declare const TreeNode: FC<PropsWithChildren<ITreeNode>>;
@@ -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,2 @@
1
+ export * from './tree-view';
2
+ export { INode, ICheckNode, IExpandNode } from './types';
@@ -0,0 +1,3 @@
1
+ import { FC, PropsWithChildren } from '@helpers';
2
+ import { ITreeViewProps } from './types';
3
+ export declare const TreeView: FC<PropsWithChildren<ITreeViewProps>>;
@@ -0,0 +1,63 @@
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
+ useCardContainer?: boolean;
28
+ showChildCount?: boolean;
29
+ expandDisabled?: boolean;
30
+ onCheck: (checked: string[], node?: ICheckNode) => void;
31
+ onClick?: (node: ICheckNode) => void;
32
+ onExpand?: (expanded: string[], node?: IExpandNode) => void;
33
+ }
34
+ export interface ITreeNode {
35
+ checkState: number;
36
+ disabled: boolean;
37
+ expanded: boolean;
38
+ isParent: boolean;
39
+ isLeaf: boolean;
40
+ expandDisabled: boolean;
41
+ label: string;
42
+ value: string;
43
+ children: ReactNode;
44
+ treeId: string;
45
+ invalid: boolean;
46
+ childCount: number;
47
+ showChildCount: boolean;
48
+ helpfulMessage?: string;
49
+ onCheck: (node: ICheckNode) => void;
50
+ onClick: (node: ICheckNode) => void;
51
+ onExpand: (node: IExpandNode) => void;
52
+ }
53
+ export interface ICheckNode extends INode {
54
+ checked: boolean;
55
+ }
56
+ export interface IExpandNode extends INode {
57
+ expanded: boolean;
58
+ }
59
+ export declare enum CheckboxState {
60
+ UNCHECKED = 0,
61
+ CHECKED = 1,
62
+ INDETERMINATE = 2
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edvisor/product-language",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "description": "Edvisor.io product-language components",
6
6
  "repository": "https://github.com/edvisor-io/front-end/",