@zohodesk/components 1.0.0-temp-259.2 → 1.0.0-temp-259.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.26
4
+
5
+ - **v1/Button** — Removed the `bgAppearance`, `borderAppearance`, `paletteShade`, and `isReadOnly` props. Use the `appearance`, `hoverAppearance`, and `selectedAppearance` objects instead. Added new `*Lighter` palette variants to support lighter button appearances.
6
+
3
7
  ## 1.6.25
4
8
 
5
9
  - **v1/shared** - `Loader` component renamed to `Spinner`
package/README.md CHANGED
@@ -1,7 +1,25 @@
1
- # DOT Style Guide
1
+ # @zohodesk/components
2
2
 
3
- Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development across projects.
3
+ Reusable React UI primitives for building DOT applications. This package is part of the **DOT System** (**D**esign **O**ptimization **T**hinking).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @zohodesk/components
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Import the UI building blocks you need from `@zohodesk/components` and use them in your React app for common interface patterns, including:
14
+
15
+ - Buttons, inputs, and form controls
16
+ - Overlays, dialogs, and selection patterns
17
+ - Avatars, tabs, and other shared UI primitives
18
+
19
+ ```js
20
+ import * as components from '@zohodesk/components';
21
+ ```
4
22
 
5
23
  ## Changelog
6
24
 
