@rovula/ui 0.0.48 → 0.0.50

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.
Files changed (33) hide show
  1. package/dist/cjs/bundle.css +9 -3
  2. package/dist/cjs/bundle.js +3 -3
  3. package/dist/cjs/bundle.js.map +1 -1
  4. package/dist/cjs/types/components/Tree/Tree.d.ts +4 -45
  5. package/dist/cjs/types/components/Tree/Tree.stories.d.ts +9 -1
  6. package/dist/cjs/types/components/Tree/TreeItem.d.ts +4 -0
  7. package/dist/cjs/types/components/Tree/index.d.ts +4 -0
  8. package/dist/cjs/types/components/Tree/type.d.ts +76 -0
  9. package/dist/cjs/types/index.d.ts +1 -0
  10. package/dist/components/Tree/Tree.js +20 -52
  11. package/dist/components/Tree/Tree.stories.js +2210 -8
  12. package/dist/components/Tree/TreeItem.js +81 -0
  13. package/dist/components/Tree/index.js +4 -0
  14. package/dist/components/Tree/type.js +1 -0
  15. package/dist/esm/bundle.css +9 -3
  16. package/dist/esm/bundle.js +1 -1
  17. package/dist/esm/bundle.js.map +1 -1
  18. package/dist/esm/types/components/Tree/Tree.d.ts +4 -45
  19. package/dist/esm/types/components/Tree/Tree.stories.d.ts +9 -1
  20. package/dist/esm/types/components/Tree/TreeItem.d.ts +4 -0
  21. package/dist/esm/types/components/Tree/index.d.ts +4 -0
  22. package/dist/esm/types/components/Tree/type.d.ts +76 -0
  23. package/dist/esm/types/index.d.ts +1 -0
  24. package/dist/index.d.ts +82 -2
  25. package/dist/index.js +1 -0
  26. package/dist/src/theme/global.css +12 -4
  27. package/package.json +1 -1
  28. package/src/components/Tree/Tree.stories.tsx +2397 -8
  29. package/src/components/Tree/Tree.tsx +52 -188
  30. package/src/components/Tree/TreeItem.tsx +232 -0
  31. package/src/components/Tree/index.ts +5 -0
  32. package/src/components/Tree/type.ts +90 -0
  33. package/src/index.ts +1 -0
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ActionButton, Checkbox, Loading } from "@/index";
3
+ import { cn } from "@/utils/cn";
4
+ import { useCallback, useEffect, useMemo } from "react";
5
+ import Icon from "../Icon/Icon";
6
+ const TreeItem = ({ id, title, classes, children, isFirstLevel = false, disabled, icon, showIcon, showExpandButton, enableSeparatorLine = true, isLastItem, checkIsExpanded, checkIsChecked, checkIsLoading, onExpandChange, onCheckedChange, onClickItem, renderIcon, renderElement, renderTitle, renderRightSection, }) => {
7
+ const isLoading = useMemo(() => checkIsLoading === null || checkIsLoading === void 0 ? void 0 : checkIsLoading(id), [checkIsLoading, id]);
8
+ const isChecked = useMemo(() => checkIsChecked(id), [checkIsChecked, id]);
9
+ const isExpanded = useMemo(() => checkIsExpanded(id), [checkIsExpanded, id]);
10
+ const hasChildren = useMemo(() => !!(children === null || children === void 0 ? void 0 : children.length), [children]);
11
+ const shouldExpandButton = useMemo(() => (showExpandButton !== undefined ? showExpandButton : hasChildren), [hasChildren, showExpandButton]);
12
+ const handleExpandToggle = useCallback(() => {
13
+ onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, !isExpanded);
14
+ }, [id, isExpanded, onExpandChange]);
15
+ // TODO move to props
16
+ const lineSize = 2;
17
+ const horizontalLineWidth = 4;
18
+ const expandButtonSize = 30;
19
+ const spacing = 2;
20
+ const styles = {
21
+ branch: {
22
+ height: isLastItem && !(isExpanded && hasChildren)
23
+ ? `calc(50% + ${lineSize}px)`
24
+ : `calc(100% + ${lineSize}px)`,
25
+ width: lineSize,
26
+ marginTop: -lineSize,
27
+ borderBottomLeftRadius: lineSize / 2,
28
+ },
29
+ horizontalLine: {
30
+ height: lineSize,
31
+ width: lineSize +
32
+ horizontalLineWidth +
33
+ (shouldExpandButton ? 0 : expandButtonSize + spacing),
34
+ marginLeft: -lineSize + 0.1,
35
+ borderBottomLeftRadius: lineSize / 2,
36
+ },
37
+ expandButton: {
38
+ width: expandButtonSize,
39
+ height: expandButtonSize,
40
+ },
41
+ childPadding: {
42
+ paddingLeft: isFirstLevel
43
+ ? expandButtonSize / 2 - lineSize / 2
44
+ : expandButtonSize / 2 + horizontalLineWidth - lineSize / 2,
45
+ },
46
+ };
47
+ useEffect(() => {
48
+ if (isExpanded && !isLoading && !hasChildren) {
49
+ handleExpandToggle();
50
+ }
51
+ }, [isLoading, handleExpandToggle]);
52
+ const handleOnClickItem = useCallback(() => {
53
+ onClickItem === null || onClickItem === void 0 ? void 0 : onClickItem(id);
54
+ }, [onClickItem, id]);
55
+ const defaultIcon = (_jsx(Icon, { name: isExpanded ? "folder-open" : "folder", className: "fill-warning" }));
56
+ const customIcon = icon !== null && icon !== void 0 ? icon : renderIcon === null || renderIcon === void 0 ? void 0 : renderIcon({
57
+ id,
58
+ expanded: isExpanded,
59
+ selected: isChecked,
60
+ });
61
+ const rightIcon = renderRightSection === null || renderRightSection === void 0 ? void 0 : renderRightSection({
62
+ id,
63
+ expanded: isExpanded,
64
+ selected: isChecked,
65
+ });
66
+ const titleContent = renderTitle
67
+ ? renderTitle({ id, title, expanded: isExpanded, selected: isChecked })
68
+ : title;
69
+ const elementWrapper = (content) => renderElement
70
+ ? renderElement({
71
+ id,
72
+ expanded: isExpanded,
73
+ selected: isChecked,
74
+ children: content,
75
+ styles,
76
+ onClick: handleOnClickItem,
77
+ })
78
+ : content;
79
+ return elementWrapper(_jsxs("div", { className: cn("flex flex-row w-full ", classes === null || classes === void 0 ? void 0 : classes.elementWrapper), children: [_jsx("div", { className: cn("bg-grey-150", classes === null || classes === void 0 ? void 0 : classes.branch), style: styles.branch }), _jsxs("div", { className: cn("flex flex-col w-full", classes === null || classes === void 0 ? void 0 : classes.itemWrapper), children: [_jsxs("div", { className: cn("flex items-center py-2 min-h-10", classes === null || classes === void 0 ? void 0 : classes.itemContainer), children: [!isFirstLevel && (_jsx("div", { className: cn("bg-grey-150", classes === null || classes === void 0 ? void 0 : classes.horizontalLine), style: styles.horizontalLine })), isFirstLevel && !shouldExpandButton && (_jsx("div", { className: cn("flex mr-[2px]", classes === null || classes === void 0 ? void 0 : classes.expandButton), style: styles.expandButton })), shouldExpandButton && (_jsx("div", { className: cn("flex mr-[2px]", classes === null || classes === void 0 ? void 0 : classes.expandButton), style: styles.expandButton, onClick: !isLoading && handleExpandToggle, children: _jsx(ActionButton, { variant: "icon", size: "sm", children: isLoading ? (_jsx(Loading, {})) : (_jsx(Icon, { name: isExpanded ? "chevron-down" : "chevron-right" })) }) })), _jsx(Checkbox, { id: id, className: cn("size-[16pt]", classes === null || classes === void 0 ? void 0 : classes.checkbox), checked: isChecked, disabled: disabled, onCheckedChange: (newChecked) => onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(id, newChecked) }), _jsxs("div", { className: cn("ml-2 gap-1 flex flex-1 items-center text-foreground", classes === null || classes === void 0 ? void 0 : classes.item), onClick: handleOnClickItem, children: [showIcon ? customIcon || defaultIcon : null, _jsx("div", { className: cn("flex flex-1 cursor-pointer text-subtitle5 text-ellipsis", classes === null || classes === void 0 ? void 0 : classes.title), children: titleContent })] }), rightIcon] }), isExpanded && hasChildren && (_jsx("div", { className: cn("flex flex-col", classes === null || classes === void 0 ? void 0 : classes.childrenWrapper), style: styles.childPadding, children: children === null || children === void 0 ? void 0 : children.map((child, idx) => (_jsx(TreeItem, Object.assign({ classes: classes, isLastItem: idx === children.length - 1, checkIsExpanded: checkIsExpanded, checkIsChecked: checkIsChecked, checkIsLoading: checkIsLoading, onExpandChange: onExpandChange, onCheckedChange: onCheckedChange, renderIcon: renderIcon, renderElement: renderElement, renderTitle: renderTitle, disabled: disabled, showIcon: showIcon }, child), child.id))) })), enableSeparatorLine && isFirstLevel && !isLastItem && (_jsx("div", { className: cn("bg-grey-150 w-full h-[2px] rounded", classes === null || classes === void 0 ? void 0 : classes.separatorLine) }))] })] }));
80
+ };
81
+ export default TreeItem;
@@ -0,0 +1,4 @@
1
+ import Tree from "./Tree";
2
+ import TreeItem from "./TreeItem";
3
+ export * from "./type";
4
+ export { Tree, TreeItem };
@@ -0,0 +1 @@
1
+ export {};
@@ -796,9 +796,6 @@ input[type=number] {
796
796
  width: 100%;
797
797
  height: 100%;
798
798
  }
