@nypl/design-system-react-components 1.2.0-rc-2 → 1.2.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.
@@ -12,6 +12,9 @@ interface LabelProps {
12
12
  /** Controls whether the "(Required)" text should be displayed alongside the
13
13
  * label's text. False by default. */
14
14
  isRequired?: boolean;
15
+ /** Allows the '(Required)' text to be changed for language purposes
16
+ * Note: Parenthesis will be added automatically by the component */
17
+ requiredLabelText?: string;
15
18
  }
16
19
  /**
17
20
  * A label for form inputs. It should never be used alone.
@@ -56,6 +56,9 @@ export interface InputProps {
56
56
  /** Whether or not to display the "(Required)" text in the label text.
57
57
  * True by default. */
58
58
  showRequiredLabel?: boolean;
59
+ /** Allows the '(Required)' text to be changed for language purposes
60
+ * Note: Parenthesis will be added automatically by the component */
61
+ requiredLabelText?: string;
59
62
  /** The amount to increase or decrease when using the number type. */
60
63
  step?: number;
61
64
  /** FOR INTERNAL DS USE ONLY: the input variant to display. */
@@ -3,7 +3,7 @@ export interface TooltipProps {
3
3
  /** Any child node passed to the component. */
4
4
  children: React.ReactNode;
5
5
  /** Value used to populate the tooltip content. */
6
- content: string | React.ReactNode;
6
+ content: string | number | React.ReactNode;
7
7
  /** A class name for the Tooltip parent div. */
8
8
  className?: string;
9
9
  /** ID that other components can cross reference for accessibility purposes. */
@@ -2514,33 +2514,49 @@ var AudioPlayer = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(funct
2514
2514
  id = props.id,
2515
2515
  _props$iframeTitle = props.iframeTitle,
2516
2516
  iframeTitle = _props$iframeTitle === void 0 ? null : _props$iframeTitle,
2517
- rest = _objectWithoutPropertiesLoose(props, _excluded$Z); // The root iframe object generated from the embedCode.
2517
+ rest = _objectWithoutPropertiesLoose(props, _excluded$Z);
2518
2518
 
2519
+ var _useState = React.useState(false),
2520
+ invalidEmbed = _useState[0],
2521
+ setInvalidEmbed = _useState[1];
2519
2522
 
2520
- var iframeDoc = parseIframeEmbedCode(embedCode); // when no embedCode or it was a broken code.
2523
+ var _useState2 = React.useState(undefined),
2524
+ iframeDoc = _useState2[0],
2525
+ setIframeDoc = _useState2[1];
2526
+ /**
2527
+ * Main hooks to check the embedCode structure.
2528
+ */
2521
2529
 
2522
- var isInvalidEmbed = !embedCode || !iframeDoc || !isValidEmbedCode(iframeDoc);
2523
- var errorMessage = "<strong>Error: </strong>This audio player has not been configured properly. Please contact the site administrator.";
2524
2530
 
2525
- function isValidEmbedCode(doc) {
2526
- var _doc$src;
2531
+ React.useEffect(function () {
2532
+ // The root iframe object generated from the embedCode.
2533
+ var iframe = parseIframeEmbedCode(embedCode); // when no embedCode or it was a broken code.
2527
2534
 
2528
- return audioType !== "file" && (doc == null ? void 0 : (_doc$src = doc.src) == null ? void 0 : _doc$src.includes(audioType + ".com"));
2529
- } // Only set the iframe title if it doesn't already have it in the iframe.
2535
+ var isInvalidEmbed = !embedCode || !iframe || !isValidEmbedCode(audioType, iframe); // Only set the iframe title if it doesn't already have it in the iframe.
2530
2536
 
2537
+ if (iframe && !iframe.title) {
2538
+ iframe.title = iframeTitle ? iframeTitle : "Embedded audio player";
2539
+ }
2531
2540
 
2532
- if (iframeDoc && !iframeDoc.title) {
2533
- iframeDoc.title = iframeTitle ? iframeTitle : "Embedded audio player";
2534
- }
2541
+ var isThirdPartyService = !!thirdPartyServices.find(function (service) {
2542
+ return service === audioType;
2543
+ });
2544
+ var isThirdPartyWithoutCode = isThirdPartyService && !embedCode;
2535
2545
 
2536
- var isThirdPartyService = !!thirdPartyServices.find(function (service) {
2537
- return service === audioType;
2538
- });
2539
- var isThirdPartyWithoutCode = isThirdPartyService && !embedCode;
2546
+ if (isThirdPartyWithoutCode) {
2547
+ console.warn("NYPL Reservoir AudioPlayer: The `embedCode` prop is required when using a 3rd party streaming service.");
2548
+ isInvalidEmbed = true;
2549
+ }
2550
+
2551
+ setInvalidEmbed(isInvalidEmbed);
2552
+ setIframeDoc(iframe);
2553
+ }, [embedCode, audioType, iframeTitle]);
2554
+ var errorMessage = "<strong>Error: </strong>This audio player has not been configured properly. Please contact the site administrator.";
2540
2555
 
2541
- if (isThirdPartyWithoutCode) {
2542
- console.warn("NYPL Reservoir AudioPlayer: The `embedCode` prop is required when using a 3rd party streaming service.");
2543
- isInvalidEmbed = true;
2556
+ function isValidEmbedCode(audioType, doc) {
2557
+ var _doc$src;
2558
+
2559
+ return audioType !== "file" && (doc == null ? void 0 : (_doc$src = doc.src) == null ? void 0 : _doc$src.includes(audioType + ".com"));
2544
2560
  }
2545
2561
 
2546
2562
  var styles = react.useMultiStyleConfig("AudioPlayer", {});
@@ -2567,7 +2583,7 @@ var AudioPlayer = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(funct
2567
2583
  "data-testid": "audio-player-component",
2568
2584
  ref: ref,
2569
2585
  __css: styles
2570
- }, rest), isInvalidEmbed ? React__default.createElement(react.Box, {
2586
+ }, rest), invalidEmbed ? React__default.createElement(react.Box, {
2571
2587
  dangerouslySetInnerHTML: {
2572
2588
  __html: errorMessage
2573
2589
  },
@@ -4053,7 +4069,7 @@ var Form = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(function (pr
4053
4069
  }
4054
4070
  });
4055
4071
 
4056
- var _excluded$18 = ["children", "className", "htmlFor", "id", "isInlined", "isRequired"];
4072
+ var _excluded$18 = ["children", "className", "htmlFor", "id", "isInlined", "isRequired", "requiredLabelText"];
4057
4073
  /**
4058
4074
  * A label for form inputs. It should never be used alone.
4059
4075
  */
@@ -4067,6 +4083,7 @@ var Label = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(function (p
4067
4083
  isInlined = _props$isInlined === void 0 ? false : _props$isInlined,
4068
4084
  _props$isRequired = props.isRequired,
4069
4085
  isRequired = _props$isRequired === void 0 ? false : _props$isRequired,
4086
+ requiredLabelText = props.requiredLabelText,
4070
4087
  rest = _objectWithoutPropertiesLoose(props, _excluded$18);
4071
4088
 
4072
4089
  var styles = react.useStyleConfig("Label", {
@@ -4084,10 +4101,10 @@ var Label = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(function (p
4084
4101
  htmlFor: htmlFor,
4085
4102
  ref: ref,
4086
4103
  __css: styles
4087
- }, rest), children, isRequired && React__default.createElement("span", null, " (Required)"));
4104
+ }, rest), children, isRequired && React__default.createElement("span", null, requiredLabelText ? " (" + requiredLabelText + ")" : " (Required)"));
4088
4105
  }));
