@dhis2-ui/text-area 9.11.0 → 9.11.1-beta.10

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 (34) hide show
  1. package/build/cjs/index.js +0 -2
  2. package/build/cjs/text-area/__tests__/text-area.test.js +1 -7
  3. package/build/cjs/text-area/features/accepts_initial_focus/index.js +1 -2
  4. package/build/cjs/text-area/features/can_be_blurred/index.js +1 -2
  5. package/build/cjs/text-area/features/can_be_changed/index.js +1 -2
  6. package/build/cjs/text-area/features/can_be_disabled/index.js +0 -1
  7. package/build/cjs/text-area/features/can_be_focused/index.js +1 -2
  8. package/build/cjs/text-area/features/common/index.js +0 -1
  9. package/build/cjs/text-area/index.js +0 -1
  10. package/build/cjs/text-area/text-area.e2e.stories.js +41 -0
  11. package/build/cjs/text-area/text-area.js +10 -61
  12. package/build/cjs/text-area/{text-area.stories.js → text-area.prod.stories.js} +31 -52
  13. package/build/cjs/text-area/text-area.styles.js +1 -4
  14. package/build/cjs/text-area-field/__tests__/text-area-field.test.js +1 -7
  15. package/build/cjs/text-area-field/features/can_be_required/index.js +0 -1
  16. package/build/cjs/text-area-field/index.js +0 -1
  17. package/build/cjs/text-area-field/text-area-field.e2e.stories.js +18 -0
  18. package/build/cjs/text-area-field/text-area-field.js +3 -34
  19. package/build/cjs/text-area-field/{text-area-field.stories.js → text-area-field.prod.stories.js} +35 -56
  20. package/build/es/text-area/features/accepts_initial_focus/index.js +1 -1
  21. package/build/es/text-area/features/can_be_blurred/index.js +1 -1
  22. package/build/es/text-area/features/can_be_changed/index.js +1 -1
  23. package/build/es/text-area/features/can_be_focused/index.js +1 -1
  24. package/build/es/text-area/{text-area.stories.e2e.js → text-area.e2e.stories.js} +13 -7
  25. package/build/es/text-area/text-area.js +7 -47
  26. package/build/es/text-area/{text-area.stories.js → text-area.prod.stories.js} +19 -14
  27. package/build/es/text-area/text-area.styles.js +1 -1
  28. package/build/es/text-area-field/text-area-field.e2e.stories.js +10 -0
  29. package/build/es/text-area-field/text-area-field.js +2 -26
  30. package/build/es/text-area-field/{text-area-field.stories.js → text-area-field.prod.stories.js} +18 -10
  31. package/package.json +10 -10
  32. package/build/cjs/text-area/text-area.stories.e2e.js +0 -30
  33. package/build/cjs/text-area-field/text-area-field.stories.e2e.js +0 -15
  34. package/build/es/text-area-field/text-area-field.stories.e2e.js +0 -8
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.WithLabelAndRequired = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _index = require("./index.js");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ var _default = exports.default = {
11
+ title: 'TextAreaField'
12
+ };
13
+ const WithLabelAndRequired = () => /*#__PURE__*/_react.default.createElement(_index.TextAreaField, {
14
+ name: "textarea",
15
+ label: "I am required and have an asterisk",
16
+ required: true
17
+ });
18
+ exports.WithLabelAndRequired = WithLabelAndRequired;
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TextAreaField = void 0;
7
-
7
+ var _uiConstants = require("@dhis2/ui-constants");
8
8
  var _box = require("@dhis2-ui/box");
9
-
10
9
  var _field = require("@dhis2-ui/field");
11
-
12
- var _uiConstants = require("@dhis2/ui-constants");
13
-
14
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
-
16
11
  var _react = _interopRequireDefault(require("react"));
17
-
18
- var _index = require("../index.js");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
12
+ var _index = require("../text-area/index.js");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
14
  const TextAreaField = _ref => {
23
15
  let {
24
16
  className,
@@ -85,7 +77,6 @@ const TextAreaField = _ref => {
85
77
  rows: rows
86
78
  })));
87
79
  };
88
-
89
80
  exports.TextAreaField = TextAreaField;
