@redhat-cloud-services/frontend-components 3.8.4 → 3.8.5

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.
Files changed (80) hide show
  1. package/BulkSelect/index.d.ts +1 -0
  2. package/BulkSelect/index.js +11 -0
  3. package/BulkSelect/index.js.map +1 -1
  4. package/ConditionalFilter/CheckboxFilter.d.ts +11 -37
  5. package/ConditionalFilter/CheckboxFilter.js +30 -90
  6. package/ConditionalFilter/CheckboxFilter.js.map +1 -1
  7. package/ConditionalFilter/ConditionalFilter.d.ts +34 -56
  8. package/ConditionalFilter/ConditionalFilter.js +54 -148
  9. package/ConditionalFilter/ConditionalFilter.js.map +1 -1
  10. package/ConditionalFilter/GroupFilter.d.ts +52 -46
  11. package/ConditionalFilter/GroupFilter.js +38 -70
  12. package/ConditionalFilter/GroupFilter.js.map +1 -1
  13. package/ConditionalFilter/RadioFilter.d.ts +11 -36
  14. package/ConditionalFilter/RadioFilter.js +27 -84
  15. package/ConditionalFilter/RadioFilter.js.map +1 -1
  16. package/ConditionalFilter/TextFilter.d.ts +27 -25
  17. package/ConditionalFilter/TextFilter.js +14 -72
  18. package/ConditionalFilter/TextFilter.js.map +1 -1
  19. package/ConditionalFilter/conditionalFilterConstants.d.ts +17 -19
  20. package/ConditionalFilter/conditionalFilterConstants.js.map +1 -1
  21. package/ConditionalFilter/groupFilterConstants.d.ts +47 -7
  22. package/ConditionalFilter/groupFilterConstants.js +62 -58
  23. package/ConditionalFilter/groupFilterConstants.js.map +1 -1
  24. package/ConditionalFilter/groupType.d.ts +8 -7
  25. package/ConditionalFilter/groupType.js.map +1 -1
  26. package/ConditionalFilter/index.d.ts +8 -7
  27. package/ConditionalFilter/index.js.map +1 -1
  28. package/DownloadButton/index.d.ts +1 -0
  29. package/DownloadButton/index.js +11 -0
  30. package/DownloadButton/index.js.map +1 -1
  31. package/FilterChips/FilterChips.d.ts +22 -38
  32. package/FilterChips/FilterChips.js +9 -31
  33. package/FilterChips/FilterChips.js.map +1 -1
  34. package/FilterChips/index.d.ts +3 -1
  35. package/FilterChips/index.js +11 -0
  36. package/FilterChips/index.js.map +1 -1
  37. package/PrimaryToolbar/Actions.d.ts +30 -30
  38. package/PrimaryToolbar/Actions.js +46 -86
  39. package/PrimaryToolbar/Actions.js.map +1 -1
  40. package/PrimaryToolbar/PrimaryToolbar.d.ts +30 -77
  41. package/PrimaryToolbar/PrimaryToolbar.js +40 -111
  42. package/PrimaryToolbar/PrimaryToolbar.js.map +1 -1
  43. package/PrimaryToolbar/SortBy.d.ts +8 -19
  44. package/PrimaryToolbar/SortBy.js +1 -10
  45. package/PrimaryToolbar/SortBy.js.map +1 -1
  46. package/PrimaryToolbar/index.d.ts +6 -4
  47. package/PrimaryToolbar/index.js +1 -0
  48. package/PrimaryToolbar/index.js.map +1 -1
  49. package/esm/BulkSelect/index.js +1 -0
  50. package/esm/BulkSelect/index.js.map +1 -1
  51. package/esm/ConditionalFilter/CheckboxFilter.js +31 -91
  52. package/esm/ConditionalFilter/CheckboxFilter.js.map +1 -1
  53. package/esm/ConditionalFilter/ConditionalFilter.js +56 -150
  54. package/esm/ConditionalFilter/ConditionalFilter.js.map +1 -1
  55. package/esm/ConditionalFilter/GroupFilter.js +38 -70
  56. package/esm/ConditionalFilter/GroupFilter.js.map +1 -1
  57. package/esm/ConditionalFilter/RadioFilter.js +29 -83
  58. package/esm/ConditionalFilter/RadioFilter.js.map +1 -1
  59. package/esm/ConditionalFilter/TextFilter.js +13 -70
  60. package/esm/ConditionalFilter/TextFilter.js.map +1 -1
  61. package/esm/ConditionalFilter/conditionalFilterConstants.js.map +1 -1
  62. package/esm/ConditionalFilter/groupFilterConstants.js +62 -58
  63. package/esm/ConditionalFilter/groupFilterConstants.js.map +1 -1
  64. package/esm/ConditionalFilter/groupType.js.map +1 -1
  65. package/esm/ConditionalFilter/index.js.map +1 -1
  66. package/esm/DownloadButton/index.js +1 -0
  67. package/esm/DownloadButton/index.js.map +1 -1
  68. package/esm/FilterChips/FilterChips.js +9 -31
  69. package/esm/FilterChips/FilterChips.js.map +1 -1
  70. package/esm/FilterChips/index.js +1 -0
  71. package/esm/FilterChips/index.js.map +1 -1
  72. package/esm/PrimaryToolbar/Actions.js +46 -86
  73. package/esm/PrimaryToolbar/Actions.js.map +1 -1
  74. package/esm/PrimaryToolbar/PrimaryToolbar.js +41 -93
  75. package/esm/PrimaryToolbar/PrimaryToolbar.js.map +1 -1
  76. package/esm/PrimaryToolbar/SortBy.js +1 -10
  77. package/esm/PrimaryToolbar/SortBy.js.map +1 -1
  78. package/esm/PrimaryToolbar/index.js +1 -0
  79. package/esm/PrimaryToolbar/index.js.map +1 -1
  80. package/package.json +1 -1