4089
4106
 
4090
- var _excluded$19 = ["className", "defaultValue", "helperText", "id", "invalidText", "isDisabled", "isInvalid", "isRequired", "labelText", "max", "maxLength", "min", "name", "onChange", "onClick", "onFocus", "placeholder", "showHelperInvalidText", "showLabel", "showRequiredLabel", "step", "textInputType", "type", "value"];
4107
+ var _excluded$19 = ["className", "defaultValue", "helperText", "id", "invalidText", "isDisabled", "isInvalid", "isRequired", "labelText", "max", "maxLength", "min", "name", "onChange", "onClick", "onFocus", "placeholder", "showHelperInvalidText", "showLabel", "showRequiredLabel", "requiredLabelText", "step", "textInputType", "type", "value"];
4091
4108
 
4092
4109
  var TextInputFormats = {
4093
4110
  email: "jdoe@domain.com",
@@ -4131,6 +4148,7 @@ var TextInput = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(functio
4131
4148
  showLabel = _props$showLabel === void 0 ? true : _props$showLabel,
4132
4149
  _props$showRequiredLa = props.showRequiredLabel,
4133
4150
  showRequiredLabel = _props$showRequiredLa === void 0 ? true : _props$showRequiredLa,
4151
+ requiredLabelText = props.requiredLabelText,
4134
4152
  _props$step = props.step,
4135
4153
  step = _props$step === void 0 ? 1 : _props$step,
4136
4154
  _props$textInputType = props.textInputType,
@@ -4226,7 +4244,8 @@ var TextInput = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(functio
4226
4244
  }, rest), labelText && showLabel && !isHidden && React__default.createElement(Label, {
4227
4245
  htmlFor: id,
4228
4246
  id: id + "-label",
4229
- isRequired: showRequiredLabel && isRequired
4247
+ isRequired: showRequiredLabel && isRequired,
4248
+ requiredLabelText: requiredLabelText
4230
4249
  }, labelText), fieldOutput);
4231
4250
  }));
4232
4251
 
@@ -15593,10 +15612,10 @@ var Tooltip$1 = /*#__PURE__*/react.chakra( /*#__PURE__*/React.forwardRef(functio
15593
15612
  shouldWrapChildren = props.shouldWrapChildren,
15594
15613
  rest = _objectWithoutPropertiesLoose(props, _excluded$2d);
15595
15614
 
15596
- if (typeof content !== "string") {
15615
+ if (typeof content !== "string" && typeof content !== "number") {
15597
15616
  React__default.Children.map(content, function (contentChild) {
15598
15617
  if (contentChild.type !== Icon || contentChild.type !== Image) {
15599
- console.warn("NYPL Reservoir Tooltip: Pass in a string, DS Icon, or DS Image into the 'content' prop.");
15618
+ console.warn("NYPL Reservoir Tooltip: Pass in a string, number, DS Icon, or DS Image into the 'content' prop.");
15600
15619
  }
15601
15620
  });
15602
15621
  }