@takashi145/react-multi-select-buttons 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/dist/index.js +70 -248
  3. package/package.json +6 -1
package/README.md CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  Button-based multi-select components for React.
4
4
 
5
+ ![sample](https://github.com/user-attachments/assets/3f598c27-63aa-4930-8d14-d13476d58975)
6
+
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
- npm install @takashi145/@takashi145/react-multi-select-buttons
10
+ npm install @takashi145/react-multi-select-buttons
9
11
  ```
10
12
 
11
13
  ## Components
package/dist/index.js CHANGED
@@ -1,220 +1,42 @@
1
- (function(){try{if(typeof document<`u`){var e=document.createElement(`style`);e.appendChild(document.createTextNode(`.multi-select-picker{grid-template-columns:repeat(auto-fit,minmax(96px,1fr));gap:8px;display:grid}.multi-select-picker__cell{min-width:0}.multi-select-picker__item{color:#111827;cursor:pointer;background:#fff;border:1px solid #d0d7de;border-radius:10px;justify-content:space-between;align-items:center;width:100%;min-height:44px;padding:10px 12px;display:flex}.multi-select-picker__item.is-selected{background:#eff6ff;border-color:#2563eb}.multi-select-picker__item:active{background:#f3f4f6;transform:scale(.96)}.multi-select-picker__item.is-disabled:active,.multi-select-picker__item.is-limit:active{background:#fff;transform:none}.multi-select-picker__item.is-disabled,.multi-select-picker__item.is-limit{cursor:not-allowed;opacity:.55}.multi-select-picker__label,.multi-select-picker__order{font:inherit}
2
- /*$vite$:1*/`)),document.head.appendChild(e)}}catch(e){console.error(`vite-plugin-css-injected-by-js`,e)}})();import { useMemo as e } from "react";
3
- //#region \0rolldown/runtime.js
4
- var t = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), n = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
5
- if (typeof require < "u") return require.apply(this, arguments);
6
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
7
- }), r = /* @__PURE__ */ t(((e) => {
8
- var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
9
- function r(e, n, r) {
10
- var i = null;
11
- if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
12
- else r = n;
13
- return n = r.ref, {
14
- $$typeof: t,
15
- type: e,
16
- key: i,
17
- ref: n === void 0 ? null : n,
18
- props: r
19
- };
20
- }
21
- e.Fragment = n, e.jsx = r, e.jsxs = r;
22
- })), i = /* @__PURE__ */ t(((e) => {
23
- process.env.NODE_ENV !== "production" && (function() {
24
- function t(e) {
25
- if (e == null) return null;
26
- if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
27
- if (typeof e == "string") return e;
28
- switch (e) {
29
- case v: return "Fragment";
30
- case b: return "Profiler";
31
- case y: return "StrictMode";
32
- case w: return "Suspense";
33
- case T: return "SuspenseList";
34
- case O: return "Activity";
35
- }
36
- if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
37
- case _: return "Portal";
38
- case S: return e.displayName || "Context";
39
- case x: return (e._context.displayName || "Context") + ".Consumer";
40
- case C:
41
- var n = e.render;
42
- return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
43
- case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
44
- case D:
45
- n = e._payload, e = e._init;
46
- try {
47
- return t(e(n));
48
- } catch {}
49
- }
50
- return null;
51
- }
52
- function r(e) {
53
- return "" + e;
54
- }
55
- function i(e) {
56
- try {
57
- r(e);
58
- var t = !1;
59
- } catch {
60
- t = !0;
61
- }
62
- if (t) {
63
- t = console;
64
- var n = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
65
- return n.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), r(e);
66
- }
67
- }
68
- function a(e) {
69
- if (e === v) return "<>";
70
- if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
71
- try {
72
- var n = t(e);
73
- return n ? "<" + n + ">" : "<...>";
74
- } catch {
75
- return "<...>";
76
- }
77
- }
78
- function o() {
79
- var e = A.A;
80
- return e === null ? null : e.getOwner();
81
- }
82
- function s() {
83
- return Error("react-stack-top-frame");
84
- }
85
- function c(e) {
86
- if (j.call(e, "key")) {
87
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
88
- if (t && t.isReactWarning) return !1;
89
- }
90
- return e.key !== void 0;
91
- }
92
- function l(e, t) {
93
- function n() {
94
- P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
95
- }
96
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
97
- get: n,
98
- configurable: !0
99
- });
100
- }
101
- function u() {
102
- var e = t(this.type);
103
- return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
104
- }
105
- function d(e, t, n, r, i, a) {
106
- var o = n.ref;
107
- return e = {
108
- $$typeof: g,
109
- type: e,
110
- key: t,
111
- props: n,
112
- _owner: r
113
- }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
114
- enumerable: !1,
115
- value: null
116
- }) : Object.defineProperty(e, "ref", {
117
- enumerable: !1,
118
- get: u
119
- }), e._store = {}, Object.defineProperty(e._store, "validated", {
120
- configurable: !1,
121
- enumerable: !1,
122
- writable: !0,
123
- value: 0
124
- }), Object.defineProperty(e, "_debugInfo", {
125
- configurable: !1,
126
- enumerable: !1,
127
- writable: !0,
128
- value: null
129
- }), Object.defineProperty(e, "_debugStack", {
130
- configurable: !1,
131
- enumerable: !1,
132
- writable: !0,
133
- value: i
134
- }), Object.defineProperty(e, "_debugTask", {
135
- configurable: !1,
136
- enumerable: !1,
137
- writable: !0,
138
- value: a
139
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
140
- }
141
- function f(e, n, r, a, s, u) {
142
- var f = n.children;
143
- if (f !== void 0) if (a) if (M(f)) {
144
- for (a = 0; a < f.length; a++) p(f[a]);
145
- Object.freeze && Object.freeze(f);
146
- } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
147
- else p(f);
148
- if (j.call(n, "key")) {
149
- f = t(e);
150
- var m = Object.keys(n).filter(function(e) {
151
- return e !== "key";
152
- });
153
- a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), R[f + a] = !0);
154
- }
155
- if (f = null, r !== void 0 && (i(r), f = "" + r), c(n) && (i(n.key), f = "" + n.key), "key" in n) for (var h in r = {}, n) h !== "key" && (r[h] = n[h]);
156
- else r = n;
157
- return f && l(r, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, r, o(), s, u);
158
- }
159
- function p(e) {
160
- m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
161
- }
162
- function m(e) {
163
- return typeof e == "object" && !!e && e.$$typeof === g;
164
- }
165
- var h = n("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
166
- return null;
167
- };
168
- h = { react_stack_bottom_frame: function(e) {
169
- return e();
170
- } };
171
- var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(a(s)), R = {};
172
- e.Fragment = v, e.jsx = function(e, t, n) {
173
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
174
- return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(a(e)) : L);
175
- }, e.jsxs = function(e, t, n) {
176
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
177
- return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(a(e)) : L);
178
- };
179
- })();
180
- })), a = (/* @__PURE__ */ t(((e, t) => {
181
- process.env.NODE_ENV === "production" ? t.exports = r() : t.exports = i();
182
- })))();
183
- function o({ isSelected: e, isDisabled: t, isInteractive: n, onClick: r, label: i }) {
184
- return /* @__PURE__ */ (0, a.jsx)("button", {
1
+ (function(){try{if(typeof document<`u`){var e=document.createElement(`style`);e.appendChild(document.createTextNode(`@layer multi-select-picker{.multi-select-picker{grid-template-columns:repeat(auto-fit,minmax(96px,1fr));gap:8px;display:grid}.multi-select-picker__cell{min-width:0}}.multi-select-picker__item{color:#111827;cursor:pointer;background:#fff;border:1px solid #d0d7de;border-radius:10px;justify-content:space-between;align-items:center;width:100%;min-height:44px;padding:10px 12px;display:flex}.multi-select-picker__item.is-selected{background:#eff6ff;border-color:#2563eb}.multi-select-picker__item:active{background:#f3f4f6;transform:scale(.96)}.multi-select-picker__item.is-disabled:active,.multi-select-picker__item.is-limit:active{background:#fff;transform:none}.multi-select-picker__item.is-disabled,.multi-select-picker__item.is-limit{cursor:not-allowed;opacity:.55}.multi-select-picker__label,.multi-select-picker__order{font:inherit}
2
+ /*$vite$:1*/`)),document.head.appendChild(e)}}catch(e){console.error(`vite-plugin-css-injected-by-js`,e)}})();import { jsx as e } from "react/jsx-runtime";
3
+ import { useMemo as t } from "react";
4
+ //#region src/components/DefaultMultiSelectButton.tsx
5
+ function n({ isSelected: t, isDisabled: n, isInteractive: r, onClick: i, label: a }) {
6
+ return /* @__PURE__ */ e("button", {
185
7
  type: "button",
186
8
  className: [
187
9
  "multi-select-picker__item",
188
- e ? "is-selected" : "",
189
- t ? "is-disabled" : "",
190
- !n && !t ? "is-limit" : ""
10
+ t ? "is-selected" : "",
11
+ n ? "is-disabled" : "",
12
+ !r && !n ? "is-limit" : ""
191
13
  ].filter(Boolean).join(" "),
192
- onClick: r,
193
- "aria-disabled": t,
194
- "aria-pressed": e,
195
- children: /* @__PURE__ */ (0, a.jsx)("span", {
14
+ onClick: i,
15
+ "aria-disabled": n,
16
+ "aria-pressed": t,
17
+ children: /* @__PURE__ */ e("span", {
196
18
  className: "multi-select-picker__label",
197
- children: i
19
+ children: a
198
20
  })
199
21
  });
200
22
  }
201
23
  //#endregion
202
24
  //#region src/utils/selection.ts
203
- function s(e, t) {
204
- return c(e, t) >= 0;
25
+ function r(e, t) {
26
+ return i(e, t) >= 0;
205
27
  }
206
- function c(e, t) {
28
+ function i(e, t) {
207
29
  return t.findIndex((t) => Object.is(e, t));
208
30
  }
209
- function l({ item: e, selectedItemKeys: t, selectedItems: n, maxSelection: r, isDisabled: i }) {
210
- if (i) return {
31
+ function a({ item: e, selectedItemKeys: t, selectedItems: n, maxSelection: r, isDisabled: a }) {
32
+ if (a) return {
211
33
  type: "disabled",
212
34
  nextSelectedItems: n
213
35
  };
214
- let a = c(e.key, t);
215
- return a >= 0 ? {
36
+ let o = i(e.key, t);
37
+ return o >= 0 ? {
216
38
  type: "deselected",
217
- nextSelectedItems: n.filter((e, t) => t !== a)
39
+ nextSelectedItems: n.filter((e, t) => t !== o)
218
40
  } : n.length >= r ? {
219
41
  type: "limit",
220
42
  nextSelectedItems: n
@@ -225,53 +47,53 @@ function l({ item: e, selectedItemKeys: t, selectedItems: n, maxSelection: r, is
225
47
  }
226
48
  //#endregion
227
49
  //#region src/hooks/useSelectablePicker.ts
228
- function u({ items: t, selectedItems: n, maxSelection: r, onChange: i, onSelectionLimitReached: a, onDisabledClick: o }) {
229
- return e(() => {
230
- d(t.map((e) => e.key), "items");
231
- let e = n.map((e) => e.key);
232
- return d(e, "selectedItems"), t.map((t, u) => {
233
- let { key: d, value: f } = t, p = c(d, e), m = p >= 0, h = t.disabled ?? !1;
50
+ function o({ items: e, selectedItems: n, maxSelection: o, onChange: c, onSelectionLimitReached: l, onDisabledClick: u }) {
51
+ return t(() => {
52
+ s(e.map((e) => e.key), "items");
53
+ let t = n.map((e) => e.key);
54
+ return s(t, "selectedItems"), e.map((e, s) => {
55
+ let { key: d, value: f } = e, p = i(d, t), m = p >= 0, h = e.disabled ?? !1;
234
56
  return {
235
57
  key: d,
236
- index: u,
58
+ index: s,
237
59
  renderParams: {
238
- item: t,
60
+ item: e,
239
61
  value: f,
240
62
  isSelected: m,
241
63
  isDisabled: h,
242
- isInteractive: s(d, e) || !h && n.length < r,
64
+ isInteractive: r(d, t) || !h && n.length < o,
243
65
  selectedOrder: m ? p + 1 : null,
244
66
  onClick: () => {
245
- let s = l({
246
- item: t,
247
- selectedItemKeys: e,
67
+ let r = a({
68
+ item: e,
69
+ selectedItemKeys: t,
248
70
  selectedItems: n,
249
- maxSelection: r,
71
+ maxSelection: o,
250
72
  isDisabled: h
251
73
  });
252
- if (s.type === "disabled") {
253
- o?.(t);
74
+ if (r.type === "disabled") {
75
+ u?.(e);
254
76
  return;
255
77
  }
256
- if (s.type === "limit") {
257
- a?.(t);
78
+ if (r.type === "limit") {
79
+ l?.(e);
258
80
  return;
259
81
  }
260
- i(s.nextSelectedItems);
82
+ c(r.nextSelectedItems);
261
83
  }
262
84
  }
263
85
  };
264
86
  });
265
87
  }, [
266
- t,
267
- r,
268
- i,
88
+ e,
269
89
  o,
270
- a,
90
+ c,
91
+ u,
92
+ l,
271
93
  n
272
94
  ]);
273
95
  }
274
- function d(e, t) {
96
+ function s(e, t) {
275
97
  let n = /* @__PURE__ */ new Set();
276
98
  for (let r of e) {
277
99
  if (n.has(r)) throw Error(`MultiSelectButtons received duplicate key in ${t}: ${String(r)}`);
@@ -280,50 +102,50 @@ function d(e, t) {
280
102
  }
281
103
  //#endregion
282
104
  //#region src/components/MultiSelectButtons.tsx
283
- function f(e) {
284
- let { className: t, items: n, style: r, renderValue: i } = e, s = u(e);
285
- return /* @__PURE__ */ (0, a.jsx)("div", {
286
- className: ["multi-select-picker", t].filter(Boolean).join(" "),
287
- style: r,
288
- children: s.map(({ key: e, index: t, renderParams: r }) => /* @__PURE__ */ (0, a.jsx)("div", {
105
+ function c(t) {
106
+ let { className: r, items: i, style: a, renderValue: s } = t, c = o(t);
107
+ return /* @__PURE__ */ e("div", {
108
+ className: ["multi-select-picker", r].filter(Boolean).join(" "),
109
+ style: a,
110
+ children: c.map(({ key: t, index: r, renderParams: a }) => /* @__PURE__ */ e("div", {
289
111
  className: "multi-select-picker__cell",
290
- children: i ? i(r) : /* @__PURE__ */ (0, a.jsx)(o, {
291
- ...r,
292
- label: n[t]?.label ?? String(r.value)
112
+ children: s ? s(a) : /* @__PURE__ */ e(n, {
113
+ ...a,
114
+ label: i[r]?.label ?? String(a.value)
293
115
  })
294
- }, e))
116
+ }, t))
295
117
  });
296
118
  }
297
119
  //#endregion
298
120
  //#region src/components/NumberMultiSelectButtons.tsx
299
- function p({ min: t, max: n, step: r = 1, selectedValues: i, maxSelection: o, onChange: s, getValueLabel: c, isValueDisabled: l, renderValue: u, onSelectionLimitReached: d, onDisabledClick: p, className: m, style: h }) {
300
- let g = e(() => {
121
+ function l({ min: n, max: r, step: i = 1, selectedValues: a, maxSelection: o, onChange: s, getValueLabel: l, isValueDisabled: u, renderValue: d, onSelectionLimitReached: f, onDisabledClick: p, className: m, style: h }) {
122
+ let g = t(() => {
301
123
  let e = [];
302
- for (let i = t; i <= n; i += r) e.push({
303
- key: i,
304
- label: c?.(i, e.length) ?? String(i),
305
- value: i,
306
- disabled: l?.(i, e.length) ?? !1
124
+ for (let t = n; t <= r; t += i) e.push({
125
+ key: t,
126
+ label: l?.(t, e.length) ?? String(t),
127
+ value: t,
128
+ disabled: u?.(t, e.length) ?? !1
307
129
  });
308
130
  return e;
309
131
  }, [
310
- c,
311
132
  l,
133
+ u,
134
+ r,
312
135
  n,
313
- t,
314
- r
136
+ i
315
137
  ]);
316
- return /* @__PURE__ */ (0, a.jsx)(f, {
138
+ return /* @__PURE__ */ e(c, {
317
139
  items: g,
318
- selectedItems: e(() => i.flatMap((e) => g.find((t) => Object.is(t.value, e)) ?? []), [g, i]),
140
+ selectedItems: t(() => a.flatMap((e) => g.find((t) => Object.is(t.value, e)) ?? []), [g, a]),
319
141
  maxSelection: o,
320
142
  onChange: (e) => s(e.map((e) => e.value)),
321
- renderValue: u,
322
- onSelectionLimitReached: (e) => d?.(e.value),
143
+ renderValue: d,
144
+ onSelectionLimitReached: (e) => f?.(e.value),
323
145
  onDisabledClick: (e) => p?.(e.value),
324
146
  className: m,
325
147
  style: h
326
148
  });
327
149
  }
328
150
  //#endregion
329
- export { f as MultiSelectButtons, p as NumberMultiSelectButtons };
151
+ export { c as MultiSelectButtons, l as NumberMultiSelectButtons };
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@takashi145/react-multi-select-buttons",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Button-based multi-select components for React.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/takashi145/react-multi-select-buttons"
9
+ },
10
+ "homepage": "https://github.com/takashi145/react-multi-select-buttons#readme",
6
11
  "type": "module",
7
12
  "files": [
8
13
  "dist"