@react-aria/color 3.0.0-beta.21 → 3.0.0-beta.23

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/dist/main.js CHANGED
@@ -39,7 +39,7 @@ $parcel$export(module.exports, "useColorField", () => $58c850037bc7a7ce$export$7
39
39
  * OF ANY KIND, either express or implied. See the License for the specific language
40
40
  * governing permissions and limitations under the License.
41
41
  */
42
- var $4f97b428b4cbcd4e$exports = {};
42
+ var $4a33e168940636d5$exports = {};
43
43
  var $f141a15c3076a67b$exports = {};
44
44
  $f141a15c3076a67b$exports = {
45
45
  "colorInputLabel": (args)=>`${args.label}, ${args.channelLabel}`,
@@ -346,7 +346,7 @@ $7377d28aec5fa200$exports = {
346
346
  };
347
347
 
348
348
 
349
- $4f97b428b4cbcd4e$exports = {
349
+ $4a33e168940636d5$exports = {
350
350
  "ar-AE": $f141a15c3076a67b$exports,
351
351
  "bg-BG": $435ac2a9fdd2ae5e$exports,
352
352
  "cs-CZ": $6b29758b432284f5$exports,
@@ -609,21 +609,27 @@ function $99936ad0bf67c8c4$export$dd62420467d245ca({ direction: direction , stat
609
609
 
610
610
 
611
611
  function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
612
- let { isDisabled: isDisabled , inputXRef: inputXRef , inputYRef: inputYRef , containerRef: containerRef , "aria-label": ariaLabel } = props;
613
- let stringFormatter = (0, $kZqDi$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($4f97b428b4cbcd4e$exports))));
612
+ let { isDisabled: isDisabled , inputXRef: inputXRef , inputYRef: inputYRef , containerRef: containerRef , "aria-label": ariaLabel , xName: xName , yName: yName } = props;
613
+ let stringFormatter = (0, $kZqDi$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($4a33e168940636d5$exports))));
614
614
  let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $kZqDi$reactariautils.useGlobalListeners)();
615
615
  let { direction: direction , locale: locale } = (0, $kZqDi$reactariai18n.useLocale)();
616
- let focusedInputRef = (0, $kZqDi$react.useRef)(null);
616
+ let [focusedInput, setFocusedInput] = (0, $kZqDi$react.useState)(null);
617
617
  let focusInput = (0, $kZqDi$react.useCallback)((inputRef = inputXRef)=>{
618
618
  if (inputRef.current) (0, $kZqDi$reactariautils.focusWithoutScrolling)(inputRef.current);
619
619
  }, [
620
620
  inputXRef
621
621
  ]);
622
- let stateRef = (0, $kZqDi$react.useRef)(null);
623
- stateRef.current = state;
624
- let { xChannel: xChannel , yChannel: yChannel , zChannel: zChannel } = stateRef.current.channels;
625
- let xChannelStep = stateRef.current.xChannelStep;
626
- let yChannelStep = stateRef.current.yChannelStep;
622
+ (0, $kZqDi$reactariautils.useFormReset)(inputXRef, [
623
+ state.xValue,
624
+ state.yValue
625
+ ], ([x, y])=>{
626
+ let newColor = state.value.withChannelValue(state.channels.xChannel, x).withChannelValue(state.channels.yChannel, y);
627
+ state.setValue(newColor);
628
+ });
629
+ let [valueChangedViaKeyboard, setValueChangedViaKeyboard] = (0, $kZqDi$react.useState)(false);
630
+ let { xChannel: xChannel , yChannel: yChannel , zChannel: zChannel } = state.channels;
631
+ let xChannelStep = state.xChannelStep;
632
+ let yChannelStep = state.yChannelStep;
627
633
  let currentPosition = (0, $kZqDi$react.useRef)(null);
628
634
  let { keyboardProps: keyboardProps } = (0, $kZqDi$reactariainteractions.useKeyboard)({
629
635
  onKeyDown (e) {
@@ -635,37 +641,42 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
635
641
  // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us
636
642
  e.preventDefault();
637
643
  // remember to set this and unset it so that onChangeEnd is fired
638
- stateRef.current.setDragging(true);
639
- valueChangedViaKeyboard.current = true;
644
+ state.setDragging(true);
645
+ setValueChangedViaKeyboard(true);
646
+ let dir;
640
647
  switch(e.key){
641
648
  case "PageUp":
642
- stateRef.current.incrementY(stateRef.current.yChannelPageStep);
643
- focusedInputRef.current = inputYRef.current;
649
+ state.incrementY(state.yChannelPageStep);
650
+ dir = "y";
644
651
  break;
645
652
  case "PageDown":
646
- stateRef.current.decrementY(stateRef.current.yChannelPageStep);
647
- focusedInputRef.current = inputYRef.current;
653
+ state.decrementY(state.yChannelPageStep);
654
+ dir = "y";
648
655
  break;
649
656
  case "Home":
650
- direction === "rtl" ? stateRef.current.incrementX(stateRef.current.xChannelPageStep) : stateRef.current.decrementX(stateRef.current.xChannelPageStep);
651
- focusedInputRef.current = inputXRef.current;
657
+ direction === "rtl" ? state.incrementX(state.xChannelPageStep) : state.decrementX(state.xChannelPageStep);
658
+ dir = "x";
652
659
  break;
653
660
  case "End":
654
- direction === "rtl" ? stateRef.current.decrementX(stateRef.current.xChannelPageStep) : stateRef.current.incrementX(stateRef.current.xChannelPageStep);
655
- focusedInputRef.current = inputXRef.current;
661
+ direction === "rtl" ? state.decrementX(state.xChannelPageStep) : state.incrementX(state.xChannelPageStep);
662
+ dir = "x";
656
663
  break;
657
664
  }
658
- stateRef.current.setDragging(false);
659
- if (focusedInputRef.current) focusInput(focusedInputRef.current ? focusedInputRef : inputXRef);
665
+ state.setDragging(false);
666
+ if (dir) {
667
+ let input = dir === "x" ? inputXRef : inputYRef;
668
+ focusInput(input);
669
+ setFocusedInput(dir);
670
+ }
660
671
  }
661
672
  });
662
673
  let moveHandler = {
663
674
  onMoveStart () {
664
675
  currentPosition.current = null;
665
- stateRef.current.setDragging(true);
676
+ state.setDragging(true);
666
677
  },
667
678
  onMove ({ deltaX: deltaX , deltaY: deltaY , pointerType: pointerType , shiftKey: shiftKey }) {
668
- let { incrementX: incrementX , decrementX: decrementX , incrementY: incrementY , decrementY: decrementY , xChannelPageStep: xChannelPageStep , xChannelStep: xChannelStep , yChannelPageStep: yChannelPageStep , yChannelStep: yChannelStep , getThumbPosition: getThumbPosition , setColorFromPoint: setColorFromPoint } = stateRef.current;
679
+ let { incrementX: incrementX , decrementX: decrementX , incrementY: incrementY , decrementY: decrementY , xChannelPageStep: xChannelPageStep , xChannelStep: xChannelStep , yChannelPageStep: yChannelPageStep , yChannelStep: yChannelStep , getThumbPosition: getThumbPosition , setColorFromPoint: setColorFromPoint } = state;
669
680
  if (currentPosition.current == null) currentPosition.current = getThumbPosition();
670
681
  let { width: width , height: height } = containerRef.current.getBoundingClientRect();
671
682
  let valueChanged = deltaX !== 0 || deltaY !== 0;
@@ -676,9 +687,10 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
676
687
  else if (deltaX < 0 && direction === "ltr" || deltaX > 0 && direction === "rtl") decrementX(deltaXValue);
677
688
  else if (deltaY > 0) decrementY(deltaYValue);
678
689
  else if (deltaY < 0) incrementY(deltaYValue);
679
- valueChangedViaKeyboard.current = valueChanged;
690
+ setValueChangedViaKeyboard(valueChanged);
680
691
  // set the focused input based on which axis has the greater delta
681
- focusedInputRef.current = valueChanged && Math.abs(deltaY) > Math.abs(deltaX) ? inputYRef.current : inputXRef.current;
692
+ focusedInput = valueChanged && Math.abs(deltaY) > Math.abs(deltaX) ? "y" : "x";
693
+ setFocusedInput(focusedInput);
682
694
  } else {
683
695
  currentPosition.current.x += (direction === "rtl" ? -1 : 1) * deltaX / width;
684
696
  currentPosition.current.y += deltaY / height;
@@ -687,18 +699,15 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
687
699
  },
688
700
  onMoveEnd () {
689
701
  isOnColorArea.current = undefined;
690
- stateRef.current.setDragging(false);
691
- focusInput(focusedInputRef.current ? focusedInputRef : inputXRef);
702
+ state.setDragging(false);
703
+ let input = focusedInput === "x" ? inputXRef : inputYRef;
704
+ focusInput(input);
692
705
  }
693
706
  };
694
707
  let { moveProps: movePropsThumb } = (0, $kZqDi$reactariainteractions.useMove)(moveHandler);
695
- let valueChangedViaKeyboard = (0, $kZqDi$react.useRef)(false);
696
708
  let { focusWithinProps: focusWithinProps } = (0, $kZqDi$reactariainteractions.useFocusWithin)({
697
709
  onFocusWithinChange: (focusWithin)=>{
698
- if (!focusWithin) {
699
- valueChangedViaKeyboard.current = false;
700
- focusedInputRef.current;
701
- }
710
+ if (!focusWithin) setValueChangedViaKeyboard(false);
702
711
  }
703
712
  });
704
713
  let currentPointer = (0, $kZqDi$react.useRef)(undefined);
@@ -717,7 +726,7 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
717
726
  let onThumbDown = (id)=>{
718
727
  if (!state.isDragging) {
719
728
  currentPointer.current = id;
720
- valueChangedViaKeyboard.current = false;
729
+ setValueChangedViaKeyboard(false);
721
730
  focusInput();
722
731
  state.setDragging(true);
723
732
  if (typeof PointerEvent !== "undefined") addGlobalListener(window, "pointerup", onThumbUp, false);
@@ -732,7 +741,7 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
732
741
  var _e_pointerId;
733
742
  let id = (_e_pointerId = e.pointerId) !== null && _e_pointerId !== void 0 ? _e_pointerId : (_e_changedTouches = e.changedTouches) === null || _e_changedTouches === void 0 ? void 0 : _e_changedTouches[0].identifier;
734
743
  if (id === currentPointer.current) {
735
- valueChangedViaKeyboard.current = false;
744
+ setValueChangedViaKeyboard(false);
736
745
  focusInput();
737
746
  state.setDragging(false);
738
747
  currentPointer.current = undefined;
@@ -752,7 +761,7 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
752
761
  if (direction === "rtl") x = 1 - x;
753
762
  if (x >= 0 && x <= 1 && y >= 0 && y <= 1 && !state.isDragging && currentPointer.current === undefined) {
754
763
  isOnColorArea.current = true;
755
- valueChangedViaKeyboard.current = false;
764
+ setValueChangedViaKeyboard(false);
756
765
  currentPointer.current = id;
757
766
  state.setColorFromPoint(x, y);
758
767
  focusInput();
@@ -770,7 +779,7 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
770
779
  let id = (_e_pointerId = e.pointerId) !== null && _e_pointerId !== void 0 ? _e_pointerId : (_e_changedTouches = e.changedTouches) === null || _e_changedTouches === void 0 ? void 0 : _e_changedTouches[0].identifier;
771
780
  if (isOnColorArea.current && id === currentPointer.current) {
772
781
  isOnColorArea.current = false;
773
- valueChangedViaKeyboard.current = false;
782
+ setValueChangedViaKeyboard(false);
774
783
  currentPointer.current = undefined;
775
784
  state.setDragging(false);
776
785
  focusInput();
@@ -815,17 +824,17 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
815
824
  }, focusWithinProps, keyboardProps, movePropsThumb);
816
825
  let { focusProps: xInputFocusProps } = (0, $kZqDi$reactariainteractions.useFocus)({
817
826
  onFocus: ()=>{
818
- focusedInputRef.current = inputXRef.current;
827
+ setFocusedInput("x");
819
828
  }
820
829
  });
821
830
  let { focusProps: yInputFocusProps } = (0, $kZqDi$reactariainteractions.useFocus)({
822
831
  onFocus: ()=>{
823
- focusedInputRef.current = inputYRef.current;
832
+ setFocusedInput("y");
824
833
  }
825
834
  });
826
835
  let isMobile = (0, $kZqDi$reactariautils.isIOS)() || (0, $kZqDi$reactariautils.isAndroid)();
827
836
  function getAriaValueTextForChannel(channel) {
828
- return valueChangedViaKeyboard.current ? stringFormatter.format("colorNameAndValue", {
837
+ return valueChangedViaKeyboard ? stringFormatter.format("colorNameAndValue", {
829
838
  name: state.value.getChannelName(channel, locale),
830
839
  value: state.value.formatChannelValue(channel, locale)
831
840
  }) : [
@@ -902,12 +911,13 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
902
911
  "aria-valuetext": getAriaValueTextForChannel(xChannel),
903
912
  disabled: isDisabled,
904
913
  value: state.value.getChannelValue(xChannel),
905
- tabIndex: isMobile || !focusedInputRef.current || focusedInputRef.current === inputXRef.current ? undefined : -1,
914
+ name: xName,
915
+ tabIndex: isMobile || !focusedInput || focusedInput === "x" ? undefined : -1,
906
916
  /*
907
917
  So that only a single "2d slider" control shows up when listing form elements for screen readers,
908
918
  add aria-hidden="true" to the unfocused control when the value has not changed via the keyboard,
909
919
  but remove aria-hidden to reveal the input for each channel when the value has changed with the keyboard.
910
- */ "aria-hidden": isMobile || !focusedInputRef.current || focusedInputRef.current === inputXRef.current || valueChangedViaKeyboard.current ? undefined : "true",
920
+ */ "aria-hidden": isMobile || !focusedInput || focusedInput === "x" || valueChangedViaKeyboard ? undefined : "true",
911
921
  onChange: (e)=>{
912
922
  state.setXValue(parseFloat(e.target.value));
913
923
  }
@@ -925,12 +935,13 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
925
935
  "aria-orientation": "vertical",
926
936
  disabled: isDisabled,
927
937
  value: state.value.getChannelValue(yChannel),
928
- tabIndex: isMobile || focusedInputRef.current && focusedInputRef.current === inputYRef.current ? undefined : -1,
938
+ name: yName,
939
+ tabIndex: isMobile || focusedInput === "y" ? undefined : -1,
929
940
  /*
930
941
  So that only a single "2d slider" control shows up when listing form elements for screen readers,
931
942
  add aria-hidden="true" to the unfocused input when the value has not changed via the keyboard,
932
943
  but remove aria-hidden to reveal the input for each channel when the value has changed with the keyboard.
933
- */ "aria-hidden": isMobile || focusedInputRef.current && focusedInputRef.current === inputYRef.current || valueChangedViaKeyboard.current ? undefined : "true",
944
+ */ "aria-hidden": isMobile || focusedInput === "y" || valueChangedViaKeyboard ? undefined : "true",
934
945
  onChange: (e)=>{
935
946
  state.setYValue(parseFloat(e.target.value));
936
947
  }
@@ -953,7 +964,7 @@ function $47925bd68062ac17$export$2f92a7a615a014f6(props, state) {
953
964
 
954
965
 
955
966
  function $afbb9647440a7f5b$export$106b7a4e66508f66(props, state) {
956
- let { trackRef: trackRef , inputRef: inputRef , orientation: orientation , channel: channel , "aria-label": ariaLabel } = props;
967
+ let { trackRef: trackRef , inputRef: inputRef , orientation: orientation , channel: channel , "aria-label": ariaLabel , name: name } = props;
957
968
  let { locale: locale , direction: direction } = (0, $kZqDi$reactariai18n.useLocale)();
958
969
  // Provide a default aria-label if there is no other label provided.
959
970
  if (!props.label && !ariaLabel && !props["aria-labelledby"]) ariaLabel = state.value.getChannelName(channel, locale);
@@ -966,6 +977,7 @@ function $afbb9647440a7f5b$export$106b7a4e66508f66(props, state) {
966
977
  index: 0,
967
978
  orientation: orientation,
968
979
  isDisabled: props.isDisabled,
980
+ name: name,
969
981
  trackRef: trackRef,
970
982
  inputRef: inputRef
971
983
  }, state);
@@ -996,9 +1008,9 @@ function $afbb9647440a7f5b$export$106b7a4e66508f66(props, state) {
996
1008
  case "blue":
997
1009
  case "alpha":
998
1010
  {
999
- let start1 = value.withChannelValue(channel, state.getThumbMinValue(0)).toString("css");
1000
- let end1 = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString("css");
1001
- return `linear-gradient(to ${to}, ${start1}, ${end1})`;
1011
+ let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString("css");
1012
+ let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString("css");
1013
+ return `linear-gradient(to ${to}, ${start}, ${end})`;
1002
1014
  }
1003
1015
  default:
1004
1016
  throw new Error("Unknown color channel: " + channel);
@@ -1045,7 +1057,7 @@ function $afbb9647440a7f5b$export$106b7a4e66508f66(props, state) {
1045
1057
 
1046
1058
 
1047
1059
  function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
1048
- let { isDisabled: isDisabled , innerRadius: innerRadius , outerRadius: outerRadius , "aria-label": ariaLabel } = props;
1060
+ let { isDisabled: isDisabled , innerRadius: innerRadius , outerRadius: outerRadius , "aria-label": ariaLabel , name: name } = props;
1049
1061
  let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $kZqDi$reactariautils.useGlobalListeners)();
1050
1062
  let thumbRadius = (innerRadius + outerRadius) / 2;
1051
1063
  let focusInput = (0, $kZqDi$react.useCallback)(()=>{
@@ -1053,8 +1065,7 @@ function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
1053
1065
  }, [
1054
1066
  inputRef
1055
1067
  ]);
1056
- let stateRef = (0, $kZqDi$react.useRef)(null);
1057
- stateRef.current = state;
1068
+ (0, $kZqDi$reactariautils.useFormReset)(inputRef, state.hue, state.setHue);
1058
1069
  let currentPosition = (0, $kZqDi$react.useRef)(null);
1059
1070
  let { keyboardProps: keyboardProps } = (0, $kZqDi$reactariainteractions.useKeyboard)({
1060
1071
  onKeyDown (e) {
@@ -1066,18 +1077,18 @@ function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
1066
1077
  // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us
1067
1078
  e.preventDefault();
1068
1079
  // remember to set this and unset it so that onChangeEnd is fired
1069
- stateRef.current.setDragging(true);
1080
+ state.setDragging(true);
1070
1081
  switch(e.key){
1071
1082
  case "PageUp":
1072
1083
  e.preventDefault();
1073
- state.increment(stateRef.current.pageStep);
1084
+ state.increment(state.pageStep);
1074
1085
  break;
1075
1086
  case "PageDown":
1076
1087
  e.preventDefault();
1077
- state.decrement(stateRef.current.pageStep);
1088
+ state.decrement(state.pageStep);
1078
1089
  break;
1079
1090
  }
1080
- stateRef.current.setDragging(false);
1091
+ state.setDragging(false);
1081
1092
  }
1082
1093
  });
1083
1094
  let moveHandler = {
@@ -1086,13 +1097,13 @@ function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
1086
1097
  state.setDragging(true);
1087
1098
  },
1088
1099
  onMove ({ deltaX: deltaX , deltaY: deltaY , pointerType: pointerType , shiftKey: shiftKey }) {
1089
- if (currentPosition.current == null) currentPosition.current = stateRef.current.getThumbPosition(thumbRadius);
1100
+ if (currentPosition.current == null) currentPosition.current = state.getThumbPosition(thumbRadius);
1090
1101
  currentPosition.current.x += deltaX;
1091
1102
  currentPosition.current.y += deltaY;
1092
1103
  if (pointerType === "keyboard") {
1093
- if (deltaX > 0 || deltaY < 0) state.increment(shiftKey ? stateRef.current.pageStep : stateRef.current.step);
1094
- else if (deltaX < 0 || deltaY > 0) state.decrement(shiftKey ? stateRef.current.pageStep : stateRef.current.step);
1095
- } else stateRef.current.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);
1104
+ if (deltaX > 0 || deltaY < 0) state.increment(shiftKey ? state.pageStep : state.step);
1105
+ else if (deltaX < 0 || deltaY > 0) state.decrement(shiftKey ? state.pageStep : state.step);
1106
+ } else state.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);
1096
1107
  },
1097
1108
  onMoveEnd () {
1098
1109
  isOnTrack.current = undefined;
@@ -1150,7 +1161,7 @@ function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
1150
1161
  if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
1151
1162
  isOnTrack.current = true;
1152
1163
  currentPointer.current = id;
1153
- stateRef.current.setHueFromPoint(x, y, radius);
1164
+ state.setHueFromPoint(x, y, radius);
1154
1165
  focusInput();
1155
1166
  state.setDragging(true);
1156
1167
  if (typeof PointerEvent !== "undefined") addGlobalListener(window, "pointerup", onTrackUp, false);
@@ -1266,6 +1277,7 @@ function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
1266
1277
  "aria-valuetext": state.value.formatChannelValue("hue", locale),
1267
1278
  disabled: isDisabled,
1268
1279
  value: `${state.value.getChannelValue("hue")}`,
1280
+ name: name,
1269
1281
  onChange: (e)=>{
1270
1282
  state.setHue(parseFloat(e.target.value));
1271
1283
  }