@seeqdev/qomponents 0.0.132 → 0.0.134

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.
Files changed (156) hide show
  1. package/README.md +135 -135
  2. package/dist/Accordion/Accordion.js +8 -8
  3. package/dist/Accordion/Accordion.stories.js +114 -114
  4. package/dist/Accordion/Accordion.test.js +54 -54
  5. package/dist/Accordion/Accordion.types.js +1 -1
  6. package/dist/Accordion/index.js +1 -1
  7. package/dist/Alert/Alert.js +33 -33
  8. package/dist/Alert/Alert.stories.js +51 -51
  9. package/dist/Alert/Alert.test.js +50 -50
  10. package/dist/Alert/Alert.types.d.ts +1 -0
  11. package/dist/Alert/Alert.types.js +1 -1
  12. package/dist/Alert/index.js +1 -1
  13. package/dist/Button/Button.js +91 -91
  14. package/dist/Button/Button.stories.js +99 -99
  15. package/dist/Button/Button.test.js +48 -48
  16. package/dist/Button/Button.types.js +4 -4
  17. package/dist/Button/index.js +1 -1
  18. package/dist/ButtonGroup/ButtonGroup.js +32 -32
  19. package/dist/ButtonGroup/ButtonGroup.stories.js +384 -384
  20. package/dist/ButtonGroup/ButtonGroup.test.js +66 -66
  21. package/dist/ButtonGroup/ButtonGroup.types.d.ts +1 -0
  22. package/dist/ButtonGroup/ButtonGroup.types.js +1 -1
  23. package/dist/ButtonGroup/index.js +1 -1
  24. package/dist/ButtonWithDropdown/ButtonWithDropdown.js +59 -59
  25. package/dist/ButtonWithDropdown/ButtonWithDropdown.stories.js +142 -142
  26. package/dist/ButtonWithDropdown/ButtonWithDropdown.test.js +92 -92
  27. package/dist/ButtonWithDropdown/ButtonWithDropdown.types.d.ts +1 -0
  28. package/dist/ButtonWithDropdown/ButtonWithDropdown.types.js +1 -1
  29. package/dist/ButtonWithDropdown/index.js +1 -1
  30. package/dist/ButtonWithPopover/ButtonWithPopover.js +61 -61
  31. package/dist/ButtonWithPopover/ButtonWithPopover.stories.js +74 -74
  32. package/dist/ButtonWithPopover/ButtonWithPopover.test.js +81 -81
  33. package/dist/ButtonWithPopover/ButtonWithPopover.types.js +1 -1
  34. package/dist/ButtonWithPopover/index.js +1 -1
  35. package/dist/Carousel/Carousel.js +69 -66
  36. package/dist/Carousel/Carousel.js.map +1 -1
  37. package/dist/Carousel/Carousel.stories.js +114 -114
  38. package/dist/Carousel/Carousel.test.js +47 -47
  39. package/dist/Carousel/Carousel.types.d.ts +1 -0
  40. package/dist/Carousel/Carousel.types.js +1 -1
  41. package/dist/Carousel/index.js +1 -1
  42. package/dist/Checkbox/Checkbox.js +25 -25
  43. package/dist/Checkbox/Checkbox.stories.js +33 -33
  44. package/dist/Checkbox/Checkbox.test.js +93 -93
  45. package/dist/Checkbox/Checkbox.types.d.ts +1 -0
  46. package/dist/Checkbox/Checkbox.types.js +1 -1
  47. package/dist/Checkbox/index.js +1 -1
  48. package/dist/Collapse/Collapse.js +14 -17
  49. package/dist/Collapse/Collapse.js.map +1 -1
  50. package/dist/Collapse/Collapse.stories.js +36 -36
  51. package/dist/Collapse/Collapse.test.js +18 -18
  52. package/dist/Collapse/Collapse.types.d.ts +1 -0
  53. package/dist/Collapse/Collapse.types.js +1 -1
  54. package/dist/Collapse/index.js +1 -1
  55. package/dist/Icon/Icon.js +54 -54
  56. package/dist/Icon/Icon.stories.js +46 -46
  57. package/dist/Icon/Icon.test.js +54 -54
  58. package/dist/Icon/Icon.types.d.ts +1 -0
  59. package/dist/Icon/Icon.types.js +15 -15
  60. package/dist/Icon/index.js +1 -1
  61. package/dist/InputGroup/InputGroup.js +31 -31
  62. package/dist/InputGroup/InputGroup.stories.js +167 -167
  63. package/dist/InputGroup/InputGroup.test.js +42 -42
  64. package/dist/InputGroup/InputGroup.types.d.ts +1 -0
  65. package/dist/InputGroup/InputGroup.types.js +1 -1
  66. package/dist/InputGroup/index.js +1 -1
  67. package/dist/Modal/Modal.js +99 -99
  68. package/dist/Modal/Modal.js.map +1 -1
  69. package/dist/Modal/Modal.stories.js +126 -126
  70. package/dist/Modal/Modal.test.js +107 -107
  71. package/dist/Modal/Modal.types.js +1 -1
  72. package/dist/Modal/index.js +1 -1
  73. package/dist/ProgressBar/ProgressBar.js +49 -29
  74. package/dist/ProgressBar/ProgressBar.js.map +1 -1
  75. package/dist/ProgressBar/ProgressBar.stories.js +80 -72
  76. package/dist/ProgressBar/ProgressBar.stories.js.map +1 -1
  77. package/dist/ProgressBar/ProgressBar.test.js +43 -37
  78. package/dist/ProgressBar/ProgressBar.test.js.map +1 -1
  79. package/dist/ProgressBar/ProgressBar.types.d.ts +2 -0
  80. package/dist/ProgressBar/ProgressBar.types.js +1 -1
  81. package/dist/ProgressBar/index.js +1 -1
  82. package/dist/SeeqActionDropdown/SeeqActionDropdown.js +47 -47
  83. package/dist/SeeqActionDropdown/SeeqActionDropdown.stories.js +79 -79
  84. package/dist/SeeqActionDropdown/SeeqActionDropdown.test.js +72 -72
  85. package/dist/SeeqActionDropdown/SeeqActionDropdown.types.d.ts +1 -0
  86. package/dist/SeeqActionDropdown/SeeqActionDropdown.types.js +1 -1
  87. package/dist/SeeqActionDropdown/index.js +1 -1
  88. package/dist/SeeqActionDropdown/variants.js +22 -22
  89. package/dist/Select/Select.js +173 -173
  90. package/dist/Select/Select.stories.js +79 -79
  91. package/dist/Select/Select.test.js +181 -181
  92. package/dist/Select/Select.types.js +1 -1
  93. package/dist/Select/index.js +2 -2
  94. package/dist/Slider/Slider.js +12 -12
  95. package/dist/Slider/Slider.stories.js +57 -57
  96. package/dist/Slider/Slider.test.js +32 -32
  97. package/dist/Slider/Slider.types.d.ts +1 -0
  98. package/dist/Slider/Slider.types.js +1 -1
  99. package/dist/Slider/index.js +1 -1
  100. package/dist/Tabs/Tabs.js +21 -21
  101. package/dist/Tabs/Tabs.stories.js +90 -90
  102. package/dist/Tabs/Tabs.test.js +90 -90
  103. package/dist/Tabs/Tabs.types.d.ts +1 -0
  104. package/dist/Tabs/Tabs.types.js +1 -1
  105. package/dist/Tabs/index.js +1 -1
  106. package/dist/TextArea/TextArea.js +24 -24
  107. package/dist/TextArea/TextArea.stories.js +45 -45
  108. package/dist/TextArea/TextArea.test.js +67 -67
  109. package/dist/TextArea/TextArea.types.d.ts +1 -0
  110. package/dist/TextArea/TextArea.types.js +1 -1
  111. package/dist/TextArea/index.js +1 -1
  112. package/dist/TextField/TextField.js +78 -78
  113. package/dist/TextField/TextField.stories.js +69 -69
  114. package/dist/TextField/TextField.test.js +38 -38
  115. package/dist/TextField/TextField.types.d.ts +1 -0
  116. package/dist/TextField/TextField.types.js +1 -1
  117. package/dist/TextField/index.js +1 -1
  118. package/dist/ToolbarButton/ToolbarButton.js +74 -74
  119. package/dist/ToolbarButton/ToolbarButton.stories.js +93 -93
  120. package/dist/ToolbarButton/ToolbarButton.test.js +92 -92
  121. package/dist/ToolbarButton/ToolbarButton.types.js +1 -1
  122. package/dist/ToolbarButton/index.js +1 -1
  123. package/dist/Tooltip/QTip.stories.js +44 -44
  124. package/dist/Tooltip/QTip.types.js +1 -1
  125. package/dist/Tooltip/QTipPerformance.stories.js +29 -29
  126. package/dist/Tooltip/Qtip.js +167 -167
  127. package/dist/Tooltip/Tooltip.js +35 -35
  128. package/dist/Tooltip/Tooltip.stories.js +31 -31
  129. package/dist/Tooltip/Tooltip.types.d.ts +1 -0
  130. package/dist/Tooltip/Tooltip.types.js +2 -2
  131. package/dist/Tooltip/TooltipPerformance.stories.js +29 -29
  132. package/dist/Tooltip/index.js +2 -2
  133. package/dist/Tooltip/qTip.utilities.js +10 -10
  134. package/dist/example/.eslintrc.cjs +14 -14
  135. package/dist/example/README.md +33 -33
  136. package/dist/example/index.html +13 -13
  137. package/dist/example/package.json +30 -30
  138. package/dist/example/src/ComplexSelectExample.tsx +81 -81
  139. package/dist/example/src/Example.tsx +408 -408
  140. package/dist/example/src/index.css +102 -102
  141. package/dist/example/src/main.tsx +10 -10
  142. package/dist/example/src/vite-env.d.ts +1 -1
  143. package/dist/example/tsconfig.json +33 -33
  144. package/dist/example/tsconfig.node.json +12 -12
  145. package/dist/example/vite.config.ts +12 -12
  146. package/dist/index.esm.js +15266 -7869
  147. package/dist/index.esm.js.map +1 -1
  148. package/dist/index.js +15230 -7833
  149. package/dist/index.js.map +1 -1
  150. package/dist/styles.css +3714 -3709
  151. package/dist/types.js +1 -1
  152. package/dist/utils/browserId.js +28 -28
  153. package/dist/utils/svg.js +19 -19
  154. package/dist/utils/validateStyleDimension.js +13 -13
  155. package/dist/utils/validateStyleDimension.test.js +19 -19
  156. package/package.json +89 -86
