@variamosple/variamos-components 0.4.0 → 0.4.1

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.
@@ -1,96 +1,101 @@
1
1
  import { jsxs as l, jsx as e } from "react/jsx-runtime";
2
- import { useState as a, useEffect as N } from "react";
3
- import { Modal as o, Form as t, Alert as k, Button as y } from "react-bootstrap";
4
- const G = ({
5
- show: i,
6
- onHide: d,
7
- onSubmit: C,
8
- categories: n,
9
- isSubmitting: c,
10
- errorMessage: s
2
+ import { useState as o, useEffect as x } from "react";
3
+ import { Modal as i, Form as r, Alert as k, Button as B } from "react-bootstrap";
4
+ import { bugFormErrors as F, TITLE_MAX_LENGTH as D } from "./bugFormErrors.js";
5
+ const A = ({
6
+ show: c,
7
+ onHide: p,
8
+ onSubmit: N,
9
+ categories: s,
10
+ isSubmitting: u,
11
+ errorMessage: h
11
12
  }) => {
12
- const [u, h] = a(""), [p, m] = a(""), [g, b] = a(""), [F, f] = a(null), [x, v] = a(!1);
13
- N(() => {
14
- i && (h(""), m(""), b(n[0] || "Other"), f(null), v(!1));
15
- }, [i, n]);
16
- const B = (r) => {
17
- if (r.preventDefault(), r.currentTarget.checkValidity() === !1) {
18
- r.stopPropagation(), v(!0);
13
+ const [n, m] = o(""), [a, b] = o(""), [g, v] = o(""), [I, f] = o(null), [L, C] = o(!1), d = L ? F({ title: n, description: a }) : {};
14
+ x(() => {
15
+ c && (m(""), b(""), v(s[0] || "Other"), f(null), C(!1));
16
+ }, [c, s]);
17
+ const T = (t) => {
18
+ t.preventDefault(), C(!0);
19
+ const y = F({ title: n, description: a });
20
+ if (y.title || y.description) {
21
+ t.stopPropagation();
19
22
  return;
20
23
  }
21
- C({ title: u, description: p, category: g }, F ?? void 0);
24
+ N({ title: n, description: a, category: g }, I ?? void 0);
22
25
  };
23
26
  return /* @__PURE__ */ l(
24
- o,
27
+ i,
25
28
  {
26
- show: i,
27
- onHide: d,
29
+ show: c,
30
+ onHide: p,
28
31
  backdrop: "static",
29
32
  keyboard: !1,
30
33
  centered: !0,
31
34
  children: [
32
- /* @__PURE__ */ e(o.Header, { closeButton: !0, children: /* @__PURE__ */ e(o.Title, { children: "Report a New Bug" }) }),
33
- /* @__PURE__ */ l(t, { noValidate: !0, validated: x, onSubmit: B, children: [
34
- /* @__PURE__ */ l(o.Body, { children: [
35
- s ? /* @__PURE__ */ e(k, { variant: "danger", role: "alert", children: s }) : null,
36
- /* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugTitle", children: [
37
- /* @__PURE__ */ e(t.Label, { children: "Title *" }),
35
+ /* @__PURE__ */ e(i.Header, { closeButton: !0, children: /* @__PURE__ */ e(i.Title, { children: "Report a New Bug" }) }),
36
+ /* @__PURE__ */ l(r, { noValidate: !0, onSubmit: T, children: [
37
+ /* @__PURE__ */ l(i.Body, { children: [
38
+ h ? /* @__PURE__ */ e(k, { variant: "danger", role: "alert", children: h }) : null,
39
+ /* @__PURE__ */ l(r.Group, { className: "mb-3", controlId: "bugTitle", children: [
40
+ /* @__PURE__ */ e(r.Label, { children: "Title *" }),
38
41
  /* @__PURE__ */ e(
39
- t.Control,
42
+ r.Control,
40
43
  {
41
44
  required: !0,
42
45
  type: "text",
43
46
  placeholder: "e.g. Build error on auth routes",
44
- value: u,
45
- onChange: (r) => h(r.target.value),
46
- maxLength: 100
47
+ value: n,
48
+ onChange: (t) => m(t.target.value),
49
+ maxLength: D,
50
+ isInvalid: !!d.title
47
51
  }
48
52
  ),
49
- /* @__PURE__ */ e(t.Control.Feedback, { type: "invalid", children: "Title is required (max 100 characters)" })
53
+ /* @__PURE__ */ e(r.Control.Feedback, { type: "invalid", children: d.title })
50
54
  ] }),
51
- /* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugDescription", children: [
52
- /* @__PURE__ */ e(t.Label, { children: "Description *" }),
55
+ /* @__PURE__ */ l(r.Group, { className: "mb-3", controlId: "bugDescription", children: [
56
+ /* @__PURE__ */ e(r.Label, { children: "Description *" }),
53
57
  /* @__PURE__ */ e(
54
- t.Control,
58
+ r.Control,
55
59
  {
56
60
  required: !0,
57
61
  as: "textarea",
58
62
  rows: 4,
59
63
  placeholder: "Describe step-by-step how to reproduce the bug...",
60
- value: p,
61
- onChange: (r) => m(r.target.value)
64
+ value: a,
65
+ onChange: (t) => b(t.target.value),
66
+ isInvalid: !!d.description
62
67
  }
63
68
  ),
64
- /* @__PURE__ */ e(t.Control.Feedback, { type: "invalid", children: "Description is required" })
69
+ /* @__PURE__ */ e(r.Control.Feedback, { type: "invalid", children: d.description })
65
70
  ] }),
66
- /* @__PURE__ */ e("div", { className: "row", children: /* @__PURE__ */ e("div", { className: "col-md-12", children: /* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugCategory", children: [
67
- /* @__PURE__ */ e(t.Label, { children: "Category *" }),
71
+ /* @__PURE__ */ e("div", { className: "row", children: /* @__PURE__ */ e("div", { className: "col-md-12", children: /* @__PURE__ */ l(r.Group, { className: "mb-3", controlId: "bugCategory", children: [
72
+ /* @__PURE__ */ e(r.Label, { children: "Category *" }),
68
73
  /* @__PURE__ */ e(
69
- t.Select,
74
+ r.Select,
70
75
  {
71
76
  required: !0,
72
77
  value: g,
73
- onChange: (r) => b(r.target.value),
74
- children: n.map((r) => /* @__PURE__ */ e("option", { value: r, children: r }, r))
78
+ onChange: (t) => v(t.target.value),
79
+ children: s.map((t) => /* @__PURE__ */ e("option", { value: t, children: t }, t))
75
80
  }
76
81
  )
77
82
  ] }) }) }),
78
- /* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugFile", children: [
79
- /* @__PURE__ */ e(t.Label, { children: "Attachment (Optional)" }),
83
+ /* @__PURE__ */ l(r.Group, { className: "mb-3", controlId: "bugFile", children: [
84
+ /* @__PURE__ */ e(r.Label, { children: "Attachment (Optional)" }),
80
85
  /* @__PURE__ */ e(
81
- t.Control,
86
+ r.Control,
82
87
  {
83
88
  type: "file",
84
- onChange: (r) => {
85
- r.target.files && r.target.files.length > 0 && f(r.target.files[0]);
89
+ onChange: (t) => {
90
+ t.target.files && t.target.files.length > 0 && f(t.target.files[0]);
86
91
  }
87
92
  }
88
93
  )
89
94
  ] })
90
95
  ] }),
91
- /* @__PURE__ */ l(o.Footer, { children: [
92
- /* @__PURE__ */ e(y, { variant: "secondary", onClick: d, disabled: c, children: "Cancel" }),
93
- /* @__PURE__ */ e(y, { variant: "primary", type: "submit", disabled: c, children: c ? "Creating..." : "Report Bug" })
96
+ /* @__PURE__ */ l(i.Footer, { children: [
97
+ /* @__PURE__ */ e(B, { variant: "secondary", onClick: p, disabled: u, children: "Cancel" }),
98
+ /* @__PURE__ */ e(B, { variant: "primary", type: "submit", disabled: u, children: u ? "Creating..." : "Report Bug" })
94
99
  ] })
95
100
  ] })
96
101
  ]
@@ -98,5 +103,5 @@ const G = ({
98
103
  );
99
104
  };
100
105
  export {
101
- G as BugFormModal
106
+ A as BugFormModal
102
107
  };
@@ -0,0 +1,11 @@
1
+ export interface BugFormFields {
2
+ title: string;
3
+ description: string;
4
+ }
5
+ export declare const TITLE_MAX_LENGTH = 100;
6
+ /**
7
+ * The message of each invalid field, or nothing for a valid one. The form
8
+ * shows them only after a submission attempt, and writes no message text
9
+ * otherwise, so that no style of the host application can show it early.
10
+ */
11
+ export declare function bugFormErrors({ title, description, }: BugFormFields): Partial<Record<keyof BugFormFields, string>>;
@@ -0,0 +1,12 @@
1
+ const t = 100;
2
+ function T({
3
+ title: i,
4
+ description: e
5
+ }) {
6
+ const r = {};
7
+ return (i.trim() === "" || i.length > 100) && (r.title = "Title is required (max 100 characters)"), e.trim() === "" && (r.description = "Description is required"), r;
8
+ }
9
+ export {
10
+ t as TITLE_MAX_LENGTH,
11
+ T as bugFormErrors
12
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@variamosple/variamos-components",
3
3
  "private": false,
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
7
7
  "types": "dist/main.d.ts",