@itcase/forms 1.0.63 → 1.0.64

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.
@@ -0,0 +1,27 @@
1
+ .form-chips {
2
+ &&_state {
3
+ &_success {
4
+ & .chips {
5
+ /* border: solid 1px var(--choice-success-border); */
6
+ }
7
+ }
8
+ &_error {
9
+ & .chips {
10
+ /* border: solid 1px var(--choice-error-border); */
11
+ }
12
+ }
13
+ &_focus {
14
+ /* border: solid 1px var(--choice-focus-border); */
15
+ }
16
+ }
17
+ }
18
+ .form-field {
19
+ &_type_chips {
20
+ }
21
+ }
22
+ :root {
23
+ --chips-success-border: var(--color-success-border-primary);
24
+ --chips-success-border-hover: var(--color-surface-border-quaternary);
25
+ --chips-error-border: var(--color-error-border-primary);
26
+ --chips-focus-border: var(--color-surface-border-quaternary);
27
+ }
@@ -25,6 +25,16 @@
25
25
  }
26
26
  }
27
27
 
28
+ .form {
29
+ &-field {
30
+ &_type_code {
31
+ ^&__content {
32
+ justify-content: space-between;
33
+ }
34
+ }
35
+ }
36
+ }
37
+
28
38
  .form {
29
39
  &^&-field_type_float {
30
40
  position: relative;
@@ -101,4 +111,3 @@
101
111
  }
102
112
  }
103
113
  }
104
-
@@ -33,6 +33,7 @@ var Select = require('@itcase/ui/components/Select');
33
33
  var Switch = require('@itcase/ui/components/Switch');
34
34
  var Textarea = require('@itcase/ui/components/Textarea');
35
35
  var reactImask = require('react-imask');
36
+ var Chips = require('@itcase/ui/components/Chips');
36
37
  var Button = require('@itcase/ui/components/Button');
37
38
  var Group$1 = require('@itcase/ui/components/Group');
38
39
  var Notification = require('@itcase/ui/components/Notification');
