@bytebrand/fe-ui-core 4.2.66 → 4.2.67

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,49 @@
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import MaterialAutocomplete from "../../../../source/components/_common/MaterialAutocomplete/MaterialAutocomplete";
4
+ let value: any = null;
5
+ const setValue = jest.fn();
6
+ const materialAutocompleteProps = {
7
+ onChange: setValue,
8
+ label: 'test label',
9
+ value: value,
10
+ error: false,
11
+ required: true,
12
+ items: [
13
+ { value: '+49', label: '+49', icon: 'de' },
14
+ { value: '+43', label: '+43', icon: 'at' }
15
+ ],
16
+ listWithImage: 'true'
17
+ }
18
+ describe('MaterialAutocomplete', () => {
19
+ it('renders component without errors', () => {
20
+ const { container, getByRole, getByText } = render(<MaterialAutocomplete {...materialAutocompleteProps} />)
21
+ expect(container).toBeInTheDocument();
22
+ const input = getByRole('combobox');
23
+ const button = getByRole('button');
24
+ fireEvent.click(button);
25
+ const listItem = getByText('+43');
26
+ fireEvent.click(listItem);
27
+ expect(input).toHaveAttribute('value', '+43');
28
+ })
29
+
30
+ it('renders component, open list and choose any option from list', () => {
31
+ const { getByRole, getByText } = render(<MaterialAutocomplete {...materialAutocompleteProps} />)
32
+ const input = getByRole('combobox');
33
+ const button = getByRole('button');
34
+ fireEvent.click(button);
35
+ const listItem = getByText('+43');
36
+ fireEvent.click(listItem);
37
+ expect(input).toHaveAttribute('value', '+43');
38
+ })
39
+
40
+ it('renders component, open list and check if we have icons in list, when "listWithImage: true"', () => {
41
+ const { getByRole, container } = render(<MaterialAutocomplete {...materialAutocompleteProps} />)
42
+ const button = getByRole('button');
43
+ fireEvent.click(button);
44
+ const iconDe = container.querySelector('[id="flag-icons-de"]');
45
+ const iconAt = container.querySelector('[id="flag-icons-at"]');
46
+ expect(iconDe).toBeInTheDocument();
47
+ expect(iconAt).toBeInTheDocument();
48
+ })
49
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/fe-ui-core",
3
- "version": "4.2.66",
3
+ "version": "4.2.67",
4
4
  "description": "UI components for the auto.de project",
5
5
  "main": "index.ts",
6
6
  "module": "dist/common.js",
@@ -114,9 +114,9 @@ export const Theme = createTheme({
114
114
  },
115
115
  MuiInputLabel: {
116
116
  styleOverrides: {
117
- root: ({ ownerState }) => ({
117
+ root: ({ ownerState: { size } }: { ownerState: { size?: string } }) => ({
118
118
  maxWidth: 'calc(100% - 28px)',
119
- ...(ownerState.size === 'custom' && { // tslint:disable-line
119
+ ...(size === 'custom' && {
120
120
  marginTop: isMobileOnly ? '0px' :'-4px',
121
121
  ['&.MuiInputLabel-shrink, &.Mui-focused']: {
122
122
  marginTop: 0
@@ -127,8 +127,8 @@ export const Theme = createTheme({
127
127
  },
128
128
  MuiOutlinedInput: {
129
129
  styleOverrides: {
130
- root: ({ ownerState }) => ({
131
- ...(ownerState.size === 'small' && {
130
+ root: ({ ownerState: { size, name } }: { ownerState: { size?: string, name?: string } }) => ({
131
+ ...(size === 'small' && {
132
132
  paddingRight: '0 !important',
133
133
  flexWrap: 'nowrap !important',
134
134
  backgroundColor: '#fff',
@@ -150,11 +150,11 @@ export const Theme = createTheme({
150
150
  opacity:'0.38'
151
151
  },
152
152
  ['& .MuiAutocomplete-input']: {
153
- ...(ownerState.name === 'mobileSearch' && {
153
+ ...(name === 'mobileSearch' && {
154
154
  textAlign: isMobileOnly ? 'right !important' : 'left'
155
155
  })
156
156
  },
157
- ...(ownerState.size === 'custom' && {
157
+ ...(size === 'custom' && {
158
158
  height: isMobileOnly ? 56 : 48,
159
159
  boxSizing: 'border-box',
160
160
  backgroundColor: '#fff',
@@ -164,7 +164,7 @@ export const Theme = createTheme({
164
164
  padding: '5.5px 4px 7.5px 6px !important'
165
165
  }
166
166
  }),
167
- ...(ownerState.name === 'mobileSearch' && {
167
+ ...(name === 'mobileSearch' && {
168
168
  color: isMobileOnly ? '#005ccb' : 'rgba(0, 0, 0, 0.87)',
169
169
  backgroundColor: isMobileOnly ? 'transparent' : '#fff',
170
170
  paddingRight: isMobileOnly ? '33px !important' : '42px !important',
@@ -181,7 +181,7 @@ export const Theme = createTheme({
181
181
  borderWidth: isMobileOnly ? 0 : 1
182
182
  }
183
183
  })
184
- })
184
+ } as any)
185
185
  }
186
186
  }
187
187
  }
@@ -11,6 +11,7 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
11
11
  import { Theme, ArrowSelect, CheckboxLabel } from './MaterialAutocomplete.styled';
12
12
  import isEqual from 'lodash/isEqual';
13
13
  import IconSVG from '../IconSVG/IconSVG';
14
+ import { isMobileOnly } from 'react-device-detect';
14
15
 
15
16
  export interface IItems {
16
17
  value: string | number;
@@ -100,11 +101,8 @@ const MaterialAutocomplete: React.FC<IMaterialAutocompleteProps> = ({
100
101
  multiple={multiple}
101
102
  handleHomeEndKeys
102
103
  value={value}
103
- name={name}
104
- error={error ? error.toString() : ''}
105
104
  readOnly={readOnly}
106
- listwithimage={listWithImage}
107
- onChange={(e, newValue, reason: string, details?: { option: any }) => {
105
+ onChange={(e, newValue, _: string, details?: { option: any }) => {
108
106
  e.persist();
109
107
  if (typeof newValue === 'string') {
110
108
  onChange(newValue);
@@ -150,17 +148,16 @@ const MaterialAutocomplete: React.FC<IMaterialAutocompleteProps> = ({
150
148
  }}
151
149
  options={multiple ? items.map(option => option.label) : items}
152
150
  ListboxProps={{
153
- sx: {
154
- maxHeight: {
155
- xs: MOBILE_ITEM_HEIGHT * MENU_ITEMS,
156
- sm: ITEM_HEIGHT * MENU_ITEMS
157
- }
151
+ style: {
152
+ maxHeight: isMobileOnly ?
153
+ MOBILE_ITEM_HEIGHT * MENU_ITEMS
154
+ : ITEM_HEIGHT * MENU_ITEMS
158
155
  }
159
156
  }}
160
157
  forcePopupIcon
161
158
  popupIcon={disableIcon ? '' : <ArrowSelect name='arrowSelect' customDimensions />}
162
159
  isOptionEqualToValue={(option, value) => option.value === value}
163
- renderOption={(props, option) => {
160
+ renderOption={(props: any, option) => {
164
161
  if (multiple) {
165
162
  return (
166
163
  <li {...props}>
@@ -218,8 +215,7 @@ const MaterialAutocomplete: React.FC<IMaterialAutocompleteProps> = ({
218
215
  InputProps={{ ...params.InputProps, readOnly }}
219
216
  />
220
217
  )}
221
- >
222
- </Autocomplete>
218
+ />
223
219
  </ThemeProvider>
224
220
  );
225
221
  };
package/tsconfig.json CHANGED
@@ -58,6 +58,8 @@
58
58
  },
59
59
  "exclude": [
60
60
  "node_modules",
61
- "static"
61
+ "static",
62
+ "__tests__",
63
+ "**/*.js"
62
64
  ]
63
65
  }
package/tslint.json CHANGED
@@ -20,7 +20,6 @@
20
20
  "no-console": [true, "warn", "error"],
21
21
  "switch-default": true,
22
22
  "no-empty-interface": true,
23
- // "no-magic-numbers": [true, 0, -1, 1, 2, 10, 8, 16],
24
23
  "no-parameter-reassignment": true,
25
24
  "no-duplicate-switch-case": true,
26
25
  "no-duplicate-imports": true,