7
- See [CHANGELOG.md](./CHANGELOG.md) for details on release history and updates.
25
+ See [CHANGELOG.md](https://unpkg.com/@zohodesk/components/CHANGELOG.md) for details on release history and updates.
@@ -200,7 +200,8 @@ const Button = /*#__PURE__*/forwardRef(function Button(props, ref) {
200
200
  a11yAttributes,
201
201
  customId,
202
202
  testId,
203
- dataSelectorId
203
+ dataSelectorId,
204
+ customClass
204
205
  } = props;
205
206
  const isLoading = status === STATUS.LOADING;
206
207
  const isSuccess = status === STATUS.SUCCESS;
@@ -208,7 +209,7 @@ const Button = /*#__PURE__*/forwardRef(function Button(props, ref) {
208
209
  const overlayActive = (isLoading || isSuccess) && loaderPlacement === LOADER_PLACEMENT.OVERLAY;
209
210
  const classNames = useMemo(() => cssJSLogic({
210
211
  props
211
- }), [palette, appearance, hoverAppearance, selectedAppearance, size, variant, status, isDisabled, isSelected, shape, loaderPlacement, disabledAppearance, props.customClass]);
212
+ }), [palette, appearance, hoverAppearance, selectedAppearance, size, variant, status, isDisabled, isSelected, shape, loaderPlacement, disabledAppearance, customClass]);
212
213
 
213
214
  const handleClick = event => {
214
215
  if (isDisabledState) return;
@@ -18,14 +18,49 @@ import Button from '@zohodesk/components/es/v1/Button/Button';
18
18
  </Button>
19
19
  ```
20
20
 
21
- ### With Palette Variants
21
+ ### With Palette
22
22
 
23
23
  ```jsx
24
- <Button palette="primary">Save</Button>
24
+ <Button palette="brand">Save</Button>
25
25
  <Button palette="danger">Delete</Button>
26
26
  <Button palette="success">Confirm</Button>
27
27
  ```
28
28
 
29
+ ### With Appearance
30
+
31
+ `appearance`, `hoverAppearance`, and `selectedAppearance` are objects with optional `bg`, `border`, and `text` keys. Each key accepts `true` (use palette color), `false` (suppress), or a palette name string.
32
+
33
+ ```jsx
34
+ <Button palette="brand" appearance={{ bg: false, border: true }}>
35
+ Ghost
36
+ </Button>
37
+
38
+ <Button
39
+ palette="brand"
40
+ appearance={{ bg: false, border: true }}
41
+ hoverAppearance={{ bg: false, border: true }}
42
+ selectedAppearance={{ bg: false, border: true }}
43
+ >
44
+ Ghost with states
45
+ </Button>
46
+ ```
47
+
48
+ ### Using Presets
49
+
50
+ ```jsx
51
+ import {
52
+ BRAND_GHOST,
53
+ BRAND_TEXT_ONLY,
54
+ SECONDARY_GHOST_BRAND_TINTED_ONSELECT,
55
+ BRAND_TINTED_OUTLINE,
56
+ BRAND_TEXT_TINTED_HOVER
57
+ } from '@zohodesk/components/es/v1/Button/constants/presets';
58
+
59
+ <Button {...BRAND_GHOST}>Brand Ghost</Button>
60
+ <Button {...BRAND_TEXT_ONLY}>Brand Text Only</Button>
61
+ <Button {...SECONDARY_GHOST_BRAND_TINTED_ONSELECT}>Secondary Ghost</Button>
62
+ ```
63
+
29
64
  ### With Icon
30
65
 
31
66
  ```jsx
@@ -36,76 +71,104 @@ import Button from '@zohodesk/components/es/v1/Button/Button';
36
71
  </Button>
37
72
  ```
38
73
 
39
- ### Loading State
74
+ ### Loading / Success State
40
75
 
41
76
  ```jsx
42
- <Button status="loading" loaderPlacement="overlay">
43
- Saving...
44
- </Button>
45
-
46
- <Button status="loading" loaderPlacement="start">
47
- Loading
48
- </Button>
77
+ <Button status="loading" loaderPlacement="overlay">Saving...</Button>
78
+ <Button status="loading" loaderPlacement="start">Loading</Button>
79
+ <Button status="success">Done</Button>
49
80
  ```
50
81
 
51
- ### Disabled / Read Only
82
+ ### Disabled
52
83
 
53
84
  ```jsx
54
85
  <Button isDisabled>Disabled</Button>
55
- <Button isReadOnly>Read Only</Button>
86
+ <Button isDisabled disabledAppearance="strike">Disabled Strike</Button>
87
+ ```
88
+
89
+ ### Shape
90
+
91
+ ```jsx
92
+ <Button shape="pill">Pill</Button>
93
+ <Button shape="rectangle">Rectangle</Button>
94
+ <Button shape="roundedRectangle">Rounded</Button>
56
95
  ```
57
96
 
58
97
  ## Props
59
98
 
60
99
  | Prop | Type | Default | Description |
61
100
  |---|---|---|---|
62
- | `customId` | `string` | — | `data-id` attribute for automation |
63
- | `testId` | `string` | — | `data-test-id` attribute for testing |
64
- | `palette` | `oneOf: default, primary, secondary, danger, success` | `default` | Color palette |
65
- | `appearance` | `array of: border, text, bg` | `['bg', 'border']` | Which treatments are colored at rest |
66
- | `hoverAppearance` | `array of: border, text, bg` | `['bg', 'border']` | Which treatments are colored on hover/focus/active |
67
- | `selectedAppearance` | `array of: border, text, bg` | `['bg', 'border']` | Which treatments are colored when `isSelected` |
101
+ | `palette` | `oneOf: brand, brandLighter, info, infoLighter, secondary, secondaryLighter, danger, dangerLighter, success, successLighter, warning, warningLighter` | `''` | Color palette |
102
+ | `appearance` | `{ bg?, border?, text? }` | `{ bg: true, text: true }` | Color treatments at rest. Values: `true`, `false`, or a palette name |
103
+ | `hoverAppearance` | `{ bg?, border?, text? }` | `{ bg: true, text: true }` | Color treatments on hover/focus/active |
104
+ | `selectedAppearance` | `{ bg?, border?, text? }` | `{ bg: true, text: true }` | Color treatments when `isSelected` is true |
68
105
  | `variant` | `oneOf: text, icon, iconWithText` | `text` | Display variant |
69
106
  | `size` | `oneOf: small, medium, large, full` | `medium` | Size variant |
70
107
  | `status` | `oneOf: default, loading, success` | `default` | Status state |
71
- | `loaderPlacement` | `oneOf: start, end, overlay` | `overlay` | Where loader appears |
108
+ | `loaderPlacement` | `oneOf: start, end, overlay` | `overlay` | Where the loader appears |
109
+ | `shape` | `oneOf: pill, rectangle, roundedRectangle` | `roundedRectangle` | Border shape |
72
110
  | `iconName` | `string` | — | Icon name from `@zohodesk/icons` |
73
111
  | `iconSize` | `number` | `16` | Icon size in pixels |
74
112
  | `iconPlacement` | `oneOf: left, right` | `left` | Icon position relative to text |
75
- | `paletteShade` | `oneOf: default, lighter` | `default` | Shade variant |
76
- | `disabledAppearance` | `oneOf: none, dull, strike` | `dull` | Disabled visual style |
113
+ | `disabledAppearance` | `oneOf: none, dull, strike` | `dull` | Visual style when disabled |
114
+ | `isDisabled` | `bool` | `false` | Disables the button |
115
+ | `isSelected` | `bool` | `false` | Selected/pressed state (`aria-pressed`) |
116
+ | `type` | `oneOf: button, submit, reset` | `button` | HTML button type |
117
+ | `onClick` | `func` | — | Click handler (suppressed when disabled or loading) |
118
+ | `title` | `string` | — | Tooltip / `data-title` attribute |
119
+ | `children` | `node` | — | Button label content |
77
120
  | `renderIcon` | `node \| func` | — | Custom icon render slot |
78
121
  | `renderBefore` | `node \| func` | — | Slot before main content |
79
122
  | `renderAfter` | `node \| func` | — | Slot after main content |
80
123
  | `renderLoader` | `node \| func` | — | Custom loader render slot |
81
124
  | `renderSuccess` | `node \| func` | — | Custom success render slot |
82
- | `children` | `node` | — | Button text content |
83
- | `type` | `oneOf: button, submit, reset` | `button` | HTML button type |
84
- | `onClick` | `func` | — | Click event handler |
85
- | `isDisabled` | `bool` | `false` | Disables the button |
86
- | `isReadOnly` | `bool` | `false` | Read-only state |
87
- | `isSelected` | `bool` | `false` | Selected/pressed state |
88
- | `isRounded` | `bool` | `false` | Rounded border radius |
89
- | `title` | `string` | — | Title/tooltip text |
125
+ | `customId` | `string` | — | `data-id` attribute |
126
+ | `testId` | `string` | — | `data-test-id` attribute |
127
+ | `dataSelectorId` | `string` | — | `data-selector-id` attribute |
128
+ | `a11yAttributes` | `object` | `{}` | Extra ARIA/accessibility attributes spread onto `<button>` |
129
+ | `customClass` | `{ wrapper?, text?, icon?, loader?, success? }` | `{}` | CSS class overrides per part |
130
+ | `customProps` | `{ text?, icon? }` | `{}` | Extra props forwarded to text/icon sub-elements |
131
+ | `customAttributes` | `{ button?, contentWrapper?, loader?, success?, icon?, text? }` | `{}` | Extra HTML attributes per internal element |
132
+
133
+ ## Presets
134
+
135
+ Ready-made palette + appearance combinations exported from `constants/presets`:
136
+
137
+ | Name | Palette | Appearance | Description |
138
+ |---|---|---|---|
139
+ | `BRAND_GHOST` | `brand` | `{ bg: false, border: true }` | Transparent bg, brand border |
140
+ | `BRAND_TEXT_ONLY` | `brand` | `{ bg: false }` | Text only, no border |
141
+ | `BRAND_TINTED_OUTLINE` | `brandLighter` | `{ border: true }` | Tinted fill, brand border |
142
+ | `SUCCESS_GHOST` | `success` | `{ bg: false, border: true }` | Transparent bg, success border |
143
+ | `SUCCESS_TEXT_ONLY` | `success` | `{ bg: false }` | Text only, no border |
144
+ | `SUCCESS_TINTED_OUTLINE` | `successLighter` | `{ border: true }` | Tinted fill, success border |
145
+ | `SECONDARY_GHOST_BRAND_TINTED_ONSELECT` | `secondary` | `{ bg: false, border: true }` | Secondary ghost; selected state switches to brand tint |
146
+ | `BLACK_TEXT_BRAND_ONHOVER` | `brand` | `{ bg: false, text: 'black' }` | Black text, brand color on hover |
147
+ | `BRAND_BG_ONSELECT` | `brand` | `{ bg: false, border: true }` | Ghost without a defined selected state |
148
+ | `BRAND_TEXT_TINTED_HOVER` | `brandLighter` | `{ bg: false }` | Ghost that becomes tinted on hover |
149
+ | `BRAND_TEXT_TINTED_DANGER_HOVER` | `brandLighter` | `{ bg: false }` | Ghost that becomes danger-tinted on hover |
90
150
 
91
151
  ## Customization
92
152
 
93
153
  ### Parts
94
154
 
95
- | Part | Element | Description |
155
+ | Part key | Element | Description |
96
156
  |---|---|---|
97
- | `wrapper` | `<button>` root | The outermost button element |
98
- | `text` | Typography | The text label |
99
-
100
- ### CSS Custom Properties
157
+ | `button` | `<button>` | Outermost button element |
158
+ | `contentWrapper` | Inner `<Flex>` | Wraps icon + text content |
159
+ | `text` | `<Typography>` | Text label |
160
+ | `icon` | `<Icon>` | Icon element |
161
+ | `loader` | `<Flex>` | Loader wrapper |
162
+ | `success` | `<Flex>` | Success tick wrapper |
101
163
 
102
- The `.varClass` block in `Button.module.css` defines local custom properties that size variants override:
164
+ Pass class overrides via `customClass`, extra props via `customProps`, or arbitrary HTML attributes via `customAttributes`.
103
165
 
104
- | Property | Default | Description |
105
- |---|---|---|
106
- | `--local-Button-radius` | `4px` | Border radius |
107
- | `--local-Button-gap` | `8px` | Content gap |
108
- | `--local-Button-padding-block` | `6px` | Block padding |
109
- | `--local-Button-padding-inline` | `15px` | Inline padding |
110
- | `--local-Button-min-width` | `90px` | Minimum width |
111
- | `--local-Button-spinner-size` | `16px` | Spinner/tick size |
166
+ ```jsx
167
+ <Button
168
+ customClass={{ wrapper: 'myBtn', text: 'myBtnText' }}
169
+ customAttributes={{ button: { 'data-analytics': 'save' } }}
170
+ a11yAttributes={{ 'aria-label': 'Save document' }}
171
+ >
172
+ Save
173
+ </Button>
174
+ ```
@@ -1,12 +1,16 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
1
3
  import React from 'react';
2
- import { cleanup, render, screen } from '@testing-library/react';
4
+ import { cleanup, render } from '@testing-library/react';
3
5
  import userEvent from '@testing-library/user-event';
4
- import Button from "../Button";
6
+ import Button from "../index";
5
7
  import '@testing-library/jest-dom';
8
+ import { PALETTE, VARIANT, SIZE, STATUS, LOADER_PLACEMENT, SHAPE, DISABLED_APPEARANCE, BUTTON_TYPE } from "../constants";
9
+ import { BRAND_GHOST, BRAND_TEXT_ONLY, BRAND_TINTED_OUTLINE, SUCCESS_GHOST, SUCCESS_TEXT_ONLY, SUCCESS_TINTED_OUTLINE, SECONDARY_GHOST_BRAND_TINTED_ONSELECT, BLACK_TEXT_BRAND_ONHOVER, BRAND_BG_ONSELECT, BRAND_TEXT_TINTED_HOVER, BRAND_TEXT_TINTED_DANGER_HOVER } from "../constants/presets";
6
10
  afterEach(() => {
7
11
  cleanup();
8
12
  });
9
- describe('Button - Component', () => {
13
+ describe('Button', () => {
10
14
  test('Should render with the basic set of default props', () => {
11
15
  const {
12
16
  asFragment
@@ -19,8 +23,7 @@ describe('Button - Component', () => {
19
23
  } = render( /*#__PURE__*/React.createElement(Button, null, "Click Me"));
20
24
  expect(asFragment()).toMatchSnapshot();
21
25
  });
22
- const palette = ['default', 'primary', 'secondary', 'danger', 'success'];
23
- test.each(palette)('Should render palette of buttons - %s', palette => {
26
+ test.each(Object.values(PALETTE))('Should render palette of buttons - %s', palette => {
24
27
  const {
25
28
  asFragment
26
29
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -28,34 +31,46 @@ describe('Button - Component', () => {
28
31
  }));
29
32
  expect(asFragment()).toMatchSnapshot();
30
33
  });
31
- const appearanceCombos = [['bg'], ['border'], ['text'], ['bg', 'border'], []];
32
- test.each(appearanceCombos.map(combo => [combo]))('Should render appearance of buttons - %s', appearance => {
34
+ const appearanceCombos = [{
35
+ bg: true,
36
+ text: 'black'
37
+ }, {
38
+ border: true
39
+ }, {
40
+ text: true
41
+ }, {
42
+ bg: false,
43
+ border: true
44
+ }, {}];
45
+ test.each(appearanceCombos.map(combo => [combo]))('Should render appearance of buttons - %o', appearance => {
33
46
  const {
34
47
  asFragment
35
48
  } = render( /*#__PURE__*/React.createElement(Button, {
49
+ palette: PALETTE.BRAND,
36
50
  appearance: appearance
37
51
  }));
38
52
  expect(asFragment()).toMatchSnapshot();
39
53
  });
40
- test.each(appearanceCombos.map(combo => [combo]))('Should render hoverAppearance of buttons - %s', appearance => {
54
+ test.each(appearanceCombos.map(combo => [combo]))('Should render hoverAppearance of buttons - %o', appearance => {
41
55
  const {
42
56
  asFragment
43
57
  } = render( /*#__PURE__*/React.createElement(Button, {
58
+ palette: PALETTE.BRAND,
44
59
  hoverAppearance: appearance
45
60
  }));
46
61
  expect(asFragment()).toMatchSnapshot();
47
62
  });
48
- test.each(appearanceCombos.map(combo => [combo]))('Should render selectedAppearance of buttons - %s', appearance => {
63
+ test.each(appearanceCombos.map(combo => [combo]))('Should render selectedAppearance of buttons - %o', appearance => {
49
64
  const {
50
65
  asFragment
51
66
  } = render( /*#__PURE__*/React.createElement(Button, {
67
+ palette: PALETTE.BRAND,
52
68
  isSelected: true,
53
69
  selectedAppearance: appearance
54
70
  }));
55
71
  expect(asFragment()).toMatchSnapshot();
56
72
  });
57
- const variant = ['text', 'icon', 'iconWithText'];
58
- test.each(variant)('Should render variant of buttons - %s', variant => {
73
+ test.each(Object.values(VARIANT))('Should render variant of buttons - %s', variant => {
59
74
  const {
60
75
  asFragment
61
76
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -63,8 +78,7 @@ describe('Button - Component', () => {
63
78
  }));
64
79
  expect(asFragment()).toMatchSnapshot();
65
80
  });
66
- const size = ['small', 'medium', 'large', 'full'];
67
- test.each(size)('Should render Sizes of buttons - %s', size => {
81
+ test.each(Object.values(SIZE))('Should render Sizes of buttons - %s', size => {
68
82
  const {
69
83
  asFragment
70
84
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -72,8 +86,7 @@ describe('Button - Component', () => {
72
86
  }));
73
87
  expect(asFragment()).toMatchSnapshot();
74
88
  });
75
- const status = ['default', 'loading', 'success'];
76
- test.each(status)('Should render Status of buttons - %s', status => {
89
+ test.each(Object.values(STATUS))('Should render Status of buttons - %s', status => {
77
90
  const {
78
91
  asFragment
79
92
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -81,8 +94,7 @@ describe('Button - Component', () => {
81
94
  }));
82
95
  expect(asFragment()).toMatchSnapshot();
83
96
  });
84
- const loaderPlacement = ['start', 'end', 'overlay'];
85
- test.each(loaderPlacement)('Should render loaderPlacement of buttons - %s', loaderPlacement => {
97
+ test.each(Object.values(LOADER_PLACEMENT))('Should render loaderPlacement of buttons - %s', loaderPlacement => {
86
98
  const {
87
99
  asFragment
88
100
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -91,7 +103,7 @@ describe('Button - Component', () => {
91
103
  }));
92
104
  expect(asFragment()).toMatchSnapshot();
93
105
  });
94
- test('Should render with iconName and iconSize ', () => {
106
+ test('Should render with iconName and iconSize', () => {
95
107
  const {
96
108
  asFragment
97
109
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -101,7 +113,7 @@ describe('Button - Component', () => {
101
113
  }));
102
114
  expect(asFragment()).toMatchSnapshot();
103
115
  });
104
- test('Should render with iconPlacement ', () => {
116
+ test('Should render with iconPlacement', () => {
105
117
  const {
106
118
  asFragment
107
119
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -147,8 +159,7 @@ describe('Button - Component', () => {
147
159
  }));
148
160
  expect(asFragment()).toMatchSnapshot();
149
161
  });
150
- const type = ['button', 'submit', 'reset'];
151
- test.each(type)('Should render type of buttons - %s', type => {
162
+ test.each(Object.values(BUTTON_TYPE))('Should render type of buttons - %s', type => {
152
163
  const {
153
164
  asFragment
154
165
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -174,14 +185,6 @@ describe('Button - Component', () => {
174
185
  }));
175
186
  expect(asFragment()).toMatchSnapshot();
176
187
  });
177
- test('Should render with readOnly style when isReadOnly prop is true', () => {
178
- const {
179
- asFragment
180
- } = render( /*#__PURE__*/React.createElement(Button, {
181
- isReadOnly: true
182
- }));
183
- expect(asFragment()).toMatchSnapshot();
184
- });
185
188
  test('Should render with selected style when isSelected prop is true', () => {
186
189
  const {
187
190
  asFragment
@@ -190,8 +193,7 @@ describe('Button - Component', () => {
190
193
  }));
191
194
  expect(asFragment()).toMatchSnapshot();
192
195
  });
193
- const shape = ['pill', 'rectangle', 'roundedRectangle'];
194
- test.each(shape)('Should render shape of buttons - %s', shape => {
196
+ test.each(Object.values(SHAPE))('Should render shape of buttons - %s', shape => {
195
197
  const {
196
198
  asFragment
197
199
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -199,17 +201,7 @@ describe('Button - Component', () => {
199
201
  }));
200
202
  expect(asFragment()).toMatchSnapshot();
201
203
  });
202
- const paletteShade = ['default', 'lighter'];
203
- test.each(paletteShade)('Should render paletteShade of buttons - %s', shade => {
204
- const {
205
- asFragment
206
- } = render( /*#__PURE__*/React.createElement(Button, {
207
- paletteShade: shade
208
- }));
209
- expect(asFragment()).toMatchSnapshot();
210
- });
211
- const disabledAppearance = ['none', 'dull', 'strike'];
212
- test.each(disabledAppearance)('Should render disabledAppearance of buttons - %s', style => {
204
+ test.each(Object.values(DISABLED_APPEARANCE))('Should render disabledAppearance of buttons - %s', style => {
213
205
  const {
214
206
  asFragment
215
207
  } = render( /*#__PURE__*/React.createElement(Button, {
@@ -247,9 +239,6 @@ describe('Button - Component', () => {
247
239
  variant: "iconWithText",
248
240
  iconName: "check",
249
241
  customProps: {
250
- wrapper: {
251
- 'data-wrapper': 'wrapperProps'
252
- },
253
242
  text: {
254
243
  'data-text': 'textProps'
255
244
  },
@@ -260,6 +249,21 @@ describe('Button - Component', () => {
260
249
  }, "Button"));
261
250
  expect(asFragment()).toMatchSnapshot();
262
251
  });
252
+ test('Should apply customAttributes to button elements', () => {
253
+ const {
254
+ asFragment
255
+ } = render( /*#__PURE__*/React.createElement(Button, {
256
+ customAttributes: {
257
+ button: {
258
+ 'data-wrapper': 'wrapperAttr'
259
+ },
260
+ text: {
261
+ 'data-text': 'textAttr'
262
+ }
263
+ }
264
+ }, "Button"));
265
+ expect(asFragment()).toMatchSnapshot();
266
+ });
263
267
  test('Should render with customId and testId', () => {
264
268
  const {
265
269
  asFragment
@@ -280,4 +284,83 @@ describe('Button - Component', () => {
280
284
  }, "Button"));
281
285
  expect(asFragment()).toMatchSnapshot();
282
286
  });
287
+ test('Should render renderBefore slot content in DOM', () => {
288
+ const {
289
+ getByText
290
+ } = render( /*#__PURE__*/React.createElement(Button, {
291
+ renderBefore: () => /*#__PURE__*/React.createElement("span", null, "BeforeSlot")
292
+ }, "Button"));
293
+ expect(getByText('BeforeSlot')).toBeInTheDocument();
294
+ });
295
+ test('Should render renderAfter slot content in DOM', () => {
296
+ const {
297
+ getByText
298
+ } = render( /*#__PURE__*/React.createElement(Button, {
299
+ renderAfter: () => /*#__PURE__*/React.createElement("span", null, "AfterSlot")
300
+ }, "Button"));
301
+ expect(getByText('AfterSlot')).toBeInTheDocument();
302
+ });
303
+ test('Should render renderIcon slot content in DOM', () => {
304
+ const {
305
+ getByText
306
+ } = render( /*#__PURE__*/React.createElement(Button, {
307
+ variant: "icon",
308
+ renderIcon: () => /*#__PURE__*/React.createElement("span", null, "IconSlot")
309
+ }));
310
+ expect(getByText('IconSlot')).toBeInTheDocument();
311
+ });
312
+ test('Should not call onClick when button is disabled', () => {
313
+ const onClick = jest.fn();
314
+ const {
315
+ getByRole
316
+ } = render( /*#__PURE__*/React.createElement(Button, {
317
+ isDisabled: true,
318
+ onClick: onClick
319
+ }));
320
+ userEvent.click(getByRole('button'));
321
+ expect(onClick).not.toHaveBeenCalled();
322
+ });
323
+ test('Should render loader overlay when status is loading and loaderPlacement is overlay', () => {
324
+ const {
325
+ asFragment
326
+ } = render( /*#__PURE__*/React.createElement(Button, {
327
+ status: "loading",
328
+ loaderPlacement: "overlay"
329
+ }));
330
+ expect(asFragment()).toMatchSnapshot();
331
+ });
332
+ test('Should render success overlay when status is success and loaderPlacement is overlay', () => {
333
+ const {
334
+ asFragment
335
+ } = render( /*#__PURE__*/React.createElement(Button, {
336
+ status: "success",
337
+ loaderPlacement: "overlay"
338
+ }));
339
+ expect(asFragment()).toMatchSnapshot();
340
+ });
341
+ test('Should render with dataSelectorId', () => {
342
+ const {
343
+ asFragment
344
+ } = render( /*#__PURE__*/React.createElement(Button, {
345
+ dataSelectorId: "selectorId"
346
+ }));
347
+ expect(asFragment()).toMatchSnapshot();
348
+ });
349
+ describe('Presets', () => {
350
+ const presets = [['BRAND_GHOST', BRAND_GHOST], ['BRAND_TEXT_ONLY', BRAND_TEXT_ONLY], ['BRAND_TINTED_OUTLINE', BRAND_TINTED_OUTLINE], ['SUCCESS_GHOST', SUCCESS_GHOST], ['SUCCESS_TEXT_ONLY', SUCCESS_TEXT_ONLY], ['SUCCESS_TINTED_OUTLINE', SUCCESS_TINTED_OUTLINE], ['SECONDARY_GHOST_BRAND_TINTED_ONSELECT', SECONDARY_GHOST_BRAND_TINTED_ONSELECT], ['BLACK_TEXT_BRAND_ONHOVER', BLACK_TEXT_BRAND_ONHOVER], ['BRAND_BG_ONSELECT', BRAND_BG_ONSELECT], ['BRAND_TEXT_TINTED_HOVER', BRAND_TEXT_TINTED_HOVER], ['BRAND_TEXT_TINTED_DANGER_HOVER', BRAND_TEXT_TINTED_DANGER_HOVER]];
351
+ test.each(presets)('Should render preset %s', (_name, preset) => {
352
+ const {
353
+ asFragment
354
+ } = render( /*#__PURE__*/React.createElement(Button, preset, "Button"));
355
+ expect(asFragment()).toMatchSnapshot();
356
+ });
357
+ test.each(presets)('Should render preset %s in selected state', (_name, preset) => {
358
+ const {
359
+ asFragment
360
+ } = render( /*#__PURE__*/React.createElement(Button, _extends({}, preset, {
361
+ isSelected: true
362
+ }), "Button"));
363
+ expect(asFragment()).toMatchSnapshot();
364
+ });
365
+ });
283
366
  });