@swan-io/lake 2.0.1 → 2.0.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/package.json +2 -2
- package/src/components/FixedListViewCells.js +1 -3
- package/src/components/LakeTooltip.d.ts +1 -0
- package/src/components/LakeTooltip.js +3 -3
- package/src/components/QuickActions.d.ts +3 -1
- package/src/components/QuickActions.js +15 -7
- package/src/utils/__tests__/rifm.test.js +21 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-io/lake",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14.0.0",
|
|
6
6
|
"yarn": "^1.20.0"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@popperjs/core": "^2.11.7",
|
|
30
|
-
"@swan-io/boxed": "^1.0.
|
|
30
|
+
"@swan-io/boxed": "^1.0.2",
|
|
31
31
|
"@swan-io/chicane": "^1.3.4",
|
|
32
32
|
"dayjs": "^1.11.7",
|
|
33
33
|
"polished": "^4.2.2",
|
|
@@ -108,9 +108,7 @@ export const SimpleHeaderCell = ({ text, sort, justifyContent = "flex-start", on
|
|
|
108
108
|
export const ColorPatchCell = ({ isHovered, alternativeText, color, }) => {
|
|
109
109
|
return isHovered ? (_jsx(View, { style: [styles.colorPatch, { backgroundColor: colors[color].primary }], children: isNotNullish(alternativeText) ? (_jsx(LakeText, { style: styles.alternativeText, children: alternativeText })) : null })) : null;
|
|
110
110
|
};
|
|
111
|
-
export const SimpleTitleCell = ({ isHighlighted = false, text, }) => (_jsx(View, { style: styles.cell, children: _jsx(LakeText, { numberOfLines: 1, color: colors.gray[900], variant: "medium",
|
|
112
|
-
color: colors.current.primary,
|
|
113
|
-
}), children: text }) }));
|
|
111
|
+
export const SimpleTitleCell = ({ isHighlighted = false, text, }) => (_jsx(View, { style: styles.cell, children: _jsx(LakeText, { numberOfLines: 1, color: isHighlighted ? colors.current.primary : colors.gray[900], style: styles.regularText, variant: "medium", children: text }) }));
|
|
114
112
|
export const SimpleRegularTextCell = ({ variant = "regular", text, textAlign = "left", }) => {
|
|
115
113
|
return (_jsx(View, { style: styles.cell, children: _jsx(LakeText, { align: textAlign, color: colors.gray[900], style: styles.regularText, variant: variant, children: text }) }));
|
|
116
114
|
};
|
|
@@ -5,7 +5,7 @@ import { usePopper } from "react-popper";
|
|
|
5
5
|
import { match } from "ts-pattern";
|
|
6
6
|
import { colors, shadows } from "../constants/design";
|
|
7
7
|
import { useHover } from "../hooks/useHover";
|
|
8
|
-
import {
|
|
8
|
+
import { isNotNullish } from "../utils/nullish";
|
|
9
9
|
import { getRootElement, matchReferenceWidthModifier } from "../utils/popper";
|
|
10
10
|
import { Icon } from "./Icon";
|
|
11
11
|
import { LakeText } from "./LakeText";
|
|
@@ -83,7 +83,7 @@ const styles = StyleSheet.create({
|
|
|
83
83
|
});
|
|
84
84
|
const isReactText = (node) => ["string", "number"].includes(typeof node);
|
|
85
85
|
const MAX_WIDTH = "calc(100vw - 20px)";
|
|
86
|
-
export const LakeTooltip = memo(forwardRef(({ children, content, describedBy, matchReferenceWidth = false, hideArrow = false, onHide, onShow, placement, width, togglableOnFocus = false, containerStyle, }, forwardedRef) => {
|
|
86
|
+
export const LakeTooltip = memo(forwardRef(({ children, content, describedBy, matchReferenceWidth = false, hideArrow = false, onHide, onShow, placement, width, togglableOnFocus = false, containerStyle, disabled = false, }, forwardedRef) => {
|
|
87
87
|
const referenceRef = useRef(null);
|
|
88
88
|
const rootElement = getRootElement(referenceRef.current);
|
|
89
89
|
const [popperElement, setPopperElement] = useState(null);
|
|
@@ -157,7 +157,7 @@ export const LakeTooltip = memo(forwardRef(({ children, content, describedBy, ma
|
|
|
157
157
|
void update?.();
|
|
158
158
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
159
159
|
}, [content]);
|
|
160
|
-
return (_jsxs(_Fragment, { children: [_jsx(View, { ref: referenceRef, style: containerStyle, children: children }),
|
|
160
|
+
return (_jsxs(_Fragment, { children: [_jsx(View, { ref: referenceRef, style: containerStyle, children: children }), isNotNullish(rootElement) && visible && !disabled && (_jsx(Portal, { container: rootElement, children: _jsx("div", { ref: setPopperElement, style: { ...popperStyles.popper, maxWidth: MAX_WIDTH }, ...attributes.popper, role: "tooltip", "aria-describedby": describedBy, children: _jsxs(View, { style: [
|
|
161
161
|
styles.base,
|
|
162
162
|
state?.placement === "top" && styles.baseTop,
|
|
163
163
|
state?.placement === "bottom" && styles.baseBottom,
|
|
@@ -9,6 +9,8 @@ export type QuickAction = {
|
|
|
9
9
|
};
|
|
10
10
|
type Props = {
|
|
11
11
|
actions: QuickAction[];
|
|
12
|
+
tooltipDisabled?: boolean;
|
|
13
|
+
tooltipText?: string;
|
|
12
14
|
};
|
|
13
|
-
export declare const QuickActions: ({ actions }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare const QuickActions: ({ actions, tooltipDisabled, tooltipText }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
14
16
|
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { ActivityIndicator, StyleSheet, View } from "react-native";
|
|
3
3
|
import { colors, spacings } from "../constants/design";
|
|
4
|
+
import { isNullishOrEmpty } from "../utils/nullish";
|
|
4
5
|
import { Icon } from "./Icon";
|
|
5
6
|
import { LakeText } from "./LakeText";
|
|
7
|
+
import { LakeTooltip } from "./LakeTooltip";
|
|
6
8
|
import { Pressable } from "./Pressable";
|
|
7
9
|
import { Space } from "./Space";
|
|
8
10
|
const styles = StyleSheet.create({
|
|
@@ -24,15 +26,21 @@ const styles = StyleSheet.create({
|
|
|
24
26
|
paddingHorizontal: spacings[12],
|
|
25
27
|
flexBasis: "30%",
|
|
26
28
|
},
|
|
29
|
+
disabled: {
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
paddingHorizontal: spacings[12],
|
|
32
|
+
flexBasis: "30%",
|
|
33
|
+
opacity: 0.4,
|
|
34
|
+
},
|
|
27
35
|
label: {
|
|
28
36
|
lineHeight: 16,
|
|
29
37
|
},
|
|
30
38
|
});
|
|
31
|
-
export const QuickActions = ({ actions }) => {
|
|
32
|
-
return (_jsx(View, { style: styles.container, children: actions.map((action, index) => (_jsxs(Pressable, { onPress: action.onPress, style: styles.action, disabled: action.isLoading === true, children: [_jsx(View, { style: [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
export const QuickActions = ({ actions, tooltipDisabled = false, tooltipText }) => {
|
|
40
|
+
return (_jsx(View, { style: styles.container, children: actions.map((action, index) => (_jsx(LakeTooltip, { content: tooltipText, placement: "top", disabled: tooltipDisabled || isNullishOrEmpty(tooltipText), children: _jsxs(Pressable, { onPress: action.onPress, style: tooltipDisabled ? styles.action : styles.disabled, disabled: action.isLoading === true || !tooltipDisabled, children: [_jsx(View, { style: [
|
|
41
|
+
styles.icon,
|
|
42
|
+
action.backgroundColor != null
|
|
43
|
+
? { backgroundColor: action.backgroundColor, borderColor: action.backgroundColor }
|
|
44
|
+
: null,
|
|
45
|
+
], children: action.isLoading === true ? (_jsx(ActivityIndicator, { color: action.color ?? colors.gray[300], size: 16 })) : (_jsx(Icon, { name: action.icon, size: 16, color: action.color ?? colors.gray[300] })) }), _jsx(Space, { height: 8 }), _jsx(LakeText, { variant: "smallRegular", align: "center", style: styles.label, children: action.label })] }, index) }, index))) }));
|
|
38
46
|
};
|
|
@@ -20,15 +20,15 @@ test('it respects accept: "alpha" param', async () => {
|
|
|
20
20
|
return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
|
|
21
21
|
};
|
|
22
22
|
const utils = render(_jsx(Test, {}));
|
|
23
|
-
const input = await utils.findByRole("textbox");
|
|
23
|
+
const input = (await utils.findByRole("textbox"));
|
|
24
24
|
typeInInput(input, "test");
|
|
25
|
-
expect(input).
|
|
25
|
+
expect(input.value).toBe("te st/");
|
|
26
26
|
clearInput(input);
|
|
27
27
|
typeInInput(input, "1234");
|
|
28
|
-
expect(input).
|
|
28
|
+
expect(input.value).toBe("");
|
|
29
29
|
clearInput(input);
|
|
30
30
|
typeInInput(input, "te34");
|
|
31
|
-
expect(input).
|
|
31
|
+
expect(input.value).toBe("te ");
|
|
32
32
|
clearInput(input);
|
|
33
33
|
});
|
|
34
34
|
test('it respects accept: "numeric" param', async () => {
|
|
@@ -42,15 +42,15 @@ test('it respects accept: "numeric" param', async () => {
|
|
|
42
42
|
return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
|
|
43
43
|
};
|
|
44
44
|
const utils = render(_jsx(Test, {}));
|
|
45
|
-
const input = await utils.findByRole("textbox");
|
|
45
|
+
const input = (await utils.findByRole("textbox"));
|
|
46
46
|
typeInInput(input, "test");
|
|
47
|
-
expect(input).
|
|
47
|
+
expect(input.value).toBe("");
|
|
48
48
|
clearInput(input);
|
|
49
49
|
typeInInput(input, "1234");
|
|
50
|
-
expect(input).
|
|
50
|
+
expect(input.value).toBe("12 34/");
|
|
51
51
|
clearInput(input);
|
|
52
52
|
typeInInput(input, "te34");
|
|
53
|
-
expect(input).
|
|
53
|
+
expect(input.value).toBe("34 ");
|
|
54
54
|
clearInput(input);
|
|
55
55
|
});
|
|
56
56
|
test('it respects accept: "alphanumeric" param', async () => {
|
|
@@ -64,18 +64,18 @@ test('it respects accept: "alphanumeric" param', async () => {
|
|
|
64
64
|
return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
|
|
65
65
|
};
|
|
66
66
|
const utils = render(_jsx(Test, {}));
|
|
67
|
-
const input = await utils.findByRole("textbox");
|
|
67
|
+
const input = (await utils.findByRole("textbox"));
|
|
68
68
|
typeInInput(input, "test");
|
|
69
|
-
expect(input).
|
|
69
|
+
expect(input.value).toBe("te st/");
|
|
70
70
|
clearInput(input);
|
|
71
71
|
typeInInput(input, "1234");
|
|
72
|
-
expect(input).
|
|
72
|
+
expect(input.value).toBe("12 34/");
|
|
73
73
|
clearInput(input);
|
|
74
74
|
typeInInput(input, "te34");
|
|
75
|
-
expect(input).
|
|
75
|
+
expect(input.value).toBe("te 34/");
|
|
76
76
|
clearInput(input);
|
|
77
77
|
typeInInput(input, "t__4");
|
|
78
|
-
expect(input).
|
|
78
|
+
expect(input.value).toBe("t4 ");
|
|
79
79
|
clearInput(input);
|
|
80
80
|
});
|
|
81
81
|
test("it appends characters at given indexes", async () => {
|
|
@@ -89,15 +89,15 @@ test("it appends characters at given indexes", async () => {
|
|
|
89
89
|
return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
|
|
90
90
|
};
|
|
91
91
|
const utils = render(_jsx(Test, {}));
|
|
92
|
-
const input = await utils.findByRole("textbox");
|
|
92
|
+
const input = (await utils.findByRole("textbox"));
|
|
93
93
|
typeInInput(input, "12");
|
|
94
|
-
expect(input).
|
|
94
|
+
expect(input.value).toBe("12 ");
|
|
95
95
|
clearInput(input);
|
|
96
96
|
typeInInput(input, "1234");
|
|
97
|
-
expect(input).
|
|
97
|
+
expect(input.value).toBe("12 34/");
|
|
98
98
|
clearInput(input);
|
|
99
99
|
typeInInput(input, "123456");
|
|
100
|
-
expect(input).
|
|
100
|
+
expect(input.value).toBe("12 34/56");
|
|
101
101
|
clearInput(input);
|
|
102
102
|
});
|
|
103
103
|
test("it truncates the formatted text to the maximum length", async () => {
|
|
@@ -111,14 +111,14 @@ test("it truncates the formatted text to the maximum length", async () => {
|
|
|
111
111
|
return (_jsx(Rifm, { ...props, value: value, onChange: setValue, children: ({ value, onChange }) => _jsx("input", { type: "text", value: value, onChange: onChange }) }));
|
|
112
112
|
};
|
|
113
113
|
const utils = render(_jsx(Test, {}));
|
|
114
|
-
const input = await utils.findByRole("textbox");
|
|
114
|
+
const input = (await utils.findByRole("textbox"));
|
|
115
115
|
typeInInput(input, "1234");
|
|
116
|
-
expect(input).
|
|
116
|
+
expect(input.value).toBe("12 34/");
|
|
117
117
|
clearInput(input);
|
|
118
118
|
typeInInput(input, "123456");
|
|
119
|
-
expect(input).
|
|
119
|
+
expect(input.value).toBe("12 34/56");
|
|
120
120
|
clearInput(input);
|
|
121
121
|
typeInInput(input, "12345678");
|
|
122
|
-
expect(input).
|
|
122
|
+
expect(input.value).toBe("12 34/56");
|
|
123
123
|
clearInput(input);
|
|
124
124
|
});
|