@@ -154,9 +155,11 @@ function FieldWrapperBase(props) {
154
155
  labelHidden,
155
156
  labelTextColor,
156
157
  labelTextSize,
158
+ labelTextSizeMobile,
157
159
  labelTextWeight,
158
160
  helpText,
159
161
  helpTextSize,
162
+ helpTextSizeMobile,
160
163
  helpTextWeight,
161
164
  helpTextColor,
162
165
  isErrorState,
@@ -223,6 +226,7 @@ function FieldWrapperBase(props) {
223
226
  htmlFor: id
224
227
  }, /*#__PURE__*/React__default.default.createElement(Text.Text, {
225
228
  size: labelTextSize,
229
+ sizeMobile: labelTextSizeMobile,
226
230
  textColor: labelTextColor,
227
231
  textWeight: labelTextWeight
228
232
  }, label, labelHidden && '\u00A0')), desc && /*#__PURE__*/React__default.default.createElement("div", {
@@ -256,6 +260,7 @@ function FieldWrapperBase(props) {
256
260
  className: "form-field__message-item form-field__message-item_type_help-text",
257
261
  dataTestId: `${inputName}FieldMessageHelpText`,
258
262
  size: helpTextSize,
263
+ sizeMobile: helpTextSizeMobile,
259
264
  textColor: helpTextColor,
260
265
  textWeight: helpTextWeight
261
266
  }, helpText), (!isErrorState && !helpText || isErrorState && !helpText && !errorMessage) && /*#__PURE__*/React__default.default.createElement(Text.Text, {
@@ -2371,6 +2376,107 @@ MaskedInputField.propTypes = {
2371
2376
  unmasked: PropTypes__default.default.string
2372
2377
  };
2373
2378
 
2379
+ function ChipsField(props) {
2380
+ const {
2381
+ classNameGroupItem,
2382
+ fieldProps,
2383
+ initialValue,
2384
+ inputProps,
2385
+ isDisabled,
2386
+ isRequired,
2387
+ name,
2388
+ options,
2389
+ showMessage,
2390
+ onChange
2391
+ } = props;
2392
+ const {
2393
+ change
2394
+ } = reactFinalForm.useForm();
2395
+
2396
+ // Callback for value changes
2397
+ const onChangeSomeInput = React.useCallback((inputValue, newOptionValue) => {
2398
+ const updatedValues = inputValue.includes(newOptionValue) ? inputValue.filter(selectedValue => selectedValue !== newOptionValue) : [...inputValue, newOptionValue];
2399
+ change(name, updatedValues);
2400
+ onChange && onChange(updatedValues);
2401
+ }, [change, name, onChange]);
2402
+ React.useEffect(() => {
2403
+ initialValue && change(name, initialValue);
2404
+ // update the form value only when the initialValue changes, so use disable eslint to ignore the warning
2405
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2406
+ }, [initialValue]);
2407
+ return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
2408
+ initialValue: initialValue,
2409
+ name: name
2410
+ }, function Render({
2411
+ input,
2412
+ meta
2413
+ }) {
2414
+ const {
2415
+ isErrorState,
2416
+ isValidState,
2417
+ errorKey,
2418
+ errorMessage
2419
+ } = useFieldValidationState({
2420
+ fieldProps: fieldProps,
2421
+ input: input,
2422
+ meta: meta
2423
+ });
2424
+ const updatedInputProps = useValidationAppearanceInputProps({
2425
+ validationStateKey: isErrorState ? errorKey : 'success',
2426
+ inputProps: inputProps
2427
+ });
2428
+ const activeOptionsList = React.useMemo(() => {
2429
+ const emptyOptionsList = [{
2430
+ value: null,
2431
+ label: null
2432
+ }];
2433
+ if (input?.value) {
2434
+ const currentOptions = options.filter(option => input.value?.includes(option.value));
2435
+ return currentOptions || emptyOptionsList;
2436
+ }
2437
+ return emptyOptionsList;
2438
+ }, [input.value]);
2439
+ return /*#__PURE__*/React__default.default.createElement(FieldWrapper, Object.assign({
2440
+ className: clsx__default.default('form-field_type_chips', 'form__item_type_chips', classNameGroupItem),
2441
+ errorKey: errorKey,
2442
+ errorMessage: errorMessage,
2443
+ fieldClassName: 'form-chips',
2444
+ inputName: input.name,
2445
+ inputValue: input.value,
2446
+ isDisabled: isDisabled,
2447
+ isErrorState: isErrorState,
2448
+ isRequired: isRequired,
2449
+ isValidState: isValidState,
2450
+ metaActive: meta.active,
2451
+ metaError: meta.error,
2452
+ showMessage: showMessage
2453
+ }, fieldProps), options.map(option => /*#__PURE__*/React__default.default.createElement(Chips.Chips, Object.assign({
2454
+ isActive: activeOptionsList.includes(option),
2455
+ className: clsx__default.default(meta.active && 'form-chips_state_focus', meta.error && meta.touched && `form-chips_state_${errorKey}`),
2456
+ key: option.value,
2457
+ label: option.label,
2458
+ value: option.value,
2459
+ onClick: () => onChangeSomeInput(input.value, option.value)
2460
+ }, updatedInputProps))));
2461
+ });
2462
+ }
2463
+ ChipsField.propTypes = {
2464
+ classNameGroupItem: PropTypes__default.default.string,
2465
+ fieldProps: PropTypes__default.default.object,
2466
+ initialValue: PropTypes__default.default.array,
2467
+ input: PropTypes__default.default.object,
2468
+ inputProps: PropTypes__default.default.object,
2469
+ isDisabled: PropTypes__default.default.bool,
2470
+ isRequired: PropTypes__default.default.bool,
2471
+ name: PropTypes__default.default.string,
2472
+ options: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
2473
+ value: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.number, PropTypes__default.default.bool]),
2474
+ label: PropTypes__default.default.string
2475
+ })),
2476
+ showMessage: PropTypes__default.default.bool,
2477
+ onChange: PropTypes__default.default.func
2478
+ };
2479
+
2374
2480
  const focusOnError = (formElementsList, errors) => {
2375
2481
  const selectsIds = Object.keys(errors).map(fieldName => {
2376
2482
  if (fieldName === finalForm.FORM_ERROR) {
@@ -2485,6 +2591,7 @@ const formTypes = {
2485
2591
  checkbox: 'checkbox',
2486
2592
  custom: 'custom',
2487
2593
  choice: 'choice',
2594
+ chips: 'chips',
2488
2595
  code: 'code',
2489
2596
  datePicker: 'datePicker',
2490
2597
  dateRangePicker: 'dateRangePicker',
@@ -2512,6 +2619,12 @@ function generateField(field, config, props) {
2512
2619
  key: config.key
2513
2620
  }, field, props));
2514
2621
  }
2622
+ case formTypes.chips:
2623
+ {
2624
+ return /*#__PURE__*/React__default.default.createElement(ChipsField, Object.assign({
2625
+ key: config.key
2626
+ }, field, props));
2627
+ }
2515
2628
  case formTypes.code:
2516
2629
  {
2517
2630
  return /*#__PURE__*/React__default.default.createElement(CodeField, Object.assign({
@@ -3030,6 +3143,7 @@ Object.defineProperty(exports, "useFormState", {
3030
3143
  get: function () { return reactFinalForm.useFormState; }
3031
3144
  });
3032
3145
  exports.Checkbox = CheckboxField;
3146
+ exports.ChipsField = ChipsField;
3033
3147
  exports.ChoiceField = ChoiceField;
3034
3148
  exports.CodeField = CodeField;
3035
3149
  exports.CustomField = CustomField;
@@ -32,6 +32,7 @@ import { Select } from '@itcase/ui/components/Select';
32
32
  import { Switch } from '@itcase/ui/components/Switch';
33
33
  import { Textarea } from '@itcase/ui/components/Textarea';
34
34
  import { useIMask } from 'react-imask';
35
+ import { Chips } from '@itcase/ui/components/Chips';
35
36
  import { Button } from '@itcase/ui/components/Button';
36
37
  import { Group as Group$1 } from '@itcase/ui/components/Group';
37
38
  import { NotificationItem } from '@itcase/ui/components/Notification';
@@ -140,9 +141,11 @@ function FieldWrapperBase(props) {
140
141
  labelHidden,
141
142
  labelTextColor,
142
143
  labelTextSize,
144
+ labelTextSizeMobile,
143
145
  labelTextWeight,
144
146
  helpText,
145
147
  helpTextSize,
148
+ helpTextSizeMobile,
146
149
  helpTextWeight,
147
150
  helpTextColor,
148
151
  isErrorState,
@@ -209,6 +212,7 @@ function FieldWrapperBase(props) {
209
212
  htmlFor: id
210
213
  }, /*#__PURE__*/React.createElement(Text, {
211
214
  size: labelTextSize,
215
+ sizeMobile: labelTextSizeMobile,
212
216
  textColor: labelTextColor,
213
217
  textWeight: labelTextWeight
214
218
  }, label, labelHidden && '\u00A0')), desc && /*#__PURE__*/React.createElement("div", {
@@ -242,6 +246,7 @@ function FieldWrapperBase(props) {
242
246
  className: "form-field__message-item form-field__message-item_type_help-text",
243
247
  dataTestId: `${inputName}FieldMessageHelpText`,
244
248
  size: helpTextSize,
249
+ sizeMobile: helpTextSizeMobile,
245
250
  textColor: helpTextColor,
246
251
  textWeight: helpTextWeight
247
252
  }, helpText), (!isErrorState && !helpText || isErrorState && !helpText && !errorMessage) && /*#__PURE__*/React.createElement(Text, {
@@ -2357,6 +2362,107 @@ MaskedInputField.propTypes = {
2357
2362
  unmasked: PropTypes.string
2358
2363
  };
2359
2364
 
2365
+ function ChipsField(props) {
2366
+ const {
2367
+ classNameGroupItem,
2368
+ fieldProps,
2369
+ initialValue,
2370
+ inputProps,
2371
+ isDisabled,
2372
+ isRequired,
2373
+ name,
2374
+ options,
2375
+ showMessage,
2376
+ onChange
2377
+ } = props;
2378
+ const {
2379
+ change
2380
+ } = useForm();
2381
+
2382
+ // Callback for value changes
2383
+ const onChangeSomeInput = useCallback((inputValue, newOptionValue) => {
2384
+ const updatedValues = inputValue.includes(newOptionValue) ? inputValue.filter(selectedValue => selectedValue !== newOptionValue) : [...inputValue, newOptionValue];
2385
+ change(name, updatedValues);
2386
+ onChange && onChange(updatedValues);
2387
+ }, [change, name, onChange]);
2388
+ useEffect(() => {
2389
+ initialValue && change(name, initialValue);
2390
+ // update the form value only when the initialValue changes, so use disable eslint to ignore the warning
2391
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2392
+ }, [initialValue]);
2393
+ return /*#__PURE__*/React.createElement(Field, {
2394
+ initialValue: initialValue,
2395
+ name: name
2396
+ }, function Render({
2397
+ input,
2398
+ meta
2399
+ }) {
2400
+ const {
2401
+ isErrorState,
2402
+ isValidState,
2403
+ errorKey,
2404
+ errorMessage
2405
+ } = useFieldValidationState({
2406
+ fieldProps: fieldProps,
2407
+ input: input,
2408
+ meta: meta
2409
+ });
2410
+ const updatedInputProps = useValidationAppearanceInputProps({
2411
+ validationStateKey: isErrorState ? errorKey : 'success',
2412
+ inputProps: inputProps
2413
+ });
2414
+ const activeOptionsList = useMemo(() => {
2415
+ const emptyOptionsList = [{
2416
+ value: null,
2417
+ label: null
2418
+ }];
2419
+ if (input?.value) {
2420
+ const currentOptions = options.filter(option => input.value?.includes(option.value));
2421
+ return currentOptions || emptyOptionsList;
2422
+ }
2423
+ return emptyOptionsList;
2424
+ }, [input.value]);
2425
+ return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
2426
+ className: clsx('form-field_type_chips', 'form__item_type_chips', classNameGroupItem),
2427
+ errorKey: errorKey,
2428
+ errorMessage: errorMessage,
2429
+ fieldClassName: 'form-chips',
2430
+ inputName: input.name,
2431
+ inputValue: input.value,
2432
+ isDisabled: isDisabled,
2433
+ isErrorState: isErrorState,
2434
+ isRequired: isRequired,
2435
+ isValidState: isValidState,
2436
+ metaActive: meta.active,
2437
+ metaError: meta.error,
2438
+ showMessage: showMessage
2439
+ }, fieldProps), options.map(option => /*#__PURE__*/React.createElement(Chips, Object.assign({
2440
+ isActive: activeOptionsList.includes(option),
2441
+ className: clsx(meta.active && 'form-chips_state_focus', meta.error && meta.touched && `form-chips_state_${errorKey}`),
2442
+ key: option.value,
2443
+ label: option.label,
2444
+ value: option.value,
2445
+ onClick: () => onChangeSomeInput(input.value, option.value)
2446
+ }, updatedInputProps))));
2447
+ });
2448
+ }
2449
+ ChipsField.propTypes = {
2450
+ classNameGroupItem: PropTypes.string,
2451
+ fieldProps: PropTypes.object,
2452
+ initialValue: PropTypes.array,
2453
+ input: PropTypes.object,
2454
+ inputProps: PropTypes.object,
2455
+ isDisabled: PropTypes.bool,
2456
+ isRequired: PropTypes.bool,
2457
+ name: PropTypes.string,
2458
+ options: PropTypes.arrayOf(PropTypes.shape({
2459
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
2460
+ label: PropTypes.string
2461
+ })),
2462
+ showMessage: PropTypes.bool,
2463
+ onChange: PropTypes.func
2464
+ };
2465
+
2360
2466
  const focusOnError = (formElementsList, errors) => {
2361
2467
  const selectsIds = Object.keys(errors).map(fieldName => {
2362
2468
  if (fieldName === FORM_ERROR) {
@@ -2471,6 +2577,7 @@ const formTypes = {
2471
2577
  checkbox: 'checkbox',
2472
2578
  custom: 'custom',
2473
2579
  choice: 'choice',
2580
+ chips: 'chips',
2474
2581
  code: 'code',
2475
2582
  datePicker: 'datePicker',
2476
2583
  dateRangePicker: 'dateRangePicker',
@@ -2498,6 +2605,12 @@ function generateField(field, config, props) {
2498
2605
  key: config.key
2499
2606
  }, field, props));
2500
2607
  }
2608
+ case formTypes.chips:
2609
+ {
2610
+ return /*#__PURE__*/React.createElement(ChipsField, Object.assign({
2611
+ key: config.key
2612
+ }, field, props));
2613
+ }
2501
2614
  case formTypes.code:
2502
2615
  {
2503
2616
  return /*#__PURE__*/React.createElement(CodeField, Object.assign({
@@ -3003,4 +3116,4 @@ const DEFAULT_MESSAGES_FIELDS = {
3003
3116
  }
3004
3117
  };
3005
3118
 
3006
- export { CheckboxField as Checkbox, ChoiceField, CodeField, CustomField, DEFAULT_MESSAGES_FIELDS, DatePickerField, FieldWrapper, FieldWrapperBase, FileInput, FinalForm, Group, InputField, MaskedInputField, RadioGroup, SegmentedField, SelectField, SwitchField as Switch, TextareaField as Textarea, addRequiredFieldsParamToSchema, emailValidation, focusOnError, focusOnErrorDecorator, formTypes, generateField, phoneValidation, sendFormDataToServer, setErrorsMutator, useYupValidationSchema };
3119
+ export { CheckboxField as Checkbox, ChipsField, ChoiceField, CodeField, CustomField, DEFAULT_MESSAGES_FIELDS, DatePickerField, FieldWrapper, FieldWrapperBase, FileInput, FinalForm, Group, InputField, MaskedInputField, RadioGroup, SegmentedField, SelectField, SwitchField as Switch, TextareaField as Textarea, addRequiredFieldsParamToSchema, emailValidation, focusOnError, focusOnErrorDecorator, formTypes, generateField, phoneValidation, sendFormDataToServer, setErrorsMutator, useYupValidationSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/forms",
3
- "version": "1.0.63",
3
+ "version": "1.0.64",
4
4
  "description": "Forms fields, inputs, etc.",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -30,16 +30,16 @@
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
32
  "dependencies": {
33
- "@itcase/common": "^1.2.2",
34
- "@itcase/ui": "^1.1.15",
35
- "axios": "^1.7.2",
33
+ "@itcase/common": "^1.2.6",
34
+ "@itcase/ui": "^1.1.21",
35
+ "axios": "^1.7.3",
36
36
  "clsx": "^2.1.1",
37
37
  "final-form": "^4.20.10",
38
38
  "final-form-focus": "^1.1.2",
39
- "libphonenumber-js": "^1.11.4",
39
+ "libphonenumber-js": "^1.11.5",
40
40
  "lodash": "^4.17.21",
41
- "luxon": "^3.4.4",
42
- "postcss": "^8.4.39",
41
+ "luxon": "^3.5.0",
42
+ "postcss": "^8.4.41",
43
43
  "prop-types": "^15.8.1",
44
44
  "react": "^18.3.1",
45
45
  "react-date-range": "^2.0.1",
@@ -51,9 +51,10 @@
51
51
  "react-select": "^5.8.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@babel/core": "^7.24.9",
55
- "@babel/eslint-parser": "^7.24.8",
56
- "@babel/preset-env": "^7.24.8",
54
+ "@itcase/lint": "^1.0.8",
55
+ "@babel/core": "^7.25.2",
56
+ "@babel/eslint-parser": "^7.25.1",
57
+ "@babel/preset-env": "^7.25.3",
57
58
  "@babel/preset-react": "^7.24.7",
58
59
  "@commitlint/cli": "^19.3.0",
59
60
  "@commitlint/config-conventional": "^19.2.2",
@@ -65,24 +66,28 @@
65
66
  "@rollup/plugin-json": "^6.1.0",
66
67
  "@rollup/plugin-node-resolve": "^15.2.3",
67
68
  "@rollup/plugin-terser": "^0.4.4",
69
+ "@semantic-release/changelog": "^6.0.3",
68
70
  "@semantic-release/git": "^10.0.1",
71
+ "@semantic-release/release-notes-generator": "14.0.1",
72
+ "@types/react": "^18",
73
+ "@types/react-dom": "^18.3.0",
69
74
  "babel-plugin-inline-react-svg": "^2.0.2",
70
75
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
71
76
  "conventional-changelog-conventionalcommits": "^8.0.0",
72
- "eslint": "9.7.0",
77
+ "eslint": "9.8.0",
73
78
  "eslint-config-prettier": "9.1.0",
74
79
  "eslint-config-standard": "17.1.0",
75
80
  "eslint-plugin-babel": "5.3.1",
76
81
  "eslint-plugin-import": "2.29.1",
77
- "eslint-plugin-n": "17.9.0",
82
+ "eslint-plugin-n": "17.10.2",
78
83
  "eslint-plugin-node": "11.1.0",
79
- "eslint-plugin-prettier": "5.1.3",
80
- "eslint-plugin-promise": "6.4.0",
81
- "eslint-plugin-react": "7.34.4",
84
+ "eslint-plugin-prettier": "5.2.1",
85
+ "eslint-plugin-promise": "7.0.0",
86
+ "eslint-plugin-react": "7.35.0",
82
87
  "eslint-plugin-react-hooks": "4.6.2",
83
88
  "eslint-plugin-standard": "5.0.0",
84
- "husky": "^9.0.11",
85
- "lint-staged": "^15.2.7",
89
+ "husky": "^9.1.4",
90
+ "lint-staged": "^15.2.8",
86
91
  "npm": "^10.8.2",
87
92
  "postcss-aspect-ratio-polyfill": "^2.0.0",
88
93
  "postcss-cli": "^11.0.0",
@@ -97,21 +102,22 @@
97
102
  "postcss-import": "^16.1.0",
98
103
  "postcss-import-ext-glob": "^2.1.1",
99
104
  "postcss-mixins": "^10.0.1",
100
- "postcss-nested": "^6.0.1",
105
+ "postcss-nested": "^6.2.0",
101
106
  "postcss-nested-ancestors": "^3.0.0",
102
107
  "postcss-normalize": "^10.0.1",
103
108
  "postcss-prepend-imports": "^1.0.1",
104
- "postcss-preset-env": "^9.6.0",
109
+ "postcss-preset-env": "^10.0.0",
105
110
  "postcss-pxtorem": "^6.1.0",
106
111
  "postcss-responsive-type": "github:ITCase/postcss-responsive-type",
107
112
  "postcss-sort-media-queries": "^5.2.0",
108
113
  "prettier": "3.3.3",
109
- "rollup": "^4.18.1",
114
+ "rollup": "^4.20.0",
110
115
  "rollup-plugin-peer-deps-external": "^2.2.4",
111
116
  "semantic-release": "^24.0.0",
112
- "stylelint": "^16.7.0",
117
+ "stylelint": "^16.8.1",
113
118
  "stylelint-config-standard": "^36.0.1",
114
119
  "stylelint-no-unsupported-browser-features": "^8.0.1",
115
- "stylelint-order": "^6.0.4"
120
+ "stylelint-order": "^6.0.4",
121
+ "typescript": "^5.5.4"
116
122
  }
117
123
  }