@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/index.js
CHANGED
|
@@ -40,7 +40,7 @@ var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(
|
|
|
40
40
|
var checkIcon__default = /*#__PURE__*/_interopDefaultLegacy(checkIcon);
|
|
41
41
|
var minusIcon__default = /*#__PURE__*/_interopDefaultLegacy(minusIcon);
|
|
42
42
|
|
|
43
|
-
const _excluded$
|
|
43
|
+
const _excluded$7 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
44
44
|
function mapCheckedToAriaChecked(value) {
|
|
45
45
|
switch (value) {
|
|
46
46
|
case true:
|
|
@@ -72,7 +72,7 @@ const CheckboxCore = React__namespace.forwardRef(function CheckboxCore(props, re
|
|
|
72
72
|
id,
|
|
73
73
|
testId
|
|
74
74
|
} = props,
|
|
75
|
-
sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$
|
|
75
|
+
sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$7);
|
|
76
76
|
const innerRef = React__namespace.useRef(null);
|
|
77
77
|
React__namespace.useEffect(() => {
|
|
78
78
|
if (innerRef.current != null) {
|
|
@@ -161,11 +161,11 @@ const colors$1 = {
|
|
|
161
161
|
active: activeRed
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
|
-
const styles$
|
|
164
|
+
const styles$6 = {};
|
|
165
165
|
const _generateStyles$1 = (checked, error) => {
|
|
166
166
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
167
|
-
if (styles$
|
|
168
|
-
return styles$
|
|
167
|
+
if (styles$6[styleKey]) {
|
|
168
|
+
return styles$6[styleKey];
|
|
169
169
|
}
|
|
170
170
|
const palette = error ? colors$1.error : colors$1.default;
|
|
171
171
|
let newStyles = {};
|
|
@@ -209,11 +209,11 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
-
styles$
|
|
213
|
-
return styles$
|
|
212
|
+
styles$6[styleKey] = aphrodite.StyleSheet.create(newStyles);
|
|
213
|
+
return styles$6[styleKey];
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
-
const _excluded$
|
|
216
|
+
const _excluded$6 = ["checked", "disabled", "error", "groupName", "id", "testId"];
|
|
217
217
|
const {
|
|
218
218
|
blue,
|
|
219
219
|
red,
|
|
@@ -236,7 +236,7 @@ const RadioCore = React__namespace.forwardRef(function RadioCore(props, ref) {
|
|
|
236
236
|
id,
|
|
237
237
|
testId
|
|
238
238
|
} = props,
|
|
239
|
-
sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$
|
|
239
|
+
sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$6);
|
|
240
240
|
const stateStyles = _generateStyles(checked, error);
|
|
241
241
|
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
|
|
242
242
|
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$1, _extends__default["default"]({}, sharedProps, {
|
|
@@ -303,11 +303,11 @@ const colors = {
|
|
|
303
303
|
active: wonderBlocksTokens.color.activeRed
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
|
-
const styles$
|
|
306
|
+
const styles$5 = {};
|
|
307
307
|
const _generateStyles = (checked, error) => {
|
|
308
308
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
309
|
-
if (styles$
|
|
310
|
-
return styles$
|
|
309
|
+
if (styles$5[styleKey]) {
|
|
310
|
+
return styles$5[styleKey];
|
|
311
311
|
}
|
|
312
312
|
const palette = error ? colors.error : colors.default;
|
|
313
313
|
let newStyles = {};
|
|
@@ -352,11 +352,11 @@ const _generateStyles = (checked, error) => {
|
|
|
352
352
|
}
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
-
styles$
|
|
356
|
-
return styles$
|
|
355
|
+
styles$5[styleKey] = aphrodite.StyleSheet.create(newStyles);
|
|
356
|
+
return styles$5[styleKey];
|
|
357
357
|
};
|
|
358
358
|
|
|
359
|
-
const _excluded$
|
|
359
|
+
const _excluded$5 = ["checked", "description", "disabled", "error", "id", "label", "onChange", "style", "className", "variant"];
|
|
360
360
|
const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props, ref) {
|
|
361
361
|
const {
|
|
362
362
|
checked,
|
|
@@ -370,7 +370,7 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
|
|
|
370
370
|
className,
|
|
371
371
|
variant
|
|
372
372
|
} = props,
|
|
373
|
-
coreProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$
|
|
373
|
+
coreProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$5);
|
|
374
374
|
const handleClick = () => {
|
|
375
375
|
if (variant === "radio" && checked) {
|
|
376
376
|
return;
|
|
@@ -386,14 +386,14 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
|
|
|
386
386
|
};
|
|
387
387
|
const getLabel = id => {
|
|
388
388
|
return React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
|
|
389
|
-
style: [styles$
|
|
389
|
+
style: [styles$4.label, disabled && styles$4.disabledLabel]
|
|
390
390
|
}, React__namespace.createElement("label", {
|
|
391
391
|
htmlFor: id
|
|
392
392
|
}, label));
|
|
393
393
|
};
|
|
394
394
|
const getDescription = id => {
|
|
395
395
|
return React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
396
|
-
style: styles$
|
|
396
|
+
style: styles$4.description,
|
|
397
397
|
id: id
|
|
398
398
|
}, description);
|
|
399
399
|
};
|
|
@@ -408,7 +408,7 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
|
|
|
408
408
|
style: style,
|
|
409
409
|
className: className
|
|
410
410
|
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
411
|
-
style: styles$
|
|
411
|
+
style: styles$4.wrapper,
|
|
412
412
|
tabIndex: -1
|
|
413
413
|
}, React__namespace.createElement(ChoiceCore, _extends__default["default"]({}, coreProps, {
|
|
414
414
|
id: uniqueId,
|
|
@@ -423,7 +423,7 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
|
|
|
423
423
|
}), label && getLabel(uniqueId)), description && getDescription(descriptionId));
|
|
424
424
|
});
|
|
425
425
|
});
|
|
426
|
-
const styles$
|
|
426
|
+
const styles$4 = aphrodite.StyleSheet.create({
|
|
427
427
|
wrapper: {
|
|
428
428
|
flexDirection: "row",
|
|
429
429
|
alignItems: "flex-start",
|
|
@@ -455,13 +455,13 @@ const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
|
455
455
|
}));
|
|
456
456
|
});
|
|
457
457
|
|
|
458
|
-
const _excluded$
|
|
458
|
+
const _excluded$4 = ["disabled", "error"];
|
|
459
459
|
const Radio = React__namespace.forwardRef(function Radio(props, ref) {
|
|
460
460
|
const {
|
|
461
461
|
disabled = false,
|
|
462
462
|
error = false
|
|
463
463
|
} = props,
|
|
464
|
-
otherProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$
|
|
464
|
+
otherProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$4);
|
|
465
465
|
return React__namespace.createElement(ChoiceInternal, _extends__default["default"]({}, otherProps, {
|
|
466
466
|
variant: "radio",
|
|
467
467
|
disabled: disabled,
|
|
@@ -470,7 +470,7 @@ const Radio = React__namespace.forwardRef(function Radio(props, ref) {
|
|
|
470
470
|
}));
|
|
471
471
|
});
|
|
472
472
|
|
|
473
|
-
const _excluded$
|
|
473
|
+
const _excluded$3 = ["checked", "disabled", "onChange", "value", "variant"];
|
|
474
474
|
const Choice = React__namespace.forwardRef(function Choice(props, ref) {
|
|
475
475
|
const {
|
|
476
476
|
checked = false,
|
|
@@ -478,7 +478,7 @@ const Choice = React__namespace.forwardRef(function Choice(props, ref) {
|
|
|
478
478
|
onChange = () => {},
|
|
479
479
|
variant
|
|
480
480
|
} = props,
|
|
481
|
-
remainingProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$
|
|
481
|
+
remainingProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$3);
|
|
482
482
|
const getChoiceComponent = variant => {
|
|
483
483
|
if (variant === "checkbox") {
|
|
484
484
|
return Checkbox;
|
|
@@ -495,7 +495,7 @@ const Choice = React__namespace.forwardRef(function Choice(props, ref) {
|
|
|
495
495
|
}));
|
|
496
496
|
});
|
|
497
497
|
|
|
498
|
-
const styles$
|
|
498
|
+
const styles$3 = aphrodite.StyleSheet.create({
|
|
499
499
|
fieldset: {
|
|
500
500
|
border: "none",
|
|
501
501
|
padding: 0,
|
|
@@ -543,16 +543,16 @@ const CheckboxGroup = React__namespace.forwardRef(function CheckboxGroup(props,
|
|
|
543
543
|
const allChildren = React__namespace.Children.toArray(children).filter(Boolean);
|
|
544
544
|
return React__namespace.createElement(StyledFieldset$1, {
|
|
545
545
|
"data-testid": testId,
|
|
546
|
-
style: styles$
|
|
546
|
+
style: styles$3.fieldset,
|
|
547
547
|
ref: ref
|
|
548
548
|
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
549
549
|
style: style
|
|
550
550
|
}, label && React__namespace.createElement(StyledLegend$1, {
|
|
551
|
-
style: styles$
|
|
551
|
+
style: styles$3.legend
|
|
552
552
|
}, React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, label)), description && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
553
|
-
style: styles$
|
|
553
|
+
style: styles$3.description
|
|
554
554
|
}, description), errorMessage && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
555
|
-
style: styles$
|
|
555
|
+
style: styles$3.error
|
|
556
556
|
}, errorMessage), (label || description || errorMessage) && React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
557
557
|
size: wonderBlocksTokens.spacing.small_12
|
|
558
558
|
}), allChildren.map((child, index) => {
|
|
@@ -568,7 +568,7 @@ const CheckboxGroup = React__namespace.forwardRef(function CheckboxGroup(props,
|
|
|
568
568
|
id: `${groupName}-${value}`,
|
|
569
569
|
key: value,
|
|
570
570
|
onChange: () => handleChange(value, checked),
|
|
571
|
-
style: [index > 0 && styles$
|
|
571
|
+
style: [index > 0 && styles$3.defaultLineGap, style],
|
|
572
572
|
variant: "checkbox"
|
|
573
573
|
});
|
|
574
574
|
})));
|
|
@@ -591,16 +591,16 @@ const RadioGroup = React__namespace.forwardRef(function RadioGroup(props, ref) {
|
|
|
591
591
|
const allChildren = React__namespace.Children.toArray(children).filter(Boolean);
|
|
592
592
|
return React__namespace.createElement(StyledFieldset, {
|
|
593
593
|
"data-testid": testId,
|
|
594
|
-
style: styles$
|
|
594
|
+
style: styles$3.fieldset,
|
|
595
595
|
ref: ref
|
|
596
596
|
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
597
597
|
style: style
|
|
598
598
|
}, label && React__namespace.createElement(StyledLegend, {
|
|
599
|
-
style: styles$
|
|
599
|
+
style: styles$3.legend
|
|
600
600
|
}, React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, label)), description && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
601
|
-
style: styles$
|
|
601
|
+
style: styles$3.description
|
|
602
602
|
}, description), errorMessage && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
603
|
-
style: styles$
|
|
603
|
+
style: styles$3.error
|
|
604
604
|
}, errorMessage), (label || description || errorMessage) && React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
605
605
|
size: wonderBlocksTokens.spacing.small_12
|
|
606
606
|
}), allChildren.map((child, index) => {
|
|
@@ -616,14 +616,14 @@ const RadioGroup = React__namespace.forwardRef(function RadioGroup(props, ref) {
|
|
|
616
616
|
id: `${groupName}-${value}`,
|
|
617
617
|
key: value,
|
|
618
618
|
onChange: () => onChange(value),
|
|
619
|
-
style: [index > 0 && styles$
|
|
619
|
+
style: [index > 0 && styles$3.defaultLineGap, style],
|
|
620
620
|
variant: "radio"
|
|
621
621
|
});
|
|
622
622
|
})));
|
|
623
623
|
});
|
|
624
624
|
|
|
625
|
-
const _excluded$
|
|
626
|
-
const defaultErrorMessage = "This field is required.";
|
|
625
|
+
const _excluded$2 = ["id", "type", "value", "name", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoFocus", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
|
|
626
|
+
const defaultErrorMessage$1 = "This field is required.";
|
|
627
627
|
const StyledInput = wonderBlocksCore.addStyle("input");
|
|
628
628
|
class TextField extends React__namespace.Component {
|
|
629
629
|
constructor(props) {
|
|
@@ -648,7 +648,7 @@ class TextField extends React__namespace.Component {
|
|
|
648
648
|
}
|
|
649
649
|
});
|
|
650
650
|
} else if (required) {
|
|
651
|
-
const requiredString = typeof required === "string" ? required : defaultErrorMessage;
|
|
651
|
+
const requiredString = typeof required === "string" ? required : defaultErrorMessage$1;
|
|
652
652
|
const maybeError = newValue ? null : requiredString;
|
|
653
653
|
this.setState({
|
|
654
654
|
error: maybeError
|
|
@@ -718,12 +718,12 @@ class TextField extends React__namespace.Component {
|
|
|
718
718
|
autoComplete,
|
|
719
719
|
forwardedRef
|
|
720
720
|
} = _this$props,
|
|
721
|
-
otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$
|
|
721
|
+
otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$2);
|
|
722
722
|
return React__namespace.createElement(wonderBlocksCore.IDProvider, {
|
|
723
723
|
id: id,
|
|
724
724
|
scope: "text-field"
|
|
725
725
|
}, uniqueId => React__namespace.createElement(StyledInput, _extends__default["default"]({
|
|
726
|
-
style: [styles$
|
|
726
|
+
style: [styles$2.input, wonderBlocksTypography.styles.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],
|
|
727
727
|
id: uniqueId,
|
|
728
728
|
type: type,
|
|
729
729
|
placeholder: placeholder,
|
|
@@ -749,7 +749,7 @@ TextField.defaultProps = {
|
|
|
749
749
|
disabled: false,
|
|
750
750
|
light: false
|
|
751
751
|
};
|
|
752
|
-
const styles$
|
|
752
|
+
const styles$2 = aphrodite.StyleSheet.create({
|
|
753
753
|
input: {
|
|
754
754
|
width: "100%",
|
|
755
755
|
height: 40,
|
|
@@ -813,11 +813,11 @@ class FieldHeading extends React__namespace.Component {
|
|
|
813
813
|
testId
|
|
814
814
|
} = this.props;
|
|
815
815
|
const requiredIcon = React__namespace.createElement(StyledSpan, {
|
|
816
|
-
style: styles.required,
|
|
816
|
+
style: styles$1.required,
|
|
817
817
|
"aria-hidden": true
|
|
818
818
|
}, " ", "*");
|
|
819
819
|
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
|
|
820
|
-
style: styles.label,
|
|
820
|
+
style: styles$1.label,
|
|
821
821
|
tag: "label",
|
|
822
822
|
htmlFor: id && `${id}-field`,
|
|
823
823
|
testId: testId && `${testId}-label`
|
|
@@ -834,7 +834,7 @@ class FieldHeading extends React__namespace.Component {
|
|
|
834
834
|
return null;
|
|
835
835
|
}
|
|
836
836
|
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
837
|
-
style: styles.description,
|
|
837
|
+
style: styles$1.description,
|
|
838
838
|
testId: testId && `${testId}-description`
|
|
839
839
|
}, description), React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
840
840
|
size: wonderBlocksTokens.spacing.xxxSmall_4
|
|
@@ -852,7 +852,7 @@ class FieldHeading extends React__namespace.Component {
|
|
|
852
852
|
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
853
853
|
size: wonderBlocksTokens.spacing.small_12
|
|
854
854
|
}), React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
|
|
855
|
-
style: styles.error,
|
|
855
|
+
style: styles$1.error,
|
|
856
856
|
role: "alert",
|
|
857
857
|
id: id && `${id}-error`,
|
|
858
858
|
testId: testId && `${testId}-error`
|
|
@@ -870,7 +870,7 @@ class FieldHeading extends React__namespace.Component {
|
|
|
870
870
|
}), field, this.maybeRenderError());
|
|
871
871
|
}
|
|
872
872
|
}
|
|
873
|
-
const styles = aphrodite.StyleSheet.create({
|
|
873
|
+
const styles$1 = aphrodite.StyleSheet.create({
|
|
874
874
|
label: {
|
|
875
875
|
color: wonderBlocksTokens.color.offBlack
|
|
876
876
|
},
|
|
@@ -885,7 +885,7 @@ const styles = aphrodite.StyleSheet.create({
|
|
|
885
885
|
}
|
|
886
886
|
});
|
|
887
887
|
|
|
888
|
-
const _excluded = ["id", "type", "label", "description", "value", "disabled", "required", "validate", "onChange", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "ariaDescribedby", "onValidate", "onFocus", "onBlur"];
|
|
888
|
+
const _excluded$1 = ["id", "type", "label", "description", "value", "disabled", "required", "validate", "onChange", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "ariaDescribedby", "onValidate", "onFocus", "onBlur"];
|
|
889
889
|
class LabeledTextField extends React__namespace.Component {
|
|
890
890
|
constructor(props) {
|
|
891
891
|
super(props);
|
|
@@ -952,7 +952,7 @@ class LabeledTextField extends React__namespace.Component {
|
|
|
952
952
|
forwardedRef,
|
|
953
953
|
ariaDescribedby
|
|
954
954
|
} = _this$props,
|
|
955
|
-
otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
|
|
955
|
+
otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
|
|
956
956
|
return React__namespace.createElement(wonderBlocksCore.IDProvider, {
|
|
957
957
|
id: id,
|
|
958
958
|
scope: "labeled-text-field"
|
|
@@ -997,9 +997,210 @@ var labeledTextField = React__namespace.forwardRef((props, ref) => React__namesp
|
|
|
997
997
|
forwardedRef: ref
|
|
998
998
|
})));
|
|
999
999
|
|
|
1000
|
+
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"];
|
|
1001
|
+
const defaultErrorMessage = "This field is required.";
|
|
1002
|
+
const StyledTextArea = wonderBlocksCore.addStyle("textarea");
|
|
1003
|
+
const TextArea = React__namespace.forwardRef(function TextArea(props, ref) {
|
|
1004
|
+
const {
|
|
1005
|
+
onChange,
|
|
1006
|
+
value,
|
|
1007
|
+
placeholder,
|
|
1008
|
+
disabled,
|
|
1009
|
+
id,
|
|
1010
|
+
testId,
|
|
1011
|
+
style,
|
|
1012
|
+
readOnly,
|
|
1013
|
+
autoComplete,
|
|
1014
|
+
name,
|
|
1015
|
+
className,
|
|
1016
|
+
autoFocus,
|
|
1017
|
+
rows,
|
|
1018
|
+
spellCheck,
|
|
1019
|
+
wrap,
|
|
1020
|
+
minLength,
|
|
1021
|
+
maxLength,
|
|
1022
|
+
onClick,
|
|
1023
|
+
onKeyDown,
|
|
1024
|
+
onKeyUp,
|
|
1025
|
+
onFocus,
|
|
1026
|
+
onBlur,
|
|
1027
|
+
validate,
|
|
1028
|
+
onValidate,
|
|
1029
|
+
required,
|
|
1030
|
+
resizeType,
|
|
1031
|
+
light
|
|
1032
|
+
} = props,
|
|
1033
|
+
otherProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded);
|
|
1034
|
+
const [error, setError] = React__namespace.useState(null);
|
|
1035
|
+
const ids = wonderBlocksCore.useUniqueIdWithMock("text-area");
|
|
1036
|
+
const uniqueId = id != null ? id : ids.get("id");
|
|
1037
|
+
const handleChange = event => {
|
|
1038
|
+
const newValue = event.target.value;
|
|
1039
|
+
onChange(newValue);
|
|
1040
|
+
handleValidation(newValue);
|
|
1041
|
+
};
|
|
1042
|
+
const handleValidation = newValue => {
|
|
1043
|
+
if (validate) {
|
|
1044
|
+
const error = validate(newValue) || null;
|
|
1045
|
+
setError(error);
|
|
1046
|
+
if (onValidate) {
|
|
1047
|
+
onValidate(error);
|
|
1048
|
+
}
|
|
1049
|
+
} else if (required) {
|
|
1050
|
+
const requiredString = typeof required === "string" ? required : defaultErrorMessage;
|
|
1051
|
+
const error = newValue ? null : requiredString;
|
|
1052
|
+
setError(error);
|
|
1053
|
+
if (onValidate) {
|
|
1054
|
+
onValidate(error);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
wonderBlocksCore.useOnMountEffect(() => {
|
|
1059
|
+
if (value !== "") {
|
|
1060
|
+
handleValidation(value);
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
const getStyles = () => {
|
|
1064
|
+
const baseStyles = [styles.textarea, wonderBlocksTypography.styles.LabelMedium, resizeType && resizeStyles[resizeType]];
|
|
1065
|
+
const defaultStyles = [styles.default, !disabled && styles.defaultFocus, disabled && styles.disabled, !!error && styles.error];
|
|
1066
|
+
const lightStyles = [styles.light, !disabled && styles.lightFocus, disabled && styles.lightDisabled, !!error && styles.lightError];
|
|
1067
|
+
return [...baseStyles, ...(light ? lightStyles : defaultStyles)];
|
|
1068
|
+
};
|
|
1069
|
+
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
1070
|
+
style: {
|
|
1071
|
+
width: "100%"
|
|
1072
|
+
}
|
|
1073
|
+
}, React__namespace.createElement(StyledTextArea, _extends__default["default"]({
|
|
1074
|
+
id: uniqueId,
|
|
1075
|
+
"data-testid": testId,
|
|
1076
|
+
ref: ref,
|
|
1077
|
+
className: className,
|
|
1078
|
+
style: [...getStyles(), style],
|
|
1079
|
+
value: value,
|
|
1080
|
+
onChange: handleChange,
|
|
1081
|
+
placeholder: placeholder,
|
|
1082
|
+
disabled: disabled,
|
|
1083
|
+
readOnly: readOnly,
|
|
1084
|
+
autoComplete: autoComplete,
|
|
1085
|
+
name: name,
|
|
1086
|
+
autoFocus: autoFocus,
|
|
1087
|
+
rows: rows,
|
|
1088
|
+
spellCheck: spellCheck,
|
|
1089
|
+
wrap: wrap,
|
|
1090
|
+
minLength: minLength,
|
|
1091
|
+
maxLength: maxLength,
|
|
1092
|
+
onClick: onClick,
|
|
1093
|
+
onKeyDown: onKeyDown,
|
|
1094
|
+
onKeyUp: onKeyUp,
|
|
1095
|
+
onFocus: onFocus,
|
|
1096
|
+
onBlur: onBlur,
|
|
1097
|
+
required: !!required
|
|
1098
|
+
}, otherProps, {
|
|
1099
|
+
"aria-invalid": !!error
|
|
1100
|
+
})));
|
|
1101
|
+
});
|
|
1102
|
+
const styles = aphrodite.StyleSheet.create({
|
|
1103
|
+
textarea: {
|
|
1104
|
+
borderRadius: wonderBlocksTokens.border.radius.medium_4,
|
|
1105
|
+
boxSizing: "border-box",
|
|
1106
|
+
padding: `10px ${wonderBlocksTokens.spacing.medium_16}px`,
|
|
1107
|
+
minHeight: "1em"
|
|
1108
|
+
},
|
|
1109
|
+
default: {
|
|
1110
|
+
background: wonderBlocksTokens.color.white,
|
|
1111
|
+
border: `1px solid ${wonderBlocksTokens.color.offBlack50}`,
|
|
1112
|
+
color: wonderBlocksTokens.color.offBlack,
|
|
1113
|
+
"::placeholder": {
|
|
1114
|
+
color: wonderBlocksTokens.color.offBlack64
|
|
1115
|
+
}
|
|
1116
|
+
},
|
|
1117
|
+
defaultFocus: {
|
|
1118
|
+
":focus-visible": {
|
|
1119
|
+
borderColor: wonderBlocksTokens.color.blue,
|
|
1120
|
+
outline: `1px solid ${wonderBlocksTokens.color.blue}`,
|
|
1121
|
+
outlineOffset: 0
|
|
1122
|
+
}
|
|
1123
|
+
},
|
|
1124
|
+
disabled: {
|
|
1125
|
+
background: wonderBlocksTokens.color.offWhite,
|
|
1126
|
+
border: `1px solid ${wonderBlocksTokens.color.offBlack16}`,
|
|
1127
|
+
color: wonderBlocksTokens.color.offBlack64,
|
|
1128
|
+
"::placeholder": {
|
|
1129
|
+
color: wonderBlocksTokens.color.offBlack64
|
|
1130
|
+
},
|
|
1131
|
+
cursor: "not-allowed"
|
|
1132
|
+
},
|
|
1133
|
+
error: {
|
|
1134
|
+
background: wonderBlocksTokens.color.fadedRed8,
|
|
1135
|
+
border: `1px solid ${wonderBlocksTokens.color.red}`,
|
|
1136
|
+
color: wonderBlocksTokens.color.offBlack,
|
|
1137
|
+
"::placeholder": {
|
|
1138
|
+
color: wonderBlocksTokens.color.offBlack64
|
|
1139
|
+
},
|
|
1140
|
+
":focus-visible": {
|
|
1141
|
+
outlineColor: wonderBlocksTokens.color.red,
|
|
1142
|
+
borderColor: wonderBlocksTokens.color.red
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
light: {
|
|
1146
|
+
background: wonderBlocksTokens.color.white,
|
|
1147
|
+
border: `1px solid ${wonderBlocksTokens.color.offBlack16}`,
|
|
1148
|
+
color: wonderBlocksTokens.color.offBlack,
|
|
1149
|
+
"::placeholder": {
|
|
1150
|
+
color: wonderBlocksTokens.color.offBlack64
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1153
|
+
lightFocus: {
|
|
1154
|
+
":focus-visible": {
|
|
1155
|
+
outline: `1px solid ${wonderBlocksTokens.color.blue}`,
|
|
1156
|
+
outlineOffset: 0,
|
|
1157
|
+
borderColor: wonderBlocksTokens.color.blue,
|
|
1158
|
+
boxShadow: `0px 0px 0px 2px ${wonderBlocksTokens.color.blue}, 0px 0px 0px 3px ${wonderBlocksTokens.color.white}`
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
lightDisabled: {
|
|
1162
|
+
backgroundColor: "transparent",
|
|
1163
|
+
border: `1px solid ${wonderBlocksTokens.color.white32}`,
|
|
1164
|
+
color: wonderBlocksTokens.color.white64,
|
|
1165
|
+
"::placeholder": {
|
|
1166
|
+
color: wonderBlocksTokens.color.white64
|
|
1167
|
+
},
|
|
1168
|
+
cursor: "not-allowed"
|
|
1169
|
+
},
|
|
1170
|
+
lightError: {
|
|
1171
|
+
background: wonderBlocksTokens.color.fadedRed8,
|
|
1172
|
+
border: `1px solid ${wonderBlocksTokens.color.red}`,
|
|
1173
|
+
boxShadow: `0px 0px 0px 1px ${wonderBlocksTokens.color.red}, 0px 0px 0px 2px ${wonderBlocksTokens.color.white}`,
|
|
1174
|
+
color: wonderBlocksTokens.color.offBlack,
|
|
1175
|
+
"::placeholder": {
|
|
1176
|
+
color: wonderBlocksTokens.color.offBlack64
|
|
1177
|
+
},
|
|
1178
|
+
":focus-visible": {
|
|
1179
|
+
outlineColor: wonderBlocksTokens.color.red,
|
|
1180
|
+
borderColor: wonderBlocksTokens.color.red,
|
|
1181
|
+
boxShadow: `0px 0px 0px 2px ${wonderBlocksTokens.color.red}, 0px 0px 0px 3px ${wonderBlocksTokens.color.white}`
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
const resizeStyles = aphrodite.StyleSheet.create({
|
|
1186
|
+
both: {
|
|
1187
|
+
resize: "both"
|
|
1188
|
+
},
|
|
1189
|
+
none: {
|
|
1190
|
+
resize: "none"
|
|
1191
|
+
},
|
|
1192
|
+
horizontal: {
|
|
1193
|
+
resize: "horizontal"
|
|
1194
|
+
},
|
|
1195
|
+
vertical: {
|
|
1196
|
+
resize: "vertical"
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1000
1200
|
exports.Checkbox = Checkbox;
|
|
1001
1201
|
exports.CheckboxGroup = CheckboxGroup;
|
|
1002
1202
|
exports.Choice = Choice;
|
|
1003
1203
|
exports.LabeledTextField = labeledTextField;
|
|
1004
1204
|
exports.RadioGroup = RadioGroup;
|
|
1205
|
+
exports.TextArea = TextArea;
|
|
1005
1206
|
exports.TextField = TextField$1;
|
package/package.json
CHANGED
|
@@ -187,7 +187,11 @@ describe("FieldHeading", () => {
|
|
|
187
187
|
render(
|
|
188
188
|
<FieldHeading
|
|
189
189
|
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
190
|
-
label={
|
|
190
|
+
label={
|
|
191
|
+
<I18nInlineMarkup b={(s: string) => <b>{s}</b>}>
|
|
192
|
+
{"<b>Test</b> Hello, world!"}
|
|
193
|
+
</I18nInlineMarkup>
|
|
194
|
+
}
|
|
191
195
|
/>,
|
|
192
196
|
);
|
|
193
197
|
|
|
@@ -205,7 +209,11 @@ describe("FieldHeading", () => {
|
|
|
205
209
|
<FieldHeading
|
|
206
210
|
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
207
211
|
label={<Body>Hello, world</Body>}
|
|
208
|
-
description={
|
|
212
|
+
description={
|
|
213
|
+
<I18nInlineMarkup b={(s: string) => <b>{s}</b>}>
|
|
214
|
+
{"<b>Test</b> description"}
|
|
215
|
+
</I18nInlineMarkup>
|
|
216
|
+
}
|
|
209
217
|
/>,
|
|
210
218
|
);
|
|
211
219
|
|