diginet-core-ui 1.3.93 → 1.3.94

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.
@@ -1,22 +1,16 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, forwardRef, useRef, useMemo, useImperativeHandle } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
4
  import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
6
- import { boxBorder, displayBlock, overflowHidden, parseHeight, pointerEventsNone, positionRelative, userSelectNone } from "../../styles/general";
5
+ import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
6
+ import { boxBorder, overflowHidden, parseHeight, pd, pointerEventsNone, positionRelative, textColor, userSelectNone } from "../../styles/general";
7
+ import { useTheme } from "../../theme";
7
8
  import { classNames } from "../../utils";
8
- import theme from "../../theme/settings";
9
9
  const {
10
- colors: {
11
- text: {
12
- main
13
- }
14
- },
15
10
  typography: {
16
11
  paragraph1
17
- },
18
- spacing
19
- } = theme;
12
+ }
13
+ } = useTheme();
20
14
  const AccordionDetails = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
21
15
  action = {},
22
16
  children,
@@ -24,6 +18,7 @@ const AccordionDetails = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
24
18
  id,
25
19
  style
26
20
  }, reference) => {
21
+ if (!reference) reference = useRef(null);
27
22
  const ref = useRef(null);
28
23
  useImperativeHandle(reference, () => {
29
24
  const currentRef = ref.current || {};
@@ -48,16 +43,15 @@ const AccordionDetails = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
48
43
  }, [children, className, id, style]);
49
44
  }));
50
45
  const DetailsRootCSS = css`
51
- ${displayBlock};
52
46
  ${positionRelative};
53
47
  ${overflowHidden};
54
48
  ${parseHeight(0)};
55
- transition: height 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
49
+ transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
56
50
  .DGN-UI-Accordion-Details-Content {
57
51
  ${boxBorder};
58
52
  ${paragraph1};
59
- padding: ${spacing([0, 6, 4, 6])};
60
- color: ${main};
53
+ ${pd([0, 6, 4, 6])};
54
+ ${textColor('text/main')};
61
55
  &.disabled {
62
56
  ${pointerEventsNone};
63
57
  ${userSelectNone};
@@ -1,14 +1,10 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useRef, forwardRef, Children, cloneElement, useMemo, useImperativeHandle } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
4
  import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
6
- import { borderRadius4px } from "../../styles/general";
7
- import classNames from "../../utils/classNames";
8
- import theme from "../../theme/settings";
9
- const {
10
- spacing
11
- } = theme;
5
+ import { Children, cloneElement, forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
6
+ import { borderRadius, borderRadius4px, mg } from "../../styles/general";
7
+ import { classNames } from "../../utils";
12
8
  const AccordionGroup = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
13
9
  action = {},
14
10
  children,
@@ -16,6 +12,7 @@ const AccordionGroup = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
16
12
  collapseOther,
17
13
  style
18
14
  }, reference) => {
15
+ if (!reference) reference = useRef(null);
19
16
  const ref = useRef(null);
20
17
  const onCollapseOther = (e, onExpand) => {
21
18
  if (collapseOther) {
@@ -60,7 +57,7 @@ const AccordionGroupRootCSS = css`
60
57
  }