799
- .h-1\/2{
800
- height: 50%;
801
- }
802
799
  .h-10{
803
800
  height: 2.5rem;
804
801
  }
@@ -829,6 +826,9 @@ input[type=number] {
829
826
  .h-\[24px\]{
830
827
  height: 24px;
831
828
  }
829
+ .h-\[2px\]{
830
+ height: 2px;
831
+ }
832
832
  .h-\[32px\]{
833
833
  height: 32px;
834
834
  }
@@ -2717,6 +2717,9 @@ input[type=number] {
2717
2717
  .fill-error{
2718
2718
  fill: color-mix(in srgb, var(--state-color-error-default) calc(100% * 1), transparent);
2719
2719
  }
2720
+ .fill-info{
2721
+ fill: color-mix(in srgb, var(--state-color-info-default) calc(100% * 1), transparent);
2722
+ }
2720
2723
  .fill-inherit{
2721
2724
  fill: inherit;
2722
2725
  }
@@ -2735,6 +2738,9 @@ input[type=number] {
2735
2738
  .fill-primary-default{
2736
2739
  fill: color-mix(in srgb, var(--state-color-primary-default) calc(100% * 1), transparent);
2737
2740
  }
2741
+ .fill-secondary{
2742
+ fill: color-mix(in srgb, var(--state-color-secondary-default) calc(100% * 1), transparent);
2743
+ }
2738
2744
  .fill-warning{
2739
2745
  fill: color-mix(in srgb, var(--state-color-warning-default) calc(100% * 1), transparent);
2740
2746
  }