aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/lib/utils.ts
diff options
context:
space:
mode:
authorDaniel Vigaru <22689627+danielvigaru@users.noreply.github.com>2025-02-02 01:20:21 +0200
committerGitHub <noreply@github.com>2025-02-01 23:20:21 +0000
commit5c147350eaafe5e32c731e187a1f907d1db93bad (patch)
treeaaba429188062d2135bb5a75c260e24143ad6e27 /apps/mobile/lib/utils.ts
parenta8ac16e713a95e41428b56ad0790a0a7d2453653 (diff)
downloadkarakeep-5c147350eaafe5e32c731e187a1f907d1db93bad.tar.zst
fix(mobile): margin for "Lists" tab content (#927)
* fix: left margin for list items * refactor: move type into func definition * fix: missing return type Co-authored-by: Joseph Chambers <5374985+imcodingideas@users.noreply.github.com> * style: remove trailing space --------- Co-authored-by: Joseph Chambers <5374985+imcodingideas@users.noreply.github.com>
Diffstat (limited to 'apps/mobile/lib/utils.ts')
-rw-r--r--apps/mobile/lib/utils.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/apps/mobile/lib/utils.ts b/apps/mobile/lib/utils.ts
index 88283f01..bfb6c9ed 100644
--- a/apps/mobile/lib/utils.ts
+++ b/apps/mobile/lib/utils.ts
@@ -5,3 +5,40 @@ import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
+
+/**
+ * Merge props conditionally.
+ *
+ * @example
+ * ```
+ * <View {...condProps(
+ * { condition: true, props: { className: "foo" } },
+ * { condition: true, props: { style: { margin: "10px" } } },
+ * )} />
+ * ```
+ * results in:
+ * ```
+ * <View className="foo" style={ margin: "10px" } />
+ * ```
+ * @example
+ * ```
+ * <View style={condProps(
+ * { condition: true, color: "red" },
+ * { condition: true, fontWeight: "bold" }
+ * )} />
+ * ```
+ * results in:
+ * ```
+ * <View style={ color: "red", fontWeight: "bold" } />
+ * ```
+ */
+export function condProps(
+ ...condProps: {
+ condition: boolean;
+ props: Record<string, unknown>;
+ }[]
+): Record<string, unknown> {
+ return condProps.reduce((acc, { condition, props }) => {
+ return condition ? { ...acc, ...props } : acc;
+ }, {});
+}