61
58
  &.expanding {
62
59
  ${borderRadius4px};
63
- margin: ${spacing([0, 0, 4, 0])};
60
+ ${mg([0, 0, 4, 0])};
64
61
  .DGN-UI-Divider {
65
62
  display: none !important;
66
63
  }
@@ -73,7 +70,7 @@ const AccordionGroupRootCSS = css`
73
70
  }
74
71
  &.expanding {
75
72
  ${borderRadius4px};
76
- margin: ${spacing([4, 0, 0, 0])};
73
+ ${mg([4, 0, 0, 0])};
77
74
  .DGN-UI-Accordion-Summary {
78
75
  border-radius: 4px 4px 0px 0px;
79
76
  }
@@ -85,11 +82,11 @@ const AccordionGroupRootCSS = css`
85
82
  &:not(:first-of-type):not(:last-child) {
86
83
  &,
87
84
  .DGN-UI-Accordion-Summary {
88
- border-radius: 0px;
85
+ ${borderRadius(0)};
89
86
  }
90
87
  &.expanding {
91
88
  ${borderRadius4px};
92
- margin: ${spacing([4, 0])};
89
+ ${mg([4, 0])};
93
90
  .DGN-UI-Accordion-Summary {
94
91
  border-radius: 4px 4px 0px 0px;
95
92
  }
@@ -1,20 +1,32 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useEffect, useRef, forwardRef, useState, useMemo, useImperativeHandle } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
+ import { Divider } from "./..";
4
5
  import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
6
+ import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
7
+ import { bgColor, borderRadius4px, cursorNotAllowed, displayBlock, parseHeight, parseWidth, positionRelative, shadowNone } from "../../styles/general";
8
+ import { classNames } from "../../utils";
6
9
  import AccordionContext from "./context";
7
- import Divider from "../divider";
8
- import { borderRadius4px, displayBlock, parseWidth, positionRelative } from "../../styles/general";
9
- import classNames from "../../utils/classNames";
10
- import theme from "../../theme/settings";
11
- const {
12
- colors: {
13
- line: {
14
- category
10
+ const handleTransition = (timer, el, beginHeight, endHeight = null) => {
11
+ const getAutoHeightDuration = height => {
12
+ if (!height) {
13
+ return 0;
15
14
  }
15
+ const constant = height / 36;
16
+
17
+ // https://www.wolframalpha.com/input/?i=(4+%2B+15+*+(x+%2F+36+)+**+0.25+%2B+(x+%2F+36)+%2F+5)+*+10
18
+ return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
19
+ };
20
+ const duration = getAutoHeightDuration(beginHeight);
21
+ el.style.transitionDuration = `${duration}ms`;
22
+ el.style.height = `${beginHeight}px`;
23
+ if (timer.current) {
24
+ clearTimeout(timer.current);
16
25
  }
17
- } = theme;
26
+ timer.current = setTimeout(() => {
27
+ el.style.height = endHeight;
28
+ }, duration);
29
+ };
18
30
  const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
19
31
  action = {},
20
32
  boxShadow,
@@ -23,16 +35,24 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
23
35
  disabled,
24
36
  expand,
25
37
  expanded,
38
+ fullHeight,
26
39
  id,
27
40
  onClick,
28
41
  onCollapse,
29
42
  onExpand,
30
43
  style
31
44
  }, reference) => {
45
+ if (!reference) reference = useRef(null);
32
46
  const ref = useRef(null);
47
+ const timer = useRef(null);
33
48
  const [expandState, setExpandState] = useState(expanded || expand);
49
+ const _AccordionRootCSS = AccordionRootCSS(fullHeight, expandState);
34
50
  useEffect(() => {
35
51
  if (ref.current) {
52
+ if (fullHeight) {
53
+ handleTransition(timer, ref.current, ref.current.clientHeight, expandState ? '100%' : null);
54
+ }
55
+ // Handle margin top bot when in group
36
56
  const previous = ref.current.previousElementSibling;
37
57
  if (previous) {
38
58
  expandState ? previous.classList.add('previousExpanding') : previous.classList.remove('previousExpanding');
@@ -58,12 +78,13 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
58
78
  return currentRef;
59
79
  });
60
80
  return useMemo(() => {
81
+ var _ref$current;
61
82
  return jsx("div", {
62
83
  id: id,
63
- css: AccordionRootCSS,
84
+ css: [_AccordionRootCSS, boxShadow && AccordionRootBoxShadowCSS, disabled && AccordionRootDisabledCSS],
64
85
  ref: ref,
65
86
  style: style,
66
- className: classNames('DGN-UI-Accordion', disabled && 'disabled', boxShadow === true && 'boxShadow', expandState && 'expanding', className)
87
+ className: classNames('DGN-UI-Accordion', disabled && 'disabled', expandState && 'expanding', className)
67
88
  }, jsx(AccordionContext.Provider, {
68
89
  value: {
69
90
  expanded,
@@ -72,41 +93,46 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
72
93
  onClickAccordion: onClick ? onClickAccordion : null,
73
94
  onExpand,
74
95
  onCollapse,
75
- setExpandState
96
+ setExpandState,
97
+ handleTransition,
98
+ fullHeight: fullHeight ? ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientHeight) || 0 : 0
76
99
  }
77
100
  }, children, jsx(Divider, {
78
- color: category,
101
+ color: 'line/category',
79
102
  style: {
80
103
  margin: 0,
81
104
  display: 'none'
82
105
  }
83
106
  })));
84
- }, [boxShadow, children, className, disabled, expanded, id, onClick, onCollapse, onExpand, style, expandState]);
107
+ }, [boxShadow, children, className, disabled, expand, expanded, fullHeight, id, onClick, onCollapse, onExpand, style, expandState]);
85
108
  }));
