@binamik/components 0.1.1 → 0.1.2
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/Assets/animations/Spinner/SpinnerStyles.d.ts +1 -0
- package/dist/Buttons/DefaultButton/Button.styles.d.ts +1 -0
- package/dist/Table/EmptyRow.d.ts +6 -0
- package/dist/Table/Header.d.ts +8 -0
- package/dist/Table/MobileSortMenu.d.ts +7 -0
- package/dist/Table/Row.d.ts +12 -0
- package/dist/Table/Table.d.ts +38 -0
- package/dist/Table/helpers.d.ts +5 -0
- package/dist/Table/index.d.ts +5 -0
- package/dist/Table/styles.d.ts +2349 -0
- package/dist/binamik-components.es.js +770 -3
- package/dist/binamik-components.umd.js +402 -24
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -31,7 +31,8 @@ var __objRest = (source, exclude) => {
|
|
|
31
31
|
};
|
|
32
32
|
import { keyframes, css, Global } from "@emotion/react";
|
|
33
33
|
import styled from "@emotion/styled";
|
|
34
|
-
import
|
|
34
|
+
import React, { useMemo, useCallback, useState, useEffect, createContext, Fragment as Fragment$1, useContext } from "react";
|
|
35
|
+
import { motion, AnimatePresence } from "framer-motion";
|
|
35
36
|
const dashAnimation = keyframes`
|
|
36
37
|
0% {
|
|
37
38
|
stroke-dasharray: 1, 200;
|
|
@@ -158,7 +159,7 @@ shouldUseNative() ? Object.assign : function(target, source) {
|
|
|
158
159
|
* This source code is licensed under the MIT license found in the
|
|
159
160
|
* LICENSE file in the root directory of this source tree.
|
|
160
161
|
*/
|
|
161
|
-
var f =
|
|
162
|
+
var f = React, g = 60103;
|
|
162
163
|
reactJsxRuntime_production_min.Fragment = 60107;
|
|
163
164
|
if (typeof Symbol === "function" && Symbol.for) {
|
|
164
165
|
var h = Symbol.for;
|
|
@@ -185,6 +186,7 @@ reactJsxRuntime_production_min.jsxs = q;
|
|
|
185
186
|
}
|
|
186
187
|
const jsx = jsxRuntime.exports.jsx;
|
|
187
188
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
189
|
+
const Fragment = jsxRuntime.exports.Fragment;
|
|
188
190
|
const Spinner = ({
|
|
189
191
|
size,
|
|
190
192
|
color,
|
|
@@ -693,4 +695,769 @@ const PreventScroll = () => {
|
|
|
693
695
|
`
|
|
694
696
|
});
|
|
695
697
|
};
|
|
696
|
-
|
|
698
|
+
const MIN_TABLE_MOBILE_BREAKPOINT = 480;
|
|
699
|
+
const parseBreakpointProp = (props) => Math.max(props.mobileBreakpoint, MIN_TABLE_MOBILE_BREAKPOINT);
|
|
700
|
+
const filterProps = {
|
|
701
|
+
shouldForwardProp(prop) {
|
|
702
|
+
return !["columnTemplate", "mobileBreakpoint", "customCss"].includes(prop);
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
const TableWrapper = styled(motion.div, filterProps)`
|
|
706
|
+
--radius: 0.625rem;
|
|
707
|
+
--column-template: ${(props) => props.columnTemplate};
|
|
708
|
+
--table-padding: 1.875rem;
|
|
709
|
+
|
|
710
|
+
--header-row-display: grid;
|
|
711
|
+
--label-background: rgba(0, 0, 0, 0.045);
|
|
712
|
+
--highlight-transition: 150ms ease-in-out;
|
|
713
|
+
|
|
714
|
+
--row-padding: 0.5rem;
|
|
715
|
+
--row-margin: 0;
|
|
716
|
+
--row-border: none;
|
|
717
|
+
--row-even-background: var(--clr-gray14);
|
|
718
|
+
--row-odd-background: var(--clr-white);
|
|
719
|
+
--row-hover-background: var(--clr-gray11);
|
|
720
|
+
|
|
721
|
+
--cell-column-template: 1fr;
|
|
722
|
+
--cell-padding: 0.75rem;
|
|
723
|
+
|
|
724
|
+
--row-annex-border: 1px solid var(--clr-gray7);
|
|
725
|
+
--row-annex-padding: calc(var(--row-padding) + var(--cell-padding));
|
|
726
|
+
--row-annex-margin: 0 var(--row-annex-padding) var(--row-annex-padding);
|
|
727
|
+
|
|
728
|
+
--mobile-decorators-content: none;
|
|
729
|
+
--mobile-ref-width: 20ch;
|
|
730
|
+
--mobile-ref-display: none;
|
|
731
|
+
--mobile-sorting-display: none;
|
|
732
|
+
|
|
733
|
+
--table-row-height: 3.75rem;
|
|
734
|
+
|
|
735
|
+
width: 100%;
|
|
736
|
+
color: #2d2d2d;
|
|
737
|
+
line-height: 1.25;
|
|
738
|
+
border-collapse: collapse;
|
|
739
|
+
background-color: var(--clr-white);
|
|
740
|
+
border: 1px solid var(--clr-gray11);
|
|
741
|
+
padding: var(--table-padding);
|
|
742
|
+
border-radius: var(--radius);
|
|
743
|
+
font-size: 0.875rem;
|
|
744
|
+
position: relative;
|
|
745
|
+
|
|
746
|
+
* {
|
|
747
|
+
box-sizing: border-box;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
@media (max-width: ${parseBreakpointProp}px) {
|
|
751
|
+
--column-template: 1fr;
|
|
752
|
+
|
|
753
|
+
--header-row-display: none;
|
|
754
|
+
|
|
755
|
+
--row-padding: 0;
|
|
756
|
+
--row-margin: 1rem 0;
|
|
757
|
+
--row-border: 1px solid var(--clr-gray7);
|
|
758
|
+
--row-even-background: var(--clr-gray15);
|
|
759
|
+
--row-hover-background: var(--clr-gray14);
|
|
760
|
+
|
|
761
|
+
--cell-column-template: var(--mobile-ref-width) minmax(0, 1fr);
|
|
762
|
+
--cell-padding: 1rem;
|
|
763
|
+
|
|
764
|
+
--row-annex-padding: var(--cell-padding);
|
|
765
|
+
--row-annex-margin: var(--row-annex-padding);
|
|
766
|
+
|
|
767
|
+
--mobile-decorators-content: '';
|
|
768
|
+
--mobile-ref-display: block;
|
|
769
|
+
--mobile-sorting-display: flex;
|
|
770
|
+
--mobile-cell-display: grid;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
@media (max-width: 480px) {
|
|
774
|
+
--table-padding: 1.25rem;
|
|
775
|
+
|
|
776
|
+
--cell-padding: 0.9rem 0.8rem;
|
|
777
|
+
--mobile-ref-width: 15ch;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
@media (max-width: 360px) {
|
|
781
|
+
--table-padding: 0.7rem;
|
|
782
|
+
--cell-padding: 0.8rem 0.65rem;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
${(props) => props.customCss}
|
|
786
|
+
`;
|
|
787
|
+
const TableRowAnnexWrapper = styled(motion.div)`
|
|
788
|
+
width: auto;
|
|
789
|
+
position: relative;
|
|
790
|
+
border: var(--row-annex-border);
|
|
791
|
+
border-radius: var(--radius);
|
|
792
|
+
margin: var(--row-annex-margin);
|
|
793
|
+
padding: var(--row-annex-padding);
|
|
794
|
+
background-color: rgba(255, 255, 255, 0.6);
|
|
795
|
+
transition: background-color var(--highlight-transition);
|
|
796
|
+
`;
|
|
797
|
+
const tableRowStyle = css`
|
|
798
|
+
display: grid;
|
|
799
|
+
width: 100%;
|
|
800
|
+
grid-template-columns: var(--column-template);
|
|
801
|
+
padding: var(--row-padding);
|
|
802
|
+
border-radius: var(--radius);
|
|
803
|
+
transition: background-color var(--highlight-transition);
|
|
804
|
+
min-height: var(--table-row-height);
|
|
805
|
+
color: var(--clr-gray3);
|
|
806
|
+
min-height: 0;
|
|
807
|
+
min-width: 0;
|
|
808
|
+
`;
|
|
809
|
+
const TableRowContainer = styled(motion.li)`
|
|
810
|
+
margin: var(--row-margin);
|
|
811
|
+
border: var(--row-border);
|
|
812
|
+
border-radius: var(--radius);
|
|
813
|
+
padding: 0.01px 0;
|
|
814
|
+
transition: background-color var(--highlight-transition);
|
|
815
|
+
background-color: var(--clr-white);
|
|
816
|
+
|
|
817
|
+
&:first-of-type {
|
|
818
|
+
margin-top: 0;
|
|
819
|
+
}
|
|
820
|
+
&:last-of-type {
|
|
821
|
+
margin-bottom: 0;
|
|
822
|
+
}
|
|
823
|
+
&:nth-of-type(even) {
|
|
824
|
+
background-color: var(--row-even-background);
|
|
825
|
+
}
|
|
826
|
+
&:nth-of-type(odd) {
|
|
827
|
+
background-color: var(--row-odd-background);
|
|
828
|
+
}
|
|
829
|
+
&:not(.empty_row):hover {
|
|
830
|
+
background-color: var(--row-hover-background);
|
|
831
|
+
}
|
|
832
|
+
`;
|
|
833
|
+
const TableRowWrapper = styled(motion.div)`
|
|
834
|
+
${tableRowStyle}
|
|
835
|
+
|
|
836
|
+
max-width: 100%;
|
|
837
|
+
min-width: 0;
|
|
838
|
+
|
|
839
|
+
&:last-of-type .TableCellWrapper:last-of-type::before {
|
|
840
|
+
border-radius: 0 0 var(--radius) var(--radius);
|
|
841
|
+
}
|
|
842
|
+
&:last-of-type .TableCellWrapper:last-of-type .TableCellRef {
|
|
843
|
+
border-radius: 0 0 0 var(--radius);
|
|
844
|
+
}
|
|
845
|
+
`;
|
|
846
|
+
const TableHeaderRow = styled(motion.div)`
|
|
847
|
+
${tableRowStyle}
|
|
848
|
+
min-height: 4.375rem;
|
|
849
|
+
background-color: var(--label-background);
|
|
850
|
+
font-weight: bold;
|
|
851
|
+
color: var(--clr-gray3);
|
|
852
|
+
border-radius: var(--radius);
|
|
853
|
+
display: var(--header-row-display);
|
|
854
|
+
`;
|
|
855
|
+
const TableBody = styled(motion.ul)`
|
|
856
|
+
width: 100%;
|
|
857
|
+
list-style: none;
|
|
858
|
+
margin: 0;
|
|
859
|
+
padding: 0;
|
|
860
|
+
`;
|
|
861
|
+
const tableCellStyle = css`
|
|
862
|
+
padding: var(--cell-padding);
|
|
863
|
+
height: 100%;
|
|
864
|
+
display: flex;
|
|
865
|
+
align-items: center;
|
|
866
|
+
margin: 0;
|
|
867
|
+
`;
|
|
868
|
+
const nonHeaderCellStyle = css`
|
|
869
|
+
position: relative;
|
|
870
|
+
|
|
871
|
+
&::before {
|
|
872
|
+
content: var(--mobile-decorators-content);
|
|
873
|
+
position: absolute;
|
|
874
|
+
inset: 0;
|
|
875
|
+
pointer-events: none;
|
|
876
|
+
z-index: 0;
|
|
877
|
+
background-color: transparent;
|
|
878
|
+
transition: background-color var(--highlight-transition);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
&:nth-of-type(even) {
|
|
882
|
+
&::before {
|
|
883
|
+
background-color: rgba(0, 0, 0, 0.02);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
&:hover {
|
|
888
|
+
&::before {
|
|
889
|
+
background-color: rgba(0, 0, 0, 0.06);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
&:first-of-type::before {
|
|
894
|
+
border-radius: var(--radius) var(--radius) 0 0;
|
|
895
|
+
}
|
|
896
|
+
`;
|
|
897
|
+
const TableCell = styled.div`
|
|
898
|
+
${tableCellStyle}
|
|
899
|
+
|
|
900
|
+
width: 100%;
|
|
901
|
+
`;
|
|
902
|
+
const TableCellWrapper = styled.div`
|
|
903
|
+
${nonHeaderCellStyle}
|
|
904
|
+
|
|
905
|
+
min-width: 0;
|
|
906
|
+
|
|
907
|
+
display: var(--mobile-cell-display, flex);
|
|
908
|
+
|
|
909
|
+
margin: 0;
|
|
910
|
+
width: 100%;
|
|
911
|
+
align-items: center;
|
|
912
|
+
grid-template-columns: var(--cell-column-template);
|
|
913
|
+
|
|
914
|
+
& > * {
|
|
915
|
+
border-radius: none;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
&:first-of-type {
|
|
919
|
+
.TableCellRef {
|
|
920
|
+
border-radius: var(--radius) 0 0 0;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
`;
|
|
924
|
+
const TableCellRef = styled.div`
|
|
925
|
+
${tableCellStyle}
|
|
926
|
+
|
|
927
|
+
display: var(--mobile-ref-display);
|
|
928
|
+
background-color: var(--label-background);
|
|
929
|
+
font-weight: bold;
|
|
930
|
+
color: var(--clr-gray3);
|
|
931
|
+
`;
|
|
932
|
+
const sortableStyles = css`
|
|
933
|
+
&.sortable,
|
|
934
|
+
&.sorted-asc,
|
|
935
|
+
&.sorted-desc {
|
|
936
|
+
cursor: pointer;
|
|
937
|
+
position: relative;
|
|
938
|
+
padding-left: 3.5ch;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
&::after,
|
|
942
|
+
&::before {
|
|
943
|
+
content: '';
|
|
944
|
+
display: block;
|
|
945
|
+
position: absolute;
|
|
946
|
+
height: 0.8ch;
|
|
947
|
+
width: 0.8ch;
|
|
948
|
+
border: 0 solid var(--clr-gray3);
|
|
949
|
+
transform: rotate(45deg);
|
|
950
|
+
left: var(--cell-padding);
|
|
951
|
+
}
|
|
952
|
+
&::before {
|
|
953
|
+
border-width: 1.5px 0 0 1.5px;
|
|
954
|
+
margin-bottom: 1.2ch;
|
|
955
|
+
}
|
|
956
|
+
&::after {
|
|
957
|
+
border-width: 0 1.5px 1.5px 0;
|
|
958
|
+
margin-top: 0.8ch;
|
|
959
|
+
}
|
|
960
|
+
&:not(.sortable) {
|
|
961
|
+
cursor: default;
|
|
962
|
+
&::before,
|
|
963
|
+
&::after {
|
|
964
|
+
content: none;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
&.sorted-desc {
|
|
968
|
+
&::before {
|
|
969
|
+
content: none;
|
|
970
|
+
}
|
|
971
|
+
&::after {
|
|
972
|
+
content: '';
|
|
973
|
+
margin-top: 0;
|
|
974
|
+
margin-bottom: 0.65ch;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
&.sorted-asc {
|
|
978
|
+
&::after {
|
|
979
|
+
content: none;
|
|
980
|
+
}
|
|
981
|
+
&::before {
|
|
982
|
+
content: '';
|
|
983
|
+
margin-bottom: 0;
|
|
984
|
+
margin-top: 0.2ch;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
`;
|
|
988
|
+
const TableHeaderWrapper = styled.div`
|
|
989
|
+
${tableCellStyle}
|
|
990
|
+
transition: background-color var(--highlight-transition);
|
|
991
|
+
border-radius: var(--radius);
|
|
992
|
+
|
|
993
|
+
&:hover {
|
|
994
|
+
background-color: var(--clr-gray8);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
${sortableStyles}
|
|
998
|
+
`;
|
|
999
|
+
const MobileSortButton = styled(motion.button)`
|
|
1000
|
+
display: var(--mobile-sorting-display);
|
|
1001
|
+
align-items: center;
|
|
1002
|
+
color: var(--clr-gray3);
|
|
1003
|
+
margin: 0.5rem;
|
|
1004
|
+
background-color: var(--clr-gray12);
|
|
1005
|
+
border-radius: var(--radius);
|
|
1006
|
+
padding: 0.5rem;
|
|
1007
|
+
margin: -0.5rem 0 1rem auto;
|
|
1008
|
+
cursor: default;
|
|
1009
|
+
|
|
1010
|
+
> svg {
|
|
1011
|
+
margin-right: 0.5rem;
|
|
1012
|
+
font-size: 1.75rem;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
> p {
|
|
1016
|
+
margin-right: 0.25rem;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
&.sortable {
|
|
1020
|
+
cursor: pointer;
|
|
1021
|
+
&:hover {
|
|
1022
|
+
background-color: var(--clr-gray8);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
&::after {
|
|
1026
|
+
content: '';
|
|
1027
|
+
display: inline-block;
|
|
1028
|
+
width: 0.4rem;
|
|
1029
|
+
height: 0.4rem;
|
|
1030
|
+
border: 1px solid var(--clr-gray4);
|
|
1031
|
+
border-width: 0 1px 1px 0;
|
|
1032
|
+
transform: rotate(45deg);
|
|
1033
|
+
margin: 0 0.25rem;
|
|
1034
|
+
transition: transform 300ms, margin 300ms;
|
|
1035
|
+
margin-bottom: 0.25rem;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
&.open {
|
|
1039
|
+
z-index: 11;
|
|
1040
|
+
&::after {
|
|
1041
|
+
transform: rotate(225deg);
|
|
1042
|
+
margin-top: 0.1rem;
|
|
1043
|
+
margin-bottom: 0;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
`;
|
|
1048
|
+
const MobileSortTooltip = styled(motion.div)`
|
|
1049
|
+
position: absolute;
|
|
1050
|
+
top: 2.5rem;
|
|
1051
|
+
right: 0;
|
|
1052
|
+
background-color: var(--clr-white);
|
|
1053
|
+
color: var(--clr-gray3);
|
|
1054
|
+
margin: var(--table-padding);
|
|
1055
|
+
padding: 0.5rem;
|
|
1056
|
+
border-radius: var(--radius);
|
|
1057
|
+
z-index: 11;
|
|
1058
|
+
display: flex;
|
|
1059
|
+
flex-direction: column;
|
|
1060
|
+
align-items: flex-end;
|
|
1061
|
+
border: 1px solid var(--clr-gray10);
|
|
1062
|
+
overflow: auto;
|
|
1063
|
+
max-height: calc(100vh - 5rem);
|
|
1064
|
+
transform-origin: top right;
|
|
1065
|
+
${depth(8)}
|
|
1066
|
+
`;
|
|
1067
|
+
const MobileSortTooltipOption = styled.button`
|
|
1068
|
+
background-color: var(--clr-white);
|
|
1069
|
+
padding: 0.5rem;
|
|
1070
|
+
border-radius: var(--radius);
|
|
1071
|
+
color: inherit;
|
|
1072
|
+
display: flex;
|
|
1073
|
+
align-items: center;
|
|
1074
|
+
justify-content: space-between;
|
|
1075
|
+
flex-direction: row-reverse;
|
|
1076
|
+
width: 100%;
|
|
1077
|
+
|
|
1078
|
+
> p {
|
|
1079
|
+
margin: 0.17rem 0;
|
|
1080
|
+
margin-right: 0.25rem;
|
|
1081
|
+
margin-left: 1.75rem;
|
|
1082
|
+
&:not(:last-child) {
|
|
1083
|
+
margin-left: 0.5rem;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
&:hover {
|
|
1087
|
+
background-color: var(--clr-gray8);
|
|
1088
|
+
}
|
|
1089
|
+
`;
|
|
1090
|
+
const MobileSortTooltipBackdrop = styled(motion.button)`
|
|
1091
|
+
position: fixed;
|
|
1092
|
+
inset: 0;
|
|
1093
|
+
z-index: 10;
|
|
1094
|
+
width: 100%;
|
|
1095
|
+
height: 100%;
|
|
1096
|
+
background-color: transparent;
|
|
1097
|
+
cursor: default;
|
|
1098
|
+
`;
|
|
1099
|
+
const LOOK_AT_ME = "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
|
|
1100
|
+
const buildColumnTemplate = (columns = []) => {
|
|
1101
|
+
const safeColumnsWidths = columns.map(({ width }) => (width == null ? void 0 : width.replace(/\s/g, "")) || "1fr");
|
|
1102
|
+
return safeColumnsWidths.join(" ");
|
|
1103
|
+
};
|
|
1104
|
+
const validateProps = ({
|
|
1105
|
+
columns = [],
|
|
1106
|
+
children = [],
|
|
1107
|
+
mobileBreakpoint = 900
|
|
1108
|
+
}) => {
|
|
1109
|
+
if (mobileBreakpoint < MIN_TABLE_MOBILE_BREAKPOINT) {
|
|
1110
|
+
console.warn(`Table: mobileBreakpoint (${mobileBreakpoint}) is too small. The minimum of ${MIN_TABLE_MOBILE_BREAKPOINT} will be used instead.${LOOK_AT_ME}`);
|
|
1111
|
+
}
|
|
1112
|
+
const columnTemplate = buildColumnTemplate(columns);
|
|
1113
|
+
const splitTemplate = columnTemplate.split(" ");
|
|
1114
|
+
splitTemplate.map((value, idx) => ({ value, idx })).filter((width) => !CSS.supports("grid-template-columns", width.value)).forEach((width) => {
|
|
1115
|
+
const parsedWidth = width.value.replace(/"/g, '\\"');
|
|
1116
|
+
console.warn(`Table: Invalid width value "${parsedWidth}" on columnsWidths[${width.idx}].${LOOK_AT_ME}`);
|
|
1117
|
+
});
|
|
1118
|
+
const tableRowChildren = children.map((value, idx) => ({ value, idx })).filter((child) => {
|
|
1119
|
+
var _a, _b, _c, _d;
|
|
1120
|
+
return React.isValidElement(child.value) && (((_b = (_a = child.value) == null ? void 0 : _a.type) == null ? void 0 : _b.displayName) === "TableRow" || ((_d = (_c = child.value) == null ? void 0 : _c.type) == null ? void 0 : _d.displayName) === "EmptyRow");
|
|
1121
|
+
});
|
|
1122
|
+
tableRowChildren.forEach((child) => {
|
|
1123
|
+
var _a, _b, _c, _d, _e;
|
|
1124
|
+
const childChildrenLength = (_c = (_b = (_a = child.value) == null ? void 0 : _a.props) == null ? void 0 : _b.children) == null ? void 0 : _c.filter((childChild) => childChild !== void 0).length;
|
|
1125
|
+
if (React.isValidElement(child.value) && ((_e = (_d = child.value) == null ? void 0 : _d.type) == null ? void 0 : _e.displayName) !== "EmptyRow" && childChildrenLength !== columns.length) {
|
|
1126
|
+
console.warn(`Table: children[${child.idx}] length (${childChildrenLength}) should be equal to labels length (${columns.length}).${LOOK_AT_ME}`);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
const nonTableRowChildren = children.map((value, idx) => ({ value, idx })).filter((child) => !tableRowChildren.some((tableRowChild) => tableRowChild.idx === child.idx));
|
|
1130
|
+
nonTableRowChildren.forEach((child) => {
|
|
1131
|
+
console.warn(`Table: children[${child.idx}] is not a TableRow. See TableRow component.${LOOK_AT_ME}`);
|
|
1132
|
+
});
|
|
1133
|
+
};
|
|
1134
|
+
const changeSortOrder = (sortOrder) => sortOrder !== "asc" ? "asc" : "desc";
|
|
1135
|
+
const TableHeader = ({
|
|
1136
|
+
column,
|
|
1137
|
+
onSort
|
|
1138
|
+
}) => {
|
|
1139
|
+
const {
|
|
1140
|
+
sortedColumn,
|
|
1141
|
+
sortedOrder = ""
|
|
1142
|
+
} = useTable();
|
|
1143
|
+
const sortOrder = useMemo(() => sortedColumn === column.name ? sortedOrder : "", [column.name, sortedColumn, sortedOrder]);
|
|
1144
|
+
const handleSortClick = useCallback(() => {
|
|
1145
|
+
if (!column.sortable)
|
|
1146
|
+
return;
|
|
1147
|
+
onSort(changeSortOrder(sortOrder));
|
|
1148
|
+
}, [column.sortable, onSort, sortOrder]);
|
|
1149
|
+
return /* @__PURE__ */ jsx(TableHeaderWrapper, {
|
|
1150
|
+
className: ["TableHeader", sortOrder ? `sorted-${sortOrder}` : "", column.sortable ? "sortable" : ""].join(" "),
|
|
1151
|
+
onClick: handleSortClick,
|
|
1152
|
+
role: column.sortable ? "button" : void 0,
|
|
1153
|
+
children: column.label
|
|
1154
|
+
});
|
|
1155
|
+
};
|
|
1156
|
+
var DefaultContext = {
|
|
1157
|
+
color: void 0,
|
|
1158
|
+
size: void 0,
|
|
1159
|
+
className: void 0,
|
|
1160
|
+
style: void 0,
|
|
1161
|
+
attr: void 0
|
|
1162
|
+
};
|
|
1163
|
+
var IconContext = React.createContext && React.createContext(DefaultContext);
|
|
1164
|
+
var __assign = globalThis && globalThis.__assign || function() {
|
|
1165
|
+
__assign = Object.assign || function(t) {
|
|
1166
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
1167
|
+
s = arguments[i];
|
|
1168
|
+
for (var p2 in s)
|
|
1169
|
+
if (Object.prototype.hasOwnProperty.call(s, p2))
|
|
1170
|
+
t[p2] = s[p2];
|
|
1171
|
+
}
|
|
1172
|
+
return t;
|
|
1173
|
+
};
|
|
1174
|
+
return __assign.apply(this, arguments);
|
|
1175
|
+
};
|
|
1176
|
+
var __rest = globalThis && globalThis.__rest || function(s, e) {
|
|
1177
|
+
var t = {};
|
|
1178
|
+
for (var p2 in s)
|
|
1179
|
+
if (Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0)
|
|
1180
|
+
t[p2] = s[p2];
|
|
1181
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1182
|
+
for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++) {
|
|
1183
|
+
if (e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]))
|
|
1184
|
+
t[p2[i]] = s[p2[i]];
|
|
1185
|
+
}
|
|
1186
|
+
return t;
|
|
1187
|
+
};
|
|
1188
|
+
function Tree2Element(tree) {
|
|
1189
|
+
return tree && tree.map(function(node, i) {
|
|
1190
|
+
return React.createElement(node.tag, __assign({
|
|
1191
|
+
key: i
|
|
1192
|
+
}, node.attr), Tree2Element(node.child));
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
function GenIcon(data) {
|
|
1196
|
+
return function(props) {
|
|
1197
|
+
return React.createElement(IconBase, __assign({
|
|
1198
|
+
attr: __assign({}, data.attr)
|
|
1199
|
+
}, props), Tree2Element(data.child));
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
function IconBase(props) {
|
|
1203
|
+
var elem = function(conf) {
|
|
1204
|
+
var attr = props.attr, size = props.size, title = props.title, svgProps = __rest(props, ["attr", "size", "title"]);
|
|
1205
|
+
var computedSize = size || conf.size || "1em";
|
|
1206
|
+
var className;
|
|
1207
|
+
if (conf.className)
|
|
1208
|
+
className = conf.className;
|
|
1209
|
+
if (props.className)
|
|
1210
|
+
className = (className ? className + " " : "") + props.className;
|
|
1211
|
+
return React.createElement("svg", __assign({
|
|
1212
|
+
stroke: "currentColor",
|
|
1213
|
+
fill: "currentColor",
|
|
1214
|
+
strokeWidth: "0"
|
|
1215
|
+
}, conf.attr, attr, svgProps, {
|
|
1216
|
+
className,
|
|
1217
|
+
style: __assign(__assign({
|
|
1218
|
+
color: props.color || conf.color
|
|
1219
|
+
}, conf.style), props.style),
|
|
1220
|
+
height: computedSize,
|
|
1221
|
+
width: computedSize,
|
|
1222
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
1223
|
+
}), title && React.createElement("title", null, title), props.children);
|
|
1224
|
+
};
|
|
1225
|
+
return IconContext !== void 0 ? React.createElement(IconContext.Consumer, null, function(conf) {
|
|
1226
|
+
return elem(conf);
|
|
1227
|
+
}) : elem(DefaultContext);
|
|
1228
|
+
}
|
|
1229
|
+
function BiSortAlt2(props) {
|
|
1230
|
+
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M7 20h2V8h3L8 4 4 8h3zm13-4h-3V4h-2v12h-3l4 4z" } }] })(props);
|
|
1231
|
+
}
|
|
1232
|
+
function BiSortDown(props) {
|
|
1233
|
+
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "m6 20 4-4H7V4H5v12H2zm5-12h9v2h-9zm0 4h7v2h-7zm0-8h11v2H11zm0 12h5v2h-5z" } }] })(props);
|
|
1234
|
+
}
|
|
1235
|
+
function BiSortUp(props) {
|
|
1236
|
+
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24" }, "child": [{ "tag": "path", "attr": { "d": "M11 9h9v2h-9zm0 4h7v2h-7zm0-8h11v2H11zm0 12h5v2h-5zm-6 3h2V8h3L6 4 2 8h3z" } }] })(props);
|
|
1237
|
+
}
|
|
1238
|
+
const MobileSortMenu = ({
|
|
1239
|
+
onSortingChange
|
|
1240
|
+
}) => {
|
|
1241
|
+
const {
|
|
1242
|
+
columns = [],
|
|
1243
|
+
sortedOrder = "",
|
|
1244
|
+
sortedColumn = ""
|
|
1245
|
+
} = useTable();
|
|
1246
|
+
const sortableColumns = useMemo(() => {
|
|
1247
|
+
return columns.filter(({
|
|
1248
|
+
sortable
|
|
1249
|
+
}) => sortable);
|
|
1250
|
+
}, [columns]);
|
|
1251
|
+
const sortedLabel = useMemo(() => {
|
|
1252
|
+
var _a;
|
|
1253
|
+
return ((_a = columns.find(({
|
|
1254
|
+
name
|
|
1255
|
+
}) => name === sortedColumn)) == null ? void 0 : _a.label) || "";
|
|
1256
|
+
}, [columns, sortedColumn]);
|
|
1257
|
+
const isTableSortable = useMemo(() => sortableColumns.length, [sortableColumns]);
|
|
1258
|
+
const [isMenuOpen, setMenuOpen] = useState(false);
|
|
1259
|
+
const toggleMenu = useCallback(() => {
|
|
1260
|
+
if (isTableSortable) {
|
|
1261
|
+
setMenuOpen((v) => !v);
|
|
1262
|
+
}
|
|
1263
|
+
}, [isTableSortable]);
|
|
1264
|
+
useEffect(() => {
|
|
1265
|
+
if (isTableSortable) {
|
|
1266
|
+
setMenuOpen(false);
|
|
1267
|
+
}
|
|
1268
|
+
}, [isTableSortable]);
|
|
1269
|
+
const handleSortingChange = useCallback((column) => () => {
|
|
1270
|
+
setMenuOpen(false);
|
|
1271
|
+
onSortingChange(column)(changeSortOrder(sortedColumn === column.name ? sortedOrder : ""));
|
|
1272
|
+
}, [onSortingChange, sortedColumn, sortedOrder]);
|
|
1273
|
+
return isTableSortable || sortedLabel && sortedOrder ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1274
|
+
children: [/* @__PURE__ */ jsxs(MobileSortButton, {
|
|
1275
|
+
className: [isTableSortable ? "sortable" : "", isMenuOpen ? "open" : ""].join(" "),
|
|
1276
|
+
onClick: toggleMenu,
|
|
1277
|
+
disabled: !isTableSortable,
|
|
1278
|
+
type: "button",
|
|
1279
|
+
layout: true,
|
|
1280
|
+
children: [isTableSortable && (!sortedLabel || !sortedOrder) ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1281
|
+
children: [/* @__PURE__ */ jsx(BiSortAlt2, {}), /* @__PURE__ */ jsx("p", {
|
|
1282
|
+
children: "Ordenar"
|
|
1283
|
+
})]
|
|
1284
|
+
}) : null, sortedLabel && sortedOrder ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1285
|
+
children: [sortedOrder === "asc" ? /* @__PURE__ */ jsx(BiSortDown, {}) : /* @__PURE__ */ jsx(BiSortUp, {}), /* @__PURE__ */ jsx("p", {
|
|
1286
|
+
children: sortedLabel
|
|
1287
|
+
})]
|
|
1288
|
+
}) : null]
|
|
1289
|
+
}), /* @__PURE__ */ jsx(AnimatePresence, {
|
|
1290
|
+
children: isMenuOpen ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1291
|
+
children: [/* @__PURE__ */ jsx(MobileSortTooltipBackdrop, {
|
|
1292
|
+
onClick: toggleMenu,
|
|
1293
|
+
type: "button"
|
|
1294
|
+
}), /* @__PURE__ */ jsx(MobileSortTooltip, {
|
|
1295
|
+
initial: {
|
|
1296
|
+
transform: "scale(0)",
|
|
1297
|
+
opacity: 0
|
|
1298
|
+
},
|
|
1299
|
+
animate: {
|
|
1300
|
+
transform: "scale(1)",
|
|
1301
|
+
opacity: 1
|
|
1302
|
+
},
|
|
1303
|
+
exit: {
|
|
1304
|
+
transform: "scale(0)",
|
|
1305
|
+
opacity: 0
|
|
1306
|
+
},
|
|
1307
|
+
transition: {
|
|
1308
|
+
type: "tween"
|
|
1309
|
+
},
|
|
1310
|
+
children: sortableColumns.map((column) => /* @__PURE__ */ jsxs(MobileSortTooltipOption, {
|
|
1311
|
+
onClick: handleSortingChange(column),
|
|
1312
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1313
|
+
children: column.label
|
|
1314
|
+
}), column.name === sortedColumn ? sortedOrder === "desc" ? /* @__PURE__ */ jsx(BiSortDown, {
|
|
1315
|
+
size: "1.25rem"
|
|
1316
|
+
}) : /* @__PURE__ */ jsx(BiSortUp, {
|
|
1317
|
+
size: "1.25rem"
|
|
1318
|
+
}) : null]
|
|
1319
|
+
}, column.key))
|
|
1320
|
+
})]
|
|
1321
|
+
}) : null
|
|
1322
|
+
})]
|
|
1323
|
+
}) : null;
|
|
1324
|
+
};
|
|
1325
|
+
const defaultSortingHandler = (_) => void 0;
|
|
1326
|
+
const TableContext = createContext({});
|
|
1327
|
+
const Table = ({
|
|
1328
|
+
columns = [],
|
|
1329
|
+
children,
|
|
1330
|
+
customCss,
|
|
1331
|
+
sorting,
|
|
1332
|
+
onSortingChange = defaultSortingHandler,
|
|
1333
|
+
mobileBreakpoint = 900
|
|
1334
|
+
}) => {
|
|
1335
|
+
const handleSortChange = useCallback((column) => (order) => {
|
|
1336
|
+
if (!(column == null ? void 0 : column.sortable))
|
|
1337
|
+
return;
|
|
1338
|
+
onSortingChange({
|
|
1339
|
+
column: column.name,
|
|
1340
|
+
order
|
|
1341
|
+
});
|
|
1342
|
+
}, [onSortingChange]);
|
|
1343
|
+
useEffect(() => {
|
|
1344
|
+
const effectiveChildren = children.flat().filter(Boolean);
|
|
1345
|
+
validateProps({
|
|
1346
|
+
columns,
|
|
1347
|
+
children: effectiveChildren,
|
|
1348
|
+
mobileBreakpoint
|
|
1349
|
+
});
|
|
1350
|
+
}, [children, columns, mobileBreakpoint]);
|
|
1351
|
+
const columnTemplate = useMemo(() => buildColumnTemplate(columns), [columns]);
|
|
1352
|
+
const indexedColumns = useMemo(() => {
|
|
1353
|
+
return columns.map((column, index) => __spreadProps(__spreadValues({}, column), {
|
|
1354
|
+
index,
|
|
1355
|
+
key: `${column.name}-${index}`
|
|
1356
|
+
}));
|
|
1357
|
+
}, [columns]);
|
|
1358
|
+
return /* @__PURE__ */ jsx(TableContext.Provider, {
|
|
1359
|
+
value: {
|
|
1360
|
+
columns: indexedColumns,
|
|
1361
|
+
sortedOrder: sorting == null ? void 0 : sorting.order,
|
|
1362
|
+
sortedColumn: sorting == null ? void 0 : sorting.column
|
|
1363
|
+
},
|
|
1364
|
+
children: /* @__PURE__ */ jsxs(TableWrapper, {
|
|
1365
|
+
columnTemplate,
|
|
1366
|
+
customCss,
|
|
1367
|
+
mobileBreakpoint,
|
|
1368
|
+
layout: true,
|
|
1369
|
+
children: [/* @__PURE__ */ jsx(MobileSortMenu, {
|
|
1370
|
+
onSortingChange: handleSortChange
|
|
1371
|
+
}), /* @__PURE__ */ jsx(TableHeaderRow, {
|
|
1372
|
+
layout: true,
|
|
1373
|
+
children: indexedColumns.map((column) => /* @__PURE__ */ jsx(TableHeader, {
|
|
1374
|
+
column,
|
|
1375
|
+
onSort: handleSortChange(column)
|
|
1376
|
+
}, column.key))
|
|
1377
|
+
}), /* @__PURE__ */ jsx(TableBody, {
|
|
1378
|
+
children: children.map((child, idx) => /* @__PURE__ */ jsx(Fragment$1, {
|
|
1379
|
+
children: child
|
|
1380
|
+
}, idx))
|
|
1381
|
+
})]
|
|
1382
|
+
})
|
|
1383
|
+
});
|
|
1384
|
+
};
|
|
1385
|
+
function useTable() {
|
|
1386
|
+
const context = useContext(TableContext);
|
|
1387
|
+
if (!context) {
|
|
1388
|
+
throw new Error("useTable and TableRow must be used within a Table");
|
|
1389
|
+
}
|
|
1390
|
+
return context;
|
|
1391
|
+
}
|
|
1392
|
+
const TableRow = (_c) => {
|
|
1393
|
+
var _d = _c, {
|
|
1394
|
+
children,
|
|
1395
|
+
className,
|
|
1396
|
+
annex
|
|
1397
|
+
} = _d, other = __objRest(_d, [
|
|
1398
|
+
"children",
|
|
1399
|
+
"className",
|
|
1400
|
+
"annex"
|
|
1401
|
+
]);
|
|
1402
|
+
const {
|
|
1403
|
+
columns = []
|
|
1404
|
+
} = useTable();
|
|
1405
|
+
const rowId = useMemo(() => `table-row-${Math.random().toString(16).slice(2)}`, []);
|
|
1406
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
1407
|
+
children: /* @__PURE__ */ jsxs(TableRowContainer, __spreadProps(__spreadValues({
|
|
1408
|
+
layout: true,
|
|
1409
|
+
className
|
|
1410
|
+
}, other), {
|
|
1411
|
+
children: [/* @__PURE__ */ jsx(TableRowWrapper, {
|
|
1412
|
+
id: rowId,
|
|
1413
|
+
layoutId: rowId,
|
|
1414
|
+
className: "TableRow",
|
|
1415
|
+
children: columns.map((column) => /* @__PURE__ */ jsxs(TableCellWrapper, {
|
|
1416
|
+
className: `TableCellWrapper column-${column.index}`,
|
|
1417
|
+
children: [/* @__PURE__ */ jsx(TableCellRef, {
|
|
1418
|
+
className: `TableCellRef column-${column.index}`,
|
|
1419
|
+
children: column.label
|
|
1420
|
+
}), /* @__PURE__ */ jsx(TableCell, {
|
|
1421
|
+
className: `TableCell column-${column.index}`,
|
|
1422
|
+
children: children[column.index] || null
|
|
1423
|
+
})]
|
|
1424
|
+
}, column.key))
|
|
1425
|
+
}), /* @__PURE__ */ jsx(AnimatePresence, {
|
|
1426
|
+
children: annex ? /* @__PURE__ */ jsx(TableRowAnnexWrapper, {
|
|
1427
|
+
layoutId: `${rowId}-annex`,
|
|
1428
|
+
initial: {
|
|
1429
|
+
opacity: 0
|
|
1430
|
+
},
|
|
1431
|
+
animate: {
|
|
1432
|
+
opacity: 1
|
|
1433
|
+
},
|
|
1434
|
+
exit: {
|
|
1435
|
+
opacity: 0,
|
|
1436
|
+
height: 0,
|
|
1437
|
+
padding: 0,
|
|
1438
|
+
margin: 0,
|
|
1439
|
+
overflow: "hidden"
|
|
1440
|
+
},
|
|
1441
|
+
transition: {
|
|
1442
|
+
type: "tween"
|
|
1443
|
+
},
|
|
1444
|
+
"aria-details": rowId,
|
|
1445
|
+
className: "TableRowAnnex",
|
|
1446
|
+
children: annex
|
|
1447
|
+
}, "annex") : null
|
|
1448
|
+
})]
|
|
1449
|
+
}))
|
|
1450
|
+
});
|
|
1451
|
+
};
|
|
1452
|
+
TableRow.displayName = "TableRow";
|
|
1453
|
+
const EmptyRow = () => {
|
|
1454
|
+
const {
|
|
1455
|
+
columns = []
|
|
1456
|
+
} = useTable();
|
|
1457
|
+
return /* @__PURE__ */ jsx(TableRow, {
|
|
1458
|
+
className: "empty_row",
|
|
1459
|
+
children: Array(columns.length).fill(null)
|
|
1460
|
+
});
|
|
1461
|
+
};
|
|
1462
|
+
EmptyRow.displayName = "EmptyRow";
|
|
1463
|
+
export { Button, EmptyRow, PreventScroll, Spinner, Table, TableRow, binamikCssReset, binamikGlobalStyles, binamikTheme, depth };
|