@salt-ds/lab 1.0.0-alpha.11 → 1.0.0-alpha.12

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 (90) hide show
  1. package/dist-cjs/accordion/Accordion.css.js +1 -1
  2. package/dist-cjs/accordion/Accordion.js +33 -108
  3. package/dist-cjs/accordion/Accordion.js.map +1 -1
  4. package/dist-cjs/accordion/AccordionContext.js +15 -11
  5. package/dist-cjs/accordion/AccordionContext.js.map +1 -1
  6. package/dist-cjs/accordion/AccordionGroup.js +23 -0
  7. package/dist-cjs/accordion/AccordionGroup.js.map +1 -0
  8. package/dist-cjs/accordion/AccordionHeader.css.js +6 -0
  9. package/dist-cjs/accordion/AccordionHeader.css.js.map +1 -0
  10. package/dist-cjs/accordion/AccordionHeader.js +50 -0
  11. package/dist-cjs/accordion/AccordionHeader.js.map +1 -0
  12. package/dist-cjs/accordion/AccordionPanel.css.js +6 -0
  13. package/dist-cjs/accordion/AccordionPanel.css.js.map +1 -0
  14. package/dist-cjs/accordion/AccordionPanel.js +45 -0
  15. package/dist-cjs/accordion/AccordionPanel.js.map +1 -0
  16. package/dist-cjs/form-field-legacy/FormFieldLegacy.css.js +1 -1
  17. package/dist-cjs/index.js +8 -9
  18. package/dist-cjs/index.js.map +1 -1
  19. package/dist-cjs/list-deprecated/ListItem.css.js +1 -1
  20. package/dist-cjs/list-next/ListItemNext.css.js +1 -1
  21. package/dist-cjs/multiline-input/MultilineInput.css.js +6 -0
  22. package/dist-cjs/multiline-input/MultilineInput.css.js.map +1 -0
  23. package/dist-cjs/multiline-input/MultilineInput.js +150 -0
  24. package/dist-cjs/multiline-input/MultilineInput.js.map +1 -0
  25. package/dist-cjs/pill/Pill.css.js +1 -1
  26. package/dist-cjs/toggle-button/ToggleButton.css.js +1 -1
  27. package/dist-cjs/tokenized-input/TokenizedInput.css.js +1 -1
  28. package/dist-cjs/toolbar/ToolbarButton.css.js +1 -1
  29. package/dist-es/accordion/Accordion.css.js +1 -1
  30. package/dist-es/accordion/Accordion.js +35 -110
  31. package/dist-es/accordion/Accordion.js.map +1 -1
  32. package/dist-es/accordion/AccordionContext.js +15 -11
  33. package/dist-es/accordion/AccordionContext.js.map +1 -1
  34. package/dist-es/accordion/AccordionGroup.js +19 -0
  35. package/dist-es/accordion/AccordionGroup.js.map +1 -0
  36. package/dist-es/accordion/AccordionHeader.css.js +4 -0
  37. package/dist-es/accordion/AccordionHeader.css.js.map +1 -0
  38. package/dist-es/accordion/AccordionHeader.js +46 -0
  39. package/dist-es/accordion/AccordionHeader.js.map +1 -0
  40. package/dist-es/accordion/AccordionPanel.css.js +4 -0
  41. package/dist-es/accordion/AccordionPanel.css.js.map +1 -0
  42. package/dist-es/accordion/AccordionPanel.js +41 -0
  43. package/dist-es/accordion/AccordionPanel.js.map +1 -0
  44. package/dist-es/form-field-legacy/FormFieldLegacy.css.js +1 -1
  45. package/dist-es/index.js +4 -4
  46. package/dist-es/list-deprecated/ListItem.css.js +1 -1
  47. package/dist-es/list-next/ListItemNext.css.js +1 -1
  48. package/dist-es/multiline-input/MultilineInput.css.js +4 -0
  49. package/dist-es/multiline-input/MultilineInput.css.js.map +1 -0
  50. package/dist-es/multiline-input/MultilineInput.js +146 -0
  51. package/dist-es/multiline-input/MultilineInput.js.map +1 -0
  52. package/dist-es/pill/Pill.css.js +1 -1
  53. package/dist-es/toggle-button/ToggleButton.css.js +1 -1
  54. package/dist-es/tokenized-input/TokenizedInput.css.js +1 -1
  55. package/dist-es/toolbar/ToolbarButton.css.js +1 -1
  56. package/dist-types/accordion/Accordion.d.ts +22 -6
  57. package/dist-types/accordion/AccordionContext.d.ts +8 -8
  58. package/dist-types/accordion/AccordionGroup.d.ts +4 -0
  59. package/dist-types/accordion/AccordionHeader.d.ts +4 -0
  60. package/dist-types/accordion/AccordionPanel.d.ts +4 -0
  61. package/dist-types/accordion/index.d.ts +3 -4
  62. package/dist-types/index.d.ts +1 -0
  63. package/dist-types/multiline-input/MultilineInput.d.ts +40 -0
  64. package/dist-types/multiline-input/index.d.ts +1 -0
  65. package/package.json +3 -3
  66. package/dist-cjs/accordion/AccordionDetails.js +0 -87
  67. package/dist-cjs/accordion/AccordionDetails.js.map +0 -1
  68. package/dist-cjs/accordion/AccordionSection.js +0 -111
  69. package/dist-cjs/accordion/AccordionSection.js.map +0 -1
  70. package/dist-cjs/accordion/AccordionSectionContext.js +0 -24
  71. package/dist-cjs/accordion/AccordionSectionContext.js.map +0 -1
  72. package/dist-cjs/accordion/AccordionSummary.js +0 -64
  73. package/dist-cjs/accordion/AccordionSummary.js.map +0 -1
  74. package/dist-cjs/accordion/utils.js +0 -8
  75. package/dist-cjs/accordion/utils.js.map +0 -1
  76. package/dist-es/accordion/AccordionDetails.js +0 -83
  77. package/dist-es/accordion/AccordionDetails.js.map +0 -1
  78. package/dist-es/accordion/AccordionSection.js +0 -107
  79. package/dist-es/accordion/AccordionSection.js.map +0 -1
  80. package/dist-es/accordion/AccordionSectionContext.js +0 -19
  81. package/dist-es/accordion/AccordionSectionContext.js.map +0 -1
  82. package/dist-es/accordion/AccordionSummary.js +0 -60
  83. package/dist-es/accordion/AccordionSummary.js.map +0 -1
  84. package/dist-es/accordion/utils.js +0 -4
  85. package/dist-es/accordion/utils.js.map +0 -1
  86. package/dist-types/accordion/AccordionDetails.d.ts +0 -8
  87. package/dist-types/accordion/AccordionSection.d.ts +0 -9
  88. package/dist-types/accordion/AccordionSectionContext.d.ts +0 -8
  89. package/dist-types/accordion/AccordionSummary.d.ts +0 -5
  90. package/dist-types/accordion/utils.d.ts +0 -1