86
- const AccordionRootCSS = css`
109
+ const AccordionRootCSS = (fullHeight, expandState) => css`
87
110
  ${displayBlock};
88
111
  ${positionRelative};
89
112
  ${borderRadius4px};
90
113
  ${parseWidth('100%')};
91
- transition: margin 300ms ease;
92
- &.boxShadow {
93
- box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
94
- }
95
- &.disabled {
96
- cursor: no-drop;
97
- box-shadow: none;
98
- }
114
+ ${fullHeight && expandState && parseHeight('100%')};
115
+ ${bgColor('system/white')};
116
+ transition: margin 300ms ease, height 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
117
+ `;
118
+ const AccordionRootBoxShadowCSS = css`
119
+ box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
120
+ `;
121
+ const AccordionRootDisabledCSS = css`
122
+ ${cursorNotAllowed};
123
+ ${shadowNone};
99
124
  `;
100
125
  Accordion.defaultProps = {
101
126
  boxShadow: true,
102
127
  className: '',
103
128
  disabled: false,
104
129
  expand: false,
130
+ fullHeight: false,
105
131
  style: {}
106
132
  };
107
133
  Accordion.propTypes = {
108
134
  /** The box-shadow of component. */
109
- boxShadow: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
135
+ boxShadow: PropTypes.bool,
110
136
  /** The content of the component (insist <AccordionSummary />, <AccordionDetails />). */
111
137
  children: PropTypes.node,
112
138
  /** Class for component. */
@@ -117,6 +143,8 @@ Accordion.propTypes = {
117
143
  expand: PropTypes.bool,
118
144
  /** Expand state of accordion (should use this). */
119
145
  expanded: PropTypes.bool,
146
+ /** If `true`, Accordion height will 100% of it parent. */
147
+ fullHeight: PropTypes.bool,
120
148
  /** Callback fired when Accordion is collapsed. */
121
149
  onCollapse: PropTypes.func,
122
150
  /** Callback fired when Accordion is expanded. */
@@ -1,22 +1,25 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useEffect, useRef, useContext, forwardRef, useMemo, useImperativeHandle } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
+ import { ButtonIcon, Typography } from "./..";
4
5
  import PropTypes from 'prop-types';
5
- import { jsx } from '@emotion/core';
6
- import { SummaryRootCSS } from "./css";
7
- import AccordionContext from "./context";
8
- import { ButtonIcon, Typography } from '..';
6
+ import { forwardRef, memo, useContext, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
7
+ import { bgColor, bgTransparent, borderRadius4px, boxBorder, breakWord, cursorPointer, displayFlex, displayInlineBlock, displayInlineFlex, flexRow, flexRowReverse, inset, itemsCenter, justifyBetween, justifyCenter, justifyEnd, mgl, mgr, parseMaxWidthHeight, parseMinHeight, parseMinWidthHeight, parseWidth, parseWidthHeight, pd, pointerEventsInitial, pointerEventsNone, positionAbsolute, positionRelative, textColor, userSelectNone } from "../../styles/general";
8
+ import { useTheme } from "../../theme";
9
9
  import { classNames } from "../../utils";
10
- import theme from "../../theme/settings";
10
+ import AccordionContext from "./context";
11
11
  const {
12
12
  colors: {
13
13
  system: {
14
- active,
14
+ active: systemActive,
15
15
  disabled: systemDisabled
16
16
  }
17
17
  },
18
+ typography: {
19
+ heading3
20
+ },
18
21
  spacing
19
- } = theme;
22
+ } = useTheme();
20
23
  const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
21
24
  action = {},
22
25
  background,
@@ -31,6 +34,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
31
34
  style,
32
35
  title
33
36
  }, reference) => {
37
+ if (!reference) reference = useRef(null);
34
38
  const {
35
39
  expanded,
36
40
  expandState,
@@ -38,7 +42,9 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
38
42
  onClickAccordion,
39
43
  onExpand,
40
44
  onCollapse,
41
- setExpandState
45
+ setExpandState,
46
+ handleTransition,
47
+ fullHeight
42
48
  } = useContext(AccordionContext);
43
49
  const ref = useRef(null);
44
50
  const expandIconRef = useRef(null);
@@ -64,32 +70,17 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
64
70
  }
65
71
  };
66
72
  const showHideDetailHandler = type => {
67
- if (ref.current) {
68
- const detailsEl = ref.current.nextElementSibling;
73
+ if (!ref.current) return;
74
+ const detailEl = ref.current.nextElementSibling;
75
+ if (detailEl) {
76
+ const summaryHeight = ref.current.clientHeight;
69
77
  if (type === 'show') {
70
- if (detailsEl) {
71
- const scrollHeight = detailsEl.scrollHeight;
72
- const duration = Math.max(Math.min(scrollHeight, 1500), 200);
73
- detailsEl.style.height = scrollHeight + 'px';
74
- if (!detailsEl.style.transitionDuration) {
75
- detailsEl.style.transitionDuration = duration + 'ms';
76
- }
77
- if (timer.current) {
78
- clearTimeout(timer.current);
79
- }
80
- timer.current = setTimeout(() => {
81
- detailsEl.style.height = 'auto';
82
- }, (detailsEl.firstChild.childNodes.length || 2.5) * 100);
83
- }
78
+ const height = Math.max(detailEl.scrollHeight, fullHeight - summaryHeight);
79
+ handleTransition(timer, detailEl, height, `calc(100% - ${summaryHeight}px)`);
84
80
  } else {
85
- if (detailsEl && detailsEl.style.height) {
86
- detailsEl.style.height = detailsEl.scrollHeight + 'px';
87
- if (timer.current) {
88
- clearTimeout(timer.current);
89
- }
90
- timer.current = setTimeout(() => {
91
- detailsEl.style.height = null;
92
- }, 10);
81
+ if (detailEl.style.height) {
82
+ const height = detailEl.scrollHeight;
83
+ handleTransition(timer, detailEl, height);
93
84
  }
94
85
  }
95
86
  }
@@ -125,7 +116,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
125
116
  }, jsx(Typography, {
126
117
  type: 'h3',
127
118
  lineClamp: 2,
128
- color: disabled ? systemDisabled : active,
119
+ color: disabled ? 'system/disabled' : 'system/active',
129
120
  style: {
130
121
  marginRight: children && title ? spacing([4]) : 0
131
122
  }
@@ -150,7 +141,158 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
150
141
  }, collapseIcon)))));
151
142
  }, [background, children, className, collapseIcon, expandIcon, expandIconAt, expandIconProps, id, onClick, style, title, disabled, expanded, expandState, onClickAccordion, onCollapse, onExpand]);
152
143
  }));
144
+ const SummaryRootCSS = background => css`
145
+ ${displayFlex};
146
+ ${flexRow};
147
+ ${positionRelative};
148
+ ${justifyBetween};
149
+ ${itemsCenter};
150
+ ${cursorPointer};
151
+ ${boxBorder};
152
+ ${borderRadius4px};
153
+ ${parseWidth('100%')};
154
+ ${parseMinHeight(56)};
155
+ ${pd([4, 6])};
156
+ ${bgColor(background)};
157
+ .Accordion-Expand-Icon,
158
+ .Accordion-Collapse-Icon {
159
+ ${cursorPointer};
160
+ color: ${systemActive} !important;
161
+ &:active,
162
+ &:focus,
163
+ &:hover {
164
+ ${bgColor('transparent')};
165
+ ${textColor('system/active')};
166
+ }
167
+ }
168
+ .Accordion-Icon-Root {
169
+ ${displayFlex};
170
+ ${flexRow};
171
+ .Accordion-Icon.rotate-able {
172
+ ${boxBorder};
173
+ ${parseWidthHeight(24)};
174
+ &:not(.TreeView) {
175
+ transform: rotateZ(0deg);
176
+ transform-origin: center;
177
+ }
178
+ &.TreeView {
179
+ transform-origin: center;
180
+ }
181
+ }
182
+ }
183
+ &.start {
184
+ ${flexRowReverse};
185
+ ${justifyEnd};
186
+ .Accordion-Icon.rotate-able {
187
+ ${mgr([2])};
188
+ &.TreeView {
189
+ transform: rotateZ(-90deg);
190
+ }
191
+ }
192
+ }
193
+ &.end {
194
+ .Accordion-Icon.rotate-able {
195
+ ${mgl([2])};
196
+ &.TreeView {
197
+ transform: rotateZ(90deg);
198
+ }
199
+ }
200
+ }
201
+ &.expanding {
202
+ border-radius: 4px 4px 0px 0px;
203
+ .Accordion-Icon.rotate-able {
204
+ &:not(.TreeView) {
205
+ transform: rotateZ(90deg);
206
+ }
207
+ &.TreeView {
208
+ transform: rotateZ(0deg);
209
+ }
210
+ }
211
+ .Accordion-Icon:not(.rotate-able) {
212
+ .Accordion-Expand-Icon {
213
+ transform: scale(0);
214
+ }
215
+ .Accordion-Collapse-Icon {
216
+ transform: scale(1);
217
+ }
218
+ }
219
+ }
220
+ &:not(.disabled) {
221
+ transition: background-color 300ms ease;
222
+ &:hover {
223
+ ${bgColor('fill.hover')};
224
+ }
225
+ &:focus {
226
+ ${bgColor('fill.focus')};
227
+ }
228
+ &:active {
229
+ ${bgColor('fill.pressed')};
230
+ }
231
+ }
232
+ &.disabled {
233
+ ${pointerEventsNone};
234
+ ${bgColor('fill.disabled')};
235
+ .DGN-UI-Accordion-Summary-Content,
236
+ .Accordion-Expand-Icon {
237
+ color: ${systemDisabled} !important;
238
+ }
239
+ }
240
+ &.treeview-disabled {
241
+ ${pointerEventsNone};
242
+ &:hover {
243
+ ${bgTransparent};
244
+ }
245
+ .TreeView-Item {
246
+ ${textColor('system.disabled')};
247
+ }
248
+ .Accordion-Icon.rotate-able.TreeView .DGN-UI-Icon {
249
+ ${cursorPointer};
250
+ ${pointerEventsInitial};
251
+ }
252
+ }
253
+ .DGN-UI-Accordion-Summary-Content {
254
+ ${heading3};
255
+ ${flexRow};
256
+ ${positionRelative};
257
+ ${breakWord};
258
+ ${userSelectNone};
259
+ ${boxBorder}
260
+ ${itemsCenter};
261
+ ${textColor('system.active')};
262
+ ${parseWidth('100%')};
263
+ ${parseMinHeight(24)};
264
+ }
265
+ .Accordion-Icon {
266
+ ${displayInlineBlock};
267
+ ${positionRelative};
268
+ ${cursorPointer};
269
+ ${parseWidthHeight(24)};
270
+ transition: transform 200ms linear;
271
+ .Accordion-Expand-Icon {
272
+ transform: scale(1);
273
+ transition: transform 200ms linear;
274
+ &.effect {
275
+ ${positionRelative};
276
+ }
277
+ }
278
+ .Accordion-Collapse-Icon {
279
+ ${positionAbsolute};
280
+ ${inset(0)};
281
+ transform: scale(0);
282
+ transition: transform 200ms linear;
283
+ }
284
+ .effect {
285
+ ${displayInlineFlex};
286
+ ${justifyCenter};
287
+ ${itemsCenter};
288
+ ${cursorPointer};
289
+ ${parseMinWidthHeight(24)};
290
+ ${parseMaxWidthHeight(34)};
291
+ }
292
+ }
293
+ `;
153
294
  AccordionSummary.defaultProps = {
295
+ background: 'system/white',
154
296
  className: '',
155
297
  expandIcon: 'ArrowRight',
156
298
  expandIconAt: 'start',
@@ -159,7 +301,7 @@ AccordionSummary.defaultProps = {
159
301
  };
160
302
  AccordionSummary.propTypes = {
161
303
  /** Background for label summary. */
162
- background: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
304
+ background: PropTypes.string,
163
305
  /** The content of the component. */
164
306
  children: PropTypes.node,
165
307
  /** Class for component. */