|
1 | | -import { jsx as r, jsxs as d } from "react/jsx-runtime"; |
| 1 | +import { jsx as l, jsxs as f } from "react/jsx-runtime"; |
2 | 2 | import "react"; |
3 | | -import g from "classnames"; |
4 | | -import o from "prop-types"; |
5 | | -import { Field as p } from "react-final-form"; |
6 | | -import { DENSITY as c } from "../../types.mjs"; |
| 3 | +import _ from "classnames"; |
| 4 | +import r from "prop-types"; |
| 5 | +import { Field as h } from "react-final-form"; |
| 6 | +import N from "../Tip/Tip.mjs"; |
| 7 | +import { DENSITY as x } from "../../types.mjs"; |
7 | 8 | /* empty css */ |
8 | | -const n = ({ density: l = "", label: t = "", name: e, onChange: i = () => { |
9 | | -}, ...s }) => { |
10 | | - const f = g( |
| 9 | +const b = ({ |
| 10 | + className: a = "", |
| 11 | + density: m = "", |
| 12 | + label: t = "", |
| 13 | + labelTip: o = "", |
| 14 | + name: e, |
| 15 | + readOnly: c = !1, |
| 16 | + onChange: s = () => { |
| 17 | + }, |
| 18 | + ...d |
| 19 | +}) => { |
| 20 | + const p = _( |
| 21 | + "test", |
| 22 | + "form-field-toggle", |
11 | 23 | "form-field__wrapper", |
12 | | - l && `form-field__wrapper-${l}` |
| 24 | + m && `form-field__wrapper-${m}`, |
| 25 | + (t || o) && "form-field-toggle_has-label", |
| 26 | + a |
13 | 27 | ); |
14 | | - return /* @__PURE__ */ r(p, { name: e, value: s.value, type: "checkbox", children: ({ input: a }) => /* @__PURE__ */ d( |
15 | | - "label", |
| 28 | + return /* @__PURE__ */ l(h, { name: e, value: d.value, type: "checkbox", children: ({ input: i }) => /* @__PURE__ */ f( |
| 29 | + "div", |
16 | 30 | { |
17 | | - className: "form-field-toggle", |
| 31 | + className: p, |
18 | 32 | "data-testid": e ? `${e}-form-field-toggle` : "form-field-toggle", |
19 | 33 | children: [ |
20 | | - t && /* @__PURE__ */ r("div", { className: "form-field__label", children: t }), |
21 | | - /* @__PURE__ */ r( |
22 | | - "input", |
23 | | - { |
24 | | - "data-testid": e ? `${e}-form-toggle` : "form-toggle", |
25 | | - id: e, |
26 | | - ...a, |
27 | | - ...s, |
28 | | - onChange: (m) => { |
29 | | - i && i(m), a.onChange(m); |
30 | | - }, |
31 | | - type: "checkbox" |
32 | | - } |
33 | | - ), |
34 | | - /* @__PURE__ */ r("div", { className: f, children: /* @__PURE__ */ r("span", { className: "form-field-toggle__switch" }) }) |
| 34 | + (t || o) && /* @__PURE__ */ f("label", { htmlFor: e, className: "form-field-toggle__label", children: [ |
| 35 | + t, |
| 36 | + o && /* @__PURE__ */ l(N, { text: o }) |
| 37 | + ] }), |
| 38 | + /* @__PURE__ */ f("label", { htmlFor: e, className: "form-field-toggle__toggle-wrapper", children: [ |
| 39 | + /* @__PURE__ */ l( |
| 40 | + "input", |
| 41 | + { |
| 42 | + type: "checkbox", |
| 43 | + "data-testid": e ? `${e}-form-toggle` : "form-toggle", |
| 44 | + id: e, |
| 45 | + ...i, |
| 46 | + ...d, |
| 47 | + value: String(i.checked), |
| 48 | + disabled: c, |
| 49 | + onChange: (g) => { |
| 50 | + s == null || s(g), i.onChange(g); |
| 51 | + } |
| 52 | + } |
| 53 | + ), |
| 54 | + /* @__PURE__ */ l("span", { className: "form-field-toggle__switch" }) |
| 55 | + ] }) |
35 | 56 | ] |
36 | 57 | } |
37 | 58 | ) }); |
38 | 59 | }; |
39 | | -n.propTypes = { |
40 | | - density: c, |
41 | | - label: o.string, |
42 | | - name: o.string.isRequired, |
43 | | - onChange: o.func |
| 60 | +b.propTypes = { |
| 61 | + className: r.string, |
| 62 | + density: x, |
| 63 | + label: r.string, |
| 64 | + labelTip: r.string, |
| 65 | + name: r.string.isRequired, |
| 66 | + readOnly: r.bool, |
| 67 | + onChange: r.func |
44 | 68 | }; |
45 | 69 | export { |
46 | | - n as default |
| 70 | + b as default |
47 | 71 | }; |
48 | 72 | //# sourceMappingURL=FormToggle.mjs.map |
0 commit comments