@cambly/syntax-core 2.10.0 → 3.0.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/dist/index.js CHANGED
@@ -753,11 +753,95 @@ var MiniActionCard = ({
753
753
  var MiniActionCard_default = MiniActionCard;
754
754
 
755
755
  // src/RadioButton/RadioButton.tsx
756
- var import_react6 = require("react");
756
+ var import_react7 = require("react");
757
757
  var import_classnames8 = __toESM(require_classnames());
758
758
 
759
759
  // css-module:./RadioButton.module.css#css-module
760
- var RadioButton_module_default = { "radioButton": "_radioButton_1kj8n_1", "focusedRadioButton": "_focusedRadioButton_1kj8n_8", "smBase": "_smBase_1kj8n_13", "mdBase": "_mdBase_1kj8n_18", "radioStyleOverride": "_radioStyleOverride_1kj8n_23", "smOverride": "_smOverride_1kj8n_28", "mdOverride": "_mdOverride_1kj8n_33", "outer": "_outer_1kj8n_38", "sm": "_sm_1kj8n_13", "md": "_md_1kj8n_18", "errorOuterBackgroundColor": "_errorOuterBackgroundColor_1kj8n_57", "outerBackgroundColor": "_outerBackgroundColor_1kj8n_61", "background": "_background_1kj8n_65", "errorBorderColor": "_errorBorderColor_1kj8n_71", "borderColor": "_borderColor_1kj8n_75", "circle": "_circle_1kj8n_79", "smInner": "_smInner_1kj8n_83", "mdInner": "_mdInner_1kj8n_89" };
760
+ var RadioButton_module_default = { "radioBaseContainer": "_radioBaseContainer_x6och_1", "smBase": "_smBase_x6och_8", "mdBase": "_mdBase_x6och_13", "radioStyleOverride": "_radioStyleOverride_x6och_18", "smOverride": "_smOverride_x6och_23", "mdOverride": "_mdOverride_x6och_28", "background": "_background_x6och_33", "sm": "_sm_x6och_8", "md": "_md_x6och_13", "neutralBorder": "_neutralBorder_x6och_50", "smCheckedBorder": "_smCheckedBorder_x6och_54", "mdCheckedBorder": "_mdCheckedBorder_x6och_58", "errorBorderColor": "_errorBorderColor_x6och_62", "borderColor": "_borderColor_x6och_66", "focusedRadioButton": "_focusedRadioButton_x6och_70" };
761
+
762
+ // src/useFocusVisible.tsx
763
+ var import_react6 = require("react");
764
+ var hasSetupGlobalListeners = false;
765
+ var currentModality = null;
766
+ var changeHandlers = /* @__PURE__ */ new Set();
767
+ var hasEventBeforeFocus = false;
768
+ var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
769
+ function isValidKey(e) {
770
+ return !(e.metaKey || !isMac && e.altKey || e.ctrlKey);
771
+ }
772
+ function triggerChangeHandlers(modality, e) {
773
+ changeHandlers.forEach((handler) => {
774
+ handler(modality, e);
775
+ });
776
+ }
777
+ function handleKeyboardEvent(e) {
778
+ hasEventBeforeFocus = true;
779
+ if (isValidKey(e)) {
780
+ currentModality = "keyboard";
781
+ triggerChangeHandlers("keyboard", e);
782
+ }
783
+ }
784
+ function handlePointerEvent(e) {
785
+ currentModality = "pointer";
786
+ if (e.type === "mousedown" || e.type === "pointerdown") {
787
+ hasEventBeforeFocus = true;
788
+ triggerChangeHandlers("pointer", e);
789
+ }
790
+ }
791
+ function handleFocusEvent(e) {
792
+ if (e.target === window || e.target === document) {
793
+ return;
794
+ }
795
+ if (!hasEventBeforeFocus) {
796
+ currentModality = "keyboard";
797
+ triggerChangeHandlers("keyboard", e);
798
+ }
799
+ hasEventBeforeFocus = false;
800
+ }
801
+ function handleWindowBlur() {
802
+ hasEventBeforeFocus = false;
803
+ }
804
+ function isFocusVisible() {
805
+ return currentModality !== "pointer";
806
+ }
807
+ function setupGlobalFocusEvents() {
808
+ if (typeof window === "undefined" || hasSetupGlobalListeners) {
809
+ return;
810
+ }
811
+ const { focus } = HTMLElement.prototype;
812
+ HTMLElement.prototype.focus = function focusElement(...args) {
813
+ hasEventBeforeFocus = true;
814
+ focus.apply(this, args);
815
+ };
816
+ document.addEventListener("keydown", handleKeyboardEvent, true);
817
+ document.addEventListener("keyup", handleKeyboardEvent, true);
818
+ window.addEventListener("focus", handleFocusEvent, true);
819
+ window.addEventListener("blur", handleWindowBlur, false);
820
+ if (typeof PointerEvent !== "undefined") {
821
+ document.addEventListener("pointerdown", handlePointerEvent, true);
822
+ document.addEventListener("pointermove", handlePointerEvent, true);
823
+ document.addEventListener("pointerup", handlePointerEvent, true);
824
+ } else {
825
+ document.addEventListener("mousedown", handlePointerEvent, true);
826
+ document.addEventListener("mousemove", handlePointerEvent, true);
827
+ document.addEventListener("mouseup", handlePointerEvent, true);
828
+ }
829
+ hasSetupGlobalListeners = true;
830
+ }
831
+ function useFocusVisible() {
832
+ setupGlobalFocusEvents();
833
+ const [isFocusVisibleState, setFocusVisible] = (0, import_react6.useState)(isFocusVisible());
834
+ (0, import_react6.useEffect)(() => {
835
+ const handler = () => {
836
+ setFocusVisible(isFocusVisible());
837
+ };
838
+ changeHandlers.add(handler);
839
+ return () => {
840
+ changeHandlers.delete(handler);
841
+ };
842
+ }, []);
843
+ return { isFocusVisible: isFocusVisibleState };
844
+ }
761
845
 
762
846
  // src/RadioButton/RadioButton.tsx
763
847
  var import_jsx_runtime12 = require("react/jsx-runtime");
@@ -766,15 +850,22 @@ var RadioButton = ({
766
850
  disabled = false,
767
851
  error = false,
768
852
  label,
853
+ name,
769
854
  onChange,
770
855
  size = "md",
771
- value = ""
856
+ value
772
857
  }) => {
773
- const [isFocused, setIsFocused] = (0, import_react6.useState)(false);
858
+ const [isFocused, setIsFocused] = (0, import_react7.useState)(false);
859
+ const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
860
+ const sharedStyles = (0, import_classnames8.default)(RadioButton_module_default.background, RadioButton_module_default[size], {
861
+ [RadioButton_module_default.errorBorderColor]: error,
862
+ [RadioButton_module_default.borderColor]: !error,
863
+ [RadioButton_module_default.focusedRadioButton]: isFocused && isFocusVisible2
864
+ });
774
865
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
775
866
  "label",
776
867
  {
777
- className: (0, import_classnames8.default)(RadioButton_module_default.radioButton, {
868
+ className: (0, import_classnames8.default)(RadioButton_module_default.radioBaseContainer, {
778
869
  [RadioButton_module_default.smBase]: size === "sm",
779
870
  [RadioButton_module_default.mdBase]: size === "md"
780
871
  }),
@@ -783,6 +874,7 @@ var RadioButton = ({
783
874
  "input",
784
875
  {
785
876
  type: "radio",
877
+ name,
786
878
  className: (0, import_classnames8.default)(RadioButton_module_default.radioStyleOverride, {
787
879
  [RadioButton_module_default.smOverride]: size === "sm",
788
880
  [RadioButton_module_default.mdOverride]: size === "md"
@@ -790,7 +882,7 @@ var RadioButton = ({
790
882
  checked,
791
883
  onChange,
792
884
  disabled,
793
- value: value != null ? value : label,
885
+ value,
794
886
  onFocus: () => {
795
887
  setIsFocused(true);
796
888
  },
@@ -802,31 +894,12 @@ var RadioButton = ({
802
894
  checked ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
803
895
  "div",
804
896
  {
805
- className: (0, import_classnames8.default)(RadioButton_module_default.outer, RadioButton_module_default[size], {
806
- [RadioButton_module_default.errorOuterBackgroundColor]: error,
807
- [RadioButton_module_default.outerBackgroundColor]: !error,
808
- [RadioButton_module_default.focusedRadioButton]: isFocused
809
- }),
810
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
811
- "div",
812
- {
813
- className: (0, import_classnames8.default)(RadioButton_module_default.circle, {
814
- [RadioButton_module_default.smInner]: size === "sm",
815
- [RadioButton_module_default.mdInner]: size === "md"
816
- })
817
- }
818
- )
819
- }
820
- ) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
821
- "div",
822
- {
823
- className: (0, import_classnames8.default)(RadioButton_module_default.background, RadioButton_module_default[size], {
824
- [RadioButton_module_default.errorBorderColor]: error,
825
- [RadioButton_module_default.borderColor]: !error,
826
- [RadioButton_module_default.focusedRadioButton]: isFocused
897
+ className: (0, import_classnames8.default)(sharedStyles, {
898
+ [RadioButton_module_default.mdCheckedBorder]: size === "md",
899
+ [RadioButton_module_default.smCheckedBorder]: size === "sm"
827
900
  })
828
901
  }
829
- ),
902
+ ) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames8.default)(sharedStyles, RadioButton_module_default.neutralBorder) }),
830
903
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
831
904
  Typography_default,
832
905
  {
@@ -842,7 +915,7 @@ var RadioButton = ({
842
915
  var RadioButton_default = RadioButton;
843
916
 
844
917
  // src/SelectList/SelectList.tsx
845
- var import_react7 = require("react");
918
+ var import_react8 = require("react");
846
919
  var import_classnames9 = __toESM(require_classnames());
847
920
 
848
921
  // ../syntax-design-tokens/dist/js/index.js
@@ -887,7 +960,7 @@ var SelectList = ({
887
960
  selectedValue = "",
888
961
  size = "md"
889
962
  }) => {
890
- const id = (0, import_react7.useId)();
963
+ const id = (0, import_react8.useId)();
891
964
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
892
965
  "div",
893
966
  {