@dr.pogodin/react-utils 1.33.0 → 1.33.2

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 (38) hide show
  1. package/build/development/shared/components/Checkbox/index.js +1 -0
  2. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  3. package/build/development/shared/components/Modal/index.js +11 -2
  4. package/build/development/shared/components/Modal/index.js.map +1 -1
  5. package/build/development/shared/components/selectors/NativeDropdown/index.js +1 -1
  6. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  7. package/build/development/shared/components/selectors/Switch/index.js +3 -3
  8. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  9. package/build/development/shared/components/selectors/common.js +7 -2
  10. package/build/development/shared/components/selectors/common.js.map +1 -1
  11. package/build/development/style.css +3 -3
  12. package/build/development/web.bundle.js +6 -6
  13. package/build/production/shared/components/Checkbox/index.js +1 -1
  14. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  15. package/build/production/shared/components/Modal/index.js +1 -1
  16. package/build/production/shared/components/Modal/index.js.map +1 -1
  17. package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
  18. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  19. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  20. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  21. package/build/production/shared/components/selectors/common.js +2 -2
  22. package/build/production/shared/components/selectors/common.js.map +1 -1
  23. package/build/production/style.css +1 -1
  24. package/build/production/style.css.map +1 -1
  25. package/build/production/web.bundle.js +1 -1
  26. package/build/production/web.bundle.js.map +1 -1
  27. package/build/types-code/shared/components/selectors/Switch/index.d.ts +1 -1
  28. package/build/types-code/shared/components/selectors/common.d.ts +4 -8
  29. package/build/types-scss/src/shared/components/selectors/Switch/theme.scss.d.ts +1 -0
  30. package/config/webpack/app-base.js +4 -7
  31. package/config/webpack/lib-base.js +4 -7
  32. package/package.json +3 -3
  33. package/src/shared/components/Checkbox/index.tsx +1 -0
  34. package/src/shared/components/Modal/index.tsx +26 -2
  35. package/src/shared/components/selectors/NativeDropdown/index.tsx +2 -2
  36. package/src/shared/components/selectors/Switch/index.tsx +2 -2
  37. package/src/shared/components/selectors/Switch/theme.scss +1 -1
  38. package/src/shared/components/selectors/common.ts +14 -2
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
3
  import { type OptionsT } from '../common';
4
- declare const validThemeKeys: readonly ["container", "label", "option", "selected", "switch"];
4
+ declare const validThemeKeys: readonly ["container", "label", "option", "options", "selected"];
5
5
  type PropsT = {
6
6
  label?: React.ReactNode;
7
7
  onChange?: (value: string) => void;
@@ -15,13 +15,9 @@ export type PropsT<NameT, OnChangeT = React.ChangeEventHandler<HTMLSelectElement
15
15
  theme: Theme<typeof validThemeKeys>;
16
16
  value?: string;
17
17
  };
18
- export declare const optionValidator: PT.Requireable<NonNullable<string | NonNullable<PT.InferProps<{
19
- name: PT.Requireable<string>;
20
- value: PT.Validator<string>;
21
- }>>>>;
22
- export declare const optionsValidator: PT.Requireable<NonNullable<NonNullable<string | NonNullable<PT.InferProps<{
23
- name: PT.Requireable<string>;
24
- value: PT.Validator<string>;
25
- }>>>>[]>;
18
+ export declare const optionValidator: PT.Requireable<OptionT<React.ReactNode> | string>;
19
+ export declare const optionsValidator: PT.Requireable<NonNullable<string | OptionT<React.ReactNode>>[]>;
20
+ export declare const stringOptionValidator: PT.Requireable<OptionT<string> | string>;
21
+ export declare const stringOptionsValidator: PT.Requireable<NonNullable<string | OptionT<string>>[]>;
26
22
  /** Returns option value and name as a tuple. */
27
23
  export declare function optionValueName<NameT>(option: OptionT<NameT> | string): [string, NameT | string];
@@ -3,4 +3,5 @@ export declare const container: string;
3
3
  export declare const context: string;
4
4
  export declare const hoc: string;
5
5
  export declare const option: string;
6
+ export declare const options: string;
6
7
  export declare const selected: string;
