@norges-domstoler/dds-components 11.1.0 → 11.1.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.
@@ -0,0 +1 @@
1
+ export declare function useElementHeight(element: HTMLDivElement | null): number | null;
package/dist/cjs/index.js CHANGED
@@ -7555,7 +7555,25 @@ var useIsMounted = function useIsMounted() {
7555
7555
  }, []);
7556
7556
  };
7557
7557
 
7558
- var expandingAnimation = styled.css(["@media (prefers-reduced-motion:no-preference){transition:padding 0.2s,visibility 0.3s,max-height 0.2s cubic-bezier(0.4,0,0.2,1);}"]);
7558
+ function useElementHeight(element) {
7559
+ var _useState = React.useState(null),
7560
+ _useState2 = _slicedToArray(_useState, 2),
7561
+ height = _useState2[0],
7562
+ setHeight = _useState2[1];
7563
+ React.useEffect(function () {
7564
+ if (!element) return;
7565
+ var resizeObserver = new ResizeObserver(function () {
7566
+ setHeight(element.offsetHeight);
7567
+ });
7568
+ resizeObserver.observe(element);
7569
+ return function () {
7570
+ return resizeObserver.disconnect();
7571
+ };
7572
+ }, [element]);
7573
+ return height;
7574
+ }
7575
+
7576
+ var expandingAnimation = styled.css(["@media (prefers-reduced-motion:no-preference){transition:height 0.2s cubic-bezier(0.4,0,0.2,1);}"]);
7559
7577
  function getPadding(props) {
7560
7578
  var padding = props.padding;
7561
7579
  return padding || cardAccordionTokens.body.padding;
@@ -7563,28 +7581,20 @@ function getPadding(props) {
7563
7581
  var Body = styled__default.default.div.withConfig({
7564
7582
  displayName: "CardAccordionBody__Body",
7565
7583
  componentId: "sc-igsnpx-0"
7566
- })(["@media (prefers-reduced-motion:no-preference){", "}padding:", ";", " ", " ", ""], function (_ref) {
7584
+ })(["@media (prefers-reduced-motion:no-preference){", "}", " height:", "px;overflow:hidden;"], function (_ref) {
7567
7585
  var animate = _ref.animate;
7568
7586
  return animate && expandingAnimation;
7569
- }, getPadding, getFontStyling(typographyTypes$3.body), function (_ref2) {
7570
- var paddingTop = _ref2.paddingTop;
7571
- return paddingTop && styled.css(["padding-top:", ";"], paddingTop);
7572
- }, function (_ref3) {
7573
- var isExpanded = _ref3.isExpanded;
7574
- return !isExpanded && styled.css(["padding-top:0;padding-bottom:0;"]);
7587
+ }, getFontStyling(typographyTypes$3.body), function (_ref2) {
7588
+ var height = _ref2.height,
7589
+ isExpanded = _ref2.isExpanded;
7590
+ return isExpanded ? height : 0;
7575
7591
  });
7576
7592
  var BodyContainer = styled__default.default.div.withConfig({
7577
7593
  displayName: "CardAccordionBody__BodyContainer",
7578
7594
  componentId: "sc-igsnpx-1"
7579
- })(["", " overflow:hidden;visibility:", ";max-height:", "px;"], function (_ref4) {
7580
- var animate = _ref4.animate;
7581
- return animate && expandingAnimation;
7582
- }, function (_ref5) {
7583
- var isExpanded = _ref5.isExpanded;
7584
- return isExpanded ? 'visible' : 'hidden';
7585
- }, function (_ref6) {
7586
- var maxHeight = _ref6.maxHeight;
7587
- return maxHeight ? maxHeight : 0;
7595
+ })(["padding:", ";", ""], getPadding, function (_ref3) {
7596
+ var paddingTop = _ref3.paddingTop;
7597
+ return paddingTop && styled.css(["padding-top:", ";"], paddingTop);
7588
7598
  });
7589
7599
  var CardAccordionBody = /*#__PURE__*/React.forwardRef(function (props, ref) {
7590
7600
  var children = props.children,
@@ -7593,20 +7603,24 @@ var CardAccordionBody = /*#__PURE__*/React.forwardRef(function (props, ref) {
7593
7603
  id = props.id,
7594
7604
  className = props.className,
7595
7605
  htmlProps = props.htmlProps,
7596
- rest = tslib.__rest(props, ["children", "isExpanded", "headerId", "id", "className", "htmlProps"]);
7606
+ padding = props.padding,
7607
+ paddingTop = props.paddingTop,
7608
+ rest = tslib.__rest(props, ["children", "isExpanded", "headerId", "id", "className", "htmlProps", "padding", "paddingTop"]);
7597
7609
  var bodyRef = React.useRef(null);
7598
- var isMounted = useIsMounted();
7599
7610
  var _useState = React.useState(false),
7600
7611
  _useState2 = _slicedToArray(_useState, 2),
7601
7612
  animate = _useState2[0],
7602
7613
  setAnimate = _useState2[1];
7603
- var _useState3 = React.useState(0),
7614
+ var isMounted = useIsMounted();
7615
+ var height = useElementHeight(bodyRef.current);
7616
+ var _useState3 = React.useState(null),
7604
7617
  _useState4 = _slicedToArray(_useState3, 2),
7605
- maxHeight = _useState4[0],
7606
- setMaxHeight = _useState4[1];
7618
+ initialExpandedHeight = _useState4[0],
7619
+ setIntialExpandedHeight = _useState4[1];
7607
7620
  React.useLayoutEffect(function () {
7621
+ // For å unngå initiell animasjon dersom Accordion er satt til å være åpen som default.
7608
7622
  if (bodyRef.current && isExpanded) {
7609
- setMaxHeight(bodyRef.current.scrollHeight);
7623
+ setIntialExpandedHeight(bodyRef.current.scrollHeight);
7610
7624
  }
7611
7625
  }, []);
7612
7626
  React.useEffect(function () {
@@ -7614,22 +7628,17 @@ var CardAccordionBody = /*#__PURE__*/React.forwardRef(function (props, ref) {
7614
7628
  setAnimate(true);
7615
7629
  }
7616
7630
  }, [isMounted]);
7617
- React.useEffect(function () {
7618
- if (!isExpanded) {
7619
- setMaxHeight(0);
7620
- } else if (bodyRef && bodyRef.current) {
7621
- setMaxHeight(bodyRef.current.scrollHeight);
7622
- }
7623
- }, [isExpanded]);
7624
7631
  var bodyProps = Object.assign(Object.assign({}, getBaseHTMLProps(id, className, htmlProps, rest)), {
7625
7632
  ref: ref,
7626
7633
  isExpanded: isExpanded,
7627
- role: 'region'
7634
+ role: 'region',
7635
+ height: height || initialExpandedHeight || 0
7628
7636
  });
7629
7637
  var bodyContainerProps = {
7630
7638
  ref: bodyRef,
7631
- maxHeight: maxHeight,
7632
- isExpanded: isExpanded
7639
+ isExpanded: isExpanded,
7640
+ padding: padding,
7641
+ paddingTop: paddingTop
7633
7642
  };
7634
7643
  return jsxRuntime.jsx(Body, Object.assign({}, bodyProps, {
7635
7644
  animate: animate,
@@ -7,8 +7,9 @@ import useIsMounted from '../../../hooks/useIsMounted.js';
7
7
  import { getBaseHTMLProps } from '../../../types/BaseComponentProps.js';
8
8
  import { getFontStyling } from '../../Typography/Typography.utils.js';
9
9
  import { cardAccordionTokens, typographyTypes } from './CardAccordion.tokens.js';
10
+ import { useElementHeight } from './useElementHeight.js';
10
11
 
11
- var expandingAnimation = css(["@media (prefers-reduced-motion:no-preference){transition:padding 0.2s,visibility 0.3s,max-height 0.2s cubic-bezier(0.4,0,0.2,1);}"]);
12
+ var expandingAnimation = css(["@media (prefers-reduced-motion:no-preference){transition:height 0.2s cubic-bezier(0.4,0,0.2,1);}"]);
12
13
  function getPadding(props) {
13
14
  var padding = props.padding;
14
15
  return padding || cardAccordionTokens.body.padding;
@@ -16,28 +17,20 @@ function getPadding(props) {
16
17
  var Body = styled.div.withConfig({
17
18
  displayName: "CardAccordionBody__Body",
18
19
  componentId: "sc-igsnpx-0"
19
- })(["@media (prefers-reduced-motion:no-preference){", "}padding:", ";", " ", " ", ""], function (_ref) {
20
+ })(["@media (prefers-reduced-motion:no-preference){", "}", " height:", "px;overflow:hidden;"], function (_ref) {
20
21
  var animate = _ref.animate;
21
22
  return animate && expandingAnimation;
22
- }, getPadding, getFontStyling(typographyTypes.body), function (_ref2) {
23
- var paddingTop = _ref2.paddingTop;
24
- return paddingTop && css(["padding-top:", ";"], paddingTop);
25
- }, function (_ref3) {
26
- var isExpanded = _ref3.isExpanded;
27
- return !isExpanded && css(["padding-top:0;padding-bottom:0;"]);
23
+ }, getFontStyling(typographyTypes.body), function (_ref2) {
24
+ var height = _ref2.height,
25
+ isExpanded = _ref2.isExpanded;
26
+ return isExpanded ? height : 0;
28
27
  });
29
28
  var BodyContainer = styled.div.withConfig({
30
29
  displayName: "CardAccordionBody__BodyContainer",
31
30
  componentId: "sc-igsnpx-1"
32
- })(["", " overflow:hidden;visibility:", ";max-height:", "px;"], function (_ref4) {
33
- var animate = _ref4.animate;
34
- return animate && expandingAnimation;
35
- }, function (_ref5) {
36
- var isExpanded = _ref5.isExpanded;
37
- return isExpanded ? 'visible' : 'hidden';
38
- }, function (_ref6) {
39
- var maxHeight = _ref6.maxHeight;
40
- return maxHeight ? maxHeight : 0;
31
+ })(["padding:", ";", ""], getPadding, function (_ref3) {
32
+ var paddingTop = _ref3.paddingTop;
33
+ return paddingTop && css(["padding-top:", ";"], paddingTop);
41
34
  });
42
35
  var CardAccordionBody = /*#__PURE__*/forwardRef(function (props, ref) {
43
36
  var children = props.children,
@@ -46,20 +39,24 @@ var CardAccordionBody = /*#__PURE__*/forwardRef(function (props, ref) {
46
39
  id = props.id,
47
40
  className = props.className,
48
41
  htmlProps = props.htmlProps,
49
- rest = __rest(props, ["children", "isExpanded", "headerId", "id", "className", "htmlProps"]);
42
+ padding = props.padding,
43
+ paddingTop = props.paddingTop,
44
+ rest = __rest(props, ["children", "isExpanded", "headerId", "id", "className", "htmlProps", "padding", "paddingTop"]);
50
45
  var bodyRef = useRef(null);
51
- var isMounted = useIsMounted();
52
46
  var _useState = useState(false),
53
47
  _useState2 = _slicedToArray(_useState, 2),
54
48
  animate = _useState2[0],
55
49
  setAnimate = _useState2[1];
56
- var _useState3 = useState(0),
50
+ var isMounted = useIsMounted();
51
+ var height = useElementHeight(bodyRef.current);
52
+ var _useState3 = useState(null),
57
53
  _useState4 = _slicedToArray(_useState3, 2),
58
- maxHeight = _useState4[0],
59
- setMaxHeight = _useState4[1];
54
+ initialExpandedHeight = _useState4[0],
55
+ setIntialExpandedHeight = _useState4[1];
60
56
  useLayoutEffect(function () {
57
+ // For å unngå initiell animasjon dersom Accordion er satt til å være åpen som default.
61
58
  if (bodyRef.current && isExpanded) {
62
- setMaxHeight(bodyRef.current.scrollHeight);
59
+ setIntialExpandedHeight(bodyRef.current.scrollHeight);
63
60
  }
64
61
  }, []);
65
62
  useEffect(function () {
@@ -67,22 +64,17 @@ var CardAccordionBody = /*#__PURE__*/forwardRef(function (props, ref) {
67
64
  setAnimate(true);
68
65
  }
69
66
  }, [isMounted]);
70
- useEffect(function () {
71
- if (!isExpanded) {
72
- setMaxHeight(0);
73
- } else if (bodyRef && bodyRef.current) {
74
- setMaxHeight(bodyRef.current.scrollHeight);
75
- }
76
- }, [isExpanded]);
77
67
  var bodyProps = Object.assign(Object.assign({}, getBaseHTMLProps(id, className, htmlProps, rest)), {
78
68
  ref: ref,
79
69
  isExpanded: isExpanded,
80
- role: 'region'
70
+ role: 'region',
71
+ height: height || initialExpandedHeight || 0
81
72
  });
82
73
  var bodyContainerProps = {
83
74
  ref: bodyRef,
84
- maxHeight: maxHeight,
85
- isExpanded: isExpanded
75
+ isExpanded: isExpanded,
76
+ padding: padding,
77
+ paddingTop: paddingTop
86
78
  };
87
79
  return jsx(Body, Object.assign({}, bodyProps, {
88
80
  animate: animate,
@@ -0,0 +1 @@
1
+ export declare function useElementHeight(element: HTMLDivElement | null): number | null;
@@ -0,0 +1,22 @@
1
+ import { slicedToArray as _slicedToArray } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { useState, useEffect } from 'react';
3
+
4
+ function useElementHeight(element) {
5
+ var _useState = useState(null),
6
+ _useState2 = _slicedToArray(_useState, 2),
7
+ height = _useState2[0],
8
+ setHeight = _useState2[1];
9
+ useEffect(function () {
10
+ if (!element) return;
11
+ var resizeObserver = new ResizeObserver(function () {
12
+ setHeight(element.offsetHeight);
13
+ });
14
+ resizeObserver.observe(element);
15
+ return function () {
16
+ return resizeObserver.disconnect();
17
+ };
18
+ }, [element]);
19
+ return height;
20
+ }
21
+
22
+ export { useElementHeight };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norges-domstoler/dds-components",
3
- "version": "11.1.0",
3
+ "version": "11.1.1",
4
4
  "description": "React components used in Elsa - domstolenes designsystem",
5
5
  "author": "Elsa team",
6
6
  "license": "MIT",