@asnewyla/select 0.2.1 → 0.2.2

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.js CHANGED
@@ -1,20 +1,44 @@
1
- 'use strict';
1
+ 'use client';
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
20
 
3
- var unstyledSelect = require('@asnewyla/unstyled-select');
4
- var react = require('react');
5
- var jsxRuntime = require('react/jsx-runtime');
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ Select: () => Select
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
6
27
 
7
28
  // src/components/Select.tsx
29
+ var import_unstyled_select = require("@asnewyla/unstyled-select");
30
+ var import_react = require("react");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
8
32
  function SelectInner({ label, id, error, disabled, className, placeholder, ...rest }, ref) {
9
- const generatedId = react.useId();
33
+ const generatedId = (0, import_react.useId)();
10
34
  const selectId = id ?? generatedId;
11
35
  const errorId = `${selectId}-error`;
12
36
  const labelId = `${selectId}-label`;
13
37
  const renderValue = (selectedOptions, { removeOption }) => {
14
38
  if (rest.multiple) {
15
- return selectedOptions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "xd-select-chips", children: selectedOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "xd-select-chip", children: [
39
+ return selectedOptions.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "xd-select-chips", children: selectedOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "xd-select-chip", children: [
16
40
  option.label,
17
- /* @__PURE__ */ jsxRuntime.jsx(
41
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
18
42
  "button",
19
43
  {
20
44
  type: "button",
@@ -27,10 +51,10 @@ function SelectInner({ label, id, error, disabled, className, placeholder, ...re
27
51
  children: "\xD7"
28
52
  }
29
53
  )
30
- ] }, option.value)) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "xd-select-value", "data-placeholder": "true", children: placeholder });
54
+ ] }, option.value)) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "xd-select-value", "data-placeholder": "true", children: placeholder });
31
55
  }
32
56
  const selected = selectedOptions[0];
33
- return /* @__PURE__ */ jsxRuntime.jsx(
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
34
58
  "span",
35
59
  {
36
60
  className: "xd-select-value",
@@ -39,10 +63,10 @@ function SelectInner({ label, id, error, disabled, className, placeholder, ...re
39
63
  }
40
64
  );
41
65
  };
42
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "xd-select", children: [
43
- /* @__PURE__ */ jsxRuntime.jsx("label", { className: "xd-select-label", id: labelId, htmlFor: selectId, children: label }),
44
- /* @__PURE__ */ jsxRuntime.jsx(
45
- unstyledSelect.UnstyledSelect,
66
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "xd-select", children: [
67
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: "xd-select-label", id: labelId, htmlFor: selectId, children: label }),
68
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
69
+ import_unstyled_select.UnstyledSelect,
46
70
  {
47
71
  id: selectId,
48
72
  placeholder,
@@ -56,11 +80,12 @@ function SelectInner({ label, id, error, disabled, className, placeholder, ...re
56
80
  ref
57
81
  }
58
82
  ),
59
- error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "xd-select-error", id: errorId, children: error })
83
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "xd-select-error", id: errorId, children: error })
60
84
  ] });
61
85
  }