@@ -1,2 +1,3 @@
1
1
  export { default } from './BulkSelect';
2
2
  export { default as BulkSelect } from './BulkSelect';
3
+ export * from './BulkSelect';
@@ -1,4 +1,14 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
14
  };
@@ -8,4 +18,5 @@ var BulkSelect_1 = require("./BulkSelect");
8
18
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(BulkSelect_1).default; } });
9
19
  var BulkSelect_2 = require("./BulkSelect");
10
20
  Object.defineProperty(exports, "BulkSelect", { enumerable: true, get: function () { return __importDefault(BulkSelect_2).default; } });
21
+ __exportStar(require("./BulkSelect"), exports);
11
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/BulkSelect/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAuC;AAA9B,sHAAA,OAAO,OAAA;AAChB,2CAAqD;AAA5C,yHAAA,OAAO,OAAc"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/BulkSelect/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAuC;AAA9B,sHAAA,OAAO,OAAA;AAChB,2CAAqD;AAA5C,yHAAA,OAAO,OAAc;AAC9B,+CAA6B"}
@@ -1,38 +1,12 @@
1
- export default CheckboxFilter;
2
- declare class CheckboxFilter extends React.Component<any, any, any> {
3
- constructor(props: any);
4
- constructor(props: any, context: any);
5
- onToggle: (isExpanded: any) => void;
6
- calculateSelected: () => any[];
7
- onSelect: (event: any, selection: any) => void;
8
- }
9
- declare namespace CheckboxFilter {
10
- namespace propTypes {
11
- const onChange: PropTypes.Requireable<(...args: any[]) => any>;
12
- const value: PropTypes.Requireable<(string | PropTypes.InferProps<{
13
- label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
14
- value: PropTypes.Requireable<string>;
15
- }> | null | undefined)[]>;
16
- const placeholder: PropTypes.Requireable<string>;
17
- const items: PropTypes.Requireable<(PropTypes.InferProps<{
18
- value: PropTypes.Requireable<string>;
19
- label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
20
- id: PropTypes.Requireable<string>;
21
- onClick: PropTypes.Requireable<(...args: any[]) => any>;
22
- }> | null | undefined)[]>;
23
- const isDisabled: PropTypes.Requireable<boolean>;
24
- const className: PropTypes.Requireable<string>;
25
- }
26
- namespace defaultProps {
27
- const items_1: never[];
28
- export { items_1 as items };
29
- const value_1: never[];
30
- export { value_1 as value };
31
- export function onChange_1(): undefined;
32
- export { onChange_1 as onChange };
33
- const isDisabled_1: boolean;
34
- export { isDisabled_1 as isDisabled };
35
- }
1
+ import React from 'react';
2
+ import { FilterItem, FilterValue } from './TextFilter';
3
+ export interface CheckboxFilterProps {
4
+ onChange?: (e: React.MouseEvent | React.ChangeEvent | React.FormEvent<HTMLInputElement>, newSelection: string | FilterValue | (string | FilterValue)[], selection?: string | FilterValue) => void;
5
+ value?: (string | FilterValue)[];
6
+ placeholder?: string;
7
+ items?: FilterItem[];
8
+ isDisabled?: boolean;
9
+ className?: string;
36
10
  }
37
- import React from "react";
38
- import PropTypes from "prop-types";
11
+ declare const CheckboxFilter: React.FunctionComponent<CheckboxFilterProps>;
12
+ export default CheckboxFilter;
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __assign = (this && this.__assign) || function () {
18
3
  __assign = Object.assign || function(t) {
19
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -69,85 +54,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
69
54
  };
70
55
  Object.defineProperty(exports, "__esModule", { value: true });
71
56
  var react_1 = __importStar(require("react"));
72
- var prop_types_1 = __importDefault(require("prop-types"));
73
57
  var react_core_1 = require("@patternfly/react-core");
74
- var TextFilter_1 = __importDefault(require("./TextFilter"));
75
58
  var isEqual_1 = __importDefault(require("lodash/isEqual"));
76
- var CheckboxFilter = (function (_super) {
77
- __extends(CheckboxFilter, _super);
78
- function CheckboxFilter() {
79
- var _this = _super !== null && _super.apply(this, arguments) || this;
80
- _this.state = {
81
- isExpanded: false,
82
- selected: [],
83
- };
84
- _this.onToggle = function (isExpanded) {
85
- _this.setState({
86
- isExpanded: isExpanded,
87
- });
88
- };
89
- _this.calculateSelected = function () {
90
- var selected = _this.state.selected;
91
- var value = _this.props.value;
92
- return Array.from(new Set(__spreadArray(__spreadArray([], (value && value.length > 0 && value.constructor === Array ? value.map(function (item) { return item.value || item; }) : []), true), selected, true)));
93
- };
94
- _this.onSelect = function (event, selection) {
95
- var onChange = _this.props.onChange;
96
- var newSelection = _this.calculateSelected();
97
- if (newSelection.includes(selection)) {
98
- newSelection = newSelection.filter(function (item) { return item !== selection; });
99
- }
100
- else {
101
- newSelection = __spreadArray(__spreadArray([], newSelection, true), [selection], false);
102
- }
103
- onChange(event, newSelection, selection);
104
- _this.setState({ selected: newSelection });
105
- };
106
- return _this;
107
- }
108
- CheckboxFilter.prototype.componentDidUpdate = function (_a) {
109
- var prevSelected = _a.value;
110
- var value = this.props.value;
111
- if (!(0, isEqual_1.default)(prevSelected, value)) {
112
- this.setState({
113
- selected: value,
114
- });
115
- }
59
+ var omit_1 = __importDefault(require("lodash/omit"));
60
+ var TextFilter_1 = __importStar(require("./TextFilter"));
61
+ var CheckboxFilter = function (_a) {
62
+ var _b = _a.items, items = _b === void 0 ? [] : _b, _c = _a.value, value = _c === void 0 ? [] : _c, _d = _a.onChange, onChange = _d === void 0 ? function () { return undefined; } : _d, _e = _a.isDisabled, isDisabled = _e === void 0 ? false : _e, props = __rest(_a, ["items", "value", "onChange", "isDisabled"]);
63
+ var placeholder = props.placeholder, className = props.className;
64
+ var _f = (0, react_1.useState)(false), isExpanded = _f[0], setExpanded = _f[1];
65
+ var _g = (0, react_1.useState)([]), selected = _g[0], setSelected = _g[1];
66
+ var prevSelected = (0, react_1.useRef)(selected);
67
+ var changeSelected = function (value) {
68
+ prevSelected.current = selected;
69
+ setSelected(value);
116
70
  };
117
- CheckboxFilter.prototype.render = function () {
118
- var isExpanded = this.state.isExpanded;
119
- var _a = this.props, items = _a.items, placeholder = _a.placeholder, isDisabled = _a.isDisabled, className = _a.className;
120
- return (react_1.default.createElement(react_1.Fragment, null, !items || (items && items.length <= 0) ? (react_1.default.createElement(TextFilter_1.default, __assign({}, this.props, { value: "".concat(this.calculateSelected()) }))) : (react_1.default.createElement(react_core_1.Select, { className: className, variant: react_core_1.SelectVariant.checkbox, "aria-label": "Select Input", onToggle: this.onToggle, isDisabled: isDisabled, onSelect: this.onSelect, selections: this.calculateSelected(), isOpen: isExpanded, placeholderText: placeholder, ouiaId: placeholder }, items.map(function (_a, key) {
121
- var value = _a.value, onClick = _a.onClick, label = _a.label, id = _a.id, item = __rest(_a, ["value", "onClick", "label", "id"]);
122
- return (react_1.default.createElement(react_core_1.SelectOption, __assign({}, item, { key: id || key, value: String(value || id || key), onClick: function (e) { return onClick && onClick(e, __assign({ value: value, label: label, id: id }, item), key); } }), label));
123
- })))));
71
+ (0, react_1.useEffect)(function () {
72
+ !(0, isEqual_1.default)(prevSelected.current, value) && value && changeSelected(value);
73
+ }, [selected]);
74
+ var calculateSelected = function () {
75
+ return Array.from(new Set(__spreadArray(__spreadArray([], (value && value.length > 0 && value.constructor === Array
76
+ ? value.map(function (item) {
77
+ return (0, TextFilter_1.isFilterValue)(item) ? item.value : item;
78
+ })
79
+ : []), true), selected, true)));
124
80
  };
125
- return CheckboxFilter;
126
- }(react_1.Component));
127
- CheckboxFilter.propTypes = {
128
- onChange: prop_types_1.default.func,
129
- value: prop_types_1.default.arrayOf(prop_types_1.default.oneOfType([
130
- prop_types_1.default.string,
131
- prop_types_1.default.shape({
132
- label: prop_types_1.default.node,
133
- value: prop_types_1.default.string,
134
- }),
135
- ])),
136
- placeholder: prop_types_1.default.string,
137
- items: prop_types_1.default.arrayOf(prop_types_1.default.shape({
138
- value: prop_types_1.default.string,
139
- label: prop_types_1.default.node,
140
- id: prop_types_1.default.string,
141
- onClick: prop_types_1.default.func,
142
- })),
143
- isDisabled: prop_types_1.default.bool,
144
- className: prop_types_1.default.string,
145
- };
146
- CheckboxFilter.defaultProps = {
147
- items: [],
148
- value: [],
149
- onChange: function () { return undefined; },
150
- isDisabled: false,
81
+ var onSelect = function (event, selection) {
82
+ var newSelection = calculateSelected();
83
+ newSelection = newSelection.includes(selection) ? newSelection.filter(function (item) { return item !== selection; }) : __spreadArray(__spreadArray([], newSelection, true), [selection], false);
84
+ onChange === null || onChange === void 0 ? void 0 : onChange(event, newSelection, selection);
85
+ changeSelected(newSelection);
86
+ };
87
+ return (react_1.default.createElement(react_1.Fragment, null, !items || (items && items.length <= 0) ? (react_1.default.createElement(TextFilter_1.default, __assign({}, props, { onChange: onChange, isDisabled: isDisabled, value: "".concat(calculateSelected()) }))) : (react_1.default.createElement(react_core_1.Select, { className: className, variant: react_core_1.SelectVariant.checkbox, "aria-label": "Select Input", onToggle: function (isExpanded) { return setExpanded(isExpanded); }, isDisabled: isDisabled, onSelect: function (event, value) { return onSelect(event, value); }, selections: calculateSelected(), isOpen: isExpanded, placeholderText: placeholder, ouiaId: placeholder }, items.map(function (_a, key) {
88
+ var value = _a.value, onClick = _a.onClick, label = _a.label, id = _a.id, item = __rest(_a, ["value", "onClick", "label", "id"]);
89
+ return (react_1.default.createElement(react_core_1.SelectOption, __assign({}, (0, omit_1.default)(item, 'onChange'), { key: id || key, value: String(value || id || key), onClick: function (e) { return onClick === null || onClick === void 0 ? void 0 : onClick(e, __assign({ value: value, label: label, id: id }, item), key); } }), label));
90
+ })))));
151
91
  };
152
92
  exports.default = CheckboxFilter;
153
93
  //# sourceMappingURL=CheckboxFilter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CheckboxFilter.js","sourceRoot":"","sources":["../src/ConditionalFilter/CheckboxFilter.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmD;AACnD,0DAAmC;AACnC,qDAA6E;AAC7E,4DAAgC;AAChC,2DAAqC;AAMrC;IAA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AQ,gBACpB,cAAc,EACzB,QAAQ,EAAE,UAAC,UAAU,IAAK,OAAA,WAAW,CAAC,UAAU,CAAC,EAAvB,CAAuB,EACjD,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,UAAC,KAAK,EAAE,KAAK,IAAK,OAAA,QAAQ,CAAC,KAAK,EAAE,KAA6B,CAAC,EAA9C,CAA8C,EAC1E,UAAU,EAAE,iBAAiB,EAAE,EAC/B,MAAM,EAAE,UAAU,EAClB,eAAe,EAAE,WAAW,EAC5B,MAAM,EAAE,WAAW,IAElB,KAAK,CAAC,GAAG,CAAC,UAAC,EAAsC,EAAE,GAAG;QAAzC,IAAA,KAAK,WAAA,EAAE,OAAO,aAAA,EAAE,KAAK,WAAA,EAAE,EAAE,QAAA,EAAK,IAAI,cAApC,mCAAsC,CAAF;QAAY,OAAA,CAC1D,8BAAC,yBAAY,eACP,IAAA,cAAI,EAAC,IAAI,EAAE,UAAU,CAAC,IAC1B,GAAG,EAAE,EAAE,IAAI,GAAG,EACd,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,IAAI,GAAG,CAAC,EACjC,OAAO,EAAE,UAAC,CAAC,IAAK,OAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,aAAI,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,EAAE,IAAA,IAAK,IAAI,GAAI,GAAG,CAAC,EAAhD,CAAgD,KAE/D,KAAK,CACO,CAChB,CAAA;KAAA,CAAC,CACK,CACV,CACQ,CACZ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,cAAc,CAAC"}
@@ -1,58 +1,36 @@
1
- export default ConditionalFilter;
2
- declare class ConditionalFilter extends React.Component<any, any, any> {
3
- constructor(props: any);
4
- breakpointConstant: number;
5
- dropdownToggle: (isOpen: any) => void;
6
- onChange: (_e: any, value: any) => void;
7
- getWrapper: () => React.ExoticComponent<{
8
- children?: React.ReactNode;
9
- }> | ((props: any) => JSX.Element);
10
- updateFilterViewport: (width: any) => boolean;
11
- resizeListener: void | undefined;
1
+ import React from 'react';
2
+ import { RadioFilterProps } from './RadioFilter';
3
+ import { CheckboxFilterProps } from './CheckboxFilter';
4
+ import { GroupFilterProps } from './GroupFilter';
5
+ import './conditional-filter.scss';
6
+ declare type FilterValues = TextInputProps & RadioFilterProps & CheckboxFilterProps & GroupFilterProps & {
7
+ items?: Value[];
8
+ value?: string | (string | Value)[] | Record<string, unknown>;
9
+ };
10
+ interface TextInputProps {
11
+ id?: string;
12
+ onChange?: () => void;
13
+ placeholder?: string;
14
+ value?: string;
15
+ }
16
+ interface Value {
17
+ label?: Node;
18
+ value?: string;
12
19
  }
13
- declare namespace ConditionalFilter {
14
- namespace propTypes {
15
- const id: PropTypes.Requireable<string>;
16
- const isDisabled: PropTypes.Requireable<boolean>;
17
- const useMobileLayout: PropTypes.Requireable<boolean>;
18
- const value: PropTypes.Requireable<string>;
19
- const placeholder: PropTypes.Requireable<string>;
20
- const onChange: PropTypes.Requireable<(...args: any[]) => any>;
21
- const hideLabel: PropTypes.Requireable<boolean>;
22
- const items: PropTypes.Requireable<(PropTypes.InferProps<{
23
- id: PropTypes.Requireable<string>;
24
- label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
25
- value: PropTypes.Requireable<string>;
26
- type: PropTypes.Requireable<string>;
27
- filterValues: PropTypes.Requireable<PropTypes.InferProps<{
28
- value: PropTypes.Requireable<string>;
29
- placeholder: PropTypes.Requireable<string>;
30
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
31
- }> | PropTypes.InferProps<{
32
- value: PropTypes.Requireable<PropTypes.InferProps<{}>>;
33
- items: PropTypes.Requireable<(PropTypes.InferProps<{
34
- label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
35
- value: PropTypes.Requireable<string>;
36
- }> | null | undefined)[]>;
37
- placeholder: PropTypes.Requireable<string>;
38
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
39
- }>>;
40
- }> | null | undefined)[]>;
41
- }
42
- namespace defaultProps {
43
- const value_1: string;
44
- export { value_1 as value };
45
- const items_1: never[];
46
- export { items_1 as items };
47
- const hideLabel_1: boolean;
48
- export { hideLabel_1 as hideLabel };
49
- const isDisabled_1: boolean;
50
- export { isDisabled_1 as isDisabled };
51
- const id_1: string;
52
- export { id_1 as id };
53
- const useMobileLayout_1: boolean;
54
- export { useMobileLayout_1 as useMobileLayout };
55
- }
20
+ export interface ConditionalFilterItem {
21
+ id?: string;
22
+ label?: Node;
23
+ value?: string;
24
+ type: 'text' | 'checkbox' | 'radio' | 'custom' | 'group';
25
+ filterValues?: TextInputProps | FilterValues;
26
+ placeholder?: string;
56
27
  }
57
- import React from "react";
58
- import PropTypes from "prop-types";
28
+ export interface ConditionalFilterProps extends TextInputProps {
29
+ hideLabel: boolean;
30
+ items: ConditionalFilterItem[];
31
+ id: string;
32
+ isDisabled: boolean;
33
+ useMobileLayout: boolean;
34
+ }
35
+ declare const ConditionalFilter: React.FunctionComponent<ConditionalFilterProps>;
36
+ export default ConditionalFilter;
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __assign = (this && this.__assign) || function () {
18
3
  __assign = Object.assign || function(t) {
19
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -44,150 +29,71 @@ var __importStar = (this && this.__importStar) || function (mod) {
44
29
  __setModuleDefault(result, mod);
45
30
  return result;
46
31
  };
47
- var __rest = (this && this.__rest) || function (s, e) {
48
- var t = {};
49
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
- t[p] = s[p];
51
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
- t[p[i]] = s[p[i]];
55
- }
56
- return t;
57
- };
58
32
  var __importDefault = (this && this.__importDefault) || function (mod) {
59
33
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
34
  };
61
- var _a;
62
35
  Object.defineProperty(exports, "__esModule", { value: true });
63
36
  var react_1 = __importStar(require("react"));
37
+ var classnames_1 = __importDefault(require("classnames"));
38
+ var global_breakpoint_md_1 = __importDefault(require("@patternfly/react-tokens/dist/js/global_breakpoint_md"));
39
+ var lodash_1 = require("lodash");
64
40
  var react_core_1 = require("@patternfly/react-core");
65
41
  var react_icons_1 = require("@patternfly/react-icons");
66
- var global_breakpoint_md_1 = __importDefault(require("@patternfly/react-tokens/dist/js/global_breakpoint_md"));
67
42
  var TextFilter_1 = __importDefault(require("./TextFilter"));
68
43
  var conditionalFilterConstants_1 = require("./conditionalFilterConstants");
69
- var prop_types_1 = __importDefault(require("prop-types"));
70
44
  require("./conditional-filter.css");
71
- var react_2 = require("react");
72
- var classnames_1 = __importDefault(require("classnames"));
73
- var ConditionalFilter = (function (_super) {
74
- __extends(ConditionalFilter, _super);
75
- function ConditionalFilter(props) {
76
- var _this = this;
77
- if (!props.useMobileLayout) {
78
- console.warn("The prop \"useMobileLayout\" is set to false. You are using an outdated mobile layout of conditional filter.\n Please switch to new layout by adding \"useMobileLayout={true}\" prop to the PrimaryToolbar or ConditionalFilter directly.\n The new mobile layout will become the default in next minor release.");
79
- }
80
- _this = _super.call(this, props) || this;
81
- _this.dropdownToggle = function (isOpen) {
82
- _this.setState({
83
- isOpen: isOpen,
84
- });
45
+ var ConditionalFilter = function (_a) {
46
+ var _b = _a.hideLabel, hideLabel = _b === void 0 ? false : _b, _c = _a.id, id = _c === void 0 ? 'default-input' : _c, _d = _a.isDisabled, isDisabled = _d === void 0 ? false : _d, _f = _a.items, items = _f === void 0 ? [] : _f, onChange = _a.onChange, placeholder = _a.placeholder, _g = _a.useMobileLayout, useMobileLayout = _g === void 0 ? false : _g, _h = _a.value, value = _h === void 0 ? '' : _h;
47
+ var breakpointConstant = parseInt(global_breakpoint_md_1.default.value.replace('px', ''));
48
+ var updateFilterViewport = function (width) { return width <= breakpointConstant; };
49
+ var _j = (0, react_1.useState)(false), isOpen = _j[0], setIsOpen = _j[1];
50
+ var _k = (0, react_1.useState)(), stateValue = _k[0], setStateValue = _k[1];
51
+ var _l = (0, react_1.useState)(updateFilterViewport(window.innerWidth)), isMobile = _l[0], setIsMobile = _l[1];
52
+ var resizeListener = (0, react_1.useRef)(function (event) {
53
+ setIsMobile(updateFilterViewport((event === null || event === void 0 ? void 0 : event.target).innerWidth));
54
+ });
55
+ (0, react_1.useEffect)(function () {
56
+ useMobileLayout ||
57
+ console.warn("The prop \"useMobileLayout\" is set to false. You are using an outdated mobile layout of conditional filter.\n Please switch to new layout by adding \"useMobileLayout={true}\" prop to the PrimaryToolbar or ConditionalFilter directly.\n The new mobile layout will become the default in next minor release.");
58
+ window.addEventListener('resize', resizeListener.current);
59
+ return function () {
60
+ resizeListener.current && window.removeEventListener('resize', resizeListener.current);
85
61
  };
86
- _this.onChange = function (_e, value) {
87
- _this.setState({
88
- stateValue: value,
89
- });
90
- };
91
- _this.getWrapper = function () {
92
- return _this.props.useMobileLayout && _this.state.isMobile
93
- ? function (props) { return react_1.default.createElement(react_core_1.ToolbarToggleGroup, __assign({}, props, { breakpoint: "md", toggleIcon: react_1.default.createElement(react_icons_1.FilterIcon, null) })); }
94
- : react_2.Fragment;
95
- };
96
- _this.updateFilterViewport = function (width) { return width <= _this.breakpointConstant; };
97
- _this.breakpointConstant = parseInt(global_breakpoint_md_1.default.value.replace('px', ''));
98
- _this.state = {
99
- isOpen: false,
100
- stateValue: undefined,
101
- isMobile: _this.updateFilterViewport(window.innerWidth),
102
- };
103
- return _this;
104
- }
105
- ConditionalFilter.prototype.componentDidMount = function () {
106
- var _this = this;
107
- this.resizeListener = window.addEventListener('resize', function (event) {
108
- _this.setState(function (prev) { return (__assign(__assign({}, prev), { isMobile: _this.updateFilterViewport(event.target.innerWidth) })); });
109
- });
110
- };
111
- ConditionalFilter.prototype.componentWillUnmount = function () {
112
- if (this.resizeListener) {
113
- window.removeEventListener(this.resizeListener);
114
- }
115
- };
116
- ConditionalFilter.prototype.render = function () {
117
- var _this = this;
118
- var _a = this.props, items = _a.items, value = _a.value, onChange = _a.onChange, placeholder = _a.placeholder, hideLabel = _a.hideLabel, isDisabled = _a.isDisabled, useMobileLayout = _a.useMobileLayout, props = __rest(_a, ["items", "value", "onChange", "placeholder", "hideLabel", "isDisabled", "useMobileLayout"]);
119
- var _b = this.state, isOpen = _b.isOpen, stateValue = _b.stateValue, isMobile = _b.isMobile;
120
- var currentValue = onChange ? value : stateValue;
121
- var activeItem = items && items.length && (items.find(function (item, key) { return item.value === currentValue || key === currentValue; }) || items[0]);
122
- var onChangeCallback = onChange || this.onChange;
123
- var ActiveComponent = activeItem && (conditionalFilterConstants_1.typeMapper[activeItem.type] || conditionalFilterConstants_1.typeMapper.text);
124
- var capitalize = function (string) { return string[0].toUpperCase() + string.substring(1); };
125
- var shouldRenderNewLayout = useMobileLayout && isMobile;
126
- var Wrapper = this.getWrapper();
127
- return (react_1.default.createElement(Wrapper, null,
128
- useMobileLayout && isMobile && (react_1.default.createElement(react_core_1.ToolbarGroup, { className: "ins-c-conditional-filter mobile" }, items.map(function (activeItem, key) {
129
- var ActiveComponent = activeItem && (conditionalFilterConstants_1.typeMapper[activeItem.type] || conditionalFilterConstants_1.typeMapper.text);
130
- return (react_1.default.createElement(react_core_1.ToolbarItem, { key: key },
131
- react_1.default.createElement(ActiveComponent, __assign({}, (activeItem.type !== conditionalFilterConstants_1.conditionalFilterType.custom && {
132
- placeholder: placeholder || activeItem.placeholder || "Filter by ".concat(activeItem.label),
133
- id: (activeItem.filterValues && activeItem.filterValues.id) || currentValue,
134
- }), activeItem.filterValues))));
135
- }))),
136
- !shouldRenderNewLayout && (react_1.default.createElement(react_2.Fragment, null, !items || (items && items.length <= 0) ? (react_1.default.createElement("div", { className: (0, classnames_1.default)('ins-c-conditional-filter', {
137
- desktop: useMobileLayout,
138
- }) },
139
- react_1.default.createElement(TextFilter_1.default, __assign({}, props, { value: currentValue, onChange: function (e) { return onChangeCallback(e, e.target.value); }, placeholder: placeholder, "widget-type": "InsightsInput" })))) : (react_1.default.createElement(react_core_1.Split, { className: (0, classnames_1.default)('ins-c-conditional-filter', {
140
- desktop: useMobileLayout,
141
- }) },
142
- items.length > 1 && (react_1.default.createElement(react_core_1.SplitItem, null,
143
- react_1.default.createElement(react_core_1.Dropdown, { className: "ins-c-conditional-filter__group", onSelect: function () { return _this.dropdownToggle(false); }, isOpen: isOpen, ouiaId: "ConditionalFilter", toggle: react_1.default.createElement(react_core_1.DropdownToggle, { "aria-label": "Conditional filter", onToggle: this.dropdownToggle, isDisabled: isDisabled, className: hideLabel ? 'ins-c-conditional-filter__no-label' : '', ouiaId: "ConditionalFilter" },
144
- react_1.default.createElement(react_icons_1.FilterIcon, { size: "sm" }),
145
- !hideLabel && (react_1.default.createElement("span", { className: "ins-c-conditional-filter__value-selector" }, activeItem && capitalize(activeItem.label)))), dropdownItems: items.map(function (item, key) { return (react_1.default.createElement(react_core_1.DropdownItem, { key: item.id ? "".concat(item.id, "-dropdown") : key, component: "button", ouiaId: item.label, onClick: function (e) { return onChangeCallback(e, item.value || key, item); }, isHovered: activeItem.label === item.label }, capitalize(item.label))); }) }))),
146
- ActiveComponent && (react_1.default.createElement(react_core_1.SplitItem, { isFilled: true },
147
- react_1.default.createElement(ActiveComponent, __assign({}, (activeItem.type !== conditionalFilterConstants_1.conditionalFilterType.custom && {
148
- placeholder: placeholder || activeItem.placeholder || "Filter by ".concat(activeItem.label),
149
- id: (activeItem.filterValues && activeItem.filterValues.id) || currentValue,
150
- }), activeItem.filterValues))))))))));
151
- };
152
- return ConditionalFilter;
153
- }(react_1.Component));
154
- var TextInputProps = {
155
- value: prop_types_1.default.string,
156
- placeholder: prop_types_1.default.string,
157
- onChange: prop_types_1.default.func,
158
- };
159
- ConditionalFilter.propTypes = __assign(__assign({ hideLabel: prop_types_1.default.bool, items: prop_types_1.default.arrayOf(prop_types_1.default.shape({
160
- id: prop_types_1.default.string,
161
- label: prop_types_1.default.node,
162
- value: prop_types_1.default.string,
163
- type: prop_types_1.default.oneOf(['text', 'checkbox', 'radio', 'custom', 'group']),
164
- filterValues: prop_types_1.default.oneOfType([
165
- prop_types_1.default.shape(TextInputProps),
166
- prop_types_1.default.shape(__assign(__assign({}, TextInputProps), { value: prop_types_1.default.oneOfType([
167
- prop_types_1.default.string,
168
- prop_types_1.default.arrayOf(prop_types_1.default.oneOfType([
169
- prop_types_1.default.string,
170
- prop_types_1.default.shape({
171
- label: prop_types_1.default.node,
172
- value: prop_types_1.default.string,
173
- }),
174
- ])),
175
- prop_types_1.default.shape((_a = {},
176
- _a[prop_types_1.default.string] = prop_types_1.default.any,
177
- _a)),
178
- ]), items: prop_types_1.default.arrayOf(prop_types_1.default.shape({
179
- label: prop_types_1.default.node,
180
- value: prop_types_1.default.string,
181
- })) })),
182
- ]),
183
- })) }, TextInputProps), { id: prop_types_1.default.string, isDisabled: prop_types_1.default.bool, useMobileLayout: prop_types_1.default.bool });
184
- ConditionalFilter.defaultProps = {
185
- value: '',
186
- items: [],
187
- hideLabel: false,
188
- isDisabled: false,
189
- id: 'default-input',
190
- useMobileLayout: false,
62
+ }, []);
63
+ var currentValue = onChange ? value : stateValue;
64
+ var activeItem = items && items.length && (items.find(function (item, key) { return item.value === currentValue || key === Number(currentValue); }) || items[0]);
65
+ var onChangeDefault = function (_e, value) { return setStateValue(value); };
66
+ var onChangeCallback = onChange || onChangeDefault;
67
+ var shouldRenderNewLayout = useMobileLayout && isMobile;
68
+ var capitalize = function (string) { return string[0].toUpperCase() + string.substring(1); };
69
+ var ActiveComponent = activeItem && (conditionalFilterConstants_1.typeMapper[activeItem.type] || conditionalFilterConstants_1.typeMapper.text);
70
+ var Wrapper = useMobileLayout && isMobile
71
+ ? function (props) { return react_1.default.createElement(react_core_1.ToolbarToggleGroup, __assign({}, props, { breakpoint: "md", toggleIcon: react_1.default.createElement(react_icons_1.FilterIcon, null) })); }
72
+ : react_1.Fragment;
73
+ return (react_1.default.createElement(Wrapper, null,
74
+ useMobileLayout && isMobile && (react_1.default.createElement(react_core_1.ToolbarGroup, { className: "ins-c-conditional-filter mobile" }, items.map(function (activeItem, key) {
75
+ var ActiveComponent = activeItem && (conditionalFilterConstants_1.typeMapper[activeItem.type] || conditionalFilterConstants_1.typeMapper.text);
76
+ return (react_1.default.createElement(react_core_1.ToolbarItem, { key: key },
77
+ react_1.default.createElement(ActiveComponent, __assign({}, (activeItem.type !== conditionalFilterConstants_1.conditionalFilterType.custom && {
78
+ placeholder: placeholder || activeItem.placeholder || "Filter by ".concat(activeItem.label),
79
+ id: activeItem.filterValues ? activeItem.filterValues.id : currentValue ? String(currentValue) : undefined,
80
+ }), (0, lodash_1.omit)(activeItem.filterValues, 'value')))));
81
+ }))),
82
+ !shouldRenderNewLayout && (react_1.default.createElement(react_1.Fragment, null, !items || (items && items.length <= 0) ? (react_1.default.createElement("div", { className: (0, classnames_1.default)('ins-c-conditional-filter', {
83
+ desktop: useMobileLayout,
84
+ }) },
85
+ react_1.default.createElement(TextFilter_1.default, { id: id, isDisabled: isDisabled, onChange: function (e) { return onChangeCallback(e, Number(e.target.value)); }, placeholder: placeholder, value: currentValue ? String(currentValue) : undefined, "widget-type": "InsightsInput" }))) : (react_1.default.createElement(react_core_1.Split, { className: (0, classnames_1.default)('ins-c-conditional-filter', {
86
+ desktop: useMobileLayout,
87
+ }) },
88
+ items.length > 1 && (react_1.default.createElement(react_core_1.SplitItem, null,
89
+ react_1.default.createElement(react_core_1.Dropdown, { className: "ins-c-conditional-filter__group", onSelect: function () { return setIsOpen(false); }, isOpen: isOpen, ouiaId: "ConditionalFilter", toggle: react_1.default.createElement(react_core_1.DropdownToggle, { "aria-label": "Conditional filter", onToggle: setIsOpen, isDisabled: isDisabled, className: hideLabel ? 'ins-c-conditional-filter__no-label' : '', ouiaId: "ConditionalFilter" },
90
+ react_1.default.createElement(react_icons_1.FilterIcon, { size: "sm" }),
91
+ !hideLabel && (react_1.default.createElement("span", { className: "ins-c-conditional-filter__value-selector" }, activeItem && capitalize(String(activeItem.label))))), dropdownItems: items.map(function (item, key) { return (react_1.default.createElement(react_core_1.DropdownItem, { key: item.id ? "".concat(item.id, "-dropdown") : key, component: "button", ouiaId: String(item.label), onClick: function (e) { return onChangeCallback(e, item.value || key); }, isHovered: activeItem.label === item.label }, capitalize(String(item.label)))); }) }))),
92
+ ActiveComponent && (react_1.default.createElement(react_core_1.SplitItem, { isFilled: true },
93
+ react_1.default.createElement(ActiveComponent, __assign({}, (activeItem.type !== conditionalFilterConstants_1.conditionalFilterType.custom && {
94
+ placeholder: placeholder || activeItem.placeholder || "Filter by ".concat(activeItem.label),
95
+ id: (activeItem.filterValues && activeItem.filterValues.id) || currentValue ? String(currentValue) : undefined,
96
+ }), (0, lodash_1.omit)(activeItem.filterValues, 'value')))))))))));
191
97
  };
192
98
  exports.default = ConditionalFilter;
193
99
  //# sourceMappingURL=ConditionalFilter.js.map