@webority/ui-react 0.2.0 → 0.3.0

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 (2) hide show
  1. package/dist/ui-react.js +140 -83
  2. package/package.json +3 -3
package/dist/ui-react.js CHANGED
@@ -233,13 +233,20 @@ var re = class extends HTMLElement {
233
233
  let e = Number(this.getAttribute("debounce"));
234
234
  return Number.isFinite(e) && e >= 0 ? e : 250;
235
235
  }
236
- _readOptions() {
237
- return this._optionsProp ? this._optionsProp : [...this.querySelectorAll(":scope > wui-option")].map((e) => ({
236
+ _snapshotDeclared() {
237
+ if (this._declared) return;
238
+ let e = [...this.querySelectorAll(":scope > wui-option")];
239
+ e.length && (this._declared = e.map((e) => ({
238
240
  value: e.getAttribute("value") ?? e.textContent.trim(),
239
- label: e.innerHTML
240
- }));
241
+ label: e.innerHTML,
242
+ selected: e.hasAttribute("selected")
243
+ })));
244
+ }
245
+ _readOptions() {
246
+ return this._optionsProp ? this._optionsProp : (this._snapshotDeclared(), this._declared || []);
241
247
  }
242
248
  render() {
249
+ this._snapshotDeclared();
243
250
  let e = this.getAttribute("placeholder") || "Search…";
244
251
  this.innerHTML = `
245
252
  <div class="search-select">
@@ -504,17 +511,24 @@ var re = class extends HTMLElement {
504
511
  get options() {
505
512
  return this._readOptions();
506
513
  }
507
- _readOptions() {
508
- return this._optionsProp ? this._optionsProp : [...this.querySelectorAll(":scope > wui-option")].map((e) => ({
514
+ _snapshotDeclared() {
515
+ if (this._declared) return;
516
+ let e = [...this.querySelectorAll(":scope > wui-option")];
517
+ e.length && (this._declared = e.map((e) => ({
509
518
  value: e.getAttribute("value") ?? e.textContent.trim(),
510
- label: e.innerHTML
511
- }));
519
+ label: e.innerHTML,
520
+ selected: e.hasAttribute("selected")
521
+ })));
522
+ }
523
+ _readOptions() {
524
+ return this._optionsProp ? this._optionsProp : (this._snapshotDeclared(), this._declared || []);
512
525
  }
513
526
  _labelFor(e) {
514
527
  let t = this._readOptions().find((t) => String(t.value) === String(e));
515
528
  return t ? t.label : e;
516
529
  }
517
530
  render() {
531
+ this._snapshotDeclared();
518
532
  let e = this.hasAttribute("searchable"), t = this.getAttribute("search-placeholder") || "Search…";
519
533
  this._internals?.setFormValue(this._values.join(",")), this.innerHTML = `
520
534
  <div class="search-select">
@@ -1951,14 +1965,20 @@ var re = class extends HTMLElement {
1951
1965
  get options() {
1952
1966
  return this._readOptions();
1953
1967
  }
1954
- _readOptions() {
1955
- return this._optionsProp ? this._optionsProp : [...this.querySelectorAll(":scope > wui-option")].map((e) => ({
1968
+ _snapshotDeclared() {
1969
+ if (this._declared) return;
1970
+ let e = [...this.querySelectorAll(":scope > wui-option")];
1971
+ e.length && (this._declared = e.map((e) => ({
1956
1972
  value: e.getAttribute("value") ?? e.textContent.trim(),
1957
1973
  label: e.innerHTML,
1958
1974
  selected: e.hasAttribute("selected")
1959
- }));
1975
+ })));
1976
+ }
1977
+ _readOptions() {
1978
+ return this._optionsProp ? this._optionsProp : (this._snapshotDeclared(), this._declared || []);
1960
1979
  }
1961
1980
  render() {
1981
+ this._snapshotDeclared();
1962
1982
  let e = this._readOptions(), t = this.hasAttribute("searchable"), n = this.getAttribute("placeholder") || "Select...", r = this.getAttribute("search-placeholder") || "Search...", i = e.find((e) => String(e.value) === String(this._value)) || e.find((e) => e.selected);
1963
1983
  i && (this._value = String(i.value)), this._internals?.setFormValue(this._value);
1964
1984
  let a = e.map((e) => {
@@ -2106,6 +2126,7 @@ function me({ value: e, onChange: r, options: i, loadOptions: a, placeholder: s
2106
2126
  children: [p, g && /* @__PURE__ */ t(U, {})]
2107
2127
  }),
2108
2128
  /* @__PURE__ */ t("wui-autocomplete", {
2129
+ id: f,
2109
2130
  ref: v,
2110
2131
  name: f,
2111
2132
  placeholder: s,
@@ -2143,6 +2164,8 @@ function ge({ name: e, src: n, className: r = "" }) {
2143
2164
  })
2144
2165
  }) : /* @__PURE__ */ t("span", {
2145
2166
  className: i,
2167
+ role: "img",
2168
+ "aria-label": e,
2146
2169
  children: he(e)
2147
2170
  });
2148
2171
  }
@@ -2215,13 +2238,22 @@ function ye({ title: r, titleClassName: i = "", header: a, headerExtra: o, heade
2215
2238
  }
2216
2239
  //#endregion
2217
2240
  //#region src/components/AppCheckbox.jsx
2218
- var be = i(function({ label: e, className: n = "", ...r }, i) {
2219
- return /* @__PURE__ */ t(m.Check, {
2220
- type: "checkbox",
2221
- label: e,
2222
- className: n || void 0,
2223
- ref: i,
2224
- ...r
2241
+ var be = i(function({ label: e, id: r, name: i, className: a = "", ...o }, c) {
2242
+ let l = s(), u = r || i || l;
2243
+ return /* @__PURE__ */ n("div", {
2244
+ className: `form-check${a ? ` ${a}` : ""}`,
2245
+ children: [/* @__PURE__ */ t("input", {
2246
+ type: "checkbox",
2247
+ className: "form-check-input",
2248
+ id: u,
2249
+ name: i,
2250
+ ref: c,
2251
+ ...o
2252
+ }), e != null && /* @__PURE__ */ t("label", {
2253
+ className: "form-check-label",
2254
+ htmlFor: u,
2255
+ children: e
2256
+ })]
2225
2257
  });
2226
2258
  });
2227
2259
  //#endregion
@@ -2311,7 +2343,7 @@ function Se({ name: r, multiple: i = !1, value: a, checked: o, onChange: s, icon
2311
2343
  className: "struct-card-title",
2312
2344
  children: m
2313
2345
  }), h && /* @__PURE__ */ t("span", {
2314
- className: "struct-card-description",
2346
+ className: "struct-card-desc",
2315
2347
  children: h
2316
2348
  })] })
2317
2349
  }),
@@ -2328,15 +2360,16 @@ function Se({ name: r, multiple: i = !1, value: a, checked: o, onChange: s, icon
2328
2360
  }
2329
2361
  //#endregion
2330
2362
  //#region src/components/AppChoiceChip.jsx
2331
- function Ce({ multiple: e = !0, label: r, name: i, checked: a, onChange: o, children: s, className: c = "" }) {
2363
+ function Ce({ multiple: e = !0, label: r, name: i, value: a, checked: o, onChange: s, children: c, className: l = "" }) {
2332
2364
  return /* @__PURE__ */ n("label", {
2333
- className: `choice-chip${a ? " checked" : ""}${c ? ` ${c}` : ""}`,
2365
+ className: `choice-chip${o ? " checked" : ""}${l ? ` ${l}` : ""}`,
2334
2366
  children: [/* @__PURE__ */ t("input", {
2335
2367
  type: e ? "checkbox" : "radio",
2336
2368
  name: i,
2337
- checked: a,
2338
- onChange: o
2339
- }), r ?? s]
2369
+ value: a,
2370
+ checked: o,
2371
+ onChange: s
2372
+ }), /* @__PURE__ */ t("span", { children: r ?? c })]
2340
2373
  });
2341
2374
  }
2342
2375
  //#endregion
@@ -2401,6 +2434,7 @@ var K = i(function({ label: e, required: r = !1, error: i, hint: a, help: o, hel
2401
2434
  type: E,
2402
2435
  className: D,
2403
2436
  disabled: y,
2437
+ required: r,
2404
2438
  "aria-invalid": i ? "true" : "false",
2405
2439
  ref: x,
2406
2440
  ...b
@@ -3012,28 +3046,29 @@ function X({ rows: e = 4, cols: n = 5 }) {
3012
3046
  }
3013
3047
  //#endregion
3014
3048
  //#region src/components/AppSelectMini.jsx
3015
- function Z({ value: e, onChange: n, options: r = [], placeholder: i = "Select...", ariaLabel: a, id: s, disabled: c }) {
3016
- let u = l(null);
3049
+ function Z({ value: e, onChange: n, options: r = [], placeholder: i = "Select...", name: a, ariaLabel: s, id: c, disabled: u }) {
3050
+ let d = l(null);
3017
3051
  return o(() => {
3018
- u.current && (u.current.options = r.map((e) => ({
3052
+ d.current && (d.current.options = r.map((e) => ({
3019
3053
  value: e.value,
3020
3054
  label: e.label ?? e.text ?? ""
3021
3055
  })));
3022
3056
  }, [r]), o(() => {
3023
- let t = u.current;
3057
+ let t = d.current;
3024
3058
  t && String(t.value ?? "") !== String(e ?? "") && (t.value = e ?? "");
3025
3059
  }, [e]), o(() => {
3026
- let e = u.current;
3060
+ let e = d.current;
3027
3061
  if (!e) return;
3028
3062
  let t = () => n?.(e.value);
3029
3063
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
3030
3064
  }, [n]), /* @__PURE__ */ t("wui-select", {
3031
- ref: u,
3065
+ ref: d,
3066
+ name: a,
3032
3067
  compact: "",
3033
- id: s,
3068
+ id: c,
3034
3069
  placeholder: i,
3035
- "aria-label": a,
3036
- disabled: c ? "" : void 0
3070
+ "aria-label": s,
3071
+ disabled: u ? "" : void 0
3037
3072
  });
3038
3073
  }
3039
3074
  //#endregion
@@ -3503,54 +3538,55 @@ function Je(e) {
3503
3538
  }
3504
3539
  //#endregion
3505
3540
  //#region src/components/AppFilePicker.jsx
3506
- function Ye({ label: e, value: r, onPick: i, accept: a = ".jpg,.jpeg,.png", required: c, error: d }) {
3507
- let [f, p] = u(null), [m, h] = u(!1), g = l(null), _ = s();
3541
+ function Ye({ label: e, value: r, name: i, onPick: a, accept: c = ".jpg,.jpeg,.png", required: d, error: f }) {
3542
+ let [p, m] = u(null), [h, g] = u(!1), _ = l(null), v = s(), y = i || v;
3508
3543
  o(() => {
3509
3544
  if (r instanceof File) {
3510
3545
  let e = URL.createObjectURL(r);
3511
- return p(e), () => URL.revokeObjectURL(e);
3546
+ return m(e), () => URL.revokeObjectURL(e);
3512
3547
  }
3513
- p(null);
3548
+ m(null);
3514
3549
  }, [r]);
3515
- let v = r?.url || f, y = (e) => {
3550
+ let b = r?.url || p, x = (e) => {
3516
3551
  let t = Ke(e);
3517
- return t ? ($(t, "error"), !1) : (i(e), !0);
3518
- }, b = (e) => {
3552
+ return t ? ($(t, "error"), !1) : (a(e), !0);
3553
+ }, S = (e) => {
3519
3554
  let t = e.target.files?.[0] || null;
3520
- t && (y(t) || (e.target.value = ""));
3521
- }, x = (e) => {
3522
- e.preventDefault(), h(!1);
3555
+ t && (x(t) || (e.target.value = ""));
3556
+ }, C = (e) => {
3557
+ e.preventDefault(), g(!1);
3523
3558
  let t = e.dataTransfer.files?.[0];
3524
- t && y(t);
3525
- }, S = () => g.current?.click(), C = /* @__PURE__ */ t("input", {
3526
- id: _,
3527
- ref: g,
3559
+ t && x(t);
3560
+ }, w = () => _.current?.click(), T = /* @__PURE__ */ t("input", {
3561
+ id: y,
3562
+ name: i,
3563
+ ref: _,
3528
3564
  type: "file",
3529
- accept: a,
3530
- className: "d-none",
3565
+ accept: c,
3566
+ hidden: !0,
3531
3567
  onClick: (e) => {
3532
3568
  e.currentTarget.value = "";
3533
3569
  },
3534
- onChange: b
3570
+ onChange: S
3535
3571
  });
3536
3572
  return /* @__PURE__ */ n("div", {
3537
3573
  className: "field",
3538
3574
  children: [
3539
3575
  /* @__PURE__ */ n("label", {
3540
3576
  className: "label",
3541
- htmlFor: _,
3542
- children: [e, c && /* @__PURE__ */ t(U, {})]
3577
+ htmlFor: y,
3578
+ children: [e, d && /* @__PURE__ */ t(U, {})]
3543
3579
  }),
3544
- v ? /* @__PURE__ */ n("div", {
3545
- className: `file-preview${d ? " error" : ""}`,
3580
+ b ? /* @__PURE__ */ n("div", {
3581
+ className: `file-preview${f ? " error" : ""}`,
3546
3582
  children: [
3547
3583
  /* @__PURE__ */ n("button", {
3548
3584
  type: "button",
3549
3585
  className: "file-preview-open",
3550
3586
  "aria-label": `Change ${e}`,
3551
- onClick: S,
3587
+ onClick: w,
3552
3588
  children: [/* @__PURE__ */ t("img", {
3553
- src: v,
3589
+ src: b,
3554
3590
  alt: `${e} preview`,
3555
3591
  className: "file-preview-img"
3556
3592
  }), /* @__PURE__ */ t("span", {
@@ -3570,26 +3606,26 @@ function Ye({ label: e, value: r, onPick: i, accept: a = ".jpg,.jpeg,.png", requ
3570
3606
  className: "file-preview-remove",
3571
3607
  "aria-label": `Remove ${e}`,
3572
3608
  title: "Remove image",
3573
- onClick: () => i(null),
3609
+ onClick: () => a(null),
3574
3610
  children: /* @__PURE__ */ t(A, {
3575
3611
  name: "x",
3576
3612
  size: 16,
3577
3613
  variant: "Linear"
3578
3614
  })
3579
3615
  }),
3580
- C
3616
+ T
3581
3617
  ]
3582
3618
  }) : /* @__PURE__ */ n("div", {
3583
- className: `file-input file-input-tall${m ? " dragging" : ""}${d ? " error" : ""}`,
3619
+ className: `file-input file-input-tall${h ? " dragging" : ""}${f ? " error" : ""}`,
3584
3620
  onDragOver: (e) => {
3585
- e.preventDefault(), m || h(!0);
3621
+ e.preventDefault(), h || g(!0);
3586
3622
  },
3587
3623
  onDragLeave: (e) => {
3588
- e.preventDefault(), h(!1);
3624
+ e.preventDefault(), g(!1);
3589
3625
  },
3590
- onDrop: x,
3626
+ onDrop: C,
3591
3627
  children: [/* @__PURE__ */ n("label", {
3592
- htmlFor: _,
3628
+ htmlFor: y,
3593
3629
  className: "file-input-zone-label",
3594
3630
  children: [
3595
3631
  /* @__PURE__ */ t("span", {
@@ -3612,11 +3648,11 @@ function Ye({ label: e, value: r, onPick: i, accept: a = ".jpg,.jpeg,.png", requ
3612
3648
  children: "JPG, JPEG or PNG · up to 5 MB"
3613
3649
  })
3614
3650
  ]
3615
- }), C]
3651
+ }), T]
3616
3652
  }),
3617
- d && /* @__PURE__ */ t("div", {
3653
+ f && /* @__PURE__ */ t("div", {
3618
3654
  className: "field-error",
3619
- children: d
3655
+ children: f
3620
3656
  })
3621
3657
  ]
3622
3658
  });
@@ -3705,6 +3741,7 @@ function Ze({ values: e, onChange: r, options: i, placeholder: a = "Select…",
3705
3741
  children: [f, h && /* @__PURE__ */ t(U, {})]
3706
3742
  }),
3707
3743
  /* @__PURE__ */ t("wui-multiselect", {
3744
+ id: d,
3708
3745
  ref: _,
3709
3746
  name: d,
3710
3747
  placeholder: a,
@@ -3775,13 +3812,22 @@ function $e({ value: e, onChange: r, country: i, disabled: a = !1, name: s, labe
3775
3812
  }
3776
3813
  //#endregion
3777
3814
  //#region src/components/AppRadio.jsx
3778
- var et = i(function({ label: e, className: n = "", ...r }, i) {
3779
- return /* @__PURE__ */ t(m.Check, {
3780
- type: "radio",
3781
- label: e,
3782
- className: n || void 0,
3783
- ref: i,
3784
- ...r
3815
+ var et = i(function({ label: e, id: r, name: i, className: a = "", ...o }, c) {
3816
+ let l = s(), u = r || i || l;
3817
+ return /* @__PURE__ */ n("div", {
3818
+ className: `form-check${a ? ` ${a}` : ""}`,
3819
+ children: [/* @__PURE__ */ t("input", {
3820
+ type: "radio",
3821
+ className: "form-check-input",
3822
+ id: u,
3823
+ name: i,
3824
+ ref: c,
3825
+ ...o
3826
+ }), e != null && /* @__PURE__ */ t("label", {
3827
+ className: "form-check-label",
3828
+ htmlFor: u,
3829
+ children: e
3830
+ })]
3785
3831
  });
3786
3832
  });
3787
3833
  //#endregion
@@ -3790,17 +3836,18 @@ function tt({ value: e, onValueChange: r, placeholder: i, ariaLabel: a, iconSize
3790
3836
  return /* @__PURE__ */ n("div", {
3791
3837
  className: [
3792
3838
  "search-wrap",
3793
- "search-field",
3794
3839
  e ? "has-value" : "",
3795
3840
  s
3796
3841
  ].filter(Boolean).join(" "),
3797
3842
  children: [
3798
3843
  /* @__PURE__ */ t(A, {
3799
3844
  name: "search",
3800
- size: o
3845
+ size: o,
3846
+ className: "search-icon"
3801
3847
  }),
3802
3848
  /* @__PURE__ */ t(m.Control, {
3803
- className: "search-input w-100",
3849
+ type: "search",
3850
+ className: "input search-input",
3804
3851
  placeholder: i,
3805
3852
  value: e,
3806
3853
  onChange: (e) => r(e.target.value),
@@ -3843,6 +3890,7 @@ function rt({ value: e, onChange: r, options: i = [], placeholder: a = "Select..
3843
3890
  let x = /* @__PURE__ */ t("wui-select", {
3844
3891
  ref: b,
3845
3892
  id: _ || v,
3893
+ name: v,
3846
3894
  placeholder: a,
3847
3895
  "search-placeholder": s,
3848
3896
  searchable: c ? "" : void 0,
@@ -3941,13 +3989,22 @@ function ot({ label: e, tone: n = "", className: r = "" }) {
3941
3989
  }
3942
3990
  //#endregion
3943
3991
  //#region src/components/AppSwitch.jsx
3944
- var st = i(function({ label: e, className: n = "", ...r }, i) {
3945
- return /* @__PURE__ */ t(m.Check, {
3946
- type: "switch",
3947
- "aria-label": e,
3948
- className: n || void 0,
3949
- ref: i,
3950
- ...r
3992
+ var st = i(function({ label: e, id: r, name: i, className: a = "", ...o }, c) {
3993
+ let l = s(), u = r || i || l;
3994
+ return /* @__PURE__ */ n("div", {
3995
+ className: `form-check form-switch${a ? ` ${a}` : ""}`,
3996
+ children: [/* @__PURE__ */ t("input", {
3997
+ type: "checkbox",
3998
+ className: "form-check-input",
3999
+ id: u,
4000
+ name: i,
4001
+ ref: c,
4002
+ ...o
4003
+ }), e != null && /* @__PURE__ */ t("label", {
4004
+ className: "form-check-label",
4005
+ htmlFor: u,
4006
+ children: e
4007
+ })]
3951
4008
  });
3952
4009
  });
3953
4010
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/ui-react",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Webority shared React component library — App* primitives on react-bootstrap + the @webority/theme design system.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -28,8 +28,8 @@
28
28
  "iconsax-react": "^0.0.8",
29
29
  "react-phone-number-input": "^3.4.17",
30
30
  "react-toastify": "^11.1.0",
31
- "@webority/theme": "^0.2.0",
32
- "@webority/ui-elements": "^0.2.0"
31
+ "@webority/theme": "^0.3.0",
32
+ "@webority/ui-elements": "^0.3.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "bootstrap": "5.3.3",