@swan-io/lake 3.0.0 → 3.2.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,4 +1,4 @@
|
|
|
1
|
-
import { DateFormat, DatePickerDate
|
|
1
|
+
import { DateFormat, DatePickerDate } from "@swan-io/shared-business/src/components/DatePicker";
|
|
2
2
|
import { ValidatorResult } from "react-ux-form";
|
|
3
3
|
import { Simplify } from "type-fest";
|
|
4
4
|
type Item<T> = {
|
|
@@ -22,8 +22,6 @@ export type FilterRadioDef<T> = {
|
|
|
22
22
|
export type FilterDateDef<Values = unknown> = {
|
|
23
23
|
type: "date";
|
|
24
24
|
label: string;
|
|
25
|
-
monthNames: MonthNames;
|
|
26
|
-
dayNames: WeekDayNames;
|
|
27
25
|
cancelText: string;
|
|
28
26
|
submitText: string;
|
|
29
27
|
noValueText: string;
|
|
@@ -154,11 +154,11 @@ function FilterCheckbox({ label, items, width, checkAllLabel, value, onValueChan
|
|
|
154
154
|
return (_jsxs(Pressable, { role: "radio", "aria-checked": isSelected, style: ({ hovered }) => [styles.radio, hovered && styles.itemHovered], onPress: onPress, children: [_jsx(LakeCheckbox, { value: isSelected }), _jsx(Space, { width: 12 }), _jsx(Text, { style: styles.itemLabel, children: item.label })] }));
|
|
155
155
|
} }), _jsx(Space, { height: 8 }), _jsx(View, { style: styles.buttonContainer, children: _jsx(LakeButton, { color: "current", onPress: save, children: applyButtonLabel }) }), _jsx(Space, { height: 24 })] }) })] }));
|
|
156
156
|
}
|
|
157
|
-
function FilterDate({ label,
|
|
157
|
+
function FilterDate({ label, initialValue, noValueText, cancelText, submitText, dateFormat, isSelectable, validate, onSave, onPressRemove, autoOpen = false, }) {
|
|
158
158
|
const inputRef = useRef(null);
|
|
159
159
|
const [visible, { close, toggle }] = useDisclosure(autoOpen);
|
|
160
160
|
const value = useMemo(() => (isNotNullish(initialValue) ? dayjs(initialValue).format(dateFormat) : ""), [initialValue, dateFormat]);
|
|
161
|
-
return (_jsxs(View, { style: styles.container, children: [_jsx(FilterTag, { label: label, onPress: toggle, ref: inputRef, onPressRemove: onPressRemove, isActive: visible, value: isNotNullish(initialValue) ? dayjs(initialValue).format(dateFormat) : noValueText }), _jsx(DatePickerModal, { visible: visible,
|
|
161
|
+
return (_jsxs(View, { style: styles.container, children: [_jsx(FilterTag, { label: label, onPress: toggle, ref: inputRef, onPressRemove: onPressRemove, isActive: visible, value: isNotNullish(initialValue) ? dayjs(initialValue).format(dateFormat) : noValueText }), _jsx(DatePickerModal, { visible: visible, format: dateFormat, firstWeekDay: "monday", label: label, cancelLabel: cancelText, confirmLabel: submitText, value: value, isSelectable: isSelectable, validate: validate, onChange: value => {
|
|
162
162
|
const formattedValue = dayjs(value, dateFormat, true).toJSON();
|
|
163
163
|
onSave(formattedValue);
|
|
164
164
|
}, onDissmiss: close })] }));
|
|
@@ -211,7 +211,7 @@ export const FiltersStack = ({ filters, openedFilters, definition, onChangeOpene
|
|
|
211
211
|
onChangeFilters({ ...filters, [filterName]: undefined });
|
|
212
212
|
onChangeOpened(openedFilters.filter(f => f !== filterName));
|
|
213
213
|
} })))
|
|
214
|
-
.with({ type: "date" }, ({ type, label,
|
|
214
|
+
.with({ type: "date" }, ({ type, label, noValueText, cancelText, submitText, dateFormat, isSelectable, validate, }) => (_jsx(FilterDate, { label: label, noValueText: noValueText, cancelText: cancelText, submitText: submitText, dateFormat: dateFormat, autoOpen: lastOpenedFilter === filterName, isSelectable: isSelectable ? date => isSelectable(date, filters) : undefined, validate: validate ? value => validate(value, filters) : undefined, initialValue: getFilterValue(type, filters, filterName), onSave: value => onChangeFilters({ ...filters, [filterName]: value }), onPressRemove: () => {
|
|
215
215
|
onChangeFilters({ ...filters, [filterName]: undefined });
|
|
216
216
|
onChangeOpened(openedFilters.filter(f => f !== filterName));
|
|
217
217
|
} })))
|
|
@@ -15,6 +15,7 @@ export type LakeTextInputProps = Except<TextInputProps, "editable" | "keyboardTy
|
|
|
15
15
|
multiline?: boolean;
|
|
16
16
|
icon?: IconName;
|
|
17
17
|
unit?: string;
|
|
18
|
+
units?: string[];
|
|
18
19
|
inputMode?: TextInputProps["inputMode"];
|
|
19
20
|
pattern?: string;
|
|
20
21
|
children?: ReactNode;
|
|
@@ -22,6 +23,7 @@ export type LakeTextInputProps = Except<TextInputProps, "editable" | "keyboardTy
|
|
|
22
23
|
style?: TextInputProps["style"];
|
|
23
24
|
containerStyle?: ViewProps["style"];
|
|
24
25
|
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
26
|
+
onUnitChange?: (value: string) => void;
|
|
25
27
|
maxCharCount?: number;
|
|
26
28
|
help?: string;
|
|
27
29
|
renderEnd?: () => ReactNode;
|
|
@@ -229,6 +231,7 @@ export declare const LakeTextInput: import("react").ForwardRefExoticComponent<{
|
|
|
229
231
|
multiline?: boolean | undefined;
|
|
230
232
|
icon?: "lake-building-bank" | "lake-calendar-arrow-swap" | "lake-card" | "lake-card-add" | "lake-card-filled" | "lake-card-one-off" | "lake-card-physical" | "lake-card-recurring" | "lake-card-single-use" | "lake-card-virtual" | "lake-chevron-double" | "lake-clipboard-bullet" | "lake-clock" | "lake-clock-arrow-swap" | "lake-close" | "lake-currencies" | "lake-delivery-grouped" | "lake-delivery-individual" | "lake-document-csv" | "lake-document-jpg" | "lake-document-pdf" | "lake-document-png" | "lake-document-xls" | "lake-email" | "lake-id-card" | "lake-inbox-empty" | "lake-menu" | "lake-people" | "lake-person-arrow-swap" | "lake-phone" | "lake-receipt" | "lake-settings" | "lake-signature" | "lake-transfer" | "lake-world-map" | "add-circle-filled" | "add-circle-regular" | "add-filled" | "approvals-app-filled" | "apps-list-filled" | "apps-list-regular" | "arrow-counterclockwise-filled" | "arrow-clockwise-filled" | "arrow-down-filled" | "arrow-down-regular" | "arrow-download-filled" | "arrow-left-filled" | "arrow-left-regular" | "arrow-right-filled" | "arrow-right-regular" | "arrow-swap-filled" | "arrow-swap-regular" | "arrow-up-filled" | "arrow-up-regular" | "arrow-upload-filled" | "arrow-upload-regular" | "beaker-filled" | "beaker-regular" | "board-filled" | "board-regular" | "box-regular" | "building-bank-filled" | "building-bank-regular" | "building-filled" | "building-multiple-regular" | "building-regular" | "building-shop-regular" | "calendar-ltr-regular" | "cart-regular" | "chat-help-filled" | "chat-help-regular" | "check-filled" | "check-regular" | "checkmark-circle-regular" | "checkmark-filled" | "chevron-down-filled" | "chevron-left-filled" | "chevron-right-filled" | "chevron-up-down-regular" | "chevron-up-filled" | "clipboard-search-regular" | "clock-filled" | "clock-regular" | "cloud-sync-filled" | "cloud-sync-regular" | "code-filled" | "code-regular" | "color-regular" | "comment-note-regular" | "copy-filled" | "copy-regular" | "cursor-click-regular" | "database-filled" | "database-regular" | "delete-filled" | "delete-regular" | "desktop-regular" | "device-meeting-room-regular" | "dismiss-circle-regular" | "dismiss-filled" | "dismiss-regular" | "document-regular" | "earth-regular" | "edit-filled" | "edit-regular" | "error-circle-filled" | "error-circle-regular" | "eye-filled" | "eye-off-filled" | "eye-regular" | "filter-filled" | "flag-filled" | "flag-regular" | "flash-filled" | "flash-regular" | "form-new-filled" | "form-new-regular" | "hand-right-regular" | "image-add-filled" | "image-add-regular" | "image-filled" | "image-regular" | "info-filled" | "info-regular" | "key-regular" | "link-filled" | "live-filled" | "live-regular" | "lock-closed-filled" | "lock-closed-regular" | "lock-open-filled" | "lock-open-regular" | "mail-filled" | "mail-regular" | "money-regular" | "more-vertical-filled" | "open-filled" | "open-regular" | "options-regular" | "paint-brush-filled" | "paint-brush-regular" | "pause-regular" | "payment-filled" | "payment-regular" | "people-add-regular" | "people-community-filled" | "people-community-regular" | "people-filled" | "people-regular" | "people-team-regular" | "person-accounts-filled" | "person-accounts-regular" | "person-add-regular" | "person-call-filled" | "person-call-regular" | "person-filled" | "person-lock-regular" | "person-regular" | "phone-filled" | "phone-regular" | "pin-regular" | "play-filled" | "play-regular" | "preview-link-filled" | "qr-code-regular" | "question-circle-regular" | "receipt-money-filled" | "receipt-money-regular" | "rocket-regular" | "search-filled" | "send-filled" | "send-regular" | "settings-filled" | "settings-regular" | "shield-checkmark-filled" | "shield-checkmark-regular" | "shield-error-regular" | "shield-regular" | "sign-out-regular" | "signature-filled" | "signature-regular" | "subtract-circle-filled" | "subtract-circle-regular" | "target-arrow-regular" | "task-list-square-ltr-filled" | "task-list-square-ltr-regular" | "warning-filled" | "warning-regular" | "window-dev-tools-filled" | "window-dev-tools-regular" | undefined;
|
|
231
233
|
unit?: string | undefined;
|
|
234
|
+
units?: string[] | undefined;
|
|
232
235
|
inputMode?: TextInputProps["inputMode"];
|
|
233
236
|
pattern?: string | undefined;
|
|
234
237
|
children?: ReactNode;
|
|
@@ -236,6 +239,7 @@ export declare const LakeTextInput: import("react").ForwardRefExoticComponent<{
|
|
|
236
239
|
style?: TextInputProps["style"];
|
|
237
240
|
containerStyle?: ViewProps["style"];
|
|
238
241
|
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
242
|
+
onUnitChange?: ((value: string) => void) | undefined;
|
|
239
243
|
maxCharCount?: number | undefined;
|
|
240
244
|
help?: string | undefined;
|
|
241
245
|
renderEnd?: (() => ReactNode) | undefined;
|
|
@@ -10,6 +10,7 @@ import { isNotNullish, isNotNullishOrEmpty, isNullish } from "../utils/nullish";
|
|
|
10
10
|
import { Box } from "./Box";
|
|
11
11
|
import { Fill } from "./Fill";
|
|
12
12
|
import { Icon } from "./Icon";
|
|
13
|
+
import { LakeSelect } from "./LakeSelect";
|
|
13
14
|
import { LakeText } from "./LakeText";
|
|
14
15
|
const TRANSPARENT = "transparent";
|
|
15
16
|
const styles = StyleSheet.create({
|
|
@@ -106,6 +107,8 @@ const styles = StyleSheet.create({
|
|
|
106
107
|
borderWidth: 1,
|
|
107
108
|
borderLeftWidth: 0,
|
|
108
109
|
flexShrink: 0,
|
|
110
|
+
borderTopLeftRadius: 0,
|
|
111
|
+
borderBottomLeftRadius: 0,
|
|
109
112
|
},
|
|
110
113
|
unitDisabled: {
|
|
111
114
|
borderColor: colors.gray[50],
|
|
@@ -121,7 +124,7 @@ const styles = StyleSheet.create({
|
|
|
121
124
|
paddingTop: spacings[4],
|
|
122
125
|
},
|
|
123
126
|
});
|
|
124
|
-
export const LakeTextInput = forwardRef(({ ariaExpanded, ariaControls, error, disabled = false, validating = false, valid = false, readOnly = false, icon, children, unit, color = "gray", inputMode = "text", hideErrors = false, onChange, pattern, style: stylesFromProps, containerStyle: containerStylesFromProps, onFocus: originalOnFocus, onBlur: originalOnBlur, value, defaultValue, multiline = false, containerRef,
|
|
127
|
+
export const LakeTextInput = forwardRef(({ ariaExpanded, ariaControls, error, disabled = false, validating = false, valid = false, readOnly = false, icon, children, unit, units, color = "gray", inputMode = "text", hideErrors = false, onChange, onUnitChange, pattern, style: stylesFromProps, containerStyle: containerStylesFromProps, onFocus: originalOnFocus, onBlur: originalOnBlur, value, defaultValue, multiline = false, containerRef,
|
|
125
128
|
//maxCharCount is different from maxLength(props inherited of TextInput)
|
|
126
129
|
//maxLength truncates the text in the limitation asked,
|
|
127
130
|
//maxCharCount doesn't have limitation but displays a counter of characters
|
|
@@ -154,7 +157,7 @@ maxCharCount, help, renderEnd, ...props }, forwardRef) => {
|
|
|
154
157
|
disabled && styles.disabled,
|
|
155
158
|
readOnly && styles.readOnly,
|
|
156
159
|
isFocused && styles.focused,
|
|
157
|
-
isNotNullish(unit) && styles.inputWithUnit,
|
|
160
|
+
isNotNullish(unit ?? units) && styles.inputWithUnit,
|
|
158
161
|
hasError && styles.error,
|
|
159
162
|
valid && styles.valid,
|
|
160
163
|
stylesFromProps,
|
|
@@ -164,5 +167,5 @@ maxCharCount, help, renderEnd, ...props }, forwardRef) => {
|
|
|
164
167
|
readOnly && hasError && styles.readOnlyError,
|
|
165
168
|
disabled && styles.disabled,
|
|
166
169
|
readOnly && styles.readOnly,
|
|
167
|
-
] }), isNotNullish(renderEnd) && _jsx(View, { style: styles.endComponents, children: renderEnd() }), validating && (_jsx(ActivityIndicator, { size: "small", style: styles.endIcon, color: colors.current[500] })), !validating && hasError && (_jsx(Icon, { name: "warning-regular", size: 20, color: colors.negative[400], style: [styles.endIcon, readOnly && styles.readOnlyEndIcon] })), !validating && !hasError && valid && (_jsx(Icon, { name: "checkmark-filled", size: 20, color: colors.positive[400], style: [styles.endIcon, readOnly && styles.readOnlyEndIcon] }))] }), isNotNullish(unit) && (_jsx(LakeText, { color: colors.gray[900], style: [styles.unit, (disabled || readOnly) && styles.unitDisabled], children: unit }))] }), children] }), !hideErrors && (_jsxs(Box, { direction: "row", style: styles.errorContainer, children: [isNotNullish(error) ? (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], children: error })) : (_jsx(LakeText, { variant: "smallRegular", color: colors.gray[500], children: help ?? " " })), isNotNullish(maxCharCount) && (_jsxs(_Fragment, { children: [_jsx(Fill, { minWidth: 4 }), _jsxs(LakeText, { variant: "smallRegular", color: charCount > maxCharCount ? colors.negative[500] : colors.gray[400], style: styles.descriptionLimitation, children: [charCount, " / ", maxCharCount] })] }))] }))] }));
|
|
170
|
+
] }), isNotNullish(renderEnd) && _jsx(View, { style: styles.endComponents, children: renderEnd() }), validating && (_jsx(ActivityIndicator, { size: "small", style: styles.endIcon, color: colors.current[500] })), !validating && hasError && (_jsx(Icon, { name: "warning-regular", size: 20, color: colors.negative[400], style: [styles.endIcon, readOnly && styles.readOnlyEndIcon] })), !validating && !hasError && valid && (_jsx(Icon, { name: "checkmark-filled", size: 20, color: colors.positive[400], style: [styles.endIcon, readOnly && styles.readOnlyEndIcon] }))] }), isNotNullish(units) && isNotNullish(onUnitChange) ? (_jsx(Box, { children: _jsx(LakeSelect, { value: unit, onValueChange: onUnitChange, items: units.map(value => ({ name: value, value })), disabled: disabled, style: [styles.unit, (disabled || readOnly) && styles.unitDisabled], mode: "borderless", hideErrors: true }) })) : isNotNullish(unit) ? (_jsx(LakeText, { color: colors.gray[900], style: [styles.unit, (disabled || readOnly) && styles.unitDisabled], children: unit })) : null] }), children] }), !hideErrors && (_jsxs(Box, { direction: "row", style: styles.errorContainer, children: [isNotNullish(error) ? (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], children: error })) : (_jsx(LakeText, { variant: "smallRegular", color: colors.gray[500], children: help ?? " " })), isNotNullish(maxCharCount) && (_jsxs(_Fragment, { children: [_jsx(Fill, { minWidth: 4 }), _jsxs(LakeText, { variant: "smallRegular", color: charCount > maxCharCount ? colors.negative[500] : colors.gray[400], style: styles.descriptionLimitation, children: [charCount, " / ", maxCharCount] })] }))] }))] }));
|
|
168
171
|
});
|