@aspprev/versi-ds 0.5.4 → 0.5.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.
@@ -3122,6 +3122,9 @@ function SelectMultiView(props) {
3122
3122
  const containerRef = useRef6(null);
3123
3123
  const triggerRef = useRef6(null);
3124
3124
  const groupRef = useRef6(null);
3125
+ const valueRef = useRef6(null);
3126
+ const measurementRef = useRef6(null);
3127
+ const [visibleCount, setVisibleCount] = useState6(null);
3125
3128
  const baseId = useId4();
3126
3129
  const triggerId = `${baseId}-trigger`;
3127
3130
  const labelId = `${baseId}-label`;
@@ -3129,7 +3132,18 @@ function SelectMultiView(props) {
3129
3132
  const summaryId = `${baseId}-summary`;
3130
3133
  const errorId = `${baseId}-error`;
3131
3134
  const selectedCount = checkedList.length;
3135
+ const selectedLabels = checkedList.map(
3136
+ (value) => options.find((option) => option.value === value)?.label ?? value
3137
+ );
3138
+ const selectionKey = JSON.stringify(selectedLabels);
3139
+ const displayedCount = Math.min(selectedCount, visibleCount ?? selectedCount);
3140
+ const hiddenCount = selectedCount - displayedCount;
3141
+ const chipClass = cs(
3142
+ "rounded-full px-1 py-0.5 text-sm",
3143
+ disabled ? "bg-surface-muted text-field-content-disabled" : "bg-action-primary text-action-primary-content"
3144
+ );
3132
3145
  const selectedSummary = selectedCount === 0 ? "Nenhuma op\xE7\xE3o selecionada" : selectedCount === 1 ? "1 op\xE7\xE3o selecionada" : `${selectedCount} op\xE7\xF5es selecionadas`;
3146
+ const accessibleSummary = selectedCount > 0 ? `${selectedSummary}: ${selectedLabels.join(", ")}` : selectedSummary;
3133
3147
  const describedBy = [summaryId, error ? errorId : void 0].filter(Boolean).join(" ");
3134
3148
  const floatingLayerClass = getFloatingLayerClass(
3135
3149
  triggerRef.current,
@@ -3140,6 +3154,53 @@ function SelectMultiView(props) {
3140
3154
  setIsOpened(false);
3141
3155
  triggerRef.current?.focus({ preventScroll: true });
3142
3156
  };
3157
+ useEffect5(() => {
3158
+ const valueElement = valueRef.current;
3159
+ const measurements = measurementRef.current;
3160
+ if (!valueElement || !measurements || selectedCount === 0) return;
3161
+ let active = true;
3162
+ const update = () => {
3163
+ if (!active) return;
3164
+ const available = valueElement.getBoundingClientRect().width;
3165
+ const labels = Array.from(measurements.querySelectorAll("[data-label-width]"));
3166
+ const partialLabels = Array.from(measurements.querySelectorAll("[data-partial-width]"));
3167
+ const counters = Array.from(measurements.querySelectorAll("[data-counter-width]"));
3168
+ const gap = Number.parseFloat(window.getComputedStyle(valueElement).columnGap) || 0;
3169
+ const totalWidth = labels.reduce((sum, element) => sum + element.getBoundingClientRect().width, 0) + Math.max(0, selectedCount - 1) * gap;
3170
+ if (totalWidth <= available) {
3171
+ setVisibleCount(selectedCount);
3172
+ return;
3173
+ }
3174
+ let used = 0;
3175
+ let fitting = 0;
3176
+ for (let index = 0; index < labels.length; index += 1) {
3177
+ const fullWidth = labels[index].getBoundingClientRect().width;
3178
+ used += fullWidth + (index > 0 ? gap : 0);
3179
+ const remaining = selectedCount - index - 1;
3180
+ const counterWidth = remaining > 0 ? counters[remaining - 1].getBoundingClientRect().width + gap : 0;
3181
+ if (used + counterWidth <= available) fitting = index + 1;
3182
+ else {
3183
+ const partialWidth = Math.min(fullWidth, partialLabels[index].getBoundingClientRect().width);
3184
+ if (used - fullWidth + partialWidth + counterWidth <= available) fitting = index + 1;
3185
+ break;
3186
+ }
3187
+ }
3188
+ setVisibleCount(Math.max(1, fitting));
3189
+ };
3190
+ update();
3191
+ const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(update) : void 0;
3192
+ observer?.observe(valueElement);
3193
+ observer?.observe(measurements);
3194
+ window.addEventListener("resize", update);
3195
+ document.fonts?.addEventListener("loadingdone", update);
3196
+ void document.fonts?.ready.then(update);
3197
+ return () => {
3198
+ active = false;
3199
+ observer?.disconnect();
3200
+ window.removeEventListener("resize", update);
3201
+ document.fonts?.removeEventListener("loadingdone", update);
3202
+ };
3203
+ }, [selectionKey, selectedCount, onClear]);
3143
3204
  useEffect5(() => {
3144
3205
  if (!isOpened) return;
3145
3206
  groupRef.current?.querySelector('input[type="checkbox"]')?.focus({ preventScroll: true });
@@ -3236,26 +3297,46 @@ function SelectMultiView(props) {
3236
3297
  }
3237
3298
  },
3238
3299
  className: cs(
3239
- "flex h-control-md w-full cursor-pointer items-center justify-between rounded-sm border border-field-border-default bg-field-surface px-3 text-field-icon focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring",
3300
+ "flex h-control-md w-full cursor-pointer items-center justify-between gap-1 rounded-sm border border-field-border-default bg-field-surface px-3 text-field-icon focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring",
3240
3301
  error && "border-2 px-[calc(var(--spacing-xs)-1px)] border-field-border-error text-field-assistive-error",
3241
3302
  !error && isOpened && "border-field-border-active text-field-content",
3242
3303
  !error && selectedCount > 0 && "text-field-content",
3243
3304
  disabled && "cursor-not-allowed border-field-border-default bg-field-surface-disabled text-field-content-disabled"
3244
3305
  ),
3245
3306
  children: [
3246
- /* @__PURE__ */ jsx8(
3307
+ /* @__PURE__ */ jsxs7(
3247
3308
  "span",
3248
3309
  {
3310
+ ref: valueRef,
3311
+ title: selectedCount > 0 ? selectedLabels.join(", ") : void 0,
3249
3312
  className: cs(
3250
- "min-w-0 flex-1 truncate text-left text-base font-normal",
3313
+ "field-value relative flex min-w-0 flex-1 items-center gap-1 overflow-hidden text-left text-base font-normal",
3251
3314
  {
3315
+ "mr-[40px]": selectedCount > 0 && Boolean(onClear),
3252
3316
  "text-field-placeholder": !disabled && selectedCount === 0,
3253
- "pr-12 text-field-content": !disabled && selectedCount > 0,
3317
+ "text-field-content": !disabled && selectedCount > 0,
3254
3318
  "text-field-content-disabled": disabled && selectedCount > 0,
3255
3319
  "text-field-placeholder-disabled": disabled && selectedCount === 0
3256
3320
  }
3257
3321
  ),
3258
- children: "Selecione"
3322
+ children: [
3323
+ selectedCount === 0 ? /* @__PURE__ */ jsx8("span", { className: "min-w-0 truncate", "aria-hidden": "true", children: "Selecione" }) : selectedLabels.slice(0, displayedCount).map((text, index) => /* @__PURE__ */ jsx8("span", { className: cs("min-w-0 truncate", index < displayedCount - 1 && "shrink-0", chipClass), "aria-hidden": "true", children: text }, index)),
3324
+ hiddenCount > 0 && /* @__PURE__ */ jsxs7("span", { "aria-hidden": "true", className: cs("shrink-0", chipClass), children: [
3325
+ "+",
3326
+ hiddenCount
3327
+ ] }),
3328
+ selectedCount > 0 && /* @__PURE__ */ jsxs7("span", { ref: measurementRef, "aria-hidden": "true", className: "pointer-events-none invisible absolute left-0 top-0 flex w-max whitespace-pre", style: { font: "inherit" }, children: [
3329
+ selectedLabels.map((text, index) => /* @__PURE__ */ jsx8("span", { "data-label-width": true, className: chipClass, children: text }, index)),
3330
+ selectedLabels.map((text, index) => /* @__PURE__ */ jsxs7("span", { "data-partial-width": true, className: chipClass, children: [
3331
+ Array.from(text).slice(0, 6).join(""),
3332
+ "\u2026"
3333
+ ] }, index)),
3334
+ selectedLabels.map((_, index) => /* @__PURE__ */ jsxs7("span", { "data-counter-width": true, className: chipClass, children: [
3335
+ "+",
3336
+ index + 1
3337
+ ] }, index))
3338
+ ] })
3339
+ ]
3259
3340
  }
3260
3341
  ),
3261
3342
  /* @__PURE__ */ jsx8(
@@ -3278,7 +3359,7 @@ function SelectMultiView(props) {
3278
3359
  ]
3279
3360
  }
3280
3361
  ),
3281
- /* @__PURE__ */ jsx8("span", { id: summaryId, className: "sr-only", children: selectedSummary }),
3362
+ /* @__PURE__ */ jsx8("span", { id: summaryId, className: "sr-only", children: accessibleSummary }),
3282
3363
  isOpened && /* @__PURE__ */ jsx8(
3283
3364
  "div",
3284
3365
  {
@@ -3329,18 +3410,18 @@ function SelectMultiView(props) {
3329
3410
  })
3330
3411
  }
3331
3412
  ),
3332
- selectedCount > 0 && onClear && /* @__PURE__ */ jsxs7(
3413
+ selectedCount > 0 && onClear && /* @__PURE__ */ jsx8(
3333
3414
  "button",
3334
3415
  {
3335
3416
  type: "button",
3336
3417
  "aria-label": `Limpar sele\xE7\xE3o de ${label ?? "op\xE7\xF5es"}`,
3337
3418
  disabled,
3338
- onClick: onClear,
3339
- className: "absolute right-9 top-1/2 flex min-h-6 min-w-6 -translate-y-1/2 touch-manipulation items-center justify-center gap-1 rounded-full bg-action-primary px-2 text-xs text-action-primary-content focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring disabled:cursor-not-allowed disabled:bg-field-surface-disabled disabled:text-field-content-disabled",
3340
- children: [
3341
- /* @__PURE__ */ jsx8("span", { "aria-hidden": "true", className: "field-value", "data-has-value": "true", children: selectedCount }),
3342
- /* @__PURE__ */ jsx8(MdClose, { "aria-hidden": "true", size: 10 })
3343
- ]
3419
+ onClick: () => {
3420
+ onClear();
3421
+ triggerRef.current?.focus({ preventScroll: true });
3422
+ },
3423
+ className: "absolute right-[40px] top-1/2 flex h-6 w-6 -translate-y-1/2 touch-manipulation items-center justify-center rounded-sm text-field-icon focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring disabled:cursor-not-allowed disabled:text-field-content-disabled",
3424
+ children: /* @__PURE__ */ jsx8(MdClose, { "aria-hidden": "true", size: 16 })
3344
3425
  }
3345
3426
  )
3346
3427
  ]
@@ -3840,4 +3921,4 @@ export {
3840
3921
  RadioCardGroup,
3841
3922
  OtpCodeInput_default
3842
3923
  };
3843
- //# sourceMappingURL=chunk-YT6ZM6WC.js.map
3924
+ //# sourceMappingURL=chunk-VUXHE4S6.js.map