cozy-ui 124.1.1 → 125.0.0

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,74 +1,110 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
8
- var _excluded = ["children", "className", "monoColumn"],
9
- _excluded2 = ["children"],
10
- _excluded3 = ["children"];
11
-
12
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
-
14
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
-
4
+ var _excluded = ["children", "className", "monoColumn", "withTopBar"],
5
+ _excluded2 = ["className", "children"],
6
+ _excluded3 = ["className", "children"];
16
7
  import cx from 'classnames';
17
8
  import PropTypes from 'prop-types';
18
- import React, { Component } from 'react';
9
+ import React, { createContext, forwardRef, useContext, useMemo } from 'react';
19
10
  var styles = {
20
11
  "o-layout": "styles__o-layout___3TSz9",
12
+ "o-layout-topbar": "styles__o-layout-topbar___2SHWi",
21
13
  "o-layout-2panes": "styles__o-layout-2panes___1CDQw",
22
- "o-layout--rounded": "styles__o-layout--rounded___1WX4D",
23
- "o-layout-2panes--rounded": "styles__o-layout-2panes--rounded___1FuZT"
14
+ "o-layout-main": "styles__o-layout-main___3mPxz",
15
+ "o-layout-main-monocolumn": "styles__o-layout-main-monocolumn___2a7vz",
16
+ "o-layout-main-monocolumn--topbar": "styles__o-layout-main-monocolumn--topbar___9_4Xd",
17
+ "o-layout-main-2panes": "styles__o-layout-main-2panes___3ickD",
18
+ "o-layout-main-2panes--topbar": "styles__o-layout-main-2panes--topbar___cGi-H",
19
+ "o-layout-content": "styles__o-layout-content___3D5gN",
20
+ "o-layout-content-monocolumn": "styles__o-layout-content-monocolumn___1rpxp",
21
+ "o-layout-content-2panes": "styles__o-layout-content-2panes___2Hotr"
24
22
  };
