@swan-io/lake 2.7.36 → 2.7.38

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.36",
3
+ "version": "2.7.38",
4
4
  "engines": {
5
5
  "node": ">=18.0.0",
6
6
  "yarn": "^1.22.0"
@@ -6,6 +6,7 @@ type Props<T> = {
6
6
  value?: T;
7
7
  getId?: (item: T) => unknown;
8
8
  onChange: (value: T) => void;
9
+ disabled?: boolean;
9
10
  };
10
- export declare const ChoicePicker: <T>({ items, getId, large, renderItem, value, onChange, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const ChoicePicker: <T>({ items, getId, large, renderItem, value, disabled, onChange, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
11
12
  export {};
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { ScrollView, StyleSheet, View } from "react-native";
4
4
  import { match } from "ts-pattern";
5
+ import { commonStyles } from "../constants/commonStyles";
5
6
  import { breakpoints, negativeSpacings, spacings } from "../constants/design";
6
7
  import { useResponsive } from "../hooks/useResponsive";
7
8
  import { clampValue } from "../utils/math";
@@ -100,7 +101,7 @@ const styles = StyleSheet.create({
100
101
  },
101
102
  });
102
103
  const identity = (x) => x;
103
- export const ChoicePicker = ({ items, getId = identity, large = false, renderItem, value, onChange, }) => {
104
+ export const ChoicePicker = ({ items, getId = identity, large = false, renderItem, value, disabled = false, onChange, }) => {
104
105
  const containerRef = useRef(null);
105
106
  const { desktop } = useResponsive(breakpoints.medium);
106
107
  const [mobilePosition, setMobilePosition] = useState("start");
@@ -179,12 +180,13 @@ export const ChoicePicker = ({ items, getId = identity, large = false, renderIte
179
180
  styles.container,
180
181
  !desktop && styles.mobileContainer,
181
182
  !desktop && { width: `${items.length * 100}%` },
182
- ], children: items.map((item, index) => (_jsx(Pressable, { style: [
183
+ ], children: items.map((item, index) => (_jsx(Pressable, { disabled: disabled, style: [
183
184
  styles.item,
185
+ disabled && commonStyles.disabled,
184
186
  desktop && styles.itemAnimation,
185
187
  desktop && { animationDelay: `${200 + 100 * index}ms` },
186
188
  large && styles.itemLarge,
187
189
  !desktop && styles.itemSmallViewport,
188
190
  !desktop && { width: `${100 / items.length}%` },
189
- ], onPress: () => onChange(item), children: ({ hovered }) => (_jsx(Tile, { hovered: hovered, selected: value != null && getId(item) === getId(value), flexGrow: 1, children: _jsxs(View, { style: styles.tileContents, children: [_jsx(View, { style: styles.tileRenderedContents, children: renderItem(item) }), desktop && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 24 }), _jsx(LakeRadio, { value: value != null && getId(item) === getId(value) })] }))] }) })) }, String(index)))) }) }), !desktop && (_jsx(LakeButton, { icon: "chevron-left-filled", mode: "secondary", forceBackground: true, onPress: onPressPrevious, disabled: mobilePosition === "start", style: styles.leftButton })), !desktop && (_jsx(LakeButton, { icon: "chevron-right-filled", mode: "secondary", forceBackground: true, onPress: onPressNext, disabled: mobilePosition === "end", style: styles.rightButton }))] }));
191
+ ], onPress: () => onChange(item), children: ({ hovered }) => (_jsx(Tile, { hovered: hovered, selected: value != null && getId(item) === getId(value), flexGrow: 1, children: _jsxs(View, { style: styles.tileContents, children: [_jsx(View, { style: styles.tileRenderedContents, children: renderItem(item) }), desktop && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 24 }), _jsx(LakeRadio, { value: value != null && getId(item) === getId(value) })] }))] }) })) }, String(index)))) }) }), !desktop && (_jsx(LakeButton, { icon: "chevron-left-filled", mode: "secondary", forceBackground: true, onPress: onPressPrevious, disabled: mobilePosition === "start" || disabled, style: styles.leftButton })), !desktop && (_jsx(LakeButton, { icon: "chevron-right-filled", mode: "secondary", forceBackground: true, onPress: onPressNext, disabled: mobilePosition === "end" || disabled, style: styles.rightButton }))] }));
190
192
  };
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { Children, forwardRef, Fragment, memo } from "react";
3
3
  import { ActivityIndicator, StyleSheet, View, } from "react-native";
