@cypress-design/react-accordion 0.1.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.
@@ -0,0 +1,181 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var clsx = require('clsx');
5
+ var detailsAnimation = require('@cypress-design/details-animation');
6
+ var iconsRegistry = require('@cypress-design/icon-registry');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n["default"] = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
+ var clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
30
+ var iconsRegistry__namespace = /*#__PURE__*/_interopNamespace(iconsRegistry);
31
+
32
+ /******************************************************************************
33
+ Copyright (c) Microsoft Corporation.
34
+
35
+ Permission to use, copy, modify, and/or distribute this software for any
36
+ purpose with or without fee is hereby granted.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
39
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
40
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
41
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
42
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
43
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
44
+ PERFORMANCE OF THIS SOFTWARE.
45
+ ***************************************************************************** */
46
+
47
+ var __assign$1 = function() {
48
+ __assign$1 = Object.assign || function __assign(t) {
49
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
50
+ s = arguments[i];
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
52
+ }
53
+ return t;
54
+ };
55
+ return __assign$1.apply(this, arguments);
56
+ };
57
+
58
+ function __rest$1(s, e) {
59
+ var t = {};
60
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
61
+ t[p] = s[p];
62
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
63
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
64
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
65
+ t[p[i]] = s[p[i]];
66
+ }
67
+ return t;
68
+ }
69
+
70
+ var CssClasses = {
71
+ details: '',
72
+ summary: 'details-none min-h-65px py-12px card open:rounded-b-none px-24px flex items-center',
73
+ summaryColor: 'bg-white',
74
+ summaryTitle: 'text-18px leading-28px font-medium',
75
+ summaryTitleColor: 'text-indigo-500',
76
+ summaryDescription: 'text-14px leading-20px font-normal',
77
+ summaryDescriptionColor: 'text-gray-700',
78
+ icon: 'mr-24px flex-shrink-0',
79
+ separator: 'w-1px h-40px bg-gray-100 mr-16px',
80
+ chevron: 'flex-shrink-0 transition transform rotate-0 open:rotate-180',
81
+ contentWrapper: 'border border-gray-100 rounded-b-md border-t-0',
82
+ content: 'px-24px py-16px'
83
+ };
84
+
85
+ /******************************************************************************
86
+ Copyright (c) Microsoft Corporation.
87
+
88
+ Permission to use, copy, modify, and/or distribute this software for any
89
+ purpose with or without fee is hereby granted.
90
+
91
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
92
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
93
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
94
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
95
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
96
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
97
+ PERFORMANCE OF THIS SOFTWARE.
98
+ ***************************************************************************** */
99
+
100
+ var __assign = function() {
101
+ __assign = Object.assign || function __assign(t) {
102
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
103
+ s = arguments[i];
104
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
105
+ }
106
+ return t;
107
+ };
108
+ return __assign.apply(this, arguments);
109
+ };
110
+
111
+ function __rest(s, e) {
112
+ var t = {};
113
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
114
+ t[p] = s[p];
115
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
116
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
117
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
118
+ t[p[i]] = s[p[i]];
119
+ }
120
+ return t;
121
+ }
122
+
123
+ var compileReactIconProperties = function (_a) {
124
+ var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
125
+ var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
126
+ if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName)) {
127
+ newAttributes[attrName] =
128
+ attributes[attrName];
129
+ }
130
+ return newAttributes;
131
+ }, {});
132
+ var componentProps = __assign({ width: size, height: size, fill: 'none', dangerouslySetInnerHTML: {
133
+ __html: body
134
+ } }, filteredAttributes);
135
+ if (attributes.className) {
136
+ compiledClasses.push(attributes.className);
137
+ }
138
+ if (compiledClasses.length) {
139
+ componentProps.className = compiledClasses.join(' ');
140
+ }
141
+ return componentProps;
142
+ };
143
+ var IconChevronDownSmall = function (props) {
144
+ var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["8", "16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
145
+ var iconBodies = {
146
+ "8": "<path d=\"m1 2.5 3 3 3-3\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>",
147
+ "16": "<path d=\"m4 6 4 4 4-4\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>"
148
+ };
149
+ var body = iconBodies[size];
150
+ if (!body) {
151
+ throw Error("Icon \"chevron-down-small\" is not available in size " + size);
152
+ }
153
+ return React__namespace.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
154
+ };
155
+
156
+ /* <windicss-keep class=""> */
157
+
158
+ var Accordion = function (_a) {
159
+ var title = _a.title, description = _a.description, Icon = _a.icon, _b = _a.separator, separator = _b === void 0 ? false : _b, children = _a.children, headingClassName = _a.headingClassName, titleClassName = _a.titleClassName, descriptionClassName = _a.descriptionClassName, fullWidthContent = _a.fullWidthContent, rest = __rest$1(_a, ["title", "description", "icon", "separator", "children", "headingClassName", "titleClassName", "descriptionClassName", "fullWidthContent"]);
160
+ var details = React__namespace.useRef(null);
161
+ var content = React__namespace.useRef(null);
162
+ React__namespace.useEffect(function () {
163
+ if (details.current && content.current) {
164
+ new detailsAnimation.DetailsAnimation(details.current, content.current);
165
+ }
166
+ }, []);
167
+ return (React__namespace.createElement("details", __assign$1({}, rest, { className: clsx__default["default"](rest.className), ref: details }),
168
+ React__namespace.createElement("summary", { className: clsx__default["default"]('flex items-center', CssClasses.summary, headingClassName !== null && headingClassName !== void 0 ? headingClassName : CssClasses.summaryColor) },
169
+ Icon && React__namespace.createElement(Icon, { className: CssClasses.icon }),
170
+ Icon && separator && React__namespace.createElement("hr", { className: CssClasses.separator }),
171
+ React__namespace.createElement("div", { className: "flex-grow pr-16px" },
172
+ React__namespace.createElement("div", { className: clsx__default["default"](titleClassName !== null && titleClassName !== void 0 ? titleClassName : CssClasses.summaryTitleColor, CssClasses.summaryTitle) }, title),
173
+ description && (React__namespace.createElement("div", { className: clsx__default["default"](CssClasses.summaryDescription, descriptionClassName !== null && descriptionClassName !== void 0 ? descriptionClassName : CssClasses.summaryDescriptionColor) }, description))),
174
+ React__namespace.createElement(IconChevronDownSmall, { strokeColor: "gray-300", className: clsx__default["default"]('open:icon-dark-gray-500', CssClasses.chevron) })),
175
+ React__namespace.createElement("div", { ref: content, className: CssClasses.contentWrapper }, fullWidthContent ? (React__namespace.createElement(React__namespace.Fragment, null, children)) : (React__namespace.createElement("div", { className: CssClasses.content }, children)))));
176
+ };
177
+
178
+ module.exports = Accordion;
179
+
180
+ /* <windicss-keep class="flex items-center flex-grow pr-16px open:icon-dark-gray-500 details-none min-h-65px py-12px card open:rounded-b-none px-24px bg-white text-18px leading-28px font-medium text-indigo-500 text-14px leading-20px font-normal text-gray-700 mr-24px flex-shrink-0 w-1px h-40px bg-gray-100 mr-16px transition transform rotate-0 open:rotate-180 border border-gray-100 rounded-b-md border-t-0 py-16px"> */
181
+ //# sourceMappingURL=index.umd.js.map