diff --git a/apps/mobile/app/components/dialog/dialog-container.js b/apps/mobile/app/components/dialog/dialog-container.tsx similarity index 69% rename from apps/mobile/app/components/dialog/dialog-container.js rename to apps/mobile/app/components/dialog/dialog-container.tsx index 4ed387e35..db2584fc0 100644 --- a/apps/mobile/app/components/dialog/dialog-container.js +++ b/apps/mobile/app/components/dialog/dialog-container.tsx @@ -18,25 +18,36 @@ along with this program. If not, see . */ import React from "react"; -import { View } from "react-native"; +import { View, ViewProps } from "react-native"; import { DDS } from "../../services/device-detection"; import { useThemeColors } from "@notesnook/theme"; import { getElevationStyle } from "../../utils/elevation"; -const DialogContainer = ({ width, height, ...restProps }) => { +const DialogContainer = ({ + width, + height, + style, + ...restProps +}: ViewProps & { + width?: any; + height?: any; +}) => { const { colors } = useThemeColors(); return ( ); }; diff --git a/apps/mobile/app/components/dialogs/color-picker/index.tsx b/apps/mobile/app/components/dialogs/color-picker/index.tsx new file mode 100644 index 000000000..a80d1060f --- /dev/null +++ b/apps/mobile/app/components/dialogs/color-picker/index.tsx @@ -0,0 +1,302 @@ +/* +This file is part of the Notesnook project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +import { isThemeColor, useThemeColors } from "@notesnook/theme"; +import React, { useRef, useState } from "react"; +import { TextInput, View } from "react-native"; +import { FlashList } from "react-native-actions-sheet"; +import Icon from "react-native-vector-icons/MaterialCommunityIcons"; +import { useSettingStore } from "../../../stores/use-setting-store"; +import { SIZE } from "../../../utils/size"; +import BaseDialog from "../../dialog/base-dialog"; +import DialogContainer from "../../dialog/dialog-container"; +import { Button } from "../../ui/button"; +import Input from "../../ui/input"; +import { PressableButton } from "../../ui/pressable"; +import { ToastManager } from "../../../services/event-manager"; +import { Toast } from "../../toast"; +import { db } from "../../../common/database"; +import { useRelationStore } from "../../../stores/use-relation-store"; +import { useMenuStore } from "../../../stores/use-menu-store"; +const arrayOfColors = [ + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7", + "#FF5733", + "#33FF57", + "#339DFF", + "#FF33E9", + "#E9FF33", + "#FF3395", + "#95FF33", + "#FF3369", + "#6933FF", + "#33FFC7" +]; +const HEX_COLOR_REGEX_ALPHA = + /^#(?:(?:[\da-fA-F]{3}){1,2}|(?:[\da-fA-F]{4}){1,2})$/; + +const convertToColorObjects = (colors: string[]) => { + const colorObjects = []; + for (let i = 0; i < colors.length; i += 3) { + colorObjects.push({ + colorOne: colors[i], + colorTwo: colors[i + 1], + colorThree: colors[i + 2] + }); + } + return colorObjects; +}; + +const ColorPicker = ({ + visible, + setVisible +}: { + visible: boolean; + setVisible: (value: boolean) => void; +}) => { + const [selectedColor, setSelectedColor] = useState(); + const { colors } = useThemeColors(); + const inputRef = useRef(null); + const title = useRef(); + + const renderItem = ({ + item + }: { + item: { colorOne: string; colorTwo: string; colorThree: string }; + }) => ( + + {Object.keys(item).map((key) => ( + { + const color = item[key as keyof typeof item]; + setSelectedColor(color); + inputRef.current?.setNativeProps({ + placeholder: color, + text: color + }); + }} + > + {selectedColor === item[key as keyof typeof item] ? ( + + ) : null} + + ))} + + ); + + return ( + { + setVisible(false); + useSettingStore.getState().setSheetKeyboardHandler(true); + }} + statusBarTranslucent={false} + centered + > + + + + + + + { + if (HEX_COLOR_REGEX_ALPHA.test(value)) { + setSelectedColor(value); + inputRef.current?.setNativeProps({ + placeholder: value, + text: value + }); + } + }} + /> + + + + { + title.current = value; + }} + placeholder={title.current || "Color title"} + /> + +