grommet 2.40.1 → 2.40.2
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.
|
@@ -11,14 +11,21 @@ var _Heading = require("../Heading");
|
|
|
11
11
|
var _AccordionContext = require("../Accordion/AccordionContext");
|
|
12
12
|
var _propTypes = require("./propTypes");
|
|
13
13
|
var _useThemeValue2 = require("../../utils/useThemeValue");
|
|
14
|
-
var _excluded = ["children", "header", "label", "onClick", "onMouseOut", "onMouseOver", "onFocus", "onBlur"];
|
|
14
|
+
var _excluded = ["children", "header", "id", "label", "onClick", "onMouseOut", "onMouseOver", "onFocus", "onBlur"];
|
|
15
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
17
17
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
18
18
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
19
|
+
// Ideally we should use `useId` from react but this is only available
|
|
20
|
+
// in React 18 and we want to keep compatibility with React 17 and 16.
|
|
21
|
+
function getUID() {
|
|
22
|
+
var timestamp = Date.now() + Math.random();
|
|
23
|
+
return "grommet-accordion-button-" + timestamp;
|
|
24
|
+
}
|
|
19
25
|
var AccordionPanel = exports.AccordionPanel = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
20
26
|
var children = _ref.children,
|
|
21
27
|
header = _ref.header,
|
|
28
|
+
id = _ref.id,
|
|
22
29
|
label = _ref.label,
|
|
23
30
|
onClick = _ref.onClick,
|
|
24
31
|
_onMouseOut = _ref.onMouseOut,
|
|
@@ -26,7 +33,7 @@ var AccordionPanel = exports.AccordionPanel = /*#__PURE__*/(0, _react.forwardRef
|
|
|
26
33
|
_onFocus = _ref.onFocus,
|
|
27
34
|
_onBlur = _ref.onBlur,
|
|
28
35
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
29
|
-
var
|
|
36
|
+
var panelButtonId = id ? "grommet_accordion_button_" + id : getUID();
|
|
30
37
|
var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
|
|
31
38
|
theme = _useThemeValue.theme;
|
|
32
39
|
var _useContext = (0, _react.useContext)(_AccordionContext.AccordionContext),
|
|
@@ -78,7 +85,7 @@ var AccordionPanel = exports.AccordionPanel = /*#__PURE__*/(0, _react.forwardRef
|
|
|
78
85
|
border: panelBorder,
|
|
79
86
|
margin: abutMargin
|
|
80
87
|
}, /*#__PURE__*/_react["default"].createElement(_Button.Button, {
|
|
81
|
-
id:
|
|
88
|
+
id: panelButtonId,
|
|
82
89
|
"aria-expanded": active,
|
|
83
90
|
plain: theme.button["default"] ? true : undefined,
|
|
84
91
|
onClick: onPanelChange,
|
|
@@ -107,7 +114,8 @@ var AccordionPanel = exports.AccordionPanel = /*#__PURE__*/(0, _react.forwardRef
|
|
|
107
114
|
}, header || /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({
|
|
108
115
|
align: "center",
|
|
109
116
|
direction: "row",
|
|
110
|
-
justify: "between"
|
|
117
|
+
justify: "between",
|
|
118
|
+
id: id
|
|
111
119
|
}, rest), typeof label === 'string' ? /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
112
120
|
pad: {
|
|
113
121
|
horizontal: 'xsmall'
|
|
@@ -128,7 +136,7 @@ var AccordionPanel = exports.AccordionPanel = /*#__PURE__*/(0, _react.forwardRef
|
|
|
128
136
|
})))), /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
129
137
|
role: "region",
|
|
130
138
|
border: contentBorder,
|
|
131
|
-
"aria-labelledby":
|
|
139
|
+
"aria-labelledby": panelButtonId
|
|
132
140
|
}, animate ? /*#__PURE__*/_react["default"].createElement(_Collapsible.Collapsible, {
|
|
133
141
|
open: active
|
|
134
142
|
}, children) : active && children));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var _excluded = ["children", "header", "label", "onClick", "onMouseOut", "onMouseOver", "onFocus", "onBlur"];
|
|
1
|
+
var _excluded = ["children", "header", "id", "label", "onClick", "onMouseOut", "onMouseOver", "onFocus", "onBlur"];
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
-
import React, { forwardRef, useContext, useMemo, useState
|
|
4
|
+
import React, { forwardRef, useContext, useMemo, useState } from 'react';
|
|
5
5
|
import { normalizeColor, parseMetricToNum } from '../../utils';
|
|
6
6
|
import { Box } from '../Box';
|
|
7
7
|
import { Button } from '../Button';
|
|
@@ -10,9 +10,17 @@ import { Heading } from '../Heading';
|
|
|
10
10
|
import { AccordionContext } from '../Accordion/AccordionContext';
|
|
11
11
|
import { AccordionPanelPropTypes } from './propTypes';
|
|
12
12
|
import { useThemeValue } from '../../utils/useThemeValue';
|
|
13
|
+
|
|
14
|
+
// Ideally we should use `useId` from react but this is only available
|
|
15
|
+
// in React 18 and we want to keep compatibility with React 17 and 16.
|
|
16
|
+
function getUID() {
|
|
17
|
+
var timestamp = Date.now() + Math.random();
|
|
18
|
+
return "grommet-accordion-button-" + timestamp;
|
|
19
|
+
}
|
|
13
20
|
var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
14
21
|
var children = _ref.children,
|
|
15
22
|
header = _ref.header,
|
|
23
|
+
id = _ref.id,
|
|
16
24
|
label = _ref.label,
|
|
17
25
|
onClick = _ref.onClick,
|
|
18
26
|
_onMouseOut = _ref.onMouseOut,
|
|
@@ -20,7 +28,7 @@ var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
20
28
|
_onFocus = _ref.onFocus,
|
|
21
29
|
_onBlur = _ref.onBlur,
|
|
22
30
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
-
var
|
|
31
|
+
var panelButtonId = id ? "grommet_accordion_button_" + id : getUID();
|
|
24
32
|
var _useThemeValue = useThemeValue(),
|
|
25
33
|
theme = _useThemeValue.theme;
|
|
26
34
|
var _useContext = useContext(AccordionContext),
|
|
@@ -72,7 +80,7 @@ var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
72
80
|
border: panelBorder,
|
|
73
81
|
margin: abutMargin
|
|
74
82
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
75
|
-
id:
|
|
83
|
+
id: panelButtonId,
|
|
76
84
|
"aria-expanded": active,
|
|
77
85
|
plain: theme.button["default"] ? true : undefined,
|
|
78
86
|
onClick: onPanelChange,
|
|
@@ -101,7 +109,8 @@ var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
101
109
|
}, header || /*#__PURE__*/React.createElement(Box, _extends({
|
|
102
110
|
align: "center",
|
|
103
111
|
direction: "row",
|
|
104
|
-
justify: "between"
|
|
112
|
+
justify: "between",
|
|
113
|
+
id: id
|
|
105
114
|
}, rest), typeof label === 'string' ? /*#__PURE__*/React.createElement(Box, {
|
|
106
115
|
pad: {
|
|
107
116
|
horizontal: 'xsmall'
|
|
@@ -122,7 +131,7 @@ var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
122
131
|
})))), /*#__PURE__*/React.createElement(Box, {
|
|
123
132
|
role: "region",
|
|
124
133
|
border: contentBorder,
|
|
125
|
-
"aria-labelledby":
|
|
134
|
+
"aria-labelledby": panelButtonId
|
|
126
135
|
}, animate ? /*#__PURE__*/React.createElement(Collapsible, {
|
|
127
136
|
open: active
|
|
128
137
|
}, children) : active && children));
|