@@ -282,14 +282,11 @@ function configFactory(ops) {
282
282
  modules: {
283
283
  getLocalIdent: utils_1.getLocalIdent,
284
284
  localIdentName: o.cssLocalIdent,
285
- // TODO: This flag defaults `true` for ES module builds since
286
- // css-loader@7.0.0:
285
+ // This flag defaults `true` for ES module builds since css-loader@7.0.0:
287
286
  // https://github.com/webpack-contrib/css-loader/releases/tag/v7.0.0
288
- // For now we'll keep it `false` to avoid a breaking change for
289
- // host projects, and also because babel-plugin-react-css-modules
290
- // we rely upon is pending an upgrade to support named style
291
- // imports:
292
- // https://github.com/birdofpreyru/babel-plugin-react-css-modules/issues/44
287
+ // We'll keep it `false` to avoid a breaking change for dependant
288
+ // projects, and I am also not sure what are the benefits of
289
+ // named CSS exports anyway.
293
290
  namedExport: false,
294
291
  },
295
292
  },
@@ -103,14 +103,11 @@ function configFactory(ops) {
103
103
  modules: {
104
104
  getLocalIdent: utils_1.getLocalIdent,
105
105
  localIdentName: ops.cssLocalIdent,
106
- // TODO: This flag defaults `true` for ES module builds since
107
- // css-loader@7.0.0:
106
+ // This flag defaults `true` for ES module builds since css-loader@7.0.0:
108
107
  // https://github.com/webpack-contrib/css-loader/releases/tag/v7.0.0
109
- // For now we'll keep it `false` to avoid a breaking change for
110
- // host projects, and also because babel-plugin-react-css-modules
111
- // we rely upon is pending an upgrade to support named style
112
- // imports:
113
- // https://github.com/birdofpreyru/babel-plugin-react-css-modules/issues/44
108
+ // We'll keep it `false` to avoid a breaking change for dependant
109
+ // projects, and I am also not sure what are the benefits of
110
+ // named CSS exports anyway.
114
111
  namedExport: false,
115
112
  },
116
113
  },
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.33.0",
2
+ "version": "1.33.2",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@babel/runtime": "^7.24.4",
12
- "@dr.pogodin/babel-plugin-react-css-modules": "^6.13.0",
12
+ "@dr.pogodin/babel-plugin-react-css-modules": "^6.13.1",
13
13
  "@dr.pogodin/csurf": "^1.13.0",
14
14
  "@dr.pogodin/js-utils": "^0.0.9",
15
15
  "@dr.pogodin/react-global-state": "^0.14.0",
@@ -95,7 +95,7 @@
95
95
  "eslint-config-airbnb-typescript": "^18.0.0",
96
96
  "eslint-import-resolver-babel-module": "^5.3.2",
97
97
  "eslint-plugin-import": "^2.29.1",
98
- "eslint-plugin-jest": "^28.0.0",
98
+ "eslint-plugin-jest": "^28.2.0",
99
99
  "eslint-plugin-jsx-a11y": "^6.8.0",
100
100
  "eslint-plugin-react": "^7.34.1",
101
101
  "eslint-plugin-react-hooks": "^4.6.0",
