@centreon/ui 24.4.53 → 24.4.55

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "24.4.53",
3
+ "version": "24.4.55",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -27,6 +27,14 @@ const useStyles = makeStyles()((theme: Theme) => ({
27
27
  },
28
28
  noLabelInput: {
29
29
  padding: theme.spacing(1)
30
+ },
31
+ select: {
32
+ '& > fieldset > legend': {
33
+ maxWidth: 0
34
+ },
35
+ '&.Mui-focused > fieldset > legend': {
36
+ maxWidth: '100%'
37
+ }
30
38
  }
31
39
  }));
32
40
 
@@ -83,6 +91,9 @@ const SelectField = ({
83
91
  {label && <InputLabel>{label}</InputLabel>}
84
92
  <Select
85
93
  displayEmpty
94
+ classes={{
95
+ root: classes.select
96
+ }}
86
97
  fullWidth={fullWidth}
87
98
  inputProps={{
88
99
  'aria-label': ariaLabel,
@@ -0,0 +1,27 @@
1
+ import FluidTypography from '.';
2
+
3
+ const initialize = ({ width, min, max, pref }): void => {
4
+ cy.viewport(width, 590);
5
+
6
+ cy.mount({
7
+ Component: (
8
+ <FluidTypography max={max} min={min} pref={pref} text="Unreachable" />
9
+ )
10
+ });
11
+ };
12
+
13
+ describe('FluidTypography', () => {
14
+ [500, 300, 150].forEach((width) => {
15
+ Object.entries({ max: '80px', min: '30px', pref: 10 }).forEach(
16
+ ([key, value]) => {
17
+ it(`displays the text when the viewport is ${width}px and the ${key} is ${value}`, () => {
18
+ initialize({ [key]: value, width });
19
+
20
+ cy.contains('Unreachable').should('be.visible');
21
+
22
+ cy.matchImageSnapshot();
23
+ });
24
+ }
25
+ );
26
+ });
27
+ });
@@ -40,9 +40,9 @@ basic.args = {
40
40
 
41
41
  export const with200pxWidth = FluidTypographyTemplate.bind({});
42
42
  with200pxWidth.args = {
43
- height: '200px',
43
+ height: '50%',
44
44
  text: 'Hello world',
45
- width: '200px'
45
+ width: '50%'
46
46
  };
47
47
 
48
48
  export const with20pxHeight = FluidTypographyTemplate.bind({});
@@ -1,49 +1,42 @@
1
- import { useRef } from 'react';
2
-
3
1
  import { Typography, TypographyProps } from '@mui/material';
4
2
 
5
- import useFluidResizeObserver from './useFluidResizeObserver';
6
-
7
3
  type CustomTypographyProps = Pick<TypographyProps, 'variant'>;
8
4
  export interface FluidTypographyProps extends CustomTypographyProps {
9
5
  className?: string;
6
+ containerClassName?: string;
7
+ max?: string;
8
+ min?: string;
9
+ pref?: number;
10
10
  text: string;
11
11
  }
12
12
 
13
13
  const FluidTypography = ({
14
14
  text,
15
15
  variant = 'body1',
16
- className
16
+ className,
17
+ containerClassName,
18
+ min = '10px',
19
+ max = '1000px',
20
+ pref = 19
17
21
  }: FluidTypographyProps): JSX.Element => {
18
- const containerRef = useRef<HTMLElement>();
19
- const parentRef = useRef<HTMLElement>();
20
-
21
- const size = useFluidResizeObserver({ ref: containerRef });
22
- const parentSize = useFluidResizeObserver({ isParent: true, ref: parentRef });
23
-
24
22
  return (
25
23
  <div
26
- ref={parentRef}
24
+ className={containerClassName}
27
25
  style={{
28
- height: `${parentSize.height}px`,
26
+ containerType: 'inline-size',
27
+ height: `100%`,
29
28
  width: `100%`
30
29
  }}
31
30
  >
32
- <div ref={containerRef} style={{ height: '100%', width: '100%' }}>
33
- <Typography
34
- className={className}
35
- sx={{
36
- fontSize: `clamp(10px, min(${Math.floor(
37
- size.width / 6
38
- )}px, ${Math.floor(size.height / 6)}px), min(${size.width}px, ${
39
- size.height
40
- }px))`
41
- }}
42
- variant={variant}
43
- >
44
- {text}
45
- </Typography>
46
- </div>
31
+ <Typography
32
+ className={className}
33
+ sx={{
34
+ fontSize: `clamp(${min}, ${pref}cqi, ${max})`
35
+ }}
36
+ variant={variant}
37
+ >
38
+ {text}
39
+ </Typography>
47
40
  </div>
48
41
  );
49
42
  };
@@ -22,6 +22,8 @@ const ChildComponent = (): JSX.Element => {
22
22
  <Button onClick={() => toggleFullscreen(document.body)}>
23
23
  {isFullscreenActivated ? labelExitFullscreen : labelEnterFullscreen}
24
24
  </Button>
25
+ <input id="input" />
26
+ <textarea id="textarea" />
25
27
  </div>
26
28
  );
27
29
  };
@@ -94,16 +96,35 @@ describe('Fullscreen', () => {
94
96
  .should('have.attr', 'data-fullscreenActivated', 'false')
95
97
  .should('have.attr', 'data-fullscreenEnabled', 'true');
96
98
 
97
- cy.get('#test').realPress(['Alt', 'F']);
99
+ cy.get('#test').realPress(['F']);
98
100
 
99
101
  cy.get('#test')
100
102
  .should('have.attr', 'data-fullscreenActivated', 'true')
101
103
  .should('have.attr', 'data-fullscreenEnabled', 'true');
102
104
 
103
- cy.get('#test').realPress(['Alt', 'F']);
105
+ cy.get('#test').realPress(['F']);
104
106
 
105
107
  cy.get('#test')
106
108
  .should('have.attr', 'data-fullscreenActivated', 'false')
107
109
  .should('have.attr', 'data-fullscreenEnabled', 'true');
108
110
  });
111
+
112
+ ['input', 'textarea'].forEach((tag) => {
113
+ it(`cannot toggle fullscreen feature using the shortcut when ${tag === 'input' ? 'an' : 'a'} ${tag} is focused`, () => {
114
+ initialize();
115
+
116
+ cy.get('#test')
117
+ .should('have.attr', 'data-fullscreenActivated', 'false')
118
+ .should('have.attr', 'data-fullscreenEnabled', 'true');
119
+
120
+ cy.get(`#${tag}`).focus();
121
+
122
+ cy.get('#test').realPress(['F']);
123
+
124
+ cy.get('#test')
125
+ .should('have.attr', 'data-fullscreenActivated', 'false')
126
+ .should('have.attr', 'data-fullscreenEnabled', 'true');
127
+ cy.get(`#${tag}`).should('have.value', 'F');
128
+ });
129
+ });
109
130
  });
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
- import { equals } from 'ramda';
3
+ import { equals, includes } from 'ramda';
4
4
  import { useSearchParams } from 'react-router-dom';
5
5
 
6
6
  import { useDeepCompare } from '../useMemoComponent';
@@ -16,7 +16,15 @@ export const useFullscreenListener = (): boolean => {
16
16
  useFullscreen();
17
17
 
18
18
  const toggle = (event: KeyboardEvent): void => {
19
- if (!event.altKey || !equals(event.code, 'KeyF')) {
19
+ if (
20
+ includes(document.activeElement?.tagName, ['INPUT', 'TEXTAREA']) ||
21
+ equals(
22
+ document.activeElement?.getAttribute('data-lexical-editor'),
23
+ 'true'
24
+ ) ||
25
+ equals(document.activeElement?.getAttribute('contenteditable'), 'true') ||
26
+ !equals(event.code, 'KeyF')
27
+ ) {
20
28
  return;
21
29
  }
22
30
 
@@ -24,6 +24,7 @@ interface UseInfiniteScrollListing<T> {
24
24
  interface UseInfiniteScrollListingProps<T> {
25
25
  customQueryParameters?: Array<QueryParameter>;
26
26
  decoder?: JsonDecoder.Decoder<Listing<T>>;
27
+ enabled?: boolean;
27
28
  endpoint: string;
28
29
  limit?: number;
29
30
  pageAtom: PrimitiveAtom<number>;
@@ -40,7 +41,8 @@ export const useInfiniteScrollListing = <T>({
40
41
  suspense = true,
41
42
  parameters,
42
43
  customQueryParameters,
43
- limit = 100
44
+ limit = 100,
45
+ enabled = true
44
46
  }: UseInfiniteScrollListingProps<T>): UseInfiniteScrollListing<T> => {
45
47
  const [maxPage, setMaxPage] = useState(1);
46
48
 
@@ -61,6 +63,7 @@ export const useInfiniteScrollListing = <T>({
61
63
  getQueryKey: () => [queryKeyName, page],
62
64
  isPaginated: true,
63
65
  queryOptions: {
66
+ enabled,
64
67
  refetchOnMount: false,
65
68
  refetchOnWindowFocus: false,
66
69
  suspense: suspense && equals(page, 1)
@@ -1,56 +0,0 @@
1
- import {
2
- MutableRefObject,
3
- useCallback,
4
- useEffect,
5
- useRef,
6
- useState
7
- } from 'react';
8
-
9
- interface Size {
10
- height: number;
11
- width: number;
12
- }
13
-
14
- interface UseFluidResizeObserver {
15
- isParent?: boolean;
16
- ref: MutableRefObject<HTMLElement | undefined>;
17
- }
18
-
19
- const useFluidResizeObserver = ({
20
- ref,
21
- isParent
22
- }: UseFluidResizeObserver): Size => {
23
- const [size, setSize] = useState<Size>({ height: 0, width: 0 });
24
-
25
- const observer = useRef<ResizeObserver | null>(null);
26
-
27
- const resizeObserver = useCallback(
28
- (element) => {
29
- if (observer.current) {
30
- observer.current.disconnect();
31
- }
32
-
33
- observer.current = new ResizeObserver(
34
- ([entry]: Array<ResizeObserverEntry>) => {
35
- setSize({
36
- height: entry.target?.getBoundingClientRect().height || 0,
37
- width: entry.target?.getBoundingClientRect().width || 0
38
- });
39
- }
40
- );
41
-
42
- if (element && observer.current) {
43
- observer.current.observe(element);
44
- }
45
- },
46
- [ref.current]
47
- );
48
-
49
- useEffect(() => {
50
- resizeObserver(isParent ? ref.current?.parentElement : ref.current);
51
- }, [ref.current]);
52
-
53
- return size;
54
- };
55
-
56
- export default useFluidResizeObserver;