musae 0.2.1 → 0.2.3
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/components/avatar/avatar.d.ts +0 -2
- package/dist/components/avatar/avatar.js +6 -5
- package/dist/components/avatar/group.js +1 -1
- package/dist/components/avatar/types.d.ts +3 -9
- package/dist/components/calendar/hooks.js +4 -4
- package/dist/components/checkbox/checkbox.js +3 -2
- package/dist/components/collapse/collapse.d.ts +4 -0
- package/dist/components/collapse/collapse.js +97 -0
- package/dist/components/collapse/context.d.ts +7 -0
- package/dist/components/collapse/context.js +12 -0
- package/dist/components/collapse/hooks.d.ts +12 -0
- package/dist/components/collapse/hooks.js +43 -0
- package/dist/components/collapse/index.d.ts +2 -0
- package/dist/components/collapse/item.d.ts +4 -0
- package/dist/components/collapse/item.js +144 -0
- package/dist/components/collapse/types.d.ts +87 -0
- package/dist/components/dialog/popup.js +3 -3
- package/dist/components/drawer/popup.js +15 -15
- package/dist/components/icon/icon.js +1 -1
- package/dist/components/icon/icons/index.js +1 -0
- package/dist/components/icon/icons/navigation/index.d.ts +2 -1
- package/dist/components/icon/icons/navigation/index.js +1 -0
- package/dist/components/icon/icons/navigation/unfold-more.d.ts +3 -0
- package/dist/components/icon/icons/navigation/unfold-more.js +10 -0
- package/dist/components/image/preview/operations.js +3 -3
- package/dist/components/layout/header.js +1 -1
- package/dist/components/loading/loading.d.ts +1 -1
- package/dist/components/loading/loading.js +69 -4
- package/dist/components/loading/types.d.ts +13 -0
- package/dist/components/notification/holder.js +12 -12
- package/dist/components/notification/notification.js +1 -1
- package/dist/components/popper/dropdown.js +2 -2
- package/dist/components/rate/star.js +13 -15
- package/dist/components/ripple/hooks.js +4 -1
- package/dist/components/switch/switch.js +4 -4
- package/dist/components/table/body.js +35 -3
- package/dist/components/table/context.d.ts +6 -0
- package/dist/components/table/context.js +10 -2
- package/dist/components/table/header/cell.d.ts +3 -0
- package/dist/components/table/header/cell.js +129 -0
- package/dist/components/table/{header.d.ts → header/header.d.ts} +1 -1
- package/dist/components/table/{header.js → header/header.js} +38 -11
- package/dist/components/table/hooks.d.ts +8 -21
- package/dist/components/table/hooks.js +36 -58
- package/dist/components/table/table.d.ts +1 -1
- package/dist/components/table/table.js +12 -6
- package/dist/components/table/types.d.ts +72 -4
- package/dist/components/tour/tour.js +1 -1
- package/dist/components/waterfall/hooks.d.ts +1 -2
- package/dist/components/waterfall/hooks.js +2 -8
- package/dist/components/waterfall/waterfall.js +9 -5
- package/dist/components/watermark/types.d.ts +1 -1
- package/dist/components/watermark/watermark.js +1 -1
- package/dist/hooks/use-class-names.d.ts +15 -0
- package/dist/hooks/use-expand-effect.d.ts +1 -1
- package/dist/hooks/use-expand-effect.js +12 -8
- package/dist/hooks/use-image.d.ts +11 -0
- package/dist/hooks/use-image.js +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stylex.css +31 -17
- package/dist/utils/class-name.d.ts +65 -3
- package/dist/utils/class-name.js +39 -5
- package/dist/utils/styles.d.ts +1 -1
- package/package.json +6 -6
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useTable
|
|
2
|
+
import { useTable } from '../context.js';
|
|
3
3
|
import { flexRender } from '@tanstack/react-table';
|
|
4
|
-
import { props } from '
|
|
5
|
-
import { useTheme } from '
|
|
4
|
+
import { props } from '../../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
5
|
+
import { useTheme } from '../../theme/hooks.js';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
|
-
import { ColorToken } from '
|
|
8
|
-
import { typography } from '
|
|
7
|
+
import { ColorToken } from '../../../utils/colors.js';
|
|
8
|
+
import { typography } from '../../theme/theme.js';
|
|
9
9
|
|
|
10
10
|
const styles = {
|
|
11
11
|
cell: props => [{
|
|
12
12
|
backgroundColor: "musae-q1mx2j",
|
|
13
13
|
textAlign: "musae-1yc453h",
|
|
14
14
|
position: "musae-1n2onr6",
|
|
15
|
+
paddingInline: "musae-iujutg",
|
|
16
|
+
paddingStart: null,
|
|
17
|
+
paddingLeft: null,
|
|
18
|
+
paddingEnd: null,
|
|
19
|
+
paddingRight: null,
|
|
20
|
+
paddingBlock: "musae-avjae4",
|
|
21
|
+
paddingTop: null,
|
|
22
|
+
paddingBottom: null,
|
|
23
|
+
borderColor: "musae-eqt46j",
|
|
24
|
+
borderInlineColor: null,
|
|
25
|
+
borderInlineStartColor: null,
|
|
26
|
+
borderLeftColor: null,
|
|
27
|
+
borderInlineEndColor: null,
|
|
28
|
+
borderRightColor: null,
|
|
29
|
+
borderBlockColor: null,
|
|
30
|
+
borderTopColor: null,
|
|
31
|
+
borderBottomColor: null,
|
|
32
|
+
borderStyle: "musae-1y0btm7",
|
|
33
|
+
borderInlineStyle: null,
|
|
34
|
+
borderInlineStartStyle: null,
|
|
35
|
+
borderLeftStyle: null,
|
|
36
|
+
borderInlineEndStyle: null,
|
|
37
|
+
borderRightStyle: null,
|
|
38
|
+
borderBlockStyle: null,
|
|
39
|
+
borderTopStyle: null,
|
|
40
|
+
borderBottomStyle: null,
|
|
41
|
+
borderBottomWidth: "musae-lntmim",
|
|
15
42
|
$$css: true
|
|
16
43
|
}, {
|
|
17
|
-
"--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial"
|
|
44
|
+
"--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial",
|
|
45
|
+
"--borderColor": props.borderColor != null ? props.borderColor : "initial"
|
|
18
46
|
}],
|
|
19
47
|
unbordered: props => [{
|
|
20
48
|
":not(:last-of-type)::after_content": "musae-x7gz8e",
|
|
@@ -24,7 +52,7 @@ const styles = {
|
|
|
24
52
|
":not(:last-of-type)::after_height": "musae-1su0kt9",
|
|
25
53
|
":not(:last-of-type)::after_backgroundColor": "musae-9cqmhv",
|
|
26
54
|
":not(:last-of-type)::after_transform": "musae-1kmnipp",
|
|
27
|
-
":not(:last-of-type)::after_insetInlineEnd": "musae-
|
|
55
|
+
":not(:last-of-type)::after_insetInlineEnd": "musae-1sd0t5p",
|
|
28
56
|
":not(:last-of-type)::after_left": null,
|
|
29
57
|
":not(:last-of-type)::after_right": null,
|
|
30
58
|
$$css: true
|
|
@@ -53,11 +81,10 @@ const Header = props$1 => {
|
|
|
53
81
|
if (!table) return null;
|
|
54
82
|
const headerGroups = table.getHeaderGroups();
|
|
55
83
|
const styled = props(styles.cell({
|
|
56
|
-
backgroundColor: theme.colors[ColorToken.Surface]
|
|
57
|
-
|
|
84
|
+
backgroundColor: theme.colors[ColorToken.Surface],
|
|
85
|
+
borderColor: theme.colors[ColorToken.OutlineVariant]
|
|
86
|
+
}), typography.label.small, bordered && styles.bordered, !bordered && styles.unbordered({
|
|
58
87
|
backgroundColor: theme.colors[ColorToken.OutlineVariant]
|
|
59
|
-
}), styles$1.cell({
|
|
60
|
-
outlineColor: theme.colors[ColorToken.OutlineVariant]
|
|
61
88
|
}));
|
|
62
89
|
return React.createElement("thead", {
|
|
63
90
|
className: props$1.className
|
|
@@ -1,33 +1,20 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { ContextValue,
|
|
3
|
-
export declare const styles: Readonly<{
|
|
4
|
-
readonly cell: (props: {
|
|
5
|
-
outlineColor: CSSProperties["borderColor"];
|
|
6
|
-
}) => readonly [Readonly<{
|
|
7
|
-
paddingInline: import("@stylexjs/stylex/lib/StyleXTypes").StyleXClassNameFor<"paddingInline", string>;
|
|
8
|
-
paddingBlock: import("@stylexjs/stylex/lib/StyleXTypes").StyleXClassNameFor<"paddingBlock", string>;
|
|
9
|
-
borderColor: import("@stylexjs/stylex/lib/StyleXTypes").StyleXClassNameFor<"borderColor", import("csstype").Property.BorderColor | undefined>;
|
|
10
|
-
borderStyle: import("@stylexjs/stylex/lib/StyleXTypes").StyleXClassNameFor<"borderStyle", "solid">;
|
|
11
|
-
borderBottomWidth: import("@stylexjs/stylex/lib/StyleXTypes").StyleXClassNameFor<"borderBottomWidth", string>;
|
|
12
|
-
}>, typeof import("@stylexjs/stylex/lib/StyleXTypes").StyleXInlineStylesTag];
|
|
13
|
-
}>;
|
|
1
|
+
import { type ColumnDef } from "@tanstack/react-table";
|
|
2
|
+
import type { Column, ContextValue, SortDescriptor } from "./types";
|
|
14
3
|
/**
|
|
15
4
|
* @description
|
|
16
5
|
* use columns
|
|
17
6
|
*/
|
|
18
|
-
export declare const useColumns: <T>(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @description
|
|
22
|
-
* use table context hook
|
|
23
|
-
*/
|
|
24
|
-
export declare const useTable: <T>() => ContextValue<T>;
|
|
7
|
+
export declare const useColumns: <T>({ columns }: {
|
|
8
|
+
columns: Column<T>[];
|
|
9
|
+
}) => ColumnDef<T, any>[];
|
|
25
10
|
/**
|
|
26
11
|
* @author murukal
|
|
27
12
|
* @description
|
|
28
13
|
* for context value
|
|
29
14
|
*/
|
|
30
|
-
export declare const useContextValue: <T>({ table: _table, bordered, }: {
|
|
15
|
+
export declare const useContextValue: <T>({ table: _table, bordered, sortDescriptor: _sortDescriptor, onSortChange: _onSortChange, }: {
|
|
31
16
|
table: ContextValue<T>["table"];
|
|
32
17
|
bordered: boolean;
|
|
18
|
+
sortDescriptor?: SortDescriptor;
|
|
19
|
+
onSortChange?: (sortDescriptor: SortDescriptor) => void;
|
|
33
20
|
}) => ContextValue<unknown>;
|
|
@@ -1,72 +1,50 @@
|
|
|
1
1
|
import { createColumnHelper } from '@tanstack/react-table';
|
|
2
|
-
import { useRef, useMemo,
|
|
3
|
-
import
|
|
2
|
+
import { useRef, useMemo, createElement } from 'react';
|
|
3
|
+
import Cell from './header/cell.js';
|
|
4
|
+
import { useControlledState, useEvent } from '@aiszlab/relax';
|
|
4
5
|
|
|
5
|
-
const styles = {
|
|
6
|
-
cell: props => [{
|
|
7
|
-
paddingInline: "musae-iujutg",
|
|
8
|
-
paddingStart: null,
|
|
9
|
-
paddingLeft: null,
|
|
10
|
-
paddingEnd: null,
|
|
11
|
-
paddingRight: null,
|
|
12
|
-
paddingBlock: "musae-avjae4",
|
|
13
|
-
paddingTop: null,
|
|
14
|
-
paddingBottom: null,
|
|
15
|
-
borderColor: "musae-eqt46j",
|
|
16
|
-
borderInlineColor: null,
|
|
17
|
-
borderInlineStartColor: null,
|
|
18
|
-
borderLeftColor: null,
|
|
19
|
-
borderInlineEndColor: null,
|
|
20
|
-
borderRightColor: null,
|
|
21
|
-
borderBlockColor: null,
|
|
22
|
-
borderTopColor: null,
|
|
23
|
-
borderBottomColor: null,
|
|
24
|
-
borderStyle: "musae-1y0btm7",
|
|
25
|
-
borderInlineStyle: null,
|
|
26
|
-
borderInlineStartStyle: null,
|
|
27
|
-
borderLeftStyle: null,
|
|
28
|
-
borderInlineEndStyle: null,
|
|
29
|
-
borderRightStyle: null,
|
|
30
|
-
borderBlockStyle: null,
|
|
31
|
-
borderTopStyle: null,
|
|
32
|
-
borderBottomStyle: null,
|
|
33
|
-
borderBottomWidth: "musae-lntmim",
|
|
34
|
-
$$css: true
|
|
35
|
-
}, {
|
|
36
|
-
"--borderColor": props.outlineColor != null ? props.outlineColor : "initial"
|
|
37
|
-
}]
|
|
38
|
-
};
|
|
39
6
|
/**
|
|
40
7
|
* @description
|
|
41
8
|
* use columns
|
|
42
9
|
*/
|
|
43
|
-
const useColumns = (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
10
|
+
const useColumns = ({ columns }) => {
|
|
11
|
+
const helper = useRef(createColumnHelper());
|
|
12
|
+
return useMemo(() => {
|
|
13
|
+
return columns.map(({ key, render, title, sortable = false, sortDirections = ["ascending", "descending"] }) => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return helper.current.accessor(key, {
|
|
16
|
+
header: createElement(Cell, { children: title, sortable, value: key, sortDirections }),
|
|
17
|
+
cell: (_context) => {
|
|
18
|
+
const value = _context.getValue();
|
|
19
|
+
if (!render) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
return render(value, _context.row.original, _context.row.index);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}, [columns]);
|
|
56
27
|
};
|
|
57
28
|
/**
|
|
58
29
|
* @author murukal
|
|
59
30
|
* @description
|
|
60
31
|
* for context value
|
|
61
32
|
*/
|
|
62
|
-
const useContextValue = ({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
const useContextValue = ({ table: _table, bordered, sortDescriptor: _sortDescriptor, onSortChange: _onSortChange, }) => {
|
|
34
|
+
const [sortDescriptor, setSortDescriptor] = useControlledState(_sortDescriptor);
|
|
35
|
+
// sort change handler
|
|
36
|
+
const onSortChange = useEvent((sortDescriptor) => {
|
|
37
|
+
setSortDescriptor(sortDescriptor);
|
|
38
|
+
_onSortChange?.(sortDescriptor);
|
|
39
|
+
});
|
|
40
|
+
return useMemo(() => ({
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
table: _table,
|
|
43
|
+
bordered,
|
|
44
|
+
// sort descriptor
|
|
45
|
+
sortDescriptor,
|
|
46
|
+
onSortChange,
|
|
47
|
+
}), [_table, bordered, sortDescriptor, onSortChange]);
|
|
70
48
|
};
|
|
71
49
|
|
|
72
|
-
export {
|
|
50
|
+
export { useColumns, useContextValue };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { TableProps } from "./types";
|
|
3
|
-
declare const Table: <T>({ bordered, dataSource,
|
|
3
|
+
declare const Table: <T>({ bordered, dataSource, columns: _columns, sortDescriptor, onSortChange, }: TableProps<T>) => React.JSX.Element;
|
|
4
4
|
export default Table;
|
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import { useReactTable, getCoreRowModel } from '@tanstack/react-table';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useColumns, useContextValue } from './hooks.js';
|
|
4
|
-
import Header from './header.js';
|
|
4
|
+
import Header from './header/header.js';
|
|
5
5
|
import Context from './context.js';
|
|
6
6
|
import Body from './body.js';
|
|
7
7
|
|
|
8
8
|
const Table = ({
|
|
9
9
|
bordered = false,
|
|
10
10
|
dataSource = [],
|
|
11
|
-
|
|
11
|
+
columns: _columns = [],
|
|
12
|
+
sortDescriptor,
|
|
13
|
+
onSortChange
|
|
12
14
|
}) => {
|
|
13
|
-
const columns = useColumns(
|
|
15
|
+
const columns = useColumns({
|
|
16
|
+
columns: _columns
|
|
17
|
+
});
|
|
14
18
|
const table = useReactTable({
|
|
15
|
-
columns
|
|
19
|
+
columns,
|
|
16
20
|
data: dataSource,
|
|
17
21
|
getCoreRowModel: getCoreRowModel()
|
|
18
22
|
});
|
|
19
23
|
const contextValue = useContextValue({
|
|
20
24
|
table,
|
|
21
|
-
bordered
|
|
25
|
+
bordered,
|
|
26
|
+
sortDescriptor,
|
|
27
|
+
onSortChange
|
|
22
28
|
});
|
|
23
29
|
return React.createElement(Context.Provider, {
|
|
24
30
|
value: contextValue
|
|
25
31
|
}, React.createElement("table", {
|
|
26
32
|
...{
|
|
27
|
-
className: "musae-
|
|
33
|
+
className: "musae-h8yej3"
|
|
28
34
|
}
|
|
29
35
|
}, React.createElement(Header, null), React.createElement(Body, null)));
|
|
30
36
|
};
|
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeepKeys } from "@tanstack/react-table";
|
|
2
2
|
import type { Table } from "@tanstack/react-table";
|
|
3
3
|
import type { ComponentProps } from "../../types/element";
|
|
4
|
+
import type { Key, ReactNode } from "react";
|
|
5
|
+
export type SortDirection = "ascending" | "descending" | null;
|
|
6
|
+
export type SortDescriptor = {
|
|
7
|
+
key: Key;
|
|
8
|
+
direction: SortDirection;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* column def
|
|
13
|
+
*/
|
|
14
|
+
export type Column<T, V = unknown> = {
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* key
|
|
18
|
+
*/
|
|
19
|
+
key: DeepKeys<T>;
|
|
20
|
+
/**
|
|
21
|
+
* @description
|
|
22
|
+
* title
|
|
23
|
+
*/
|
|
24
|
+
title: ReactNode | (() => ReactNode);
|
|
25
|
+
/**
|
|
26
|
+
* @description
|
|
27
|
+
* custom render, render is not provided, just render value
|
|
28
|
+
*/
|
|
29
|
+
render?: (value: V, record: T, index: number) => ReactNode | unknown;
|
|
30
|
+
/**
|
|
31
|
+
* @description
|
|
32
|
+
* enable sort
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
sortable?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @description
|
|
38
|
+
* allowed sort orders
|
|
39
|
+
*/
|
|
40
|
+
sortDirections?: SortDirection[];
|
|
41
|
+
};
|
|
4
42
|
/**
|
|
5
43
|
* @description
|
|
6
44
|
* table props
|
|
@@ -14,17 +52,28 @@ export type TableProps<T> = {
|
|
|
14
52
|
dataSource?: T[];
|
|
15
53
|
/**
|
|
16
54
|
* @description
|
|
17
|
-
*
|
|
18
|
-
* so in musae, we use this function to create columns
|
|
55
|
+
* columns
|
|
19
56
|
* @default void 0
|
|
20
57
|
*/
|
|
21
|
-
columns?:
|
|
58
|
+
columns?: Column<T>[];
|
|
22
59
|
/**
|
|
23
60
|
* @description
|
|
24
61
|
* bordered
|
|
25
62
|
* @default false
|
|
26
63
|
*/
|
|
27
64
|
bordered?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* @description
|
|
67
|
+
* sort descriptor
|
|
68
|
+
* @default void 0
|
|
69
|
+
*/
|
|
70
|
+
sortDescriptor?: SortDescriptor;
|
|
71
|
+
/**
|
|
72
|
+
* @description
|
|
73
|
+
* callback when table has changed, like sort
|
|
74
|
+
* @default void 0
|
|
75
|
+
*/
|
|
76
|
+
onSortChange?: (sortDescriptor: SortDescriptor) => void;
|
|
28
77
|
};
|
|
29
78
|
/**
|
|
30
79
|
* @author murukal
|
|
@@ -42,6 +91,15 @@ export type ContextValue<T> = {
|
|
|
42
91
|
* if current table is bordered
|
|
43
92
|
*/
|
|
44
93
|
bordered: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* {@link} `SortDescriptor`
|
|
96
|
+
*/
|
|
97
|
+
sortDescriptor?: SortDescriptor;
|
|
98
|
+
/**
|
|
99
|
+
* @description
|
|
100
|
+
* `SortDescriptor` Setter
|
|
101
|
+
*/
|
|
102
|
+
onSortChange?: (sortDescriptor: SortDescriptor) => void;
|
|
45
103
|
};
|
|
46
104
|
/**
|
|
47
105
|
* @description
|
|
@@ -53,3 +111,13 @@ export type HeaderProps = ComponentProps;
|
|
|
53
111
|
* body props
|
|
54
112
|
*/
|
|
55
113
|
export type BodyProps = ComponentProps;
|
|
114
|
+
/**
|
|
115
|
+
* @description
|
|
116
|
+
* header cell props
|
|
117
|
+
*/
|
|
118
|
+
export type HeaderCellProps = {
|
|
119
|
+
sortable?: boolean;
|
|
120
|
+
children: ReactNode | (() => ReactNode);
|
|
121
|
+
value: Key;
|
|
122
|
+
sortDirections: SortDirection[];
|
|
123
|
+
};
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
* @description
|
|
4
4
|
* repaint child
|
|
5
5
|
*/
|
|
6
|
-
export declare const useRepaint: ({ columns, rowGap
|
|
6
|
+
export declare const useRepaint: ({ columns, rowGap }: {
|
|
7
7
|
columns: number;
|
|
8
8
|
rowGap: number;
|
|
9
|
-
isSequential: boolean;
|
|
10
9
|
}) => {
|
|
11
10
|
maxHeight: number;
|
|
12
11
|
collect: (index: number, ref: HTMLDivElement | null) => void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useEvent
|
|
1
|
+
import { useEvent } from '@aiszlab/relax';
|
|
2
2
|
import { useRef, useState, useCallback } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
6
6
|
* repaint child
|
|
7
7
|
*/
|
|
8
|
-
const useRepaint = ({ columns, rowGap
|
|
8
|
+
const useRepaint = ({ columns, rowGap }) => {
|
|
9
9
|
const items = useRef(new Map());
|
|
10
10
|
const [maxHeight, setMaxHeight] = useState(0);
|
|
11
11
|
const [orders, setOrders] = useState(new Map());
|
|
@@ -30,12 +30,6 @@ const useRepaint = ({ columns, rowGap, isSequential, }) => {
|
|
|
30
30
|
setMaxHeight(Math.max(...columnHeights));
|
|
31
31
|
setOrders(_orders);
|
|
32
32
|
});
|
|
33
|
-
useUpdateEffect(() => {
|
|
34
|
-
// no need to repaint when `sequential`
|
|
35
|
-
if (isSequential)
|
|
36
|
-
return;
|
|
37
|
-
repaint();
|
|
38
|
-
}, [rowGap]);
|
|
39
33
|
const order = useCallback((index) => {
|
|
40
34
|
return orders.get(index) ?? null;
|
|
41
35
|
}, [orders]);
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { useRepaint } from './hooks.js';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useGutters } from '../../hooks/use-gutters.js';
|
|
6
|
-
import { useMounted } from '@aiszlab/relax';
|
|
6
|
+
import { useUpdateEffect, useMounted } from '@aiszlab/relax';
|
|
7
7
|
import Sequential from './sequential.js';
|
|
8
8
|
|
|
9
9
|
const styles = {
|
|
@@ -60,8 +60,7 @@ const Waterfall = ({
|
|
|
60
60
|
repaint
|
|
61
61
|
} = useRepaint({
|
|
62
62
|
columns,
|
|
63
|
-
rowGap
|
|
64
|
-
isSequential: sequential
|
|
63
|
+
rowGap
|
|
65
64
|
});
|
|
66
65
|
const styled = props(styles.waterfall({
|
|
67
66
|
rowGap,
|
|
@@ -69,17 +68,22 @@ const Waterfall = ({
|
|
|
69
68
|
}), !sequential && maxHeight > 0 && styles.repainted({
|
|
70
69
|
maxHeight: maxHeight
|
|
71
70
|
}));
|
|
71
|
+
useUpdateEffect(() => {
|
|
72
|
+
// no need to repaint when `sequential`
|
|
73
|
+
if (sequential) return;
|
|
74
|
+
repaint();
|
|
75
|
+
}, [rowGap]);
|
|
72
76
|
useMounted(() => {
|
|
73
77
|
// no need to observer when `sequential`
|
|
74
78
|
if (sequential) return;
|
|
75
79
|
// observer be called when the component is mounted
|
|
76
80
|
// so in waterfall we use current time to first render
|
|
77
|
-
// FIXME: repaint twice in layout effect & resize observer
|
|
78
81
|
const resizer = new ResizeObserver(() => {
|
|
79
82
|
repaint();
|
|
80
83
|
});
|
|
81
84
|
Array.from(items.current.values()).forEach(node => {
|
|
82
|
-
|
|
85
|
+
if (!node) return;
|
|
86
|
+
resizer.observe(node);
|
|
83
87
|
});
|
|
84
88
|
return () => {
|
|
85
89
|
resizer.disconnect();
|
|
@@ -192,4 +192,19 @@ export declare const useClassNames: <T extends ComponentToken>(token: T) => {
|
|
|
192
192
|
1: string;
|
|
193
193
|
2: string;
|
|
194
194
|
};
|
|
195
|
+
36: {
|
|
196
|
+
0: string;
|
|
197
|
+
1: string;
|
|
198
|
+
2: string;
|
|
199
|
+
};
|
|
200
|
+
37: {
|
|
201
|
+
0: string;
|
|
202
|
+
1: string;
|
|
203
|
+
2: string;
|
|
204
|
+
3: string;
|
|
205
|
+
7: string;
|
|
206
|
+
4: string;
|
|
207
|
+
5: string;
|
|
208
|
+
6: string;
|
|
209
|
+
};
|
|
195
210
|
}[T];
|
|
@@ -7,23 +7,27 @@ import { useUpdateEffect } from '@aiszlab/relax';
|
|
|
7
7
|
const useExpandEffect = ({ expanded, target, animate, }) => {
|
|
8
8
|
useUpdateEffect(async () => {
|
|
9
9
|
if (expanded) {
|
|
10
|
-
target.current.
|
|
11
|
-
target.current.
|
|
12
|
-
target.current.
|
|
10
|
+
target.current.style.height = "0";
|
|
11
|
+
target.current.style.overflow = "hidden";
|
|
12
|
+
target.current.style.display = "inherit";
|
|
13
13
|
await animate(target.current, {
|
|
14
14
|
height: "auto",
|
|
15
15
|
});
|
|
16
|
-
target.current.
|
|
16
|
+
target.current.style.height = "";
|
|
17
|
+
target.current.style.overflow = "";
|
|
18
|
+
target.current.style.display = "";
|
|
17
19
|
return;
|
|
18
20
|
}
|
|
19
21
|
// style play like display: none
|
|
20
|
-
target.current.
|
|
21
|
-
target.current.
|
|
22
|
-
target.current.
|
|
22
|
+
target.current.style.overflow = "hidden";
|
|
23
|
+
target.current.style.height = "auto";
|
|
24
|
+
target.current.style.display = "inherit";
|
|
23
25
|
await animate(target.current, {
|
|
24
26
|
height: 0,
|
|
25
27
|
});
|
|
26
|
-
target.current.
|
|
28
|
+
target.current.style.height = "";
|
|
29
|
+
target.current.style.overflow = "";
|
|
30
|
+
target.current.style.display = "none";
|
|
27
31
|
}, [expanded]);
|
|
28
32
|
};
|
|
29
33
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTMLAttributeReferrerPolicy } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* prefetch image
|
|
5
|
+
* if image load failed, get fail status
|
|
6
|
+
*/
|
|
7
|
+
export declare const useImage: ({ src, crossOrigin, referrerPolicy, }: {
|
|
8
|
+
src?: string;
|
|
9
|
+
crossOrigin?: string;
|
|
10
|
+
referrerPolicy?: HTMLAttributeReferrerPolicy;
|
|
11
|
+
}) => false | "error" | "loaded";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* prefetch image
|
|
6
|
+
* if image load failed, get fail status
|
|
7
|
+
*/
|
|
8
|
+
const useImage = ({ src, crossOrigin, referrerPolicy = "no-referrer", }) => {
|
|
9
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!src) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
setIsLoaded(false);
|
|
15
|
+
const image = new Image();
|
|
16
|
+
image.onload = () => {
|
|
17
|
+
setIsLoaded("loaded");
|
|
18
|
+
};
|
|
19
|
+
image.onerror = () => {
|
|
20
|
+
setIsLoaded("error");
|
|
21
|
+
};
|
|
22
|
+
image.crossOrigin = crossOrigin ?? null;
|
|
23
|
+
image.referrerPolicy = referrerPolicy;
|
|
24
|
+
image.src = src;
|
|
25
|
+
return () => {
|
|
26
|
+
image.onload = null;
|
|
27
|
+
image.onerror = null;
|
|
28
|
+
image.remove();
|
|
29
|
+
};
|
|
30
|
+
}, [src, crossOrigin, referrerPolicy]);
|
|
31
|
+
return isLoaded;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { useImage };
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export { Upload } from "./components/upload";
|
|
|
47
47
|
export { Progress } from "./components/progress";
|
|
48
48
|
export { Popover } from "./components/popover";
|
|
49
49
|
export { Watermark } from "./components/watermark";
|
|
50
|
+
export { Collapse } from "./components/collapse";
|
|
50
51
|
/**
|
|
51
52
|
* @description
|
|
52
53
|
* hooks
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ export { default as Upload } from './components/upload/upload.js';
|
|
|
44
44
|
export { default as Progress } from './components/progress/progress.js';
|
|
45
45
|
export { default as Popover } from './components/popover/popover.js';
|
|
46
46
|
export { default as Watermark } from './components/watermark/watermark.js';
|
|
47
|
+
export { default as Collapse } from './components/collapse/collapse.js';
|
|
47
48
|
export { useMessage } from './components/message/hooks.js';
|
|
48
49
|
export { useNotification } from './components/notification/hooks.js';
|
|
49
50
|
export { useTheme } from './components/theme/hooks.js';
|