@digital-ai/dot-components 4.6.0 → 4.8.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/index.esm.js
CHANGED
|
@@ -8561,14 +8561,26 @@ const defaultColumns = {
|
|
|
8561
8561
|
xl: 12,
|
|
8562
8562
|
xxl: 12
|
|
8563
8563
|
};
|
|
8564
|
+
// Ensures that the children returned is a list of children
|
|
8565
|
+
const ensureChildrenList = children => {
|
|
8566
|
+
if (children instanceof Array) {
|
|
8567
|
+
return children;
|
|
8568
|
+
}
|
|
8569
|
+
return [children];
|
|
8570
|
+
};
|
|
8564
8571
|
const Grid = ({
|
|
8565
8572
|
className,
|
|
8566
|
-
children
|
|
8573
|
+
children,
|
|
8574
|
+
isLoading
|
|
8567
8575
|
}) => {
|
|
8568
8576
|
const rootClasses = useStylesWithRootClass(rootClassName$I, className);
|
|
8569
|
-
return
|
|
8577
|
+
return jsxs("div", {
|
|
8570
8578
|
className: rootClasses,
|
|
8571
|
-
children: children
|
|
8579
|
+
children: [children, isLoading && jsx(DotProgress, {
|
|
8580
|
+
className: "loading-more-data",
|
|
8581
|
+
color: "inherit",
|
|
8582
|
+
size: 20
|
|
8583
|
+
})]
|
|
8572
8584
|
});
|
|
8573
8585
|
};
|
|
8574
8586
|
const StyledGrid = styled(Grid)`
|
|
@@ -8592,10 +8604,75 @@ const StyledGrid = styled(Grid)`
|
|
|
8592
8604
|
${gap && `grid-gap: ${gap};`}
|
|
8593
8605
|
${width && `width: ${width};`}
|
|
8594
8606
|
${height && `height: ${height};`}
|
|
8607
|
+
.loading-more-data {
|
|
8608
|
+
margin: auto;
|
|
8609
|
+
}
|
|
8595
8610
|
`}
|
|
8596
8611
|
`;
|
|
8597
|
-
const CssGrid =
|
|
8598
|
-
|
|
8612
|
+
const CssGrid = _a => {
|
|
8613
|
+
var {
|
|
8614
|
+
children,
|
|
8615
|
+
loadMoreData,
|
|
8616
|
+
onError
|
|
8617
|
+
} = _a,
|
|
8618
|
+
gridArgs = __rest(_a, ["children", "loadMoreData", "onError"]);
|
|
8619
|
+
const [page, setPage] = useState(0);
|
|
8620
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8621
|
+
const [isDone, setIsDone] = useState(false);
|
|
8622
|
+
const [gridItems, setGridItems] = useState(ensureChildrenList(children));
|
|
8623
|
+
const [lastElement, setLastElement] = useState(null);
|
|
8624
|
+
useEffect(() => {
|
|
8625
|
+
setGridItems(ensureChildrenList(children));
|
|
8626
|
+
}, [children]);
|
|
8627
|
+
const fetchData = useCallback(nextPage => __awaiter(void 0, void 0, void 0, function* () {
|
|
8628
|
+
setIsLoading(true);
|
|
8629
|
+
try {
|
|
8630
|
+
const newItems = yield loadMoreData(nextPage);
|
|
8631
|
+
if (newItems && newItems.length > 0) {
|
|
8632
|
+
setGridItems(prevItems => [...prevItems, ...newItems]);
|
|
8633
|
+
} else {
|
|
8634
|
+
setIsDone(true);
|
|
8635
|
+
}
|
|
8636
|
+
} catch (error) {
|
|
8637
|
+
if (onError) {
|
|
8638
|
+
onError(error);
|
|
8639
|
+
}
|
|
8640
|
+
} finally {
|
|
8641
|
+
setIsLoading(false);
|
|
8642
|
+
}
|
|
8643
|
+
}), [loadMoreData, onError]);
|
|
8644
|
+
const observer = useRef(new IntersectionObserver(entries => {
|
|
8645
|
+
const first = entries[0];
|
|
8646
|
+
if (first.isIntersecting) {
|
|
8647
|
+
setPage(prevNum => prevNum + 1);
|
|
8648
|
+
}
|
|
8649
|
+
}));
|
|
8650
|
+
useEffect(() => {
|
|
8651
|
+
if (loadMoreData && !isDone && page) {
|
|
8652
|
+
fetchData(page);
|
|
8653
|
+
}
|
|
8654
|
+
}, [page, loadMoreData, isDone]);
|
|
8655
|
+
useEffect(() => {
|
|
8656
|
+
const currentElement = lastElement;
|
|
8657
|
+
const currentObserver = observer.current;
|
|
8658
|
+
if (currentElement) {
|
|
8659
|
+
currentObserver.observe(currentElement);
|
|
8660
|
+
}
|
|
8661
|
+
return () => {
|
|
8662
|
+
if (currentElement) {
|
|
8663
|
+
currentObserver.unobserve(currentElement);
|
|
8664
|
+
}
|
|
8665
|
+
};
|
|
8666
|
+
}, [lastElement]);
|
|
8667
|
+
// Adds the lastElement ref to the last Element of the grid
|
|
8668
|
+
const gridItemsWithLastElement = useMemo(() => [...gridItems.slice(0, -1), jsx("div", {
|
|
8669
|
+
ref: setLastElement,
|
|
8670
|
+
children: gridItems[gridItems.length - 1]
|
|
8671
|
+
}, "last-grid-item")], [gridItems]);
|
|
8672
|
+
return jsx(StyledGrid, Object.assign({}, gridArgs, {
|
|
8673
|
+
isLoading: isLoading,
|
|
8674
|
+
children: gridItemsWithLastElement
|
|
8675
|
+
}));
|
|
8599
8676
|
};
|
|
8600
8677
|
|
|
8601
8678
|
const breakpointsGetter = (value, theme, breakpoint) => {
|
|
@@ -12714,6 +12791,12 @@ function DotDashboardHeader({
|
|
|
12714
12791
|
}
|
|
12715
12792
|
|
|
12716
12793
|
const rootClassName$C = 'dot-empty-state';
|
|
12794
|
+
const emptyStateImageSizing = {
|
|
12795
|
+
xsmall: 9,
|
|
12796
|
+
dense: 15,
|
|
12797
|
+
normal: 31,
|
|
12798
|
+
large: 49
|
|
12799
|
+
};
|
|
12717
12800
|
const StyledEmptyState = styled.div`
|
|
12718
12801
|
${({
|
|
12719
12802
|
theme
|
|
@@ -12729,8 +12812,10 @@ const StyledEmptyState = styled.div`
|
|
|
12729
12812
|
}
|
|
12730
12813
|
|
|
12731
12814
|
.empty-state-image {
|
|
12815
|
+
display: inline-flex;
|
|
12816
|
+
justify-content: center;
|
|
12732
12817
|
min-height: ${theme.spacing(10)};
|
|
12733
|
-
margin-bottom: ${theme.spacing(
|
|
12818
|
+
margin-bottom: ${theme.spacing(3)};
|
|
12734
12819
|
}
|
|
12735
12820
|
|
|
12736
12821
|
h2 {
|
|
@@ -12744,6 +12829,34 @@ const StyledEmptyState = styled.div`
|
|
|
12744
12829
|
.dot-button {
|
|
12745
12830
|
margin-top: ${theme.spacing(4)};
|
|
12746
12831
|
}
|
|
12832
|
+
|
|
12833
|
+
&.xsmall {
|
|
12834
|
+
.empty-state-image {
|
|
12835
|
+
height: ${theme.spacing(emptyStateImageSizing.xsmall)};
|
|
12836
|
+
width: ${theme.spacing(emptyStateImageSizing.xsmall)};
|
|
12837
|
+
}
|
|
12838
|
+
}
|
|
12839
|
+
|
|
12840
|
+
&.dense {
|
|
12841
|
+
.empty-state-image {
|
|
12842
|
+
height: ${theme.spacing(emptyStateImageSizing.dense)};
|
|
12843
|
+
width: ${theme.spacing(emptyStateImageSizing.dense)};
|
|
12844
|
+
}
|
|
12845
|
+
}
|
|
12846
|
+
|
|
12847
|
+
&.normal {
|
|
12848
|
+
.empty-state-image {
|
|
12849
|
+
height: ${theme.spacing(emptyStateImageSizing.normal)};
|
|
12850
|
+
width: ${theme.spacing(emptyStateImageSizing.normal)};
|
|
12851
|
+
}
|
|
12852
|
+
}
|
|
12853
|
+
|
|
12854
|
+
&.large {
|
|
12855
|
+
.empty-state-image {
|
|
12856
|
+
height: ${theme.spacing(emptyStateImageSizing.large)};
|
|
12857
|
+
width: ${theme.spacing(emptyStateImageSizing.large)};
|
|
12858
|
+
}
|
|
12859
|
+
}
|
|
12747
12860
|
}
|
|
12748
12861
|
`}
|
|
12749
12862
|
`;
|
|
@@ -12798,13 +12911,14 @@ const DotEmptyState = ({
|
|
|
12798
12911
|
illustrationId,
|
|
12799
12912
|
imageAltText,
|
|
12800
12913
|
imageSrc,
|
|
12914
|
+
size = 'normal',
|
|
12801
12915
|
subtitle,
|
|
12802
12916
|
title
|
|
12803
12917
|
}) => {
|
|
12804
12918
|
const rootClasses = useStylesWithRootClass(rootClassName$C, className);
|
|
12805
12919
|
return jsxs(StyledEmptyState, {
|
|
12806
12920
|
"aria-label": ariaLabel,
|
|
12807
|
-
className: rootClasses
|
|
12921
|
+
className: `${rootClasses} ${size}`,
|
|
12808
12922
|
"data-testid": dataTestId,
|
|
12809
12923
|
children: [jsxs("div", {
|
|
12810
12924
|
className: "empty-state-image-container",
|
package/package.json
CHANGED
|
@@ -23,6 +23,10 @@ export interface CssGridProps extends CommonProps {
|
|
|
23
23
|
gridTemplateAreas?: string;
|
|
24
24
|
/** Height of the grid */
|
|
25
25
|
height?: string;
|
|
26
|
+
/** Function called to load more items when the end of the grid is reached. Should return an array of ReactNodes. */
|
|
27
|
+
loadMoreData?: (page: number) => Promise<ReactNode[]>;
|
|
28
|
+
/** Error handler function for handling any errors that might come from the loadMoreData function */
|
|
29
|
+
onError?: (error: Error) => void;
|
|
26
30
|
/** Row, overrides columnsBreakpoints */
|
|
27
31
|
rowGap?: GridOptions;
|
|
28
32
|
/** Row, configuration */
|
|
@@ -30,9 +34,13 @@ export interface CssGridProps extends CommonProps {
|
|
|
30
34
|
/** Width of the grid */
|
|
31
35
|
width?: string;
|
|
32
36
|
}
|
|
37
|
+
interface InternalGridProps extends CssGridProps {
|
|
38
|
+
isLoading: boolean;
|
|
39
|
+
}
|
|
33
40
|
export declare const rootClassName = "dot-grid";
|
|
34
41
|
export declare const defaultGutter: GridOptions;
|
|
35
42
|
export declare const defaultColumns: GridOptions;
|
|
36
|
-
export declare const Grid: ({ className, children }:
|
|
37
|
-
export declare const StyledGrid: import("styled-components").StyledComponent<({ className, children }:
|
|
38
|
-
export declare const CssGrid: (
|
|
43
|
+
export declare const Grid: ({ className, children, isLoading }: InternalGridProps) => import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
export declare const StyledGrid: import("styled-components").StyledComponent<({ className, children, isLoading }: InternalGridProps) => import("react/jsx-runtime").JSX.Element, any, {}, never>;
|
|
45
|
+
export declare const CssGrid: ({ children, loadMoreData, onError, ...gridArgs }: CssGridProps) => import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ButtonProps } from '../button';
|
|
2
2
|
import { CommonProps } from '../CommonProps';
|
|
3
|
+
export type EmptyStateSize = 'xsmall' | 'dense' | 'normal' | 'large';
|
|
3
4
|
export interface EmptyStateProps extends CommonProps {
|
|
4
5
|
/** primary button properties */
|
|
5
6
|
buttonProps?: ButtonProps;
|
|
@@ -9,9 +10,11 @@ export interface EmptyStateProps extends CommonProps {
|
|
|
9
10
|
imageAltText?: string;
|
|
10
11
|
/** location of image */
|
|
11
12
|
imageSrc?: string;
|
|
13
|
+
/** sizing of the empty state (illustration, img) */
|
|
14
|
+
size?: EmptyStateSize;
|
|
12
15
|
/** subtitle text displayed */
|
|
13
16
|
subtitle?: string;
|
|
14
17
|
/** title text displayed */
|
|
15
18
|
title: string;
|
|
16
19
|
}
|
|
17
|
-
export declare const DotEmptyState: ({ ariaLabel, buttonProps, className, "data-testid": dataTestId, illustrationId, imageAltText, imageSrc, subtitle, title, }: EmptyStateProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare const DotEmptyState: ({ ariaLabel, buttonProps, className, "data-testid": dataTestId, illustrationId, imageAltText, imageSrc, size, subtitle, title, }: EmptyStateProps) => import("react/jsx-runtime").JSX.Element;
|