@entropix/react 0.1.1 → 0.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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { forwardRef, useMemo, useCallback, createContext, useState, useEffect, useRef, useContext } from 'react';
2
- import { useButton, useToggle, useDialog, useTabs, useAccordion, useMenu } from '@entropix/core';
3
- import { jsx } from 'react/jsx-runtime';
2
+ import { useButton, useToggle, useInput, useDialog, useTabs, useAccordion, useMenu, useRadioGroup, useSelect } from '@entropix/core';
3
+ import { jsx, jsxs } from 'react/jsx-runtime';
4
4
  import { createPortal } from 'react-dom';
5
5
 
6
6
  // src/utils/map-accessibility-to-aria.ts
@@ -26,7 +26,9 @@ var ARIA_MAP = {
26
26
  valueNow: "aria-valuenow",
27
27
  valueMin: "aria-valuemin",
28
28
  valueMax: "aria-valuemax",
29
- valueText: "aria-valuetext"
29
+ valueText: "aria-valuetext",
30
+ required: "aria-required",
31
+ invalid: "aria-invalid"
30
32
  };
31
33
  function mapAccessibilityToAria(props) {
32
34
  const result = {};
@@ -661,6 +663,462 @@ function MenuItem({
661
663
  }
662
664
  );
663
665
  }
666
+ var Input = forwardRef(function Input2({
667
+ value,
668
+ defaultValue,
669
+ onChange,
670
+ disabled,
671
+ readOnly,
672
+ required,
673
+ invalid,
674
+ label,
675
+ helperText,
676
+ errorMessage,
677
+ variant = "default",
678
+ size = "md",
679
+ className,
680
+ type,
681
+ placeholder,
682
+ name,
683
+ ...rest
684
+ }, ref) {
685
+ const isInvalid = invalid || !!errorMessage;
686
+ const {
687
+ value: inputValue,
688
+ isDisabled,
689
+ isReadOnly,
690
+ isRequired,
691
+ isInvalid: _,
692
+ getInputProps,
693
+ getLabelProps,
694
+ getHelperTextProps,
695
+ getErrorMessageProps
696
+ } = useInput({
697
+ value,
698
+ defaultValue,
699
+ onChange,
700
+ disabled,
701
+ readOnly,
702
+ required,
703
+ invalid: isInvalid,
704
+ type,
705
+ placeholder,
706
+ name
707
+ });
708
+ const propGetterReturn = getInputProps();
709
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
710
+ const labelProps = getLabelProps();
711
+ const helperProps = getHelperTextProps();
712
+ const errorProps = getErrorMessageProps();
713
+ const handleChange = useCallback(
714
+ (event) => {
715
+ onChange?.(event.target.value);
716
+ },
717
+ [onChange]
718
+ );
719
+ const dataState = isInvalid ? "invalid" : isDisabled ? "disabled" : void 0;
720
+ return /* @__PURE__ */ jsxs(
721
+ "div",
722
+ {
723
+ className: cn("entropix-input-wrapper", className),
724
+ "data-state": dataState,
725
+ "data-variant": variant,
726
+ "data-size": size,
727
+ children: [
728
+ label && /* @__PURE__ */ jsxs(
729
+ "label",
730
+ {
731
+ className: "entropix-input-label",
732
+ id: labelProps.id,
733
+ htmlFor: labelProps.htmlFor,
734
+ children: [
735
+ label,
736
+ isRequired && /* @__PURE__ */ jsx("span", { className: "entropix-input-required", children: "*" })
737
+ ]
738
+ }
739
+ ),
740
+ /* @__PURE__ */ jsx(
741
+ "input",
742
+ {
743
+ ref,
744
+ className: "entropix-input",
745
+ ...ariaProps,
746
+ ...rest,
747
+ type,
748
+ name,
749
+ placeholder,
750
+ value: inputValue,
751
+ onChange: handleChange,
752
+ disabled: isDisabled || void 0,
753
+ readOnly: isReadOnly || void 0,
754
+ "data-state": dataState,
755
+ "data-variant": variant,
756
+ "data-size": size
757
+ }
758
+ ),
759
+ isInvalid && errorMessage ? /* @__PURE__ */ jsx("span", { className: "entropix-input-error", ...errorProps, children: errorMessage }) : helperText ? /* @__PURE__ */ jsx("span", { className: "entropix-input-helper", ...helperProps, children: helperText }) : null
760
+ ]
761
+ }
762
+ );
763
+ });
764
+ var Textarea = forwardRef(
765
+ function Textarea2({
766
+ value,
767
+ defaultValue,
768
+ onChange,
769
+ disabled,
770
+ readOnly,
771
+ required,
772
+ invalid,
773
+ label,
774
+ helperText,
775
+ errorMessage,
776
+ variant = "default",
777
+ size = "md",
778
+ rows,
779
+ resize = "vertical",
780
+ className,
781
+ placeholder,
782
+ name,
783
+ style,
784
+ ...rest
785
+ }, ref) {
786
+ const isInvalid = invalid || !!errorMessage;
787
+ const {
788
+ value: inputValue,
789
+ isDisabled,
790
+ isReadOnly,
791
+ isRequired,
792
+ getInputProps,
793
+ getLabelProps,
794
+ getHelperTextProps,
795
+ getErrorMessageProps
796
+ } = useInput({
797
+ value,
798
+ defaultValue,
799
+ onChange,
800
+ disabled,
801
+ readOnly,
802
+ required,
803
+ invalid: isInvalid,
804
+ placeholder,
805
+ name
806
+ });
807
+ const propGetterReturn = getInputProps();
808
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
809
+ const labelProps = getLabelProps();
810
+ const helperProps = getHelperTextProps();
811
+ const errorProps = getErrorMessageProps();
812
+ const handleChange = useCallback(
813
+ (event) => {
814
+ onChange?.(event.target.value);
815
+ },
816
+ [onChange]
817
+ );
818
+ const dataState = isInvalid ? "invalid" : isDisabled ? "disabled" : void 0;
819
+ return /* @__PURE__ */ jsxs(
820
+ "div",
821
+ {
822
+ className: cn("entropix-input-wrapper", className),
823
+ "data-state": dataState,
824
+ "data-variant": variant,
825
+ "data-size": size,
826
+ children: [
827
+ label && /* @__PURE__ */ jsxs(
828
+ "label",
829
+ {
830
+ className: "entropix-input-label",
831
+ id: labelProps.id,
832
+ htmlFor: labelProps.htmlFor,
833
+ children: [
834
+ label,
835
+ isRequired && /* @__PURE__ */ jsx("span", { className: "entropix-input-required", children: "*" })
836
+ ]
837
+ }
838
+ ),
839
+ /* @__PURE__ */ jsx(
840
+ "textarea",
841
+ {
842
+ ref,
843
+ className: "entropix-textarea",
844
+ ...ariaProps,
845
+ ...rest,
846
+ name,
847
+ placeholder,
848
+ value: inputValue,
849
+ onChange: handleChange,
850
+ disabled: isDisabled || void 0,
851
+ readOnly: isReadOnly || void 0,
852
+ rows,
853
+ style: { ...style, resize },
854
+ "data-state": dataState,
855
+ "data-variant": variant,
856
+ "data-size": size
857
+ }
858
+ ),
859
+ isInvalid && errorMessage ? /* @__PURE__ */ jsx("span", { className: "entropix-input-error", ...errorProps, children: errorMessage }) : helperText ? /* @__PURE__ */ jsx("span", { className: "entropix-input-helper", ...helperProps, children: helperText }) : null
860
+ ]
861
+ }
862
+ );
863
+ }
864
+ );
865
+ var Checkbox = forwardRef(
866
+ function Checkbox2({
867
+ checked,
868
+ defaultChecked,
869
+ onChange,
870
+ disabled,
871
+ label,
872
+ indeterminate = false,
873
+ className,
874
+ style,
875
+ children,
876
+ onClick,
877
+ onKeyDown: externalOnKeyDown,
878
+ ...rest
879
+ }, ref) {
880
+ const { isChecked, isDisabled, getToggleProps } = useToggle({
881
+ checked,
882
+ defaultChecked,
883
+ onChange,
884
+ disabled,
885
+ role: "checkbox"
886
+ });
887
+ const propGetterReturn = getToggleProps();
888
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
889
+ if (indeterminate) {
890
+ ariaProps["aria-checked"] = "mixed";
891
+ }
892
+ if (label && !children) {
893
+ ariaProps["aria-label"] = label;
894
+ }
895
+ const actionMap = useMemo(
896
+ () => ({
897
+ toggle: propGetterReturn.onAction ?? (() => {
898
+ })
899
+ }),
900
+ [propGetterReturn.onAction]
901
+ );
902
+ const onKeyDown = useKeyboardHandler(
903
+ propGetterReturn.keyboardConfig,
904
+ actionMap
905
+ );
906
+ const handleClick = useCallback(
907
+ (event) => {
908
+ propGetterReturn.onAction?.();
909
+ onClick?.(event);
910
+ },
911
+ [propGetterReturn.onAction, onClick]
912
+ );
913
+ const handleKeyDown = useCallback(
914
+ (event) => {
915
+ onKeyDown?.(event);
916
+ externalOnKeyDown?.(event);
917
+ },
918
+ [onKeyDown, externalOnKeyDown]
919
+ );
920
+ const dataState = indeterminate ? "indeterminate" : isChecked ? "checked" : "unchecked";
921
+ return /* @__PURE__ */ jsxs(
922
+ "button",
923
+ {
924
+ ref,
925
+ type: "button",
926
+ className: cn("entropix-checkbox", className),
927
+ style,
928
+ ...ariaProps,
929
+ ...rest,
930
+ disabled: isDisabled || void 0,
931
+ onClick: propGetterReturn.onAction || onClick ? handleClick : void 0,
932
+ onKeyDown: onKeyDown || externalOnKeyDown ? handleKeyDown : void 0,
933
+ "data-state": dataState,
934
+ children: [
935
+ /* @__PURE__ */ jsx("span", { className: "entropix-checkbox__indicator", "data-state": dataState }),
936
+ (label || children) && /* @__PURE__ */ jsx("span", { className: "entropix-checkbox__label", children: label || children })
937
+ ]
938
+ }
939
+ );
940
+ }
941
+ );
942
+ var RadioContext = createContext(null);
943
+ function useRadioContext() {
944
+ const context = useContext(RadioContext);
945
+ if (!context) {
946
+ throw new Error(
947
+ "Radio compound components must be used within a <RadioGroup> provider."
948
+ );
949
+ }
950
+ return context;
951
+ }
952
+ function RadioGroup({
953
+ children,
954
+ label,
955
+ className,
956
+ ...options
957
+ }) {
958
+ const radioGroup = useRadioGroup(options);
959
+ const propGetterReturn = radioGroup.getRadioGroupProps();
960
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
961
+ if (label) {
962
+ ariaProps["aria-label"] = label;
963
+ }
964
+ return /* @__PURE__ */ jsx(RadioContext.Provider, { value: radioGroup, children: /* @__PURE__ */ jsx(
965
+ "div",
966
+ {
967
+ ...ariaProps,
968
+ className: cn("entropix-radio-group", className),
969
+ "data-orientation": options.orientation ?? "vertical",
970
+ children
971
+ }
972
+ ) });
973
+ }
974
+ function RadioItem({
975
+ value,
976
+ disabled,
977
+ label,
978
+ children,
979
+ className
980
+ }) {
981
+ const { getRadioProps, selectedValue } = useRadioContext();
982
+ const propGetterReturn = getRadioProps(value, { disabled });
983
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
984
+ const isChecked = value === selectedValue;
985
+ const actionMap = useMemo(
986
+ () => ({}),
987
+ []
988
+ );
989
+ const onKeyDown = useKeyboardHandler(
990
+ propGetterReturn.keyboardConfig,
991
+ actionMap
992
+ );
993
+ const handleClick = useCallback(() => {
994
+ propGetterReturn.onAction?.();
995
+ }, [propGetterReturn.onAction]);
996
+ return /* @__PURE__ */ jsxs(
997
+ "button",
998
+ {
999
+ type: "button",
1000
+ ...ariaProps,
1001
+ className: cn("entropix-radio-item", className),
1002
+ onClick: handleClick,
1003
+ onKeyDown,
1004
+ "data-state": isChecked ? "checked" : "unchecked",
1005
+ "data-disabled": disabled || void 0,
1006
+ children: [
1007
+ /* @__PURE__ */ jsx(
1008
+ "span",
1009
+ {
1010
+ className: "entropix-radio-item__indicator",
1011
+ "data-state": isChecked ? "checked" : "unchecked"
1012
+ }
1013
+ ),
1014
+ (label || children) && /* @__PURE__ */ jsx("span", { className: "entropix-radio-item__label", children: label || children })
1015
+ ]
1016
+ }
1017
+ );
1018
+ }
1019
+ var SelectContext = createContext(null);
1020
+ function useSelectContext() {
1021
+ const context = useContext(SelectContext);
1022
+ if (!context) {
1023
+ throw new Error(
1024
+ "Select compound components must be used within a <Select> provider."
1025
+ );
1026
+ }
1027
+ return context;
1028
+ }
1029
+ function Select({ children, label, className, ...options }) {
1030
+ const select = useSelect(options);
1031
+ const labelProps = select.getLabelProps();
1032
+ return /* @__PURE__ */ jsx(SelectContext.Provider, { value: select, children: /* @__PURE__ */ jsxs("div", { className: cn("entropix-select", className), children: [
1033
+ label && /* @__PURE__ */ jsx(
1034
+ "label",
1035
+ {
1036
+ className: "entropix-select-label",
1037
+ id: labelProps.id,
1038
+ htmlFor: labelProps.htmlFor,
1039
+ children: label
1040
+ }
1041
+ ),
1042
+ children
1043
+ ] }) });
1044
+ }
1045
+ function SelectTrigger({
1046
+ placeholder = "Select...",
1047
+ children,
1048
+ className
1049
+ }) {
1050
+ const { getTriggerProps, toggle, open, selectedValue, isDisabled } = useSelectContext();
1051
+ const propGetterReturn = getTriggerProps();
1052
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
1053
+ const handleClick = useCallback(() => {
1054
+ propGetterReturn.onAction?.();
1055
+ }, [propGetterReturn.onAction]);
1056
+ const onKeyDown = useKeyboardHandler(propGetterReturn.keyboardConfig, {
1057
+ activate: toggle,
1058
+ moveDown: open,
1059
+ moveUp: open
1060
+ });
1061
+ return /* @__PURE__ */ jsxs(
1062
+ "button",
1063
+ {
1064
+ type: "button",
1065
+ ...ariaProps,
1066
+ className: cn("entropix-select-trigger", className),
1067
+ onClick: handleClick,
1068
+ onKeyDown,
1069
+ disabled: isDisabled || void 0,
1070
+ children: [
1071
+ /* @__PURE__ */ jsx("span", { className: "entropix-select-trigger__value", children: children ?? (selectedValue || placeholder) }),
1072
+ /* @__PURE__ */ jsx("span", { className: "entropix-select-trigger__chevron", "aria-hidden": "true", children: "\u25BE" })
1073
+ ]
1074
+ }
1075
+ );
1076
+ }
1077
+ function SelectContent({ children, className }) {
1078
+ const { isOpen, getListboxProps, close } = useSelectContext();
1079
+ const propGetterReturn = getListboxProps();
1080
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
1081
+ const onKeyDown = useKeyboardHandler(propGetterReturn.keyboardConfig, {
1082
+ dismiss: close
1083
+ });
1084
+ if (!isOpen) return null;
1085
+ return /* @__PURE__ */ jsx(
1086
+ "div",
1087
+ {
1088
+ ...ariaProps,
1089
+ className: cn("entropix-select-content", className),
1090
+ onKeyDown,
1091
+ "data-state": "open",
1092
+ children
1093
+ }
1094
+ );
1095
+ }
1096
+ function SelectOption({
1097
+ value,
1098
+ index,
1099
+ disabled,
1100
+ children,
1101
+ className
1102
+ }) {
1103
+ const { getOptionProps, selectedValue } = useSelectContext();
1104
+ const propGetterReturn = getOptionProps(value, index ?? 0, { disabled });
1105
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
1106
+ const isSelected = value === selectedValue;
1107
+ const handleClick = useCallback(() => {
1108
+ propGetterReturn.onAction?.();
1109
+ }, [propGetterReturn.onAction]);
1110
+ return /* @__PURE__ */ jsx(
1111
+ "div",
1112
+ {
1113
+ ...ariaProps,
1114
+ className: cn("entropix-select-option", className),
1115
+ onClick: handleClick,
1116
+ "data-state": isSelected ? "selected" : "unselected",
1117
+ "data-disabled": disabled || void 0,
1118
+ children
1119
+ }
1120
+ );
1121
+ }
664
1122
  var BREAKPOINTS = {
665
1123
  sm: 640,
666
1124
  md: 768,
@@ -777,6 +1235,6 @@ var Divider = forwardRef(function Divider2({ orientation = "horizontal", spacing
777
1235
  );
778
1236
  });
779
1237
 
780
- export { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, BREAKPOINTS, Button, Container, Dialog, DialogClose, DialogContent, DialogDescription, DialogOverlay, DialogTitle, DialogTrigger, Divider, Inline, Menu, MenuContent, MenuItem, MenuTrigger, Stack, Switch, Tab, TabList, TabPanel, Tabs, Toggle, mapAccessibilityToAria, useBreakpoint, useBreakpointValue, useFocusRestore, useFocusTrap, useKeyboardHandler, useMediaQuery };
1238
+ export { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, BREAKPOINTS, Button, Checkbox, Container, Dialog, DialogClose, DialogContent, DialogDescription, DialogOverlay, DialogTitle, DialogTrigger, Divider, Inline, Input, Menu, MenuContent, MenuItem, MenuTrigger, RadioGroup, RadioItem, Select, SelectContent, SelectOption, SelectTrigger, Stack, Switch, Tab, TabList, TabPanel, Tabs, Textarea, Toggle, mapAccessibilityToAria, useBreakpoint, useBreakpointValue, useFocusRestore, useFocusTrap, useKeyboardHandler, useMediaQuery };
781
1239
  //# sourceMappingURL=index.js.map
782
1240
  //# sourceMappingURL=index.js.map