@invoicebox/ui 0.1.0-alpha.184 → 0.1.0-alpha.186
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.
|
@@ -9,6 +9,7 @@ export type TOption<TValue> = {
|
|
|
9
9
|
export type TGroup = {
|
|
10
10
|
label: string;
|
|
11
11
|
id: string;
|
|
12
|
+
entity?: unknown;
|
|
12
13
|
};
|
|
13
14
|
export type TProps<TValue> = Pick<TInputProps, 'label' | 'hasError' | 'placeholder' | 'name' | 'size'> & {
|
|
14
15
|
value: TValue | null;
|
|
@@ -17,8 +18,9 @@ export type TProps<TValue> = Pick<TInputProps, 'label' | 'hasError' | 'placehold
|
|
|
17
18
|
groups?: TGroup[];
|
|
18
19
|
isResetButtonEnabled?: boolean;
|
|
19
20
|
renderOption?: (entity?: any) => ReactNode;
|
|
21
|
+
renderGroup?: (entity?: any) => ReactNode;
|
|
20
22
|
dropdownHeader?: ReactNode;
|
|
21
23
|
isDrawerOptions?: boolean;
|
|
22
24
|
scrollbarMaxHeight?: number;
|
|
23
25
|
};
|
|
24
|
-
export declare const Select: <TValue extends string | number>({ label, hasError, placeholder, name, value, onChange, options, groups, isResetButtonEnabled, size, renderOption, dropdownHeader, isDrawerOptions, scrollbarMaxHeight, }: TProps<TValue>) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare const Select: <TValue extends string | number>({ label, hasError, placeholder, name, value, onChange, options, groups, isResetButtonEnabled, size, renderOption, dropdownHeader, isDrawerOptions, renderGroup, scrollbarMaxHeight, }: TProps<TValue>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -42,6 +42,7 @@ var Select = exports.Select = function Select(_ref) {
|
|
|
42
42
|
dropdownHeader = _ref.dropdownHeader,
|
|
43
43
|
_ref$isDrawerOptions = _ref.isDrawerOptions,
|
|
44
44
|
isDrawerOptions = _ref$isDrawerOptions === void 0 ? false : _ref$isDrawerOptions,
|
|
45
|
+
renderGroup = _ref.renderGroup,
|
|
45
46
|
_ref$scrollbarMaxHeig = _ref.scrollbarMaxHeight,
|
|
46
47
|
scrollbarMaxHeight = _ref$scrollbarMaxHeig === void 0 ? MAX_LIST_HEIGHT : _ref$scrollbarMaxHeig;
|
|
47
48
|
var palette = (0, _palette.useComponentPalette)('select');
|
|
@@ -112,14 +113,39 @@ var Select = exports.Select = function Select(_ref) {
|
|
|
112
113
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
|
|
113
114
|
handleShow();
|
|
114
115
|
};
|
|
116
|
+
var handleOptionRender = function handleOptionRender(option) {
|
|
117
|
+
if (renderOption) {
|
|
118
|
+
if (!option.entity) {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.error('option.entity not found');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
return renderOption(option.entity);
|
|
124
|
+
}
|
|
125
|
+
return /*#__PURE__*/_react["default"].createElement(S.DefaultOptionWrapper, null, " ", option.label);
|
|
126
|
+
};
|
|
127
|
+
var handleGroupRender = function handleGroupRender(group) {
|
|
128
|
+
if (group) {
|
|
129
|
+
if (renderGroup) {
|
|
130
|
+
if (!group.entity) {
|
|
131
|
+
// eslint-disable-next-line no-console
|
|
132
|
+
console.error('group.entity not found');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
return renderGroup(group.entity);
|
|
136
|
+
}
|
|
137
|
+
return /*#__PURE__*/_react["default"].createElement(S.Group, {
|
|
138
|
+
variant: "headerText"
|
|
139
|
+
}, group.label);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
};
|
|
115
143
|
var dropdownContent = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, dropdownHeader, optionGroups.map(function (_ref2) {
|
|
116
144
|
var group = _ref2.group,
|
|
117
145
|
groupOptions = _ref2.options;
|
|
118
146
|
return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
|
|
119
147
|
key: (group === null || group === void 0 ? void 0 : group.id) || null
|
|
120
|
-
},
|
|
121
|
-
variant: "headerText"
|
|
122
|
-
}, group.label), groupOptions.map(function (option) {
|
|
148
|
+
}, handleGroupRender(group), groupOptions.map(function (option) {
|
|
123
149
|
return /*#__PURE__*/_react["default"].createElement(S.Option, {
|
|
124
150
|
key: option.value,
|
|
125
151
|
$palette: palette,
|
|
@@ -127,8 +153,8 @@ var Select = exports.Select = function Select(_ref) {
|
|
|
127
153
|
onClick: handleSelect,
|
|
128
154
|
"data-value": JSON.stringify(option.value),
|
|
129
155
|
"data-option-identifier": OPTION_IDENTIFIER,
|
|
130
|
-
$isGrouped: !!group
|
|
131
|
-
},
|
|
156
|
+
$isGrouped: !!group && !renderGroup
|
|
157
|
+
}, handleOptionRender(option));
|
|
132
158
|
}));
|
|
133
159
|
}));
|
|
134
160
|
return /*#__PURE__*/_react["default"].createElement(S.Wrapper, {
|
|
@@ -7,3 +7,4 @@ export declare const WithDropdownHeader: StoryObj<TProps<string>>;
|
|
|
7
7
|
export declare const RenderOption: StoryObj<TProps<string>>;
|
|
8
8
|
export declare const WithGroups: StoryObj<TProps<string>>;
|
|
9
9
|
export declare const RenderOptionWithGroups: StoryObj<TProps<string>>;
|
|
10
|
+
export declare const WithCustomGroups: StoryObj<TProps<string>>;
|
|
@@ -4,7 +4,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports["default"] = exports.WithGroups = exports.WithDropdownHeader = exports.RenderOptionWithGroups = exports.RenderOption = exports.Default = void 0;
|
|
7
|
+
exports["default"] = exports.WithGroups = exports.WithDropdownHeader = exports.WithCustomGroups = exports.RenderOptionWithGroups = exports.RenderOption = exports.Default = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _addonActions = require("@storybook/addon-actions");
|
|
10
10
|
var _ = require(".");
|
|
@@ -130,6 +130,9 @@ var COMMON_ARGS = {
|
|
|
130
130
|
var renderOption = function renderOption(entity) {
|
|
131
131
|
return /*#__PURE__*/_react["default"].createElement("div", null, "Hello ", entity.name, " ");
|
|
132
132
|
};
|
|
133
|
+
var renderGroup = function renderGroup(group) {
|
|
134
|
+
return /*#__PURE__*/_react["default"].createElement("div", null, "Group name is: ", group.name, " ");
|
|
135
|
+
};
|
|
133
136
|
var Default = exports.Default = {
|
|
134
137
|
args: _objectSpread({}, COMMON_ARGS),
|
|
135
138
|
render: Component
|
|
@@ -170,4 +173,23 @@ var RenderOptionWithGroups = exports.RenderOptionWithGroups = {
|
|
|
170
173
|
renderOption: renderOption
|
|
171
174
|
}),
|
|
172
175
|
render: Component
|
|
176
|
+
};
|
|
177
|
+
var WithCustomGroups = exports.WithCustomGroups = {
|
|
178
|
+
args: _objectSpread(_objectSpread({}, COMMON_ARGS), {}, {
|
|
179
|
+
groups: [{
|
|
180
|
+
label: 'Group 1',
|
|
181
|
+
id: '1',
|
|
182
|
+
entity: {
|
|
183
|
+
name: 'name group 1'
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
label: 'Group 2',
|
|
187
|
+
id: '2',
|
|
188
|
+
entity: {
|
|
189
|
+
name: 'name group 2'
|
|
190
|
+
}
|
|
191
|
+
}],
|
|
192
|
+
renderGroup: renderGroup
|
|
193
|
+
}),
|
|
194
|
+
render: Component
|
|
173
195
|
};
|