@assembly-js/design-system 3.1.11 → 3.1.14

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 (45) hide show
  1. package/dist/esm/components/UserCompanySelector/ListItem.js +12 -9
  2. package/dist/esm/components/UserCompanySelector/SelectedValueChip.js +5 -1
  3. package/dist/esm/components/UserCompanySelector/UserCompanySelector.js +36 -46
  4. package/dist/esm/components/UserCompanySelector/__tests__/getClassNames.test.js +81 -0
  5. package/dist/esm/components/UserCompanySelector/__tests__/getOptionRelevanceScore.test.js +115 -0
  6. package/dist/esm/components/UserCompanySelector/data.js +17 -15
  7. package/dist/esm/components/UserCompanySelector/getClassNames.js +44 -0
  8. package/dist/esm/components/UserCompanySelector/getOptionRelevanceScore.js +33 -0
  9. package/dist/esm/types/components/UserCompanySelector/ListItem.d.ts +8 -3
  10. package/dist/esm/types/components/UserCompanySelector/UserCompanySelector.stories.d.ts +2 -0
  11. package/dist/esm/types/components/UserCompanySelector/__tests__/getClassNames.test.d.ts +1 -0
  12. package/dist/esm/types/components/UserCompanySelector/__tests__/getOptionRelevanceScore.test.d.ts +1 -0
  13. package/dist/esm/types/components/UserCompanySelector/getClassNames.d.ts +11 -0
  14. package/dist/esm/types/components/UserCompanySelector/getOptionRelevanceScore.d.ts +14 -0
  15. package/dist/esm/types/components/UserCompanySelector/types.d.ts +11 -0
  16. package/dist/esm/types/index.d.ts +1 -1
  17. package/dist/esm/types/tsconfig.tsbuildinfo +1 -1
  18. package/dist/styles/main.css +1 -1
  19. package/dist/types/components/UserCompanySelector/ListItem.d.ts +8 -3
  20. package/dist/types/components/UserCompanySelector/UserCompanySelector.stories.d.ts +2 -0
  21. package/dist/types/components/UserCompanySelector/__tests__/getClassNames.test.d.ts +1 -0
  22. package/dist/types/components/UserCompanySelector/__tests__/getOptionRelevanceScore.test.d.ts +1 -0
  23. package/dist/types/components/UserCompanySelector/getClassNames.d.ts +11 -0
  24. package/dist/types/components/UserCompanySelector/getOptionRelevanceScore.d.ts +14 -0
  25. package/dist/types/components/UserCompanySelector/types.d.ts +11 -0
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/tsconfig.tsbuildinfo +1 -1
  28. package/dist/umd/components/UserCompanySelector/ListItem.js +15 -12
  29. package/dist/umd/components/UserCompanySelector/SelectedValueChip.js +5 -1
  30. package/dist/umd/components/UserCompanySelector/UserCompanySelector.js +38 -50
  31. package/dist/umd/components/UserCompanySelector/__tests__/getClassNames.test.js +96 -0
  32. package/dist/umd/components/UserCompanySelector/__tests__/getOptionRelevanceScore.test.js +130 -0
  33. package/dist/umd/components/UserCompanySelector/data.js +17 -15
  34. package/dist/umd/components/UserCompanySelector/getClassNames.js +64 -0
  35. package/dist/umd/components/UserCompanySelector/getOptionRelevanceScore.js +53 -0
  36. package/dist/umd/types/components/UserCompanySelector/ListItem.d.ts +8 -3
  37. package/dist/umd/types/components/UserCompanySelector/UserCompanySelector.stories.d.ts +2 -0
  38. package/dist/umd/types/components/UserCompanySelector/__tests__/getClassNames.test.d.ts +1 -0
  39. package/dist/umd/types/components/UserCompanySelector/__tests__/getOptionRelevanceScore.test.d.ts +1 -0
  40. package/dist/umd/types/components/UserCompanySelector/getClassNames.d.ts +11 -0
  41. package/dist/umd/types/components/UserCompanySelector/getOptionRelevanceScore.d.ts +14 -0
  42. package/dist/umd/types/components/UserCompanySelector/types.d.ts +11 -0
  43. package/dist/umd/types/index.d.ts +1 -1
  44. package/dist/umd/types/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +1 -1
@@ -1,17 +1,17 @@
1
1
  // This file is generated by a script. Do not edit this file directly.
