@nolwenture/formik-jsonschema-form 1.3.1 → 1.3.3

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.
@@ -78,12 +78,13 @@ const SelectedBox = styled_components_1.default.div `
78
78
  background: ${(props) => props.theme.color.background.default};
79
79
  border: ${(props) => props.theme.strokeWidth.thin} solid
80
80
  ${(props) => props.theme.color.border.default};
81
- padding: 0 0.05rem;
82
81
  font-family: ${(props) => props.theme.typography.fontFamily.base};
83
82
  font-size: ${(props) => props.theme.typography.size.small};
84
83
  display: flex;
85
84
  justify-content: center;
86
85
  align-items: start;
86
+ width: 1rem;
87
+ height: 1rem;
87
88
  `;
88
89
  const NotSelectedBox = styled_components_1.default.div `
89
90
  background: ${(props) => props.theme.color.background.default};
@@ -91,8 +92,9 @@ const NotSelectedBox = styled_components_1.default.div `
91
92
  ${(props) => props.theme.color.border.default};
92
93
  border-radius: ${(props) => props.theme.borderRadius.none};
93
94
  display: inline-flex;
94
- width: 0.85rem;
95
- height: 0.85rem;
95
+ width: 1rem;
96
+ height: 1rem;
97
+ min-width: 1rem;
96
98
  `;
97
99
  exports.SelectedIcon = (0, styled_components_1.default)(fa_1.FaCheck) `
98
100
  color: ${(props) => props.theme.color.text.default};
@@ -124,11 +126,7 @@ const BooleanFieldValue = ({ name, className, value, label, }) => {
124
126
  return ((0, jsx_runtime_1.jsx)("div", { className: className, children: value === true ? ((0, jsx_runtime_1.jsxs)(Selected, { children: [(0, jsx_runtime_1.jsx)(SelectedBox, { children: (0, jsx_runtime_1.jsx)(exports.SelectedIcon, {}) }), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Selected" })] })) : ((0, jsx_runtime_1.jsxs)(Selected, { children: [(0, jsx_runtime_1.jsx)(NotSelectedBox, {}), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Not selected" })] })) }));
125
127
  };
126
128
  exports.BooleanFieldValue = BooleanFieldValue;
127
- const MultipleChoiceFieldValue = ({ inputProps, name, className, style, selected, notSelected }) => {
128
- return ((0, jsx_runtime_1.jsx)(exports.MultipleChoiceFieldWrapper, { children: (0, jsx_runtime_1.jsxs)(styledComponents_1.MultipleChoiceFieldContainer, { className: className, style: (0, getStyle_1.getStyle)(style ?? ""), children: [!selected && !notSelected && (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), selected &&
129
- selected.length > 0 &&
130
- selected.map((s) => ((0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldElement, { "data-fjsf-enum-value-view": s.const, children: (0, jsx_runtime_1.jsxs)(Selected, { children: [(0, jsx_runtime_1.jsx)(SelectedBox, { children: (0, jsx_runtime_1.jsx)(exports.SelectedIcon, {}) }), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: s.title ?? "Hello" })] }) }, s.title ?? s))), notSelected &&
131
- notSelected?.length > 0 &&
132
- notSelected.map((n) => ((0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldElement, { children: (0, jsx_runtime_1.jsxs)(NotSelected, { children: [(0, jsx_runtime_1.jsx)(NotSelectedBox, {}), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: n.title })] }) }, n.title ?? n)))] }) }));
129
+ const MultipleChoiceFieldValue = ({ inputProps, name, className, style, values }) => {
130
+ return ((0, jsx_runtime_1.jsx)(exports.MultipleChoiceFieldWrapper, { children: (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldContainer, { className: className, style: (0, getStyle_1.getStyle)(style ?? ""), children: values.map((item) => ((0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldElement, { "data-fjsf-enum-value-view": item.const, children: item.selected ? ((0, jsx_runtime_1.jsxs)(Selected, { children: [(0, jsx_runtime_1.jsx)(SelectedBox, { children: (0, jsx_runtime_1.jsx)(exports.SelectedIcon, {}) }), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: item.title })] })) : ((0, jsx_runtime_1.jsxs)(NotSelected, { children: [(0, jsx_runtime_1.jsx)(NotSelectedBox, {}), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: item.title })] })) }, item.const))) }) }));
133
131
  };
