@noya-app/noya-designsystem 0.1.73 → 0.1.75

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/dist/index.mjs CHANGED
@@ -3801,11 +3801,14 @@ function Icon({
3801
3801
  // src/components/Spacer.tsx
3802
3802
  import * as React8 from "react";
3803
3803
  var SpacerVertical = React8.forwardRef(
3804
- ({ size, inline, ...props }, ref) => {
3804
+ ({ size, inline, className, ...props }, ref) => {
3805
3805
  return /* @__PURE__ */ React8.createElement(
3806
3806
  "span",
3807
3807
  {
3808
- className: `${inline ? "n-inline-block" : "n-block"} ${size === void 0 ? "n-flex n-flex-1" : ""}`,
3808
+ className: cx(
3809
+ `${inline ? "n-inline-block" : "n-block"} ${size === void 0 ? "n-flex n-flex-1" : ""}`,
3810
+ className
3811
+ ),
3809
3812
  style: size ? {
3810
3813
  minHeight: `${size}px`
3811
3814
  } : void 0,
@@ -3816,11 +3819,14 @@ var SpacerVertical = React8.forwardRef(
3816
3819
  }
3817
3820
  );
3818
3821
  var SpacerHorizontal = React8.forwardRef(
3819
- ({ size, inline, ...props }, ref) => {
3822
+ ({ size, inline, className, ...props }, ref) => {
3820
3823
  return /* @__PURE__ */ React8.createElement(
3821
3824
  "span",
3822
3825
  {
3823
- className: `${inline ? "n-inline-block" : "n-block"} ${size === void 0 ? "n-flex n-flex-1" : ""}`,
3826
+ className: cx(
3827
+ `${inline ? "n-inline-block" : "n-block"} ${size === void 0 ? "n-flex n-flex-1" : ""}`,
3828
+ className
3829
+ ),
3824
3830
  style: size ? {
3825
3831
  minWidth: `${size}px`
3826
3832
  } : void 0,
@@ -4854,10 +4860,14 @@ var InputElement = forwardRef9(
4854
4860
  onSubmit,
4855
4861
  as = "input",
4856
4862
  style: style2,
4863
+ attachInputRef = true,
4857
4864
  ...props
4858
4865
  }, forwardedRef) => {
4859
4866
  const { endWidth, inputRef, size, id, startWidth } = useInputFieldContext();
4860
- const ref = useMergeRefs(inputRef, forwardedRef);
4867
+ const ref = useMergeRefs(
4868
+ attachInputRef ? inputRef : null,
4869
+ forwardedRef
4870
+ );
4861
4871
  const spacingStyles = getFieldSpacing({
4862
4872
  endWidth,
4863
4873
  variant: $variant,
@@ -4929,6 +4939,7 @@ var InputFieldTypeahead = (props) => {
4929
4939
  InputElement,
4930
4940
  {
4931
4941
  as: "span",
4942
+ attachInputRef: false,
4932
4943
  style: useMemo8(
4933
4944
  () => ({
4934
4945
  position: "absolute",
@@ -5059,7 +5070,9 @@ function InputFieldRoot({
5059
5070
  const startRef = React20.useRef(null);
5060
5071
  const inputRef = React20.useRef(null);
5061
5072
  const endRef = React20.useRef(null);
5073
+ const rootRef = React20.useRef(null);
5062
5074
  const measuredInputSize = useSize(inputRef, "width");
5075
+ const measuredRootSize = useSize(rootRef, "width");
5063
5076
  const measuredStartSize = useSize(startRef, "width");
5064
5077
  const measuredEndSize = useSize(endRef, "width");
5065
5078
  const labelType = useLabelType();
@@ -5092,18 +5105,34 @@ function InputFieldRoot({
5092
5105
  () => /* @__PURE__ */ React20.createElement(Label, { htmlFor: id, className: "!n-text-text-disabled" }, labelProp ?? label),
5093
5106
  [id, labelProp, label]
5094
5107
  );
5095
- const rootElement = /* @__PURE__ */ React20.createElement(RootContainer, { $width: width, style: style2, className }, children, start && /* @__PURE__ */ React20.createElement("span", { ref: startRef, className: cx(startBaseStyles, startClassName) }, start), (end || label) && /* @__PURE__ */ React20.createElement(
5096
- "span",
5108
+ const rootElement = /* @__PURE__ */ React20.createElement(
5109
+ RootContainer,
5097
5110
  {
5098
- ref: endRef,
5099
- className: cx(endStyles, label && end && "n-gap-1.5", endClassName)
5111
+ ref: rootRef,
5112
+ $width: width,
5113
+ style: style2,
5114
+ className
5100
5115
  },
5101
- labelProp ? insetLabel : label && labelType === "inset" && insetLabel,
5102
- end
5103
- ));
5116
+ children,
5117
+ start && /* @__PURE__ */ React20.createElement("span", { ref: startRef, className: cx(startBaseStyles, startClassName) }, start),
5118
+ (end || label) && /* @__PURE__ */ React20.createElement(
5119
+ "span",
5120
+ {
5121
+ ref: endRef,
5122
+ className: cx(endStyles, label && end && "n-gap-1.5", endClassName)
5123
+ },
5124
+ labelProp ? insetLabel : label && labelType === "inset" && insetLabel,
5125
+ end
5126
+ )
5127
+ );
5128
+ const measuredWidth = useMemo8(() => {
5129
+ const inputWidth = measuredInputSize && measuredInputSize.width > 0 ? measuredInputSize.width : void 0;
5130
+ const rootWidth = measuredRootSize && measuredRootSize.width > 0 ? measuredRootSize.width : void 0;
5131
+ return inputWidth ?? rootWidth ?? width;
5132
+ }, [measuredInputSize, measuredRootSize, width]);
5104
5133
  const measuredWidthObject = useMemo8(
5105
- () => measuredInputSize ? { width: measuredInputSize.width + 4 } : void 0,
5106
- [measuredInputSize]
5134
+ () => measuredWidth && measuredWidth > 0 ? { width: measuredWidth + 4 } : void 0,
5135
+ [measuredWidth]
5107
5136
  );
5108
5137
  return /* @__PURE__ */ React20.createElement(InputFieldContext.Provider, { value: contextValue }, renderPopoverContent ? /* @__PURE__ */ React20.createElement(
5109
5138
  Popover,
@@ -10932,9 +10961,28 @@ var ComboboxState = class {
10932
10961
  this.filter = this.lastSubmittedValue.itemName;
10933
10962
  this.notifyChange();
10934
10963
  }
10935
- reset(newFilter = "") {
10964
+ reset(newFilter = "", options) {
10936
10965
  this.filter = newFilter;
10937
- this.selectedIndex = 0;
10966
+ const filteredItems = this.getFilteredItems();
10967
+ const normalizedTitle = options?.selectedItemTitle ? options.selectedItemTitle.toString().toLowerCase() : void 0;
10968
+ const normalizedValue = options?.selectedItemValue ? options.selectedItemValue.toString().toLowerCase() : void 0;
10969
+ const matchedIndex = normalizedTitle || normalizedValue ? filteredItems.findIndex((item) => {
10970
+ if (!isSelectableMenuItem(item)) return false;
10971
+ const title = item.title?.toString().toLowerCase();
10972
+ const value = item.value?.toString().toLowerCase();
10973
+ if (normalizedValue && value === normalizedValue) return true;
10974
+ if (normalizedTitle && title === normalizedTitle) return true;
10975
+ return false;
10976
+ }) : -1;
10977
+ if (matchedIndex !== -1) {
10978
+ this.selectedIndex = matchedIndex;
10979
+ this.notifyChange();
10980
+ return;
10981
+ }
10982
+ const firstSelectableIndex = filteredItems.findIndex(
10983
+ (item) => isSelectableMenuItem(item)
10984
+ );
10985
+ this.selectedIndex = firstSelectableIndex === -1 ? 0 : firstSelectableIndex;
10938
10986
  this.notifyChange();
10939
10987
  }
10940
10988
  getSelectedItem() {
@@ -11218,6 +11266,13 @@ var Combobox = memoGeneric(
11218
11266
  }
11219
11267
  }
11220
11268
  const initialValueString = getInitialValueString();
11269
+ const resetSelectionOptions = useMemo28(
11270
+ () => props.mode === "string" ? { selectedItemTitle: initialValueString } : {
11271
+ selectedItemTitle: initialValueString,
11272
+ selectedItemValue: props.value?.value?.toString()
11273
+ },
11274
+ [initialValueString, props.mode, props.value]
11275
+ );
11221
11276
  const [comboboxState] = useState27(
11222
11277
  () => new ComboboxState(
11223
11278
  items,
@@ -11228,6 +11283,7 @@ var Combobox = memoGeneric(
11228
11283
  const state = useComboboxState(comboboxState);
11229
11284
  const [isFocused, setIsFocused] = useState27(false);
11230
11285
  const listRef = useRef21(null);
11286
+ const menuOpenedRef = useRef21(false);
11231
11287
  const [shouldBlur, setShouldBlur] = useState27(false);
11232
11288
  const { fieldId: id } = useLabel({
11233
11289
  fieldId: rest.id
@@ -11245,9 +11301,20 @@ var Combobox = memoGeneric(
11245
11301
  listRef.current.scrollToIndex(selectedIndex);
11246
11302
  }
11247
11303
  }, [selectedIndex]);
11304
+ useEffect20(() => {
11305
+ if (!shouldShowMenu) {
11306
+ menuOpenedRef.current = false;
11307
+ return;
11308
+ }
11309
+ if (menuOpenedRef.current) return;
11310
+ menuOpenedRef.current = true;
11311
+ if (listRef.current) {
11312
+ listRef.current.scrollToIndex(selectedIndex);
11313
+ }
11314
+ }, [shouldShowMenu, selectedIndex]);
11248
11315
  const handleBlur = useCallback28(() => {
11249
11316
  ref.current?.blur();
11250
- comboboxState.reset(initialValueString);
11317
+ comboboxState.reset(initialValueString, resetSelectionOptions);
11251
11318
  if (props.mode === "string") {
11252
11319
  props.onBlur?.(
11253
11320
  state.filter === state.lastSubmittedValue.filter,
@@ -11263,12 +11330,20 @@ var Combobox = memoGeneric(
11263
11330
  }
11264
11331
  }
11265
11332
  setIsFocused(false);
11266
- }, [filter, initialValueString, props, state, comboboxState]);
11333
+ }, [
11334
+ filter,
11335
+ initialValueString,
11336
+ props,
11337
+ resetSelectionOptions,
11338
+ state,
11339
+ comboboxState
11340
+ ]);
11267
11341
  const handleFocus = useCallback28(
11268
11342
  (event) => {
11269
11343
  setIsFocused(true);
11270
11344
  comboboxState.reset(
11271
- openMenuBehavior === "showAllItems" ? "" : initialValueString
11345
+ openMenuBehavior === "showAllItems" ? "" : initialValueString,
11346
+ resetSelectionOptions
11272
11347
  );
11273
11348
  if (ref.current) {
11274
11349
  const length = ref.current.value.length;
@@ -11276,7 +11351,13 @@ var Combobox = memoGeneric(
11276
11351
  }
11277
11352
  onFocus?.(event);
11278
11353
  },
11279
- [initialValueString, onFocus, openMenuBehavior, comboboxState]
11354
+ [
11355
+ initialValueString,
11356
+ onFocus,
11357
+ openMenuBehavior,
11358
+ resetSelectionOptions,
11359
+ comboboxState
11360
+ ]
11280
11361
  );
11281
11362
  const handleUpdateSelection = useCallback28(
11282
11363
  (item) => {
@@ -11441,7 +11522,8 @@ var Combobox = memoGeneric(
11441
11522
  return;
11442
11523
  }
11443
11524
  comboboxState.reset(
11444
- openMenuBehavior === "showAllItems" ? "" : initialValueString
11525
+ openMenuBehavior === "showAllItems" ? "" : initialValueString,
11526
+ resetSelectionOptions
11445
11527
  );
11446
11528
  ref.current?.focus();
11447
11529
  },
@@ -11450,6 +11532,7 @@ var Combobox = memoGeneric(
11450
11532
  openMenuBehavior,
11451
11533
  initialValueString,
11452
11534
  handleBlur,
11535
+ resetSelectionOptions,
11453
11536
  comboboxState
11454
11537
  ]
11455
11538
  );
@@ -15373,6 +15456,12 @@ function BaseToolbar({
15373
15456
  innerClassName,
15374
15457
  enableAbsoluteBreakpoint = true
15375
15458
  }) {
15459
+ const childrenContainerClassName = cx(
15460
+ "n-flex n-items-center n-justify-center n-text-text-muted n-pointer-events-none n-inset-0 n-pl-1 n-pr-1 n-min-w-0",
15461
+ "@xl/toolbar:!n-absolute @xl/toolbar:!n-pl-0 @xl/toolbar:!n-pr-0"
15462
+ );
15463
+ const childrenElement = children && /* @__PURE__ */ React85.createElement("div", { className: childrenContainerClassName }, /* @__PURE__ */ React85.createElement("div", { className: "n-flex n-items-center n-justify-center n-pointer-events-auto" }, children));
15464
+ const leftElement = left && /* @__PURE__ */ React85.createElement("div", { className: "n-flex n-gap-toolbar-separator" }, left);
15376
15465
  return /* @__PURE__ */ React85.createElement(
15377
15466
  BaseToolbarContainer,
15378
15467
  {
@@ -15383,14 +15472,8 @@ function BaseToolbar({
15383
15472
  },
15384
15473
  logo && /* @__PURE__ */ React85.createElement(React85.Fragment, null, logo, /* @__PURE__ */ React85.createElement(DividerVertical, null)),
15385
15474
  /* @__PURE__ */ React85.createElement(Spacer.Horizontal, { size: 10 }),
15386
- left && /* @__PURE__ */ React85.createElement(React85.Fragment, null, /* @__PURE__ */ React85.createElement("div", { className: "n-flex n-gap-toolbar-separator" }, left), /* @__PURE__ */ React85.createElement(Spacer.Horizontal, { size: 10 })),
15387
- children && /* @__PURE__ */ React85.createElement(
15388
- "div",
15389
- {
15390
- className: "n-flex n-items-center n-justify-center n-text-text-muted n-pointer-events-none @xl/toolbar:!n-absolute n-inset-0"
15391
- },
15392
- /* @__PURE__ */ React85.createElement("div", { className: "n-flex n-items-center n-justify-center n-pointer-events-auto" }, children)
15393
- ),
15475
+ childrenElement,
15476
+ leftElement && /* @__PURE__ */ React85.createElement(React85.Fragment, null, childrenElement && /* @__PURE__ */ React85.createElement(React85.Fragment, null, /* @__PURE__ */ React85.createElement(Spacer.Horizontal, { size: 10, className: "@xl/toolbar:!n-hidden" }), /* @__PURE__ */ React85.createElement(DividerVertical, { className: "@xl/toolbar:!n-hidden" })), /* @__PURE__ */ React85.createElement(Spacer.Horizontal, { size: 10, className: "@xl/toolbar:!n-hidden" }), leftElement, /* @__PURE__ */ React85.createElement(Spacer.Horizontal, { size: 10 })),
15394
15477
  /* @__PURE__ */ React85.createElement(Spacer.Horizontal, null),
15395
15478
  /* @__PURE__ */ React85.createElement(Spacer.Horizontal, { size: 10 }),
15396
15479
  /* @__PURE__ */ React85.createElement("div", { className: "n-flex n-gap-toolbar-separator" }, right),