2
2
  (function (global, factory) {
3
3
  if (typeof define === "function" && define.amd) {
4
- define(["exports", "react", "../Avatar/Avatar", "../Typography", "clsx", "../Avatar/UserWithCompanyAvatar", "../../common/utils"], factory);
4
+ define(["exports", "react", "../Avatar/Avatar", "../Typography", "../Avatar/UserWithCompanyAvatar", "../../common/utils"], factory);
5
5
  } else if (typeof exports !== "undefined") {
6
- factory(exports, require("react"), require("../Avatar/Avatar"), require("../Typography"), require("clsx"), require("../Avatar/UserWithCompanyAvatar"), require("../../common/utils"));
6
+ factory(exports, require("react"), require("../Avatar/Avatar"), require("../Typography"), require("../Avatar/UserWithCompanyAvatar"), require("../../common/utils"));
7
7
  } else {
8
8
  var mod = {
9
9
  exports: {}
10
10
  };
11
- factory(mod.exports, global.react, global.Avatar, global.Typography, global.clsx, global.UserWithCompanyAvatar, global.utils);
11
+ factory(mod.exports, global.react, global.Avatar, global.Typography, global.UserWithCompanyAvatar, global.utils);
12
12
  global.ListItem = mod.exports;
13
13
  }
14
- })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _Avatar, _Typography, _clsx, _UserWithCompanyAvatar, _utils) {
14
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _Avatar, _Typography, _UserWithCompanyAvatar, _utils) {
15
15
  "use strict";
16
16
 
17
17
  Object.defineProperty(_exports, "__esModule", {
@@ -19,15 +19,16 @@
19
19
  });
20
20
  _exports.ListItem = ListItem;
21
21
  _react = _interopRequireDefault(_react);
22
- _clsx = _interopRequireDefault(_clsx);
23
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
24
23
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
25
- function ListItem(_ref) {
24
+ function ListItem(props) {
26
25
  var _option$avatarSrc, _option$avatarFallbac, _option$label;
27
- var option = _ref.data,
28
- innerRef = _ref.innerRef,
29
- isFocused = _ref.isFocused,
30
- innerProps = _ref.innerProps;
26
+ var option = props.data,
27
+ innerRef = props.innerRef,
28
+ isFocused = props.isFocused,
29
+ isSelected = props.isSelected,
30
+ innerProps = props.innerProps,
31
+ listClassName = props.listClassName;
31
32
  var avatarSrc = option.avatarSrc,
32
33
  avatarFallbackColor = option.avatarFallbackColor,
33
34
  label = option.label,
@@ -39,13 +40,15 @@
39
40
  key: option.value,
40
41
  ref: innerRef
41
42
  }, innerProps, {
42
- className: (0, _clsx["default"])('cop-flex cop-cursor-pointer cop-items-center cop-gap-3 cop-px-3 hover:cop-bg-gray-100', {
43
+ "data-focused": isFocused || undefined,
44
+ "data-selected": isSelected || undefined,
45
+ className: (0, _utils.cn)('cop-flex cop-cursor-pointer cop-items-center cop-gap-3 cop-px-3 hover:cop-bg-gray-100', {
43
46
  'cop-h-10': !!companyName,
44
47
  // if an option has company name to render, the option should have a height of 40px
45
48
  'cop-h-8': !companyName,
46
49
  // if an option has no company name to render, the option should have a height of 32px
47
50
  'cop-bg-primary': isFocused
48
- })
51
+ }, listClassName)
49
52
  }), option.type !== 'company' ? /*#__PURE__*/_react["default"].createElement(_UserWithCompanyAvatar.UserWithCompanyAvatar, {
50
53
  size: "sm",
51
54
  avatarSrc: (_option$avatarSrc = option.avatarSrc) !== null && _option$avatarSrc !== void 0 ? _option$avatarSrc : '',
@@ -39,8 +39,12 @@
39
39
  }
40
40
  };
41
41
  return /*#__PURE__*/_react["default"].createElement(_Chip.Chip, {
42
- className: "!cop-rounded cop-border cop-border-solid cop-py-[5px] cop-max-w-[200px]",
42
+ className: "cop-max-w-[200px] !cop-rounded cop-border cop-border-solid cop-py-[5px]",
43
43
  variant: "outlined",
44
+ onClick: function onClick() {
45
+ return null;
46
+ } // passing onclick would allow showing the hover state - this is a temporary solution avoiding doing big changes in the chip component might causing regressions
47
+ ,
44
48
  truncate: true,
45
49
  onClose: handleRemove,
46
50
  prefixIcon: option.type === 'company' ? /*#__PURE__*/_react["default"].createElement(_Avatar.Avatar, {
@@ -2,17 +2,17 @@
2
2
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
3
  (function (global, factory) {
4
4
  if (typeof define === "function" && define.amd) {
5
- define(["exports", "react", "react-select", "./ListItem", "../Typography", "./SelectedValueChip", "./LimitedOptionsList", "../../theme/colors"], factory);
5
+ define(["exports", "react", "react-select", "./ListItem", "../Typography", "./SelectedValueChip", "./LimitedOptionsList", "../../theme/colors", "./getClassNames", "./getOptionRelevanceScore"], factory);
6
6
  } else if (typeof exports !== "undefined") {
7
- factory(exports, require("react"), require("react-select"), require("./ListItem"), require("../Typography"), require("./SelectedValueChip"), require("./LimitedOptionsList"), require("../../theme/colors"));
7
+ factory(exports, require("react"), require("react-select"), require("./ListItem"), require("../Typography"), require("./SelectedValueChip"), require("./LimitedOptionsList"), require("../../theme/colors"), require("./getClassNames"), require("./getOptionRelevanceScore"));
8
8
  } else {
9
9
  var mod = {
10
10
  exports: {}
11
11
  };
12
- factory(mod.exports, global.react, global.reactSelect, global.ListItem, global.Typography, global.SelectedValueChip, global.LimitedOptionsList, global.colors);
12
+ factory(mod.exports, global.react, global.reactSelect, global.ListItem, global.Typography, global.SelectedValueChip, global.LimitedOptionsList, global.colors, global.getClassNames, global.getOptionRelevanceScore);
13
13
  global.UserCompanySelector = mod.exports;
14
14
  }
15
- })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _reactSelect, _ListItem, _Typography, _SelectedValueChip, _LimitedOptionsList, _colors) {
15
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _reactSelect, _ListItem, _Typography, _SelectedValueChip, _LimitedOptionsList, _colors, _getClassNames, _getOptionRelevanceScore) {
16
16
  "use strict";
17
17
  'use client';
18
18
 
@@ -22,7 +22,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
22
22
  _exports.UserCompanySelector = void 0;
23
23
  _react = _interopRequireWildcard(_react);
24
24
  _reactSelect = _interopRequireDefault(_reactSelect);
25
- var _excluded = ["autoFocus", "grouped", "name", "internalUsers", "clientUsers", "companies", "onChange", "onBlur", "placeholder", "styles", "ignoreCompanies", "ignoreFilterClientsByCompany", "limitSelectedOptions", "initialValue", "customLabels", "listHeading"];
25
+ var _excluded = ["autoFocus", "grouped", "name", "internalUsers", "clientUsers", "companies", "onChange", "onBlur", "placeholder", "styles", "ignoreCompanies", "ignoreFilterClientsByCompany", "limitSelectedOptions", "initialValue", "customLabels", "listHeading", "listClassName", "variant"];
26
26
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
27
27
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
28
28
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
@@ -93,6 +93,9 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
93
93
  initialValue = _ref.initialValue,
94
94
  customLabels = _ref.customLabels,
95
95
  listHeading = _ref.listHeading,
96
+ listClassName = _ref.listClassName,
97
+ _ref$variant = _ref.variant,
98
+ variant = _ref$variant === void 0 ? 'default' : _ref$variant,
96
99
  others = _objectWithoutProperties(_ref, _excluded);
97
100
  var limitSelectedOptions = limitSelectedOptionsUnvalidated === 0 ? 1000 : Math.min(1000, limitSelectedOptionsUnvalidated);
98
101
  var companiesMap = (0, _react.useMemo)(function () {
@@ -116,29 +119,9 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
116
119
  _useState4 = _slicedToArray(_useState3, 2),
117
120
  inputValue = _useState4[0],
118
121
  setInputValue = _useState4[1];
119
-
120
- /**
121
- * Returns a relevance score for an option based on the input value.
122
- * Higher scores indicate more relevant matches (direct name matches > company name matches).
123
- * @param option - the option to score
124
- * @returns 2 for direct name match, 1 for company name match only, 0 for no match
125
- */
126
- var getOptionRelevanceScore = (0, _react.useCallback)(function (option) {
127
- if (!inputValue) {
128
- return 1; // Show all options when no input
129
- }
130
- var lowerInput = inputValue.toLowerCase();
131
- var nameMatches = option.label.toLowerCase().includes(lowerInput);
132
- if (option.type === 'client') {
133
- var _option$companyId, _company$label;
134
- var company = companiesMap.get((_option$companyId = option.companyId) !== null && _option$companyId !== void 0 ? _option$companyId : '');
135
- var companyMatches = company === null || company === void 0 || (_company$label = company.label) === null || _company$label === void 0 ? void 0 : _company$label.toLowerCase().includes(lowerInput);
136
- if (nameMatches) return 2; // Direct name match - highest priority
137
- if (companyMatches) return 1; // Company name match - lower priority
138
- return 0; // No match
139
- }
140
- return nameMatches ? 1 : 0;
141
- }, [inputValue, companiesMap]);
122
+ var scoreOption = (0, _react.useCallback)(function (option) {
123
+ return (0, _getOptionRelevanceScore.getOptionRelevanceScore)(option, inputValue, companiesMap, ignoreCompanies);
124
+ }, [inputValue, companiesMap, ignoreCompanies]);
142
125
  var isOptionSelected = (0, _react.useCallback)(function (option) {
143
126
  return selectedOptions.some(function (o) {
144
127
  return o.value === option.value;
@@ -182,7 +165,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
182
165
  options: group.options.map(function (opt) {
183
166
  return {
184
167
  opt: opt,
185
- score: getOptionRelevanceScore(opt)
168
+ score: scoreOption(opt)
186
169
  };
187
170
  }).filter(function (_ref2) {
188
171
  var score = _ref2.score;
@@ -198,7 +181,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
198
181
  var filteredFlatOptions = [].concat(_toConsumableArray(filteredInternalUsers), _toConsumableArray(filteredClients), _toConsumableArray(filteredCompanies)).map(function (opt) {
199
182
  return {
200
183
  opt: opt,
201
- score: getOptionRelevanceScore(opt)
184
+ score: scoreOption(opt)
202
185
  };
203
186
  }).filter(function (_ref4) {
204
187
  var score = _ref4.score;
@@ -213,7 +196,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
213
196
  // when grouped is true then we need to show the options list in a group manner.
214
197
  var opts = grouped ? filteredGroupedOptions : filteredFlatOptions;
215
198
  return opts;
216
- }, [internalUsers, clientUsers, companies, grouped, selectedOptions, ignoreFilterClientsByCompany, limitSelectedOptions, getOptionRelevanceScore, isOptionSelected, customLabels]);
199
+ }, [internalUsers, clientUsers, companies, grouped, selectedOptions, ignoreFilterClientsByCompany, limitSelectedOptions, scoreOption, isOptionSelected, customLabels]);
217
200
 
218
201
  /**
219
202
  * Handles the change of the selected options
@@ -268,8 +251,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
268
251
  * @returns the option with the company data
269
252
  */
270
253
  var getCompanyData = (0, _react.useCallback)(function (option) {
271
- var _option$companyId2, _clientToCompanyCount2, _option$value;
272
- var company = option.type === 'client' ? companiesMap.get((_option$companyId2 = option.companyId) !== null && _option$companyId2 !== void 0 ? _option$companyId2 : '') : undefined;
254
+ var _option$companyId, _clientToCompanyCount2, _option$value;
255
+ var company = option.type === 'client' ? companiesMap.get((_option$companyId = option.companyId) !== null && _option$companyId !== void 0 ? _option$companyId : '') : undefined;
273
256
 
274
257
  // only setup the company avatar data if the client is part of more than one company
275
258
  var clientsCount = (_clientToCompanyCount2 = clientToCompanyCount.get((_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : '')) !== null && _clientToCompanyCount2 !== void 0 ? _clientToCompanyCount2 : 0;
@@ -280,11 +263,12 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
280
263
  } : {});
281
264
  }, [companiesMap, clientToCompanyCount]);
282
265
  var handleFilterOption = (0, _react.useCallback)(function (option, inputValue) {
266
+ var _option$data$label$to, _option$data$label;
283
267
  var lowerCaseInputValue = inputValue.toLowerCase();
284
268
  if (ignoreCompanies && option.data.type === 'company') {
285
269
  return false;
286
270
  }
287
- var optionLabel = option.data.label.toLowerCase();
271
+ var optionLabel = (_option$data$label$to = (_option$data$label = option.data.label) === null || _option$data$label === void 0 ? void 0 : _option$data$label.toLowerCase()) !== null && _option$data$label$to !== void 0 ? _option$data$label$to : '';
288
272
  // for clients option, we should filter by company name too
289
273
  // e.g. if a client company is ACME and the input is ACME, the result should
290
274
  // show the client with the company ACME and the client with the company name
@@ -322,7 +306,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
322
306
  },
323
307
  Option: function Option(props) {
324
308
  return /*#__PURE__*/_react["default"].createElement(_ListItem.ListItem, _extends({}, props, {
325
- data: getCompanyData(props.data)
309
+ data: getCompanyData(props.data),
310
+ listClassName: listClassName
326
311
  }));
327
312
  },
328
313
  DropdownIndicator: function DropdownIndicator() {
@@ -345,7 +330,10 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
345
330
  }));
346
331
  }
347
332
  };
348
- }, [getCompanyData]);
333
+ }, [getCompanyData, listHeading, listClassName]);
334
+ var variantClassNames = (0, _react.useMemo)(function () {
335
+ return (0, _getClassNames.getClassNames)(variant);
336
+ }, [variant]);
349
337
  return /*#__PURE__*/_react["default"].createElement(_reactSelect["default"], _extends({
350
338
  autoFocus: autoFocus,
351
339
  isMulti: true,
@@ -359,7 +347,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
359
347
  placeholder: placeholder,
360
348
  filterOption: handleFilterOption,
361
349
  unstyled: true,
362
- styles: _objectSpread({
350
+ styles: _objectSpread(_objectSpread({
363
351
  clearIndicator: function clearIndicator() {
364
352
  return {
365
353
  display: 'none' // hide the clear button. Unfortunatelly, the class specificity is not enough to override the default styles.
@@ -370,20 +358,20 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
370
358
  color: _colors.colors.gray[500]
371
359
  });
372
360
  }
373
- }, styles),
374
- classNames: {
375
- valueContainer: function valueContainer() {
376
- return 'cop-flex cop-gap-1';
377
- },
378
- input: function input() {
379
- return 'cop-text-base cop-text-primary hover:cop-cursor-text';
380
- },
381
- menuList: function menuList() {
382
- return 'cop-relative cop-bg-white cop-shadow-popover-50 cop-rounded cop-border cop-border-solid cop-border-secondary cop-mt-1';
383
- },
384
- control: function control() {
385
- return 'cop-border-solid cop-border-[1px] cop-border-secondary focus-within:cop-border-primary cop-px-3 cop-py-[2px] cop-rounded';
361
+ }, variant === 'unified' ? {
362
+ menu: function menu() {
363
+ return {
364
+ position: 'static'
365
+ };
386
366
  }
367
+ } : {}), styles),
368
+ classNames: {
369
+ container: variantClassNames.container,
370
+ valueContainer: variantClassNames.valueContainer,
371
+ input: variantClassNames.input,
372
+ placeholder: variantClassNames.placeholder,
373
+ menuList: variantClassNames.menuList,
374
+ control: variantClassNames.control
387
375
  },
388
376
  components: memoizedComponents,
389
377
  value: selectedOptions
@@ -0,0 +1,96 @@
1
+ // This file is generated by a script. Do not edit this file directly.
2
+ (function (global, factory) {
3
+ if (typeof define === "function" && define.amd) {
4
+ define(["../getClassNames"], factory);
5
+ } else if (typeof exports !== "undefined") {
6
+ factory(require("../getClassNames"));
7
+ } else {
8
+ var mod = {
9
+ exports: {}
10
+ };
11
+ factory(global.getClassNames);
12
+ global.getClassNamesTest = mod.exports;
13
+ }
14
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_getClassNames) {
15
+ "use strict";
16
+
17
+ describe('getClassNames', function () {
18
+ describe('default variant', function () {
19
+ var cls = (0, _getClassNames.getClassNames)('default');
20
+ it('control has outer border, rounded, and focus-within blue border', function () {
21
+ var control = cls.control();
22
+ expect(control).toContain('cop-border-solid');
23
+ expect(control).toContain('cop-border-[1px]');
24
+ expect(control).toContain('cop-border-secondary');
25
+ expect(control).toContain('cop-rounded');
26
+ expect(control).toContain('focus-within:cop-border-primary');
27
+ });
28
+ it('menuList has its own border, shadow, rounded, and top margin', function () {
29
+ var menuList = cls.menuList();
30
+ expect(menuList).toContain('cop-shadow-popover-50');
31
+ expect(menuList).toContain('cop-rounded');
32
+ expect(menuList).toContain('cop-border');
33
+ expect(menuList).toContain('cop-border-secondary');
34
+ expect(menuList).toContain('cop-mt-1');
35
+ });
36
+ it('container returns undefined (no outer wrapper in default)', function () {
37
+ expect(cls.container).toBeUndefined();
38
+ });
39
+ });
40
+ describe('unified variant', function () {
41
+ var cls = (0, _getClassNames.getClassNames)('unified');
42
+ it('container has border, rounded corners, and shadow', function () {
43
+ var _cls$container, _cls$container2;
44
+ var container = (_cls$container = (_cls$container2 = cls.container) === null || _cls$container2 === void 0 ? void 0 : _cls$container2.call(cls)) !== null && _cls$container !== void 0 ? _cls$container : '';
45
+ expect(container).toContain('cop-border');
46
+ expect(container).toContain('cop-border-secondary');
47
+ expect(container).toContain('cop-rounded');
48
+ expect(container).toContain('cop-shadow-popover-50');
49
+ expect(container).toContain('cop-overflow-hidden');
50
+ });
51
+ it('control has no border (outer container owns all border styling)', function () {
52
+ var control = cls.control();
53
+ expect(control).toContain('cop-px-3');
54
+ expect(control).toContain('cop-py-[2px]');
55
+ expect(control).not.toContain('cop-border');
56
+ expect(control).not.toContain('cop-rounded');
57
+ expect(control).not.toContain('focus-within:cop-border-primary');
58
+ });
59
+ it('menuList has no border, no shadow, no rounded, no top margin', function () {
60
+ var menuList = cls.menuList();
61
+ expect(menuList).not.toContain('cop-shadow-popover-50');
62
+ expect(menuList).not.toContain('cop-rounded');
63
+ expect(menuList).not.toContain('cop-border-solid');
64
+ expect(menuList).not.toContain('cop-border-secondary');
65
+ expect(menuList).not.toContain('cop-mt-1');
66
+ });
67
+ });
68
+ describe('shared across variants', function () {
69
+ it('input uses 13px font size with 20px line height in default', function () {
70
+ var input = (0, _getClassNames.getClassNames)('default').input();
71
+ expect(input).toContain('cop-text-[13px]');
72
+ expect(input).toContain('cop-leading-5');
73
+ });
74
+ it('input uses 13px font size with 20px line height in unified', function () {
75
+ var input = (0, _getClassNames.getClassNames)('unified').input();
76
+ expect(input).toContain('cop-text-[13px]');
77
+ expect(input).toContain('cop-leading-5');
78
+ });
79
+ it('placeholder uses 13px font size with 20px line height in default', function () {
80
+ var placeholder = (0, _getClassNames.getClassNames)('default').placeholder();
81
+ expect(placeholder).toContain('cop-text-[13px]');
82
+ expect(placeholder).toContain('cop-leading-5');
83
+ });
84
+ it('placeholder uses 13px font size with 20px line height in unified', function () {
85
+ var placeholder = (0, _getClassNames.getClassNames)('unified').placeholder();
86
+ expect(placeholder).toContain('cop-text-[13px]');
87
+ expect(placeholder).toContain('cop-leading-5');
88
+ });
89
+ it('valueContainer is the same flex gap class in both variants', function () {
90
+ expect((0, _getClassNames.getClassNames)('default').valueContainer()).toBe((0, _getClassNames.getClassNames)('unified').valueContainer());
91
+ expect((0, _getClassNames.getClassNames)('default').valueContainer()).toContain('cop-flex');
92
+ expect((0, _getClassNames.getClassNames)('default').valueContainer()).toContain('cop-gap-1');
93
+ });
94
+ });
95
+ });
96
+ });
@@ -0,0 +1,130 @@
1
+ // This file is generated by a script. Do not edit this file directly.
2
+ (function (global, factory) {
3
+ if (typeof define === "function" && define.amd) {
4
+ define(["../getOptionRelevanceScore"], factory);
5
+ } else if (typeof exports !== "undefined") {
6
+ factory(require("../getOptionRelevanceScore"));
7
+ } else {
8
+ var mod = {
9
+ exports: {}
10
+ };
11
+ factory(global.getOptionRelevanceScore);
12
+ global.getOptionRelevanceScoreTest = mod.exports;
13
+ }
14
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_getOptionRelevanceScore) {
15
+ "use strict";
16
+
17
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ var company = {
24
+ value: 'company-1',
25
+ label: 'Acme Inc',
26
+ type: 'company'
27
+ };
28
+ var client = {
29
+ value: 'client-1',
30
+ label: 'Jane Doe',
31
+ type: 'client',
32
+ companyId: 'company-1'
33
+ };
34
+ var internalUser = {
35
+ value: 'user-1',
36
+ label: 'John Smith',
37
+ type: 'internalUser'
38
+ };
39
+ var companiesMap = new Map([[company.value, company]]);
40
+ describe('getOptionRelevanceScore', function () {
41
+ describe('empty input', function () {
42
+ it('returns 1 (show all) when input is empty', function () {
43
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, '', companiesMap)).toBe(1);
44
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(company, '', companiesMap)).toBe(1);
45
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(internalUser, '', companiesMap)).toBe(1);
46
+ });
47
+ });
48
+ describe('client options', function () {
49
+ it('returns 2 for a direct name match', function () {
50
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'jane', companiesMap)).toBe(2);
51
+ });
52
+ it('returns 1 for a company name match only', function () {
53
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'acme', companiesMap)).toBe(1);
54
+ });
55
+ it('prefers the direct name match (2) over a company match', function () {
56
+ var acmeClient = _objectSpread(_objectSpread({}, client), {}, {
57
+ label: 'Acme Person'
58
+ });
59
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(acmeClient, 'acme', companiesMap)).toBe(2);
60
+ });
61
+ it('returns 0 when neither name nor company match', function () {
62
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'zzz', companiesMap)).toBe(0);
63
+ });
64
+ it('matches case-insensitively', function () {
65
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'JANE', companiesMap)).toBe(2);
66
+ });
67
+ it('returns 0 for a company match when the company is missing from the map', function () {
68
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'acme', new Map())).toBe(0);
69
+ });
70
+ });
71
+ describe('non-client options', function () {
72
+ it('returns 1 for a matching company', function () {
73
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(company, 'acme', companiesMap)).toBe(1);
74
+ });
75
+ it('returns 0 for a non-matching company', function () {
76
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(company, 'zzz', companiesMap)).toBe(0);
77
+ });
78
+ it('returns 1 for a matching internal user', function () {
79
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(internalUser, 'john', companiesMap)).toBe(1);
80
+ });
81
+ });
82
+ describe('ignoreCompanies', function () {
83
+ it('returns 0 for company options when ignoreCompanies is true, even on a match', function () {
84
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(company, 'acme', companiesMap, true)).toBe(0);
85
+ });
86
+ it('returns 0 for company options when ignoreCompanies is true and input is empty', function () {
87
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(company, '', companiesMap, true)).toBe(0);
88
+ });
89
+ it('still scores client options normally when ignoreCompanies is true', function () {
90
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'jane', companiesMap, true)).toBe(2);
91
+ });
92
+ });
93
+ describe('null-safety (bad runtime data)', function () {
94
+ it('does not throw and returns 0 when a client label is null', function () {
95
+ var badClient = _objectSpread(_objectSpread({}, client), {}, {
96
+ label: null
97
+ });
98
+ expect(function () {
99
+ return (0, _getOptionRelevanceScore.getOptionRelevanceScore)(badClient, 'jane', companiesMap);
100
+ }).not.toThrow();
101
+ // name does not match (null), company "Acme" does not match "jane" -> 0
102
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(badClient, 'jane', companiesMap)).toBe(0);
103
+ });
104
+ it('falls back to the company match when a client label is null', function () {
105
+ var badClient = _objectSpread(_objectSpread({}, client), {}, {
106
+ label: undefined
107
+ });
108
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(badClient, 'acme', companiesMap)).toBe(1);
109
+ });
110
+ it('does not throw and returns 0 when a company label is null', function () {
111
+ var badCompany = _objectSpread(_objectSpread({}, company), {}, {
112
+ label: null
113
+ });
114
+ expect(function () {
115
+ return (0, _getOptionRelevanceScore.getOptionRelevanceScore)(badCompany, 'acme', companiesMap);
116
+ }).not.toThrow();
117
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(badCompany, 'acme', companiesMap)).toBe(0);
118
+ });
119
+ it('does not throw when the matching company in the map has a null label', function () {
120
+ var mapWithBadCompany = new Map([[company.value, _objectSpread(_objectSpread({}, company), {}, {
121
+ label: null
122
+ })]]);
123
+ expect(function () {
124
+ return (0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'acme', mapWithBadCompany);
125
+ }).not.toThrow();
126
+ expect((0, _getOptionRelevanceScore.getOptionRelevanceScore)(client, 'acme', mapWithBadCompany)).toBe(0);
127
+ });
128
+ });
129
+ });
130
+ });
@@ -22,14 +22,19 @@
22
22
  * This file is used to generate the data for the combo select stories
