@cambly/syntax-core 4.1.0 → 4.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.
- package/dist/index.css +47 -50
- package/dist/index.css.map +1 -1
- package/dist/index.js +105 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -94
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -619,10 +619,97 @@ var IconButton_default = IconButton;
|
|
|
619
619
|
|
|
620
620
|
// src/Checkbox/Checkbox.tsx
|
|
621
621
|
var import_classnames7 = __toESM(require_classnames());
|
|
622
|
-
import { useState } from "react";
|
|
622
|
+
import { useState as useState2 } from "react";
|
|
623
|
+
|
|
624
|
+
// src/useFocusVisible.tsx
|
|
625
|
+
import { useState, useEffect } from "react";
|
|
626
|
+
var hasSetupGlobalListeners = false;
|
|
627
|
+
var currentModality = null;
|
|
628
|
+
var changeHandlers = /* @__PURE__ */ new Set();
|
|
629
|
+
var hasEventBeforeFocus = false;
|
|
630
|
+
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
|
|
631
|
+
function isValidKey(e) {
|
|
632
|
+
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey);
|
|
633
|
+
}
|
|
634
|
+
function triggerChangeHandlers(modality, e) {
|
|
635
|
+
changeHandlers.forEach((handler) => {
|
|
636
|
+
handler(modality, e);
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
function handleKeyboardEvent(e) {
|
|
640
|
+
hasEventBeforeFocus = true;
|
|
641
|
+
if (isValidKey(e)) {
|
|
642
|
+
currentModality = "keyboard";
|
|
643
|
+
triggerChangeHandlers("keyboard", e);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function handlePointerEvent(e) {
|
|
647
|
+
currentModality = "pointer";
|
|
648
|
+
if (e.type === "mousedown" || e.type === "pointerdown") {
|
|
649
|
+
hasEventBeforeFocus = true;
|
|
650
|
+
triggerChangeHandlers("pointer", e);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function handleFocusEvent(e) {
|
|
654
|
+
if (e.target === window || e.target === document) {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (!hasEventBeforeFocus) {
|
|
658
|
+
currentModality = "keyboard";
|
|
659
|
+
triggerChangeHandlers("keyboard", e);
|
|
660
|
+
}
|
|
661
|
+
hasEventBeforeFocus = false;
|
|
662
|
+
}
|
|
663
|
+
function handleWindowBlur() {
|
|
664
|
+
hasEventBeforeFocus = false;
|
|
665
|
+
}
|
|
666
|
+
function isFocusVisible() {
|
|
667
|
+
return currentModality !== "pointer";
|
|
668
|
+
}
|
|
669
|
+
function setupGlobalFocusEvents() {
|
|
670
|
+
if (typeof window === "undefined" || hasSetupGlobalListeners) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
const { focus } = HTMLElement.prototype;
|
|
674
|
+
HTMLElement.prototype.focus = function focusElement(...args) {
|
|
675
|
+
hasEventBeforeFocus = true;
|
|
676
|
+
focus.apply(this, args);
|
|
677
|
+
};
|
|
678
|
+
document.addEventListener("keydown", handleKeyboardEvent, true);
|
|
679
|
+
document.addEventListener("keyup", handleKeyboardEvent, true);
|
|
680
|
+
window.addEventListener("focus", handleFocusEvent, true);
|
|
681
|
+
window.addEventListener("blur", handleWindowBlur, false);
|
|
682
|
+
if (typeof PointerEvent !== "undefined") {
|
|
683
|
+
document.addEventListener("pointerdown", handlePointerEvent, true);
|
|
684
|
+
document.addEventListener("pointermove", handlePointerEvent, true);
|
|
685
|
+
document.addEventListener("pointerup", handlePointerEvent, true);
|
|
686
|
+
} else {
|
|
687
|
+
document.addEventListener("mousedown", handlePointerEvent, true);
|
|
688
|
+
document.addEventListener("mousemove", handlePointerEvent, true);
|
|
689
|
+
document.addEventListener("mouseup", handlePointerEvent, true);
|
|
690
|
+
}
|
|
691
|
+
hasSetupGlobalListeners = true;
|
|
692
|
+
}
|
|
693
|
+
function useFocusVisible() {
|
|
694
|
+
setupGlobalFocusEvents();
|
|
695
|
+
const [isFocusVisibleState, setFocusVisible] = useState(isFocusVisible());
|
|
696
|
+
useEffect(() => {
|
|
697
|
+
const handler = () => {
|
|
698
|
+
setFocusVisible(isFocusVisible());
|
|
699
|
+
};
|
|
700
|
+
changeHandlers.add(handler);
|
|
701
|
+
return () => {
|
|
702
|
+
changeHandlers.delete(handler);
|
|
703
|
+
};
|
|
704
|
+
}, []);
|
|
705
|
+
return { isFocusVisible: isFocusVisibleState };
|
|
706
|
+
}
|
|
623
707
|
|
|
624
708
|
// css-module:./Checkbox.module.css#css-module
|
|
625
|
-
var Checkbox_module_default = { "mainContainer": "
|
|
709
|
+
var Checkbox_module_default = { "mainContainer": "_mainContainer_1jq7b_1", "checkboxContainer": "_checkboxContainer_1jq7b_8", "inputOverlay": "_inputOverlay_1jq7b_13", "checkbox": "_checkbox_1jq7b_8", "uncheckedBox": "_uncheckedBox_1jq7b_30", "uncheckedBorder": "_uncheckedBorder_1jq7b_34", "uncheckedErrorBorder": "_uncheckedErrorBorder_1jq7b_38", "checkedBox": "_checkedBox_1jq7b_42", "checkedNonError": "_checkedNonError_1jq7b_46", "checkedError": "_checkedError_1jq7b_50", "sm": "_sm_1jq7b_54", "md": "_md_1jq7b_60" };
|
|
710
|
+
|
|
711
|
+
// css-module:../Focus.module.css#css-module
|
|
712
|
+
var Focus_module_default = { "accessibilityOutlineFocus": "_accessibilityOutlineFocus_1h8bq_1" };
|
|
626
713
|
|
|
627
714
|
// src/Checkbox/Checkbox.tsx
|
|
628
715
|
import { jsx as jsx10, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
@@ -642,17 +729,18 @@ var Checkbox = ({
|
|
|
642
729
|
error = false,
|
|
643
730
|
onChange
|
|
644
731
|
}) => {
|
|
645
|
-
const [isFocused, setIsFocused] =
|
|
732
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
733
|
+
const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
|
|
646
734
|
const checkboxStyling = (0, import_classnames7.default)(Checkbox_module_default.checkbox, Checkbox_module_default[size]);
|
|
647
735
|
const uncheckedStyling = (0, import_classnames7.default)(checkboxStyling, Checkbox_module_default.uncheckedBox, {
|
|
648
736
|
[Checkbox_module_default.uncheckedBorder]: !error,
|
|
649
737
|
[Checkbox_module_default.uncheckedErrorBorder]: error,
|
|
650
|
-
[
|
|
738
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
651
739
|
});
|
|
652
740
|
const checkedStyling = (0, import_classnames7.default)(checkboxStyling, Checkbox_module_default.checkedBox, {
|
|
653
741
|
[Checkbox_module_default.checkedNonError]: !error,
|
|
654
742
|
[Checkbox_module_default.checkedError]: error,
|
|
655
|
-
[
|
|
743
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
656
744
|
});
|
|
657
745
|
return /* @__PURE__ */ jsxs2("label", { className: (0, import_classnames7.default)(Checkbox_module_default.mainContainer), children: [
|
|
658
746
|
/* @__PURE__ */ jsxs2("div", { className: Checkbox_module_default.checkboxContainer, children: [
|
|
@@ -707,91 +795,7 @@ var import_classnames8 = __toESM(require_classnames());
|
|
|
707
795
|
import { useState as useState3 } from "react";
|
|
708
796
|
|
|
709
797
|
// css-module:./RadioButton.module.css#css-module
|
|
710
|
-
var RadioButton_module_default = { "radioBaseContainer": "
|
|
711
|
-
|
|
712
|
-
// src/useFocusVisible.tsx
|
|
713
|
-
import { useState as useState2, useEffect } from "react";
|
|
714
|
-
var hasSetupGlobalListeners = false;
|
|
715
|
-
var currentModality = null;
|
|
716
|
-
var changeHandlers = /* @__PURE__ */ new Set();
|
|
717
|
-
var hasEventBeforeFocus = false;
|
|
718
|
-
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
|
|
719
|
-
function isValidKey(e) {
|
|
720
|
-
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey);
|
|
721
|
-
}
|
|
722
|
-
function triggerChangeHandlers(modality, e) {
|
|
723
|
-
changeHandlers.forEach((handler) => {
|
|
724
|
-
handler(modality, e);
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
function handleKeyboardEvent(e) {
|
|
728
|
-
hasEventBeforeFocus = true;
|
|
729
|
-
if (isValidKey(e)) {
|
|
730
|
-
currentModality = "keyboard";
|
|
731
|
-
triggerChangeHandlers("keyboard", e);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
function handlePointerEvent(e) {
|
|
735
|
-
currentModality = "pointer";
|
|
736
|
-
if (e.type === "mousedown" || e.type === "pointerdown") {
|
|
737
|
-
hasEventBeforeFocus = true;
|
|
738
|
-
triggerChangeHandlers("pointer", e);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
function handleFocusEvent(e) {
|
|
742
|
-
if (e.target === window || e.target === document) {
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
if (!hasEventBeforeFocus) {
|
|
746
|
-
currentModality = "keyboard";
|
|
747
|
-
triggerChangeHandlers("keyboard", e);
|
|
748
|
-
}
|
|
749
|
-
hasEventBeforeFocus = false;
|
|
750
|
-
}
|
|
751
|
-
function handleWindowBlur() {
|
|
752
|
-
hasEventBeforeFocus = false;
|
|
753
|
-
}
|
|
754
|
-
function isFocusVisible() {
|
|
755
|
-
return currentModality !== "pointer";
|
|
756
|
-
}
|
|
757
|
-
function setupGlobalFocusEvents() {
|
|
758
|
-
if (typeof window === "undefined" || hasSetupGlobalListeners) {
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
const { focus } = HTMLElement.prototype;
|
|
762
|
-
HTMLElement.prototype.focus = function focusElement(...args) {
|
|
763
|
-
hasEventBeforeFocus = true;
|
|
764
|
-
focus.apply(this, args);
|
|
765
|
-
};
|
|
766
|
-
document.addEventListener("keydown", handleKeyboardEvent, true);
|
|
767
|
-
document.addEventListener("keyup", handleKeyboardEvent, true);
|
|
768
|
-
window.addEventListener("focus", handleFocusEvent, true);
|
|
769
|
-
window.addEventListener("blur", handleWindowBlur, false);
|
|
770
|
-
if (typeof PointerEvent !== "undefined") {
|
|
771
|
-
document.addEventListener("pointerdown", handlePointerEvent, true);
|
|
772
|
-
document.addEventListener("pointermove", handlePointerEvent, true);
|
|
773
|
-
document.addEventListener("pointerup", handlePointerEvent, true);
|
|
774
|
-
} else {
|
|
775
|
-
document.addEventListener("mousedown", handlePointerEvent, true);
|
|
776
|
-
document.addEventListener("mousemove", handlePointerEvent, true);
|
|
777
|
-
document.addEventListener("mouseup", handlePointerEvent, true);
|
|
778
|
-
}
|
|
779
|
-
hasSetupGlobalListeners = true;
|
|
780
|
-
}
|
|
781
|
-
function useFocusVisible() {
|
|
782
|
-
setupGlobalFocusEvents();
|
|
783
|
-
const [isFocusVisibleState, setFocusVisible] = useState2(isFocusVisible());
|
|
784
|
-
useEffect(() => {
|
|
785
|
-
const handler = () => {
|
|
786
|
-
setFocusVisible(isFocusVisible());
|
|
787
|
-
};
|
|
788
|
-
changeHandlers.add(handler);
|
|
789
|
-
return () => {
|
|
790
|
-
changeHandlers.delete(handler);
|
|
791
|
-
};
|
|
792
|
-
}, []);
|
|
793
|
-
return { isFocusVisible: isFocusVisibleState };
|
|
794
|
-
}
|
|
798
|
+
var RadioButton_module_default = { "radioBaseContainer": "_radioBaseContainer_144ms_1", "smBase": "_smBase_144ms_8", "mdBase": "_mdBase_144ms_13", "radioStyleOverride": "_radioStyleOverride_144ms_18", "smOverride": "_smOverride_144ms_23", "mdOverride": "_mdOverride_144ms_28", "background": "_background_144ms_33", "sm": "_sm_144ms_8", "md": "_md_144ms_13", "neutralBorder": "_neutralBorder_144ms_50", "smCheckedBorder": "_smCheckedBorder_144ms_54", "mdCheckedBorder": "_mdCheckedBorder_144ms_58", "errorBorderColor": "_errorBorderColor_144ms_62", "borderColor": "_borderColor_144ms_66" };
|
|
795
799
|
|
|
796
800
|
// src/RadioButton/RadioButton.tsx
|
|
797
801
|
import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
@@ -810,7 +814,7 @@ var RadioButton = ({
|
|
|
810
814
|
const sharedStyles = (0, import_classnames8.default)(RadioButton_module_default.background, RadioButton_module_default[size], {
|
|
811
815
|
[RadioButton_module_default.errorBorderColor]: error,
|
|
812
816
|
[RadioButton_module_default.borderColor]: !error,
|
|
813
|
-
[
|
|
817
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
814
818
|
});
|
|
815
819
|
return /* @__PURE__ */ jsxs3(
|
|
816
820
|
"label",
|
|
@@ -866,14 +870,14 @@ var RadioButton_default = RadioButton;
|
|
|
866
870
|
|
|
867
871
|
// src/SelectList/SelectList.tsx
|
|
868
872
|
var import_classnames9 = __toESM(require_classnames());
|
|
869
|
-
import { useId } from "react";
|
|
873
|
+
import { useId, useState as useState4 } from "react";
|
|
870
874
|
|
|
871
875
|
// ../syntax-design-tokens/dist/js/index.js
|
|
872
876
|
var ColorBaseDestructive700 = "#d32a4b";
|
|
873
877
|
var ColorBaseGray800 = "#353535";
|
|
874
878
|
|
|
875
879
|
// css-module:./SelectList.module.css#css-module
|
|
876
|
-
var SelectList_module_default = { "selectContainer": "
|
|
880
|
+
var SelectList_module_default = { "selectContainer": "_selectContainer_1e7f9_1", "opacityOverlay": "_opacityOverlay_1e7f9_7", "outerTextContainer": "_outerTextContainer_1e7f9_11", "selectWrapper": "_selectWrapper_1e7f9_16", "selectBox": "_selectBox_1e7f9_21", "seletBoxMouseFocusStyling": "_seletBoxMouseFocusStyling_1e7f9_35", "unselected": "_unselected_1e7f9_40", "selected": "_selected_1e7f9_44", "arrowIcon": "_arrowIcon_1e7f9_48", "sm": "_sm_1e7f9_62", "md": "_md_1e7f9_67", "lg": "_lg_1e7f9_72", "selectError": "_selectError_1e7f9_77" };
|
|
877
881
|
|
|
878
882
|
// src/SelectList/SelectOption.tsx
|
|
879
883
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
@@ -911,6 +915,8 @@ var SelectList = ({
|
|
|
911
915
|
size = "md"
|
|
912
916
|
}) => {
|
|
913
917
|
const id = useId();
|
|
918
|
+
const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
|
|
919
|
+
const [isFocused, setIsFocused] = useState4(false);
|
|
914
920
|
return /* @__PURE__ */ jsxs4(
|
|
915
921
|
"div",
|
|
916
922
|
{
|
|
@@ -929,10 +935,16 @@ var SelectList = ({
|
|
|
929
935
|
className: (0, import_classnames9.default)(SelectList_module_default.selectBox, SelectList_module_default[size], {
|
|
930
936
|
[SelectList_module_default.unselected]: !selectedValue && !errorText,
|
|
931
937
|
[SelectList_module_default.selected]: selectedValue && !errorText,
|
|
932
|
-
[SelectList_module_default.selectError]: errorText
|
|
938
|
+
[SelectList_module_default.selectError]: errorText,
|
|
939
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2,
|
|
940
|
+
// for focus keyboard
|
|
941
|
+
[SelectList_module_default.seletBoxMouseFocusStyling]: isFocused && !isFocusVisible2
|
|
942
|
+
// for focus mouse
|
|
933
943
|
}),
|
|
934
944
|
onChange,
|
|
935
945
|
value: placeholderText && !selectedValue ? placeholderText : selectedValue,
|
|
946
|
+
onFocus: () => setIsFocused(true),
|
|
947
|
+
onBlur: () => setIsFocused(false),
|
|
936
948
|
children: [
|
|
937
949
|
placeholderText && /* @__PURE__ */ jsx14("option", { disabled: true, value: placeholderText, children: placeholderText }),
|
|
938
950
|
children
|