@cambly/syntax-core 4.0.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.d.ts +5 -0
- package/dist/index.js +108 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -94
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -160,6 +160,7 @@ function Box(props) {
|
|
|
160
160
|
display,
|
|
161
161
|
smDisplay,
|
|
162
162
|
lgDisplay,
|
|
163
|
+
flexShrink,
|
|
163
164
|
flexWrap,
|
|
164
165
|
gap: gap2,
|
|
165
166
|
justifyContent,
|
|
@@ -211,6 +212,7 @@ function Box(props) {
|
|
|
211
212
|
"display",
|
|
212
213
|
"smDisplay",
|
|
213
214
|
"lgDisplay",
|
|
215
|
+
"flexShrink",
|
|
214
216
|
"flexWrap",
|
|
215
217
|
"gap",
|
|
216
218
|
"justifyContent",
|
|
@@ -312,6 +314,7 @@ function Box(props) {
|
|
|
312
314
|
rounding && rounding !== "none" && Box_module_default[`rounding${rounding}`]
|
|
313
315
|
),
|
|
314
316
|
style: __spreadValues({
|
|
317
|
+
flexShrink,
|
|
315
318
|
height,
|
|
316
319
|
maxHeight,
|
|
317
320
|
maxWidth,
|
|
@@ -616,10 +619,97 @@ var IconButton_default = IconButton;
|
|
|
616
619
|
|
|
617
620
|
// src/Checkbox/Checkbox.tsx
|
|
618
621
|
var import_classnames7 = __toESM(require_classnames());
|
|
619
|
-
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
|
+
}
|
|
620
707
|
|
|
621
708
|
// css-module:./Checkbox.module.css#css-module
|
|
622
|
-
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" };
|
|
623
713
|
|
|
624
714
|
// src/Checkbox/Checkbox.tsx
|
|
625
715
|
import { jsx as jsx10, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
@@ -639,17 +729,18 @@ var Checkbox = ({
|
|
|
639
729
|
error = false,
|
|
640
730
|
onChange
|
|
641
731
|
}) => {
|
|
642
|
-
const [isFocused, setIsFocused] =
|
|
732
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
733
|
+
const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
|
|
643
734
|
const checkboxStyling = (0, import_classnames7.default)(Checkbox_module_default.checkbox, Checkbox_module_default[size]);
|
|
644
735
|
const uncheckedStyling = (0, import_classnames7.default)(checkboxStyling, Checkbox_module_default.uncheckedBox, {
|
|
645
736
|
[Checkbox_module_default.uncheckedBorder]: !error,
|
|
646
737
|
[Checkbox_module_default.uncheckedErrorBorder]: error,
|
|
647
|
-
[
|
|
738
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
648
739
|
});
|
|
649
740
|
const checkedStyling = (0, import_classnames7.default)(checkboxStyling, Checkbox_module_default.checkedBox, {
|
|
650
741
|
[Checkbox_module_default.checkedNonError]: !error,
|
|
651
742
|
[Checkbox_module_default.checkedError]: error,
|
|
652
|
-
[
|
|
743
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
653
744
|
});
|
|
654
745
|
return /* @__PURE__ */ jsxs2("label", { className: (0, import_classnames7.default)(Checkbox_module_default.mainContainer), children: [
|
|
655
746
|
/* @__PURE__ */ jsxs2("div", { className: Checkbox_module_default.checkboxContainer, children: [
|
|
@@ -704,91 +795,7 @@ var import_classnames8 = __toESM(require_classnames());
|
|
|
704
795
|
import { useState as useState3 } from "react";
|
|
705
796
|
|
|
706
797
|
// css-module:./RadioButton.module.css#css-module
|
|
707
|
-
var RadioButton_module_default = { "radioBaseContainer": "
|
|
708
|
-
|
|
709
|
-
// src/useFocusVisible.tsx
|
|
710
|
-
import { useState as useState2, useEffect } from "react";
|
|
711
|
-
var hasSetupGlobalListeners = false;
|
|
712
|
-
var currentModality = null;
|
|
713
|
-
var changeHandlers = /* @__PURE__ */ new Set();
|
|
714
|
-
var hasEventBeforeFocus = false;
|
|
715
|
-
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
|
|
716
|
-
function isValidKey(e) {
|
|
717
|
-
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey);
|
|
718
|
-
}
|
|
719
|
-
function triggerChangeHandlers(modality, e) {
|
|
720
|
-
changeHandlers.forEach((handler) => {
|
|
721
|
-
handler(modality, e);
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
function handleKeyboardEvent(e) {
|
|
725
|
-
hasEventBeforeFocus = true;
|
|
726
|
-
if (isValidKey(e)) {
|
|
727
|
-
currentModality = "keyboard";
|
|
728
|
-
triggerChangeHandlers("keyboard", e);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
function handlePointerEvent(e) {
|
|
732
|
-
currentModality = "pointer";
|
|
733
|
-
if (e.type === "mousedown" || e.type === "pointerdown") {
|
|
734
|
-
hasEventBeforeFocus = true;
|
|
735
|
-
triggerChangeHandlers("pointer", e);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
function handleFocusEvent(e) {
|
|
739
|
-
if (e.target === window || e.target === document) {
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
if (!hasEventBeforeFocus) {
|
|
743
|
-
currentModality = "keyboard";
|
|
744
|
-
triggerChangeHandlers("keyboard", e);
|
|
745
|
-
}
|
|
746
|
-
hasEventBeforeFocus = false;
|
|
747
|
-
}
|
|
748
|
-
function handleWindowBlur() {
|
|
749
|
-
hasEventBeforeFocus = false;
|
|
750
|
-
}
|
|
751
|
-
function isFocusVisible() {
|
|
752
|
-
return currentModality !== "pointer";
|
|
753
|
-
}
|
|
754
|
-
function setupGlobalFocusEvents() {
|
|
755
|
-
if (typeof window === "undefined" || hasSetupGlobalListeners) {
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
const { focus } = HTMLElement.prototype;
|
|
759
|
-
HTMLElement.prototype.focus = function focusElement(...args) {
|
|
760
|
-
hasEventBeforeFocus = true;
|
|
761
|
-
focus.apply(this, args);
|
|
762
|
-
};
|
|
763
|
-
document.addEventListener("keydown", handleKeyboardEvent, true);
|
|
764
|
-
document.addEventListener("keyup", handleKeyboardEvent, true);
|
|
765
|
-
window.addEventListener("focus", handleFocusEvent, true);
|
|
766
|
-
window.addEventListener("blur", handleWindowBlur, false);
|
|
767
|
-
if (typeof PointerEvent !== "undefined") {
|
|
768
|
-
document.addEventListener("pointerdown", handlePointerEvent, true);
|
|
769
|
-
document.addEventListener("pointermove", handlePointerEvent, true);
|
|
770
|
-
document.addEventListener("pointerup", handlePointerEvent, true);
|
|
771
|
-
} else {
|
|
772
|
-
document.addEventListener("mousedown", handlePointerEvent, true);
|
|
773
|
-
document.addEventListener("mousemove", handlePointerEvent, true);
|
|
774
|
-
document.addEventListener("mouseup", handlePointerEvent, true);
|
|
775
|
-
}
|
|
776
|
-
hasSetupGlobalListeners = true;
|
|
777
|
-
}
|
|
778
|
-
function useFocusVisible() {
|
|
779
|
-
setupGlobalFocusEvents();
|
|
780
|
-
const [isFocusVisibleState, setFocusVisible] = useState2(isFocusVisible());
|
|
781
|
-
useEffect(() => {
|
|
782
|
-
const handler = () => {
|
|
783
|
-
setFocusVisible(isFocusVisible());
|
|
784
|
-
};
|
|
785
|
-
changeHandlers.add(handler);
|
|
786
|
-
return () => {
|
|
787
|
-
changeHandlers.delete(handler);
|
|
788
|
-
};
|
|
789
|
-
}, []);
|
|
790
|
-
return { isFocusVisible: isFocusVisibleState };
|
|
791
|
-
}
|
|
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" };
|
|
792
799
|
|
|
793
800
|
// src/RadioButton/RadioButton.tsx
|
|
794
801
|
import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
@@ -807,7 +814,7 @@ var RadioButton = ({
|
|
|
807
814
|
const sharedStyles = (0, import_classnames8.default)(RadioButton_module_default.background, RadioButton_module_default[size], {
|
|
808
815
|
[RadioButton_module_default.errorBorderColor]: error,
|
|
809
816
|
[RadioButton_module_default.borderColor]: !error,
|
|
810
|
-
[
|
|
817
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
811
818
|
});
|
|
812
819
|
return /* @__PURE__ */ jsxs3(
|
|
813
820
|
"label",
|
|
@@ -863,14 +870,14 @@ var RadioButton_default = RadioButton;
|
|
|
863
870
|
|
|
864
871
|
// src/SelectList/SelectList.tsx
|
|
865
872
|
var import_classnames9 = __toESM(require_classnames());
|
|
866
|
-
import { useId } from "react";
|
|
873
|
+
import { useId, useState as useState4 } from "react";
|
|
867
874
|
|
|
868
875
|
// ../syntax-design-tokens/dist/js/index.js
|
|
869
876
|
var ColorBaseDestructive700 = "#d32a4b";
|
|
870
877
|
var ColorBaseGray800 = "#353535";
|
|
871
878
|
|
|
872
879
|
// css-module:./SelectList.module.css#css-module
|
|
873
|
-
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" };
|
|
874
881
|
|
|
875
882
|
// src/SelectList/SelectOption.tsx
|
|
876
883
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
@@ -908,6 +915,8 @@ var SelectList = ({
|
|
|
908
915
|
size = "md"
|
|
909
916
|
}) => {
|
|
910
917
|
const id = useId();
|
|
918
|
+
const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
|
|
919
|
+
const [isFocused, setIsFocused] = useState4(false);
|
|
911
920
|
return /* @__PURE__ */ jsxs4(
|
|
912
921
|
"div",
|
|
913
922
|
{
|
|
@@ -926,10 +935,16 @@ var SelectList = ({
|
|
|
926
935
|
className: (0, import_classnames9.default)(SelectList_module_default.selectBox, SelectList_module_default[size], {
|
|
927
936
|
[SelectList_module_default.unselected]: !selectedValue && !errorText,
|
|
928
937
|
[SelectList_module_default.selected]: selectedValue && !errorText,
|
|
929
|
-
[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
|
|
930
943
|
}),
|
|
931
944
|
onChange,
|
|
932
945
|
value: placeholderText && !selectedValue ? placeholderText : selectedValue,
|
|
946
|
+
onFocus: () => setIsFocused(true),
|
|
947
|
+
onBlur: () => setIsFocused(false),
|
|
933
948
|
children: [
|
|
934
949
|
placeholderText && /* @__PURE__ */ jsx14("option", { disabled: true, value: placeholderText, children: placeholderText }),
|
|
935
950
|
children
|