134
132
  exports.MultipleChoiceFieldValue = MultipleChoiceFieldValue;
@@ -9,16 +9,19 @@ const FormViewRegistry_1 = require("../FormViewRegistry");
9
9
  const MultipleChoiceField = (props) => {
10
10
  const { templates, components: { MultipleChoiceFieldValue }, } = (0, react_1.useContext)(FormViewRegistry_1.FormViewRegistry);
11
11
  const { name, uiSchema } = props;
12
- const { props: inputProps, style, onlyShowSelected, } = (0, react_1.useMemo)(() => (0, utils_1.extractUiSchema)(uiSchema), [uiSchema]);
12
+ const { props: inputProps, style } = (0, react_1.useMemo)(() => (0, utils_1.extractUiSchema)(uiSchema), [uiSchema]);
13
13
  const enums = (0, react_1.useMemo)(() => (0, utils_1.getEnums)(props), [props]);
14
14
  const { values } = (0, formik_1.useFormikContext)();
15
15
  const value = (0, formik_1.getIn)(values, name);
16
- const selected = (0, utils_1.getSelectedEnum)(value, enums);
17
- const notSelected = enums?.values?.filter((v) => Array.isArray(value) ? !value.includes(v.const) : value !== v.const);
18
- const hideNotSelected = onlyShowSelected === true || selected === undefined;
16
+ const allValues = enums?.values?.map((v) => ({
17
+ ...v,
18
+ selected: Array.isArray(value)
19
+ ? value.includes(v.const)
20
+ : value === v.const,
21
+ })) ?? [];
19
22
  const SelectedFieldTemplate = (props.uiSchema?.["ui:template"] &&
20
23
  templates[props.uiSchema?.["ui:template"]]) ??
21
24
  templates.FieldTemplate;
22
- return ((0, jsx_runtime_1.jsx)(SelectedFieldTemplate, { ...props, children: (0, jsx_runtime_1.jsx)(MultipleChoiceFieldValue, { inputProps: inputProps, name: name, style: style, selected: selected, notSelected: hideNotSelected ? undefined : notSelected }) }));
25
+ return ((0, jsx_runtime_1.jsx)(SelectedFieldTemplate, { ...props, children: (0, jsx_runtime_1.jsx)(MultipleChoiceFieldValue, { inputProps: inputProps, name: name, style: style, values: allValues }) }));
23
26
  };
24
27
  exports.MultipleChoiceField = MultipleChoiceField;
@@ -10,8 +10,8 @@ const setTitleValues = (name, title, defaultTitle, values) => {
10
10
  }
11
11
  const index = match ? parseInt(match[2]) : -1;
12
12
  const itemValues = match ? (0, formik_1.getIn)(values, name)[index] : (0, formik_1.getIn)(values, name);
