@drivy/cobalt 0.46.3 → 0.46.4
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.
- package/components/Sidepanel/index.js +59 -0
- package/components/Sidepanel/index.js.map +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types/src/index.d.ts +1 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import cx from 'classnames';
|
|
3
|
+
import Modal from '../Modal/index.js';
|
|
4
|
+
import useBreakpoint from '../../hooks/useBreakpoint.js';
|
|
5
|
+
import '../Icon/index.js';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import CloseIcon from '../Icon/__generated__/CloseIcon.js';
|
|
8
|
+
|
|
9
|
+
const SidepanelFooter = ({ children, className }) => {
|
|
10
|
+
return (React.createElement("div", { className: cx("c-p-sm c-border-t c-border-base", className) }, children));
|
|
11
|
+
};
|
|
12
|
+
// Memoized component to not render content when the panel is collapsing
|
|
13
|
+
function _SidepanelContent({ title, close, children }) {
|
|
14
|
+
return (React.createElement(React.Fragment, null,
|
|
15
|
+
title && (React.createElement("div", { className: "c-flex c-gap-sm c-items-center c-px-sm c-py-md c-border-b c-border-base" },
|
|
16
|
+
React.createElement("div", { className: "c-text-title-md c-flex-1" }, title),
|
|
17
|
+
close && (React.createElement("div", { className: "c-w-md c-cursor-pointer", onClick: close },
|
|
18
|
+
React.createElement(CloseIcon, { size: 24 }))))),
|
|
19
|
+
children));
|
|
20
|
+
}
|
|
21
|
+
function areSidepanelContentEqual(_prevProps, nextProps) {
|
|
22
|
+
return !nextProps.isOpen;
|
|
23
|
+
}
|
|
24
|
+
const SidepanelContent = React.memo(_SidepanelContent, areSidepanelContentEqual);
|
|
25
|
+
SidepanelContent.displayName = "SidepanelContent";
|
|
26
|
+
// Only for the API, render nothing
|
|
27
|
+
const SidepanelFooterAPI = (_props) => null;
|
|
28
|
+
const isSidepanelFooterAPIComponent = (component) => React.isValidElement(component) && component.type === SidepanelFooterAPI;
|
|
29
|
+
const _Sidepanel = ({ isOpen, title, close, children }) => {
|
|
30
|
+
const { isMobile } = useBreakpoint();
|
|
31
|
+
// To display box-shadow when visible. We can't rely on isOpen because it triggers the collapse animation and so the box shadow would not be set during the transition
|
|
32
|
+
const [isPanelVisible, setIsPanelVisible] = useState(false);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
isOpen && setIsPanelVisible(true);
|
|
35
|
+
}, [isOpen]);
|
|
36
|
+
const sidepanelFooter = React.Children.toArray(children).find((c) => isSidepanelFooterAPIComponent(c));
|
|
37
|
+
let footer = null;
|
|
38
|
+
if (React.isValidElement(sidepanelFooter)) {
|
|
39
|
+
footer = isMobile ? (React.createElement(Modal.Footer, { ...sidepanelFooter.props })) : (React.createElement(SidepanelFooter, { ...sidepanelFooter.props }));
|
|
40
|
+
}
|
|
41
|
+
return isMobile ? (React.createElement(Modal, { "aria-label": "Sidepanel", isOpen: isOpen, bodySpacing: false, close: close, title: title },
|
|
42
|
+
children,
|
|
43
|
+
footer)) : (ReactDOM.createPortal(React.createElement("div", { className: cx("cobalt-sidepanel", {
|
|
44
|
+
"cobalt-sidepanel--show": isOpen,
|
|
45
|
+
"cobalt-sidepanel--visible": isPanelVisible,
|
|
46
|
+
}), onTransitionEnd: () => {
|
|
47
|
+
!isOpen && setIsPanelVisible(false);
|
|
48
|
+
} },
|
|
49
|
+
React.createElement(SidepanelContent, { isOpen: isOpen, title: title, close: close },
|
|
50
|
+
children,
|
|
51
|
+
footer)), document.body));
|
|
52
|
+
};
|
|
53
|
+
_Sidepanel.displayName = "Sidepanel";
|
|
54
|
+
const Sidepanel = Object.assign(_Sidepanel, {
|
|
55
|
+
Footer: SidepanelFooterAPI,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export { Sidepanel };
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/Sidepanel/index.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\"\nimport cx from \"classnames\"\nimport Modal from \"../Modal\"\nimport useBreakpoint from \"../../hooks/useBreakpoint\"\nimport { CloseIcon } from \"../Icon\"\nimport ReactDOM from \"react-dom\"\n\ntype SidepanelFooterPropsType = React.PropsWithChildren<{\n className?: string\n}>\n\nconst SidepanelFooter = ({ children, className }: SidepanelFooterPropsType) => {\n return (\n <div className={cx(\"c-p-sm c-border-t c-border-base\", className)}>\n {children}\n </div>\n )\n}\n\ntype SidepanelPropsType = React.PropsWithChildren<{\n isOpen: boolean\n title?: string\n close?: () => void\n}>\n\n// Memoized component to not render content when the panel is collapsing\nfunction _SidepanelContent({ title, close, children }: SidepanelPropsType) {\n return (\n <>\n {title && (\n <div className=\"c-flex c-gap-sm c-items-center c-px-sm c-py-md c-border-b c-border-base\">\n <div className=\"c-text-title-md c-flex-1\">{title}</div>\n {close && (\n <div className=\"c-w-md c-cursor-pointer\" onClick={close}>\n <CloseIcon size={24} />\n </div>\n )}\n </div>\n )}\n {children}\n </>\n )\n}\n\nfunction areSidepanelContentEqual(\n _prevProps: SidepanelPropsType,\n nextProps: SidepanelPropsType\n) {\n return !nextProps.isOpen\n}\n\nconst SidepanelContent = React.memo(_SidepanelContent, areSidepanelContentEqual)\nSidepanelContent.displayName = \"SidepanelContent\"\n\n// Only for the API, render nothing\nconst SidepanelFooterAPI = (_props: SidepanelFooterPropsType) => null\n\nconst isSidepanelFooterAPIComponent = (\n component: React.ReactNode\n): component is React.ReactElement<SidepanelFooterPropsType> =>\n React.isValidElement(component) && component.type === SidepanelFooterAPI\n\nconst _Sidepanel = ({ isOpen, title, close, children }: SidepanelPropsType) => {\n const { isMobile } = useBreakpoint()\n\n // To display box-shadow when visible. We can't rely on isOpen because it triggers the collapse animation and so the box shadow would not be set during the transition\n const [isPanelVisible, setIsPanelVisible] = useState(false)\n\n useEffect(() => {\n isOpen && setIsPanelVisible(true)\n }, [isOpen])\n\n const sidepanelFooter = React.Children.toArray(children).find((c) =>\n isSidepanelFooterAPIComponent(c)\n )\n\n let footer: React.ReactNode = null\n if (React.isValidElement(sidepanelFooter)) {\n footer = isMobile ? (\n <Modal.Footer {...sidepanelFooter.props}></Modal.Footer>\n ) : (\n <SidepanelFooter {...sidepanelFooter.props} />\n )\n }\n\n return isMobile ? (\n <Modal\n aria-label={\"Sidepanel\"}\n isOpen={isOpen}\n bodySpacing={false}\n close={close}\n title={title}\n >\n {children}\n {footer}\n </Modal>\n ) : (\n ReactDOM.createPortal(\n <div\n className={cx(\"cobalt-sidepanel\", {\n \"cobalt-sidepanel--show\": isOpen,\n \"cobalt-sidepanel--visible\": isPanelVisible,\n })}\n onTransitionEnd={() => {\n !isOpen && setIsPanelVisible(false)\n }}\n >\n <SidepanelContent isOpen={isOpen} title={title} close={close}>\n {children}\n {footer}\n </SidepanelContent>\n </div>,\n document.body\n )\n )\n}\n\n_Sidepanel.displayName = \"Sidepanel\"\n\nexport const Sidepanel = Object.assign(_Sidepanel, {\n Footer: SidepanelFooterAPI,\n})\n"],"names":[],"mappings":";;;;;;;;AAWA,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAA4B,KAAI;AAC5E,IAAA,QACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,EAAE,CAAC,iCAAiC,EAAE,SAAS,CAAC,EAAA,EAC7D,QAAQ,CACL,EACP;AACH,CAAC,CAAA;AAQD;AACA,SAAS,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAsB,EAAA;AACvE,IAAA,QACE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA;AACG,QAAA,KAAK,KACJ,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAC,yEAAyE,EAAA;AACtF,YAAA,KAAA,CAAA,aAAA,CAAA,KAAA,E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'./components/PriceTable/index.js';
|
|
|
26
26
|
export { ProgressBar } from './components/ProgressBar/index.js';
|
|
27
27
|
export { ProgressCircular } from './components/ProgressCircular/index.js';
|
|
28
28
|
export { ProgressBanner } from './components/ProgressBanner/index.js';
|
|
29
|
+
export { Sidepanel } from './components/Sidepanel/index.js';
|
|
29
30
|
export { Tab, Tabs } from './components/Tabs/index.js';
|
|
30
31
|
export { Tag } from './components/Tag/index.js';
|
|
31
32
|
export { Chip } from './components/Chip/index.js';
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
package/types/src/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export { PriceTable, PriceTableRow } from "./components/PriceTable";
|
|
|
26
26
|
export { ProgressBar } from "./components/ProgressBar";
|
|
27
27
|
export { ProgressCircular } from "./components/ProgressCircular";
|
|
28
28
|
export { ProgressBanner } from "./components/ProgressBanner";
|
|
29
|
+
export { Sidepanel } from "./components/Sidepanel";
|
|
29
30
|
export { Tabs, Tab } from "./components/Tabs";
|
|
30
31
|
export { Tag } from "./components/Tag";
|
|
31
32
|
export { Chip } from "./components/Chip";
|