@swan-io/lake 2.7.3 → 2.7.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/lake",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "engines": {
5
5
  "node": ">=18.0.0",
6
6
  "yarn": "^1.22.0"
@@ -65,9 +65,11 @@ export type FixedListViewProps<T, ExtraInfo> = {
65
65
  data: T[];
66
66
  keyExtractor: (item: T, index: number) => string;
67
67
  highlightedRowId?: string;
68
+ headerBackgroundColor?: string;
68
69
  headerHeight: number;
69
70
  rowHeight: number;
70
71
  rowVerticalSpacing: number;
72
+ horizontalPadding?: number;
71
73
  extraInfo: ExtraInfo;
72
74
  stickedToStartColumns?: ColumnConfig<T, ExtraInfo>[];
73
75
  columns: ColumnConfig<T, ExtraInfo>[];
@@ -82,7 +84,8 @@ export type FixedListViewProps<T, ExtraInfo> = {
82
84
  count: number;
83
85
  };
84
86
  };
85
- export declare const FixedListView: <T, ExtraInfo>({ data: originalData, mode, keyExtractor, highlightedRowId, rowHeight, rowVerticalSpacing, headerHeight, renderThreshold, stickedToStartColumns: initialStickedToStartColumns, columns: initialColumns, stickedToEndColumns: initialStickedToEndColumns, extraInfo, onEndReached, onEndReachedThresholdPx, getRowLink, renderEmptyList, loading, }: FixedListViewProps<T, ExtraInfo>) => import("react/jsx-runtime").JSX.Element;
87
+ export declare const SCROLLBAR_RESERVED_SPACE = 20;
88
+ export declare const FixedListView: <T, ExtraInfo>({ data: originalData, mode, keyExtractor, highlightedRowId, rowHeight, rowVerticalSpacing, horizontalPadding, headerBackgroundColor, headerHeight, renderThreshold, stickedToStartColumns: initialStickedToStartColumns, columns: initialColumns, stickedToEndColumns: initialStickedToEndColumns, extraInfo, onEndReached, onEndReachedThresholdPx, getRowLink, renderEmptyList, loading, }: FixedListViewProps<T, ExtraInfo>) => import("react/jsx-runtime").JSX.Element;
86
89
  type PlaceholderProps = {
87
90
  count: number;
88
91
  rowHeight: number;
@@ -50,7 +50,7 @@ import { LakeHeading } from "./LakeHeading";
50
50
  import { LakeText } from "./LakeText";
51
51
  import { Space } from "./Space";
52
52
  const HORIZONTAL_SAFE_AREA = 10;
53
- const SCROLLBAR_RESERVED_SPACE = 20;
53
+ export const SCROLLBAR_RESERVED_SPACE = 20;
54
54
  const styles = StyleSheet.create({
55
55
  root: {
56
56
  height: 1,
@@ -97,16 +97,12 @@ const styles = StyleSheet.create({
97
97
  top: 0,
98
98
  bottom: 0,
99
99
  right: "100%",
100
- width: HORIZONTAL_SAFE_AREA,
101
- backgroundColor: backgroundColor.default,
102
100
  },
103
101
  stickyColumnEndOverflow: {
104
102
  position: "absolute",
105
103
  top: 0,
106
104
  bottom: 0,
107
105
  left: "100%",
108
- width: HORIZONTAL_SAFE_AREA,
109
- backgroundColor: backgroundColor.default,
110
106
  },
111
107
  rowSegment: {
112
108
  position: "absolute",
@@ -128,7 +124,6 @@ const styles = StyleSheet.create({
128
124
  flexDirection: "row",
129
125
  alignItems: "stretch",
130
126
  zIndex: 2,
131
- backgroundColor: backgroundColor.default,
132
127
  },
133
128
  segment: {
134
129
  flexDirection: "row",
@@ -177,9 +172,6 @@ const styles = StyleSheet.create({
177
172
  flexDirection: "row",
178
173
  alignItems: "stretch",
179
174
  },
180
- stickyRow: {
181
- // overflow: "hidden",
182
- },
183
175
  evenRow: {
184
176
  backgroundColor: backgroundColor.accented,
185
177
  },
@@ -226,7 +218,6 @@ const styles = StyleSheet.create({
226
218
  transitionTimingFunction: "ease-in-out",
227
219
  },
228
220
  rowBackgroundContainerPlain: {
229
- backgroundColor: backgroundColor.default,
230
221
  left: -10,
231
222
  right: -10,
232
223
  boxShadow: `inset 0 -1px ${colors.gray[100]}`,
@@ -414,14 +405,15 @@ const findNextFocusableElement = (sortedCellIds, currentCellIndex, direction) =>
414
405
  };
415
406
  const EMPTY_COLUMNS = [];
416
407
  const ZERO = 0;
417
- export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor, highlightedRowId, rowHeight, rowVerticalSpacing, headerHeight, renderThreshold = 1000, stickedToStartColumns: initialStickedToStartColumns = EMPTY_COLUMNS, columns: initialColumns, stickedToEndColumns: initialStickedToEndColumns = EMPTY_COLUMNS, extraInfo, onEndReached, onEndReachedThresholdPx = 200, getRowLink, renderEmptyList, loading, }) => {
408
+ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor, highlightedRowId, rowHeight, rowVerticalSpacing, horizontalPadding = HORIZONTAL_SAFE_AREA, headerBackgroundColor = backgroundColor.default, headerHeight, renderThreshold = 1000, stickedToStartColumns: initialStickedToStartColumns = EMPTY_COLUMNS, columns: initialColumns, stickedToEndColumns: initialStickedToEndColumns = EMPTY_COLUMNS, extraInfo, onEndReached, onEndReachedThresholdPx = 200, getRowLink, renderEmptyList, loading, }) => {
418
409
  const [viewId] = useState(() => uuid());
419
410
  // Those three refs are used to synchronize the horizontal scroll in the center columns
420
411
  const centerHeadersRef = useRef(null);
421
412
  const centerColumnsRef = useRef(null);
422
413
  const horizontalScrollbarRef = useRef(null);
423
414
  const totalRowHeight = rowHeight + rowVerticalSpacing;
424
- const totalHeight = originalData.length * totalRowHeight + headerHeight;
415
+ const rowsHeight = originalData.length * totalRowHeight;
416
+ const totalHeight = headerHeight + rowsHeight;
425
417
  // It might seem off to use the range in state instead of storing scroll/layout and deriving it,
426
418
  // but it saves a lot of render phases by allowing to bail out from rendering when the range doesn't change
427
419
  const [{ data, range: [renderedRangeStartIndex, renderedRangeEndIndex], }, setDataAndRenderRange,] = useState({ data: originalData, range: [0, 20] });
@@ -560,7 +552,7 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
560
552
  now - lastHorizontalScroll.current.date > SCROLL_THRESHOLD_MS) {
561
553
  const scrollLeft = centerColumns.scrollLeft;
562
554
  setShouldShowStartGradient(scrollLeft > 0);
563
- setShouldShowEndGradient(centerColumns.scrollWidth - HORIZONTAL_SAFE_AREA * 2 >=
555
+ setShouldShowEndGradient(centerColumns.scrollWidth - horizontalPadding * 2 >=
564
556
  scrollLeft + centerColumns.clientWidth);
565
557
  centerHeaders.scrollLeft = scrollLeft;
566
558
  horizontalScrollbar.scrollLeft = scrollLeft;
@@ -573,7 +565,7 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
573
565
  now - lastHorizontalScroll.current.date > SCROLL_THRESHOLD_MS) {
574
566
  const scrollLeft = centerHeaders.scrollLeft;
575
567
  setShouldShowStartGradient(scrollLeft > 0);
576
- setShouldShowEndGradient(centerHeaders.scrollWidth - HORIZONTAL_SAFE_AREA * 2 >=
568
+ setShouldShowEndGradient(centerHeaders.scrollWidth - horizontalPadding * 2 >=
577
569
  scrollLeft + centerHeaders.clientWidth);
578
570
  centerColumns.scrollLeft = scrollLeft;
579
571
  horizontalScrollbar.scrollLeft = scrollLeft;
@@ -586,7 +578,7 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
586
578
  now - lastHorizontalScroll.current.date > SCROLL_THRESHOLD_MS) {
587
579
  const scrollLeft = horizontalScrollbar.scrollLeft;
588
580
  setShouldShowStartGradient(scrollLeft > 0);
589
- setShouldShowEndGradient(horizontalScrollbar.scrollWidth - HORIZONTAL_SAFE_AREA * 2 >=
581
+ setShouldShowEndGradient(horizontalScrollbar.scrollWidth - horizontalPadding * 2 >=
590
582
  scrollLeft + horizontalScrollbar.clientWidth);
591
583
  centerHeaders.scrollLeft = scrollLeft;
592
584
  centerColumns.scrollLeft = scrollLeft;
@@ -602,7 +594,7 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
602
594
  horizontalScrollbar.removeEventListener("scroll", onScrollbarScroll);
603
595
  };
604
596
  }
605
- }, []);
597
+ }, [horizontalPadding]);
606
598
  const onKeyDown = useCallback((event) => {
607
599
  const target = event.nativeEvent.target;
608
600
  const currentTarget = event.nativeEvent.currentTarget;
@@ -743,9 +735,9 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
743
735
  ], children: [_jsx(View, { "aria-busy": isLoading, style: [
744
736
  styles.loadingPlaceholder,
745
737
  {
746
- top: totalHeight,
747
- marginLeft: HORIZONTAL_SAFE_AREA * 2,
748
- marginRight: HORIZONTAL_SAFE_AREA * 2,
738
+ top: rowsHeight,
739
+ marginLeft: horizontalPadding * 2,
740
+ marginRight: horizontalPadding * 2,
749
741
  },
750
742
  ], children: isLoading
751
743
  ? match(mode)
@@ -755,30 +747,39 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
755
747
  : null }), _jsx(View, { style: [styles.backgroundRows, { top: headerHeight }], children: backgroundRows }), _jsxs(View, { style: styles.scrollContentContainer, ref: scrollContentsRef, children: [stickedToStartColumns.length > 0 ? (_jsxs(View, { style: [
756
748
  styles.stickyColumn,
757
749
  {
758
- width: stickedToStartColumnsWidth + HORIZONTAL_SAFE_AREA,
759
- paddingLeft: HORIZONTAL_SAFE_AREA,
750
+ width: stickedToStartColumnsWidth + horizontalPadding,
751
+ paddingLeft: horizontalPadding,
760
752
  },
761
- ], children: [_jsxs(View, { style: [styles.headingSegment, { height: headerHeight }], children: [_jsx(HeaderSegment, { columns: stickedToStartColumns, extraInfo: extraInfo, viewId: viewId, width: stickedToStartColumnsWidth }), _jsx(View, { style: styles.stickyColumnStartOverflow }), _jsx(View, { style: [styles.topGradient, isScrolled && styles.visibleTopGradient] })] }), _jsx(View, { style: [styles.stickyRow, { height: totalHeight }], children: startRows })] })) : null, _jsxs(View, { style: [
753
+ ], children: [_jsxs(View, { style: [
754
+ styles.headingSegment,
755
+ { height: headerHeight, backgroundColor: headerBackgroundColor },
756
+ ], children: [_jsx(HeaderSegment, { columns: stickedToStartColumns, extraInfo: extraInfo, viewId: viewId, width: stickedToStartColumnsWidth }), _jsx(View, { style: [
757
+ styles.stickyColumnStartOverflow,
758
+ { width: horizontalPadding, backgroundColor: headerBackgroundColor },
759
+ ] }), _jsx(View, { style: [styles.topGradient, isScrolled && styles.visibleTopGradient] })] }), _jsx(View, { style: { height: rowsHeight }, children: startRows })] })) : null, _jsxs(View, { style: [
762
760
  styles.centerColumnsContainer,
763
761
  {
764
- paddingLeft: stickedToStartColumns.length === 0 ? HORIZONTAL_SAFE_AREA : ZERO,
765
- paddingRight: stickedToEndColumns.length === 0 ? HORIZONTAL_SAFE_AREA : ZERO,
762
+ paddingLeft: stickedToStartColumns.length === 0 ? horizontalPadding : ZERO,
763
+ paddingRight: stickedToEndColumns.length === 0 ? horizontalPadding : ZERO,
766
764
  },
767
- ], children: [_jsxs(View, { style: [styles.headingSegment, { height: headerHeight }], children: [_jsx(ScrollView, { ref: centerHeadersRef, horizontal: true, onLayout: onCenterTrackLayout, style: styles.centerColumns, contentContainerStyle: {
765
+ ], children: [_jsxs(View, { style: [
766
+ styles.headingSegment,
767
+ { height: headerHeight, backgroundColor: headerBackgroundColor },
768
+ ], children: [_jsx(ScrollView, { ref: centerHeadersRef, horizontal: true, onLayout: onCenterTrackLayout, style: styles.centerColumns, contentContainerStyle: {
768
769
  minWidth: centerColumnsWidth +
769
- (stickedToStartColumns.length === 0 ? HORIZONTAL_SAFE_AREA : 0) +
770
- (stickedToEndColumns.length === 0 ? HORIZONTAL_SAFE_AREA : 0),
770
+ (stickedToStartColumns.length === 0 ? horizontalPadding : 0) +
771
+ (stickedToEndColumns.length === 0 ? horizontalPadding : 0),
771
772
  }, children: _jsx(HeaderSegment, { columns: columns, extraInfo: extraInfo, viewId: viewId, width: centerColumnsWidth }) }), _jsx(View, { style: [styles.topGradient, isScrolled && styles.visibleTopGradient] })] }), _jsx(ScrollView, { horizontal: true, ref: centerColumnsRef, style: styles.centerColumns, contentContainerStyle: [
772
773
  styles.centerColumnsContentContainer,
773
774
  {
774
775
  minWidth: centerColumnsWidth +
775
- (stickedToStartColumns.length === 0 ? HORIZONTAL_SAFE_AREA : 0) +
776
- (stickedToEndColumns.length === 0 ? HORIZONTAL_SAFE_AREA : 0),
776
+ (stickedToStartColumns.length === 0 ? horizontalPadding : 0) +
777
+ (stickedToEndColumns.length === 0 ? horizontalPadding : 0),
777
778
  },
778
779
  ], children: centerRows }), _jsx(ScrollView, { ref: horizontalScrollbarRef, horizontal: true, style: styles.horizontalScrollbar, contentContainerStyle: {
779
780
  minWidth: centerColumnsWidth +
780
- (stickedToStartColumns.length === 0 ? HORIZONTAL_SAFE_AREA : 0) +
781
- (stickedToEndColumns.length === 0 ? HORIZONTAL_SAFE_AREA : 0),
781
+ (stickedToStartColumns.length === 0 ? horizontalPadding : 0) +
782
+ (stickedToEndColumns.length === 0 ? horizontalPadding : 0),
782
783
  } }), stickedToStartColumns.length > 0 && hasHorizontalScroll ? (_jsx(View, { style: [
783
784
  styles.leftToRightGradient,
784
785
  {
@@ -798,10 +799,16 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
798
799
  ] })) : null] }), stickedToEndColumns.length > 0 ? (_jsxs(View, { style: [
799
800
  styles.stickyColumn,
800
801
  {
801
- width: stickedToEndColumnsWidth + HORIZONTAL_SAFE_AREA,
802
- paddingRight: HORIZONTAL_SAFE_AREA,
802
+ width: stickedToEndColumnsWidth + horizontalPadding,
803
+ paddingRight: horizontalPadding,
803
804
  },
804
- ], children: [_jsxs(View, { style: [styles.headingSegment, { height: headerHeight }], children: [_jsx(View, { style: styles.stickyColumnEndOverflow }), _jsx(HeaderSegment, { columns: stickedToEndColumns, extraInfo: extraInfo, viewId: viewId, width: stickedToEndColumnsWidth }), _jsx(View, { style: [styles.topGradient, isScrolled && styles.visibleTopGradient] })] }), _jsx(View, { style: [styles.stickyRow, { height: totalHeight }], children: endRows })] })) : null] })] }), data.length === 0 && isNotNullish(renderEmptyList) && !isLoading ? (_jsx(View, { style: styles.emptyListContainer, children: renderEmptyList() })) : null, _jsx(View, { ref: endFocusAnchorRef, tabIndex: 0 })] }));
805
+ ], children: [_jsxs(View, { style: [
806
+ styles.headingSegment,
807
+ { height: headerHeight, backgroundColor: headerBackgroundColor },
808
+ ], children: [_jsx(View, { style: [
809
+ styles.stickyColumnEndOverflow,
810
+ { width: horizontalPadding, backgroundColor: headerBackgroundColor },
811
+ ] }), _jsx(HeaderSegment, { columns: stickedToEndColumns, extraInfo: extraInfo, viewId: viewId, width: stickedToEndColumnsWidth }), _jsx(View, { style: [styles.topGradient, isScrolled && styles.visibleTopGradient] })] }), _jsx(View, { style: { height: rowsHeight }, children: endRows })] })) : null] })] }), data.length === 0 && isNotNullish(renderEmptyList) && !isLoading ? (_jsx(View, { style: styles.emptyListContainer, children: renderEmptyList() })) : null, _jsx(View, { ref: endFocusAnchorRef, tabIndex: 0 })] }));
805
812
  };
