@bigbinary/neeto-molecules 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -10,7 +10,9 @@ A package of reusable molecular components for neeto products.
10
10
  - [BrowserSupport](./docs/components.md#browsersupport)
11
11
  - [Columns](./docs/components.md#columns)
12
12
  - [CustomDomain](./docs/components.md#customdomain)
13
+ - [DateFormat/TimeFormat](./docs/components.md#dateformattimeformat)
13
14
  - [DateRangeFilter](./docs/components.md#daterangefilter)
15
+ - [DynamicVariables](./docs/components.md#dynamicvariables)
14
16
  - [EmailPreview](./docs/components.md#emailpreview)
15
17
  - [ErrorPage](./docs/components.md#errorpage)
16
18
  - [IpRestriction](./docs/components.md#iprestriction)
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var pure = require('@bigbinary/neeto-commons-frontend/pure');
5
+ var utils = require('@bigbinary/neeto-commons-frontend/utils');
6
+ var neetoui = require('@bigbinary/neetoui');
7
+ var ramda = require('ramda');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+
13
+ function _extends() {
14
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = arguments[i];
17
+ for (var key in source) {
18
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
19
+ target[key] = source[key];
20
+ }
21
+ }
22
+ }
23
+ return target;
24
+ };
25
+ return _extends.apply(this, arguments);
26
+ }
27
+
28
+ var DateFormat = ramda.fromPairs(ramda.keys(utils.timeFormat).map(function (key) {
29
+ return [pure.capitalize(key), function (_ref) {
30
+ var date = _ref.date,
31
+ _ref$tooltipProps = _ref.tooltipProps,
32
+ tooltipProps = _ref$tooltipProps === void 0 ? {} : _ref$tooltipProps,
33
+ _ref$typographyProps = _ref.typographyProps,
34
+ typographyProps = _ref$typographyProps === void 0 ? {} : _ref$typographyProps;
35
+ var dateDisplay = /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, _extends({
36
+ component: "span",
37
+ style: "body2"
38
+ }, typographyProps), utils.timeFormat[key](date));
39
+ return key === "extended" ? dateDisplay : /*#__PURE__*/React__default["default"].createElement(neetoui.Tooltip, _extends({
40
+ content: utils.timeFormat.extended(date),
41
+ position: "top"
42
+ }, tooltipProps), dateDisplay);
43
+ }];
44
+ }));
45
+
46
+ module.exports = DateFormat;
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { capitalize } from '@bigbinary/neeto-commons-frontend/pure';
3
+ import { timeFormat } from '@bigbinary/neeto-commons-frontend/utils';
4
+ import { Typography, Tooltip } from '@bigbinary/neetoui';
5
+ import { fromPairs, keys } from 'ramda';
6
+
7
+ function _extends() {
8
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
9
+ for (var i = 1; i < arguments.length; i++) {
10
+ var source = arguments[i];
11
+ for (var key in source) {
12
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
13
+ target[key] = source[key];
14
+ }
15
+ }
16
+ }
17
+ return target;
18
+ };
19
+ return _extends.apply(this, arguments);
20
+ }
21
+
22
+ var DateFormat = fromPairs(keys(timeFormat).map(function (key) {
23
+ return [capitalize(key), function (_ref) {
24
+ var date = _ref.date,
25
+ _ref$tooltipProps = _ref.tooltipProps,
26
+ tooltipProps = _ref$tooltipProps === void 0 ? {} : _ref$tooltipProps,
27
+ _ref$typographyProps = _ref.typographyProps,
28
+ typographyProps = _ref$typographyProps === void 0 ? {} : _ref$typographyProps;
29
+ var dateDisplay = /*#__PURE__*/React.createElement(Typography, _extends({
30
+ component: "span",
31
+ style: "body2"
32
+ }, typographyProps), timeFormat[key](date));
33
+ return key === "extended" ? dateDisplay : /*#__PURE__*/React.createElement(Tooltip, _extends({
34
+ content: timeFormat.extended(date),
35
+ position: "top"
36
+ }, tooltipProps), dateDisplay);
37
+ }];
38
+ }));
39
+
40
+ export { DateFormat as default };
@@ -211,9 +211,9 @@ var DateRangeFilter = function DateRangeFilter(_ref) {
211
211
  autoFocus: true,
212
212
  className: "ml-3 w-full",
213
213
  dateFormat: initializers.globalProps === null || initializers.globalProps === void 0 ? void 0 : (_globalProps$user = initializers.globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.dateFormat,
214
- defaultValue: [dayjs__default["default"](startDate), dayjs__default["default"](endDate)],
215
214
  picker: "date",
216
215
  type: "range",
216
+ defaultValue: [startDate ? dayjs__default["default"](startDate) : null, endDate ? dayjs__default["default"](endDate) : null],
217
217
  onChange: function onChange(_, _ref2) {
218
218
  var _ref3 = _slicedToArray(_ref2, 2),
219
219
  startDate = _ref3[0],
@@ -204,9 +204,9 @@ var DateRangeFilter = function DateRangeFilter(_ref) {
204
204
  autoFocus: true,
205
205
  className: "ml-3 w-full",
206
206
  dateFormat: globalProps === null || globalProps === void 0 ? void 0 : (_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.dateFormat,
207
- defaultValue: [dayjs(startDate), dayjs(endDate)],
208
207
  picker: "date",
209
208
  type: "range",
209
+ defaultValue: [startDate ? dayjs(startDate) : null, endDate ? dayjs(endDate) : null],
210
210
  onChange: function onChange(_, _ref2) {
211
211
  var _ref3 = _slicedToArray(_ref2, 2),
212
212
  startDate = _ref3[0],
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var pure = require('@bigbinary/neeto-commons-frontend/pure');
5
+ var neetoIcons = require('@bigbinary/neeto-icons');
6
+ var neetoui = require('@bigbinary/neetoui');
7
+ var ramda = require('ramda');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+
13
+ function _extends() {
14
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = arguments[i];
17
+ for (var key in source) {
18
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
19
+ target[key] = source[key];
20
+ }
21
+ }
22
+ }
23
+ return target;
24
+ };
25
+ return _extends.apply(this, arguments);
26
+ }
27
+
28
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
29
+
30
+ var css = ".neeto-molecules-dynamic-variables{max-width:360px;min-width:184px}.neeto-molecules-dynamic-variables button{border:1px solid rgb(var(--neeto-ui-gray-300));border-radius:var(--neeto-ui-rounded-md);color:rgb(var(--neeto-ui-black));padding:6px;transition:var(--neeto-ui-transition);-webkit-user-select:none;-moz-user-select:none;user-select:none}.neeto-molecules-dynamic-variables button:focus,.neeto-molecules-dynamic-variables button:focus-visible,.neeto-molecules-dynamic-variables button:hover{border-color:rgb(var(--neeto-ui-primary-800));box-shadow:none;color:rgb(var(--neeto-ui-primary-800));outline:none}";
31
+ n(css,{});
32
+
33
+ var parseVariables = function parseVariables() {
34
+ var variableArr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
35
+ var uncategorized = [];
36
+ var groupedVariables = [];
37
+ var categorySet = new Set();
38
+ variableArr.forEach(function (variable) {
39
+ var category = variable.category,
40
+ label = variable.label,
41
+ variables = variable.variables;
42
+ if (category && variables) {
43
+ var parsedVariables = variables.map(ramda.assoc("category", category));
44
+ if (!categorySet.has(category)) {
45
+ categorySet.add(category);
46
+ groupedVariables.push({
47
+ label: label,
48
+ variables: parsedVariables
49
+ });
50
+ } else {
51
+ var existingGroup = pure.findBy({
52
+ label: label
53
+ }, groupedVariables);
54
+ existingGroup.variables = ramda.uniqBy(ramda.prop("key"), existingGroup.variables.concat(parsedVariables));
55
+ }
56
+ } else {
57
+ uncategorized.push(variable);
58
+ }
59
+ });
60
+ if (!ramda.isEmpty(uncategorized)) {
61
+ groupedVariables.push({
62
+ label: !ramda.isEmpty(groupedVariables) ? "Others" : null,
63
+ variables: uncategorized
64
+ });
65
+ }
66
+ return groupedVariables;
67
+ };
68
+
69
+ var Menu = neetoui.Dropdown.Menu;
70
+ var DynamicVariables = function DynamicVariables(_ref) {
71
+ var _ref$onVariableClick = _ref.onVariableClick,
72
+ onVariableClick = _ref$onVariableClick === void 0 ? pure.noop : _ref$onVariableClick,
73
+ _ref$variables = _ref.variables,
74
+ variables = _ref$variables === void 0 ? [] : _ref$variables,
75
+ _ref$dropdownProps = _ref.dropdownProps,
76
+ dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps;
77
+ if (ramda.isEmpty(variables)) {
78
+ return null;
79
+ }
80
+ var parsedVariables = parseVariables(variables);
81
+ return /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, _extends({
82
+ buttonProps: {
83
+ "data-testid": "variables-dropdown"
84
+ },
85
+ buttonStyle: "secondary",
86
+ icon: neetoIcons.Braces,
87
+ strategy: "fixed"
88
+ }, dropdownProps), /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement("div", {
89
+ className: "space-y-3 p-2 neeto-molecules-dynamic-variables",
90
+ "data-testid": "variables-list"
91
+ }, parsedVariables.map(function (_ref2) {
92
+ var label = _ref2.label,
93
+ variables = _ref2.variables;
94
+ return /*#__PURE__*/React__default["default"].createElement(React.Fragment, {
95
+ key: label
96
+ }, label && /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
97
+ className: "",
98
+ style: "h6"
99
+ }, label), /*#__PURE__*/React__default["default"].createElement("div", {
100
+ className: "flex flex-wrap items-center gap-2"
101
+ }, variables.map(function (item) {
102
+ return /*#__PURE__*/React__default["default"].createElement("button", {
103
+ key: item.label,
104
+ onClick: function onClick() {
105
+ return onVariableClick(item);
106
+ }
107
+ }, item.label);
108
+ })));
109
+ }))));
110
+ };
111
+
112
+ module.exports = DynamicVariables;
@@ -0,0 +1,106 @@
1
+ import React, { Fragment } from 'react';
2
+ import { findBy, noop } from '@bigbinary/neeto-commons-frontend/pure';
3
+ import { Braces } from '@bigbinary/neeto-icons';
4
+ import { Dropdown, Typography } from '@bigbinary/neetoui';
5
+ import { assoc, uniqBy, prop, isEmpty } from 'ramda';
6
+
7
+ function _extends() {
8
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
9
+ for (var i = 1; i < arguments.length; i++) {
10
+ var source = arguments[i];
11
+ for (var key in source) {
12
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
13
+ target[key] = source[key];
14
+ }
15
+ }
16
+ }
17
+ return target;
18
+ };
19
+ return _extends.apply(this, arguments);
20
+ }
21
+
22
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
23
+
24
+ var css = ".neeto-molecules-dynamic-variables{max-width:360px;min-width:184px}.neeto-molecules-dynamic-variables button{border:1px solid rgb(var(--neeto-ui-gray-300));border-radius:var(--neeto-ui-rounded-md);color:rgb(var(--neeto-ui-black));padding:6px;transition:var(--neeto-ui-transition);-webkit-user-select:none;-moz-user-select:none;user-select:none}.neeto-molecules-dynamic-variables button:focus,.neeto-molecules-dynamic-variables button:focus-visible,.neeto-molecules-dynamic-variables button:hover{border-color:rgb(var(--neeto-ui-primary-800));box-shadow:none;color:rgb(var(--neeto-ui-primary-800));outline:none}";
25
+ n(css,{});
26
+
27
+ var parseVariables = function parseVariables() {
28
+ var variableArr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
29
+ var uncategorized = [];
30
+ var groupedVariables = [];
31
+ var categorySet = new Set();
32
+ variableArr.forEach(function (variable) {
33
+ var category = variable.category,
34
+ label = variable.label,
35
+ variables = variable.variables;
36
+ if (category && variables) {
37
+ var parsedVariables = variables.map(assoc("category", category));
38
+ if (!categorySet.has(category)) {
39
+ categorySet.add(category);
40
+ groupedVariables.push({
41
+ label: label,
42
+ variables: parsedVariables
43
+ });
44
+ } else {
45
+ var existingGroup = findBy({
46
+ label: label
47
+ }, groupedVariables);
48
+ existingGroup.variables = uniqBy(prop("key"), existingGroup.variables.concat(parsedVariables));
49
+ }
50
+ } else {
51
+ uncategorized.push(variable);
52
+ }
53
+ });
54
+ if (!isEmpty(uncategorized)) {
55
+ groupedVariables.push({
56
+ label: !isEmpty(groupedVariables) ? "Others" : null,
57
+ variables: uncategorized
58
+ });
59
+ }
60
+ return groupedVariables;
61
+ };
62
+
63
+ var Menu = Dropdown.Menu;
64
+ var DynamicVariables = function DynamicVariables(_ref) {
65
+ var _ref$onVariableClick = _ref.onVariableClick,
66
+ onVariableClick = _ref$onVariableClick === void 0 ? noop : _ref$onVariableClick,
67
+ _ref$variables = _ref.variables,
68
+ variables = _ref$variables === void 0 ? [] : _ref$variables,
69
+ _ref$dropdownProps = _ref.dropdownProps,
70
+ dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps;
71
+ if (isEmpty(variables)) {
72
+ return null;
73
+ }
74
+ var parsedVariables = parseVariables(variables);
75
+ return /*#__PURE__*/React.createElement(Dropdown, _extends({
76
+ buttonProps: {
77
+ "data-testid": "variables-dropdown"
78
+ },
79
+ buttonStyle: "secondary",
80
+ icon: Braces,
81
+ strategy: "fixed"
82
+ }, dropdownProps), /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement("div", {
83
+ className: "space-y-3 p-2 neeto-molecules-dynamic-variables",
84
+ "data-testid": "variables-list"
85
+ }, parsedVariables.map(function (_ref2) {
86
+ var label = _ref2.label,
87
+ variables = _ref2.variables;
88
+ return /*#__PURE__*/React.createElement(Fragment, {
89
+ key: label
90
+ }, label && /*#__PURE__*/React.createElement(Typography, {
91
+ className: "",
92
+ style: "h6"
93
+ }, label), /*#__PURE__*/React.createElement("div", {
94
+ className: "flex flex-wrap items-center gap-2"
95
+ }, variables.map(function (item) {
96
+ return /*#__PURE__*/React.createElement("button", {
97
+ key: item.label,
98
+ onClick: function onClick() {
99
+ return onVariableClick(item);
100
+ }
101
+ }, item.label);
102
+ })));
103
+ }))));
104
+ };
105
+
106
+ export { DynamicVariables as default };