@@ -25,6 +25,7 @@ const Checkbox: React.FunctionComponent<PropT> = ({
25
25
  checked={checked}
26
26
  className={theme.checkbox}
27
27
  onChange={onChange}
28
+ onClick={(e) => e.stopPropagation()}
28
29
  type="checkbox"
29
30
  />
30
31
  </div>
@@ -109,9 +109,17 @@ const BaseModal: React.FunctionComponent<PropsT> = ({
109
109
  <div
110
110
  aria-label="Cancel"
111
111
  className={theme.overlay}
112
- onClick={() => onCancel && onCancel()}
112
+ onClick={(e) => {
113
+ if (onCancel) {
114
+ onCancel();
115
+ e.stopPropagation();
116
+ }
117
+ }}
113
118
  onKeyDown={(e) => {
114
- if (e.key === 'Escape' && onCancel) onCancel();
119
+ if (e.key === 'Escape' && onCancel) {
120
+ onCancel();
121
+ e.stopPropagation();
122
+ }
115
123
  }}
116
124
  ref={(node) => {
117
125
  if (node && node !== overlayRef.current) {
@@ -122,9 +130,23 @@ const BaseModal: React.FunctionComponent<PropsT> = ({
122
130
  role="button"
123
131
  tabIndex={0}
124
132
  />
133
+ {
134
+ // NOTE: These rules are disabled because our intention is to keep
135
+ // the element non-interactive (thus not on the keyboard focus chain),
136
+ // and it has `onClick` handler merely to stop propagation of click
137
+ // events to its parent container. This is needed because, for example
138
+ // when the modal is wrapped into an interactive element we don't want
139
+ // any clicks inside the modal to bubble-up to that parent element
140
+ // (because visually and logically the modal dialog does not belong
141
+ // to its parent container, where it technically belongs from
142
+ // the HTML mark-up perpective).
143
+ /* eslint-disable jsx-a11y/click-events-have-key-events,
144
+ jsx-a11y/no-noninteractive-element-interactions */
145
+ }
125
146
  <div
126
147
  aria-modal="true"
127
148
  className={theme.container}
149
+ onClick={(e) => e.stopPropagation()}
128
150
  onWheel={(event) => event.stopPropagation()}
129
151
  ref={containerRef}
130
152
  role="dialog"
@@ -132,6 +154,8 @@ const BaseModal: React.FunctionComponent<PropsT> = ({
132
154
  >
133
155
  {children}
134
156
  </div>
157
+ {/* eslint-enable jsx-a11y/click-events-have-key-events,
158
+ jsx-a11y/no-noninteractive-element-interactions */}
135
159
  <div
136
160
  onFocus={() => {
137
161
  overlayRef.current?.focus();
@@ -8,8 +8,8 @@ import defaultTheme from './theme.scss';
8
8
 
9
9
  import {
10
10
  type PropsT,
11
- optionsValidator,
12
11
  optionValueName,
12
+ stringOptionsValidator,
13
13
  validThemeKeys,
14
14
  } from '../common';
15
15
 
@@ -102,7 +102,7 @@ Dropdown.propTypes = {
102
102
  filter: PT.func,
103
103
  label: PT.node,
104
104
  onChange: PT.func,
105
- options: optionsValidator,
105
+ options: stringOptionsValidator,
106
106
  theme: ThemedDropdown.themeType.isRequired,
107
107
  value: PT.string,
108
108
  };
@@ -9,8 +9,8 @@ const validThemeKeys = [
9
9
  'container',
10
10
  'label',
11
11
  'option',
12
+ 'options',
12
13
  'selected',
13
- 'switch',
14
14
  ] as const;
15
15
 
16
16
  type PropsT = {
@@ -62,7 +62,7 @@ const BaseSwitch: React.FunctionComponent<PropsT> = ({
62
62
  return (
63
63
  <div className={theme.container}>
64
64
  {label ? <div className={theme.label}>{label}</div> : null}
65
- <div className={theme.switch}>
65
+ <div className={theme.options}>
66
66
  {optionNodes}
67
67
  </div>
68
68
  </div>
@@ -26,7 +26,7 @@
26
26
  cursor: default;
27
27
  }
28
28
 
29
- &.switch {
29
+ &.options {
30
30
  align-items: center;
31
31
  background: whitesmoke;
32
32
  border: 1px solid gray;
@@ -38,9 +38,10 @@ export type PropsT<
38
38
  value?: string;
39
39
  };
40
40
 
41
- export const optionValidator = PT.oneOfType([
41
+ export const optionValidator:
42
+ PT.Requireable<OptionT<React.ReactNode> | string> = PT.oneOfType([
42
43
  PT.shape({
43
- name: PT.string,
44
+ name: PT.node,
44
45
  value: PT.string.isRequired,
45
46
  }).isRequired,
46
47
  PT.string.isRequired,
@@ -48,6 +49,17 @@ export const optionValidator = PT.oneOfType([
48
49
 
49
50
  export const optionsValidator = PT.arrayOf(optionValidator.isRequired);
50
51
 
52
+ export const stringOptionValidator:
53
+ PT.Requireable<OptionT<string> | string> = PT.oneOfType([
54
+ PT.shape({
55
+ name: PT.string,
56
+ value: PT.string.isRequired,
57
+ }).isRequired,
58
+ PT.string.isRequired,
59
+ ]);
60
+
61
+ export const stringOptionsValidator = PT.arrayOf(stringOptionValidator.isRequired);
62
+
51
63
  /** Returns option value and name as a tuple. */
52
64
  export function optionValueName<NameT>(
53
65
  option: OptionT<NameT> | string,