806
813
  export const FixedListViewPlaceholder = ({ count, rowHeight, rowVerticalSpacing, groupHeaderHeight, headerHeight, paddingHorizontal = HORIZONTAL_SAFE_AREA, }) => {
807
814
  const totalRowHeight = rowHeight + rowVerticalSpacing;
@@ -30,7 +30,7 @@ export declare const CopyableRegularTextCell: ({ variant, text, copyWording, cop
30
30
  copyWording: string;
31
31
  copiedWording: string;
32
32
  }) => import("react/jsx-runtime").JSX.Element;
33
- export declare const BalanceCell: ({ value, currency, originalValue, formatCurrency, textAlign, }: {
33
+ export declare const BalanceCell: ({ value, currency, originalValue, formatCurrency, textAlign, variant, }: {
34
34
  value: number;
35
35
  currency: string;
36
36
  originalValue?: {
@@ -39,11 +39,13 @@ export declare const BalanceCell: ({ value, currency, originalValue, formatCurre
39
39
  } | undefined;
40
40
  formatCurrency: (value: number, currency: string) => string;
41
41
  textAlign?: "left" | "right" | "center" | undefined;
42
+ variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
42
43
  }) => import("react/jsx-runtime").JSX.Element;
43
- export declare const LinkCell: ({ children, external, onPress, }: {
44
+ export declare const LinkCell: ({ children, external, onPress, variant, }: {
44
45
  children: ReactNode;
45
46
  onPress: () => void;
46
47
  external?: boolean | undefined;
48
+ variant?: "light" | "semibold" | "medium" | "regular" | "smallSemibold" | "smallMedium" | "smallRegular" | undefined;
47
49
  }) => import("react/jsx-runtime").JSX.Element;
48
50
  export declare const StartAlignedCell: ({ children }: {
49
51
  children: ReactNode;
@@ -123,8 +123,8 @@ export const CopyableRegularTextCell = ({ variant = "regular", text, copyWording
123
123
  return (_jsxs(View, { style: styles.cell, children: [_jsx(LakeTooltip, { placement: "top", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy" ? copyWording : copiedWording, containerStyle: styles.iconContainer, children: _jsx(Pressable, { role: "button", "aria-label": copyWording, onPress: onPress, style: ({ hovered }) => [styles.icon, hovered && styles.underline], children: ({ hovered }) => (_jsx(Icon, { name: hovered ? "copy-filled" : "copy-regular", color: "currentColor", size: 14 })) }) }), _jsx(Space, { width: 4 }), _jsx(LakeText, { color: colors.gray[900], style: styles.regularText, variant: variant, children: text })] }));
124
124
  };
125
125
  // TODO: handle `+` sign properly
126
- export const BalanceCell = ({ value, currency, originalValue, formatCurrency, textAlign = "right", }) => {
127
- return (_jsxs(View, { style: styles.balanceCellContainer, children: [_jsx(View, { style: styles.cell, children: _jsxs(LakeText, { align: textAlign, color: colors.gray[900], variant: "medium", style: [
126
+ export const BalanceCell = ({ value, currency, originalValue, formatCurrency, textAlign = "right", variant = "medium", }) => {
127
+ return (_jsxs(View, { style: styles.balanceCellContainer, children: [_jsx(View, { style: styles.cell, children: _jsxs(LakeText, { align: textAlign, color: colors.gray[900], variant: variant, style: [
128
128
  styles.mediumText,
129
129
  {
130
130
  justifyContent: match(textAlign)
@@ -137,11 +137,11 @@ export const BalanceCell = ({ value, currency, originalValue, formatCurrency, te
137
137
  value < 0 && { color: colors.negative.primary },
138
138
  ], children: [value > 0 && "+", formatCurrency(value, currency)] }) }), isNotNullish(originalValue) && originalValue.currency !== currency && (_jsx(View, { style: styles.cell, children: _jsxs(LakeText, { style: styles.mediumText, align: textAlign, color: colors.gray[500], variant: "smallRegular", children: [originalValue.value > 0 && "+", formatCurrency(originalValue.value, originalValue.currency)] }) }))] }));
139
139
  };
140
- export const LinkCell = ({ children, external = false, onPress, }) => {
140
+ export const LinkCell = ({ children, external = false, onPress, variant = "medium", }) => {
141
141
  return (_jsxs(View, { style: styles.cell, children: [_jsx(Pressable, { style: ({ hovered }) => [styles.icon, hovered && styles.underline], onPress: event => {
142
142
  event.preventDefault();
143
143
  onPress();
144
- }, children: _jsx(Icon, { size: 14, name: external ? "open-regular" : "arrow-right-filled" }) }), _jsx(Space, { width: 8 }), _jsx(LakeText, { color: colors.gray[900], variant: "medium", style: styles.mediumText, children: children })] }));
144
+ }, children: _jsx(Icon, { size: 14, name: external ? "open-regular" : "arrow-right-filled" }) }), _jsx(Space, { width: 8 }), _jsx(LakeText, { color: colors.gray[900], variant: variant, style: styles.mediumText, children: children })] }));
145
145
  };
146
146
  export const StartAlignedCell = ({ children }) => {
147
147
  return _jsx(View, { style: styles.cell, children: children });
@@ -43,11 +43,11 @@ const styles = StyleSheet.create({
43
43
  placeholderTextColor: colors.gray[400],
44
44
  color: colors.gray[900],
45
45
  paddingHorizontal: spacings[8],
46
- height: 40,
46
+ height: 38,
47
47
  minWidth: 0,
48
48
  },
49
49
  multilineInput: {
50
- height: "auto",
50
+ height: "100%",
51
51
  padding: spacings[8],
52
52
  },
53
53
  inputWithUnit: {