25
- export var Layout = function Layout(_ref) {
26
- var children = _ref.children,
27
- className = _ref.className,
28
- monoColumn = _ref.monoColumn,
29
- rest = _objectWithoutProperties(_ref, _excluded);
23
+ export var LayoutContext = /*#__PURE__*/createContext();
24
+ export var useLayout = function useLayout() {
25
+ var context = useContext(LayoutContext);
30
26
 
31
- return /*#__PURE__*/React.createElement("div", _extends({
32
- className: cx(monoColumn ? styles['o-layout'] : styles['o-layout-2panes'], className, [styles['o-layout--rounded']])
33
- }, rest), children);
34
- };
35
- export var Main = function Main(_ref2) {
36
- var children = _ref2.children,
37
- rest = _objectWithoutProperties(_ref2, _excluded2);
27
+ if (!context) {
28
+ throw new Error('useLayout must be used within a LayoutContext');
29
+ }
38
30
 
39
- return /*#__PURE__*/React.createElement("main", rest, children);
31
+ return context;
40
32
  };
41
- export var Content = /*#__PURE__*/function (_Component) {
42
- _inherits(Content, _Component);
43
-
44
- var _super = _createSuper(Content);
33
+ var LayoutProvider = /*#__PURE__*/React.memo(function (_ref) {
34
+ var monoColumn = _ref.monoColumn,
35
+ withTopBar = _ref.withTopBar,
36
+ children = _ref.children;
37
+ var value = useMemo(function () {
38
+ return {
39
+ monoColumn: monoColumn,
40
+ withTopBar: withTopBar
41
+ };
42
+ }, [monoColumn, withTopBar]);
43
+ return /*#__PURE__*/React.createElement(LayoutContext.Provider, {
44
+ value: value
45
+ }, children);
46
+ });
47
+ LayoutProvider.displayName = 'LayoutProvider';
48
+ export var Layout = /*#__PURE__*/forwardRef(function (_ref2, ref) {
49
+ var children = _ref2.children,
50
+ className = _ref2.className,
51
+ monoColumn = _ref2.monoColumn,
52
+ withTopBar = _ref2.withTopBar,
53
+ props = _objectWithoutProperties(_ref2, _excluded);
45
54
 
46
- function Content() {
47
- _classCallCheck(this, Content);
55
+ var variant = monoColumn ? 'monocolumn' : '2panes';
56
+ return /*#__PURE__*/React.createElement(LayoutProvider, {
57
+ monoColumn: monoColumn,
58
+ withTopBar: withTopBar
59
+ }, /*#__PURE__*/React.createElement("div", _extends({
60
+ ref: ref,
61
+ className: cx(className, styles['o-layout'], styles["o-layout-".concat(variant)], _defineProperty({}, styles["o-layout-topbar"], withTopBar))
62
+ }, props), children));
63
+ });
64
+ Layout.displayName = 'Layout';
65
+ export var Main = /*#__PURE__*/forwardRef(function (_ref3, ref) {
66
+ var className = _ref3.className,
67
+ children = _ref3.children,
68
+ props = _objectWithoutProperties(_ref3, _excluded2);
48
69
 
49
- return _super.apply(this, arguments);
50
- }
70
+ var _useLayout = useLayout(),
71
+ monoColumn = _useLayout.monoColumn,
72
+ withTopBar = _useLayout.withTopBar;
51
73
 
52
- _createClass(Content, [{
53
- key: "render",
54
- value: function render() {
55
- var _this$props = this.props,
56
- children = _this$props.children,
57
- rest = _objectWithoutProperties(_this$props, _excluded3);
74
+ var variant = monoColumn ? 'monocolumn' : '2panes';
75
+ return /*#__PURE__*/React.createElement("main", _extends({
76
+ ref: ref,
77
+ className: cx(className, styles['o-layout-main'], styles["o-layout-main-".concat(variant)], _defineProperty({}, styles["o-layout-main-".concat(variant, "--topbar")], withTopBar))
78
+ }, props), children);
79
+ });
80
+ Main.displayName = 'Main';
81
+ export var Content = /*#__PURE__*/forwardRef(function (_ref4, ref) {
82
+ var className = _ref4.className,
83
+ children = _ref4.children,
84
+ props = _objectWithoutProperties(_ref4, _excluded3);
58
85
 
59
- return /*#__PURE__*/React.createElement("div", _extends({
60
- role: "main"
61
- }, rest), children);
62
- }
63
- }]);
86
+ var _useLayout2 = useLayout(),
87
+ monoColumn = _useLayout2.monoColumn;
64
88
 
65
- return Content;
66
- }(Component);
89
+ var variant = monoColumn ? 'monocolumn' : '2panes';
90
+ return /*#__PURE__*/React.createElement("div", _extends({
91
+ role: "main",
92
+ ref: ref,
93
+ className: cx(className, styles['o-layout-content'], styles["o-layout-content-".concat(variant)])
94
+ }, props), children);
95
+ });
96
+ Content.displayName = 'Content';
67
97
  Layout.propTypes = {
68
98
  children: PropTypes.node,
69
99
  className: PropTypes.string,
100
+
101
+ /** Used to add/remove top spacing when using with or without a topbar */
102
+ withTopBar: PropTypes.bool,
103
+
104
+ /** Should be true if no sidebar in the app */
70
105
  monoColumn: PropTypes.bool
71
106
  };
72
107
  Layout.defaultProps = {
108
+ withTopBar: true,
73
109
  monoColumn: false
74
110
  };
@@ -7,8 +7,7 @@ import PropTypes from 'prop-types';
7
7
  import React from 'react';
8
8
  var styles = {
9
9
  "o-sidebar": "styles__o-sidebar___1295j",
10
- "o-sidebar--border": "styles__o-sidebar--border___32tfw",
11
- "o-sidebar--large": "styles__o-sidebar--large___1mT8H"
10
+ "o-sidebar--border": "styles__o-sidebar--border___32tfw"
12
11
  };
13
12
  import { useSetFlagshipUI } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
14
13
  import { useCozyTheme } from "cozy-ui/transpiled/react/providers/CozyTheme";
@@ -31,7 +30,7 @@ var Sidebar = function Sidebar(_ref) {
31
30
  }, 'cozy-ui/Sidebar');
32
31
  return /*#__PURE__*/React.createElement("aside", _extends({
33
32
  id: "sidebar",
34
- className: cx(styles['o-sidebar'], [styles['o-sidebar--large']], className)
33
+ className: cx(styles['o-sidebar'], className)
35
34
  }, restProps), children);
36
35
  };
37
36