23
23
  */
24
24
 
25
- function generateRandomSrc() {
26
- return "https://i.pravatar.cc/150?img=".concat(Math.floor(Math.random() * 70) + 1);
25
+ // Deterministic avatar src so Storybook/Chromatic snapshots are stable across builds.
26
+ // pravatar exposes images 1-70, so we cycle through that range based on the item index.
27
+ function generateSrc(index) {
28
+ return "https://i.pravatar.cc/150?img=".concat(index % 70 + 1);
27
29
  }
28
30
  var firstNames = ['John', 'Jane', 'Alice', 'Bob', 'Lara', 'Mike', 'Sarah', 'David', 'Emily', 'Daniel', 'Chris', 'Olivia', 'James', 'Sophia', 'Henry', 'Emma', 'Liam', 'Mia', 'Noah', 'Zoe'];
29
31
  var lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Martinez', 'Lopez', 'Clark', 'Lewis', 'Walker', 'Young', 'Allen', 'King', 'Wright', 'Scott', 'Torres', 'Nguyen'];
30
32
 
31
- // Generate unique name combinations
33
+ // Generate unique name combinations deterministically.
34
+ // `offset` lets callers pick a different, non-overlapping slice of the same
35
+ // stable ordering so internal and client lists don't share identical names.
32
36
  function generateUniqueNames(count) {
37
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
33
38
  var combinations = [];
34
39
  for (var _i = 0, _firstNames = firstNames; _i < _firstNames.length; _i++) {
35
40
  var first = _firstNames[_i];
@@ -38,16 +43,12 @@
38
43
  combinations.push("".concat(first, " ").concat(last));
39
44
  }
40
45
  }
41
- // Shuffle and slice to the required count
42
- var shuffled = combinations.sort(function () {
43
- return 0.5 - Math.random();
44
- });
45
- return shuffled.slice(0, count);
46
+ return combinations.slice(offset, offset + count);
46
47
  }
