@nypl/design-system-react-components 0.25.5 → 0.25.6

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 CHANGED
@@ -8,6 +8,17 @@ Currently, this repo is in Prerelease. When it is released, this project will ad
8
8
 
9
9
  ## Prerelease
10
10
 
11
+ ## 0.25.6 (December 16, 2021)
12
+
13
+ ### Adds
14
+
15
+ - Adds export statements for `ProgressIndicator` and `Slider` components to `index.ts`.
16
+ - Adds `Blogs` variant to `Breadcrumbs` component.
17
+
18
+ ### Changes
19
+
20
+ - Adds "(Required)" text to the placeholder in the `SearchBar` component when `isRequired` is true.
21
+
11
22
  ## 0.25.5 (December 9, 2021)
12
23
 
13
24
  ### Fixes
@@ -1,4 +1,5 @@
1
1
  export declare enum ColorVariants {
2
+ Blogs = "blogs",
2
3
  BooksAndMore = "booksAndMore",
3
4
  Locations = "locations",
4
5
  Research = "research",
@@ -2273,6 +2273,7 @@ function Accordion(props) {
2273
2273
  }
2274
2274
 
2275
2275
  (function (ColorVariants) {
2276
+ ColorVariants["Blogs"] = "blogs";
2276
2277
  ColorVariants["BooksAndMore"] = "booksAndMore";
2277
2278
  ColorVariants["Locations"] = "locations";
2278
2279
  ColorVariants["Research"] = "research";
@@ -4099,6 +4100,15 @@ var Accordion$1 = {
4099
4100
  };
4100
4101
 
4101
4102
  // Variant styling
4103
+ var blogs = {
4104
+ bg: "section.blogs.secondary",
4105
+ color: "ui.black",
4106
+ a: {
4107
+ _hover: {
4108
+ color: "ui.gray.xdark"
4109
+ }
4110
+ }
4111
+ };
4102
4112
  var booksAndMore = {
4103
4113
  bg: "section.books-and-more.secondary"
4104
4114
  };
@@ -4187,6 +4197,7 @@ var Breadcrumb = {
4187
4197
  },
4188
4198
  // Available variants:
4189
4199
  variants: {
4200
+ blogs: blogs,
4190
4201
  booksAndMore: booksAndMore,
4191
4202
  locations: locations,
4192
4203
  research: research,
@@ -7312,6 +7323,88 @@ var Pagination$1 = function Pagination(props) {
7312
7323
  }, previousLiLink, getPaginationNumbers(currentPage), nextLiLink));
7313
7324
  };
7314
7325
 
7326
+ /**
7327
+ * A component that displays a progress status for any task that takes a long
7328
+ * time to complete or consists of multiple steps. Examples include downloading,
7329
+ * uploading, or processing.
7330
+ */
7331
+
7332
+ var ProgressIndicator$1 = function ProgressIndicator(props) {
7333
+ var _props$darkMode = props.darkMode,
7334
+ darkMode = _props$darkMode === void 0 ? false : _props$darkMode,
7335
+ _props$id = props.id,
7336
+ id = _props$id === void 0 ? generateUUID() : _props$id,
7337
+ _props$indicatorType = props.indicatorType,
7338
+ indicatorType = _props$indicatorType === void 0 ? ProgressIndicatorTypes.Linear : _props$indicatorType,
7339
+ _props$isIndeterminat = props.isIndeterminate,
7340
+ isIndeterminate = _props$isIndeterminat === void 0 ? false : _props$isIndeterminat,
7341
+ labelText = props.labelText,
7342
+ _props$showLabel = props.showLabel,
7343
+ showLabel = _props$showLabel === void 0 ? true : _props$showLabel,
7344
+ _props$size = props.size,
7345
+ size = _props$size === void 0 ? ProgressIndicatorSizes.Default : _props$size,
7346
+ _props$value = props.value,
7347
+ value = _props$value === void 0 ? 0 : _props$value;
7348
+ var styles = react.useMultiStyleConfig("ProgressIndicator", {
7349
+ darkMode: darkMode,
7350
+ size: size
7351
+ });
7352
+ var finalValue = value;
7353
+
7354
+ if (finalValue < 0 || finalValue > 100) {
7355
+ console.warn("ProgressIndicator: pass in a `value` between 0 and 100. Defaulting to 0.");
7356
+ finalValue = 0;
7357
+ }
7358
+
7359
+ var progressProps = {
7360
+ id: id,
7361
+ // If the label is visually shown, associate it with the progress indicator.
7362
+ // Otherwise, the `aria-label` will be added.
7363
+ "aria-label": showLabel ? null : labelText,
7364
+ "aria-labelledby": showLabel ? id + "-label" : null,
7365
+ // If `isIndeterminate` is true, then it overrides the `value` prop.
7366
+ isIndeterminate: isIndeterminate || null,
7367
+ value: isIndeterminate ? null : finalValue
7368
+ };
7369
+
7370
+ var progressComponent = function progressComponent(indicatorType) {
7371
+ // Only display the percentage text for the default size, not in the
7372
+ // indeterminate state, and when `showLabel` is true.
7373
+ if (indicatorType === ProgressIndicatorTypes.Circular) {
7374
+ // For the small size, since the label won't be visible, we need to add
7375
+ // it to the parent component's `aria-label` attribute.
7376
+ if (size === ProgressIndicatorSizes.Small) {
7377
+ progressProps["aria-label"] = labelText;
7378
+ }
7379
+
7380
+ return React__default.createElement(react.Box, {
7381
+ __css: styles.circularContainer
7382
+ }, React__default.createElement(react.CircularProgress, Object.assign({}, progressProps, {
7383
+ sx: styles.circular
7384
+ }), showLabel && !isIndeterminate && size !== ProgressIndicatorSizes.Small && React__default.createElement(react.CircularProgressLabel, null, finalValue, "%")), showLabel && size !== ProgressIndicatorSizes.Small && React__default.createElement(Label, {
7385
+ id: id + "-label",
7386
+ htmlFor: id
7387
+ }, labelText));
7388
+ } // The Linear progress indicator is the default.
7389
+
7390
+
7391
+ return React__default.createElement(React__default.Fragment, null, showLabel && React__default.createElement(Label, {
7392
+ id: id + "-label",
7393
+ htmlFor: id
7394
+ }, labelText), React__default.createElement(react.Box, {
7395
+ __css: styles.linearContainer
7396
+ }, React__default.createElement(react.Progress, Object.assign({}, progressProps, {
7397
+ sx: styles.linear
7398
+ })), showLabel && !isIndeterminate && React__default.createElement(react.Box, {
7399
+ __css: styles.linearPercentage
7400
+ }, finalValue, "%")));
7401
+ };
7402
+
7403
+ return React__default.createElement(react.Box, {
7404
+ __css: styles
7405
+ }, progressComponent(indicatorType));
7406
+ };
7407
+
7315
7408
  var Radio$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
7316
7409
  var className = props.className,
7317
7410
  helperText = props.helperText,
@@ -7602,7 +7695,8 @@ function SearchBar$1(props) {
7602
7695
  var helperErrorTextID = generateUUID();
7603
7696
  var ariaDescribedby = helperErrorTextID;
7604
7697
  var footnote = isInvalid ? invalidText : helperErrorText;
7605
- var finalAriaLabel = footnote ? labelText + " - " + footnote : labelText; // Render the `Select` component.
7698
+ var finalAriaLabel = footnote ? labelText + " - " + footnote : labelText;
7699
+ var textInputPlaceholder = (textInputProps == null ? void 0 : textInputProps.placeholder) + " " + (isRequired ? "(Required)" : ""); // Render the `Select` component.
7606
7700
 
7607
7701
  var selectElem = selectProps && React.createElement(Select$1, Object.assign({
7608
7702
  id: generateUUID(),
@@ -7619,7 +7713,7 @@ function SearchBar$1(props) {
7619
7713
  var textInputNative = textInputProps && React.createElement(TextInput, Object.assign({
7620
7714
  id: generateUUID(),
7621
7715
  labelText: textInputProps == null ? void 0 : textInputProps.labelText,
7622
- placeholder: textInputProps == null ? void 0 : textInputProps.placeholder,
7716
+ placeholder: textInputPlaceholder,
7623
7717
  onChange: textInputProps == null ? void 0 : textInputProps.onChange,
7624
7718
  name: textInputProps == null ? void 0 : textInputProps.name,
7625
7719
  type: exports.TextInputTypes.text,
@@ -7759,6 +7853,224 @@ function SkeletonLoader$1(props) {
7759
7853
  })))));
7760
7854
  }
7761
7855
 
7856
+ /**
7857
+ * The `Slider` component renders a singular value slider or a range slider
7858
+ * with a min and max value. The value(s) can be updated through the slider
7859
+ * thumb(s) or through the text input(s) elements.
7860
+ */
7861
+
7862
+ function Slider(props) {
7863
+ var className = props.className,
7864
+ _props$defaultValue = props.defaultValue,
7865
+ defaultValue = _props$defaultValue === void 0 ? 0 : _props$defaultValue,
7866
+ helperText = props.helperText,
7867
+ _props$id = props.id,
7868
+ id = _props$id === void 0 ? generateUUID() : _props$id,
7869
+ invalidText = props.invalidText,
7870
+ _props$isDisabled = props.isDisabled,
7871
+ isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
7872
+ _props$isInvalid = props.isInvalid,
7873
+ isInvalid = _props$isInvalid === void 0 ? false : _props$isInvalid,
7874
+ _props$isRangeSlider = props.isRangeSlider,
7875
+ isRangeSlider = _props$isRangeSlider === void 0 ? false : _props$isRangeSlider,
7876
+ _props$isRequired = props.isRequired,
7877
+ isRequired = _props$isRequired === void 0 ? false : _props$isRequired,
7878
+ labelText = props.labelText,
7879
+ _props$max = props.max,
7880
+ max = _props$max === void 0 ? 100 : _props$max,
7881
+ _props$min = props.min,
7882
+ min = _props$min === void 0 ? 0 : _props$min,
7883
+ name = props.name,
7884
+ _onChange = props.onChange,
7885
+ _props$optReqFlag = props.optReqFlag,
7886
+ optReqFlag = _props$optReqFlag === void 0 ? true : _props$optReqFlag,
7887
+ _props$showBoxes = props.showBoxes,
7888
+ showBoxes = _props$showBoxes === void 0 ? true : _props$showBoxes,
7889
+ _props$showHelperInva = props.showHelperInvalidText,
7890
+ showHelperInvalidText = _props$showHelperInva === void 0 ? true : _props$showHelperInva,
7891
+ _props$showLabel = props.showLabel,
7892
+ showLabel = _props$showLabel === void 0 ? true : _props$showLabel,
7893
+ _props$showValues = props.showValues,
7894
+ showValues = _props$showValues === void 0 ? true : _props$showValues,
7895
+ _props$step = props.step,
7896
+ step = _props$step === void 0 ? 1 : _props$step;
7897
+
7898
+ var _React$useState = React.useState(defaultValue),
7899
+ currentValue = _React$useState[0],
7900
+ setCurrentValue = _React$useState[1];
7901
+
7902
+ var finalIsInvalid = isInvalid; // In the Range Slider, if the first value is bigger than the second value,
7903
+ // then set the invalid state.
7904
+
7905
+ if (isRangeSlider && currentValue[0] > currentValue[1]) {
7906
+ finalIsInvalid = true;
7907
+ }
7908
+
7909
+ var optReqText = isRequired ? "Required" : "Optional";
7910
+ var footnote = finalIsInvalid ? invalidText : helperText;
7911
+ var styles = react.useMultiStyleConfig("CustomSlider", {
7912
+ isDisabled: isDisabled,
7913
+ isInvalid: finalIsInvalid,
7914
+ isRangeSlider: isRangeSlider,
7915
+ showBoxes: showBoxes
7916
+ }); // Props that the `Slider` and `RangeSlider` Chakra
7917
+ // components both use.
7918
+
7919
+ var sliderSharedProps = {
7920
+ // Don't focus on the thumbs for every small change.
7921
+ focusThumbOnChange: false,
7922
+ id: id,
7923
+ isDisabled: isDisabled,
7924
+ max: max,
7925
+ min: min,
7926
+ name: name,
7927
+ onChange: function onChange(val) {
7928
+ return setCurrentValue(val);
7929
+ },
7930
+ // Call the passed in `onChange` function prop to get the
7931
+ // *final* value once a user stops dragging the slider.
7932
+ onChangeEnd: function onChangeEnd(val) {
7933
+ return _onChange(val);
7934
+ },
7935
+ step: step
7936
+ }; // Props that the two `TextInput` components use.
7937
+
7938
+ var textInputSharedProps = {
7939
+ attributes: {
7940
+ max: max,
7941
+ min: min
7942
+ },
7943
+ isDisabled: isDisabled,
7944
+ isInvalid: finalIsInvalid,
7945
+ isRequired: isRequired,
7946
+ // Never show the label or helper text for the `TextInput` component.
7947
+ showHelperInvalidText: false,
7948
+ showLabel: false,
7949
+ step: step,
7950
+ type: exports.TextInputTypes.number
7951
+ };
7952
+ /**
7953
+ * This returns either the "start" or "end" `TextInput` component. Note that
7954
+ * the "end" `TextInput` component is always rendered but the "start" is
7955
+ * only used for the `isRangeSlider` case.
7956
+ */
7957
+
7958
+ var getTextInput = function getTextInput(type) {
7959
+ var inputProps = {
7960
+ start: _extends({
7961
+ // We only want the value for this box in the `isRangeSlider` case.
7962
+ value: isRangeSlider ? currentValue[0].toString() : "",
7963
+ onChange: function onChange(val) {
7964
+ // If the value is empty, set it to 0.
7965
+ var nextValue = parseInt(val.target.value, 10) ? parseInt(val.target.value, 10) : 0; // Only update the first value in the range.
7966
+
7967
+ var newValue = [nextValue, currentValue[1]];
7968
+ setCurrentValue(newValue); // If the text input was updated directly,
7969
+ // send the data back to the user.
7970
+
7971
+ _onChange && _onChange(newValue);
7972
+ }
7973
+ }, textInputSharedProps),
7974
+ end: _extends({
7975
+ // This text input *always* shows. In the default case, we only
7976
+ // keep track of one value. For the `isRangeSlider` case, we keep
7977
+ // track of an array but only want the second value.
7978
+ value: isRangeSlider ? currentValue[1].toString() : currentValue.toString(),
7979
+ onChange: function onChange(val) {
7980
+ // If the value is empty, set it to 0.
7981
+ var nextValue = parseInt(val.target.value, 10) ? parseInt(val.target.value, 10) : 0; // If the value entered is bigger than the max value,
7982
+ // then set it to the max value.
7983
+
7984
+ if (nextValue > max) {
7985
+ nextValue = max;
7986
+ } // Only update the second value in the `isRangeSlider` case,
7987
+ // or the single value in the default case.
7988
+
7989
+
7990
+ var newValue = isRangeSlider ? [currentValue[0], nextValue] : nextValue;
7991
+ setCurrentValue(newValue); // If the text input was updated directly,
7992
+ // send the data back to the user.
7993
+
7994
+ _onChange && _onChange(newValue);
7995
+ }
7996
+ }, textInputSharedProps)
7997
+ };
7998
+ var updatedLabel = !isRangeSlider ? labelText : labelText + " - " + type + " value";
7999
+ return React.createElement(TextInput, Object.assign({
8000
+ id: id + "-textInput-" + type,
8001
+ labelText: updatedLabel,
8002
+ additionalStyles: _extends({}, styles.textInput, {
8003
+ // Specific margins for each text input to
8004
+ // push the elements inside.
8005
+ marginRight: type === "start" ? "s" : null,
8006
+ marginLeft: type === "end" ? "s" : null
8007
+ })
8008
+ }, inputProps[type]));
8009
+ };
8010
+ /**
8011
+ * Returns a Chakra `Slider` or `RangeSlider` component based on the
8012
+ * `isRangeSlider` prop from the DS `Slider` component.
8013
+ */
8014
+
8015
+
8016
+ var getSliderType = function getSliderType() {
8017
+ return isRangeSlider ? React.createElement(react.RangeSlider // Both slider thumbs need values and should be in an array.
8018
+ , Object.assign({
8019
+ "aria-label": !showLabel ? [labelText + " - start value", labelText + " - end value"] : null,
8020
+ "aria-labelledby": showLabel ? [id + "-label", id + "-label"] : null,
8021
+ value: currentValue,
8022
+ // Make the thumbs larger.
8023
+ size: "lg"
8024
+ }, sliderSharedProps), React.createElement(react.RangeSliderTrack, {
8025
+ sx: styles.track
8026
+ }, React.createElement(react.RangeSliderFilledTrack, {
8027
+ sx: styles.filledTrack
8028
+ })), React.createElement(react.RangeSliderThumb, {
8029
+ index: 0,
8030
+ sx: styles.thumb
8031
+ }), React.createElement(react.RangeSliderThumb, {
8032
+ index: 1,
8033
+ sx: styles.thumb
8034
+ })) : React.createElement(react.Slider, Object.assign({
8035
+ "aria-label": !showLabel ? labelText : null,
8036
+ "aria-labelledby": id + "-label",
8037
+ value: currentValue,
8038
+ // Make the thumb larger.
8039
+ size: "lg"
8040
+ }, sliderSharedProps), React.createElement(react.SliderTrack, {
8041
+ sx: styles.track
8042
+ }, React.createElement(react.SliderFilledTrack, {
8043
+ sx: styles.filledTrack
8044
+ })), React.createElement(react.SliderThumb, {
8045
+ sx: styles.thumb
8046
+ }));
8047
+ };
8048
+
8049
+ return React.createElement(react.Box, {
8050
+ className: className,
8051
+ __css: styles
8052
+ }, showLabel && React.createElement(Label, {
8053
+ id: id + "-label",
8054
+ // We can't target the slider thumbs since those are divs and we
8055
+ // should link the label somewhere. So either target the first
8056
+ // input box in a `RangeSlider` or the only input box in a `Slider`.
8057
+ // When the input fields are not visible, remove this attribute.
8058
+ htmlFor: showBoxes ? id + "-textInput-" + (isRangeSlider ? "start" : "end") : null,
8059
+ optReqFlag: optReqFlag && optReqText
8060
+ }, labelText), React.createElement(react.Box, {
8061
+ __css: styles.container
8062
+ }, showBoxes && isRangeSlider && getTextInput("start"), showValues && React.createElement(react.Box, {
8063
+ __css: styles.leftValue
8064
+ }, min), getSliderType(), showValues && React.createElement(react.Box, {
8065
+ __css: styles.rightValue
8066
+ }, max), showBoxes && getTextInput("end")), footnote && showHelperInvalidText && React.createElement(react.Box, {
8067
+ __css: styles.helper
8068
+ }, React.createElement(HelperErrorText, {
8069
+ id: id + "-helperText",
8070
+ isInvalid: finalIsInvalid
8071
+ }, footnote)));
8072
+ }
8073
+
7762
8074
  (function (StatusBadgeTypes) {
7763
8075
  StatusBadgeTypes["Low"] = "low";
7764
8076
  StatusBadgeTypes["Medium"] = "medium";
@@ -8558,12 +8870,14 @@ exports.List = List$1;
8558
8870
  exports.Modal = Modal;
8559
8871
  exports.Notification = Notification$1;
8560
8872
  exports.Pagination = Pagination$1;
8873
+ exports.ProgressIndicator = ProgressIndicator$1;
8561
8874
  exports.Radio = Radio$1;
8562
8875
  exports.RadioGroup = RadioGroup$1;
8563
8876
  exports.SearchBar = SearchBar$1;
8564
8877
  exports.Select = Select$1;
8565
8878
  exports.SimpleGrid = SimpleGrid;
8566
8879
  exports.SkeletonLoader = SkeletonLoader$1;
8880
+ exports.Slider = Slider;
8567
8881
  exports.StatusBadge = StatusBadge$1;
8568
8882
  exports.Tabs = Tabs;
8569
8883
  exports.Template = Template$1;