@indico-data/design-system 2.45.4 → 2.45.5

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": "@indico-data/design-system",
3
- "version": "2.45.4",
3
+ "version": "2.45.5",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "lib/index.js",
@@ -126,8 +126,9 @@ const meta: Meta = {
126
126
  category: 'State Props',
127
127
  },
128
128
  defaultValue: { summary: false },
129
- description:
130
- 'Disables the button and shows a load spinner on the left hand side of the button children',
129
+ description: `Disables the button and shows a load spinner on the left hand side of the button children by default.
130
+ If iconLeft is passed, the loading icon will be displayed on the left hand side of the iconLeft.
131
+ If iconRight is passed, the loading icon will be displayed on the right hand side of the iconRight.`,
131
132
  },
132
133
  isDisabled: {
133
134
  control: 'boolean',
@@ -416,8 +417,18 @@ export const Loading: Story = {
416
417
  </Button>
417
418
  </Col>
418
419
  <Col xs={6} sm={4} md={3} lg={2} className="mb-3">
420
+ <Button {...args} variant="action" iconRight="thumbs-up">
421
+ Icon Right
422
+ </Button>
423
+ </Col>
424
+ <Col xs={6} sm={4} md={3} lg={2} className="mb-3">
425
+ <span className="mr-2">Icon Only (Left)</span>
419
426
  <Button {...args} variant="action" iconLeft="thumbs-up" />
420
427
  </Col>
428
+ <Col xs={6} sm={4} md={3} lg={2} className="mb-3">
429
+ <span className="mr-2">Icon Only (Right)</span>
430
+ <Button {...args} variant="action" iconRight="thumbs-up" />
431
+ </Col>
421
432
  </Row>
422
433
  ),
423
434
  };
@@ -59,19 +59,19 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =>
59
59
  onKeyDown={onKeyDown}
60
60
  {...rest}
61
61
  >
62
- {/* Loading Icon */}
63
- {isLoading && (
62
+ {/* Loading Icon on the left (default) */}
63
+ {isLoading && !iconRight && (
64
64
  <Icon
65
65
  name="indico-o"
66
66
  style={{ animation: 'spin 1s linear infinite' }}
67
- className="mr-2"
67
+ className={children ? 'mr-2' : ''}
68
68
  ariaLabel="Loading..."
69
69
  size={size}
70
70
  />
71
71
  )}
72
72
 
73
73
  {/* Left Icon */}
74
- {iconLeft && (
74
+ {iconLeft && !isLoading && (
75
75
  <Icon
76
76
  name={iconLeft}
77
77
  className={children ? 'mr-2' : ''}
@@ -84,7 +84,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =>
84
84
  {children}
85
85
 
86
86
  {/* Right Icon */}
87
- {iconRight && (
87
+ {iconRight && !isLoading && (
88
88
  <Icon
89
89
  name={iconRight}
90
90
  className={children ? 'ml-2' : ''}
@@ -92,6 +92,17 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =>
92
92
  size={size}
93
93
  />
94
94
  )}
95
+
96
+ {/* Loading Icon on the right */}
97
+ {isLoading && iconRight && (
98
+ <Icon
99
+ name="indico-o"
100
+ style={{ animation: 'spin 1s linear infinite' }}
101
+ className={children ? 'ml-2' : ''}
102
+ ariaLabel="Loading..."
103
+ size={size}
104
+ />
105
+ )}
95
106
  </button>
96
107
  );
97
108
  });
@@ -45,7 +45,7 @@ describe('Button', () => {
45
45
  expect(button).toHaveClass('btn--pill');
46
46
  });
47
47
 
48
- it('loads the corresponding loading class and shows loading icon', () => {
48
+ it('loads the corresponding loading class and shows loading icon when isLoading is true', () => {
49
49
  render(
50
50
  <Button isLoading onClick={onClick} ariaLabel="btn">
51
51
  Button
@@ -60,6 +60,43 @@ describe('Button', () => {
60
60
  expect(loadingIcon).toHaveClass('mr-2');
61
61
  });
62
62
 
63
+ it('displays the loading icon on the left when isLoading and iconLeft exists and hides the iconLeft', () => {
64
+ render(
65
+ <Button isLoading iconLeft="check" onClick={onClick} ariaLabel="btn">
66
+ Button
67
+ </Button>,
68
+ );
69
+ const loadingIcon = screen.getByLabelText('Loading...');
70
+ const iconLeft = screen.queryByLabelText('check Icon');
71
+
72
+ expect(loadingIcon).toHaveClass('mr-2');
73
+ expect(iconLeft).not.toBeInTheDocument();
74
+ });
75
+
76
+ it('displays the loading icon on the right when isLoading and iconRight exists and hides the iconRight', () => {
77
+ render(
78
+ <Button isLoading iconRight="check" onClick={onClick} ariaLabel="btn">
79
+ Button
80
+ </Button>,
81
+ );
82
+ const loadingIcon = screen.getByLabelText('Loading...');
83
+ const iconRight = screen.queryByLabelText('check Icon');
84
+
85
+ expect(loadingIcon).toHaveClass('ml-2');
86
+ expect(iconRight).not.toBeInTheDocument();
87
+ });
88
+
89
+ it('does not apply a margin to the loading icon when no children are present', () => {
90
+ render(<Button isLoading iconLeft="check" onClick={onClick} ariaLabel="btn" />);
91
+ const loadingIcon = screen.getByLabelText('Loading...');
92
+ expect(loadingIcon).not.toHaveClass('mr-2');
93
+ expect(loadingIcon).not.toHaveClass('ml-2');
94
+
95
+ render(<Button isLoading iconRight="check" onClick={onClick} ariaLabel="btn" />);
96
+ expect(loadingIcon).not.toHaveClass('mr-2');
97
+ expect(loadingIcon).not.toHaveClass('ml-2');
98
+ });
99
+
63
100
  it('does not apply the loading class when not loading', () => {
64
101
  render(
65
102
  <Button isLoading={false} onClick={onClick} ariaLabel="btn">