@swan-io/lake 11.1.4 → 11.1.6
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/package.json
CHANGED
|
@@ -6,36 +6,25 @@ import { TextVariant } from "./LakeText";
|
|
|
6
6
|
import { LakeTooltip } from "./LakeTooltip";
|
|
7
7
|
declare const directionStyles: {
|
|
8
8
|
column: {
|
|
9
|
-
flexShrink: number;
|
|
10
9
|
flexDirection: "column";
|
|
11
|
-
justifyContent: "center";
|
|
12
|
-
};
|
|
13
|
-
columnReverse: {
|
|
14
|
-
flexShrink: number;
|
|
15
|
-
flexDirection: "column-reverse";
|
|
16
|
-
justifyContent: "center";
|
|
17
10
|
};
|
|
18
11
|
row: {
|
|
19
|
-
flexShrink: number;
|
|
20
12
|
flexDirection: "row";
|
|
21
|
-
alignItems: "center";
|
|
22
|
-
};
|
|
23
|
-
rowReverse: {
|
|
24
|
-
flexShrink: number;
|
|
25
|
-
flexDirection: "row-reverse";
|
|
26
|
-
alignItems: "center";
|
|
27
13
|
};
|
|
28
14
|
};
|
|
29
15
|
type Align = "left" | "center" | "right";
|
|
16
|
+
type FadeOn = "left" | "right";
|
|
30
17
|
type SortDirection = "Desc" | "Asc";
|
|
31
18
|
type TooltipProp = Except<ComponentProps<typeof LakeTooltip>, "children">;
|
|
32
19
|
type CellProps = {
|
|
33
20
|
children: ReactNode;
|
|
34
21
|
align?: Align;
|
|
35
22
|
direction?: keyof typeof directionStyles;
|
|
23
|
+
fadeOn?: FadeOn;
|
|
36
24
|
style?: StyleProp<ViewStyle>;
|
|
25
|
+
contentContainerStyle?: StyleProp<ViewStyle>;
|
|
37
26
|
};
|
|
38
|
-
export declare const Cell: ({ children, align, direction, style }: CellProps) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare const Cell: ({ children, align, direction, fadeOn, style, contentContainerStyle, }: CellProps) => import("react/jsx-runtime").JSX.Element;
|
|
39
28
|
type HeaderCellProps = {
|
|
40
29
|
align?: Align;
|
|
41
30
|
sort?: SortDirection;
|
|
@@ -80,11 +69,12 @@ type LinkCellProps = {
|
|
|
80
69
|
buttonPosition?: "start" | "end";
|
|
81
70
|
children: ReactNode;
|
|
82
71
|
external?: boolean;
|
|
72
|
+
fadeOn?: FadeOn;
|
|
83
73
|
onPress: () => void;
|
|
84
74
|
tooltip?: TooltipProp;
|
|
85
75
|
variant?: TextVariant;
|
|
86
76
|
};
|
|
87
|
-
export declare const LinkCell: ({ buttonPosition, children, external, onPress, tooltip, variant, }: LinkCellProps) => import("react/jsx-runtime").JSX.Element;
|
|
77
|
+
export declare const LinkCell: ({ buttonPosition, children, external, fadeOn, onPress, tooltip, variant, }: LinkCellProps) => import("react/jsx-runtime").JSX.Element;
|
|
88
78
|
/**
|
|
89
79
|
* @deprecated Avoid usage
|
|
90
80
|
*/
|
package/src/components/Cells.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useCallback, useState } from "react";
|
|
|
3
3
|
import { StyleSheet, View } from "react-native";
|
|
4
4
|
import { match } from "ts-pattern";
|
|
5
5
|
import { visuallyHiddenStyle } from "../constants/commonStyles";
|
|
6
|
-
import { colors,
|
|
6
|
+
import { colors, invariantColors, spacings } from "../constants/design";
|
|
7
7
|
import { setClipboardText } from "../utils/clipboard";
|
|
8
8
|
import { identity } from "../utils/function";
|
|
9
9
|
import { isNotNullish, isNullish } from "../utils/nullish";
|
|
@@ -15,28 +15,22 @@ import { Pressable } from "./Pressable";
|
|
|
15
15
|
import { Space } from "./Space";
|
|
16
16
|
/* eslint-disable react-native/no-unused-styles */
|
|
17
17
|
const directionStyles = StyleSheet.create({
|
|
18
|
-
column: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
flexDirection: "row",
|
|
31
|
-
alignItems: "center",
|
|
32
|
-
},
|
|
33
|
-
rowReverse: {
|
|
34
|
-
flexShrink: 1,
|
|
35
|
-
flexDirection: "row-reverse",
|
|
36
|
-
alignItems: "center",
|
|
37
|
-
},
|
|
18
|
+
column: { flexDirection: "column" },
|
|
19
|
+
row: { flexDirection: "row" },
|
|
20
|
+
});
|
|
21
|
+
const alignItemsStyles = StyleSheet.create({
|
|
22
|
+
left: { alignItems: "flex-start" },
|
|
23
|
+
center: { alignItems: "center" },
|
|
24
|
+
right: { alignItems: "flex-end" },
|
|
25
|
+
});
|
|
26
|
+
const justifyContentStyles = StyleSheet.create({
|
|
27
|
+
left: { justifyContent: "flex-start" },
|
|
28
|
+
center: { justifyContent: "center" },
|
|
29
|
+
right: { justifyContent: "flex-end" },
|
|
38
30
|
});
|
|
39
31
|
/* eslint-enable react-native/no-unused-styles */
|
|
32
|
+
const fadeOnLeftMask = `linear-gradient(to right, ${invariantColors.transparent}, ${invariantColors.black} ${spacings[16]})`;
|
|
33
|
+
const fadeOnRightMask = `linear-gradient(to left, ${invariantColors.transparent}, ${invariantColors.black} ${spacings[16]})`;
|
|
40
34
|
const styles = StyleSheet.create({
|
|
41
35
|
cell: {
|
|
42
36
|
flexDirection: "row",
|
|
@@ -44,14 +38,21 @@ const styles = StyleSheet.create({
|
|
|
44
38
|
flexShrink: 1,
|
|
45
39
|
paddingHorizontal: spacings[16],
|
|
46
40
|
},
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
cellContentContainer: {
|
|
42
|
+
flexGrow: 1,
|
|
43
|
+
flexShrink: 1,
|
|
44
|
+
overflow: "hidden",
|
|
49
45
|
},
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
fadeOnLeft: {
|
|
47
|
+
maskImage: fadeOnLeftMask,
|
|
48
|
+
WebkitMaskImage: fadeOnLeftMask,
|
|
52
49
|
},
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
fadeOnRight: {
|
|
51
|
+
maskImage: fadeOnRightMask,
|
|
52
|
+
WebkitMaskImage: fadeOnRightMask,
|
|
53
|
+
},
|
|
54
|
+
noCursor: {
|
|
55
|
+
cursor: "text",
|
|
55
56
|
},
|
|
56
57
|
sortIcon: {
|
|
57
58
|
transitionProperty: "transform",
|
|
@@ -72,34 +73,44 @@ const styles = StyleSheet.create({
|
|
|
72
73
|
headerUnderlineActive: {
|
|
73
74
|
backgroundColor: colors.current[500],
|
|
74
75
|
},
|
|
76
|
+
// eslint-disable-next-line react-native/no-color-literals
|
|
75
77
|
buttonUnderline: {
|
|
76
|
-
|
|
78
|
+
position: "absolute",
|
|
79
|
+
bottom: 0,
|
|
80
|
+
left: 0,
|
|
81
|
+
right: spacings[8],
|
|
82
|
+
height: 2,
|
|
83
|
+
backgroundColor: "currentColor",
|
|
77
84
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
marginHorizontal: negativeSpacings[8],
|
|
85
|
+
buttonEndUnderline: {
|
|
86
|
+
right: 0,
|
|
87
|
+
left: spacings[8],
|
|
82
88
|
},
|
|
83
|
-
|
|
84
|
-
justifyContent: "center",
|
|
89
|
+
fullHeight: {
|
|
85
90
|
height: "100%",
|
|
86
|
-
paddingHorizontal: spacings[8],
|
|
87
91
|
},
|
|
88
|
-
|
|
92
|
+
button: {
|
|
89
93
|
justifyContent: "center",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
height: "100%",
|
|
95
|
+
paddingRight: spacings[8],
|
|
96
|
+
},
|
|
97
|
+
buttonEnd: {
|
|
98
|
+
paddingRight: 0,
|
|
99
|
+
paddingLeft: spacings[8],
|
|
93
100
|
},
|
|
94
101
|
actionCell: {
|
|
95
102
|
paddingVertical: spacings[16],
|
|
96
103
|
paddingHorizontal: spacings[8],
|
|
97
104
|
},
|
|
98
105
|
});
|
|
99
|
-
export const Cell = ({ children, align = "left", direction = "row", style }) => (_jsx(View, { style: [styles.cell, style], children: _jsx(View, { style: [
|
|
106
|
+
export const Cell = ({ children, align = "left", direction = "row", fadeOn, style, contentContainerStyle, }) => (_jsx(View, { style: [styles.cell, style], children: _jsx(View, { style: [
|
|
107
|
+
styles.cellContentContainer,
|
|
100
108
|
directionStyles[direction],
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
alignItemsStyles[direction === "row" ? "center" : align],
|
|
110
|
+
justifyContentStyles[direction === "row" ? align : "center"],
|
|
111
|
+
fadeOn === "left" && styles.fadeOnLeft,
|
|
112
|
+
fadeOn === "right" && styles.fadeOnRight,
|
|
113
|
+
contentContainerStyle,
|
|
103
114
|
], children: children }) }));
|
|
104
115
|
export const HeaderCell = ({ align = "left", sort, text, onPress }) => {
|
|
105
116
|
const sortActive = isNotNullish(sort) && isNotNullish(onPress);
|
|
@@ -110,9 +121,10 @@ export const HeaderCell = ({ align = "left", sort, text, onPress }) => {
|
|
|
110
121
|
.with("Desc", () => "Asc")
|
|
111
122
|
.otherwise(() => "Desc"));
|
|
112
123
|
}, children: ({ hovered }) => (_jsxs(View, { style: [
|
|
124
|
+
styles.cellContentContainer,
|
|
113
125
|
directionStyles["row"],
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
alignItemsStyles["center"],
|
|
127
|
+
justifyContentStyles[align],
|
|
116
128
|
], children: [_jsx(LakeText, { numberOfLines: 1, align: align, color: sortActive ? colors.current[500] : colors.gray[900], variant: "medium", children: text }), isNotNullish(onPress) && (_jsxs(_Fragment, { children: [_jsx(Space, { width: 8 }), _jsx(Icon, { size: 15, color: sortActive ? colors.current[500] : colors.gray[500], name: sortActive ? "arrow-down-filled" : "chevron-up-down-regular", style: [styles.sortIcon, sort === "Asc" && styles.rotated] })] })), (hovered || sortActive) && (_jsx(View, { style: [styles.headerUnderline, sortActive && styles.headerUnderlineActive] }))] })) }));
|
|
117
129
|
};
|
|
118
130
|
export const TextCell = ({ align = "left", color = colors.gray[900], text, tooltip, variant = "regular", }) => (_jsx(Cell, { align: align, children: _jsx(LakeText, { numberOfLines: 1, align: align, color: color, tooltip: tooltip, variant: variant, children: text }) }));
|
|
@@ -124,7 +136,7 @@ export const CopyableTextCell = ({ copiedWording, copyWording, text, textToCopy,
|
|
|
124
136
|
setClipboardText(clipboardText);
|
|
125
137
|
setVisibleState("copied");
|
|
126
138
|
}, [clipboardText]);
|
|
127
|
-
return (_jsxs(Cell, {
|
|
139
|
+
return (_jsxs(Cell, { style: styles.fullHeight, children: [_jsx(LakeTooltip, { content: visibleState === "copy" ? copyWording : copiedWording, onHide: () => setVisibleState("copy"), placement: "left", togglableOnFocus: true, containerStyle: styles.fullHeight, children: _jsx(Pressable, { "aria-label": copyWording, role: "button", onPress: onPress, style: styles.button, children: ({ hovered }) => (_jsxs(_Fragment, { children: [_jsx(Icon, { name: hovered ? "copy-filled" : "copy-regular", color: "currentColor", size: 14 }), hovered && _jsx(View, { role: "none", style: styles.buttonUnderline })] })) }) }), _jsx(LakeText, { numberOfLines: 1, color: colors.gray[900], tooltip: tooltip, variant: variant, children: text })] }));
|
|
128
140
|
};
|
|
129
141
|
// TODO: handle `+` sign properly
|
|
130
142
|
export const BalanceCell = ({ textAlign = "right", align = textAlign, currency, formatCurrency, originalValue, value, variant = "medium", }) => (_jsxs(Cell, { align: align, direction: "column", children: [_jsx(LakeText, { numberOfLines: 1, align: align, color: colors.gray[900], variant: variant, style: [
|
|
@@ -132,10 +144,20 @@ export const BalanceCell = ({ textAlign = "right", align = textAlign, currency,
|
|
|
132
144
|
value < 0 && { color: colors.negative.primary },
|
|
133
145
|
], children: (value > 0 ? "+" : "") + formatCurrency(value, currency) }), isNotNullish(originalValue) && originalValue.currency !== currency && (_jsx(LakeText, { numberOfLines: 1, align: align, color: colors.gray[500], variant: "smallRegular", children: (originalValue.value > 0 ? "+" : "") +
|
|
134
146
|
formatCurrency(originalValue.value, originalValue.currency) }))] }));
|
|
135
|
-
export const LinkCell = ({ buttonPosition = "start", children, external = false, onPress, tooltip, variant = "medium", }) =>
|
|
147
|
+
export const LinkCell = ({ buttonPosition = "start", children, external = false, fadeOn, onPress, tooltip, variant = "medium", }) => {
|
|
148
|
+
const atEnd = buttonPosition === "end";
|
|
149
|
+
const elements = [
|
|
150
|
+
_jsx(Pressable, { style: [styles.button, atEnd && styles.buttonEnd], onPress: event => {
|
|
136
151
|
event.preventDefault();
|
|
137
152
|
onPress();
|
|
138
|
-
}, children: _jsx(Icon, { size: 14, name: external ? "open-regular" : "arrow-right-filled" })
|
|
153
|
+
}, children: ({ hovered }) => (_jsxs(_Fragment, { children: [_jsx(Icon, { size: 14, name: external ? "open-regular" : "arrow-right-filled" }), hovered && (_jsx(View, { role: "none", style: [styles.buttonUnderline, atEnd && styles.buttonEndUnderline] }))] })) }),
|
|
154
|
+
_jsx(LakeText, { numberOfLines: 1, color: colors.gray[900], variant: variant, tooltip: tooltip, children: children }),
|
|
155
|
+
];
|
|
156
|
+
if (atEnd) {
|
|
157
|
+
elements.reverse();
|
|
158
|
+
}
|
|
159
|
+
return _jsx(Cell, { fadeOn: fadeOn, children: elements });
|
|
160
|
+
};
|
|
139
161
|
/**
|
|
140
162
|
* @deprecated Avoid usage
|
|
141
163
|
*/
|
|
@@ -7,12 +7,12 @@ export type ColumnTitleConfig<ExtraInfo> = {
|
|
|
7
7
|
export type ColumnCellConfig<T, ExtraInfo> = {
|
|
8
8
|
columnId: string;
|
|
9
9
|
item: T;
|
|
10
|
-
index: number;
|
|
11
|
-
extraInfo: ExtraInfo;
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
11
|
+
* isHovered is only set for PlainListView
|
|
14
12
|
*/
|
|
15
13
|
isHovered: boolean;
|
|
14
|
+
index: number;
|
|
15
|
+
extraInfo: ExtraInfo;
|
|
16
16
|
};
|
|
17
17
|
export type ColumnConfig<T, ExtraInfo> = {
|
|
18
18
|
id: string;
|
|
@@ -69,14 +69,12 @@ const styles = StyleSheet.create({
|
|
|
69
69
|
transitionTimingFunction: "ease-in-out",
|
|
70
70
|
},
|
|
71
71
|
headerCell: {
|
|
72
|
-
display: "flex",
|
|
73
72
|
flexDirection: "row",
|
|
74
73
|
flexGrow: 1,
|
|
75
74
|
alignItems: "center",
|
|
76
75
|
boxShadow: `0 -1px ${colors.gray[100]}`,
|
|
77
76
|
},
|
|
78
77
|
cell: {
|
|
79
|
-
display: "flex",
|
|
80
78
|
flexDirection: "row",
|
|
81
79
|
flexGrow: 1,
|
|
82
80
|
alignItems: "stretch",
|
|
@@ -36,7 +36,7 @@ export const useContextualLayer = ({ placement, visible, matchReferenceWidth = f
|
|
|
36
36
|
top: rect.top + height,
|
|
37
37
|
};
|
|
38
38
|
const horizontalPosition = match(inferedPlacement)
|
|
39
|
-
.with("left", () => ({ left: rect.left }))
|
|
39
|
+
.with("left", () => ({ left: rect.left - 12 }))
|
|
40
40
|
.with("right", () => ({ right: window.innerWidth - rect.right }))
|
|
41
41
|
.with("center", () => ({ left: rect.left + width / 2, transform: "translateX(-50%)" }))
|
|
42
42
|
.exhaustive();
|