4
4
  import { match } from "ts-pattern";
5
+ import { commonStyles } from "../constants/commonStyles";
5
6
  import { backgroundColor, colors, invariantColors, radii, spacings, texts, } from "../constants/design";
6
7
  import { isNotNullish, isNullish } from "../utils/nullish";
7
8
  import { Icon } from "./Icon";
@@ -72,10 +73,6 @@ const styles = StyleSheet.create({
72
73
  },
73
74
  text: texts.semibold,
74
75
  textSmall: texts.smallSemibold,
75
- disabled: {
76
- cursor: "not-allowed",
77
- opacity: 0.3,
78
- },
79
76
  resetOpacity: {
80
77
  opacity: 1,
81
78
  },
@@ -116,7 +113,7 @@ export const LakeButton = memo(forwardRef(({ ariaControls, ariaExpanded, ariaLab
116
113
  hasIconStart && isSmall ? styles.withIconStartSmall : styles.withIconStart,
117
114
  hasIconEnd && (isSmall ? styles.withIconEndSmall : styles.withIconEnd),
118
115
  hasOnlyIcon && (isSmall ? styles.iconSmallOnly : styles.iconOnly),
119
- disabled && styles.disabled,
116
+ disabled && commonStyles.disabled,
120
117
  disabled && forceBackground && styles.resetOpacity,
121
118
  grow && styles.grow,
122
119
  match(mode)
@@ -5,7 +5,8 @@ export type SliderProps = {
5
5
  max: number;
6
6
  step: number;
7
7
  unit: string;
8
+ disabled?: boolean;
8
9
  onChange: (value: number) => void;
9
10
  };
10
11
  export declare const sliderBreakpoint: number;
11
- export declare const LakeSlider: ({ label, value, min, max, step, unit, onChange }: SliderProps) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const LakeSlider: ({ label, value, min, max, step, unit, disabled, onChange, }: SliderProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useState } from "react";
3
3
  import { StyleSheet, View } from "react-native";
4
+ import { commonStyles } from "../constants/commonStyles";
4
5
  import { breakpoints } from "../constants/design";
5
6
  import { Box } from "./Box";
6
7
  import { LakeLabel } from "./LakeLabel";
@@ -17,7 +18,7 @@ const styles = StyleSheet.create({
17
18
  },
18
19
  });
19
20
  export const sliderBreakpoint = breakpoints.tiny;
20
- export const LakeSlider = ({ label, value, min, max, step, unit, onChange }) => {
21
+ export const LakeSlider = ({ label, value, min, max, step, unit, disabled = false, onChange, }) => {
21
22
  const [dirtyValue, setDirtyValue] = useState(String(value));
22
23
  useEffect(() => {
23
24
  setDirtyValue(String(value));
@@ -27,5 +28,8 @@ export const LakeSlider = ({ label, value, min, max, step, unit, onChange }) =>
27
28
  setDirtyValue(String(cleanValue));
28
29
  onChange(cleanValue);
29
30
  }, [min, max, dirtyValue, onChange]);
30
- return (_jsx(ResponsiveContainer, { breakpoint: sliderBreakpoint, style: styles.container, children: ({ large }) => (_jsx(_Fragment, { children: large ? (_jsxs(_Fragment, { children: [_jsx(Box, { direction: "row", justifyContent: "end", children: _jsx(View, { children: _jsx(LakeTextInput, { style: styles.input, unit: unit, value: dirtyValue, onChangeText: setDirtyValue, onBlur: sanitizeInput, inputMode: "decimal" }) }) }), _jsx("input", { type: "range", min: min, max: max, step: step, value: value, onChange: event => onChange(Number(event.target.value)), style: { backgroundSize: `${((value - min) / (max - min)) * 100}% 100%` } })] })) : (_jsx(LakeLabel, { label: label, render: id => (_jsx(LakeTextInput, { id: id, unit: unit, value: dirtyValue, onChangeText: setDirtyValue, onBlur: sanitizeInput, inputMode: "decimal" })) })) })) }));
31
+ return (_jsx(ResponsiveContainer, { breakpoint: sliderBreakpoint, style: styles.container, children: ({ large }) => (_jsx(_Fragment, { children: large ? (_jsxs(_Fragment, { children: [_jsx(Box, { direction: "row", justifyContent: "end", children: _jsx(View, { children: _jsx(LakeTextInput, { style: styles.input, unit: unit, value: dirtyValue, onChangeText: setDirtyValue, onBlur: sanitizeInput, inputMode: "decimal", disabled: disabled }) }) }), _jsx("input", { type: "range", min: min, max: max, step: step, value: value, disabled: disabled, onChange: event => onChange(Number(event.target.value)), style: {
32
+ backgroundSize: `${((value - min) / (max - min)) * 100}% 100%`,
33
+ ...(disabled ? commonStyles.disabled : {}),
34
+ } })] })) : (_jsx(LakeLabel, { label: label, render: id => (_jsx(LakeTextInput, { id: id, unit: unit, value: dirtyValue, onChangeText: setDirtyValue, onBlur: sanitizeInput, inputMode: "decimal", disabled: disabled })) })) })) }));
31
35
  };
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useRef, useState } from "react";
3
3
  import { StyleSheet, View } from "react-native";
4
+ import { commonStyles } from "../constants/commonStyles";
4
5
  import { colors } from "../constants/design";
5
6
  import { Box } from "./Box";
6
7
  import { Icon } from "./Icon";
@@ -9,9 +10,6 @@ import { Pressable } from "./Pressable";
9
10
  const HEIGHT = 26;
10
11
  const BORDER_WIDTH = 1;
11
12
  const styles = StyleSheet.create({
12
- disabled: {
13
- opacity: 0.3,
14
- },
15
13
  switch: {
16
14
  userSelect: "none",
17
15
  flexDirection: "row",
@@ -57,7 +55,7 @@ export const Toggle = ({ onToggle, value, disabled = false, mode = "desktop", on
57
55
  }, () => { });
58
56
  }, [value]);
59
57
  useEffect(reajustLayout, [reajustLayout, value, isMobile, onLabel, offLabel]);
60
- return (_jsxs(Pressable, { style: [styles.switch, disabled && styles.disabled], onPress: () => onToggle(!value), "aria-disabled": disabled, "aria-checked": value, disabled: disabled, ref: containerRef, role: "switch", onLayout: reajustLayout, children: [_jsx(View, { style: [
58
+ return (_jsxs(Pressable, { style: [styles.switch, disabled && commonStyles.disabled], onPress: () => onToggle(!value), "aria-disabled": disabled, "aria-checked": value, disabled: disabled, ref: containerRef, role: "switch", onLayout: reajustLayout, children: [_jsx(View, { style: [
61
59
  styles.handle,
62
60
  handleStyle,
63
61
  {
@@ -32,6 +32,10 @@ export declare const commonStyles: {
32
32
  readonly hidden: {
33
33
  readonly visibility: "hidden";
34
34
  };
35
+ readonly disabled: {
36
+ readonly cursor: "not-allowed";
37
+ readonly opacity: 0.5;
38
+ };
35
39
  readonly view: {
36
40
  readonly alignItems: "stretch";
37
41
  readonly backgroundColor: "transparent";
@@ -41,6 +41,7 @@ export const commonStyles = {
41
41
  fill: { flexGrow: 1, flexShrink: 1 },
42
42
  fillNoShrink: { flexGrow: 1, flexShrink: 0 },
43
43
  hidden: { visibility: "hidden" },
44
+ disabled: { cursor: "not-allowed", opacity: 0.5 },
44
45
  view: viewStyle,
45
46
  visuallyHidden: visuallyHiddenStyle,
46
47
  };
@@ -4,3 +4,4 @@ export declare const last: <T>(array: readonly T[]) => T | undefined;
4
4
  export declare const partition: <T>(array: T[], predicate: (value: T) => boolean) => [T[], T[]];
5
5
  export declare const sortedIndexOf: <T>(array: T[], value: T) => number;
6
6
  export declare const groupBy: <T, K extends string>(array: T[], getGroupName: (item: T) => K) => Partial<Record<K, T[]>>;
7
+ export declare const intersection: <T>(arrayA: readonly T[], arrayB: readonly T[]) => T[];
@@ -69,3 +69,7 @@ export const groupBy = (array, getGroupName) => {
69
69
  });
70
70
  return grouped;
71
71
  };
72
+ export const intersection = (arrayA, arrayB) => {
73
+ const toKeep = new Set(arrayB);
74
+ return arrayA.filter(item => toKeep.has(item));
75
+ };