@@ -1,5 +1,4 @@
1
- export * from "./AccordionSection";
2
- export * from "./AccordionSectionContext";
1
+ export * from "./AccordionGroup";
2
+ export * from "./AccordionPanel";
3
3
  export * from "./Accordion";
4
- export * from "./AccordionSummary";
5
- export * from "./AccordionDetails";
4
+ export * from "./AccordionHeader";
@@ -32,6 +32,7 @@ export * from "./list-next";
32
32
  export * from "./logo";
33
33
  export * from "./menu-button";
34
34
  export * from "./metric";
35
+ export * from "./multiline-input";
35
36
  export * from "./nav-item";
36
37
  export * from "./overlay";
37
38
  export * from "./pagination";
@@ -0,0 +1,40 @@
1
+ import { ComponentPropsWithoutRef, ReactNode, Ref, TextareaHTMLAttributes } from "react";
2
+ export interface MultilineInputProps extends Omit<ComponentPropsWithoutRef<"div">, "defaultValue">, Pick<ComponentPropsWithoutRef<"input">, "disabled" | "value" | "defaultValue" | "placeholder"> {
3
+ /**
4
+ * End adornment component
5
+ */
6
+ endAdornment?: ReactNode;
7
+ /**
8
+ * Styling variant with full border. Defaults to false
9
+ */
10
+ fullBorder?: boolean;
11
+ /**
12
+ * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#Attributes) applied to the `textarea` element.
13
+ */
14
+ textAreaProps?: TextareaHTMLAttributes<HTMLTextAreaElement>;
15
+ /**
16
+ * Optional ref for the textarea component
17
+ */
18
+ textAreaRef?: Ref<HTMLTextAreaElement>;
19
+ /**
20
+ * If `true`, the component is read only.
21
+ */
22
+ readOnly?: boolean;
23
+ /**
24
+ * Start adornment component
25
+ */
26
+ startAdornment?: ReactNode;
27
+ /**
28
+ * Validation status.
29
+ */
30
+ validationStatus?: "error" | "warning" | "success";
31
+ /**
32
+ * Styling variant. Defaults to "primary".
33
+ */
34
+ variant?: "primary" | "secondary";
35
+ /**
36
+ * Number of rows. Defaults to 3
37
+ */
38
+ rows?: number;
39
+ }
40
+ export declare const MultilineInput: import("react").ForwardRefExoticComponent<MultilineInputProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1 @@
1
+ export * from "./MultilineInput";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salt-ds/lab",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.12",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist-cjs/index.js",
6
6
  "sideEffects": false,
@@ -21,14 +21,14 @@
21
21
  "module": "dist-es/index.js",
22
22
  "typings": "dist-types/index.d.ts",
23
23
  "dependencies": {
24
- "@salt-ds/core": "^1.8.0-rc.2",
24
+ "@salt-ds/core": "^1.8.0-rc.3",
25
25
  "clsx": "^1.2.1",
26
26
  "react-window": "^1.8.6",
27
27
  "compute-scroll-into-view": "^3.0.0",
28
28
  "@floating-ui/react": "^0.23.0",
29
29
  "@salt-ds/window": "^0.1.0",
30
30
  "@salt-ds/styles": "^0.1.0",
31
- "@salt-ds/icons": "^1.4.0",
31
+ "@salt-ds/icons": "^1.5.0",
32
32
  "@internationalized/date": "^3.0.0",
33
33
  "tinycolor2": "^1.4.2",
34
34
  "react-color": "^2.19.3",
@@ -1,87 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var jsxRuntime = require('react/jsx-runtime');
6
- var core = require('@salt-ds/core');
7
- var clsx = require('clsx');
8
- var React = require('react');
9
- var AccordionSectionContext = require('./AccordionSectionContext.js');
10
- var Accordion = require('./Accordion.css.js');
11
- var window = require('@salt-ds/window');
12
- var styles = require('@salt-ds/styles');
13
-
14
- const withBaseName = core.makePrefixer("saltAccordionDetails");
15
- const msCollapseAnimationDuration = 150;
16
- const AccordionDetails = React.forwardRef(function AccordionDetails2({ children, className, preventUnmountOnCollapse, ...restProps }, ref) {
17
- const targetWindow = window.useWindow();
18
- styles.useComponentCssInjection({
19
- testId: "salt-accordion",
20
- css: Accordion,
21
- window: targetWindow
22
- });
23
- const { isDisabled, isExpanded } = AccordionSectionContext.useAccordionSectionContext();
24
- const rootRef = React.useRef(null);
25
- const contentRef = React.useRef(null);
26
- const forkedRef = core.useForkRef(ref, rootRef);
27
- const [state, setState] = React.useState(
28
- isExpanded ? "expanded" : "collapsed"
29
- );
30
- core.useIsomorphicLayoutEffect(() => {
31
- if (!rootRef.current) {
32
- return;
33
- }
34
- if (isExpanded) {
35
- if (state === "collapsed") {
36
- setState("measuring");
37
- } else if (state === "measuring") {
38
- rootRef.current.style.height = `${contentRef.current.getBoundingClientRect().height}px`;
39
- setState("expanding");
40
- } else if (state === "expanding") {
41
- setTimeout(() => {
42
- setState("expanded");
43
- }, msCollapseAnimationDuration);
44
- } else if (state === "expanded") {
45
- rootRef.current.style.height = "auto";
46
- }
47
- } else {
48
- if (state === "expanded") {
49
- rootRef.current.style.height = `${rootRef.current.getBoundingClientRect().height}px`;
50
- setTimeout(() => {
51
- setState("collapsing");
52
- }, 0);
53
- } else if (state === "collapsing") {
54
- rootRef.current.style.height = "0";
55
- setTimeout(() => {
56
- setState("collapsed");
57
- }, msCollapseAnimationDuration);
58
- } else if (state === "collapsed") {
59
- rootRef.current.style.height = "0";
60
- }
61
- }
62
- }, [isExpanded, state]);
63
- return /* @__PURE__ */ jsxRuntime.jsx("div", {
64
- ...restProps,
65
- ref: forkedRef,
66
- className: clsx.clsx(
67
- withBaseName(),
68
- {
69
- [withBaseName("disabled")]: isDisabled
70
- },
71
- className
72
- ),
73
- children: /* @__PURE__ */ jsxRuntime.jsx("div", {
74
- ref: contentRef,
75
- className: clsx.clsx({
76
- [withBaseName("dummy")]: state === "measuring"
77
- }),
78
- children: preventUnmountOnCollapse || state !== "collapsed" ? /* @__PURE__ */ jsxRuntime.jsx("div", {
79
- className: withBaseName("content"),
80
- children
81
- }) : null
82
- })
83
- });
84
- });
85
-
86
- exports.AccordionDetails = AccordionDetails;
87
- //# sourceMappingURL=AccordionDetails.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccordionDetails.js","sources":["../src/accordion/AccordionDetails.tsx"],"sourcesContent":["import {\n makePrefixer,\n useForkRef,\n useIsomorphicLayoutEffect,\n} from \"@salt-ds/core\";\nimport { clsx } from \"clsx\";\nimport { forwardRef, HTMLAttributes, useRef, useState } from \"react\";\nimport { useAccordionSectionContext } from \"./AccordionSectionContext\";\n\nimport accordionCss from \"./Accordion.css\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\n\nconst withBaseName = makePrefixer(\"saltAccordionDetails\");\n\nexport interface AccordionDetailsProps extends HTMLAttributes<HTMLDivElement> {\n /**\n * Render children even if the component is collapsed. Prevents unmounting of children components.\n * */\n preventUnmountOnCollapse?: boolean;\n}\n\nconst msCollapseAnimationDuration = 150;\n\n// Collapsed - the section is completely collapsed, don't render anything, height is 0\n// Measuring - the section is about to expand, rendering a dummy preview to measure\n// the height of expanded section\n// Expanding - the section is expanding but hasn't yet expanded to full size. height is set to\n// the value measured in the previous step\n// Expanded - the section is expanded, need to render the content, height is set to auto\n// Collapsing - the section is about to start collapsing, the height is set to current height\n// (auto has to be replaced by a number, then the component has to be rendered, then the value can\n// be set to 0)\ntype State =\n | \"collapsed\"\n | \"measuring\"\n | \"expanding\"\n | \"expanded\"\n | \"collapsing\";\n\nexport const AccordionDetails = forwardRef<\n HTMLDivElement,\n AccordionDetailsProps\n>(function AccordionDetails(\n { children, className, preventUnmountOnCollapse, ...restProps },\n ref\n) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-accordion\",\n css: accordionCss,\n window: targetWindow,\n });\n\n const { isDisabled, isExpanded } = useAccordionSectionContext();\n const rootRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const forkedRef = useForkRef(ref, rootRef);\n\n const [state, setState] = useState<State>(\n isExpanded ? \"expanded\" : \"collapsed\"\n );\n\n useIsomorphicLayoutEffect(() => {\n if (!rootRef.current) {\n return;\n }\n if (isExpanded) {\n if (state === \"collapsed\") {\n setState(\"measuring\");\n } else if (state === \"measuring\") {\n rootRef.current.style.height = `${\n contentRef.current!.getBoundingClientRect().height\n }px`;\n setState(\"expanding\");\n } else if (state === \"expanding\") {\n setTimeout(() => {\n setState(\"expanded\");\n }, msCollapseAnimationDuration);\n } else if (state === \"expanded\") {\n rootRef.current.style.height = \"auto\";\n }\n } else {\n if (state === \"expanded\") {\n rootRef.current.style.height = `${\n rootRef.current.getBoundingClientRect().height\n }px`;\n setTimeout(() => {\n setState(\"collapsing\");\n }, 0);\n } else if (state === \"collapsing\") {\n rootRef.current.style.height = \"0\";\n setTimeout(() => {\n setState(\"collapsed\");\n }, msCollapseAnimationDuration);\n } else if (state === \"collapsed\") {\n rootRef.current.style.height = \"0\";\n }\n }\n }, [isExpanded, state]);\n\n return (\n <div\n {...restProps}\n ref={forkedRef}\n className={clsx(\n withBaseName(),\n {\n [withBaseName(\"disabled\")]: isDisabled,\n },\n className\n )}\n >\n <div\n ref={contentRef}\n className={clsx({\n [withBaseName(\"dummy\")]: state === \"measuring\",\n })}\n >\n {preventUnmountOnCollapse || state !== \"collapsed\" ? (\n <div className={withBaseName(\"content\")}>{children}</div>\n ) : null}\n </div>\n </div>\n );\n});\n"],"names":["makePrefixer","forwardRef","AccordionDetails","useWindow","useComponentCssInjection","accordionCss","useAccordionSectionContext","useRef","useForkRef","useState","useIsomorphicLayoutEffect","jsx","clsx"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,YAAA,GAAeA,kBAAa,sBAAsB,CAAA,CAAA;AASxD,MAAM,2BAA8B,GAAA,GAAA,CAAA;AAkBvB,MAAA,gBAAA,GAAmBC,gBAG9B,CAAA,SAASC,iBACT,CAAA,EAAE,UAAU,SAAW,EAAA,wBAAA,EAAA,GAA6B,SAAU,EAAA,EAC9D,GACA,EAAA;AACA,EAAA,MAAM,eAAeC,gBAAU,EAAA,CAAA;AAC/B,EAAyBC,+BAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,gBAAA;AAAA,IACR,GAAK,EAAAC,SAAA;AAAA,IACL,MAAQ,EAAA,YAAA;AAAA,GACT,CAAA,CAAA;AAED,EAAA,MAAM,EAAE,UAAA,EAAY,UAAW,EAAA,GAAIC,kDAA2B,EAAA,CAAA;AAC9D,EAAM,MAAA,OAAA,GAAUC,aAAuB,IAAI,CAAA,CAAA;AAC3C,EAAM,MAAA,UAAA,GAAaA,aAAuB,IAAI,CAAA,CAAA;AAC9C,EAAM,MAAA,SAAA,GAAYC,eAAW,CAAA,GAAA,EAAK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AAA;AAC/B,QAAA,UAAA,CAAW,MAAM;AACf,UAAA,QAAA,CAAS,WAAW,CAAA,CAAA;AAAA,WACnB,2BAA2B,CAAA,CAAA;AAAA,OAChC,MAAA,IAAW,UAAU,WAAa,EAAA;AAChC,QAAQ,OAAA,CAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,GAAA,CAAA;AAAA,OACjC;AAAA,KACF;AAAA,GACC,EAAA,CAAC,UAAY,EAAA,KAAK,CAAC,CAAA,CAAA;AAEtB,EAAA,uBACGC,cAAA,CAAA,KAAA,EAAA;AAAA,IACE,GAAG,SAAA;AAAA,IACJ,GAAK,EAAA,SAAA;AAAA,IACL,SAAW,EAAAC,SAAA;AAAA,MACT,YAAa,EAAA;AAAA,MACb;AAAA,QACE,CAAC,YAAa,CAAA,UAAU,CAAI,GAAA,UAAA;AAAA,OAC9B;AAAA,MACA,SAAA;AAAA,KACF;AAAA,IAEA,QAAC,kBAAAD,cAAA,CAAA,KAAA,EAAA;AAAA,MACC,GAAK,EAAA,UAAA;AAAA,MACL,WAAWC,SAAK,CAAA;AAAA,QACd,CAAC,YAAA,CAAa,OAAO,CAAA,GAAI,KAAU,KAAA,WAAA;AAAA,OACpC,CAAA;AAAA,MAEA,QAAA,EAAA,wBAAA,IAA4B,KAAU,KAAA,WAAA,mBACpCD,cAAA,CAAA,KAAA,EAAA;AAAA,QAAI,SAAA,EAAW,aAAa,SAAS,CAAA;AAAA,QAAI,QAAA;AAAA,OAAS,CACjD,GAAA,IAAA;AAAA,KACN,CAAA;AAAA,GACF,CAAA,CAAA;AAEJ,CAAC;;;;"}
@@ -1,111 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var jsxRuntime = require('react/jsx-runtime');
6
- var React = require('react');
7
- var core = require('@salt-ds/core');
8
- require('../utils/useFloatingUI.js');
9
- var useLayoutEffectSkipFirst = require('../utils/useLayoutEffectSkipFirst.js');
10
- var AccordionSectionContext = require('./AccordionSectionContext.js');
11
- var clsx = require('clsx');
12
- var AccordionContext = require('./AccordionContext.js');
13
- var utils = require('./utils.js');
14
- var window = require('@salt-ds/window');
15
- var styles = require('@salt-ds/styles');
16
- var Accordion = require('./Accordion.css.js');
17
-
18
- const withBaseName = core.makePrefixer("saltAccordionSection");
19
- const AccordionSection = React.forwardRef(function Accordion$1({
20
- id: idProp,
21
- disabled: disabledProp,
22
- onChange: onChangeProp,
23
- defaultExpanded: defaultExpandedProp,
24
- expanded: expandedProp,
25
- children,
26
- className,
27
- ...restProps
28
- }, ref) {
29
- const targetWindow = window.useWindow();
30
- styles.useComponentCssInjection({
31
- testId: "salt-accordion",
32
- css: Accordion,
33
- window: targetWindow
34
- });
35
- const [id, setId] = React.useState(
36
- () => idProp != null ? idProp : `salt-${Math.round(Math.random() * 1e5)}`
37
- );
38
- if (idProp != null && idProp != id) {
39
- setId(idProp);
40
- }
41
- const {
42
- registerSection,
43
- unregisterSection,
44
- onChange,
45
- isExpanded,
46
- disabled: accordionDisabled
47
- } = AccordionContext.useAccordionContext();
48
- const isControlled = expandedProp != null;
49
- const expanded = isControlled ? expandedProp : isExpanded(id);
50
- const disabled = disabledProp != null ? disabledProp : accordionDisabled;
51
- React.useEffect(() => {
52
- registerSection(
53
- id,
54
- expandedProp != null ? expandedProp : !!defaultExpandedProp
55
- );
56
- return () => {
57
- unregisterSection(id);
58
- };
59
- }, [id, registerSection, unregisterSection]);
60
- const onToggle = React.useCallback(() => {
61
- const newExpanded = !expanded;
62
- if (onChangeProp) {
63
- onChangeProp(newExpanded);
64
- }
65
- if (!isControlled) {
66
- onChange(id, newExpanded);
67
- }
68
- }, [id, expanded, onChangeProp, onChange, isControlled]);
69
- React.useEffect(() => {
70
- const isControlled2 = expandedProp != null;
71
- if (isControlled2) {
72
- onChange(id, expandedProp);
73
- }
74
- }, [expandedProp, isControlled]);
75
- useLayoutEffectSkipFirst.useLayoutEffectSkipFirst(() => {
76
- if (utils.isNotProduction()) {
77
- const mode = (isControlled2) => isControlled2 ? "controlled" : "uncontrolled";
78
- console.error(
79
- `A component is changing from ${mode(!isControlled)} to ${mode(
80
- isControlled
81
- )} mode.`
82
- );
83
- }
84
- }, [isControlled]);
85
- const contextValue = React.useMemo(() => {
86
- return {
87
- isExpanded: expanded,
88
- isDisabled: disabled,
89
- onToggle
90
- };
91
- }, [expanded, disabled, onToggle]);
92
- return /* @__PURE__ */ jsxRuntime.jsx("div", {
93
- ...restProps,
94
- className: clsx.clsx(
95
- withBaseName(),
96
- {
97
- [withBaseName("expanded")]: expanded,
98
- [withBaseName("disabled")]: disabled
99
- },
100
- className
101
- ),
102
- ref,
103
- children: /* @__PURE__ */ jsxRuntime.jsx(AccordionSectionContext.AccordionSectionContext.Provider, {
104
- value: contextValue,
105
- children
106
- })
107
- });
108
- });
109
-
110
- exports.AccordionSection = AccordionSection;
111
- //# sourceMappingURL=AccordionSection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccordionSection.js","sources":["../src/accordion/AccordionSection.tsx"],"sourcesContent":["import {\n forwardRef,\n HTMLAttributes,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { makePrefixer } from \"@salt-ds/core\";\nimport { useLayoutEffectSkipFirst } from \"../utils\";\nimport { AccordionSectionContext } from \"./AccordionSectionContext\";\nimport { clsx } from \"clsx\";\nimport { useAccordionContext } from \"./AccordionContext\";\nimport { isNotProduction } from \"./utils\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\n\nimport accordionCss from \"./Accordion.css\";\n\nconst withBaseName = makePrefixer(\"saltAccordionSection\");\n\nexport interface AccordionSectionProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n defaultExpanded?: boolean;\n disabled?: boolean;\n expanded?: boolean;\n onChange?: (isExpanded: boolean) => void;\n className?: string;\n}\n\nexport const AccordionSection = forwardRef<\n HTMLDivElement,\n AccordionSectionProps\n>(function Accordion(\n {\n id: idProp,\n disabled: disabledProp,\n onChange: onChangeProp,\n defaultExpanded: defaultExpandedProp,\n expanded: expandedProp,\n children,\n className,\n ...restProps\n },\n ref\n) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-accordion\",\n css: accordionCss,\n window: targetWindow,\n });\n\n const [id, setId] = useState(() =>\n idProp != null ? idProp : `salt-${Math.round(Math.random() * 1e5)}`\n );\n\n if (idProp != null && idProp != id) {\n setId(idProp);\n }\n\n const {\n registerSection,\n unregisterSection,\n onChange,\n isExpanded,\n disabled: accordionDisabled,\n } = useAccordionContext();\n\n const isControlled = expandedProp != null;\n const expanded = isControlled ? expandedProp : isExpanded(id);\n const disabled = disabledProp != null ? disabledProp : accordionDisabled;\n\n useEffect(() => {\n registerSection(\n id,\n expandedProp != null ? expandedProp : !!defaultExpandedProp\n );\n return () => {\n unregisterSection(id);\n };\n }, [id, registerSection, unregisterSection]);\n\n const onToggle = useCallback(() => {\n const newExpanded = !expanded;\n if (onChangeProp) {\n onChangeProp(newExpanded);\n }\n if (!isControlled) {\n onChange(id, newExpanded);\n }\n }, [id, expanded, onChangeProp, onChange, isControlled]);\n\n useEffect(() => {\n const isControlled = expandedProp != null;\n if (isControlled) {\n onChange(id, expandedProp);\n }\n }, [expandedProp, isControlled]);\n\n useLayoutEffectSkipFirst(() => {\n if (isNotProduction()) {\n const mode = (isControlled: boolean) =>\n isControlled ? \"controlled\" : \"uncontrolled\";\n console.error(\n `A component is changing from ${mode(!isControlled)} to ${mode(\n isControlled\n )} mode.`\n );\n }\n }, [isControlled]);\n\n const contextValue: AccordionSectionContext = useMemo(() => {\n return {\n isExpanded: expanded,\n isDisabled: disabled,\n onToggle,\n };\n }, [expanded, disabled, onToggle]);\n\n return (\n <div\n {...restProps}\n className={clsx(\n withBaseName(),\n {\n [withBaseName(\"expanded\")]: expanded,\n [withBaseName(\"disabled\")]: disabled,\n },\n className\n )}\n ref={ref}\n >\n <AccordionSectionContext.Provider value={contextValue}>\n {children}\n </AccordionSectionContext.Provider>\n </div>\n );\n});\n"],"names":["makePrefixer","forwardRef","Accordion","useWindow","useComponentCssInjection","accordionCss","useState","useAccordionContext","useEffect","useCallback","isControlled","useLayoutEffectSkipFirst","isNotProduction","useMemo","jsx","clsx","AccordionSectionContext"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAM,YAAA,GAAeA,kBAAa,sBAAsB,CAAA,CAAA;AAW3C,MAAA,gBAAA,GAAmBC,gBAG9B,CAAA,SAASC,WACT,CAAA;AAAA,EACE,EAAI,EAAA,MAAA;AAAA,EACJ,QAAU,EAAA,YAAA;AAAA,EACV,QAAU,EAAA,YAAA;AAAA,EACV,eAAiB,EAAA,mBAAA;AAAA,EACjB,QAAU,EAAA,YAAA;AAAA,EACV,QAAA;AAAA,EACA,SAAA;AAAA,EACG,GAAA,SAAA;AACL,CAAA,EACA,GACA,EAAA;AACA,EAAA,MAAM,eAAeC,gBAAU,EAAA,CAAA;AAC/B,EAAyBC,+BAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,gBAAA;AAAA,IACR,GAAK,EAAAC,SAAA;AAAA,IACL,MAAQ,EAAA,YAAA;AAAA,GACT,CAAA,CAAA;AAED,EAAM,MAAA,CAAC,EAAI,EAAA,KAAK,CAAI,GAAAC,cAAA;AAAA,IAAS,MAC3B,MAAU,IAAA,IAAA,GAAO,MAAS,GAAA,CAAA,KAAA,EAAQ,KAAK,KAAM,CAAA,IAAA,CAAK,MAAO,EAAA,GAAI,GAAG,CAAA,CAAA,CAAA;AAAA,GAClE,CAAA;AAEA,EAAI,IAAA,MAAA,IAAU,IAAQ,IAAA,MAAA,IAAU,EAAI,EAAA;AAClC,IAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AAAA,GACd;AAEA,EAAM,MAAA;AAAA,IACJ,eAAA;AAAA,IACA,iBAAA;AAAA,IACA,QAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAU,EAAA,iBAAA;AAAA,MACRC,oCAAoB,EAAA,CAAA;AAExB,EAAA,M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YAAe,GAAA,cAAA,CAAA;AAChC,MAAQ,OAAA,CAAA,KAAA;AAAA,QACN,CAAgC,6BAAA,EAAA,IAAA,CAAK,CAAC,YAAY,CAAQ,CAAA,IAAA,EAAA,IAAA;AAAA,UACxD,YAAA;AAAA,SACF,CAAA,MAAA,CAAA;AAAA,OACF,CAAA;AAAA,KACF;AAAA,GACF,EAAG,CAAC,YAAY,CAAC,CAAA,CAAA;AAEjB,EAAM,MAAA,YAAA,GAAwCG,cAAQ,MAAM;AAC1D,IAAO,OAAA;AAAA,MACL,UAAY,EAAA,QAAA;AAAA,MACZ,UAAY,EAAA,QAAA;AAAA,MACZ,QAAA;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,QAAU,EAAA,QAAA,EAAU,QAAQ,CAAC,CAAA,CAAA;AAEjC,EAAA,uBACGC,cAAA,CAAA,KAAA,EAAA;AAAA,IACE,GAAG,SAAA;AAAA,IACJ,SAAW,EAAAC,SAAA;AAAA,MACT,YAAa,EAAA;AAAA,MACb;AAAA,QACE,CAAC,YAAa,CAAA,UAAU,CAAI,GAAA,QAAA;AAAA,QAC5B,CAAC,YAAa,CAAA,UAAU,CAAI,GAAA,QAAA;AAAA,OAC9B;AAAA,MACA,SAAA;AAAA,KACF;AAAA,IACA,GAAA;AAAA,IAEA,QAAA,kBAAAD,cAAA,CAACE,gDAAwB,QAAxB,EAAA;AAAA,MAAiC,KAAO,EAAA,YAAA;AAAA,MACtC,QAAA;AAAA,KACH,CAAA;AAAA,GACF,CAAA,CAAA;AAEJ,CAAC;;;;"}
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- var utils = require('./utils.js');
7
-
8
- const AccordionSectionContext = React.createContext(void 0);
9
- if (utils.isNotProduction()) {
10
- AccordionSectionContext.displayName = "AccordionSectionContext";
11
- }
12
- const useAccordionSectionContext = () => {
13
- const context = React.useContext(AccordionSectionContext);
14
- if (utils.isNotProduction() && !context) {
15
- console.error(
16
- "useAccordionSectionContext should be used inside of AccordionSection"
17
- );
18
- }
19
- return context;
20
- };
21
-
22
- exports.AccordionSectionContext = AccordionSectionContext;
23
- exports.useAccordionSectionContext = useAccordionSectionContext;
24
- //# sourceMappingURL=AccordionSectionContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccordionSectionContext.js","sources":["../src/accordion/AccordionSectionContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { isNotProduction } from \"./utils\";\n\nexport interface AccordionSectionContext {\n isDisabled?: boolean;\n isExpanded: boolean;\n onToggle: () => void;\n}\n\nexport const AccordionSectionContext = createContext<\n AccordionSectionContext | undefined\n>(undefined);\n\nif (isNotProduction()) {\n AccordionSectionContext.displayName = \"AccordionSectionContext\";\n}\n\nexport const useAccordionSectionContext = () => {\n const context = useContext(AccordionSectionContext);\n if (isNotProduction() && !context) {\n console.error(\n \"useAccordionSectionContext should be used inside of AccordionSection\"\n );\n }\n return context!;\n};\n"],"names":["createContext","isNotProduction","useContext"],"mappings":";;;;;;;AASa,MAAA,uBAAA,GAA0BA,oBAErC,KAAS,CAAA,EAAA;AAEX,IAAIC,uBAAmB,EAAA;AACrB,EAAA,uBAAA,CAAwB,WAAc,GAAA,yBAAA,CAAA;AACxC,CAAA;AAEO,MAAM,6BAA6B,MAAM;AAC9C,EAAM,MAAA,OAAA,GAAUC,iBAAW,uBAAuB,CAAA,CAAA;AAClD,EAAI,IAAAD,qBAAA,EAAqB,IAAA,CAAC,OAAS,EAAA;AACjC,IAAQ,OAAA,CAAA,KAAA;AAAA,MACN,sEAAA;AAAA,KACF,CAAA;AAAA,GACF;AACA,EAAO,OAAA,OAAA,CAAA;AACT;;;;;"}
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var jsxRuntime = require('react/jsx-runtime');
6
- var React = require('react');
7
- var clsx = require('clsx');
8
- var core = require('@salt-ds/core');
9
- var icons = require('@salt-ds/icons');
10
- var AccordionSectionContext = require('./AccordionSectionContext.js');
11
- var window = require('@salt-ds/window');
12
- var styles = require('@salt-ds/styles');
13
- var Accordion = require('./Accordion.css.js');
14
-
15
- const withBaseName = core.makePrefixer("saltAccordionSummary");
16
- const AccordionSummary = React.forwardRef(function AccordionSummary2({ className, children, icon, ...restProps }, ref) {
17
- const targetWindow = window.useWindow();
18
- styles.useComponentCssInjection({
19
- testId: "salt-accordion",
20
- css: Accordion,
21
- window: targetWindow
22
- });
23
- const { isDisabled, isExpanded, onToggle } = AccordionSectionContext.useAccordionSectionContext();
24
- const onKeyDown = React.useCallback(
25
- ({ key }) => {
26
- if (key === "Enter" || key === " ") {
27
- onToggle();
28
- }
29
- },
30
- [onToggle]
31
- );
32
- if (!icon) {
33
- icon = /* @__PURE__ */ jsxRuntime.jsx(icons.ChevronRightIcon, {
34
- "aria-hidden": true
35
- });
36
- }
37
- return /* @__PURE__ */ jsxRuntime.jsxs("div", {
38
- ...restProps,
39
- className: clsx.clsx(
40
- withBaseName(),
41
- {
42
- [withBaseName("disabled")]: isDisabled,
43
- [withBaseName("expanded")]: isExpanded
44
- },
45
- className
46
- ),
47
- ref,
48
- role: "button",
49
- "aria-expanded": isExpanded,
50
- onClick: isDisabled ? void 0 : onToggle,
51
- onKeyDown: isDisabled ? void 0 : onKeyDown,
52
- tabIndex: isDisabled ? -1 : 0,
53
- children: [
54
- /* @__PURE__ */ jsxRuntime.jsx("div", {
55
- className: withBaseName("icon"),
56
- children: icon
57
- }),
58
- children
59
- ]
60
- });
61
- });
62
-
63
- exports.AccordionSummary = AccordionSummary;
64
- //# sourceMappingURL=AccordionSummary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccordionSummary.js","sources":["../src/accordion/AccordionSummary.tsx"],"sourcesContent":["import {\n forwardRef,\n HTMLAttributes,\n KeyboardEventHandler,\n ReactNode,\n useCallback,\n} from \"react\";\nimport { clsx } from \"clsx\";\nimport { makePrefixer } from \"@salt-ds/core\";\nimport { ChevronRightIcon } from \"@salt-ds/icons\";\nimport { useAccordionSectionContext } from \"./AccordionSectionContext\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\n\nimport accordionCss from \"./Accordion.css\";\n\nconst withBaseName = makePrefixer(\"saltAccordionSummary\");\n\nexport interface AccordionSummaryProps extends HTMLAttributes<HTMLDivElement> {\n icon?: ReactNode;\n}\n\nexport const AccordionSummary = forwardRef<\n HTMLDivElement,\n AccordionSummaryProps\n>(function AccordionSummary({ className, children, icon, ...restProps }, ref) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-accordion\",\n css: accordionCss,\n window: targetWindow,\n });\n\n const { isDisabled, isExpanded, onToggle } = useAccordionSectionContext();\n\n const onKeyDown: KeyboardEventHandler<HTMLDivElement> = useCallback(\n ({ key }) => {\n if (key === \"Enter\" || key === \" \") {\n onToggle();\n }\n },\n [onToggle]\n );\n\n if (!icon) {\n icon = <ChevronRightIcon aria-hidden />;\n }\n\n return (\n <div\n {...restProps}\n className={clsx(\n withBaseName(),\n {\n [withBaseName(\"disabled\")]: isDisabled,\n [withBaseName(\"expanded\")]: isExpanded,\n },\n className\n )}\n ref={ref}\n role=\"button\"\n aria-expanded={isExpanded}\n onClick={isDisabled ? undefined : onToggle}\n onKeyDown={isDisabled ? undefined : onKeyDown}\n tabIndex={isDisabled ? -1 : 0}\n >\n <div className={withBaseName(\"icon\")}>{icon}</div>\n {children}\n </div>\n );\n});\n"],"names":["makePrefixer","forwardRef","AccordionSummary","useWindow","useComponentCssInjection","accordionCss","useAccordionSectionContext","useCallback","jsx","ChevronRightIcon","jsxs","clsx"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,YAAA,GAAeA,kBAAa,sBAAsB,CAAA,CAAA;AAM3C,MAAA,gBAAA,GAAmBC,gBAG9B,CAAA,SAASC,iBAAiB,CAAA,EAAE,WAAW,QAAU,EAAA,IAAA,EAAA,GAAS,SA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AAA,EAAA;AAAA,sBAACH,cAAA,CAAA,KAAA,EAAA;AAAA,QAAI,SAAA,EAAW,aAAa,MAAM,CAAA;AAAA,QAAI,QAAA,EAAA,IAAA;AAAA,OAAK,CAAA;AAAA,MAC3C,QAAA;AAAA,KAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAC;;;;"}
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const isNotProduction = () => process.env.NODE_ENV !== "production";
6
-
7
- exports.isNotProduction = isNotProduction;
8
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sources":["../src/accordion/utils.ts"],"sourcesContent":["export const isNotProduction = () => process.env.NODE_ENV !== \"production\";\n"],"names":[],"mappings":";;;;AAAO,MAAM,eAAkB,GAAA,MAAM,OAAQ,CAAA,GAAA,CAAI,QAAa,KAAA;;;;"}
@@ -1,83 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { makePrefixer, useForkRef, useIsomorphicLayoutEffect } from '@salt-ds/core';
3
- import { clsx } from 'clsx';
4
- import { forwardRef, useRef, useState } from 'react';
5
- import { useAccordionSectionContext } from './AccordionSectionContext.js';
6
- import css_248z from './Accordion.css.js';
7
- import { useWindow } from '@salt-ds/window';
8
- import { useComponentCssInjection } from '@salt-ds/styles';
9
-
10
- const withBaseName = makePrefixer("saltAccordionDetails");
11
- const msCollapseAnimationDuration = 150;
12
- const AccordionDetails = forwardRef(function AccordionDetails2({ children, className, preventUnmountOnCollapse, ...restProps }, ref) {
13
- const targetWindow = useWindow();
14
- useComponentCssInjection({
15
- testId: "salt-accordion",
16
- css: css_248z,
17
- window: targetWindow
18
- });
19
- const { isDisabled, isExpanded } = useAccordionSectionContext();
20
- const rootRef = useRef(null);
21
- const contentRef = useRef(null);
22
- const forkedRef = useForkRef(ref, rootRef);
23
- const [state, setState] = useState(
24
- isExpanded ? "expanded" : "collapsed"
25
- );
26
- useIsomorphicLayoutEffect(() => {
27
- if (!rootRef.current) {
28
- return;
29
- }
30
- if (isExpanded) {
31
- if (state === "collapsed") {
32
- setState("measuring");
33
- } else if (state === "measuring") {
34
- rootRef.current.style.height = `${contentRef.current.getBoundingClientRect().height}px`;
35
- setState("expanding");
36
- } else if (state === "expanding") {
37
- setTimeout(() => {
38
- setState("expanded");
39
- }, msCollapseAnimationDuration);
40
- } else if (state === "expanded") {
41
- rootRef.current.style.height = "auto";
42
- }
43
- } else {
44
- if (state === "expanded") {
45
- rootRef.current.style.height = `${rootRef.current.getBoundingClientRect().height}px`;
46
- setTimeout(() => {
47
- setState("collapsing");
48
- }, 0);
49
- } else if (state === "collapsing") {
50
- rootRef.current.style.height = "0";
51
- setTimeout(() => {
52
- setState("collapsed");
53
- }, msCollapseAnimationDuration);
54
- } else if (state === "collapsed") {
55
- rootRef.current.style.height = "0";
56
- }
57
- }
58
- }, [isExpanded, state]);
59
- return /* @__PURE__ */ jsx("div", {
60
- ...restProps,
61
- ref: forkedRef,
62
- className: clsx(
63
- withBaseName(),
64
- {
65
- [withBaseName("disabled")]: isDisabled
66
- },
67
- className
68
- ),
69
- children: /* @__PURE__ */ jsx("div", {
70
- ref: contentRef,
71
- className: clsx({
72
- [withBaseName("dummy")]: state === "measuring"
73
- }),
74
- children: preventUnmountOnCollapse || state !== "collapsed" ? /* @__PURE__ */ jsx("div", {
75
- className: withBaseName("content"),
76
- children
77
- }) : null
78
- })
79
- });
80
- });
81
-
82
- export { AccordionDetails };
83
- //# sourceMappingURL=AccordionDetails.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccordionDetails.js","sources":["../src/accordion/AccordionDetails.tsx"],"sourcesContent":["import {\n makePrefixer,\n useForkRef,\n useIsomorphicLayoutEffect,\n} from \"@salt-ds/core\";\nimport { clsx } from \"clsx\";\nimport { forwardRef, HTMLAttributes, useRef, useState } from \"react\";\nimport { useAccordionSectionContext } from \"./AccordionSectionContext\";\n\nimport accordionCss from \"./Accordion.css\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\n\nconst withBaseName = makePrefixer(\"saltAccordionDetails\");\n\nexport interface AccordionDetailsProps extends HTMLAttributes<HTMLDivElement> {\n /**\n * Render children even if the component is collapsed. Prevents unmounting of children components.\n * */\n preventUnmountOnCollapse?: boolean;\n}\n\nconst msCollapseAnimationDuration = 150;\n\n// Collapsed - the section is completely collapsed, don't render anything, height is 0\n// Measuring - the section is about to expand, rendering a dummy preview to measure\n// the height of expanded section\n// Expanding - the section is expanding but hasn't yet expanded to full size. height is set to\n// the value measured in the previous step\n// Expanded - the section is expanded, need to render the content, height is set to auto\n// Collapsing - the section is about to start collapsing, the height is set to current height\n// (auto has to be replaced by a number, then the component has to be rendered, then the value can\n// be set to 0)\ntype State =\n | \"collapsed\"\n | \"measuring\"\n | \"expanding\"\n | \"expanded\"\n | \"collapsing\";\n\nexport const AccordionDetails = forwardRef<\n HTMLDivElement,\n AccordionDetailsProps\n>(function AccordionDetails(\n { children, className, preventUnmountOnCollapse, ...restProps },\n ref\n) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-accordion\",\n css: accordionCss,\n window: targetWindow,\n });\n\n const { isDisabled, isExpanded } = useAccordionSectionContext();\n const rootRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const forkedRef = useForkRef(ref, rootRef);\n\n const [state, setState] = useState<State>(\n isExpanded ? \"expanded\" : \"collapsed\"\n );\n\n useIsomorphicLayoutEffect(() => {\n if (!rootRef.current) {\n return;\n }\n if (isExpanded) {\n if (state === \"collapsed\") {\n setState(\"measuring\");\n } else if (state === \"measuring\") {\n rootRef.current.style.height = `${\n contentRef.current!.getBoundingClientRect().height\n }px`;\n setState(\"expanding\");\n } else if (state === \"expanding\") {\n setTimeout(() => {\n setState(\"expanded\");\n }, msCollapseAnimationDuration);\n } else if (state === \"expanded\") {\n rootRef.current.style.height = \"auto\";\n }\n } else {\n if (state === \"expanded\") {\n rootRef.current.style.height = `${\n rootRef.current.getBoundingClientRect().height\n }px`;\n setTimeout(() => {\n setState(\"collapsing\");\n }, 0);\n } else if (state === \"collapsing\") {\n rootRef.current.style.height = \"0\";\n setTimeout(() => {\n setState(\"collapsed\");\n }, msCollapseAnimationDuration);\n } else if (state === \"collapsed\") {\n rootRef.current.style.height = \"0\";\n }\n }\n }, [isExpanded, state]);\n\n return (\n <div\n {...restProps}\n ref={forkedRef}\n className={clsx(\n withBaseName(),\n {\n [withBaseName(\"disabled\")]: isDisabled,\n },\n className\n )}\n >\n <div\n ref={contentRef}\n className={clsx({\n [withBaseName(\"dummy\")]: state === \"measuring\",\n })}\n >\n {preventUnmountOnCollapse || state !== \"collapsed\" ? (\n <div className={withBaseName(\"content\")}>{children}</div>\n ) : null}\n </div>\n </div>\n );\n});\n"],"names":["AccordionDetails","accordionCss"],"mappings":";;;;;;;;;AAaA,MAAM,YAAA,GAAe,aAAa,sBAAsB,CAAA,CAAA;AASxD,MAAM,2BAA8B,GAAA,GAAA,CAAA;AAkBvB,MAAA,gBAAA,GAAmB,UAG9B,CAAA,SAASA,iBACT,CAAA,EAAE,UAAU,SAAW,EAAA,wBAAA,EAAA,GAA6B,SAAU,EAAA,EAC9D,GACA,EAAA;AACA,EAAA,MAAM,eAAe,SAAU,EAAA,CAAA;AAC/B,EAAyB,wBAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,gBAAA;AAAA,IACR,GAAK,EAAAC,QAAA;AAAA,IACL,MAAQ,EAAA,YAAA;AAAA,GACT,CAAA,CAAA;AAED,EAAA,MAAM,EAAE,UAAA,EAAY,UAAW,EAAA,GAAI,0BAA2B,EAAA,CAAA;AAC9D,EAAM,MAAA,OAAA,GAAU,OAAuB,IAAI,CAAA,CAAA;AAC3C,EAAM,MAAA,UAAA,GAAa,OAAuB,IAAI,CAAA,CAAA;AAC9C,EAAM,MAAA,SAAA,GAAY,UAAW,CAAA,GAAA,EAAK,OAAO,CAA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AAA,UAAA,CAAW,MAAM;AACf,UAAA,QAAA,CAAS,WAAW,CAAA,CAAA;AAAA,WACnB,2BAA2B,CAAA,CAAA;AAAA,OAChC,MAAA,IAAW,UAAU,WAAa,EAAA;AAChC,QAAQ,OAAA,CAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,GAAA,CAAA;AAAA,OACjC;AAAA,KACF;AAAA,GACC,EAAA,CAAC,UAAY,EAAA,KAAK,CAAC,CAAA,CAAA;AAEtB,EAAA,uBACG,GAAA,CAAA,KAAA,EAAA;AAAA,IACE,GAAG,SAAA;AAAA,IACJ,GAAK,EAAA,SAAA;AAAA,IACL,SAAW,EAAA,IAAA;AAAA,MACT,YAAa,EAAA;AAAA,MACb;AAAA,QACE,CAAC,YAAa,CAAA,UAAU,CAAI,GAAA,UAAA;AAAA,OAC9B;AAAA,MACA,SAAA;AAAA,KACF;AAAA,IAEA,QAAC,kBAAA,GAAA,CAAA,KAAA,EAAA;AAAA,MACC,GAAK,EAAA,UAAA;AAAA,MACL,WAAW,IAAK,CAAA;AAAA,QACd,CAAC,YAAA,CAAa,OAAO,CAAA,GAAI,KAAU,KAAA,WAAA;AAAA,OACpC,CAAA;AAAA,MAEA,QAAA,EAAA,wBAAA,IAA4B,KAAU,KAAA,WAAA,mBACpC,GAAA,CAAA,KAAA,EAAA;AAAA,QAAI,SAAA,EAAW,aAAa,SAAS,CAAA;AAAA,QAAI,QAAA;AAAA,OAAS,CACjD,GAAA,IAAA;AAAA,KACN,CAAA;AAAA,GACF,CAAA,CAAA;AAEJ,CAAC;;;;"}
@@ -1,107 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useState, useEffect, useCallback, useMemo } from 'react';
3
- import { makePrefixer } from '@salt-ds/core';
4
- import '../utils/useFloatingUI.js';
5
- import { useLayoutEffectSkipFirst } from '../utils/useLayoutEffectSkipFirst.js';
6
- import { AccordionSectionContext } from './AccordionSectionContext.js';
7
- import { clsx } from 'clsx';
8
- import { useAccordionContext } from './AccordionContext.js';
9
- import { isNotProduction } from './utils.js';
10
- import { useWindow } from '@salt-ds/window';
11
- import { useComponentCssInjection } from '@salt-ds/styles';
12
- import css_248z from './Accordion.css.js';
13
-
14
- const withBaseName = makePrefixer("saltAccordionSection");
15
- const AccordionSection = forwardRef(function Accordion({
16
- id: idProp,
17
- disabled: disabledProp,
18
- onChange: onChangeProp,
19
- defaultExpanded: defaultExpandedProp,
20
- expanded: expandedProp,
21
- children,
22
- className,
23
- ...restProps
24
- }, ref) {
25
- const targetWindow = useWindow();
26
- useComponentCssInjection({
27
- testId: "salt-accordion",
28
- css: css_248z,
29
- window: targetWindow
30
- });
31
- const [id, setId] = useState(
32
- () => idProp != null ? idProp : `salt-${Math.round(Math.random() * 1e5)}`
33
- );
34
- if (idProp != null && idProp != id) {
35
- setId(idProp);
36
- }
37
- const {
38
- registerSection,
39
- unregisterSection,
40
- onChange,
41
- isExpanded,
42
- disabled: accordionDisabled
43
- } = useAccordionContext();
44
- const isControlled = expandedProp != null;
45
- const expanded = isControlled ? expandedProp : isExpanded(id);
46
- const disabled = disabledProp != null ? disabledProp : accordionDisabled;
47
- useEffect(() => {
48
- registerSection(
49
- id,
50
- expandedProp != null ? expandedProp : !!defaultExpandedProp
51
- );
52
- return () => {
53
- unregisterSection(id);
54
- };
55
- }, [id, registerSection, unregisterSection]);
56
- const onToggle = useCallback(() => {
57
- const newExpanded = !expanded;
58
- if (onChangeProp) {
59
- onChangeProp(newExpanded);
60
- }
61
- if (!isControlled) {
62
- onChange(id, newExpanded);
63
- }
64
- }, [id, expanded, onChangeProp, onChange, isControlled]);
65
- useEffect(() => {
66
- const isControlled2 = expandedProp != null;
67
- if (isControlled2) {
68
- onChange(id, expandedProp);
69
- }
70
- }, [expandedProp, isControlled]);
71
- useLayoutEffectSkipFirst(() => {
72
- if (isNotProduction()) {
73
- const mode = (isControlled2) => isControlled2 ? "controlled" : "uncontrolled";
74
- console.error(
75
- `A component is changing from ${mode(!isControlled)} to ${mode(
76
- isControlled
77
- )} mode.`
78
- );
79
- }
80
- }, [isControlled]);
81
- const contextValue = useMemo(() => {
82
- return {
83
- isExpanded: expanded,
84
- isDisabled: disabled,
85
- onToggle
86
- };
87
- }, [expanded, disabled, onToggle]);
88
- return /* @__PURE__ */ jsx("div", {
89
- ...restProps,
90
- className: clsx(
91
- withBaseName(),
92
- {
93
- [withBaseName("expanded")]: expanded,
94
- [withBaseName("disabled")]: disabled
95
- },
96
- className
97
- ),
98
- ref,
99
- children: /* @__PURE__ */ jsx(AccordionSectionContext.Provider, {
100
- value: contextValue,
101
- children
102
- })
103
- });
104
- });
105
-
106
- export { AccordionSection };
107
- //# sourceMappingURL=AccordionSection.js.map