@@ -1,68 +1,68 @@
1
- import React from 'react';
2
- import '@testing-library/jest-dom';
3
- import { render, screen } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
5
- import { TextArea } from './TextArea';
6
- describe('TextArea', () => {
7
- class Context {
8
- testId = 'textAreaTestId';
9
- props = {
10
- onChange: jest.fn(),
11
- onKeyUp: jest.fn(),
12
- testId: this.testId,
13
- };
14
- }
15
- let tc;
16
- beforeEach(() => {
17
- tc = new Context();
18
- });
19
- const renderTextArea = (props) => render(React.createElement(TextArea, { ...props }));
20
- it('renders the provided value', () => {
21
- const value = 'hello, this is text for a text area.';
22
- renderTextArea({ ...tc.props, value });
23
- expect(screen.getByDisplayValue(value)).toBeInTheDocument();
24
- });
25
- it('renders the provided placeholder', () => {
26
- const placeholder = 'Prompt to enter';
27
- renderTextArea({ ...tc.props, placeholder });
28
- expect(screen.getByPlaceholderText(placeholder)).toBeInTheDocument();
29
- });
30
- it('calls onChange handler', async () => {
31
- renderTextArea({ ...tc.props });
32
- await userEvent.type(screen.getByTestId(tc.testId), 'trigger');
33
- expect(tc.props.onChange).toHaveBeenCalled();
34
- });
35
- it('calls the onKeyUp handler', async () => {
36
- renderTextArea({ ...tc.props });
37
- await userEvent.type(screen.getByTestId(tc.testId), 'trigger');
38
- expect(tc.props.onKeyUp).toHaveBeenCalled();
39
- });
40
- it('respects readOnly', async () => {
41
- renderTextArea({ ...tc.props, disabled: true });
42
- expect(screen.getByTestId(tc.testId)).not.toBeEnabled();
43
- });
44
- it('provides rows', async () => {
45
- renderTextArea({ ...tc.props, rows: 7 });
46
- expect(screen.getByTestId(tc.testId)).toHaveProperty('rows', 7);
47
- });
48
- it('provides cols', async () => {
49
- renderTextArea({ ...tc.props, cols: 8 });
50
- expect(screen.getByTestId(tc.testId)).toHaveProperty('cols', 8);
51
- });
52
- it('provides name', async () => {
53
- const name = 'myTextArea';
54
- renderTextArea({ ...tc.props, name });
55
- expect(screen.getByTestId(tc.testId)).toHaveProperty('name', name);
56
- });
57
- it('provides id', async () => {
58
- const id = 'myTextId';
59
- renderTextArea({ ...tc.props, id });
60
- expect(screen.getByTestId(tc.testId)).toHaveProperty('id', id);
61
- });
62
- it('provides extraClassNames', async () => {
63
- const extraClassNames = 'extra css';
64
- renderTextArea({ ...tc.props, extraClassNames });
65
- expect(screen.getByTestId(tc.testId)).toHaveClass(extraClassNames);
66
- });
67
- });
1
+ import React from 'react';
2
+ import '@testing-library/jest-dom';
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { TextArea } from './TextArea';
6
+ describe('TextArea', () => {
7
+ class Context {
8
+ testId = 'textAreaTestId';
9
+ props = {
10
+ onChange: jest.fn(),
11
+ onKeyUp: jest.fn(),
12
+ testId: this.testId,
13
+ };
14
+ }
15
+ let tc;
16
+ beforeEach(() => {
17
+ tc = new Context();
18
+ });
19
+ const renderTextArea = (props) => render(React.createElement(TextArea, { ...props }));
20
+ it('renders the provided value', () => {
21
+ const value = 'hello, this is text for a text area.';
22
+ renderTextArea({ ...tc.props, value });
23
+ expect(screen.getByDisplayValue(value)).toBeInTheDocument();
24
+ });
25
+ it('renders the provided placeholder', () => {
26
+ const placeholder = 'Prompt to enter';
27
+ renderTextArea({ ...tc.props, placeholder });
28
+ expect(screen.getByPlaceholderText(placeholder)).toBeInTheDocument();
29
+ });
30
+ it('calls onChange handler', async () => {
31
+ renderTextArea({ ...tc.props });
32
+ await userEvent.type(screen.getByTestId(tc.testId), 'trigger');
33
+ expect(tc.props.onChange).toHaveBeenCalled();
34
+ });
35
+ it('calls the onKeyUp handler', async () => {
36
+ renderTextArea({ ...tc.props });
37
+ await userEvent.type(screen.getByTestId(tc.testId), 'trigger');
38
+ expect(tc.props.onKeyUp).toHaveBeenCalled();
39
+ });
40
+ it('respects readOnly', async () => {
41
+ renderTextArea({ ...tc.props, disabled: true });
42
+ expect(screen.getByTestId(tc.testId)).not.toBeEnabled();
43
+ });
44
+ it('provides rows', async () => {
45
+ renderTextArea({ ...tc.props, rows: 7 });
46
+ expect(screen.getByTestId(tc.testId)).toHaveProperty('rows', 7);
47
+ });
48
+ it('provides cols', async () => {
49
+ renderTextArea({ ...tc.props, cols: 8 });
50
+ expect(screen.getByTestId(tc.testId)).toHaveProperty('cols', 8);
51
+ });
52
+ it('provides name', async () => {
53
+ const name = 'myTextArea';
54
+ renderTextArea({ ...tc.props, name });
55
+ expect(screen.getByTestId(tc.testId)).toHaveProperty('name', name);
56
+ });
57
+ it('provides id', async () => {
58
+ const id = 'myTextId';
59
+ renderTextArea({ ...tc.props, id });
60
+ expect(screen.getByTestId(tc.testId)).toHaveProperty('id', id);
61
+ });
62
+ it('provides extraClassNames', async () => {
63
+ const extraClassNames = 'extra css';
64
+ renderTextArea({ ...tc.props, extraClassNames });
65
+ expect(screen.getByTestId(tc.testId)).toHaveClass(extraClassNames);
66
+ });
67
+ });
68
68
  //# sourceMappingURL=TextArea.test.js.map
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { FormControlElement } from '../types';
2
3
  export interface TextAreaProps {
3
4
  /** extra class names to be placed on the TextArea component */
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=TextArea.types.js.map
@@ -1,2 +1,2 @@
1
- export { TextArea as default } from './TextArea';
1
+ export { TextArea as default } from './TextArea';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,79 +1,79 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import '../styles.css';
3
- import { setValidInputDimension } from '../utils/validateStyleDimension';
4
- import { getQTipData } from '../Tooltip/qTip.utilities';
5
- const errorClasses = 'tw-border-sq-danger-color';
6
- const borderColorClasses = [
7
- 'tw-border-sq-disabled-gray',
8
- 'dark:tw-border-sq-dark-disabled-gray',
9
- 'dark:focus:tw-border-sq-color-dark-dark',
10
- 'dark:active:tw-border-sq-color-dark-dark',
11
- 'focus:tw-border-sq-color-dark',
12
- 'active:tw-border-sq-color-dark',
13
- ].join(' ');
14
- const baseClasses = 'tw-h-inputs tw-leading-normal tw-outline-none tw-py-1 tw-px-3' +
15
- ' disabled:tw-pointer-events-none disabled:tw-bg-sq-light-gray disabled:dark:tw-bg-sq-dark-disabled-gray' +
16
- ' disabled:tw-cursor-not-allowed tw-p-1 tw-border-solid tw-border tw-placeholder-gray-400' +
17
- ' dark:tw-placeholder-sq-dark-text-lighter specTextField';
18
- const darkTheme = 'dark:tw-bg-sq-dark-background dark:tw-text-sq-dark-text disabled:dark:tw-text-sq-dark-text-lighter';
19
- const lightTheme = 'tw-text-sq-text-color disabled:tw-text-sq-darkish-gray';
20
- const sizeClasses = {
21
- sm: 'tw-text-sm',
22
- lg: 'tw-text-xl',
23
- };
24
- /**
25
- * Textfield.
26
- */
27
- export const TextField = React.forwardRef((props, ref) => {
28
- const { readonly = false, disabled = false, onChange, onKeyUp, onFocus, onBlur, onKeyDown, id, name, size = 'sm', value, placeholder, extraClassNames, testId, type = 'text', inputGroup, step, showError, errorText, min, max, maxLength, minLength, required = false, autoComplete = 'off', inputWidth = undefined, inputHeight = undefined, autoFocus = false, ...tooltipProps } = props;
29
- const internalRef = useRef(null);
30
- const [cursor, setCursor] = useState(null);
31
- const tooltipData = getQTipData(tooltipProps);
32
- const setAllRefs = (receivedRef) => {
33
- if (ref)
34
- ref.current = receivedRef;
35
- internalRef.current = receivedRef;
36
- };
37
- useEffect(() => {
38
- const input = internalRef.current;
39
- if (input && type !== 'number' && type !== 'email')
40
- input.setSelectionRange(cursor, cursor);
41
- }, [ref, cursor, value]);
42
- const handleChange = (e) => {
43
- setCursor(e.target.selectionStart);
44
- onChange && onChange(e);
45
- };
46
- useEffect(() => {
47
- /**
48
- * we need to change the value only if it's different since the internal state of "input" will change it anyway
49
- * this will only be the case when the value has been changed externally via store (undo / redo)
50
- */
51
- if (value !== null && value !== undefined && value !== internalRef.current?.value && internalRef.current) {
52
- // we need to use this method because using the value props directly will switch the input to a "controlled"
53
- // component
54
- internalRef.current.value = `${value}`;
55
- }
56
- }, [value]);
57
- let borderRadius = 'tw-rounded-sm';
58
- if (inputGroup === 'left') {
59
- borderRadius = 'tw-rounded-l-sm tw-border-r-0 focus:tw-border-r' + ' active:tw-border-r';
60
- }
61
- else if (inputGroup === 'right') {
62
- borderRadius = 'tw-rounded-r-sm tw-border-l-0 focus:tw-border-l active:tw-border-l';
63
- }
64
- const appliedClasses = `${baseClasses} ${sizeClasses[size]} ${extraClassNames} ${lightTheme} ${darkTheme} ${borderRadius} ${showError ? errorClasses : borderColorClasses} `;
65
- const inputProp = setValidInputDimension(inputWidth, inputHeight)
66
- ? {
67
- style: setValidInputDimension(inputWidth, inputHeight),
68
- }
69
- : {};
70
- const inputLenghtProp = {};
71
- if (maxLength)
72
- inputLenghtProp.maxLength = maxLength;
73
- if (minLength)
74
- inputLenghtProp.minLength = minLength;
75
- return (React.createElement(React.Fragment, null,
76
- React.createElement("input", { ref: setAllRefs, "data-testid": testId, name: name, id: id, type: type, value: value, className: appliedClasses, placeholder: placeholder, disabled: disabled, readOnly: readonly, autoComplete: autoComplete, onChange: handleChange, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, onKeyUp: onKeyUp, step: step, required: required, autoFocus: autoFocus, min: min, max: max, ...inputLenghtProp, ...inputProp, ...tooltipData }),
77
- errorText && showError && React.createElement("div", { className: "tw-text-sq-danger-color tw-text-xs tw-mt-1" }, errorText)));
78
- });
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import '../styles.css';
3
+ import { setValidInputDimension } from '../utils/validateStyleDimension';
4
+ import { getQTipData } from '../Tooltip/qTip.utilities';
5
+ const errorClasses = 'tw-border-sq-danger-color';
6
+ const borderColorClasses = [
7
+ 'tw-border-sq-disabled-gray',
8
+ 'dark:tw-border-sq-dark-disabled-gray',
9
+ 'dark:focus:tw-border-sq-color-dark-dark',
10
+ 'dark:active:tw-border-sq-color-dark-dark',
11
+ 'focus:tw-border-sq-color-dark',
12
+ 'active:tw-border-sq-color-dark',
13
+ ].join(' ');
14
+ const baseClasses = 'tw-h-inputs tw-leading-normal tw-outline-none tw-py-1 tw-px-3' +
15
+ ' disabled:tw-pointer-events-none disabled:tw-bg-sq-light-gray disabled:dark:tw-bg-sq-dark-disabled-gray' +
16
+ ' disabled:tw-cursor-not-allowed tw-p-1 tw-border-solid tw-border tw-placeholder-gray-400' +
17
+ ' dark:tw-placeholder-sq-dark-text-lighter specTextField';
18
+ const darkTheme = 'dark:tw-bg-sq-dark-background dark:tw-text-sq-dark-text disabled:dark:tw-text-sq-dark-text-lighter';
19
+ const lightTheme = 'tw-text-sq-text-color disabled:tw-text-sq-darkish-gray';
20
+ const sizeClasses = {
21
+ sm: 'tw-text-sm',
22
+ lg: 'tw-text-xl',
23
+ };
24
+ /**
25
+ * Textfield.
26
+ */
27
+ export const TextField = React.forwardRef((props, ref) => {
28
+ const { readonly = false, disabled = false, onChange, onKeyUp, onFocus, onBlur, onKeyDown, id, name, size = 'sm', value, placeholder, extraClassNames, testId, type = 'text', inputGroup, step, showError, errorText, min, max, maxLength, minLength, required = false, autoComplete = 'off', inputWidth = undefined, inputHeight = undefined, autoFocus = false, ...tooltipProps } = props;
29
+ const internalRef = useRef(null);
30
+ const [cursor, setCursor] = useState(null);
31
+ const tooltipData = getQTipData(tooltipProps);
32
+ const setAllRefs = (receivedRef) => {
33
+ if (ref)
34
+ ref.current = receivedRef;
35
+ internalRef.current = receivedRef;
36
+ };
37
+ useEffect(() => {
38
+ const input = internalRef.current;
39
+ if (input && type !== 'number' && type !== 'email')
40
+ input.setSelectionRange(cursor, cursor);
41
+ }, [ref, cursor, value]);
42
+ const handleChange = (e) => {
43
+ setCursor(e.target.selectionStart);
44
+ onChange && onChange(e);
45
+ };
46
+ useEffect(() => {
47
+ /**
48
+ * we need to change the value only if it's different since the internal state of "input" will change it anyway
49
+ * this will only be the case when the value has been changed externally via store (undo / redo)
50
+ */
51
+ if (value !== null && value !== undefined && value !== internalRef.current?.value && internalRef.current) {
52
+ // we need to use this method because using the value props directly will switch the input to a "controlled"
53
+ // component
54
+ internalRef.current.value = `${value}`;
55
+ }
56
+ }, [value]);
57
+ let borderRadius = 'tw-rounded-sm';
58
+ if (inputGroup === 'left') {
59
+ borderRadius = 'tw-rounded-l-sm tw-border-r-0 focus:tw-border-r' + ' active:tw-border-r';
60
+ }
61
+ else if (inputGroup === 'right') {
62
+ borderRadius = 'tw-rounded-r-sm tw-border-l-0 focus:tw-border-l active:tw-border-l';
63
+ }
64
+ const appliedClasses = `${baseClasses} ${sizeClasses[size]} ${extraClassNames} ${lightTheme} ${darkTheme} ${borderRadius} ${showError ? errorClasses : borderColorClasses} `;
65
+ const inputProp = setValidInputDimension(inputWidth, inputHeight)
66
+ ? {
67
+ style: setValidInputDimension(inputWidth, inputHeight),
68
+ }
69
+ : {};
70
+ const inputLenghtProp = {};
71
+ if (maxLength)
72
+ inputLenghtProp.maxLength = maxLength;
73
+ if (minLength)
74
+ inputLenghtProp.minLength = minLength;
75
+ return (React.createElement(React.Fragment, null,
76
+ React.createElement("input", { ref: setAllRefs, "data-testid": testId, name: name, id: id, type: type, value: value, className: appliedClasses, placeholder: placeholder, disabled: disabled, readOnly: readonly, autoComplete: autoComplete, onChange: handleChange, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, onKeyUp: onKeyUp, step: step, required: required, autoFocus: autoFocus, min: min, max: max, ...inputLenghtProp, ...inputProp, ...tooltipData }),
77
+ errorText && showError && React.createElement("div", { className: "tw-text-sq-danger-color tw-text-xs tw-mt-1" }, errorText)));
78
+ });
79
79
  //# sourceMappingURL=TextField.js.map
@@ -1,70 +1,70 @@
1
- import React from 'react';
2
- import { TextField } from './TextField';
3
- import { QTip } from '../Tooltip';
4
- export default {
5
- title: 'TextField',
6
- };
7
- export const AllTextFields = () => {
8
- const renderAllVariations = () => (React.createElement(React.Fragment, null,
9
- React.createElement("div", { className: "tw-p-4 light" },
10
- React.createElement("div", { className: "tw-p-4" },
11
- React.createElement(TextField, { value: "value provided" })),
12
- React.createElement("div", { className: "tw-p-4" },
13
- React.createElement(TextField, { placeholder: "placeholder text" })),
14
- React.createElement("div", { className: "tw-p-4" },
15
- React.createElement(TextField, { placeholder: "with error", showError: true })),
16
- React.createElement("div", { className: "tw-p-4" },
17
- React.createElement(TextField, { placeholder: "with error text", showError: true, errorText: "this is a major test error and it is long on purpose to see its looks" })),
18
- React.createElement("div", { className: "tw-p-4" },
19
- React.createElement(TextField, { value: "read-only", readonly: true, onFocus: (e) => e.currentTarget.select() })),
20
- React.createElement("div", { className: "tw-p-4" },
21
- React.createElement(TextField, { value: "disabled", disabled: true, onFocus: (e) => e.currentTarget.select() })),
22
- React.createElement("div", { className: "tw-p-4" },
23
- React.createElement("div", null, "max value = 10"),
24
- React.createElement(TextField, { type: "number", value: 20, max: 10 })),
25
- React.createElement("div", { className: "tw-p-4" },
26
- React.createElement("div", null, "min value = 2"),
27
- React.createElement(TextField, { type: "number", value: 1, min: 2 })),
28
- React.createElement("div", { className: "tw-p-4" },
29
- React.createElement(TextField, { value: "large", size: "lg" })),
30
- React.createElement("div", { className: "tw-p-4" },
31
- React.createElement(TextField, { value: "with tooltip", tooltip: "small tooltip" }))),
32
- React.createElement("div", { className: "tw-p-4 tw-dark tw-bg-sq-dark-background" },
33
- React.createElement("div", { className: "tw-p-4" },
34
- React.createElement(TextField, { value: "value provided" })),
35
- React.createElement("div", { className: "tw-p-4" },
36
- React.createElement(TextField, { placeholder: "placeholder text" })),
37
- React.createElement("div", { className: "tw-p-4" },
38
- React.createElement(TextField, { placeholder: "with error", showError: true })),
39
- React.createElement("div", { className: "tw-p-4" },
40
- React.createElement(TextField, { placeholder: "with error text", showError: true, errorText: "this is a major test error and it is long on purpose to see its looks" })),
41
- React.createElement("div", { className: "tw-p-4" },
42
- React.createElement(TextField, { value: "read-only", readonly: true, onFocus: (e) => e.currentTarget.select() })),
43
- React.createElement("div", { className: "tw-p-4" },
44
- React.createElement(TextField, { value: "disabled", disabled: true, onFocus: (e) => e.currentTarget.select() })),
45
- React.createElement("div", { className: "tw-p-4" },
46
- React.createElement("div", { className: "tw-text-sq-color-dark dark:tw-text-sq-color-dark-dark" }, "max value = 10"),
47
- React.createElement(TextField, { type: "number", value: 8, max: 10 })),
48
- React.createElement("div", { className: "tw-p-4" },
49
- React.createElement("div", { className: "tw-text-sq-color-dark dark:tw-text-sq-color-dark-dark" }, "min value = 2"),
50
- React.createElement(TextField, { type: "number", value: 10, min: 2 })),
51
- React.createElement("div", { className: "tw-p-4" },
52
- React.createElement(TextField, { value: "large", size: "lg" })),
53
- React.createElement("div", { className: "tw-p-4" },
54
- React.createElement(TextField, { value: "with tooltip", tooltip: "small tooltip" })))));
55
- return (React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4" },
56
- React.createElement(QTip, null),
57
- React.createElement("div", { className: "color_topic" },
58
- React.createElement("b", null, "Topic Colors"),
59
- renderAllVariations()),
60
- React.createElement("div", { className: "color_analysis" },
61
- React.createElement("b", null, "Analysis Colors"),
62
- renderAllVariations()),
63
- React.createElement("div", { className: "color_datalab" },
64
- React.createElement("b", null, "Datalab Colors"),
65
- renderAllVariations()),
66
- React.createElement("div", { className: "color_vantage" },
67
- React.createElement("b", null, "Vantage Colors"),
68
- renderAllVariations())));
69
- };
1
+ import React from 'react';
2
+ import { TextField } from './TextField';
3
+ import { QTip } from '../Tooltip';
4
+ export default {
5
+ title: 'TextField',
6
+ };
7
+ export const AllTextFields = () => {
8
+ const renderAllVariations = () => (React.createElement(React.Fragment, null,
9
+ React.createElement("div", { className: "tw-p-4 light" },
10
+ React.createElement("div", { className: "tw-p-4" },
11
+ React.createElement(TextField, { value: "value provided" })),
12
+ React.createElement("div", { className: "tw-p-4" },
13
+ React.createElement(TextField, { placeholder: "placeholder text" })),
14
+ React.createElement("div", { className: "tw-p-4" },
15
+ React.createElement(TextField, { placeholder: "with error", showError: true })),
16
+ React.createElement("div", { className: "tw-p-4" },
17
+ React.createElement(TextField, { placeholder: "with error text", showError: true, errorText: "this is a major test error and it is long on purpose to see its looks" })),
18
+ React.createElement("div", { className: "tw-p-4" },
19
+ React.createElement(TextField, { value: "read-only", readonly: true, onFocus: (e) => e.currentTarget.select() })),
20
+ React.createElement("div", { className: "tw-p-4" },
21
+ React.createElement(TextField, { value: "disabled", disabled: true, onFocus: (e) => e.currentTarget.select() })),
22
+ React.createElement("div", { className: "tw-p-4" },
23
+ React.createElement("div", null, "max value = 10"),
24
+ React.createElement(TextField, { type: "number", value: 20, max: 10 })),
25
+ React.createElement("div", { className: "tw-p-4" },
26
+ React.createElement("div", null, "min value = 2"),
27
+ React.createElement(TextField, { type: "number", value: 1, min: 2 })),
28
+ React.createElement("div", { className: "tw-p-4" },
29
+ React.createElement(TextField, { value: "large", size: "lg" })),
30
+ React.createElement("div", { className: "tw-p-4" },
31
+ React.createElement(TextField, { value: "with tooltip", tooltip: "small tooltip" }))),
32
+ React.createElement("div", { className: "tw-p-4 tw-dark tw-bg-sq-dark-background" },
33
+ React.createElement("div", { className: "tw-p-4" },
34
+ React.createElement(TextField, { value: "value provided" })),
35
+ React.createElement("div", { className: "tw-p-4" },
36
+ React.createElement(TextField, { placeholder: "placeholder text" })),
37
+ React.createElement("div", { className: "tw-p-4" },
38
+ React.createElement(TextField, { placeholder: "with error", showError: true })),
39
+ React.createElement("div", { className: "tw-p-4" },
40
+ React.createElement(TextField, { placeholder: "with error text", showError: true, errorText: "this is a major test error and it is long on purpose to see its looks" })),
41
+ React.createElement("div", { className: "tw-p-4" },
42
+ React.createElement(TextField, { value: "read-only", readonly: true, onFocus: (e) => e.currentTarget.select() })),
43
+ React.createElement("div", { className: "tw-p-4" },
44
+ React.createElement(TextField, { value: "disabled", disabled: true, onFocus: (e) => e.currentTarget.select() })),
45
+ React.createElement("div", { className: "tw-p-4" },
46
+ React.createElement("div", { className: "tw-text-sq-color-dark dark:tw-text-sq-color-dark-dark" }, "max value = 10"),
47
+ React.createElement(TextField, { type: "number", value: 8, max: 10 })),
48
+ React.createElement("div", { className: "tw-p-4" },
49
+ React.createElement("div", { className: "tw-text-sq-color-dark dark:tw-text-sq-color-dark-dark" }, "min value = 2"),
50
+ React.createElement(TextField, { type: "number", value: 10, min: 2 })),
51
+ React.createElement("div", { className: "tw-p-4" },
52
+ React.createElement(TextField, { value: "large", size: "lg" })),
53
+ React.createElement("div", { className: "tw-p-4" },
54
+ React.createElement(TextField, { value: "with tooltip", tooltip: "small tooltip" })))));
55
+ return (React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4" },
56
+ React.createElement(QTip, null),
57
+ React.createElement("div", { className: "color_topic" },
58
+ React.createElement("b", null, "Topic Colors"),
59
+ renderAllVariations()),
60
+ React.createElement("div", { className: "color_analysis" },
61
+ React.createElement("b", null, "Analysis Colors"),
62
+ renderAllVariations()),
63
+ React.createElement("div", { className: "color_datalab" },
64
+ React.createElement("b", null, "Datalab Colors"),
65
+ renderAllVariations()),
66
+ React.createElement("div", { className: "color_vantage" },
67
+ React.createElement("b", null, "Vantage Colors"),
68
+ renderAllVariations())));
69
+ };
70
70
  //# sourceMappingURL=TextField.stories.js.map