90
81
  TextAreaField.defaultProps = {
91
82
  rows: 4,
@@ -97,71 +88,49 @@ TextAreaField.propTypes = {
97
88
  autoGrow: _propTypes.default.bool,
98
89
  className: _propTypes.default.string,
99
90
  dataTest: _propTypes.default.string,
100
-
101
91
  /** Compact mode */
102
92
  dense: _propTypes.default.bool,
103
-
104
93
  /** Disables the textarea and makes in non-interactive */
105
94
  disabled: _propTypes.default.bool,
106
-
107
95
  /** Applies 'error' styles for validation feedback. Mutually exclusive with `valid` and `warning` props */
108
96
  error: _uiConstants.sharedPropTypes.statusPropType,
109
-
110
97
  /** Adds useful help text below the textarea */
111
98
  helpText: _propTypes.default.string,
112
-
113
99
  /** Grabs initial focus on the page */
114
100
  initialFocus: _propTypes.default.bool,
115
-
116
101
  /** Sets the width of the textarea. Minimum 220px. Any valid CSS measurement can be used */
117
102
  inputWidth: _propTypes.default.string,
118
-
119
103
  /** Labels the textarea */
120
104
  label: _propTypes.default.string,
121
-
122
105
  /** Adds a loading spinner */
123
106
  loading: _propTypes.default.bool,
124
-
125
107
  /** Name associated with the text area. Passed in object argument to event handlers. */
126
108
  name: _propTypes.default.string,
127
-
128
109
  /** Placeholder text for an empty textarea */
129
110
  placeholder: _propTypes.default.string,
130
-
131
111
  /** Makes the textarea read-only */
132
112
  readOnly: _propTypes.default.bool,
133
-
134
113
  /** Adds an asterisk to the label to indicate this field is required */
135
114
  required: _propTypes.default.bool,
136
-
137
115
  /** [Resize property](https://developer.mozilla.org/en-US/docs/Web/CSS/resize) for the textarea element */
138
116
  resize: _propTypes.default.oneOf(['none', 'both', 'horizontal', 'vertical']),
139
-
140
117
  /** Initial height of the textarea, in lines of text */
141
118
  rows: _propTypes.default.number,
142
119
  tabIndex: _propTypes.default.string,
143
-
144
120
  /** Applies 'valid' styles for validation feedback. Mutually exclusive with `warning` and `error` props */
145
121
  valid: _uiConstants.sharedPropTypes.statusPropType,
146
-
147
122
  /** Validation text below the textarea to provide validation feedback. Changes appearance depending on validation status */
148
123
  validationText: _propTypes.default.string,
149
-
150
124
  /** Value in the textarea. Can be used to control component (recommended). Passed in object argument to event handlers. */
151
125
  value: _propTypes.default.string,
152
-
153
126
  /** Applies 'warning' styles for validation feedback. Mutually exclusive with `valid` and `error` props */
154
127
  warning: _uiConstants.sharedPropTypes.statusPropType,
155
-
156
128
  /** Called with signature ({ name: string, value: string }, event) */
157
129
  onBlur: _propTypes.default.func,
158
-
159
130
  /** Called with signature ({ name: string, value: string }, event) */
160
131
  onChange: _propTypes.default.func,
161
-
162
132
  /** Called with signature ({ name: string, value: string }, event) */
163
133
  onFocus: _propTypes.default.func,
164
-
165
134
  /** Called with signature ({ name: string, value: string }, event) */
166
135
  onKeyDown: _propTypes.default.func
167
136
  };
@@ -4,19 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.WithValue = exports.WithHelpText = exports.TextareaTextOverflow = exports.StatusWarning = exports.StatusValid = exports.StatusLoading = exports.StatusError = exports.Rows = exports.Resize = exports.Required = exports.ReadOnly = exports.PlaceholderNoValue = exports.NoPlaceholderNoValue = exports.LabelTextOverflow = exports.InputWidth = exports.Focus = exports.Disabled = exports.Dense = exports.Autogrow = void 0;
7
-
8
7
  var _uiConstants = require("@dhis2/ui-constants");
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var _index = require("./index.js");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function _extends() { _extends = Object.assign || 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); }
17
-
18
- const description = "\n`TextAreaField` wraps a `TextArea` component with a label, help text, validation text, and other functions.\n\nSee the regular TextArea for usage information and options.\n\n```js\nimport { TextAreaField } from '@dhis2/ui'\n```\n";
19
- var _default = {
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
12
+ const description = `
13
+ \`TextAreaField\` wraps a \`TextArea\` component with a label, help text, validation text, and other functions.
14
+
15
+ See the regular TextArea for usage information and options.
16
+
17
+ \`\`\`js
18
+ import { TextAreaField } from '@dhis2/ui'
19
+ \`\`\`
20
+ `;
21
+ var _default = exports.default = {
20
22
  title: 'Text Area Field',
21
23
  component: _index.TextAreaField,
22
24
  parameters: {
@@ -32,65 +34,57 @@ var _default = {
32
34
  name: 'textareaName'
33
35
  },
34
36
  argTypes: {
35
- valid: { ..._uiConstants.sharedPropTypes.statusArgType
37
+ valid: {
38
+ ..._uiConstants.sharedPropTypes.statusArgType
36
39
  },
37
- warning: { ..._uiConstants.sharedPropTypes.statusArgType
40
+ warning: {
41
+ ..._uiConstants.sharedPropTypes.statusArgType
38
42
  },
39
- error: { ..._uiConstants.sharedPropTypes.statusArgType
43
+ error: {
44
+ ..._uiConstants.sharedPropTypes.statusArgType
40
45
  }
41
46
  }
42
47
  };
43
- exports.default = _default;
44
-
45
48
  const Template = args => /*#__PURE__*/_react.default.createElement(_index.TextAreaField, args);
46
-
47
- const NoPlaceholderNoValue = Template.bind({});
48
- exports.NoPlaceholderNoValue = NoPlaceholderNoValue;
49
+ const NoPlaceholderNoValue = exports.NoPlaceholderNoValue = Template.bind({});
49
50
  NoPlaceholderNoValue.storyName = 'No placeholder, no value';
50
- const PlaceholderNoValue = Template.bind({});
51
- exports.PlaceholderNoValue = PlaceholderNoValue;
51
+ const PlaceholderNoValue = exports.PlaceholderNoValue = Template.bind({});
52
52
  PlaceholderNoValue.args = {
53
53
  placeholder: 'Hold the place'
54
54
  };
55
55
  PlaceholderNoValue.storyName = 'Placeholder, no value';
56
- const WithHelpText = Template.bind({});
57
- exports.WithHelpText = WithHelpText;
56
+ const WithHelpText = exports.WithHelpText = Template.bind({});
58
57
  WithHelpText.args = {
59
58
  helpText: 'With some helping text to guide the user along',
60
59
  ...PlaceholderNoValue.args
61
60
  };
62
- const WithValue = Template.bind({});
63
- exports.WithValue = WithValue;
61
+ const WithValue = exports.WithValue = Template.bind({});
64
62
  WithValue.args = {
65
63
  value: 'This is set through the value prop, which means the component is controlled.'
66
64
  };
67
- const Focus = Template.bind({});
68
- exports.Focus = Focus;
65
+ const Focus = exports.Focus = Template.bind({});
69
66
  Focus.args = {
70
67
  initialFocus: true
71
- }; // Disable stories that manipulate focus on docs page
72
-
68
+ };
69
+ // Disable stories that manipulate focus on docs page
73
70
  Focus.parameters = {
74
71
  docs: {
75
72
  disable: true
76
73
  }
77
74
  };
78
- const StatusValid = Template.bind({});
79
- exports.StatusValid = StatusValid;
75
+ const StatusValid = exports.StatusValid = Template.bind({});
80
76
  StatusValid.args = {
81
77
  valid: true,
82
78
  value: 'This value is valid'
83
79
  };
84
80
  StatusValid.storyName = 'Status: Valid';
85
- const StatusWarning = Template.bind({});
86
- exports.StatusWarning = StatusWarning;
81
+ const StatusWarning = exports.StatusWarning = Template.bind({});
87
82
  StatusWarning.args = {
88
83
  warning: true,
89
84
  value: 'This value produces a warning'
90
85
  };
91
86
  StatusWarning.storyName = 'Status: Warning';
92
- const StatusError = Template.bind({});
93
- exports.StatusError = StatusError;
87
+ const StatusError = exports.StatusError = Template.bind({});
94
88
  StatusError.args = {
95
89
  error: true,
96
90
  value: 'This value produces an error',
@@ -98,63 +92,53 @@ StatusError.args = {
98
92
  validationText: 'This describes the error, if a message is supplied.'
99
93
  };
100
94
  StatusError.storyName = 'Status: Error';
101
- const StatusLoading = Template.bind({});
102
- exports.StatusLoading = StatusLoading;
95
+ const StatusLoading = exports.StatusLoading = Template.bind({});
103
96
  StatusLoading.args = {
104
97
  loading: true,
105
98
  value: 'This value produces a loadingn state'
106
99
  };
107
100
  StatusLoading.storyName = 'Status: Loading';
108
- const Disabled = Template.bind({});
109
- exports.Disabled = Disabled;
101
+ const Disabled = exports.Disabled = Template.bind({});
110
102
  Disabled.args = {
111
103
  disabled: true,
112
104
  value: 'This field is disabled'
113
105
  };
114
- const ReadOnly = Template.bind({});
115
- exports.ReadOnly = ReadOnly;
106
+ const ReadOnly = exports.ReadOnly = Template.bind({});
116
107
  ReadOnly.args = {
117
108
  readOnly: true,
118
109
  value: 'This field is readOnly'
119
110
  };
120
- const Dense = Template.bind({});
121
- exports.Dense = Dense;
111
+ const Dense = exports.Dense = Template.bind({});
122
112
  Dense.args = {
123
113
  dense: true,
124
114
  value: 'This field is dense'
125
115
  };
126
- const LabelTextOverflow = Template.bind({});
127
- exports.LabelTextOverflow = LabelTextOverflow;
116
+ const LabelTextOverflow = exports.LabelTextOverflow = Template.bind({});
128
117
  LabelTextOverflow.args = {
129
118
  label: "This label is too long to show on a single line of the input field's label. We just let it flow to the next line so the user can still read it. However, we should always aim to keep it shorter than this!"
130
119
  };
131
120
  LabelTextOverflow.storyName = 'Label text overflow';
132
- const TextareaTextOverflow = Template.bind({});
133
- exports.TextareaTextOverflow = TextareaTextOverflow;
121
+ const TextareaTextOverflow = exports.TextareaTextOverflow = Template.bind({});
134
122
  TextareaTextOverflow.args = {
135
123
  label: 'I have a scrollbar',
136
124
  value: ['A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text', 'A line of text'].join('\n')
137
125
  };
138
-
139
126
  const Required = () => /*#__PURE__*/_react.default.createElement(_index.TextAreaField, {
140
127
  onChange: () => {},
141
128
  name: "textarea",
142
129
  label: "I am required and have an asterisk",
143
130
  required: true
144
131
  });
145
-
146
132
  exports.Required = Required;
147
133
  Required.args = {
148
134
  required: true,
149
135
  label: 'I am required and have an asterisk'
150
136
  };
151
- const Rows = Template.bind({});
152
- exports.Rows = Rows;
137
+ const Rows = exports.Rows = Template.bind({});
153
138
  Rows.args = {
154
139
  rows: 8,
155
140
  label: 'You can set the height with the rows prop. I have 8'
156
141
  };
157
-
158
142
  const InputWidth = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.TextAreaField, _extends({}, args, {
159
143
  label: "My textarea has a width of 220px (the minimum)",
160
144
  inputWidth: "220px"
@@ -162,9 +146,7 @@ const InputWidth = args => /*#__PURE__*/_react.default.createElement(_react.defa
162
146
  label: "My textarea has a width of 400px",
163
147
  inputWidth: "400px"
164
148
  })));
165
-
166
149
  exports.InputWidth = InputWidth;
167
-
168
150
  const Resize = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.TextAreaField, _extends({}, args, {
169
151
  name: "textarea1",
170
152
  label: "Resize: vertical (default)"
@@ -181,9 +163,7 @@ const Resize = args => /*#__PURE__*/_react.default.createElement(_react.default.
181
163
  label: "Resize: horizontal",
182
164
  resize: "horizontal"
183
165
  })));
184
-
185
166
  exports.Resize = Resize;
186
-
187
167
  const Autogrow = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.TextAreaField, _extends({}, args, {
188
168
  name: "textarea1",
189
169
  label: "Autogrow step 1",
@@ -207,5 +187,4 @@ const Autogrow = args => /*#__PURE__*/_react.default.createElement(_react.defaul
207
187
  label: "Autogrow step 4",
208
188
  value: ['This TextArea has a height of two rows', 'it also has autoGrow set to true so it will grow with the content.', 'See: rows is still 2...', 'And now I have 4 lines and still no scroll bar in sight.'].join('\n')
209
189
  })));
210
-
211
190
  exports.Autogrow = Autogrow;
@@ -1,6 +1,6 @@
1
1
  import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
2
2
  Given('a TextArea with initialFocus is rendered', () => {
3
- cy.visitStory('TextArea', 'With initialFocus');
3
+ cy.visitStory('TextArea', 'With initial focus');
4
4
  });
5
5
  Then('the TextArea is focused', () => {
6
6
  cy.focused().parent('[data-test="dhis2-uicore-textarea"]').should('exist');
@@ -1,6 +1,6 @@
1
1
  import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
2
2
  Given('a TextArea with initialFocus and onBlur handler is rendered', () => {
3
- cy.visitStory('TextArea', 'With initialFocus and onBlur');
3
+ cy.visitStory('TextArea', 'With initial focus and on blur');
4
4
  });
5
5
  When('the TextArea is blurred', () => {
6
6
  cy.get('[data-test="dhis2-uicore-textarea"] textarea').blur();
@@ -1,6 +1,6 @@
1
1
  import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
2
2
  Given('a TextArea with onChange handler is rendered', () => {
3
- cy.visitStory('TextArea', 'With onChange');
3
+ cy.visitStory('TextArea', 'With on change');
4
4
  });
5
5
  When('the TextArea is filled with a character', () => {
6
6
  cy.get('[data-test="dhis2-uicore-textarea"]').click().type('a');
@@ -1,6 +1,6 @@
1
1
  import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
2
2
  Given('a TextArea with onFocus handler is rendered', () => {
3
- cy.visitStory('TextArea', 'With onFocus');
3
+ cy.visitStory('TextArea', 'With on focus');
4
4
  });
5
5
  When('the TextArea is focused', () => {
6
6
  cy.get('[data-test="dhis2-uicore-textarea"] textarea').focus();
@@ -1,23 +1,29 @@
1
- import { storiesOf } from '@storybook/react';
2
1
  import React from 'react';
3
2
  import { TextArea } from './index.js';
4
3
  window.onChange = window.Cypress && window.Cypress.cy.stub();
5
4
  window.onBlur = window.Cypress && window.Cypress.cy.stub();
6
5
  window.onFocus = window.Cypress && window.Cypress.cy.stub();
7
- storiesOf('TextArea', module).add('With onChange', () => /*#__PURE__*/React.createElement(TextArea, {
6
+ export default {
7
+ title: 'TextArea'
8
+ };
9
+ export const WithOnChange = () => /*#__PURE__*/React.createElement(TextArea, {
8
10
  onChange: window.onChange,
9
11
  name: "textarea"
10
- })).add('With initialFocus and onBlur', () => /*#__PURE__*/React.createElement(TextArea, {
12
+ });
13
+ export const WithInitialFocusAndOnBlur = () => /*#__PURE__*/React.createElement(TextArea, {
11
14
  initialFocus: true,
12
15
  name: "textarea",
13
16
  onBlur: window.onBlur
14
- })).add('With onFocus', () => /*#__PURE__*/React.createElement(TextArea, {
17
+ });
18
+ export const WithOnFocus = () => /*#__PURE__*/React.createElement(TextArea, {
15
19
  name: "textarea",
16
20
  onFocus: window.onFocus
17
- })).add('With initialFocus', () => /*#__PURE__*/React.createElement(TextArea, {
21
+ });
22
+ export const WithInitialFocus = () => /*#__PURE__*/React.createElement(TextArea, {
18
23
  name: "textarea",
19
24
  initialFocus: true
20
- })).add('With disabled', () => /*#__PURE__*/React.createElement(TextArea, {
25
+ });
26
+ export const WithDisabled = () => /*#__PURE__*/React.createElement(TextArea, {
21
27
  name: "textarea",
22
28
  disabled: true
23
- }));
29
+ });
@@ -1,9 +1,9 @@
1
1
  import _JSXStyle from "styled-jsx/style";
2
-
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
-
5
- import { StatusIcon } from '@dhis2-ui/status-icon';
2
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
5
  import { sharedPropTypes } from '@dhis2/ui-constants';
6
+ import { StatusIcon } from '@dhis2-ui/status-icon';
7
7
  import cx from 'classnames';
8
8
  import PropTypes from 'prop-types';
9
9
  import React, { Component } from 'react';
@@ -11,20 +11,15 @@ import { styles } from './text-area.styles.js';
11
11
  export class TextArea extends Component {
12
12
  constructor() {
13
13
  super(...arguments);
14
-
15
14
  _defineProperty(this, "textareaRef", /*#__PURE__*/React.createRef());
16
-
17
15
  _defineProperty(this, "state", {
18
16
  height: 'auto'
19
17
  });
20
-
21
18
  _defineProperty(this, "textareaDimensions", {
22
19
  width: 0,
23
20
  height: 0
24
21
  });
25
-
26
22
  _defineProperty(this, "userHasResized", false);
27
-
28
23
  _defineProperty(this, "setTextareaDimensions", () => {
29
24
  const textarea = this.textareaRef.current;
30
25
  this.textareaDimensions = {
@@ -32,7 +27,6 @@ export class TextArea extends Component {
32
27
  height: textarea.clientHeight
33
28
  };
34
29
  });
35
-
36
30
  _defineProperty(this, "hasUserResized", () => {
37
31
  const {
38
32
  width: oldWidth,
@@ -44,68 +38,56 @@ export class TextArea extends Component {
44
38
  height: newHeight
45
39
  } = this.textareaDimensions;
46
40
  const userHasResized = newWidth !== oldWidth || newHeight !== oldHeight;
47
-
48
41
  if (userHasResized) {
49
42
  this.userHasResized = true;
50
43
  this.removeResizeListener();
51
44
  }
52
45
  });
53
-
54
46
  _defineProperty(this, "handleChange", e => {
55
47
  if (this.props.onChange) {
56
48
  this.props.onChange(this.createHandlerPayload(e), e);
57
49
  }
58
50
  });
59
-
60
51
  _defineProperty(this, "handleBlur", e => {
61
52
  if (this.props.onBlur) {
62
53
  this.props.onBlur(this.createHandlerPayload(e), e);
63
54
  }
64
55
  });
65
-
66
56
  _defineProperty(this, "handleFocus", e => {
67
57
  if (this.props.onFocus) {
68
58
  this.props.onFocus(this.createHandlerPayload(e), e);
69
59
  }
70
60
  });
71
-
72
61
  _defineProperty(this, "handleKeyDown", e => {
73
62
  if (this.props.onKeyDown) {
74
63
  this.props.onKeyDown(this.createHandlerPayload(e), e);
75
64
  }
76
65
  });
77
66
  }
78
-
79
67
  componentDidMount() {
80
68
  this.attachResizeListener();
81
-
82
69
  if (this.props.initialFocus) {
83
70
  this.textareaRef.current.focus();
84
71
  }
85
-
86
72
  if (this.shouldDoAutoGrow()) {
87
73
  this.setHeight();
88
74
  }
89
75
  }
90
-
91
76
  componentDidUpdate(prevProps) {
92
77
  if (this.shouldDoAutoGrow() && this.props.value !== prevProps.value) {
93
78
  this.setHeight();
94
79
  }
95
80
  }
96
-
97
81
  attachResizeListener() {
98
82
  const textarea = this.textareaRef.current;
99
83
  textarea.addEventListener('mousedown', this.setTextareaDimensions);
100
84
  textarea.addEventListener('mouseup', this.hasUserResized);
101
85
  }
102
-
103
86
  removeResizeListener() {
104
87
  const textarea = this.textareaRef.current;
105
88
  textarea.removeEventListener('mousedown', this.setTextareaDimensions);
106
89
  textarea.removeEventListener('mouseup', this.hasUserResized);
107
90
  }
108
-
109
91
  setHeight() {
110
92
  const textarea = this.textareaRef.current;
111
93
  const offset = textarea.offsetHeight - textarea.clientHeight;
@@ -114,18 +96,15 @@ export class TextArea extends Component {
114
96
  height
115
97
  });
116
98
  }
117
-
118
99
  shouldDoAutoGrow() {
119
100
  return this.props.autoGrow && !this.userHasResized;
120
101
  }
121
-
122
102
  createHandlerPayload(e) {
123
103
  return {
124
104
  value: e.target.value,
125
105
  name: this.props.name
126
106
  };
127
107
  }
128
-
129
108
  render() {
130
109
  const {
131
110
  className,
@@ -150,7 +129,7 @@ export class TextArea extends Component {
150
129
  } = this.state;
151
130
  return /*#__PURE__*/React.createElement("div", {
152
131
  "data-test": dataTest,
153
- className: "jsx-".concat(styles.__hash) + " " + _JSXStyle.dynamic([["3036048772", [width, height, resize]]]) + " " + (cx('textarea', className) || "")
132
+ className: `jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([["3036048772", [width, height, resize]]]) + " " + (cx('textarea', className) || "")
154
133
  }, /*#__PURE__*/React.createElement("textarea", {
155
134
  id: name,
156
135
  name: name,
@@ -165,7 +144,7 @@ export class TextArea extends Component {
165
144
  onBlur: this.handleBlur,
166
145
  onChange: this.handleChange,
167
146
  rows: rows,
168
- className: "jsx-".concat(styles.__hash) + " " + _JSXStyle.dynamic([["3036048772", [width, height, resize]]]) + " " + (cx({
147
+ className: `jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([["3036048772", [width, height, resize]]]) + " " + (cx({
169
148
  dense,
170
149
  disabled,
171
150
  error,
@@ -183,9 +162,8 @@ export class TextArea extends Component {
183
162
  }, styles), /*#__PURE__*/React.createElement(_JSXStyle, {
184
163
  id: "3036048772",
185
164
  dynamic: [width, height, resize]
186
- }, ["textarea.__jsx-style-dynamic-selector{width:".concat(width, ";height:").concat(height, ";resize:").concat(resize, ";}")]));
165
+ }, [`textarea.__jsx-style-dynamic-selector{width:${width};height:${height};resize:${resize};}`]));
187
166
  }
188
-
189
167
  }
190
168
  TextArea.defaultProps = {
191
169
  rows: 4,
@@ -198,59 +176,41 @@ TextArea.propTypes = {
198
176
  autoGrow: PropTypes.bool,
199
177
  className: PropTypes.string,
200
178
  dataTest: PropTypes.string,
201
-
202
179
  /** Compact mode */
203
180
  dense: PropTypes.bool,
204
-
205
181
  /** Disables the textarea and makes in non-interactive */
206
182
  disabled: PropTypes.bool,
207
-
208
183
  /** Applies 'error' styles for validation feedback. Mutually exclusive with `valid` and `warning` props */
209
184
  error: sharedPropTypes.statusPropType,
210
-
211
185
  /** Grabs initial focus on the page */
212
186
  initialFocus: PropTypes.bool,
213
-
214
187
  /** Adds a loading spinner */
215
188
  loading: PropTypes.bool,
216
-
217
189
  /** Name associated with the text area. Passed in object argument to event handlers. */
218
190
  name: PropTypes.string,
219
-
220
191
  /** Placeholder text for an empty textarea */
221
192
  placeholder: PropTypes.string,
222
-
223
193
  /** Makes the textarea read-only */
224
194
  readOnly: PropTypes.bool,
225
-
226
195
  /** [Resize property](https://developer.mozilla.org/en-US/docs/Web/CSS/resize) for the textarea element */
227
196
  resize: PropTypes.oneOf(['none', 'both', 'horizontal', 'vertical']),
228
-
229
197
  /** Initial height of the textarea, in lines of text */
230
198
  rows: PropTypes.number,
231
199
  tabIndex: PropTypes.string,
232
-
233
200
  /** Applies 'valid' styles for validation feedback. Mutually exclusive with `warning` and `error` props */
234
201
  valid: sharedPropTypes.statusPropType,
235
-
236
202
  /** Value in the textarea. Can be used to control component (recommended). Passed in object argument to event handlers. */
237
203
  value: PropTypes.string,
238
-
239
204
  /** Applies 'warning' styles for validation feedback. Mutually exclusive with `valid` and `error` props */
240
205
  warning: sharedPropTypes.statusPropType,
241
-
242
206
  /** Width of the text area. Can be any valid CSS measurement */
243
207
  width: PropTypes.string,
244
-
245
208
  /** Called with signature ({ name: string, value: string }, event) */
246
209
  onBlur: PropTypes.func,
247
-
248
210
  /** Called with signature ({ name: string, value: string }, event) */
249
211
  onChange: PropTypes.func,
250
-
251
212
  /** Called with signature ({ name: string, value: string }, event) */
252
213
  onFocus: PropTypes.func,
253
-
254
214
  /** Called with signature ({ name: string, value: string }, event) */
255
215
  onKeyDown: PropTypes.func
256
216
  };