47
48
 
48
- // Get 100 unique names for internal and client users
49
+ // Get 100 unique names for internal and client users (non-overlapping slices)
49
50
  var internalUserNames = generateUniqueNames(100);
50
- var clientUserNames = generateUniqueNames(100);
51
+ var clientUserNames = generateUniqueNames(100, 100);
51
52
 
52
53
  // Generate companies
53
54
  var companies = _exports.companies = Array.from({
@@ -56,7 +57,7 @@
56
57
  return {
57
58
  value: "company-".concat(i + 1),
58
59
  label: "Company ".concat(i + 1),
59
- avatarSrc: generateRandomSrc(),
60
+ avatarSrc: generateSrc(i),
60
61
  type: 'company'
61
62
  };
62
63
  });
@@ -66,20 +67,21 @@
66
67
  return {
67
68
  value: "internal-".concat(i + 1),
68
69
  label: name,
69
- avatarSrc: generateRandomSrc(),
70
+ avatarSrc: generateSrc(i),
70
71
  type: 'internalUser'
71
72
  };
72
73
  });
73
74
 
74
75
  // Generate client users (with valid companyIds)
75
76
  var clientUsers = _exports.clientUsers = clientUserNames.map(function (name, i) {
76
- var _companies$Math$floor;
77
+ var _companies;
77
78
  return {
78
79
  value: "client-".concat(i + 1),
79
80
  label: name,
80
- avatarSrc: generateRandomSrc(),
81
+ avatarSrc: generateSrc(i),
81
82
  type: 'client',
82
- companyId: (_companies$Math$floor = companies[Math.floor(Math.random() * companies.length)]) === null || _companies$Math$floor === void 0 ? void 0 : _companies$Math$floor.value
83
+ // Deterministically distribute clients across companies for stable snapshots.
84
+ companyId: (_companies = companies[i % companies.length]) === null || _companies === void 0 ? void 0 : _companies.value
83
85
  };
84
86
  });
