@dr.pogodin/react-utils 1.37.0 → 1.38.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.
Files changed (36) hide show
  1. package/build/development/shared/components/Button/index.js +4 -0
  2. package/build/development/shared/components/Button/index.js.map +1 -1
  3. package/build/development/shared/components/Modal/index.js +4 -1
  4. package/build/development/shared/components/Modal/index.js.map +1 -1
  5. package/build/development/shared/components/selectors/NativeDropdown/index.js +7 -2
  6. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  7. package/build/development/shared/components/selectors/common.js.map +1 -1
  8. package/build/development/shared/utils/jest/index.js +3 -0
  9. package/build/development/shared/utils/jest/index.js.map +1 -1
  10. package/build/development/style.css +11 -1
  11. package/build/development/web.bundle.js +4 -4
  12. package/build/production/shared/components/Button/index.js +1 -1
  13. package/build/production/shared/components/Button/index.js.map +1 -1
  14. package/build/production/shared/components/Modal/index.js +2 -2
  15. package/build/production/shared/components/Modal/index.js.map +1 -1
  16. package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
  17. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  18. package/build/production/shared/components/selectors/common.js.map +1 -1
  19. package/build/production/shared/utils/jest/index.js +1 -1
  20. package/build/production/shared/utils/jest/index.js.map +1 -1
  21. package/build/production/style.css +1 -1
  22. package/build/production/style.css.map +1 -1
  23. package/build/production/web.bundle.js +1 -1
  24. package/build/production/web.bundle.js.map +1 -1
  25. package/build/types-code/shared/components/Button/index.d.ts +1 -0
  26. package/build/types-code/shared/components/Modal/index.d.ts +4 -1
  27. package/build/types-code/shared/components/selectors/common.d.ts +2 -1
  28. package/build/types-code/shared/utils/jest/index.d.ts +1 -0
  29. package/build/types-scss/src/shared/components/selectors/NativeDropdown/theme.scss.d.ts +1 -0
  30. package/package.json +9 -9
  31. package/src/shared/components/Button/index.tsx +5 -1
  32. package/src/shared/components/Modal/index.tsx +9 -2
  33. package/src/shared/components/selectors/NativeDropdown/index.tsx +6 -1
  34. package/src/shared/components/selectors/NativeDropdown/theme.scss +6 -1
  35. package/src/shared/components/selectors/common.ts +6 -0
  36. package/src/shared/utils/jest/index.tsx +5 -0
@@ -9,6 +9,7 @@ type PropsT = {
9
9
  onMouseDown?: React.MouseEventHandler;
10
10
  openNewTab?: boolean;
11
11
  replace?: boolean;
12
+ testId?: string;
12
13
  theme: Theme<'active' | 'button' | 'disabled'>;
13
14
  to?: object | string;
14
15
  };
@@ -3,10 +3,13 @@ import { type Theme } from '@dr.pogodin/react-themes';
3
3
  type PropsT = {
4
4
  cancelOnScrolling?: boolean;
5
5
  children?: ReactNode;
6
- containerStyle?: React.CSSProperties;
7
6
  dontDisableScrolling?: boolean;
8
7
  onCancel?: () => void;
8
+ style?: React.CSSProperties;
9
+ testId?: string;
9
10
  theme: Theme<'container' | 'overlay'>;
11
+ /** @deprecated */
12
+ containerStyle?: React.CSSProperties;
10
13
  };
