dce-reactkit 3.11.4 → 3.12.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.
@@ -14,6 +14,7 @@ type Props = {
14
14
  */
15
15
  onChanged: (updatedItems: PickableItem[]) => void;
16
16
  noBottomMargin?: boolean;
17
+ hideSelectAllOrNoneButtons?: boolean;
17
18
  };
18
19
  declare const ItemPicker: React.FC<Props>;
19
20
  export default ItemPicker;
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  type Props = {
7
7
  title: React.ReactNode;
8
8
  children: React.ReactNode;
9
+ topRightChildren?: React.ReactNode;
9
10
  noBottomMargin?: boolean;
10
11
  noBottomPadding?: boolean;
11
12
  };
package/dist/esm/index.js CHANGED
@@ -1599,7 +1599,9 @@ const style$7 = `
1599
1599
 
1600
1600
  /* Container for Title */
1601
1601
  .TabBox-title-container {
1602
- /* Place on Left */
1602
+ display: flex;
1603
+ justify-content: space-between;
1604
+ align-items: center;
1603
1605
  position: relative;
1604
1606
  left: 0;
1605
1607
  text-align: left;
@@ -1632,6 +1634,19 @@ const style$7 = `
1632
1634
  background: #fdfdfd;
1633
1635
  }
1634
1636
 
1637
+ .TabBox-title-right-container {
1638
+ display: flex;
1639
+ flex-direction: row;
1640
+ align-items: bottom;
1641
+ height: 2.4rem;
1642
+ overflow: visible;
1643
+ }
1644
+
1645
+ .TabBox-title-right-contents {
1646
+ margin-right: 0.5rem;
1647
+ margin-bottom: 0.2rem;
1648
+ }
1649
+
1635
1650
  /* Make the TabBox's Children Appear Above Title if Overlap Occurs */
1636
1651
  .TabBox-children {
1637
1652
  position: relative;
@@ -1645,19 +1660,16 @@ const TabBox = (props) => {
1645
1660
  /*------------------------------------------------------------------------*/
1646
1661
  /* -------------------------------- Setup ------------------------------- */
1647
1662
  /*------------------------------------------------------------------------*/
1648
- /* -------------- Props ------------- */
1649
- const { title, children, noBottomPadding, noBottomMargin, } = props;
1663
+ const { title, children, topRightChildren, noBottomPadding, noBottomMargin, } = props;
1650
1664
  /*------------------------------------------------------------------------*/
1651
1665
  /* ------------------------------- Render ------------------------------- */
1652
1666
  /*------------------------------------------------------------------------*/
1653
- /*----------------------------------------*/
1654
- /* --------------- Main UI -------------- */
1655
- /*----------------------------------------*/
1656
- // Full UI
1657
1667
  return (React__default.createElement("div", { className: `TabBox-container ${noBottomMargin ? '' : 'mb-2'}` },
1658
1668
  React__default.createElement("style", null, style$7),
1659
1669
  React__default.createElement("div", { className: "TabBox-title-container" },
1660
- React__default.createElement("div", { className: "TabBox-title" }, title)),
1670
+ React__default.createElement("div", { className: "TabBox-title" }, title),
1671
+ topRightChildren && (React__default.createElement("div", { className: "TabBox-title-right-container" },
1672
+ React__default.createElement("div", { className: "TabBox-title-right-contents" }, topRightChildren)))),
1661
1673
  React__default.createElement("div", { className: `TabBox-box ps-2 pt-2 pe-2 ${noBottomPadding ? '' : 'pb-2'}` },
1662
1674
  React__default.createElement("div", { className: "TabBox-children" }, children))));
1663
1675
  };
@@ -2667,17 +2679,62 @@ const ItemPicker = (props) => {
2667
2679
  /*------------------------------------------------------------------------*/
2668
2680
  /* -------------- Props ------------- */
2669
2681
  // Destructure all props
2670
- const { title, items, onChanged, noBottomMargin, } = props;
2682
+ const { title, items, onChanged, noBottomMargin, hideSelectAllOrNoneButtons, } = props;
2671
2683
  /*------------------------------------------------------------------------*/
2672
2684
  /* ------------------------- Component Functions ------------------------ */
2673
2685
  /*------------------------------------------------------------------------*/
2686
+ /**
2687
+ * Updates the checked state of an item (including all children)
2688
+ * @author Yuen Ler Chow
2689
+ * @param item the item to update
2690
+ * @param checked the new checked state
2691
+ * @returns the updated item
2692
+ */
2693
+ const updateItemChecked = (item, checked) => {
2694
+ if (item.isGroup) {
2695
+ return Object.assign(Object.assign({}, item), { children: item.children.map((child) => {
2696
+ return updateItemChecked(child, checked);
2697
+ }) });
2698
+ }
2699
+ return Object.assign(Object.assign({}, item), { checked });
2700
+ };
2701
+ /**
2702
+ * Selects all items in the list
2703
+ * @author Yuen Ler Chow
2704
+ */
2705
+ const handleSelectAll = () => {
2706
+ const updatedItems = items.map((item) => {
2707
+ return updateItemChecked(item, true);
2708
+ });
2709
+ onChanged(updatedItems);
2710
+ };
2711
+ /**
2712
+ * Deselects all items in the list
2713
+ * @author Yuen Ler Chow
2714
+ */
2715
+ const handleDeselectAll = () => {
2716
+ const updatedItems = items.map((item) => {
2717
+ return updateItemChecked(item, false);
2718
+ });
2719
+ onChanged(updatedItems);
2720
+ };
2674
2721
  /*------------------------------------------------------------------------*/
2675
2722
  /* ------------------------------- Render ------------------------------- */
2676
2723
  /*------------------------------------------------------------------------*/
2677
2724
  /*----------------------------------------*/
2678
2725
  /* --------------- Main UI -------------- */
2679
2726
  /*----------------------------------------*/
2680
- return (React__default.createElement(TabBox, { title: title, noBottomMargin: noBottomMargin },
2727
+ // Select all/none
2728
+ const selectAllOrNone = (!hideSelectAllOrNoneButtons
2729
+ ? (React__default.createElement("div", { className: "d-flex h-100 align-items-end flex-row" },
2730
+ React__default.createElement("div", { className: "d-flex justify-content-end" },
2731
+ React__default.createElement("div", { className: "me-2", style: { fontSize: '1.2rem' } }, "Select"),
2732
+ React__default.createElement("div", { className: "btn-group", role: "group" },
2733
+ React__default.createElement("button", { type: "button", style: { borderRight: '0.1rem solid white' }, "aria-label": "Select all contexts", className: "btn btn-secondary py-0", onClick: handleSelectAll }, "All"),
2734
+ React__default.createElement("button", { type: "button", "aria-label": "Deselect all contexts", className: "btn btn-secondary py-0", onClick: handleDeselectAll }, "None")))))
2735
+ : undefined);
2736
+ // Main UI
2737
+ return (React__default.createElement(TabBox, { title: title, noBottomMargin: noBottomMargin, topRightChildren: selectAllOrNone },
2681
2738
  React__default.createElement("div", { style: { overflowX: 'auto' } },
2682
2739
  React__default.createElement(NestableItemList, { items: items, onChanged: onChanged }))));
2683
2740
  };