1 | import "core-js/modules/es.array.concat.js";
|
2 | import "core-js/modules/es.string.bold.js";
|
3 |
|
4 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
5 |
|
6 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
7 |
|
8 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
9 |
|
10 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
11 |
|
12 | function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
13 |
|
14 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
15 |
|
16 | import React, { useState } from 'react';
|
17 | import { transparentize } from 'polished';
|
18 | import { styled } from '@storybook/theming';
|
19 | import { Icons } from '../../icon/icon';
|
20 | var ExpanderIcon = styled(Icons)(function (_ref) {
|
21 | var theme = _ref.theme;
|
22 | return {
|
23 | marginRight: 8,
|
24 | marginLeft: -10,
|
25 | marginTop: -2,
|
26 |
|
27 | height: 12,
|
28 | width: 12,
|
29 | color: theme.base === 'light' ? transparentize(0.25, theme.color.defaultText) : transparentize(0.3, theme.color.defaultText),
|
30 | border: 'none',
|
31 | display: 'inline-block'
|
32 | };
|
33 | });
|
34 | var FlexWrapper = styled.span(function (_ref2) {
|
35 | var theme = _ref2.theme;
|
36 | return {
|
37 | display: 'flex',
|
38 | lineHeight: '20px',
|
39 | alignItems: 'center'
|
40 | };
|
41 | });
|
42 | var Section = styled.td(function (_ref3) {
|
43 | var theme = _ref3.theme;
|
44 | return {
|
45 | position: 'relative',
|
46 | letterSpacing: '0.35em',
|
47 | textTransform: 'uppercase',
|
48 | fontWeight: theme.typography.weight.black,
|
49 | fontSize: theme.typography.size.s1 - 1,
|
50 | color: theme.base === 'light' ? transparentize(0.4, theme.color.defaultText) : transparentize(0.6, theme.color.defaultText),
|
51 | background: "".concat(theme.background.app, " !important"),
|
52 | '& ~ td': {
|
53 | background: "".concat(theme.background.app, " !important")
|
54 | }
|
55 | };
|
56 | });
|
57 | var Subsection = styled.td(function (_ref4) {
|
58 | var theme = _ref4.theme;
|
59 | return {
|
60 | position: 'relative',
|
61 | fontWeight: theme.typography.weight.bold,
|
62 | fontSize: theme.typography.size.s2 - 1,
|
63 | background: theme.background.content
|
64 | };
|
65 | });
|
66 | var StyledTd = styled.td(function (_ref5) {
|
67 | var theme = _ref5.theme;
|
68 | return {
|
69 | position: 'relative'
|
70 | };
|
71 | });
|
72 | var StyledTr = styled.tr(function (_ref6) {
|
73 | var theme = _ref6.theme;
|
74 | return {
|
75 | '&:hover > td': {
|
76 | backgroundColor: "".concat(theme.background.hoverable, " !important"),
|
77 | boxShadow: "".concat(theme.color.mediumlight, " 0 - 1px 0 0 inset"),
|
78 | cursor: 'row-resize'
|
79 | }
|
80 | };
|
81 | });
|
82 | var ClickIntercept = styled.button(function () {
|
83 | return {
|
84 |
|
85 | background: 'none',
|
86 | border: 'none',
|
87 | padding: '0',
|
88 | font: 'inherit',
|
89 |
|
90 | position: 'absolute',
|
91 | top: 0,
|
92 | bottom: 0,
|
93 | left: 0,
|
94 | right: 0,
|
95 | height: '100%',
|
96 | width: '100%',
|
97 | color: 'transparent',
|
98 | cursor: 'row-resize !important'
|
99 | };
|
100 | });
|
101 | export var SectionRow = function SectionRow(_ref7) {
|
102 | var _ref7$level = _ref7.level,
|
103 | level = _ref7$level === void 0 ? 'section' : _ref7$level,
|
104 | label = _ref7.label,
|
105 | children = _ref7.children,
|
106 | _ref7$initialExpanded = _ref7.initialExpanded,
|
107 | initialExpanded = _ref7$initialExpanded === void 0 ? true : _ref7$initialExpanded,
|
108 | _ref7$colSpan = _ref7.colSpan,
|
109 | colSpan = _ref7$colSpan === void 0 ? 3 : _ref7$colSpan;
|
110 |
|
111 | var _useState = useState(initialExpanded),
|
112 | _useState2 = _slicedToArray(_useState, 2),
|
113 | expanded = _useState2[0],
|
114 | setExpanded = _useState2[1];
|
115 |
|
116 | var Level = level === 'subsection' ? Subsection : Section;
|
117 |
|
118 | var itemCount = (children === null || children === void 0 ? void 0 : children.length) || 0;
|
119 | var caption = level === 'subsection' ? "".concat(itemCount, " item").concat(itemCount !== 1 ? 's' : '') : '';
|
120 | var icon = expanded ? 'arrowdown' : 'arrowright';
|
121 | var helperText = "".concat(expanded ? 'Hide' : 'Side', " ").concat(level === 'subsection' ? itemCount : label, " item").concat(itemCount !== 1 ? 's' : '');
|
122 | return React.createElement(React.Fragment, null, React.createElement(StyledTr, {
|
123 | title: helperText
|
124 | }, React.createElement(Level, {
|
125 | colSpan: 1
|
126 | }, React.createElement(ClickIntercept, {
|
127 | onClick: function onClick(e) {
|
128 | return setExpanded(!expanded);
|
129 | },
|
130 | tabIndex: 0
|
131 | }, helperText), React.createElement(FlexWrapper, null, React.createElement(ExpanderIcon, {
|
132 | icon: icon
|
133 | }), label)), React.createElement(StyledTd, {
|
134 | colSpan: colSpan - 1
|
135 | }, React.createElement(ClickIntercept, {
|
136 | onClick: function onClick(e) {
|
137 | return setExpanded(!expanded);
|
138 | },
|
139 | tabIndex: -1,
|
140 | style: {
|
141 | outline: 'none'
|
142 | }
|
143 | }, helperText), expanded ? null : caption)), expanded ? children : null);
|
144 | }; |
\ | No newline at end of file |