11
14
  /**
12
15
  * The `<Modal>` component implements a simple themeable modal window, wrapped
@@ -1,5 +1,5 @@
1
1
  import type { Theme } from '@dr.pogodin/react-themes';
2
- type ThemeKeyT = 'active' | 'arrow' | 'container' | 'dropdown' | 'hiddenOption' | 'label' | 'option' | 'select' | 'upward';
2
+ type ThemeKeyT = 'active' | 'arrow' | 'container' | 'dropdown' | 'hiddenOption' | 'label' | 'option' | 'select' | 'invalid' | 'upward';
3
3
  export type ValueT = number | string;
4
4
  export type OptionT<NameT> = {
5
5
  name?: NameT | null;
@@ -11,6 +11,7 @@ export type PropsT<NameT, OnChangeT = React.ChangeEventHandler<HTMLSelectElement
11
11
  label?: React.ReactNode;
12
12
  onChange?: OnChangeT;
13
13
  options?: Readonly<OptionsT<NameT>>;
14
+ testId?: string;
14
15
  theme: Theme<ThemeKeyT>;
15
16
  value?: ValueT;
16
17
  };
@@ -34,6 +34,7 @@ export declare function getMockUuid(seed?: number): string;
34
34
  export declare function mockTimer(time: number): Promise<void>;
35
35
  export type MountedSceneT = HTMLElement & {
36
36
  destroy: () => void;
37
+ snapshot: () => void;
37
38
  };
38
39
  /**
39
40
  * Mounts `scene` to the DOM, and returns the root scene element.
@@ -6,6 +6,7 @@ export declare const context: string;
6
6
  export declare const dropdown: string;
7
7
  export declare const hiddenOption: string;
8
8
  export declare const hoc: string;
9
+ export declare const invalid: string;
9
10
  export declare const label: string;
10
11
  export declare const option: string;
11
12
  export declare const select: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.37.0",
2
+ "version": "1.38.1",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -30,14 +30,14 @@
30
30
  "lodash": "^4.17.21",
31
31
  "morgan": "^1.10.0",
32
32
  "node-forge": "^1.3.1",
33
- "qs": "^6.12.1",
33
+ "qs": "^6.12.2",
34
34
  "raf": "^3.4.1",
35
35
  "react": "^18.3.1",
36
36
  "react-dom": "^18.3.1",
37
37
  "react-helmet": "^6.1.0",
38
- "react-router-dom": "^6.24.0",
38
+ "react-router-dom": "^6.24.1",
39
39
  "request-ip": "^3.3.0",
40
- "rimraf": "^5.0.7",
40
+ "rimraf": "^5.0.8",
41
41
  "serialize-javascript": "^6.0.2",
42
42
  "serve-favicon": "^2.5.0",
43
43
  "source-map-support": "^0.5.21",
@@ -59,10 +59,10 @@
59
59
  "@dr.pogodin/babel-plugin-transform-assets": "^1.2.2",
60
60
  "@dr.pogodin/babel-preset-svgr": "^1.8.0",
61
61
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
62
- "@testing-library/dom": "^10.2.0",
62
+ "@testing-library/dom": "^10.3.1",
63
63
  "@testing-library/react": "^16.0.0",
64
64
  "@testing-library/user-event": "^14.5.2",
65
- "@tsconfig/recommended": "^1.0.6",
65
+ "@tsconfig/recommended": "^1.0.7",
66
66
  "@types/compression": "^1.7.5",
67
67
  "@types/config": "^3.3.4",
68
68
  "@types/cookie": "^0.6.0",
@@ -122,12 +122,12 @@
122
122
  "tsc-alias": "^1.8.10",
123
123
  "tstyche": "^2.0.0",
124
124
  "typed-scss-modules": "^8.0.1",
125
- "typescript": "^5.5.2",
126
- "typescript-eslint": "^7.14.1",
125
+ "typescript": "^5.5.3",
126
+ "typescript-eslint": "^7.15.0",
127
127
  "webpack": "^5.92.1",
128
128
  "webpack-dev-middleware": "^7.2.1",
129
129
  "webpack-hot-middleware": "^2.26.1",
130
- "webpack-merge": "^5.10.0",
130
+ "webpack-merge": "^6.0.1",
131
131
  "workbox-core": "^7.1.0",
132
132
  "workbox-precaching": "^7.1.0",
133
133
  "workbox-webpack-plugin": "^7.1.0"
@@ -17,6 +17,7 @@ type PropsT = {
17
17
  onMouseDown?: React.MouseEventHandler;
18
18
  openNewTab?: boolean;
19
19
  replace?: boolean;
20
+ testId?: string;
20
21
  theme: Theme<'active' | 'button' | 'disabled'>;
21
22
  // TODO: It needs a more precise typing of the object option.
22
23
  to?: object | string;
@@ -32,6 +33,7 @@ export const BaseButton: React.FunctionComponent<PropsT> = ({
32
33
  onMouseDown,
33
34
  openNewTab,
34
35
  replace,
36
+ testId,
35
37
  theme,
36
38
  to,
37
39
  }) => {
@@ -40,7 +42,7 @@ export const BaseButton: React.FunctionComponent<PropsT> = ({
40
42
  if (disabled) {
41
43
  if (theme.disabled) className += ` ${theme.disabled}`;
42
44
  return (
43
- <div className={className}>
45
+ <div className={className} data-testid={testId}>
44
46
  {children}
45
47
  </div>
46
48
  );
@@ -49,6 +51,7 @@ export const BaseButton: React.FunctionComponent<PropsT> = ({
49
51
  return (
50
52
  <Link
51
53
  className={className}
54
+ data-testid={testId}
52
55
  enforceA={enforceA}
53
56
  onClick={onClick}
54
57
  onMouseDown={onMouseDown}
@@ -64,6 +67,7 @@ export const BaseButton: React.FunctionComponent<PropsT> = ({
64
67
  return (
65
68
  <div
66
69
  className={className}
70
+ data-testid={testId}
67
71
  onClick={onClick}
68
72
  onKeyDown={onClick && ((e) => {
69
73
  if (e.key === 'Enter') onClick(e);
@@ -17,10 +17,14 @@ import S from './styles.scss';
17
17
  type PropsT = {
18
18
  cancelOnScrolling?: boolean;
19
19
  children?: ReactNode;
20
- containerStyle?: React.CSSProperties;
21
20
  dontDisableScrolling?: boolean;
22
21
  onCancel?: () => void;
22
+ style?: React.CSSProperties;
23
+ testId?: string;
23
24
  theme: Theme<'container' | 'overlay'>;
25
+
26
+ /** @deprecated */
27
+ containerStyle?: React.CSSProperties;
24
28
  };
