@scality/core-ui 0.183.0 → 0.184.0

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.
@@ -2,7 +2,8 @@ type Props = {
2
2
  title: string | React.ReactNode;
3
3
  content: React.ReactNode;
4
4
  link?: string;
5
+ linkText?: string;
5
6
  };
6
- export declare const InfoMessage: ({ title, content, link }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const InfoMessage: ({ title, content, link, linkText }: Props) => import("react/jsx-runtime").JSX.Element;
7
8
  export {};
8
9
  //# sourceMappingURL=InfoMessage.component.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InfoMessage.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/infomessage/InfoMessage.component.tsx"],"names":[],"mappings":"AAMA,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IAChC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAYF,eAAO,MAAM,WAAW,6BAA8B,KAAK,4CAuB1D,CAAC"}
1
+ {"version":3,"file":"InfoMessage.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/infomessage/InfoMessage.component.tsx"],"names":[],"mappings":"AAMA,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IAChC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAYF,eAAO,MAAM,WAAW,uCAAwC,KAAK,4CAuBpE,CAAC"}
@@ -13,8 +13,8 @@ const InfoMessageContainer = styled.div `
13
13
  gap: 0.5rem;
14
14
  color: white;
15
15
  `;
16
- export const InfoMessage = ({ title, content, link }) => {
16
+ export const InfoMessage = ({ title, content, link, linkText }) => {
17
17
  const { containerRef, backgroundColor } = useComputeBackgroundColor();
18
18
  const theme = useTheme();
19
- return (_jsxs(InfoMessageContainer, { ref: containerRef, style: { backgroundColor: backgroundColor }, children: [_jsxs(Stack, { children: [_jsx(Icon, { name: "Info-circle", color: theme.infoPrimary, size: "lg" }), typeof title === 'string' ? _jsx(Text, { isEmphazed: true, children: title }) : title] }), _jsx(Text, { color: "textSecondary", isGentleEmphazed: true, children: content }), link && (_jsxs(Link, { href: link, target: "_blank", style: { alignSelf: 'flex-end' }, children: ["More info ", _jsx(Icon, { name: "External-link" })] }))] }));
19
+ return (_jsxs(InfoMessageContainer, { ref: containerRef, style: { backgroundColor: backgroundColor }, children: [_jsxs(Stack, { children: [_jsx(Icon, { name: "Info-circle", color: theme.infoPrimary, size: "lg" }), typeof title === 'string' ? _jsx(Text, { isEmphazed: true, children: title }) : title] }), _jsx(Text, { color: "textSecondary", isGentleEmphazed: true, children: content }), link && (_jsxs(Link, { href: link, target: "_blank", style: { alignSelf: 'flex-end' }, children: [linkText || 'More info', " ", _jsx(Icon, { name: "External-link" })] }))] }));
20
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/textarea/TextArea.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,sBAAsB,EAMvB,MAAM,OAAO,CAAC;AAIf,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAWvC,KAAK,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAAC;AAyJ1C,eAAO,MAAM,QAAQ;cAlKT,eAAe;YACjB,aAAa,CAAC,OAAO,CAAC;aACrB,aAAa,CAAC,QAAQ,CAAC;IAChC;;;OAGG;eACQ,OAAO;2CA2J+C,CAAC"}
1
+ {"version":3,"file":"TextArea.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/textarea/TextArea.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,sBAAsB,EAMvB,MAAM,OAAO,CAAC;AAIf,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAWvC,KAAK,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAAC;AA0J1C,eAAO,MAAM,QAAQ;cAnKT,eAAe;YACjB,aAAa,CAAC,OAAO,CAAC;aACrB,aAAa,CAAC,QAAQ,CAAC;IAChC;;;OAGG;eACQ,OAAO;2CA4J+C,CAAC"}
@@ -5,7 +5,7 @@ import { spacing } from '../../spacing';
5
5
  const TextAreaContainer = styled.textarea `
6
6
  padding: ${spacing.r12} ${spacing.r8};
7
7
  border-radius: 4px;
8
- resize: vertical;
8
+ resize: ${(props) => (props.autoGrow ? 'none' : 'vertical')};
9
9
  font-family: ${(props) => props.variant === 'code' ? 'Courier New' : 'Lato'};
10
10
  font-size: ${spacing.f14};
11
11
 
@@ -19,7 +19,7 @@ const TextAreaContainer = styled.textarea `
19
19
  css `
20
20
  width: ${props.width};
21
21
  `}
22
-
22
+
23
23
  ${(props) => props.height &&
24
24
  css `
25
25
  height: ${props.height};
@@ -28,6 +28,7 @@ const TextAreaContainer = styled.textarea `
28
28
  ${(props) => props.autoGrow &&
29
29
  css `
30
30
  overflow: hidden;
31
+ box-sizing: border-box;
31
32
  `}
32
33
 
33
34
  &:placeholder-shown {
@@ -67,7 +68,7 @@ function TextAreaElement({ rows = 3, cols = 20, width, height, variant = 'code',
67
68
  if (!textarea || !autoGrow)
68
69
  return;
69
70
  // Reset height to auto to get the correct scrollHeight
70
- textarea.style.height = 'auto';
71
+ textarea.style.height = '0px';
71
72
  // Set the height to match the content
72
73
  const newHeight = textarea.scrollHeight;
73
74
  textarea.style.height = `${newHeight}px`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scality/core-ui",
3
- "version": "0.183.0",
3
+ "version": "0.184.0",
4
4
  "description": "Scality common React component library",
5
5
  "author": "Scality Engineering",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -8,6 +8,7 @@ type Props = {
8
8
  title: string | React.ReactNode;
9
9
  content: React.ReactNode;
10
10
  link?: string;
11
+ linkText?: string;
11
12
  };
12
13
 
13
14
  const InfoMessageContainer = styled.div`
@@ -20,7 +21,7 @@ const InfoMessageContainer = styled.div`
20
21
  color: white;
21
22
  `;
22
23
 
23
- export const InfoMessage = ({ title, content, link }: Props) => {
24
+ export const InfoMessage = ({ title, content, link, linkText }: Props) => {
24
25
  const { containerRef, backgroundColor } = useComputeBackgroundColor();
25
26
  const theme = useTheme();
26
27
 
@@ -38,7 +39,7 @@ export const InfoMessage = ({ title, content, link }: Props) => {
38
39
  </Text>
39
40
  {link && (
40
41
  <Link href={link} target="_blank" style={{ alignSelf: 'flex-end' }}>
41
- More info <Icon name="External-link"></Icon>
42
+ {linkText || 'More info'} <Icon name="External-link"></Icon>
42
43
  </Link>
43
44
  )}
44
45
  </InfoMessageContainer>
@@ -1,8 +1,66 @@
1
+ import React from 'react';
1
2
  import '@testing-library/jest-dom';
2
- import { render } from '@testing-library/react';
3
+ import { render, screen } from '@testing-library/react';
3
4
  import { coreUIAvailableThemes } from '../../style/theme';
4
5
  import { CoreUiThemeProvider } from '../coreuithemeprovider/CoreUiThemeProvider';
5
6
  import { useComputeBackgroundColor } from './InfoMessageUtils';
7
+ import { InfoMessage } from './InfoMessage.component';
8
+ import { getWrapper } from '../../testUtils';
9
+
10
+ describe('InfoMessage', () => {
11
+ const selectors = {
12
+ title: () => screen.getByText('Title'),
13
+ content: () => screen.getByText('Content'),
14
+ defaultLinkText: () => screen.getByText('More info'),
15
+ link: () => screen.getByRole('link'),
16
+ linkText: () => screen.getByText('Link text'),
17
+ };
18
+ it('should render', () => {
19
+ const { Wrapper } = getWrapper();
20
+ render(<InfoMessage title="Title" content="Content" />, {
21
+ wrapper: Wrapper,
22
+ });
23
+ expect(selectors.title()).toBeInTheDocument();
24
+ expect(selectors.content()).toBeInTheDocument();
25
+ });
26
+ it('should render with link and default link text', () => {
27
+ const { Wrapper } = getWrapper();
28
+ render(
29
+ <InfoMessage
30
+ title="Title"
31
+ content="Content"
32
+ link="https://www.google.com"
33
+ />,
34
+ {
35
+ wrapper: Wrapper,
36
+ },
37
+ );
38
+ expect(selectors.title()).toBeInTheDocument();
39
+ expect(selectors.content()).toBeInTheDocument();
40
+ expect(selectors.link()).toBeInTheDocument();
41
+ expect(selectors.defaultLinkText()).toBeInTheDocument();
42
+ expect(selectors.link()).toHaveAttribute('href', 'https://www.google.com');
43
+ });
44
+ it('should render with correct link text', () => {
45
+ const { Wrapper } = getWrapper();
46
+ render(
47
+ <InfoMessage
48
+ title="Title"
49
+ content="Content"
50
+ link="https://www.google.com"
51
+ linkText="Link text"
52
+ />,
53
+ {
54
+ wrapper: Wrapper,
55
+ },
56
+ );
57
+ expect(selectors.title()).toBeInTheDocument();
58
+ expect(selectors.content()).toBeInTheDocument();
59
+ expect(selectors.link()).toBeInTheDocument();
60
+ expect(selectors.linkText()).toBeInTheDocument();
61
+ expect(selectors.link()).toHaveAttribute('href', 'https://www.google.com');
62
+ });
63
+ });
6
64
 
7
65
  describe('useComputeBackgroundColor', () => {
8
66
  const SUT = jest.fn();
@@ -32,7 +32,7 @@ const TextAreaContainer = styled.textarea<{
32
32
  }>`
33
33
  padding: ${spacing.r12} ${spacing.r8};
34
34
  border-radius: 4px;
35
- resize: vertical;
35
+ resize: ${(props) => (props.autoGrow ? 'none' : 'vertical')};
36
36
  font-family: ${(props) =>
37
37
  props.variant === 'code' ? 'Courier New' : 'Lato'};
38
38
  font-size: ${spacing.f14};
@@ -49,7 +49,7 @@ const TextAreaContainer = styled.textarea<{
49
49
  css`
50
50
  width: ${props.width};
51
51
  `}
52
-
52
+
53
53
  ${(props) =>
54
54
  props.height &&
55
55
  css`
@@ -60,6 +60,7 @@ const TextAreaContainer = styled.textarea<{
60
60
  props.autoGrow &&
61
61
  css`
62
62
  overflow: hidden;
63
+ box-sizing: border-box;
63
64
  `}
64
65
 
65
66
  &:placeholder-shown {
@@ -118,7 +119,7 @@ function TextAreaElement(
118
119
  if (!textarea || !autoGrow) return;
119
120
 
120
121
  // Reset height to auto to get the correct scrollHeight
121
- textarea.style.height = 'auto';
122
+ textarea.style.height = '0px';
122
123
 
123
124
  // Set the height to match the content
124
125
  const newHeight = textarea.scrollHeight;
@@ -68,6 +68,14 @@ export const RowsAndColsSet = {
68
68
  },
69
69
  };
70
70
 
71
+ export const AutoGrowShortText = {
72
+ args: {
73
+ autoGrow: true,
74
+ defaultValue: 'Hello World!',
75
+ width: '400px',
76
+ },
77
+ };
78
+
71
79
  /**
72
80
  * Auto-growing textarea adjusts its height based on content
73
81
  * Perfect for displaying commands or long text where you want the entire content visible