@swan-io/lake 4.3.3 → 4.4.0

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": "4.3.3",
3
+ "version": "4.4.0",
4
4
  "engines": {
5
5
  "node": ">=18.0.0",
6
6
  "yarn": "^1.22.0"
@@ -741,8 +741,8 @@ export const FixedListView = ({ data: originalData, mode = "tile", keyExtractor,
741
741
  },
742
742
  ], children: isLoading
743
743
  ? match(mode)
744
- .with("tile", () => (_jsx(FixedListViewPlaceholder, { count: loading.count, rowHeight: rowHeight, rowVerticalSpacing: rowVerticalSpacing, paddingHorizontal: 0 })))
745
- .with("plain", () => (_jsx(PlainListViewPlaceholder, { count: loading.count, rowHeight: rowHeight, rowVerticalSpacing: rowVerticalSpacing, paddingHorizontal: 0 })))
744
+ .with("tile", () => (_jsx(FixedListViewPlaceholder, { count: loading.count, headerHeight: headerHeight, rowHeight: rowHeight, rowVerticalSpacing: rowVerticalSpacing, paddingHorizontal: 0 })))
745
+ .with("plain", () => (_jsx(PlainListViewPlaceholder, { count: loading.count, headerHeight: headerHeight, rowHeight: rowHeight, rowVerticalSpacing: rowVerticalSpacing, paddingHorizontal: 0 })))
746
746
  .exhaustive()
747
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: [
748
748
  styles.stickyColumn,
@@ -3,6 +3,7 @@ type Props = {
3
3
  value: boolean;
4
4
  disabled?: boolean;
5
5
  color?: ColorVariants;
6
+ isError?: boolean;
6
7
  };
7
- export declare const LakeRadio: ({ value, disabled, color }: Props) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const LakeRadio: ({ value, disabled, color, isError, }: Props) => import("react/jsx-runtime").JSX.Element;
8
9
  export {};
@@ -14,6 +14,9 @@ const styles = StyleSheet.create({
14
14
  borderWidth: 1,
15
15
  borderColor: colors.gray[500],
16
16
  },
17
+ error: {
18
+ borderColor: colors.negative[500],
19
+ },
17
20
  innerCircle: {
18
21
  justifyContent: "center",
19
22
  alignItems: "center",
@@ -28,13 +31,14 @@ const styles = StyleSheet.create({
28
31
  transform: "scale(1)",
29
32
  },
30
33
  });
31
- export const LakeRadio = ({ value, disabled = false, color = "current" }) => (_jsx(View, { style: [
34
+ export const LakeRadio = ({ value, disabled = false, color = "current", isError = false, }) => (_jsx(View, { style: [
32
35
  styles.outerCircle,
33
36
  value && { borderColor: colors[color].primary },
34
37
  disabled && {
35
38
  borderColor: colors.gray[300],
36
39
  },
37
- ], role: "none", children: _jsx(View, { "aria-hidden": !value, style: [
40
+ isError && styles.error,
41
+ ], role: "none", "aria-invalid": isError, children: _jsx(View, { "aria-hidden": !value, style: [
38
42
  styles.innerCircle,
39
43
  { backgroundColor: colors[color].primary },
40
44
  disabled && {
@@ -64,7 +64,6 @@ const styles = StyleSheet.create({
64
64
  },
65
65
  listContent: {
66
66
  paddingVertical: 12,
67
- maxHeight: 300,
68
67
  },
69
68
  item: {
70
69
  display: "flex",
@@ -169,7 +168,7 @@ const LakeSelectWithRef = ({ title, items, valueStyle, size, color = "current",
169
168
  styles.itemText,
170
169
  styles.selectPlaceholder,
171
170
  isSmall && styles.selectSmallPlaceholder,
172
- ], children: placeholder ?? " " }))] }), _jsx(Fill, { minWidth: 8 }), !disabled && (_jsx(Icon, { color: colors.gray[900], name: visible ? "chevron-up-filled" : "chevron-down-filled", size: 16 }))] })] })) }), !hideErrors && (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], style: styles.errorText, children: error ?? " " })), _jsxs(Popover, { role: "listbox", matchReferenceMinWidth: matchReferenceWidth, onDismiss: close, referenceRef: inputRef, returnFocus: true, visible: visible, field: true, children: [isNotNullish(title) && (_jsxs(_Fragment, { children: [_jsx(LakeText, { variant: "semibold", color: colors.gray[900], style: styles.selectListTitle, children: title }), _jsx(Separator, {})] })), _jsx(FlatList, { role: "list", data: items, ref: listRef, contentContainerStyle: styles.listContent, onKeyDown: (event) => {
171
+ ], children: placeholder ?? " " }))] }), _jsx(Fill, { minWidth: 8 }), !disabled && (_jsx(Icon, { color: colors.gray[900], name: visible ? "chevron-up-filled" : "chevron-down-filled", size: 16 }))] })] })) }), !hideErrors && (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], style: styles.errorText, children: error ?? " " })), _jsxs(Popover, { role: "listbox", matchReferenceMinWidth: matchReferenceWidth, onDismiss: close, referenceRef: inputRef, returnFocus: true, visible: visible, children: [isNotNullish(title) && (_jsxs(_Fragment, { children: [_jsx(LakeText, { variant: "semibold", color: colors.gray[900], style: styles.selectListTitle, children: title }), _jsx(Separator, {})] })), _jsx(FlatList, { role: "list", data: items, ref: listRef, contentContainerStyle: styles.listContent, onKeyDown: (event) => {
173
172
  const { key } = event.nativeEvent;
174
173
  if (key === "ArrowDown" || key === "ArrowUp") {
175
174
  event.preventDefault();
@@ -10,6 +10,9 @@ export type RadioGroupProps<V> = {
10
10
  color?: ColorVariants;
11
11
  disabled?: boolean;
12
12
  value?: V;
13
+ error?: string;
14
+ help?: string;
15
+ hideErrors?: boolean;
13
16
  onValueChange: (value: V) => void;
14
17
  };
15
- export declare function RadioGroup<V>({ items, direction, color, disabled, value, onValueChange, }: RadioGroupProps<V>): import("react/jsx-runtime").JSX.Element;
18
+ export declare function RadioGroup<V>({ items, direction, color, disabled, hideErrors, error, help, value, onValueChange, }: RadioGroupProps<V>): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,8 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Fragment } from "react";
3
3
  import { StyleSheet } from "react-native";
4
- import { colors } from "../constants/design";
5
- import { isNullish } from "../utils/nullish";
4
+ import { colors, spacings } from "../constants/design";
5
+ import { isNotNullishOrEmpty, isNullish } from "../utils/nullish";
6
6
  import { Box } from "./Box";
7
7
  import { LakeRadio } from "./LakeRadio";
8
8
  import { LakeText } from "./LakeText";
@@ -18,26 +18,30 @@ const styles = StyleSheet.create({
18
18
  },
19
19
  withRightSpace: {
20
20
  // use margin instead of <Space /> to avoid line starting with <Space /> because of flex-wrap
21
- marginRight: 24,
21
+ marginRight: spacings[24],
22
22
  },
23
23
  // We need this bottom margin in case there are too much items and some of them are wrapped to next line
24
24
  withBottomSpace: {
25
25
  // use margin instead of <Space /> to avoid making height bigger than expected
26
- marginBottom: 12,
26
+ marginBottom: spacings[12],
27
+ },
28
+ errorContainer: {
29
+ paddingTop: spacings[4],
27
30
  },
28
31
  });
29
- export function RadioGroup({ items, direction = "column", color = "current", disabled = false, value, onValueChange, }) {
30
- return (_jsx(Box, { direction: direction, style: styles.container, children: items.map((item, index) => {
31
- const isLast = index === items.length - 1;
32
- const isDisabled = disabled || !isNullish(item.disabled);
33
- return (_jsxs(Fragment, { children: [_jsxs(Pressable, { disabled: isDisabled, onPress: () => {
34
- if (item.value !== value) {
35
- onValueChange(item.value);
36
- }
37
- }, style: [
38
- styles.item,
39
- direction === "row" && styles.withBottomSpace,
40
- direction === "row" && !isLast && styles.withRightSpace,
41
- ], children: [_jsx(LakeRadio, { disabled: isDisabled, color: color, value: item.value === value }), _jsx(Space, { width: 12 }), _jsx(LakeText, { color: isDisabled ? colors.gray[300] : colors.gray[900], children: item.name })] }), !isLast && _jsx(Space, { height: direction === "column" ? 12 : undefined })] }, index));
42
- }) }));
32
+ export function RadioGroup({ items, direction = "column", color = "current", disabled = false, hideErrors = false, error, help, value, onValueChange, }) {
33
+ const hasError = isNotNullishOrEmpty(error);
34
+ return (_jsxs(_Fragment, { children: [_jsx(Box, { direction: direction, style: styles.container, children: items.map((item, index) => {
35
+ const isLast = index === items.length - 1;
36
+ const isDisabled = disabled || !isNullish(item.disabled);
37
+ return (_jsxs(Fragment, { children: [_jsxs(Pressable, { disabled: isDisabled, onPress: () => {
38
+ if (item.value !== value) {
39
+ onValueChange(item.value);
40
+ }
41
+ }, style: [
42
+ styles.item,
43
+ direction === "row" && styles.withBottomSpace,
44
+ direction === "row" && !isLast && styles.withRightSpace,
45
+ ], children: [_jsx(LakeRadio, { isError: hasError, disabled: isDisabled, color: color, value: item.value === value }), _jsx(Space, { width: 12 }), _jsx(LakeText, { color: isDisabled ? colors.gray[300] : colors.gray[900], children: item.name })] }), !isLast && _jsx(Space, { height: direction === "column" ? 12 : undefined })] }, index));
46
+ }) }), !hideErrors && (_jsx(Box, { direction: "row", style: styles.errorContainer, children: isNotNullishOrEmpty(error) ? (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], children: error })) : (_jsx(LakeText, { variant: "smallRegular", color: colors.gray[500], children: help ?? " " })) }))] }));
43
47
  }