@ramong26/xp-components 1.0.10 → 1.0.13

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
@@ -1,3 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
1
7
  // src/App.tsx
2
8
  import { useState } from "react";
3
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -20,6 +26,507 @@ function App() {
20
26
  ] });
21
27
  }
22
28
  var App_default = App;
29
+
30
+ // src/components/Button/Button.tsx
31
+ var Button_exports = {};
32
+ __export(Button_exports, {
33
+ default: () => Button_default
34
+ });
35
+ import { jsx as jsx2 } from "react/jsx-runtime";
36
+ var Button = ({
37
+ children,
38
+ variant = "default",
39
+ ...rest
40
+ }) => {
41
+ return /* @__PURE__ */ jsx2(
42
+ "button",
43
+ {
44
+ className: `btn btn--${variant}`,
45
+ ...rest,
46
+ style: { backgroundImage: `url(/assets/paper.png)` },
47
+ children
48
+ }
49
+ );
50
+ };
51
+ var Button_default = Button;
52
+
53
+ // src/components/Carousel/Carousel.tsx
54
+ var Carousel_exports = {};
55
+ __export(Carousel_exports, {
56
+ default: () => Carousel_default
57
+ });
58
+ import { useState as useState2, useEffect } from "react";
59
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
60
+ var paperTexture = "/xp-components/assets/paper.png";
61
+ var Carousel = ({
62
+ items,
63
+ autoPlay = false,
64
+ interval = 3e3,
65
+ ...rest
66
+ }) => {
67
+ const [currentIndex, setCurrentIndex] = useState2(0);
68
+ const [touchStartX, setTouchStartX] = useState2(null);
69
+ const [touchEndX, setTouchEndX] = useState2(null);
70
+ const handleTouchStart = (e) => {
71
+ setTouchStartX(e.touches[0].clientX);
72
+ };
73
+ const handleTouchMove = (e) => {
74
+ setTouchEndX(e.touches[0].clientX);
75
+ };
76
+ const handleTouchEnd = () => {
77
+ if (touchStartX === null || touchEndX === null) return;
78
+ const delta = touchStartX - touchEndX;
79
+ if (delta > 50) {
80
+ setCurrentIndex((prev) => (prev + 1) % items.length);
81
+ } else if (delta < -50) {
82
+ setCurrentIndex((prev) => (prev - 1 + items.length) % items.length);
83
+ }
84
+ setTouchStartX(null);
85
+ setTouchEndX(null);
86
+ };
87
+ useEffect(() => {
88
+ if (!autoPlay) return;
89
+ const timer = setInterval(() => {
90
+ setCurrentIndex((prev) => (prev + 1) % items.length);
91
+ }, interval);
92
+ return () => clearInterval(timer);
93
+ }, [autoPlay, interval, items.length]);
94
+ return /* @__PURE__ */ jsxs2(
95
+ "div",
96
+ {
97
+ className: "carousel",
98
+ style: { backgroundImage: `url(${paperTexture})` },
99
+ children: [
100
+ /* @__PURE__ */ jsx3(
101
+ "div",
102
+ {
103
+ className: "carousel__container",
104
+ ...rest,
105
+ onTouchStart: handleTouchStart,
106
+ onTouchMove: handleTouchMove,
107
+ onTouchEnd: handleTouchEnd,
108
+ children: /* @__PURE__ */ jsx3(
109
+ "ul",
110
+ {
111
+ className: "carousel__list",
112
+ style: { transform: `translateX(-${currentIndex * 100}%)` },
113
+ children: items.map((item, index) => /* @__PURE__ */ jsxs2(
114
+ "li",
115
+ {
116
+ className: "carousel__item",
117
+ onClick: item.onClick,
118
+ "aria-hidden": index !== currentIndex,
119
+ children: [
120
+ item.image && /* @__PURE__ */ jsx3(
121
+ "img",
122
+ {
123
+ src: item.image,
124
+ alt: item.title ?? "",
125
+ className: "carousel__image",
126
+ style: {
127
+ backgroundImage: `url(${paperTexture})`,
128
+ ...item.imageStyle
129
+ }
130
+ }
131
+ ),
132
+ /* @__PURE__ */ jsxs2("div", { className: "carousel__content", children: [
133
+ item.title && /* @__PURE__ */ jsx3("h2", { className: "carousel__title", children: item.title }),
134
+ item.text && /* @__PURE__ */ jsx3("p", { className: "carousel__text", children: item.text })
135
+ ] })
136
+ ]
137
+ },
138
+ index
139
+ ))
140
+ }
141
+ )
142
+ }
143
+ ),
144
+ /* @__PURE__ */ jsx3("div", { className: "carousel__indicators", children: items.map((_, index) => /* @__PURE__ */ jsx3(
145
+ "button",
146
+ {
147
+ style: { backgroundImage: `url(${paperTexture})` },
148
+ className: `carousel__indicator ${index === currentIndex ? "active" : ""}`,
149
+ onClick: () => setCurrentIndex(index),
150
+ "aria-label": `Go to slide ${index + 1}`
151
+ },
152
+ index
153
+ )) })
154
+ ]
155
+ }
156
+ );
157
+ };
158
+ var Carousel_default = Carousel;
159
+
160
+ // src/components/Checkbox/Checkbox.tsx
161
+ var Checkbox_exports = {};
162
+ __export(Checkbox_exports, {
163
+ default: () => Checkbox_default
164
+ });
165
+ import React2 from "react";
166
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
167
+ var paperTexture2 = "/xp-components/assets/paper.png";
168
+ var Checkbox = ({ label, ...rest }) => {
169
+ const reactId = React2.useId();
170
+ const id = rest.id ?? reactId;
171
+ return /* @__PURE__ */ jsxs3("label", { htmlFor: id, className: "checkbox", children: [
172
+ /* @__PURE__ */ jsx4(
173
+ "input",
174
+ {
175
+ id,
176
+ type: "checkbox",
177
+ className: "checkbox_input",
178
+ ...rest,
179
+ style: { backgroundImage: `url(${paperTexture2})` }
180
+ }
181
+ ),
182
+ label
183
+ ] });
184
+ };
185
+ var Checkbox_default = Checkbox;
186
+
187
+ // src/components/Chips/Chips.tsx
188
+ var Chips_exports = {};
189
+ __export(Chips_exports, {
190
+ default: () => Chips_default
191
+ });
192
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
193
+ var paperTexture3 = "/xp-components/assets/paper.png";
194
+ var Chips = ({
195
+ children,
196
+ onRemove,
197
+ selected,
198
+ onClick,
199
+ ...rest
200
+ }) => {
201
+ return /* @__PURE__ */ jsxs4(
202
+ "div",
203
+ {
204
+ style: { backgroundImage: `url(${paperTexture3})` },
205
+ className: `chip${selected ? " selected" : ""}`,
206
+ role: onClick ? "button" : void 0,
207
+ tabIndex: onClick ? 0 : void 0,
208
+ onClick,
209
+ onKeyDown: (e) => onClick && e.key === "Enter" && onClick(),
210
+ ...rest,
211
+ children: [
212
+ /* @__PURE__ */ jsx5("span", { className: "chip-label", children }),
213
+ onRemove && /* @__PURE__ */ jsx5(
214
+ "button",
215
+ {
216
+ type: "button",
217
+ className: "chip-remove",
218
+ "aria-label": "Remove chip",
219
+ onClick: (e) => {
220
+ e.stopPropagation();
221
+ onRemove();
222
+ },
223
+ children: "\xD7"
224
+ }
225
+ )
226
+ ]
227
+ }
228
+ );
229
+ };
230
+ var Chips_default = Chips;
231
+
232
+ // src/components/Input/Input.tsx
233
+ var Input_exports = {};
234
+ __export(Input_exports, {
235
+ default: () => Input_default
236
+ });
237
+ import { useId } from "react";
238
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
239
+ var paperTexture4 = "/xp-components/assets/paper.png";
240
+ var Input = ({
241
+ label,
242
+ variant = "default",
243
+ id: propId,
244
+ type = "text",
245
+ className = "",
246
+ ...rest
247
+ }) => {
248
+ const reactId = useId();
249
+ const id = propId || reactId;
250
+ return /* @__PURE__ */ jsxs5("div", { className: `input__wrapper`, children: [
251
+ /* @__PURE__ */ jsx6(
252
+ "input",
253
+ {
254
+ id,
255
+ type,
256
+ className: `input input--${variant} ${className}`,
257
+ style: { backgroundImage: `url(${paperTexture4})` },
258
+ ...rest
259
+ }
260
+ ),
261
+ variant === "title" && label && /* @__PURE__ */ jsx6(
262
+ "label",
263
+ {
264
+ htmlFor: id,
265
+ className: "input__placeholder",
266
+ style: { backgroundImage: `url(${paperTexture4})` },
267
+ children: label
268
+ }
269
+ )
270
+ ] });
271
+ };
272
+ var Input_default = Input;
273
+
274
+ // src/components/Select/Select.tsx
275
+ var Select_exports = {};
276
+ __export(Select_exports, {
277
+ default: () => Select_default
278
+ });
279
+ import { useState as useState3, useRef, useEffect as useEffect2, useMemo } from "react";
280
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
281
+ var paperTexture5 = "/xp-components/assets/paper.png";
282
+ var Select = ({
283
+ label,
284
+ options,
285
+ value,
286
+ onChange,
287
+ ...rest
288
+ }) => {
289
+ const [open, setOpen] = useState3(false);
290
+ const [focusedIdx, setFocusedIdx] = useState3(null);
291
+ const rootRef = useRef(null);
292
+ const ulRef = useRef(null);
293
+ useEffect2(() => {
294
+ const handleClickOutside = (event) => {
295
+ if (rootRef.current && !rootRef.current.contains(event.target)) {
296
+ setOpen(false);
297
+ setFocusedIdx(null);
298
+ }
299
+ };
300
+ window.addEventListener("mousedown", handleClickOutside);
301
+ return () => {
302
+ window.removeEventListener("mousedown", handleClickOutside);
303
+ };
304
+ }, [open]);
305
+ const handleKeyDown = (e) => {
306
+ if (!open) return;
307
+ if (e.key === "ArrowDown") {
308
+ e.preventDefault();
309
+ setFocusedIdx(
310
+ (prev) => prev === null || prev === options.length - 1 ? 0 : prev + 1
311
+ );
312
+ } else if (e.key === "ArrowUp") {
313
+ e.preventDefault();
314
+ setFocusedIdx(
315
+ (prev) => prev === null || prev === 0 ? options.length - 1 : prev - 1
316
+ );
317
+ } else if (e.key === "Enter" && focusedIdx !== null) {
318
+ e.preventDefault();
319
+ const selectedOption = options[focusedIdx];
320
+ onChange == null ? void 0 : onChange(selectedOption.value);
321
+ setOpen(false);
322
+ setFocusedIdx(null);
323
+ } else if (e.key === "Escape") {
324
+ setOpen(false);
325
+ setFocusedIdx(null);
326
+ }
327
+ };
328
+ useEffect2(() => {
329
+ if (open) setFocusedIdx(0);
330
+ else setFocusedIdx(null);
331
+ }, [open]);
332
+ useEffect2(() => {
333
+ var _a;
334
+ if (open) (_a = ulRef.current) == null ? void 0 : _a.focus();
335
+ }, [open]);
336
+ const selectedLabel = useMemo(
337
+ () => {
338
+ var _a;
339
+ return ((_a = options.find((opt) => opt.value === value)) == null ? void 0 : _a.label) ?? label;
340
+ },
341
+ [options, value, label]
342
+ );
343
+ return /* @__PURE__ */ jsxs6("div", { className: "select", ref: rootRef, children: [
344
+ /* @__PURE__ */ jsx7(
345
+ "button",
346
+ {
347
+ ...rest,
348
+ className: "select__button",
349
+ style: { backgroundImage: `url(${paperTexture5})` },
350
+ onClick: () => setOpen((v) => !v),
351
+ type: "button",
352
+ "aria-haspopup": "listbox",
353
+ "aria-expanded": open,
354
+ "aria-controls": "select-list",
355
+ "aria-label": label,
356
+ onKeyDown: handleKeyDown,
357
+ children: selectedLabel
358
+ }
359
+ ),
360
+ open && /* @__PURE__ */ jsx7(
361
+ "ul",
362
+ {
363
+ className: "select__list",
364
+ style: { backgroundImage: `url(${paperTexture5})` },
365
+ role: "listbox",
366
+ id: "select-list",
367
+ onKeyDown: handleKeyDown,
368
+ ref: ulRef,
369
+ children: options.map((opt, idx) => /* @__PURE__ */ jsx7(
370
+ "li",
371
+ {
372
+ className: `select__item ${focusedIdx === idx ? "focused" : ""}`,
373
+ role: "option",
374
+ tabIndex: focusedIdx === idx ? 0 : -1,
375
+ "aria-selected": value === opt.value,
376
+ onClick: () => {
377
+ onChange == null ? void 0 : onChange(opt.value);
378
+ setOpen(false);
379
+ setFocusedIdx(null);
380
+ },
381
+ onMouseEnter: () => setFocusedIdx(idx),
382
+ onMouseLeave: () => setFocusedIdx(null),
383
+ children: opt.label
384
+ },
385
+ opt.value
386
+ ))
387
+ }
388
+ )
389
+ ] });
390
+ };
391
+ var Select_default = Select;
392
+
393
+ // src/components/Slider/Slider.tsx
394
+ var Slider_exports = {};
395
+ __export(Slider_exports, {
396
+ default: () => Slider_default
397
+ });
398
+ import React5, { useState as useState4 } from "react";
399
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
400
+ var paperTexture6 = "/xp-components/assets/paper.png";
401
+ var Slider = ({
402
+ min = 0,
403
+ max = 100,
404
+ step = 1,
405
+ value,
406
+ onChange,
407
+ showValue = true
408
+ }) => {
409
+ const [internalValue, setInternalValue] = useState4(value ?? min);
410
+ const handleChange = (e) => {
411
+ const newValue = Number(e.target.value);
412
+ setInternalValue(newValue);
413
+ onChange == null ? void 0 : onChange(newValue);
414
+ };
415
+ React5.useEffect(() => {
416
+ if (typeof value === "number") {
417
+ setInternalValue(value);
418
+ }
419
+ }, [value]);
420
+ return /* @__PURE__ */ jsxs7("div", { className: "slider", children: [
421
+ /* @__PURE__ */ jsx8(
422
+ "input",
423
+ {
424
+ style: { backgroundImage: `url(${paperTexture6})` },
425
+ type: "range",
426
+ min,
427
+ max,
428
+ step,
429
+ value: internalValue,
430
+ onChange: handleChange,
431
+ className: "slider__input"
432
+ }
433
+ ),
434
+ showValue && /* @__PURE__ */ jsx8(
435
+ "span",
436
+ {
437
+ style: { backgroundImage: ` url(${paperTexture6})` },
438
+ className: "slider__value",
439
+ children: internalValue
440
+ }
441
+ )
442
+ ] });
443
+ };
444
+ var Slider_default = Slider;
445
+
446
+ // src/components/Switch/Switch.tsx
447
+ var Switch_exports = {};
448
+ __export(Switch_exports, {
449
+ default: () => Switch_default
450
+ });
451
+ import React6 from "react";
452
+ import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
453
+ var paperTexture7 = "/xp-components/assets/paper.png";
454
+ var Switch = ({ label, disabled, ...rest }) => {
455
+ const reactId = React6.useId();
456
+ const id = rest.id ?? reactId;
457
+ return /* @__PURE__ */ jsxs8("label", { className: `switch${disabled ? " switch--disabled" : ""}`, children: [
458
+ /* @__PURE__ */ jsx9(
459
+ "input",
460
+ {
461
+ id,
462
+ type: "checkbox",
463
+ className: "switch__input",
464
+ disabled,
465
+ ...rest
466
+ }
467
+ ),
468
+ /* @__PURE__ */ jsx9(
469
+ "span",
470
+ {
471
+ className: "switch__slider",
472
+ style: { backgroundImage: `url(${paperTexture7})` }
473
+ }
474
+ ),
475
+ label && /* @__PURE__ */ jsx9("span", { className: "switch__label", children: label })
476
+ ] });
477
+ };
478
+ var Switch_default = Switch;
479
+
480
+ // src/components/Tag/Tag.tsx
481
+ var Tag_exports = {};
482
+ __export(Tag_exports, {
483
+ default: () => Tag_default
484
+ });
485
+ import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
486
+ var paperTexture8 = "/xp-components/assets/paper.png";
487
+ var Tag = ({
488
+ children,
489
+ variant = "default",
490
+ size = "md",
491
+ icon,
492
+ closable,
493
+ onClose,
494
+ className = "",
495
+ ...rest
496
+ }) => {
497
+ return /* @__PURE__ */ jsxs9(
498
+ "span",
499
+ {
500
+ ...rest,
501
+ className: `tag tag--${variant} tag--${size} ${className}`,
502
+ style: { backgroundImage: `url(${paperTexture8})` },
503
+ children: [
504
+ icon && /* @__PURE__ */ jsx10("span", { className: "tag__icon", children: icon }),
505
+ children,
506
+ closable && /* @__PURE__ */ jsx10(
507
+ "button",
508
+ {
509
+ type: "button",
510
+ onClick: onClose,
511
+ className: "tag__close",
512
+ "aria-label": "\uB2EB\uAE30",
513
+ children: "\xD7"
514
+ }
515
+ )
516
+ ]
517
+ }
518
+ );
519
+ };
520
+ var Tag_default = Tag;
23
521
  export {
24
- App_default as App
522
+ App_default as App,
523
+ Button_exports as Button,
524
+ Carousel_exports as Carousel,
525
+ Checkbox_exports as Checkbox,
526
+ Chips_exports as Chips,
527
+ Input_exports as Input,
528
+ Select_exports as Select,
529
+ Slider_exports as Slider,
530
+ Switch_exports as Switch,
531
+ Tag_exports as Tag
25
532
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ramong26/xp-components",
3
3
  "private": false,
4
- "version": "1.0.10",
4
+ "version": "1.0.13",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.mjs",
@@ -74,6 +74,7 @@
74
74
  "vitest": "^3.2.4"
75
75
  },
76
76
  "dependencies": {
77
+ "@ramong26/xp-components": "file:/home/runner/work/xp-components/xp-components/ramong26-xp-components-1.0.13.tgz",
77
78
  "@testing-library/react": "^16.3.0",
78
79
  "@testing-library/user-event": "^14.6.1"
79
80
  },