25
29
 
26
30
  /**
@@ -40,6 +44,8 @@ const BaseModal: React.FunctionComponent<PropsT> = ({
40
44
  containerStyle,
41
45
  dontDisableScrolling,
42
46
  onCancel,
47
+ style,
48
+ testId,
43
49
  theme,
44
50
  }) => {
45
51
  const containerRef = useRef<HTMLDivElement | null>(null);
@@ -141,11 +147,12 @@ const BaseModal: React.FunctionComponent<PropsT> = ({
141
147
  <div
142
148
  aria-modal="true"
143
149
  className={theme.container}
150
+ data-testid={testId}
144
151
  onClick={(e) => e.stopPropagation()}
145
152
  onWheel={(event) => event.stopPropagation()}
146
153
  ref={containerRef}
147
154
  role="dialog"
148
- style={containerStyle}
155
+ style={style ?? containerStyle}
149
156
  >
150
157
  {children}
151
158
  </div>
@@ -30,6 +30,7 @@ const Dropdown: React.FunctionComponent<PropsT<string>> = ({
30
30
  label,
31
31
  onChange,
32
32
  options,
33
+ testId,
33
34
  theme,
34
35
  value,
35
36
  }) => {
@@ -66,12 +67,16 @@ const Dropdown: React.FunctionComponent<PropsT<string>> = ({
66
67
  </option>
67
68
  );
68
69
 
70
+ let selectClassName = theme.select;
71
+ if (!isValidValue) selectClassName += ` ${theme.invalid}`;
72
+
69
73
  return (
70
74
  <div className={theme.container}>
71
75
  { label === undefined ? null : <div className={theme.label}>{label}</div> }
72
76
  <div className={theme.dropdown}>
73
77
  <select
74
- className={theme.select}
78
+ className={selectClassName}
79
+ data-testid={testId}
75
80
  onChange={onChange}
76
81
  value={value}
77
82
  >
@@ -4,6 +4,8 @@
4
4
  .context,
5
5
  .ad.hoc {
6
6
  &.dropdown {
7
+ display: flex;
8
+ overflow: hidden;
7
9
  position: relative;
8
10
  }
9
11
 
@@ -45,7 +47,7 @@
45
47
  margin: 0 0.6em 0 1.5em;
46
48
  }
47
49
 
48
- &.option { /* Empty style */ }
50
+ &.option { color: black; }
49
51
  &.hiddenOption { display: none; }
50
52
 
51
53
  &.select {
@@ -56,6 +58,7 @@
56
58
  color: inherit;
57
59
  cursor: pointer;
58
60
  display: inline-block;
61
+ flex: 1;
59
62
  font: inherit;
60
63
  outline: none;
61
64
  padding: 0.3em 3.3em calc(0.3em + 1px) 1.2em;
@@ -70,5 +73,7 @@
70
73
  border-color: blue;
71
74
  box-shadow: 0 0 3px 1px lightblue;
72
75
  }
76
+
77
+ &.invalid { color: gray; }
73
78
  }
74
79
  }
@@ -12,6 +12,11 @@ type ThemeKeyT =
12
12
  | 'option'
13
13
  | 'select'
14
14
 
15
+ // TODO: This is currently only valid for (native) <Dropdown>,
16
+ // other kinds of selectors should be evaluated, and aligned with this
17
+ // feature, if appropriate.
18
+ | 'invalid'
19
+
15
20
  // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it
16
21
  // into a separate theme spec for that component.
17
22
  | 'upward';
@@ -33,6 +38,7 @@ export type PropsT<
33
38
  label?: React.ReactNode;
34
39
  onChange?: OnChangeT;
35
40
  options?: Readonly<OptionsT<NameT>>;
41
+ testId?: string;
36
42
  theme: Theme<ThemeKeyT>;
37
43
  value?: ValueT;
38
44
  };
@@ -66,6 +66,7 @@ export async function mockTimer(time: number) {
66
66
 
67
67
  export type MountedSceneT = HTMLElement & {
68
68
  destroy: () => void;
69
+ snapshot: () => void;
69
70
  };
70
71
 
71
72
  /**
@@ -89,6 +90,10 @@ export function mount(scene: ReactNode): MountedSceneT {
89
90
  res.remove();
90
91
  };
91
92
 
93
+ res.snapshot = () => {
94
+ expect(res).toMatchSnapshot();
95
+ };
96
+
92
97
  // NOTE: As it seems @testing-library may reset this flag to false
93
98
  // when it is simulating user events.
94
99
  global.IS_REACT_ACT_ENVIRONMENT = true;