@nethru/ui 2.1.47 → 2.1.49

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.
@@ -15,27 +15,12 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
15
15
  ...props
16
16
  }, ref) => {
17
17
  const containerRef = useRef(null);
18
- const asideRef = useRef(null);
18
+ const sectionRef = useRef(null);
19
19
  const currentX = useRef();
20
20
  const [resizing, setResizing] = useState(false);
21
+ const [asideWidth, setAsideWidth] = useState(0);
21
22
  const [asidePortion, setAsidePortion] = useState(aside ? defaultAsidePortion : 0);
22
23
  const arrangedMinWidths = useMemo(() => [Math.min(minWidths[0], 703), Math.min(minWidths[1], 346)], [minWidths]);
23
- const resetButtonStyles = useMemo(() => ({
24
- position: 'absolute',
25
- top: `${resetButtonMarginTop}px`,
26
- right: '16px',
27
- zIndex: 'var(--aside-button-zindex)',
28
- transition: 'opacity .5s',
29
- '&': {
30
- backgroundColor: '#dfe0e1'
31
- },
32
- ':hover, &.Mui-focusVisible': {
33
- backgroundColor: '#d9dadb'
34
- },
35
- '&:active': {
36
- backgroundColor: '#c7c8c8'
37
- }
38
- }), [resetButtonMarginTop]);
39
24
  const handleMouseDown = useCallback(event => {
40
25
  event.preventDefault();
41
26
  currentX.current = event.clientX;
@@ -47,13 +32,15 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
47
32
  const handleMouseMove = useCallback(event => {
48
33
  if (!resizing) return;
49
34
  const containerWidth = containerRef.current.clientWidth;
50
- const asideWidth = asideRef.current.clientWidth + currentX.current - event.clientX;
51
- const sectionWidth = containerWidth - asideWidth;
35
+ const sectionWidth = sectionRef.current.clientWidth - (currentX.current - event.clientX);
36
+ const asideWidth = containerWidth - sectionWidth;
52
37
  currentX.current = event.clientX;
53
38
  if (sectionWidth < arrangedMinWidths[0] || asideWidth < arrangedMinWidths[1]) return;
39
+ setAsideWidth(asideWidth);
54
40
  setAsidePortion(asideWidth / containerWidth * 100);
55
41
  }, [resizing, arrangedMinWidths]);
56
42
  const reset = useCallback(event => {
43
+ setAsideWidth(calcAsideWidth(containerRef.current.clientWidth, defaultAsidePortion));
57
44
  setAsidePortion(defaultAsidePortion);
58
45
  }, [defaultAsidePortion]);
59
46
  useEffect(() => {
@@ -71,6 +58,9 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
71
58
  document.removeEventListener('mouseup', handleMouseUp);
72
59
  };
73
60
  }, [resizing, handleMouseMove, handleMouseUp]);
61
+ useEffect(() => {
62
+ setAsideWidth(calcAsideWidth(containerRef.current.clientWidth, defaultAsidePortion));
63
+ }, [containerRef, defaultAsidePortion]);
74
64
  useEffect(() => {
75
65
  if (!aside) setAsidePortion(0);else if (asidePortion === 0) setAsidePortion(defaultAsidePortion);
76
66
  // eslint-disable-next-line
@@ -81,22 +71,20 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
81
71
  columns: 100,
82
72
  columnSpacing: 0,
83
73
  sx: {
84
- ...containerStyles,
74
+ ...styles.container,
85
75
  ...sx
86
76
  },
87
77
  ...props,
88
78
  children: [/*#__PURE__*/_jsxs(Grid2, {
79
+ ref: sectionRef,
89
80
  component: "section",
90
81
  size: 100 - asidePortion,
91
- sx: sectionStyles,
82
+ sx: styles.section,
92
83
  children: [children, footer]
93
84
  }), aside && /*#__PURE__*/_jsxs(Grid2, {
94
- ref: asideRef,
95
85
  component: "aside",
96
86
  size: asidePortion,
97
- sx: {
98
- position: 'relative'
99
- },
87
+ sx: styles.aside.container(asideWidth),
100
88
  children: [/*#__PURE__*/_jsxs(Stack, {
101
89
  direction: "row",
102
90
  sx: {
@@ -104,9 +92,9 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
104
92
  },
105
93
  children: [/*#__PURE__*/_jsx(Box, {
106
94
  onMouseDown: handleMouseDown,
107
- sx: dividerStyles
95
+ sx: styles.divider
108
96
  }), /*#__PURE__*/_jsx(Box, {
109
- sx: asideStyles,
97
+ sx: styles.aside.body,
110
98
  children: aside
111
99
  })]
112
100
  }), /*#__PURE__*/_jsx(Tooltip, {
@@ -115,7 +103,7 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
115
103
  variant: "crud",
116
104
  onClick: reset,
117
105
  sx: {
118
- ...resetButtonStyles,
106
+ ...styles.aside.resetButton(resetButtonMarginTop),
119
107
  opacity: asidePortion > 0 && asidePortion !== defaultAsidePortion ? 1 : 0
120
108
  },
121
109
  children: /*#__PURE__*/_jsx(SplitLayoutIcon, {})
@@ -125,24 +113,55 @@ const SplitLayout = /*#__PURE__*/forwardRef(({
125
113
  });
126
114
  });
127
115
  export default SplitLayout;
128
- const containerStyles = {
129
- height: '100%'
130
- };
131
- const sectionStyles = {
132
- padding: '24px 28px'
133
- };
134
- const dividerStyles = {
135
- width: '6px',
136
- height: '100%',
137
- borderLeft: `1px solid ${grey[400]}`,
138
- backgroundColor: blueGrey.frameBg,
139
- cursor: 'col-resize',
140
- zIndex: 'var(--divider-zindex)'
116
+ const styles = {
117
+ container: {
118
+ height: '100%'
119
+ },
120
+ section: {
121
+ padding: '24px 28px'
122
+ },
123
+ divider: {
124
+ width: '6px',
125
+ height: '100%',
126
+ borderLeft: `1px solid ${grey[400]}`,
127
+ backgroundColor: blueGrey.frameBg,
128
+ cursor: 'col-resize',
129
+ zIndex: 'var(--divider-zindex)'
130
+ },
131
+ aside: {
132
+ container: width => ({
133
+ position: 'fixed',
134
+ right: 0,
135
+ width: `${width}px`,
136
+ height: 'calc(100vh - var(--gnb-height))'
137
+ }),
138
+ body: {
139
+ width: '100%',
140
+ height: '100%',
141
+ flexGrow: 1,
142
+ backgroundColor: blueGrey.frameBg,
143
+ padding: '6px 16px 6px 10px',
144
+ overflow: 'hidden',
145
+ zIndex: 'var(--aside-zindex)'
146
+ },
147
+ resetButton: marginTop => ({
148
+ position: 'absolute',
149
+ top: `${marginTop}px`,
150
+ right: '16px',
151
+ zIndex: 'var(--aside-button-zindex)',
152
+ transition: 'opacity .5s',
153
+ '&': {
154
+ backgroundColor: '#dfe0e1'
155
+ },
156
+ ':hover, &.Mui-focusVisible': {
157
+ backgroundColor: '#d9dadb'
158
+ },
159
+ '&:active': {
160
+ backgroundColor: '#c7c8c8'
161
+ }
162
+ })
163
+ }
141
164
  };
142
- const asideStyles = {
143
- flexGrow: 1,
144
- backgroundColor: blueGrey.frameBg,
145
- padding: '6px 16px 6px 10px',
146
- overflowX: 'hidden',
147
- zIndex: 'var(--aside-zindex)'
148
- };
165
+ function calcAsideWidth(containerWidth, asidePortion) {
166
+ return containerWidth * (asidePortion / 100);
167
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nethru/ui",
3
- "version": "2.1.47",
3
+ "version": "2.1.49",
4
4
  "main": "base/index.js",
5
5
  "files": [
6
6
  "/base"