85
87
  });
@@ -0,0 +1,64 @@
1
+ // This file is generated by a script. Do not edit this file directly.
2
+ (function (global, factory) {
3
+ if (typeof define === "function" && define.amd) {
4
+ define(["exports"], factory);
5
+ } else if (typeof exports !== "undefined") {
6
+ factory(exports);
7
+ } else {
8
+ var mod = {
9
+ exports: {}
10
+ };
11
+ factory(mod.exports);
12
+ global.getClassNames = mod.exports;
13
+ }
14
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) {
15
+ "use strict";
16
+
17
+ Object.defineProperty(_exports, "__esModule", {
18
+ value: true
19
+ });
20
+ _exports.getClassNames = void 0;
21
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
22
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
24
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
25
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
26
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
27
+ var INPUT_CLASSES = 'cop-text-[13px] cop-leading-5 cop-text-primary hover:cop-cursor-text';
28
+ var PLACEHOLDER_CLASSES = 'cop-text-[13px] cop-leading-5';
29
+ var VALUE_CONTAINER_CLASSES = 'cop-flex cop-gap-1';
30
+ var getClassNames = _exports.getClassNames = function getClassNames(variant) {
31
+ var shared = {
32
+ input: function input() {
33
+ return INPUT_CLASSES;
34
+ },
35
+ placeholder: function placeholder() {
36
+ return PLACEHOLDER_CLASSES;
37
+ },
38
+ valueContainer: function valueContainer() {
39
+ return VALUE_CONTAINER_CLASSES;
40
+ }
41
+ };
42
+ if (variant === 'unified') {
43
+ return _objectSpread(_objectSpread({}, shared), {}, {
44
+ container: function container() {
45
+ return 'cop-border cop-border-solid cop-border-secondary cop-rounded cop-shadow-popover-50 cop-overflow-hidden';
46
+ },
47
+ control: function control() {
48
+ return 'cop-px-3 cop-py-[2px]';
49
+ },
50
+ menuList: function menuList() {
51
+ return 'cop-relative cop-bg-white';
52
+ }
53
+ });
54
+ }
55
+ return _objectSpread(_objectSpread({}, shared), {}, {
56
+ control: function control() {
57
+ return 'cop-border-solid cop-border-[1px] cop-border-secondary focus-within:cop-border-primary cop-px-3 cop-py-[2px] cop-rounded';
58
+ },
59
+ menuList: function menuList() {
60
+ return 'cop-relative cop-bg-white cop-shadow-popover-50 cop-rounded cop-border cop-border-solid cop-border-secondary cop-mt-1';
61
+ }
62
+ });
63
+ };
64
+ });