13
- return title.replace(/\$\{([\w$.]+)\}/g, (match) => {
14
- const keyMatch = match.match(/^\$\{([\w$.]+)\}$/);
13
+ return title.replace(/\$\{([\w$.:]+)\}/g, (match) => {
14
+ const keyMatch = match.match(/^\$\{([\w$.:]+)\}$/);
15
15
  const key = keyMatch ? keyMatch[1] : "";
16
16
  return key === "index"
17
17
  ? (index + 1).toString()
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import styled from "styled-components";
3
3
  import { MultipleChoiceFieldContainer, MultipleChoiceFieldElement, MultipleChoiceFieldLabel, } from "../../Form/fields/MultipleChoiceField/styledComponents";
4
4
  import { getStyle } from "../../utils/getStyle";
@@ -72,12 +72,13 @@ const SelectedBox = styled.div `
72
72
  background: ${(props) => props.theme.color.background.default};
73
73
  border: ${(props) => props.theme.strokeWidth.thin} solid
74
74
  ${(props) => props.theme.color.border.default};
75
- padding: 0 0.05rem;
76
75
  font-family: ${(props) => props.theme.typography.fontFamily.base};
77
76
  font-size: ${(props) => props.theme.typography.size.small};
78
77
  display: flex;
79
78
  justify-content: center;
80
79
  align-items: start;
80
+ width: 1rem;
81
+ height: 1rem;
81
82
  `;
82
83
  const NotSelectedBox = styled.div `
83
84
  background: ${(props) => props.theme.color.background.default};
@@ -85,8 +86,9 @@ const NotSelectedBox = styled.div `
85
86
  ${(props) => props.theme.color.border.default};
86
87
  border-radius: ${(props) => props.theme.borderRadius.none};
87
88
  display: inline-flex;
88
- width: 0.85rem;
89
- height: 0.85rem;
89
+ width: 1rem;
90
+ height: 1rem;
91
+ min-width: 1rem;
90
92
  `;
91
93
  export const SelectedIcon = styled(FaCheck) `
92
94
  color: ${(props) => props.theme.color.text.default};
@@ -117,10 +119,6 @@ export const MultipleChoiceFieldWrapper = styled.div `
117
119
  export const BooleanFieldValue = ({ name, className, value, label, }) => {
118
120
  return (_jsx("div", { className: className, children: value === true ? (_jsxs(Selected, { children: [_jsx(SelectedBox, { children: _jsx(SelectedIcon, {}) }), _jsx(MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Selected" })] })) : (_jsxs(Selected, { children: [_jsx(NotSelectedBox, {}), _jsx(MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Not selected" })] })) }));
119
121
  };
120
- export const MultipleChoiceFieldValue = ({ inputProps, name, className, style, selected, notSelected }) => {
121
- return (_jsx(MultipleChoiceFieldWrapper, { children: _jsxs(MultipleChoiceFieldContainer, { className: className, style: getStyle(style ?? ""), children: [!selected && !notSelected && _jsx(_Fragment, {}), selected &&
122
- selected.length > 0 &&
123
- selected.map((s) => (_jsx(MultipleChoiceFieldElement, { "data-fjsf-enum-value-view": s.const, children: _jsxs(Selected, { children: [_jsx(SelectedBox, { children: _jsx(SelectedIcon, {}) }), _jsx(MultipleChoiceFieldLabel, { children: s.title ?? "Hello" })] }) }, s.title ?? s))), notSelected &&
124
- notSelected?.length > 0 &&
125
- notSelected.map((n) => (_jsx(MultipleChoiceFieldElement, { children: _jsxs(NotSelected, { children: [_jsx(NotSelectedBox, {}), _jsx(MultipleChoiceFieldLabel, { children: n.title })] }) }, n.title ?? n)))] }) }));
122
+ export const MultipleChoiceFieldValue = ({ inputProps, name, className, style, values }) => {
123
+ return (_jsx(MultipleChoiceFieldWrapper, { children: _jsx(MultipleChoiceFieldContainer, { className: className, style: getStyle(style ?? ""), children: values.map((item) => (_jsx(MultipleChoiceFieldElement, { "data-fjsf-enum-value-view": item.const, children: item.selected ? (_jsxs(Selected, { children: [_jsx(SelectedBox, { children: _jsx(SelectedIcon, {}) }), _jsx(MultipleChoiceFieldLabel, { children: item.title })] })) : (_jsxs(NotSelected, { children: [_jsx(NotSelectedBox, {}), _jsx(MultipleChoiceFieldLabel, { children: item.title })] })) }, item.const))) }) }));
126
124
  };
@@ -1,20 +1,23 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext, useMemo } from "react";
3
3
  import { getIn, useFormikContext } from "formik";
4
- import { extractUiSchema, getEnums, getSelectedEnum } from "../../utils";
4
+ import { extractUiSchema, getEnums } from "../../utils";
5
5
  import { FormViewRegistry } from "../FormViewRegistry";
6
6
  export const MultipleChoiceField = (props) => {
7
7
  const { templates, components: { MultipleChoiceFieldValue }, } = useContext(FormViewRegistry);
8
8
  const { name, uiSchema } = props;
9
- const { props: inputProps, style, onlyShowSelected, } = useMemo(() => extractUiSchema(uiSchema), [uiSchema]);
9
+ const { props: inputProps, style } = useMemo(() => extractUiSchema(uiSchema), [uiSchema]);
10
10
  const enums = useMemo(() => getEnums(props), [props]);
11
11
  const { values } = useFormikContext();
12
12
  const value = getIn(values, name);
13
- const selected = getSelectedEnum(value, enums);
14
- const notSelected = enums?.values?.filter((v) => Array.isArray(value) ? !value.includes(v.const) : value !== v.const);
15
- const hideNotSelected = onlyShowSelected === true || selected === undefined;
13
+ const allValues = enums?.values?.map((v) => ({
14
+ ...v,
15
+ selected: Array.isArray(value)
16
+ ? value.includes(v.const)
17
+ : value === v.const,
18
+ })) ?? [];
16
19
  const SelectedFieldTemplate = (props.uiSchema?.["ui:template"] &&
17
20
  templates[props.uiSchema?.["ui:template"]]) ??
18
21
  templates.FieldTemplate;
19
- return (_jsx(SelectedFieldTemplate, { ...props, children: _jsx(MultipleChoiceFieldValue, { inputProps: inputProps, name: name, style: style, selected: selected, notSelected: hideNotSelected ? undefined : notSelected }) }));
22
+ return (_jsx(SelectedFieldTemplate, { ...props, children: _jsx(MultipleChoiceFieldValue, { inputProps: inputProps, name: name, style: style, values: allValues }) }));
20
23
  };
@@ -7,8 +7,8 @@ export const setTitleValues = (name, title, defaultTitle, values) => {
7
7
  }
8
8
  const index = match ? parseInt(match[2]) : -1;
9
9
  const itemValues = match ? getIn(values, name)[index] : getIn(values, name);
10
- return title.replace(/\$\{([\w$.]+)\}/g, (match) => {
11
- const keyMatch = match.match(/^\$\{([\w$.]+)\}$/);
10
+ return title.replace(/\$\{([\w$.:]+)\}/g, (match) => {
11
+ const keyMatch = match.match(/^\$\{([\w$.:]+)\}$/);
12
12
  const key = keyMatch ? keyMatch[1] : "";
13
13
  return key === "index"
14
14
  ? (index + 1).toString()
@@ -19,14 +19,11 @@ type BooleanValueFieldProps = {
19
19
  };
20
20
  export declare const BooleanFieldValue: React.FC<BooleanValueFieldProps>;
21
21
  type MultipleChoiceFieldValueProps = {
22
- selected: {
22
+ values: {
23
23
  const: string | number;
24
24
  title: string;
25
- }[] | undefined;
26
- notSelected: {
27
- const: string | number;
28
- title: string;
29
- }[] | undefined;
25
+ selected: boolean;
26
+ }[];
30
27
  inputProps?: any;
31
28
  name?: React.ReactNode;
32
29
  className?: string;
@@ -23,14 +23,11 @@ export declare const components: {
23
23
  label?: string;
24
24
  }>;
25
25
  MultipleChoiceFieldValue: React.FC<{
26
- selected: {
26
+ values: {
27
27
  const: string | number;
28
28
  title: string;
29
- }[] | undefined;
30
- notSelected: {
31
- const: string | number;
32
- title: string;
33
- }[] | undefined;
29
+ selected: boolean;
30
+ }[];
34
31
  inputProps?: any;
35
32
  name?: React.ReactNode;
36
33
  className?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "anttivikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [