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