@@ -1,39 +1,39 @@
1
- import React from 'react';
2
- import '@testing-library/jest-dom';
3
- import { render, screen } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
5
- import { TextField } from './TextField';
6
- describe('TextField', () => {
7
- class Context {
8
- testId = 'textFieldTestId';
9
- props = {
10
- onChange: jest.fn(),
11
- testId: this.testId,
12
- };
13
- }
14
- let tc;
15
- beforeEach(() => {
16
- tc = new Context();
17
- });
18
- const renderTextField = (props) => render(React.createElement(TextField, { ...props }));
19
- it('renders the provided value', () => {
20
- const value = 'hello';
21
- renderTextField({ ...tc.props, value });
22
- expect(screen.getByDisplayValue(value)).toBeInTheDocument();
23
- });
24
- it('renders the provided placeholder', () => {
25
- const placeholder = 'Prompt to enter';
26
- renderTextField({ ...tc.props, placeholder });
27
- expect(screen.getByPlaceholderText(placeholder)).toBeInTheDocument();
28
- });
29
- it('calls onChange handler', async () => {
30
- renderTextField({ ...tc.props });
31
- await userEvent.type(screen.getByTestId(tc.testId), 'trigger');
32
- expect(tc.props.onChange).toHaveBeenCalled();
33
- });
34
- it('autofocuses the textfield', async () => {
35
- renderTextField({ ...tc.props, autoFocus: true });
36
- expect(screen.getByTestId(tc.testId)).toHaveFocus();
37
- });
38
- });
1
+ import React from 'react';
2
+ import '@testing-library/jest-dom';
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { TextField } from './TextField';
6
+ describe('TextField', () => {
7
+ class Context {
8
+ testId = 'textFieldTestId';
9
+ props = {
10
+ onChange: jest.fn(),
11
+ testId: this.testId,
12
+ };
13
+ }
14
+ let tc;
15
+ beforeEach(() => {
16
+ tc = new Context();
17
+ });
18
+ const renderTextField = (props) => render(React.createElement(TextField, { ...props }));
19
+ it('renders the provided value', () => {
20
+ const value = 'hello';
21
+ renderTextField({ ...tc.props, value });
22
+ expect(screen.getByDisplayValue(value)).toBeInTheDocument();
23
+ });
24
+ it('renders the provided placeholder', () => {
25
+ const placeholder = 'Prompt to enter';
26
+ renderTextField({ ...tc.props, placeholder });
27
+ expect(screen.getByPlaceholderText(placeholder)).toBeInTheDocument();
28
+ });
29
+ it('calls onChange handler', async () => {
30
+ renderTextField({ ...tc.props });
31
+ await userEvent.type(screen.getByTestId(tc.testId), 'trigger');
32
+ expect(tc.props.onChange).toHaveBeenCalled();
33
+ });
34
+ it('autofocuses the textfield', async () => {
35
+ renderTextField({ ...tc.props, autoFocus: true });
36
+ expect(screen.getByTestId(tc.testId)).toHaveFocus();
37
+ });
38
+ });
39
39
  //# sourceMappingURL=TextField.test.js.map
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { TooltipComponentProps } from '../Tooltip/Tooltip.types';
2
3
  import { FormControlElement, InputGroupPlacement } from '../types';
3
4
  export interface TextFieldProps extends TooltipComponentProps {
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=TextField.types.js.map
@@ -1,2 +1,2 @@
1
- export { TextField as default } from './TextField';
1
+ export { TextField as default } from './TextField';
2
2
  //# sourceMappingURL=index.js.map