62
- var Select = react.forwardRef(SelectInner);
63
-
64
- exports.Select = Select;
65
- //# sourceMappingURL=index.js.map
86
+ var Select = (0, import_react.forwardRef)(SelectInner);
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ Select
90
+ });
66
91
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Select.tsx"],"names":["useId","jsx","jsxs","UnstyledSelect","forwardRef"],"mappings":";;;;;;;AA0BA,SAAS,WAAA,CACP,EAAE,KAAA,EAAO,EAAA,EAAI,KAAA,EAAO,QAAA,EAAU,SAAA,EAAW,WAAA,EAAa,GAAG,IAAA,EAAK,EAC9D,GAAA,EACA;AACA,EAAA,MAAM,cAAcA,WAAA,EAAM;AAC1B,EAAA,MAAM,WAAW,EAAA,IAAM,WAAA;AACvB,EAAA,MAAM,OAAA,GAAU,GAAG,QAAQ,CAAA,MAAA,CAAA;AAC3B,EAAA,MAAM,OAAA,GAAU,GAAG,QAAQ,CAAA,MAAA,CAAA;AAM3B,EAAA,MAAM,WAAA,GAAc,CAClB,eAAA,EACA,EAAE,cAAa,KACZ;AACH,IAAA,IAAI,KAAK,QAAA,EAAU;AACjB,MAAA,OAAO,eAAA,CAAgB,MAAA,GAAS,CAAA,mBAC9BC,cAAA,CAAC,UAAK,SAAA,EAAU,iBAAA,EACb,QAAA,EAAA,eAAA,CAAgB,GAAA,CAAI,CAAC,MAAA,qBACpBC,eAAA,CAAC,MAAA,EAAA,EAAwB,WA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,QACJ,OAAA,EAAS,CAAC,CAAC,KAAA;AAAA,QACX,WAAA;AAAA,QACA,iBAAA,EAAiB,OAAA;AAAA,QACjB,kBAAA,EAAkB,QAAQ,OAAA,GAAU,MAAA;AAAA,QACpC,SAAA,EACE,SAAA,GAAY,CAAA,kBAAA,EAAqB,SAAS,CAAA,CAAA,GAAK,mBAAA;AAAA,QAEjD;AAAA;AAAA,KACF;AAAA,IACC,yBACCF,cAAA,CAAC,KAAA,EAAA,EAAI,WAAU,iBAAA,EAAkB,EAAA,EAAI,SAClC,QAAA,EAAA,KAAA,EACH;AAAA,GAAA,EAEJ,CAAA;AAEJ;AAEO,IAAM,MAAA,GAASG,iBAAwC,WAAW","file":"index.js","sourcesContent":["import {\n type SelectOption,\n UnstyledSelect,\n type UnstyledSelectProps,\n type UnstyledSelectRenderValueHelpers,\n} from '@asnewyla/unstyled-select';\nimport { type ForwardedRef, forwardRef, useId } from 'react';\nimport './Select.css';\n\n// `invalid`/`renderValue` live entirely on the common (non-discriminated)\n// part of `UnstyledSelectProps`, but `Omit` on a discriminated union still\n// risks collapsing it (see unstyled-select's own test-utils for the same\n// problem). `T` has to stay a naked type parameter for the conditional to\n// distribute over the union member-by-member instead of collapsing it.\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown\n ? Omit<T, K>\n : never;\n\nexport type SelectProps = DistributiveOmit<\n UnstyledSelectProps,\n 'invalid' | 'renderValue'\n> & {\n label: string;\n error?: string;\n};\n\nfunction SelectInner(\n { label, id, error, disabled, className, placeholder, ...rest }: SelectProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const generatedId = useId();\n const selectId = id ?? generatedId;\n const errorId = `${selectId}-error`;\n const labelId = `${selectId}-label`;\n\n // Always supplied (not just for `multiple`) so the single-select value\n // and the empty-multi-select placeholder are real elements\n // (span.xd-select-value), not a bare text node — Select.css can then\n // dim/truncate them the same way it already does the chips.\n const renderValue = (\n selectedOptions: SelectOption[],\n { removeOption }: UnstyledSelectRenderValueHelpers,\n ) => {\n if (rest.multiple) {\n return selectedOptions.length > 0 ? (\n <span className=\"xd-select-chips\">\n {selectedOptions.map((option) => (\n <span key={option.value} className=\"xd-select-chip\">\n {option.label}\n <button\n type=\"button\"\n className=\"xd-select-chip-remove\"\n aria-label={`Remove ${option.label}`}\n onClick={(e) => {\n e.stopPropagation();\n removeOption(option);\n }}\n >\n ×\n </button>\n </span>\n ))}\n </span>\n ) : (\n <span className=\"xd-select-value\" data-placeholder=\"true\">\n {placeholder}\n </span>\n );\n }\n\n const selected = selectedOptions[0];\n return (\n <span\n className=\"xd-select-value\"\n data-placeholder={selected ? undefined : 'true'}\n >\n {selected ? selected.label : placeholder}\n </span>\n );\n };\n\n return (\n <div className=\"xd-select\">\n {/* `htmlFor` only auto-associates with labelable elements (input,\n button, select, ...) — the trigger is a plain `role=\"combobox\"` div, so\n it's kept here (harmless, satisfies the a11y/noLabelWithoutControl\n lint) but the real accessible-name link is `aria-labelledby` below. */}\n <label className=\"xd-select-label\" id={labelId} htmlFor={selectId}>\n {label}\n </label>\n <UnstyledSelect\n id={selectId}\n placeholder={placeholder}\n disabled={disabled}\n {...rest}\n invalid={!!error}\n renderValue={renderValue}\n aria-labelledby={labelId}\n aria-describedby={error ? errorId : undefined}\n className={\n className ? `xd-select-trigger ${className}` : 'xd-select-trigger'\n }\n ref={ref}\n />\n {error && (\n <div className=\"xd-select-error\" id={errorId}>\n {error}\n </div>\n )}\n </div>\n );\n}\n\nexport const Select = forwardRef<HTMLDivElement, SelectProps>(SelectInner);\n"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/components/Select.tsx"],"sourcesContent":["export { Select, type SelectProps } from './components';\n","import {\n type SelectOption,\n UnstyledSelect,\n type UnstyledSelectProps,\n type UnstyledSelectRenderValueHelpers,\n} from '@asnewyla/unstyled-select';\nimport { type ForwardedRef, forwardRef, useId } from 'react';\nimport './Select.css';\n\n// `invalid`/`renderValue` live entirely on the common (non-discriminated)\n// part of `UnstyledSelectProps`, but `Omit` on a discriminated union still\n// risks collapsing it (see unstyled-select's own test-utils for the same\n// problem). `T` has to stay a naked type parameter for the conditional to\n// distribute over the union member-by-member instead of collapsing it.\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown\n ? Omit<T, K>\n : never;\n\nexport type SelectProps = DistributiveOmit<\n UnstyledSelectProps,\n 'invalid' | 'renderValue'\n> & {\n label: string;\n error?: string;\n};\n\nfunction SelectInner(\n { label, id, error, disabled, className, placeholder, ...rest }: SelectProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const generatedId = useId();\n const selectId = id ?? generatedId;\n const errorId = `${selectId}-error`;\n const labelId = `${selectId}-label`;\n\n // Always supplied (not just for `multiple`) so the single-select value\n // and the empty-multi-select placeholder are real elements\n // (span.xd-select-value), not a bare text node — Select.css can then\n // dim/truncate them the same way it already does the chips.\n const renderValue = (\n selectedOptions: SelectOption[],\n { removeOption }: UnstyledSelectRenderValueHelpers,\n ) => {\n if (rest.multiple) {\n return selectedOptions.length > 0 ? (\n <span className=\"xd-select-chips\">\n {selectedOptions.map((option) => (\n <span key={option.value} className=\"xd-select-chip\">\n {option.label}\n <button\n type=\"button\"\n className=\"xd-select-chip-remove\"\n aria-label={`Remove ${option.label}`}\n onClick={(e) => {\n e.stopPropagation();\n removeOption(option);\n }}\n >\n ×\n </button>\n </span>\n ))}\n </span>\n ) : (\n <span className=\"xd-select-value\" data-placeholder=\"true\">\n {placeholder}\n </span>\n );\n }\n\n const selected = selectedOptions[0];\n return (\n <span\n className=\"xd-select-value\"\n data-placeholder={selected ? undefined : 'true'}\n >\n {selected ? selected.label : placeholder}\n </span>\n );\n };\n\n return (\n <div className=\"xd-select\">\n {/* `htmlFor` only auto-associates with labelable elements (input,\n button, select, ...) — the trigger is a plain `role=\"combobox\"` div, so\n it's kept here (harmless, satisfies the a11y/noLabelWithoutControl\n lint) but the real accessible-name link is `aria-labelledby` below. */}\n <label className=\"xd-select-label\" id={labelId} htmlFor={selectId}>\n {label}\n </label>\n <UnstyledSelect\n id={selectId}\n placeholder={placeholder}\n disabled={disabled}\n {...rest}\n invalid={!!error}\n renderValue={renderValue}\n aria-labelledby={labelId}\n aria-describedby={error ? errorId : undefined}\n className={\n className ? `xd-select-trigger ${className}` : 'xd-select-trigger'\n }\n ref={ref}\n />\n {error && (\n <div className=\"xd-select-error\" id={errorId}>\n {error}\n </div>\n )}\n </div>\n );\n}\n\nexport const Select = forwardRef<HTMLDivElement, SelectProps>(SelectInner);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,6BAKO;AACP,mBAAqD;AAyCzC;AArBZ,SAAS,YACP,EAAE,OAAO,IAAI,OAAO,UAAU,WAAW,aAAa,GAAG,KAAK,GAC9D,KACA;AACA,QAAM,kBAAc,oBAAM;AAC1B,QAAM,WAAW,MAAM;AACvB,QAAM,UAAU,GAAG,QAAQ;AAC3B,QAAM,UAAU,GAAG,QAAQ;AAM3B,QAAM,cAAc,CAClB,iBACA,EAAE,aAAa,MACZ;AACH,QAAI,KAAK,UAAU;AACjB,aAAO,gBAAgB,SAAS,IAC9B,4CAAC,UAAK,WAAU,mBACb,0BAAgB,IAAI,CAAC,WACpB,6CAAC,UAAwB,WAAU,kBAChC;AAAA,eAAO;AAAA,QACR;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAU;AAAA,YACV,cAAY,UAAU,OAAO,KAAK;AAAA,YAClC,SAAS,CAAC,MAAM;AACd,gBAAE,gBAAgB;AAClB,2BAAa,MAAM;AAAA,YACrB;AAAA,YACD;AAAA;AAAA,QAED;AAAA,WAZS,OAAO,KAalB,CACD,GACH,IAEA,4CAAC,UAAK,WAAU,mBAAkB,oBAAiB,QAChD,uBACH;AAAA,IAEJ;AAEA,UAAM,WAAW,gBAAgB,CAAC;AAClC,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,oBAAkB,WAAW,SAAY;AAAA,QAExC,qBAAW,SAAS,QAAQ;AAAA;AAAA,IAC/B;AAAA,EAEJ;AAEA,SACE,6CAAC,SAAI,WAAU,aAKb;AAAA,gDAAC,WAAM,WAAU,mBAAkB,IAAI,SAAS,SAAS,UACtD,iBACH;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACC,IAAI;AAAA,QACJ;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,SAAS,CAAC,CAAC;AAAA,QACX;AAAA,QACA,mBAAiB;AAAA,QACjB,oBAAkB,QAAQ,UAAU;AAAA,QACpC,WACE,YAAY,qBAAqB,SAAS,KAAK;AAAA,QAEjD;AAAA;AAAA,IACF;AAAA,IACC,SACC,4CAAC,SAAI,WAAU,mBAAkB,IAAI,SAClC,iBACH;AAAA,KAEJ;AAEJ;AAEO,IAAM,aAAS,yBAAwC,WAAW;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,8 +1,11 @@
1
- import { UnstyledSelect } from '@asnewyla/unstyled-select';
2
- import { forwardRef, useId } from 'react';
3
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ 'use client';
4
2
 
