elseware-ui 3.0.8 → 3.0.10

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
@@ -6415,9 +6415,21 @@ function Button({
6415
6415
  }
6416
6416
  var Button_web_default = Button;
6417
6417
 
6418
+ // src/data/styles/shared.styles.tsx
6419
+ var inputShapes = shapes;
6420
+ var inputInlineInsetClassName = "left-3";
6421
+ var inputInlinePaddingXClassName = "px-3";
6422
+ var inputRootClassName = "relative w-full";
6423
+ var inputFrameClassName = `relative h-14 w-full overflow-hidden border bg-white/95 ${inputInlinePaddingXClassName} dark:bg-eui-primary-300/10`;
6424
+ var inputFrameIdleClassName = "border-gray-300 hover:border-gray-400 dark:border-eui-dark-300 dark:hover:border-eui-dark-200";
6425
+ var inputFrameActiveClassName = "border-eui-secondary-600";
6426
+ var inputFrameErrorClassName = "border-eui-danger-500";
6427
+ var inputFrameDisabledClassName = "cursor-not-allowed opacity-60";
6428
+ var inputControlClassName = "w-full bg-transparent pt-5 pb-2 text-base font-normal text-gray-950 dark:text-gray-300";
6429
+
6418
6430
  // src/components/data-entry/input/input-label/base/InputLabel.styles.ts
6419
6431
  var inputLabelStaticClassName = "pointer-events-none select-none px-0 text-[13.5px] leading-none text-[#6B7280]";
6420
- var inputLabelBaseClassName = "pointer-events-none absolute left-3 z-10 select-none bg-white/95 px-1 font-medium leading-none dark:bg-transparent";
6432
+ var inputLabelBaseClassName = `pointer-events-none absolute ${inputInlineInsetClassName} z-10 select-none bg-transparent px-0 font-medium leading-none`;
6421
6433
  var inputLabelTransitionClassName = "transition-all duration-200 ease-out";
6422
6434
  var inputLabelRestingClassName = "top-[18px] translate-y-0 text-base leading-none text-[#6B7280]";
6423
6435
  var inputLabelFloatingClassName = "top-1.5 translate-y-0 text-xs leading-none text-[#6B7280]";
@@ -7223,7 +7235,7 @@ var Transition = {
7223
7235
  };
7224
7236
 
7225
7237
  // src/components/data-entry/input/input-response/base/InputResponse.styles.ts
7226
- var inputResponseBaseClassName = "px-2 pt-1.5 text-sm font-medium";
7238
+ var inputResponseBaseClassName = `${inputInlinePaddingXClassName} pt-1.5 text-sm font-medium`;
7227
7239
  var inputResponseVariants = textVariants;
7228
7240
  function InputResponse({
7229
7241
  name: name2,
@@ -7272,16 +7284,6 @@ function useInputFieldState(props) {
7272
7284
  };
7273
7285
  }
7274
7286
 
7275
- // src/data/styles/shared.styles.tsx
7276
- var inputShapes = shapes;
7277
- var inputRootClassName = "relative w-full";
7278
- var inputFrameClassName = "relative h-14 w-full overflow-hidden border bg-white/95 px-3 dark:bg-eui-primary-300/10";
7279
- var inputFrameIdleClassName = "border-gray-300 hover:border-gray-400 dark:border-eui-dark-300 dark:hover:border-eui-dark-200";
7280
- var inputFrameActiveClassName = "border-eui-secondary-600";
7281
- var inputFrameErrorClassName = "border-eui-danger-500";
7282
- var inputFrameDisabledClassName = "cursor-not-allowed opacity-60";
7283
- var inputControlClassName = "w-full bg-transparent pt-5 pb-2 text-base font-medium text-gray-950 dark:text-gray-50";
7284
-
7285
7287
  // src/components/data-entry/input/input/web/Input.web.styles.ts
7286
7288
  var webInputControlClassName = "placeholder-transparent outline-none transition-all duration-200 ease-out";
7287
7289
  var webPasswordToggleClassName = "absolute right-3 top-[18px] cursor-pointer text-xl text-eui-dark-200 transition-colors duration-180 hover:text-eui-secondary-700";
@@ -9041,6 +9043,24 @@ function StarRatingInput({
9041
9043
  );
9042
9044
  }
9043
9045
  var StarRatingInput_default = StarRatingInput;
9046
+ function useClickOutside(ref, fun) {
9047
+ useEffect(() => {
9048
+ const listener = (e) => {
9049
+ if (!ref.current || ref.current.contains(e.target)) {
9050
+ return;
9051
+ }
9052
+ if (fun) {
9053
+ fun();
9054
+ }
9055
+ };
9056
+ document.addEventListener("mousedown", listener);
9057
+ document.addEventListener("touchstart", listener);
9058
+ return () => {
9059
+ document.removeEventListener("mousedown", listener);
9060
+ document.removeEventListener("touchstart", listener);
9061
+ };
9062
+ }, [ref, fun]);
9063
+ }
9044
9064
  function useResolvedSelectConfig({
9045
9065
  label,
9046
9066
  placeholder,
@@ -9060,25 +9080,65 @@ function useSelectFieldState(props) {
9060
9080
  meta
9061
9081
  };
9062
9082
  }
9083
+
9084
+ // src/components/data-entry/select/web/Select.web.styles.ts
9085
+ var webSelectTriggerClassName = "flex items-center justify-between gap-3 text-left outline-none transition-all duration-200 ease-out";
9086
+ var webSelectValueClassName = "block min-w-0 flex-1 truncate text-base font-normal text-gray-950 dark:text-gray-300";
9087
+ var webSelectPlaceholderClassName = "text-gray-500 dark:text-gray-400";
9088
+ var webSelectChevronClassName = "pointer-events-none shrink-0 text-base text-gray-500 transition-transform duration-150 ease-out dark:text-gray-400";
9089
+ var webSelectChevronOpenClassName = "rotate-180";
9090
+ var webSelectDropdownClassName = "absolute left-0 right-0 top-full z-30 mt-2 overflow-hidden rounded-md border border-gray-200 bg-white shadow-xl shadow-black/10 ring-1 ring-black/5 dark:border-eui-dark-300 dark:bg-eui-dark-500 dark:shadow-black/30 dark:ring-white/10";
9091
+ var webSelectListClassName = "max-h-[228px] overflow-y-auto py-1";
9092
+ var webSelectOptionClassName = "flex min-h-11 w-full items-center px-3 py-2 text-left text-sm font-medium text-gray-800 outline-none transition-colors duration-120 ease-out dark:text-gray-100";
9093
+ var webSelectOptionHoverClassName = "hover:bg-gray-100 focus:bg-gray-100 dark:hover:bg-eui-dark-400 dark:focus:bg-eui-dark-400";
9094
+ var webSelectOptionSelectedClassName = "bg-eui-secondary-500/10 text-eui-secondary-700 dark:bg-eui-secondary-500/15 dark:text-eui-secondary-300";
9095
+ var webSelectOptionActiveClassName = "bg-gray-100 dark:bg-eui-dark-400";
9096
+ var webSelectOptionDisabledClassName = "cursor-not-allowed opacity-45 hover:bg-transparent focus:bg-transparent dark:hover:bg-transparent dark:focus:bg-transparent";
9097
+ var webSelectOptionContentClassName = "min-w-0 flex-1 truncate";
9098
+ var webSelectEmptyClassName = "px-3 py-3 text-sm font-medium text-gray-500 dark:text-gray-400";
9099
+ function getEnabledOptionIndex(options, startIndex = 0, direction = 1) {
9100
+ if (!options.length) return -1;
9101
+ for (let offset = 0; offset < options.length; offset += 1) {
9102
+ const index3 = (startIndex + offset * direction + options.length) % options.length;
9103
+ if (!options[index3]?.disabled) {
9104
+ return index3;
9105
+ }
9106
+ }
9107
+ return -1;
9108
+ }
9063
9109
  function Select(selectProps) {
9064
9110
  const {
9111
+ activeOptionClassName,
9112
+ chevronClassName,
9065
9113
  disabled = false,
9114
+ disabledOptionClassName,
9115
+ dropdownClassName,
9116
+ emptyClassName,
9117
+ emptyMessage = "No options available",
9066
9118
  id: id2,
9067
9119
  inputClassName,
9068
9120
  label,
9069
9121
  labelClassName,
9122
+ optionClassName,
9123
+ optionContentClassName,
9070
9124
  options,
9071
9125
  placeholder,
9072
9126
  responseClassName,
9127
+ selectedOptionClassName,
9073
9128
  shape,
9074
9129
  styles,
9075
9130
  className,
9076
9131
  onBlur,
9077
9132
  onFocus,
9078
- ...props
9133
+ ..._props
9079
9134
  } = selectProps;
9080
- const { field, meta } = useSelectFieldState(selectProps);
9135
+ const rootRef = useRef(null);
9136
+ const triggerRef = useRef(null);
9137
+ const reactId = useId();
9138
+ const { field, helpers, meta } = useSelectFieldState(selectProps);
9081
9139
  const [focused, setFocused] = useState(false);
9140
+ const [open, setOpen] = useState(false);
9141
+ const [activeIndex, setActiveIndex] = useState(-1);
9082
9142
  const { label: resolvedLabel, shape: resolvedShape } = useResolvedSelectConfig({
9083
9143
  label,
9084
9144
  placeholder,
@@ -9086,48 +9146,237 @@ function Select(selectProps) {
9086
9146
  });
9087
9147
  const hasError = Boolean(meta.touched && meta.error);
9088
9148
  const inputId = id2 ?? field.name;
9089
- const handleBlur = (event) => {
9090
- setFocused(false);
9091
- field.onBlur(event);
9149
+ const listboxId = `${reactId}-${field.name}-listbox`;
9150
+ const selectedIndex = options.findIndex(
9151
+ (option) => option.value === field.value
9152
+ );
9153
+ const selectedOption = selectedIndex >= 0 ? options[selectedIndex] : null;
9154
+ const selectedOptionDisabled = Boolean(selectedOption?.disabled);
9155
+ const selectedLabel = selectedOption?.label ?? "";
9156
+ const hasValue = Boolean(selectedOption);
9157
+ const resolvedActiveIndex = activeIndex >= 0 ? activeIndex : getEnabledOptionIndex(options);
9158
+ const openOptions = useCallback(() => {
9159
+ if (disabled) return;
9160
+ const initialIndex = selectedIndex >= 0 && !selectedOptionDisabled ? selectedIndex : getEnabledOptionIndex(options);
9161
+ setFocused(true);
9162
+ setOpen(true);
9163
+ setActiveIndex(initialIndex);
9164
+ }, [disabled, options, selectedIndex, selectedOptionDisabled]);
9165
+ const closeOptions = useCallback(
9166
+ (markTouched = true, keepFocused = false) => {
9167
+ setOpen(false);
9168
+ setActiveIndex(-1);
9169
+ setFocused(keepFocused);
9170
+ if (markTouched) {
9171
+ void helpers.setTouched(true);
9172
+ }
9173
+ },
9174
+ [helpers]
9175
+ );
9176
+ useClickOutside(rootRef, () => {
9177
+ if (open) {
9178
+ closeOptions();
9179
+ }
9180
+ });
9181
+ const handleButtonFocus = (event) => {
9182
+ setFocused(true);
9183
+ onFocus?.(event);
9184
+ };
9185
+ const handleRootBlur = (event) => {
9186
+ if (event.relatedTarget instanceof Node && rootRef.current?.contains(event.relatedTarget)) {
9187
+ return;
9188
+ }
9189
+ closeOptions();
9092
9190
  onBlur?.(event);
9093
9191
  };
9094
- const handleFocus = (event) => {
9192
+ const handleToggle = () => {
9193
+ if (disabled) return;
9194
+ if (open) {
9195
+ closeOptions(true, true);
9196
+ return;
9197
+ }
9198
+ openOptions();
9199
+ };
9200
+ const handleSelect = (option) => {
9201
+ if (disabled || option.disabled) return;
9202
+ void helpers.setValue(option.value);
9203
+ void helpers.setTouched(true);
9204
+ setOpen(false);
9205
+ setActiveIndex(-1);
9095
9206
  setFocused(true);
9096
- onFocus?.(event);
9207
+ window.setTimeout(() => triggerRef.current?.focus(), 0);
9097
9208
  };
9098
- return /* @__PURE__ */ jsxs("div", { className: inputRootClassName, children: [
9099
- /* @__PURE__ */ jsx(
9100
- Field,
9209
+ const setNextActiveIndex = (direction) => {
9210
+ const nextIndex = getEnabledOptionIndex(
9211
+ options,
9212
+ resolvedActiveIndex + direction,
9213
+ direction
9214
+ );
9215
+ setActiveIndex(nextIndex);
9216
+ };
9217
+ const handleKeyDown = (event) => {
9218
+ switch (event.key) {
9219
+ case "ArrowDown":
9220
+ event.preventDefault();
9221
+ if (!open) {
9222
+ openOptions();
9223
+ return;
9224
+ }
9225
+ setNextActiveIndex(1);
9226
+ return;
9227
+ case "ArrowUp":
9228
+ event.preventDefault();
9229
+ if (!open) {
9230
+ openOptions();
9231
+ return;
9232
+ }
9233
+ setNextActiveIndex(-1);
9234
+ return;
9235
+ case "Home":
9236
+ if (open) {
9237
+ event.preventDefault();
9238
+ setActiveIndex(getEnabledOptionIndex(options));
9239
+ }
9240
+ return;
9241
+ case "End":
9242
+ if (open) {
9243
+ event.preventDefault();
9244
+ setActiveIndex(
9245
+ getEnabledOptionIndex(options, options.length - 1, -1)
9246
+ );
9247
+ }
9248
+ return;
9249
+ case "Enter":
9250
+ case " ":
9251
+ event.preventDefault();
9252
+ if (!open) {
9253
+ openOptions();
9254
+ return;
9255
+ }
9256
+ if (resolvedActiveIndex >= 0) {
9257
+ handleSelect(options[resolvedActiveIndex]);
9258
+ }
9259
+ return;
9260
+ case "Escape":
9261
+ if (open) {
9262
+ event.preventDefault();
9263
+ closeOptions(true, true);
9264
+ }
9265
+ return;
9266
+ case "Tab":
9267
+ closeOptions();
9268
+ return;
9269
+ default:
9270
+ return;
9271
+ }
9272
+ };
9273
+ return /* @__PURE__ */ jsxs("div", { ref: rootRef, className: inputRootClassName, onBlur: handleRootBlur, children: [
9274
+ /* @__PURE__ */ jsx("input", { name: field.name, type: "hidden", value: field.value ?? "" }),
9275
+ /* @__PURE__ */ jsxs(
9276
+ "button",
9101
9277
  {
9102
- ...props,
9103
- ...field,
9104
- as: "select",
9105
- disabled,
9106
- id: inputId,
9107
- onBlur: handleBlur,
9108
- onFocus: handleFocus,
9278
+ "aria-activedescendant": open && resolvedActiveIndex >= 0 ? `${listboxId}-option-${resolvedActiveIndex}` : void 0,
9279
+ "aria-controls": listboxId,
9280
+ "aria-disabled": disabled || void 0,
9281
+ "aria-expanded": open,
9282
+ "aria-haspopup": "listbox",
9283
+ "aria-invalid": hasError || void 0,
9109
9284
  className: cn(
9110
9285
  inputFrameClassName,
9111
9286
  inputControlClassName,
9112
- webInputControlClassName,
9113
- hasError ? inputFrameErrorClassName : focused ? inputFrameActiveClassName : inputFrameIdleClassName,
9287
+ webSelectTriggerClassName,
9288
+ hasError ? inputFrameErrorClassName : focused || open ? inputFrameActiveClassName : inputFrameIdleClassName,
9114
9289
  inputShapes[resolvedShape],
9115
9290
  disabled && inputFrameDisabledClassName,
9116
9291
  className,
9117
- styles,
9118
- inputClassName
9292
+ styles
9119
9293
  ),
9120
- children: options.map((option) => /* @__PURE__ */ jsx(
9121
- "option",
9122
- {
9123
- value: option.value,
9124
- disabled: option.disabled,
9125
- children: option.label
9126
- },
9127
- option.value
9128
- ))
9294
+ disabled,
9295
+ id: inputId,
9296
+ onClick: handleToggle,
9297
+ onFocus: handleButtonFocus,
9298
+ onKeyDown: handleKeyDown,
9299
+ ref: triggerRef,
9300
+ role: "combobox",
9301
+ type: "button",
9302
+ children: [
9303
+ /* @__PURE__ */ jsx(
9304
+ "span",
9305
+ {
9306
+ className: cn(
9307
+ webSelectValueClassName,
9308
+ !hasValue && webSelectPlaceholderClassName,
9309
+ inputClassName
9310
+ ),
9311
+ children: hasValue ? selectedLabel : ""
9312
+ }
9313
+ ),
9314
+ /* @__PURE__ */ jsx(
9315
+ BsChevronDown,
9316
+ {
9317
+ "aria-hidden": "true",
9318
+ className: cn(
9319
+ webSelectChevronClassName,
9320
+ open && webSelectChevronOpenClassName,
9321
+ chevronClassName
9322
+ )
9323
+ }
9324
+ )
9325
+ ]
9129
9326
  }
9130
9327
  ),
9328
+ /* @__PURE__ */ jsx(TransitionDropdown_default, { visibility: open, children: /* @__PURE__ */ jsx(
9329
+ "div",
9330
+ {
9331
+ "aria-label": resolvedLabel,
9332
+ className: cn(webSelectDropdownClassName, dropdownClassName),
9333
+ id: listboxId,
9334
+ role: "listbox",
9335
+ children: /* @__PURE__ */ jsx("div", { className: webSelectListClassName, children: options.length > 0 ? options.map((option, index3) => {
9336
+ const selected = option.value === field.value;
9337
+ const active = index3 === resolvedActiveIndex;
9338
+ return /* @__PURE__ */ jsx(
9339
+ "button",
9340
+ {
9341
+ "aria-disabled": option.disabled || void 0,
9342
+ "aria-selected": selected,
9343
+ className: cn(
9344
+ webSelectOptionClassName,
9345
+ !option.disabled && webSelectOptionHoverClassName,
9346
+ selected && webSelectOptionSelectedClassName,
9347
+ active && webSelectOptionActiveClassName,
9348
+ option.disabled && webSelectOptionDisabledClassName,
9349
+ selected && selectedOptionClassName,
9350
+ active && activeOptionClassName,
9351
+ option.disabled && disabledOptionClassName,
9352
+ optionClassName
9353
+ ),
9354
+ disabled: option.disabled,
9355
+ id: `${listboxId}-option-${index3}`,
9356
+ onClick: () => handleSelect(option),
9357
+ onMouseEnter: () => {
9358
+ if (!option.disabled) {
9359
+ setActiveIndex(index3);
9360
+ }
9361
+ },
9362
+ role: "option",
9363
+ type: "button",
9364
+ children: /* @__PURE__ */ jsx(
9365
+ "span",
9366
+ {
9367
+ className: cn(
9368
+ webSelectOptionContentClassName,
9369
+ optionContentClassName
9370
+ ),
9371
+ children: option.label
9372
+ }
9373
+ )
9374
+ },
9375
+ option.value
9376
+ );
9377
+ }) : /* @__PURE__ */ jsx("div", { className: cn(webSelectEmptyClassName, emptyClassName), children: emptyMessage }) })
9378
+ }
9379
+ ) }),
9131
9380
  /* @__PURE__ */ jsx(
9132
9381
  InputLabel,
9133
9382
  {
@@ -9977,24 +10226,6 @@ function HeaderNav({ data = [], styles }) {
9977
10226
  );
9978
10227
  }
9979
10228
  var HeaderNav_default = HeaderNav;
9980
- function useClickOutside(ref, fun) {
9981
- useEffect(() => {
9982
- const listener = (e) => {
9983
- if (!ref.current || ref.current.contains(e.target)) {
9984
- return;
9985
- }
9986
- if (fun) {
9987
- fun();
9988
- }
9989
- };
9990
- document.addEventListener("mousedown", listener);
9991
- document.addEventListener("touchstart", listener);
9992
- return () => {
9993
- document.removeEventListener("mousedown", listener);
9994
- document.removeEventListener("touchstart", listener);
9995
- };
9996
- }, [ref, fun]);
9997
- }
9998
10229
  var HeaderNavItemContext = ({
9999
10230
  icon,
10000
10231
  name: name2,