@khanacademy/wonder-blocks-form 4.7.5 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/components/text-area.d.ts +153 -0
- package/dist/es/index.js +252 -52
- package/dist/index.d.ts +2 -1
- package/dist/index.js +249 -48
- package/package.json +1 -1
- package/src/components/__tests__/field-heading.test.tsx +10 -2
- package/src/components/__tests__/text-area.test.tsx +1084 -0
- package/src/components/text-area.tsx +401 -0
- package/src/index.ts +2 -0
- package/tsconfig-build.tsbuildinfo +1 -1
package/dist/es/index.js
CHANGED
|
@@ -2,15 +2,15 @@ import _extends from '@babel/runtime/helpers/extends';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
4
4
|
import { StyleSheet } from 'aphrodite';
|
|
5
|
-
import { addStyle, UniqueIDProvider, View, IDProvider } from '@khanacademy/wonder-blocks-core';
|
|
5
|
+
import { addStyle, UniqueIDProvider, View, IDProvider, useUniqueIdWithMock, useOnMountEffect } from '@khanacademy/wonder-blocks-core';
|
|
6
6
|
import { Strut } from '@khanacademy/wonder-blocks-layout';
|
|
7
|
-
import { spacing, mix, color } from '@khanacademy/wonder-blocks-tokens';
|
|
8
|
-
import { LabelMedium, LabelSmall, styles as styles$
|
|
7
|
+
import { spacing, mix, color, border } from '@khanacademy/wonder-blocks-tokens';
|
|
8
|
+
import { LabelMedium, LabelSmall, styles as styles$7 } from '@khanacademy/wonder-blocks-typography';
|
|
9
9
|
import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
|
|
10
10
|
import checkIcon from '@phosphor-icons/core/bold/check-bold.svg';
|
|
11
11
|
import minusIcon from '@phosphor-icons/core/bold/minus-bold.svg';
|
|
12
12
|
|
|
13
|
-
const _excluded$
|
|
13
|
+
const _excluded$7 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
14
14
|
function mapCheckedToAriaChecked(value) {
|
|
15
15
|
switch (value) {
|
|
16
16
|
case true:
|
|
@@ -42,7 +42,7 @@ const CheckboxCore = React.forwardRef(function CheckboxCore(props, ref) {
|
|
|
42
42
|
id,
|
|
43
43
|
testId
|
|
44
44
|
} = props,
|
|
45
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
45
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$7);
|
|
46
46
|
const innerRef = React.useRef(null);
|
|
47
47
|
React.useEffect(() => {
|
|
48
48
|
if (innerRef.current != null) {
|
|
@@ -131,11 +131,11 @@ const colors$1 = {
|
|
|
131
131
|
active: activeRed
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
-
const styles$
|
|
134
|
+
const styles$6 = {};
|
|
135
135
|
const _generateStyles$1 = (checked, error) => {
|
|
136
136
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
137
|
-
if (styles$
|
|
138
|
-
return styles$
|
|
137
|
+
if (styles$6[styleKey]) {
|
|
138
|
+
return styles$6[styleKey];
|
|
139
139
|
}
|
|
140
140
|
const palette = error ? colors$1.error : colors$1.default;
|
|
141
141
|
let newStyles = {};
|
|
@@ -179,11 +179,11 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
-
styles$
|
|
183
|
-
return styles$
|
|
182
|
+
styles$6[styleKey] = StyleSheet.create(newStyles);
|
|
183
|
+
return styles$6[styleKey];
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
const _excluded$
|
|
186
|
+
const _excluded$6 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
187
187
|
const {
|
|
188
188
|
blue,
|
|
189
189
|
red,
|
|
@@ -206,7 +206,7 @@ const RadioCore = React.forwardRef(function RadioCore(props, ref) {
|
|
|
206
206
|
id,
|
|
207
207
|
testId
|
|
208
208
|
} = props,
|
|
209
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
209
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$6);
|
|
210
210
|
const stateStyles = _generateStyles(checked, error);
|
|
211
211
|
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
212
212
|
return React.createElement(React.Fragment, null, React.createElement(StyledInput$1, _extends({}, sharedProps, {
|
|
@@ -273,11 +273,11 @@ const colors = {
|
|
|
273
273
|
active: color.activeRed
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
|
-
const styles$
|
|
276
|
+
const styles$5 = {};
|
|
277
277
|
const _generateStyles = (checked, error) => {
|
|
278
278
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
279
|
-
if (styles$
|
|
280
|
-
return styles$
|
|
279
|
+
if (styles$5[styleKey]) {
|
|
280
|
+
return styles$5[styleKey];
|
|
281
281
|
}
|
|
282
282
|
const palette = error ? colors.error : colors.default;
|
|
283
283
|
let newStyles = {};
|
|
@@ -322,11 +322,11 @@ const _generateStyles = (checked, error) => {
|
|
|
322
322
|
}
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
|
-
styles$
|
|
326
|
-
return styles$
|
|
325
|
+
styles$5[styleKey] = StyleSheet.create(newStyles);
|
|
326
|
+
return styles$5[styleKey];
|
|
327
327
|
};
|
|
328
328
|
|
|
329
|
-
const _excluded$
|
|
329
|
+
const _excluded$5 = ["checked", "description", "disabled", "error", "id", "label", "onChange", "style", "className", "variant"];
|
|
330
330
|
const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
331
331
|
const {
|
|
332
332
|
checked,
|
|
@@ -340,7 +340,7 @@ const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
|
340
340
|
className,
|
|
341
341
|
variant
|
|
342
342
|
} = props,
|
|
343
|
-
coreProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
343
|
+
coreProps = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
344
344
|
const handleClick = () => {
|
|
345
345
|
if (variant === "radio" && checked) {
|
|
346
346
|
return;
|
|
@@ -356,14 +356,14 @@ const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
|
356
356
|
};
|
|
357
357
|
const getLabel = id => {
|
|
358
358
|
return React.createElement(LabelMedium, {
|
|
359
|
-
style: [styles$
|
|
359
|
+
style: [styles$4.label, disabled && styles$4.disabledLabel]
|
|
360
360
|
}, React.createElement("label", {
|
|
361
361
|
htmlFor: id
|
|
362
362
|
}, label));
|
|
363
363
|
};
|
|
364
364
|
const getDescription = id => {
|
|
365
365
|
return React.createElement(LabelSmall, {
|
|
366
|
-
style: styles$
|
|
366
|
+
style: styles$4.description,
|
|
367
367
|
id: id
|
|
368
368
|
}, description);
|
|
369
369
|
};
|
|
@@ -378,7 +378,7 @@ const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
|
378
378
|
style: style,
|
|
379
379
|
className: className
|
|
380
380
|
}, React.createElement(View, {
|
|
381
|
-
style: styles$
|
|
381
|
+
style: styles$4.wrapper,
|
|
382
382
|
tabIndex: -1
|
|
383
383
|
}, React.createElement(ChoiceCore, _extends({}, coreProps, {
|
|
384
384
|
id: uniqueId,
|
|
@@ -393,7 +393,7 @@ const ChoiceInternal = React.forwardRef(function ChoiceInternal(props, ref) {
|
|
|
393
393
|
}), label && getLabel(uniqueId)), description && getDescription(descriptionId));
|
|
394
394
|
});
|
|
395
395
|
});
|
|
396
|
-
const styles$
|
|
396
|
+
const styles$4 = StyleSheet.create({
|
|
397
397
|
wrapper: {
|
|
398
398
|
flexDirection: "row",
|
|
399
399
|
alignItems: "flex-start",
|
|
@@ -425,13 +425,13 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
|
|
425
425
|
}));
|
|
426
426
|
});
|
|
427
427
|
|
|
428
|
-
const _excluded$
|
|
428
|
+
const _excluded$4 = ["disabled", "error"];
|
|
429
429
|
const Radio = React.forwardRef(function Radio(props, ref) {
|
|
430
430
|
const {
|
|
431
431
|
disabled = false,
|
|
432
432
|
error = false
|
|
433
433
|
} = props,
|
|
434
|
-
otherProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
434
|
+
otherProps = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
435
435
|
return React.createElement(ChoiceInternal, _extends({}, otherProps, {
|
|
436
436
|
variant: "radio",
|
|
437
437
|
disabled: disabled,
|
|
@@ -440,7 +440,7 @@ const Radio = React.forwardRef(function Radio(props, ref) {
|
|
|
440
440
|
}));
|
|
441
441
|
});
|
|
442
442
|
|
|
443
|
-
const _excluded$
|
|
443
|
+
const _excluded$3 = ["checked", "disabled", "onChange", "value", "variant"];
|
|
444
444
|
const Choice = React.forwardRef(function Choice(props, ref) {
|
|
445
445
|
const {
|
|
446
446
|
checked = false,
|
|
@@ -448,7 +448,7 @@ const Choice = React.forwardRef(function Choice(props, ref) {
|
|
|
448
448
|
onChange = () => {},
|
|
449
449
|
variant
|
|
450
450
|
} = props,
|
|
451
|
-
remainingProps = _objectWithoutPropertiesLoose(props, _excluded$
|
|
451
|
+
remainingProps = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
452
452
|
const getChoiceComponent = variant => {
|
|
453
453
|
if (variant === "checkbox") {
|
|
454
454
|
return Checkbox;
|
|
@@ -465,7 +465,7 @@ const Choice = React.forwardRef(function Choice(props, ref) {
|
|
|
465
465
|
}));
|
|
466
466
|
});
|
|
467
467
|
|
|
468
|
-
const styles$
|
|
468
|
+
const styles$3 = StyleSheet.create({
|
|
469
469
|
fieldset: {
|
|
470
470
|
border: "none",
|
|
471
471
|
padding: 0,
|
|
@@ -513,16 +513,16 @@ const CheckboxGroup = React.forwardRef(function CheckboxGroup(props, ref) {
|
|
|
513
513
|
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
514
514
|
return React.createElement(StyledFieldset$1, {
|
|
515
515
|
"data-testid": testId,
|
|
516
|
-
style: styles$
|
|
516
|
+
style: styles$3.fieldset,
|
|
517
517
|
ref: ref
|
|
518
518
|
}, React.createElement(View, {
|
|
519
519
|
style: style
|
|
520
520
|
}, label && React.createElement(StyledLegend$1, {
|
|
521
|
-
style: styles$
|
|
521
|
+
style: styles$3.legend
|
|
522
522
|
}, React.createElement(LabelMedium, null, label)), description && React.createElement(LabelSmall, {
|
|
523
|
-
style: styles$
|
|
523
|
+
style: styles$3.description
|
|
524
524
|
}, description), errorMessage && React.createElement(LabelSmall, {
|
|
525
|
-
style: styles$
|
|
525
|
+
style: styles$3.error
|
|
526
526
|
}, errorMessage), (label || description || errorMessage) && React.createElement(Strut, {
|
|
527
527
|
size: spacing.small_12
|
|
528
528
|
}), allChildren.map((child, index) => {
|
|
@@ -538,7 +538,7 @@ const CheckboxGroup = React.forwardRef(function CheckboxGroup(props, ref) {
|
|
|
538
538
|
id: `${groupName}-${value}`,
|
|
539
539
|
key: value,
|
|
540
540
|
onChange: () => handleChange(value, checked),
|
|
541
|
-
style: [index > 0 && styles$
|
|
541
|
+
style: [index > 0 && styles$3.defaultLineGap, style],
|
|
542
542
|
variant: "checkbox"
|
|
543
543
|
});
|
|
544
544
|
})));
|
|
@@ -561,16 +561,16 @@ const RadioGroup = React.forwardRef(function RadioGroup(props, ref) {
|
|
|
561
561
|
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
562
562
|
return React.createElement(StyledFieldset, {
|
|
563
563
|
"data-testid": testId,
|
|
564
|
-
style: styles$
|
|
564
|
+
style: styles$3.fieldset,
|
|
565
565
|
ref: ref
|
|
566
566
|
}, React.createElement(View, {
|
|
567
567
|
style: style
|
|
568
568
|
}, label && React.createElement(StyledLegend, {
|
|
569
|
-
style: styles$
|
|
569
|
+
style: styles$3.legend
|
|
570
570
|
}, React.createElement(LabelMedium, null, label)), description && React.createElement(LabelSmall, {
|
|
571
|
-
style: styles$
|
|
571
|
+
style: styles$3.description
|
|
572
572
|
}, description), errorMessage && React.createElement(LabelSmall, {
|
|
573
|
-
style: styles$
|
|
573
|
+
style: styles$3.error
|
|
574
574
|
}, errorMessage), (label || description || errorMessage) && React.createElement(Strut, {
|
|
575
575
|
size: spacing.small_12
|
|
576
576
|
}), allChildren.map((child, index) => {
|
|
@@ -586,14 +586,14 @@ const RadioGroup = React.forwardRef(function RadioGroup(props, ref) {
|
|
|
586
586
|
id: `${groupName}-${value}`,
|
|
587
587
|
key: value,
|
|
588
588
|
onChange: () => onChange(value),
|
|
589
|
-
style: [index > 0 && styles$
|
|
589
|
+
style: [index > 0 && styles$3.defaultLineGap, style],
|
|
590
590
|
variant: "radio"
|
|
591
591
|
});
|
|
592
592
|
})));
|
|
593
593
|
});
|
|
594
594
|
|
|
595
|
-
const _excluded$
|
|
596
|
-
const defaultErrorMessage = "This field is required.";
|
|
595
|
+
const _excluded$2 = ["id", "type", "value", "name", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoFocus", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
|
|
596
|
+
const defaultErrorMessage$1 = "This field is required.";
|
|
597
597
|
const StyledInput = addStyle("input");
|
|
598
598
|
class TextField extends React.Component {
|
|
599
599
|
constructor(props) {
|
|
@@ -618,7 +618,7 @@ class TextField extends React.Component {
|
|
|
618
618
|
}
|
|
619
619
|
});
|
|
620
620
|
} else if (required) {
|
|
621
|
-
const requiredString = typeof required === "string" ? required : defaultErrorMessage;
|
|
621
|
+
const requiredString = typeof required === "string" ? required : defaultErrorMessage$1;
|
|
622
622
|
const maybeError = newValue ? null : requiredString;
|
|
623
623
|
this.setState({
|
|
624
624
|
error: maybeError
|
|
@@ -688,12 +688,12 @@ class TextField extends React.Component {
|
|
|
688
688
|
autoComplete,
|
|
689
689
|
forwardedRef
|
|
690
690
|
} = _this$props,
|
|
691
|
-
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded$
|
|
691
|
+
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded$2);
|
|
692
692
|
return React.createElement(IDProvider, {
|
|
693
693
|
id: id,
|
|
694
694
|
scope: "text-field"
|
|
695
695
|
}, uniqueId => React.createElement(StyledInput, _extends({
|
|
696
|
-
style: [styles$
|
|
696
|
+
style: [styles$2.input, styles$7.LabelMedium, styles$2.default, disabled ? styles$2.disabled : this.state.focused ? [styles$2.focused, light && styles$2.defaultLight] : !!this.state.error && [styles$2.error, light && styles$2.errorLight], !!this.state.error && styles$2.error, style && style],
|
|
697
697
|
id: uniqueId,
|
|
698
698
|
type: type,
|
|
699
699
|
placeholder: placeholder,
|
|
@@ -719,7 +719,7 @@ TextField.defaultProps = {
|
|
|
719
719
|
disabled: false,
|
|
720
720
|
light: false
|
|
721
721
|
};
|
|
722
|
-
const styles$
|
|
722
|
+
const styles$2 = StyleSheet.create({
|
|
723
723
|
input: {
|
|
724
724
|
width: "100%",
|
|
725
725
|
height: 40,
|
|
@@ -783,11 +783,11 @@ class FieldHeading extends React.Component {
|
|
|
783
783
|
testId
|
|
784
784
|
} = this.props;
|
|
785
785
|
const requiredIcon = React.createElement(StyledSpan, {
|
|
786
|
-
style: styles.required,
|
|
786
|
+
style: styles$1.required,
|
|
787
787
|
"aria-hidden": true
|
|
788
788
|
}, " ", "*");
|
|
789
789
|
return React.createElement(React.Fragment, null, React.createElement(LabelMedium, {
|
|
790
|
-
style: styles.label,
|
|
790
|
+
style: styles$1.label,
|
|
791
791
|
tag: "label",
|
|
792
792
|
htmlFor: id && `${id}-field`,
|
|
793
793
|
testId: testId && `${testId}-label`
|
|
@@ -804,7 +804,7 @@ class FieldHeading extends React.Component {
|
|
|
804
804
|
return null;
|
|
805
805
|
}
|
|
806
806
|
return React.createElement(React.Fragment, null, React.createElement(LabelSmall, {
|
|
807
|
-
style: styles.description,
|
|
807
|
+
style: styles$1.description,
|
|
808
808
|
testId: testId && `${testId}-description`
|
|
809
809
|
}, description), React.createElement(Strut, {
|
|
810
810
|
size: spacing.xxxSmall_4
|
|
@@ -822,7 +822,7 @@ class FieldHeading extends React.Component {
|
|
|
822
822
|
return React.createElement(React.Fragment, null, React.createElement(Strut, {
|
|
823
823
|
size: spacing.small_12
|
|
824
824
|
}), React.createElement(LabelSmall, {
|
|
825
|
-
style: styles.error,
|
|
825
|
+
style: styles$1.error,
|
|
826
826
|
role: "alert",
|
|
827
827
|
id: id && `${id}-error`,
|
|
828
828
|
testId: testId && `${testId}-error`
|
|
@@ -840,7 +840,7 @@ class FieldHeading extends React.Component {
|
|
|
840
840
|
}), field, this.maybeRenderError());
|
|
841
841
|
}
|
|
842
842
|
}
|
|
843
|
-
const styles = StyleSheet.create({
|
|
843
|
+
const styles$1 = StyleSheet.create({
|
|
844
844
|
label: {
|
|
845
845
|
color: color.offBlack
|
|
846
846
|
},
|
|
@@ -855,7 +855,7 @@ const styles = StyleSheet.create({
|
|
|
855
855
|
}
|
|
856
856
|
});
|
|
857
857
|
|
|
858
|
-
const _excluded = ["id", "type", "label", "description", "value", "disabled", "required", "validate", "onChange", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "ariaDescribedby", "onValidate", "onFocus", "onBlur"];
|
|
858
|
+
const _excluded$1 = ["id", "type", "label", "description", "value", "disabled", "required", "validate", "onChange", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "ariaDescribedby", "onValidate", "onFocus", "onBlur"];
|
|
859
859
|
class LabeledTextField extends React.Component {
|
|
860
860
|
constructor(props) {
|
|
861
861
|
super(props);
|
|
@@ -922,7 +922,7 @@ class LabeledTextField extends React.Component {
|
|
|
922
922
|
forwardedRef,
|
|
923
923
|
ariaDescribedby
|
|
924
924
|
} = _this$props,
|
|
925
|
-
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
925
|
+
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
926
926
|
return React.createElement(IDProvider, {
|
|
927
927
|
id: id,
|
|
928
928
|
scope: "labeled-text-field"
|
|
@@ -967,4 +967,204 @@ var labeledTextField = React.forwardRef((props, ref) => React.createElement(Labe
|
|
|
967
967
|
forwardedRef: ref
|
|
968
968
|
})));
|
|
969
969
|
|
|
970
|
-
|
|
970
|
+
const _excluded = ["onChange", "value", "placeholder", "disabled", "id", "testId", "style", "readOnly", "autoComplete", "name", "className", "autoFocus", "rows", "spellCheck", "wrap", "minLength", "maxLength", "onClick", "onKeyDown", "onKeyUp", "onFocus", "onBlur", "validate", "onValidate", "required", "resizeType", "light"];
|
|
971
|
+
const defaultErrorMessage = "This field is required.";
|
|
972
|
+
const StyledTextArea = addStyle("textarea");
|
|
973
|
+
const TextArea = React.forwardRef(function TextArea(props, ref) {
|
|
974
|
+
const {
|
|
975
|
+
onChange,
|
|
976
|
+
value,
|
|
977
|
+
placeholder,
|
|
978
|
+
disabled,
|
|
979
|
+
id,
|
|
980
|
+
testId,
|
|
981
|
+
style,
|
|
982
|
+
readOnly,
|
|
983
|
+
autoComplete,
|
|
984
|
+
name,
|
|
985
|
+
className,
|
|
986
|
+
autoFocus,
|
|
987
|
+
rows,
|
|
988
|
+
spellCheck,
|
|
989
|
+
wrap,
|
|
990
|
+
minLength,
|
|
991
|
+
maxLength,
|
|
992
|
+
onClick,
|
|
993
|
+
onKeyDown,
|
|
994
|
+
onKeyUp,
|
|
995
|
+
onFocus,
|
|
996
|
+
onBlur,
|
|
997
|
+
validate,
|
|
998
|
+
onValidate,
|
|
999
|
+
required,
|
|
1000
|
+
resizeType,
|
|
1001
|
+
light
|
|
1002
|
+
} = props,
|
|
1003
|
+
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1004
|
+
const [error, setError] = React.useState(null);
|
|
1005
|
+
const ids = useUniqueIdWithMock("text-area");
|
|
1006
|
+
const uniqueId = id != null ? id : ids.get("id");
|
|
1007
|
+
const handleChange = event => {
|
|
1008
|
+
const newValue = event.target.value;
|
|
1009
|
+
onChange(newValue);
|
|
1010
|
+
handleValidation(newValue);
|
|
1011
|
+
};
|
|
1012
|
+
const handleValidation = newValue => {
|
|
1013
|
+
if (validate) {
|
|
1014
|
+
const error = validate(newValue) || null;
|
|
1015
|
+
setError(error);
|
|
1016
|
+
if (onValidate) {
|
|
1017
|
+
onValidate(error);
|
|
1018
|
+
}
|
|
1019
|
+
} else if (required) {
|
|
1020
|
+
const requiredString = typeof required === "string" ? required : defaultErrorMessage;
|
|
1021
|
+
const error = newValue ? null : requiredString;
|
|
1022
|
+
setError(error);
|
|
1023
|
+
if (onValidate) {
|
|
1024
|
+
onValidate(error);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
useOnMountEffect(() => {
|
|
1029
|
+
if (value !== "") {
|
|
1030
|
+
handleValidation(value);
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
const getStyles = () => {
|
|
1034
|
+
const baseStyles = [styles.textarea, styles$7.LabelMedium, resizeType && resizeStyles[resizeType]];
|
|
1035
|
+
const defaultStyles = [styles.default, !disabled && styles.defaultFocus, disabled && styles.disabled, !!error && styles.error];
|
|
1036
|
+
const lightStyles = [styles.light, !disabled && styles.lightFocus, disabled && styles.lightDisabled, !!error && styles.lightError];
|
|
1037
|
+
return [...baseStyles, ...(light ? lightStyles : defaultStyles)];
|
|
1038
|
+
};
|
|
1039
|
+
return React.createElement(View, {
|
|
1040
|
+
style: {
|
|
1041
|
+
width: "100%"
|
|
1042
|
+
}
|
|
1043
|
+
}, React.createElement(StyledTextArea, _extends({
|
|
1044
|
+
id: uniqueId,
|
|
1045
|
+
"data-testid": testId,
|
|
1046
|
+
ref: ref,
|
|
1047
|
+
className: className,
|
|
1048
|
+
style: [...getStyles(), style],
|
|
1049
|
+
value: value,
|
|
1050
|
+
onChange: handleChange,
|
|
1051
|
+
placeholder: placeholder,
|
|
1052
|
+
disabled: disabled,
|
|
1053
|
+
readOnly: readOnly,
|
|
1054
|
+
autoComplete: autoComplete,
|
|
1055
|
+
name: name,
|
|
1056
|
+
autoFocus: autoFocus,
|
|
1057
|
+
rows: rows,
|
|
1058
|
+
spellCheck: spellCheck,
|
|
1059
|
+
wrap: wrap,
|
|
1060
|
+
minLength: minLength,
|
|
1061
|
+
maxLength: maxLength,
|
|
1062
|
+
onClick: onClick,
|
|
1063
|
+
onKeyDown: onKeyDown,
|
|
1064
|
+
onKeyUp: onKeyUp,
|
|
1065
|
+
onFocus: onFocus,
|
|
1066
|
+
onBlur: onBlur,
|
|
1067
|
+
required: !!required
|
|
1068
|
+
}, otherProps, {
|
|
1069
|
+
"aria-invalid": !!error
|
|
1070
|
+
})));
|
|
1071
|
+
});
|
|
1072
|
+
const styles = StyleSheet.create({
|
|
1073
|
+
textarea: {
|
|
1074
|
+
borderRadius: border.radius.medium_4,
|
|
1075
|
+
boxSizing: "border-box",
|
|
1076
|
+
padding: `10px ${spacing.medium_16}px`,
|
|
1077
|
+
minHeight: "1em"
|
|
1078
|
+
},
|
|
1079
|
+
default: {
|
|
1080
|
+
background: color.white,
|
|
1081
|
+
border: `1px solid ${color.offBlack50}`,
|
|
1082
|
+
color: color.offBlack,
|
|
1083
|
+
"::placeholder": {
|
|
1084
|
+
color: color.offBlack64
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
defaultFocus: {
|
|
1088
|
+
":focus-visible": {
|
|
1089
|
+
borderColor: color.blue,
|
|
1090
|
+
outline: `1px solid ${color.blue}`,
|
|
1091
|
+
outlineOffset: 0
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
disabled: {
|
|
1095
|
+
background: color.offWhite,
|
|
1096
|
+
border: `1px solid ${color.offBlack16}`,
|
|
1097
|
+
color: color.offBlack64,
|
|
1098
|
+
"::placeholder": {
|
|
1099
|
+
color: color.offBlack64
|
|
1100
|
+
},
|
|
1101
|
+
cursor: "not-allowed"
|
|
1102
|
+
},
|
|
1103
|
+
error: {
|
|
1104
|
+
background: color.fadedRed8,
|
|
1105
|
+
border: `1px solid ${color.red}`,
|
|
1106
|
+
color: color.offBlack,
|
|
1107
|
+
"::placeholder": {
|
|
1108
|
+
color: color.offBlack64
|
|
1109
|
+
},
|
|
1110
|
+
":focus-visible": {
|
|
1111
|
+
outlineColor: color.red,
|
|
1112
|
+
borderColor: color.red
|
|
1113
|
+
}
|
|
1114
|
+
},
|
|
1115
|
+
light: {
|
|
1116
|
+
background: color.white,
|
|
1117
|
+
border: `1px solid ${color.offBlack16}`,
|
|
1118
|
+
color: color.offBlack,
|
|
1119
|
+
"::placeholder": {
|
|
1120
|
+
color: color.offBlack64
|
|
1121
|
+
}
|
|
1122
|
+
},
|
|
1123
|
+
lightFocus: {
|
|
1124
|
+
":focus-visible": {
|
|
1125
|
+
outline: `1px solid ${color.blue}`,
|
|
1126
|
+
outlineOffset: 0,
|
|
1127
|
+
borderColor: color.blue,
|
|
1128
|
+
boxShadow: `0px 0px 0px 2px ${color.blue}, 0px 0px 0px 3px ${color.white}`
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
lightDisabled: {
|
|
1132
|
+
backgroundColor: "transparent",
|
|
1133
|
+
border: `1px solid ${color.white32}`,
|
|
1134
|
+
color: color.white64,
|
|
1135
|
+
"::placeholder": {
|
|
1136
|
+
color: color.white64
|
|
1137
|
+
},
|
|
1138
|
+
cursor: "not-allowed"
|
|
1139
|
+
},
|
|
1140
|
+
lightError: {
|
|
1141
|
+
background: color.fadedRed8,
|
|
1142
|
+
border: `1px solid ${color.red}`,
|
|
1143
|
+
boxShadow: `0px 0px 0px 1px ${color.red}, 0px 0px 0px 2px ${color.white}`,
|
|
1144
|
+
color: color.offBlack,
|
|
1145
|
+
"::placeholder": {
|
|
1146
|
+
color: color.offBlack64
|
|
1147
|
+
},
|
|
1148
|
+
":focus-visible": {
|
|
1149
|
+
outlineColor: color.red,
|
|
1150
|
+
borderColor: color.red,
|
|
1151
|
+
boxShadow: `0px 0px 0px 2px ${color.red}, 0px 0px 0px 3px ${color.white}`
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
const resizeStyles = StyleSheet.create({
|
|
1156
|
+
both: {
|
|
1157
|
+
resize: "both"
|
|
1158
|
+
},
|
|
1159
|
+
none: {
|
|
1160
|
+
resize: "none"
|
|
1161
|
+
},
|
|
1162
|
+
horizontal: {
|
|
1163
|
+
resize: "horizontal"
|
|
1164
|
+
},
|
|
1165
|
+
vertical: {
|
|
1166
|
+
resize: "vertical"
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
export { Checkbox, CheckboxGroup, Choice, labeledTextField as LabeledTextField, RadioGroup, TextArea, TextField$1 as TextField };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import CheckboxGroup from "./components/checkbox-group";
|
|
|
4
4
|
import RadioGroup from "./components/radio-group";
|
|
5
5
|
import TextField from "./components/text-field";
|
|
6
6
|
import LabeledTextField from "./components/labeled-text-field";
|
|
7
|
-
|
|
7
|
+
import TextArea from "./components/text-area";
|
|
8
|
+
export { Checkbox, Choice, CheckboxGroup, RadioGroup, TextField, LabeledTextField, TextArea, };
|