@swan-io/lake 2.7.24 → 2.7.26
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 +1 -1
- package/src/components/BorderedIcon.d.ts +3 -2
- package/src/components/BorderedIcon.js +2 -2
- package/src/components/Card3dPreview.d.ts +1 -1
- package/src/components/Card3dPreview.js +22 -6
- package/src/components/LakeCombobox.d.ts +1 -1
- package/src/components/LakeCombobox.js +2 -2
- package/src/components/LakeSelect.d.ts +7 -3
- package/src/components/LakeSelect.js +7 -4
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColorVariants } from "../constants/design";
|
|
1
|
+
import { ColorVariants, Radii } from "../constants/design";
|
|
2
2
|
import { IconName } from "./Icon";
|
|
3
3
|
import { SpacingValue } from "./Space";
|
|
4
4
|
type Props = {
|
|
@@ -6,6 +6,7 @@ type Props = {
|
|
|
6
6
|
size?: number;
|
|
7
7
|
padding?: SpacingValue | 0;
|
|
8
8
|
color?: ColorVariants;
|
|
9
|
+
borderRadius?: Radii;
|
|
9
10
|
};
|
|
10
|
-
export declare const BorderedIcon: ({ name, size, padding, color }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const BorderedIcon: ({ name, size, padding, color, borderRadius, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
11
12
|
export {};
|
|
@@ -5,13 +5,12 @@ import { Box } from "./Box";
|
|
|
5
5
|
import { Icon } from "./Icon";
|
|
6
6
|
const styles = StyleSheet.create({
|
|
7
7
|
base: {
|
|
8
|
-
borderRadius: radii[8],
|
|
9
8
|
borderWidth: 1,
|
|
10
9
|
borderColor: colors.current[100],
|
|
11
10
|
backgroundColor: colors.current[50],
|
|
12
11
|
},
|
|
13
12
|
});
|
|
14
|
-
export const BorderedIcon = ({ name, size = 96, padding = 0, color = "current" }) => {
|
|
13
|
+
export const BorderedIcon = ({ name, size = 96, padding = 0, color = "current", borderRadius = 8, }) => {
|
|
15
14
|
const iconSize = size - padding * 2;
|
|
16
15
|
return (_jsx(Box, { alignItems: "center", justifyContent: "center", style: [
|
|
17
16
|
styles.base,
|
|
@@ -20,6 +19,7 @@ export const BorderedIcon = ({ name, size = 96, padding = 0, color = "current" }
|
|
|
20
19
|
height: size,
|
|
21
20
|
borderColor: colors[color][100],
|
|
22
21
|
backgroundColor: colors[color][50],
|
|
22
|
+
borderRadius: radii[borderRadius],
|
|
23
23
|
},
|
|
24
24
|
], children: _jsx(Icon, { name: name, size: iconSize, color: colors[color][500] }) }));
|
|
25
25
|
};
|
|
@@ -21,7 +21,7 @@ type CardParams = {
|
|
|
21
21
|
expirationDate: string;
|
|
22
22
|
cvv: string;
|
|
23
23
|
color: "Silver" | "Black";
|
|
24
|
-
logo: SVGElement | null;
|
|
24
|
+
logo: SVGElement | HTMLImageElement | null;
|
|
25
25
|
logoScale: number;
|
|
26
26
|
assetsUrls: Card3dAssetsUrls;
|
|
27
27
|
onSvgError?: (code: string) => void;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Environment, OrbitControls, Text, useGLTF, useTexture } from "@react-three/drei";
|
|
3
3
|
import { Canvas, useFrame } from "@react-three/fiber";
|
|
4
|
+
import { Result } from "@swan-io/boxed";
|
|
4
5
|
import { forwardRef, useEffect, useRef, useState } from "react";
|
|
5
6
|
import * as THREE from "three";
|
|
6
|
-
import { match } from "ts-pattern";
|
|
7
|
+
import { P, match } from "ts-pattern";
|
|
7
8
|
import { isNotNullish, isNullish } from "../utils/nullish";
|
|
8
9
|
import { createSvgImage, getMonochromeSvg } from "../utils/svg";
|
|
9
10
|
/*
|
|
@@ -26,6 +27,10 @@ And this texture is used as an alpha map on a plane.
|
|
|
26
27
|
To reproduce the shiny effect on the back of the card, we inject a custom shader in rainbow_mastercard material.
|
|
27
28
|
This custom shader chunk change the diffuse color depending on camera position.
|
|
28
29
|
*/
|
|
30
|
+
// Uses alpha channel instead of green to make pixel transparent on logo plane
|
|
31
|
+
const logoAlphaMapFragmentShader = `
|
|
32
|
+
diffuseColor.a *= texture2D(alphaMap, vAlphaMapUv).a;
|
|
33
|
+
`;
|
|
29
34
|
const shinyColorFragmentShader = `
|
|
30
35
|
float red = cameraPosition.x * cameraPosition.z;
|
|
31
36
|
float green = cameraPosition.y * cameraPosition.z;
|
|
@@ -140,10 +145,14 @@ export const Card = forwardRef(({ ownerName, cardNumber, expirationDate, cvv, co
|
|
|
140
145
|
setLogoData(null);
|
|
141
146
|
return;
|
|
142
147
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
const image = match(logo)
|
|
149
|
+
.with(P.instanceOf(HTMLImageElement), image => Result.Ok(image))
|
|
150
|
+
.otherwise(logo => {
|
|
151
|
+
// We transform the logo to white to be able to use it as alpha map
|
|
152
|
+
const whiteLogo = getMonochromeSvg(logo, "white");
|
|
153
|
+
// Convert to Image element to be able to use it as texture
|
|
154
|
+
return createSvgImage(whiteLogo);
|
|
155
|
+
});
|
|
147
156
|
if (image.isError()) {
|
|
148
157
|
handleSvgError.current?.(image.getError());
|
|
149
158
|
return;
|
|
@@ -168,7 +177,14 @@ export const Card = forwardRef(({ ownerName, cardNumber, expirationDate, cvv, co
|
|
|
168
177
|
CARD_WIDTH / 2 - LOGO_MARGIN_RIGHT,
|
|
169
178
|
CARD_HEIGHT / 2 - LOGO_MARGIN_TOP,
|
|
170
179
|
FRONT_TEXT_POSITION,
|
|
171
|
-
], scale: logoScale, children: isNotNullish(logoData) && (_jsxs("mesh", { position: [-logoData.size[0] / 2, -logoData.size[1] / 2, 0], children: [_jsx("planeGeometry", { args: logoData.size }), _jsx("meshStandardMaterial", {
|
|
180
|
+
], scale: logoScale, children: isNotNullish(logoData) && (_jsxs("mesh", { position: [-logoData.size[0] / 2, -logoData.size[1] / 2, 0], children: [_jsx("planeGeometry", { args: logoData.size }), _jsx("meshStandardMaterial", { ref: material => {
|
|
181
|
+
if (!material) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
material.onBeforeCompile = shader => {
|
|
185
|
+
shader.fragmentShader = shader.fragmentShader.replace("#include <alphamap_fragment>", logoAlphaMapFragmentShader);
|
|
186
|
+
};
|
|
187
|
+
}, color: match(color)
|
|
172
188
|
.with("Silver", () => 0x000000)
|
|
173
189
|
.with("Black", () => 0xffffff)
|
|
174
190
|
.exhaustive(), metalness: 0.1, roughness: 0.35, envMapIntensity: ENV_MAP_INTENSITY, transparent: true, alphaMap: logoData.alphaMap })] })) }), _jsx("mesh", { geometry: nodes.black_band.geometry, material: materials.black_band, position: [0, 1.774, BACK_TEXT_POSITION], rotation: [0, Math.PI / 2, 0] }), _jsx("mesh", { geometry: nodes.chip.geometry, material: materials.chip, position: [-2.78, 0.439, FRONT_TEXT_POSITION], rotation: [0, Math.PI / 2, 0] }), _jsx("mesh", { geometry: nodes.chip_pattern.geometry, material: materials.chip_pattern, position: [-2.778, 0.442, FRONT_TEXT_POSITION + 0.001], rotation: [0, Math.PI / 2, 0] }), _jsx("mesh", { geometry: nodes.mc_center.geometry, material: materials.mastercard_orange, position: [3.052, -1.832, FRONT_TEXT_POSITION], rotation: [Math.PI / 2, 0, 0] }), _jsx("mesh", { geometry: nodes.mc_left.geometry, material: materials.mastercard_red, position: [2.676, -1.773, FRONT_TEXT_POSITION], rotation: [Math.PI / 2, 0, 0] }), _jsx("mesh", { geometry: nodes.mc_right.geometry, material: materials.mastercard_yellow, position: [3.47, -1.773, FRONT_TEXT_POSITION], rotation: [-Math.PI / 2, 0, 0] }), _jsx("mesh", { geometry: nodes.metal_circle.geometry, material: materials.rainbow, position: [-2.33, -1.849, BACK_TEXT_POSITION], rotation: [-Math.PI / 2, Math.PI / 2, 0] }), _jsx("mesh", { geometry: nodes.metal_circle001.geometry, material: materials.rainbow_rough, position: [-2.629, -1.849, BACK_TEXT_POSITION - 0.001], rotation: [-Math.PI / 2, Math.PI / 2, 0], scale: [0.35, 1, 0.35] }), _jsx("mesh", { geometry: nodes.metal_circle002.geometry, material: materials.rainbow_rough, position: [-2.33, -1.849, BACK_TEXT_POSITION - 0.001], rotation: [-Math.PI / 2, Math.PI / 2, 0] }), _jsx("mesh", { geometry: nodes.metal_mastercard.geometry, material: materials.rainbow_mastercard, position: [0.914, -1.298, BACK_TEXT_POSITION - 0.001], rotation: [Math.PI / 2, 0, Math.PI], scale: 0.09 })] }) }));
|
|
@@ -27,7 +27,7 @@ export type LakeComboboxRef = {
|
|
|
27
27
|
close: () => void;
|
|
28
28
|
open: () => void;
|
|
29
29
|
};
|
|
30
|
-
declare const LakeComboboxWithRef: <I>({ inputRef, value, items, itemHeight, nbItemsDisplayed, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResultText, readOnly, id, error, hideErrors, }: LakeComboboxProps<I>,
|
|
30
|
+
declare const LakeComboboxWithRef: <I>({ inputRef, value, items, itemHeight, nbItemsDisplayed, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResultText, readOnly, id, error, hideErrors, }: LakeComboboxProps<I>, forwardedRef: ForwardedRef<LakeComboboxRef>) => import("react/jsx-runtime").JSX.Element;
|
|
31
31
|
export declare const LakeCombobox: <I>(props: LakeComboboxProps<I> & {
|
|
32
32
|
ref?: RefObject<LakeComboboxRef> | undefined;
|
|
33
33
|
}) => ReturnType<typeof LakeComboboxWithRef>;
|
|
@@ -78,7 +78,7 @@ const getItemLayout = (_data, index) => ({
|
|
|
78
78
|
offset: DEFAULT_ELEMENT_HEIGHT * index,
|
|
79
79
|
index,
|
|
80
80
|
});
|
|
81
|
-
const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEMENT_HEIGHT, nbItemsDisplayed = DEFAULT_NB_SUGGESTION_DISPLAYED, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled = false, emptyResultText, readOnly, id, error, hideErrors, },
|
|
81
|
+
const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEMENT_HEIGHT, nbItemsDisplayed = DEFAULT_NB_SUGGESTION_DISPLAYED, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled = false, emptyResultText, readOnly, id, error, hideErrors, }, forwardedRef) => {
|
|
82
82
|
const ref = useRef(null);
|
|
83
83
|
const inputTextRef = useMergeRefs(ref, inputRef);
|
|
84
84
|
const listRef = useRef(null);
|
|
@@ -92,7 +92,7 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
92
92
|
const open = useCallback(() => setState("opened"), []);
|
|
93
93
|
const close = useCallback(() => setState("closed"), []);
|
|
94
94
|
const dismiss = useCallback(() => setState("dismissed"), []);
|
|
95
|
-
useImperativeHandle(
|
|
95
|
+
useImperativeHandle(forwardedRef, () => {
|
|
96
96
|
return {
|
|
97
97
|
open,
|
|
98
98
|
close,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactElement, ReactNode } from "react";
|
|
2
|
-
import { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
1
|
+
import { ForwardedRef, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { StyleProp, TextStyle, View, ViewStyle } from "react-native";
|
|
3
3
|
import { ColorVariants } from "../constants/design";
|
|
4
4
|
import { IconName } from "./Icon";
|
|
5
5
|
export type Item<V> = {
|
|
@@ -27,4 +27,8 @@ export type SelectProps<V> = {
|
|
|
27
27
|
readOnly?: boolean;
|
|
28
28
|
style?: StyleProp<ViewStyle>;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
declare const LakeSelectWithRef: <V>({ title, items, valueStyle, size, color, disabled, mode, placeholder, readOnly, id, matchReferenceWidth, value, error, hideErrors, icon, onValueChange, PopoverFooter, style, }: SelectProps<V>, forwardedRef: ForwardedRef<View>) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare const LakeSelect: <I>(props: SelectProps<I> & {
|
|
32
|
+
ref?: ForwardedRef<View> | undefined;
|
|
33
|
+
}) => ReturnType<typeof LakeSelectWithRef>;
|
|
34
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useRef } from "react";
|
|
2
|
+
import { forwardRef, useCallback, useRef, } from "react";
|
|
3
3
|
import { FlatList, StyleSheet, View, } from "react-native";
|
|
4
4
|
import { commonStyles } from "../constants/commonStyles";
|
|
5
5
|
import { colors, invariantColors, radii, shadows, spacings, texts, } from "../constants/design";
|
|
6
6
|
import { useDisclosure } from "../hooks/useDisclosure";
|
|
7
|
+
import { useMergeRefs } from "../hooks/useMergeRefs";
|
|
7
8
|
import { getFocusableElements } from "../utils/a11y";
|
|
8
9
|
import { isNotNullish } from "../utils/nullish";
|
|
9
10
|
import { Box } from "./Box";
|
|
@@ -103,12 +104,13 @@ const styles = StyleSheet.create({
|
|
|
103
104
|
borderColor: colors.negative[500],
|
|
104
105
|
},
|
|
105
106
|
});
|
|
106
|
-
|
|
107
|
+
const LakeSelectWithRef = ({ title, items, valueStyle, size, color = "current", disabled = false, mode = "normal", placeholder, readOnly = false, id, matchReferenceWidth = true, value, error, hideErrors = false, icon, onValueChange, PopoverFooter, style, }, forwardedRef) => {
|
|
107
108
|
const inputRef = useRef(null);
|
|
108
109
|
const listRef = useRef(null);
|
|
109
110
|
const typingTimeoutRef = useRef(undefined);
|
|
110
111
|
const currentlyTypedRef = useRef(undefined);
|
|
111
112
|
const listItemRefs = useRef(Array(items.length));
|
|
113
|
+
const mergedRef = useMergeRefs(inputRef, forwardedRef);
|
|
112
114
|
const [visible, { close, open }] = useDisclosure(false);
|
|
113
115
|
const hasValue = isNotNullish(value);
|
|
114
116
|
const isSmall = size === "small";
|
|
@@ -141,7 +143,7 @@ export function LakeSelect({ title, items, valueStyle, size, color = "current",
|
|
|
141
143
|
}, 300);
|
|
142
144
|
}, [items, onValueChange, visible]);
|
|
143
145
|
const name = itemValue?.name ?? value;
|
|
144
|
-
return (_jsxs(View, { style: commonStyles.fill, children: [_jsx(Pressable, { id: id, ref:
|
|
146
|
+
return (_jsxs(View, { style: commonStyles.fill, children: [_jsx(Pressable, { id: id, ref: mergedRef, "aria-haspopup": "listbox", role: "button", "aria-expanded": visible, disabled: readOnly || disabled, style: ({ focused }) => [
|
|
145
147
|
mode === "normal" ? styles.normal : styles.borderless,
|
|
146
148
|
size === "small" && styles.small,
|
|
147
149
|
(disabled || readOnly) && styles.inputDisabled,
|
|
@@ -176,4 +178,5 @@ export function LakeSelect({ title, items, valueStyle, size, color = "current",
|
|
|
176
178
|
close();
|
|
177
179
|
}, children: [isNotNullish(item.icon) && (_jsxs(_Fragment, { children: [item.icon, _jsx(Space, { width: 12 })] })), _jsx(LakeText, { color: colors.gray[900], numberOfLines: 1, style: [styles.itemText, isSelected && styles.selected], children: item.name }), _jsx(Fill, { minWidth: 12 }), isSelected && (_jsx(Icon, { color: colors.positive[500], name: "checkmark-filled", size: 14 }))] }));
|
|
178
180
|
} }), PopoverFooter] })] }));
|
|
179
|
-
}
|
|
181
|
+
};
|
|
182
|
+
export const LakeSelect = forwardRef(LakeSelectWithRef);
|