5
3
  // src/components/Select.tsx
4
+ import {
5
+ UnstyledSelect
6
+ } from "@asnewyla/unstyled-select";
7
+ import { forwardRef, useId } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
6
9
  function SelectInner({ label, id, error, disabled, className, placeholder, ...rest }, ref) {
7
10
  const generatedId = useId();
8
11
  const selectId = id ?? generatedId;
@@ -58,7 +61,7 @@ function SelectInner({ label, id, error, disabled, className, placeholder, ...re
58
61
  ] });
59
62
  }
60
63
  var Select = forwardRef(SelectInner);
61
-
62
- export { Select };
63
- //# sourceMappingURL=index.mjs.map
64
+ export {
65
+ Select
66
+ };
64
67
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Select.tsx"],"names":[],"mappings":";;;;;AA0BA,SAAS,WAAA,CACP,EAAE,KAAA,EAAO,EAAA,EAAI,KAAA,EAAO,QAAA,EAAU,SAAA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C,MAAA;AAAA,MAAA;AAAA,QACC,SAAA,EAAU,iBAAA;AAAA,QACV,kBAAA,EAAkB,WAAW,MAAA,GAAY,MAAA;AAAA,QAExC,QAAA,EAAA,QAAA,GAAW,SAAS,KAAA,GAAQ;AAAA;AAAA,KAC/B;AAAA,EAEJ,CAAA;AAEA,EAAA,uBACE,IAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,WAAA,EAKb,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,WAAM,SAAA,EAAU,iBAAA,EAAkB,IAAI,OAAA,EAAS,OAAA,EAAS,UACtD,QAAA,EAAA,KAAA,EACH,CAAA;AAAA,oBACA,GAAA;AAAA,MAAC,cAAA;AAAA,MAAA;AAAA,QACC,EAAA,EAAI,QAAA;AAAA,QACJ,WAAA;AAAA,QACA,QAAA;AAAA,QACC,GAAG,IAAA;AAAA,QACJ,OAAA,EAAS,CAAC,CAAC,KAAA;AAAA,QACX,WAAA;AAAA,QACA,iBAAA,EAAiB,OAAA;AAAA,QACjB,kBAAA,EAAkB,QAAQ,OAAA,GAAU,MAAA;AAAA,QACpC,SAAA,EACE,SAAA,GAAY,CAAA,kBAAA,EAAqB,SAAS,CAAA,CAAA,GAAK,mBAAA;AAAA,QAEjD;AAAA;AAAA,KACF;AAAA,IACC,yBACC,GAAA,CAAC,KAAA,EAAA,EAAI,WAAU,iBAAA,EAAkB,EAAA,EAAI,SAClC,QAAA,EAAA,KAAA,EACH;AAAA,GAAA,EAEJ,CAAA;AAEJ;AAEO,IAAM,MAAA,GAAS,WAAwC,WAAW","file":"index.mjs","sourcesContent":["import {\n type SelectOption,\n UnstyledSelect,\n type UnstyledSelectProps,\n type UnstyledSelectRenderValueHelpers,\n} from '@asnewyla/unstyled-select';\nimport { type ForwardedRef, forwardRef, useId } from 'react';\nimport './Select.css';\n\n// `invalid`/`renderValue` live entirely on the common (non-discriminated)\n// part of `UnstyledSelectProps`, but `Omit` on a discriminated union still\n// risks collapsing it (see unstyled-select's own test-utils for the same\n// problem). `T` has to stay a naked type parameter for the conditional to\n// distribute over the union member-by-member instead of collapsing it.\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown\n ? Omit<T, K>\n : never;\n\nexport type SelectProps = DistributiveOmit<\n UnstyledSelectProps,\n 'invalid' | 'renderValue'\n> & {\n label: string;\n error?: string;\n};\n\nfunction SelectInner(\n { label, id, error, disabled, className, placeholder, ...rest }: SelectProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const generatedId = useId();\n const selectId = id ?? generatedId;\n const errorId = `${selectId}-error`;\n const labelId = `${selectId}-label`;\n\n // Always supplied (not just for `multiple`) so the single-select value\n // and the empty-multi-select placeholder are real elements\n // (span.xd-select-value), not a bare text node — Select.css can then\n // dim/truncate them the same way it already does the chips.\n const renderValue = (\n selectedOptions: SelectOption[],\n { removeOption }: UnstyledSelectRenderValueHelpers,\n ) => {\n if (rest.multiple) {\n return selectedOptions.length > 0 ? (\n <span className=\"xd-select-chips\">\n {selectedOptions.map((option) => (\n <span key={option.value} className=\"xd-select-chip\">\n {option.label}\n <button\n type=\"button\"\n className=\"xd-select-chip-remove\"\n aria-label={`Remove ${option.label}`}\n onClick={(e) => {\n e.stopPropagation();\n removeOption(option);\n }}\n >\n ×\n </button>\n </span>\n ))}\n </span>\n ) : (\n <span className=\"xd-select-value\" data-placeholder=\"true\">\n {placeholder}\n </span>\n );\n }\n\n const selected = selectedOptions[0];\n return (\n <span\n className=\"xd-select-value\"\n data-placeholder={selected ? undefined : 'true'}\n >\n {selected ? selected.label : placeholder}\n </span>\n );\n };\n\n return (\n <div className=\"xd-select\">\n {/* `htmlFor` only auto-associates with labelable elements (input,\n button, select, ...) — the trigger is a plain `role=\"combobox\"` div, so\n it's kept here (harmless, satisfies the a11y/noLabelWithoutControl\n lint) but the real accessible-name link is `aria-labelledby` below. */}\n <label className=\"xd-select-label\" id={labelId} htmlFor={selectId}>\n {label}\n </label>\n <UnstyledSelect\n id={selectId}\n placeholder={placeholder}\n disabled={disabled}\n {...rest}\n invalid={!!error}\n renderValue={renderValue}\n aria-labelledby={labelId}\n aria-describedby={error ? errorId : undefined}\n className={\n className ? `xd-select-trigger ${className}` : 'xd-select-trigger'\n }\n ref={ref}\n />\n {error && (\n <div className=\"xd-select-error\" id={errorId}>\n {error}\n </div>\n )}\n </div>\n );\n}\n\nexport const Select = forwardRef<HTMLDivElement, SelectProps>(SelectInner);\n"]}
1
+ {"version":3,"sources":["../src/components/Select.tsx"],"sourcesContent":["import {\n type SelectOption,\n UnstyledSelect,\n type UnstyledSelectProps,\n type UnstyledSelectRenderValueHelpers,\n} from '@asnewyla/unstyled-select';\nimport { type ForwardedRef, forwardRef, useId } from 'react';\nimport './Select.css';\n\n// `invalid`/`renderValue` live entirely on the common (non-discriminated)\n// part of `UnstyledSelectProps`, but `Omit` on a discriminated union still\n// risks collapsing it (see unstyled-select's own test-utils for the same\n// problem). `T` has to stay a naked type parameter for the conditional to\n// distribute over the union member-by-member instead of collapsing it.\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown\n ? Omit<T, K>\n : never;\n\nexport type SelectProps = DistributiveOmit<\n UnstyledSelectProps,\n 'invalid' | 'renderValue'\n> & {\n label: string;\n error?: string;\n};\n\nfunction SelectInner(\n { label, id, error, disabled, className, placeholder, ...rest }: SelectProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const generatedId = useId();\n const selectId = id ?? generatedId;\n const errorId = `${selectId}-error`;\n const labelId = `${selectId}-label`;\n\n // Always supplied (not just for `multiple`) so the single-select value\n // and the empty-multi-select placeholder are real elements\n // (span.xd-select-value), not a bare text node — Select.css can then\n // dim/truncate them the same way it already does the chips.\n const renderValue = (\n selectedOptions: SelectOption[],\n { removeOption }: UnstyledSelectRenderValueHelpers,\n ) => {\n if (rest.multiple) {\n return selectedOptions.length > 0 ? (\n <span className=\"xd-select-chips\">\n {selectedOptions.map((option) => (\n <span key={option.value} className=\"xd-select-chip\">\n {option.label}\n <button\n type=\"button\"\n className=\"xd-select-chip-remove\"\n aria-label={`Remove ${option.label}`}\n onClick={(e) => {\n e.stopPropagation();\n removeOption(option);\n }}\n >\n ×\n </button>\n </span>\n ))}\n </span>\n ) : (\n <span className=\"xd-select-value\" data-placeholder=\"true\">\n {placeholder}\n </span>\n );\n }\n\n const selected = selectedOptions[0];\n return (\n <span\n className=\"xd-select-value\"\n data-placeholder={selected ? undefined : 'true'}\n >\n {selected ? selected.label : placeholder}\n </span>\n );\n };\n\n return (\n <div className=\"xd-select\">\n {/* `htmlFor` only auto-associates with labelable elements (input,\n button, select, ...) — the trigger is a plain `role=\"combobox\"` div, so\n it's kept here (harmless, satisfies the a11y/noLabelWithoutControl\n lint) but the real accessible-name link is `aria-labelledby` below. */}\n <label className=\"xd-select-label\" id={labelId} htmlFor={selectId}>\n {label}\n </label>\n <UnstyledSelect\n id={selectId}\n placeholder={placeholder}\n disabled={disabled}\n {...rest}\n invalid={!!error}\n renderValue={renderValue}\n aria-labelledby={labelId}\n aria-describedby={error ? errorId : undefined}\n className={\n className ? `xd-select-trigger ${className}` : 'xd-select-trigger'\n }\n ref={ref}\n />\n {error && (\n <div className=\"xd-select-error\" id={errorId}>\n {error}\n </div>\n )}\n </div>\n );\n}\n\nexport const Select = forwardRef<HTMLDivElement, SelectProps>(SelectInner);\n"],"mappings":";;;AAAA;AAAA,EAEE;AAAA,OAGK;AACP,SAA4B,YAAY,aAAa;AAyCzC,SAEE,KAFF;AArBZ,SAAS,YACP,EAAE,OAAO,IAAI,OAAO,UAAU,WAAW,aAAa,GAAG,KAAK,GAC9D,KACA;AACA,QAAM,cAAc,MAAM;AAC1B,QAAM,WAAW,MAAM;AACvB,QAAM,UAAU,GAAG,QAAQ;AAC3B,QAAM,UAAU,GAAG,QAAQ;AAM3B,QAAM,cAAc,CAClB,iBACA,EAAE,aAAa,MACZ;AACH,QAAI,KAAK,UAAU;AACjB,aAAO,gBAAgB,SAAS,IAC9B,oBAAC,UAAK,WAAU,mBACb,0BAAgB,IAAI,CAAC,WACpB,qBAAC,UAAwB,WAAU,kBAChC;AAAA,eAAO;AAAA,QACR;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAU;AAAA,YACV,cAAY,UAAU,OAAO,KAAK;AAAA,YAClC,SAAS,CAAC,MAAM;AACd,gBAAE,gBAAgB;AAClB,2BAAa,MAAM;AAAA,YACrB;AAAA,YACD;AAAA;AAAA,QAED;AAAA,WAZS,OAAO,KAalB,CACD,GACH,IAEA,oBAAC,UAAK,WAAU,mBAAkB,oBAAiB,QAChD,uBACH;AAAA,IAEJ;AAEA,UAAM,WAAW,gBAAgB,CAAC;AAClC,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,oBAAkB,WAAW,SAAY;AAAA,QAExC,qBAAW,SAAS,QAAQ;AAAA;AAAA,IAC/B;AAAA,EAEJ;AAEA,SACE,qBAAC,SAAI,WAAU,aAKb;AAAA,wBAAC,WAAM,WAAU,mBAAkB,IAAI,SAAS,SAAS,UACtD,iBACH;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACC,IAAI;AAAA,QACJ;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,SAAS,CAAC,CAAC;AAAA,QACX;AAAA,QACA,mBAAiB;AAAA,QACjB,oBAAkB,QAAQ,UAAU;AAAA,QACpC,WACE,YAAY,qBAAqB,SAAS,KAAK;AAAA,QAEjD;AAAA;AAAA,IACF;AAAA,IACC,SACC,oBAAC,SAAI,WAAU,mBAAkB,IAAI,SAClC,iBACH;AAAA,KAEJ;AAEJ;AAEO,IAAM,SAAS,WAAwC,WAAW;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asnewyla/select",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Styled select/combobox with label, validation error display, and accessibility",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -41,7 +41,7 @@
41
41
  "react-dom": "^18.0.0 || ^19.0.0"
42
42
  },
43
43
  "dependencies": {
44
- "@asnewyla/unstyled-select": "0.2.0"
44
+ "@asnewyla/unstyled-select": "0.2.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@testing-library/jest-dom": "^6.4.0",