From 804a393ff86a7aab2cb5b3cdd7d90a26303b4eda Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 28 Sep 2023 11:00:50 -0500 Subject: [PATCH] move Tag, update styling --- src/view/com/Tag.tsx | 83 ++++++++++++++++++++++++++++++ src/view/com/composer/TagInput.tsx | 28 +--------- web/index.html | 21 +++++--- 3 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 src/view/com/Tag.tsx diff --git a/src/view/com/Tag.tsx b/src/view/com/Tag.tsx new file mode 100644 index 0000000000..cd71a73ac0 --- /dev/null +++ b/src/view/com/Tag.tsx @@ -0,0 +1,83 @@ +import React from 'react' +import {StyleSheet, Pressable} from 'react-native' +import { + FontAwesomeIcon, + FontAwesomeIconStyle, +} from '@fortawesome/react-native-fontawesome' + +import {usePalette} from 'lib/hooks/usePalette' +import {Text} from 'view/com/util/text/Text' + +export function Tag({value}: {value: string}) { + const pal = usePalette('default') + + return ( + + #{value} + + ) +} + +export function EditableTag({ + value, + onRemove, +}: { + value: string + onRemove: (tag: string) => void +}) { + const pal = usePalette('default') + const [hovered, setHovered] = React.useState(false) + + const hoverIn = React.useCallback(() => { + setHovered(true) + }, [setHovered]) + + const hoverOut = React.useCallback(() => { + setHovered(false) + }, [setHovered]) + + return ( + onRemove(value)} + onPointerEnter={hoverIn} + onPointerLeave={hoverOut} + style={state => [ + pal.border, + styles.tag, + { + opacity: hovered || state.pressed || state.focused ? 0.8 : 1, + outline: 0, + paddingRight: 6, + }, + ]}> + + #{value} + + + + ) +} + +const styles = StyleSheet.create({ + tag: { + flexDirection: 'row', + alignItems: 'center', + gap: 4, + paddingVertical: 3, + paddingHorizontal: 8, + borderRadius: 20, + overflow: 'hidden', + borderWidth: 1, + }, +}) diff --git a/src/view/com/composer/TagInput.tsx b/src/view/com/composer/TagInput.tsx index f575fff370..400494f082 100644 --- a/src/view/com/composer/TagInput.tsx +++ b/src/view/com/composer/TagInput.tsx @@ -5,7 +5,6 @@ import { StyleSheet, NativeSyntheticEvent, TextInputKeyPressEventData, - Pressable, } from 'react-native' import { FontAwesomeIcon, @@ -13,8 +12,8 @@ import { } from '@fortawesome/react-native-fontawesome' import {isWeb} from 'platform/detection' -import {Text} from 'view/com/util/text/Text' import {usePalette} from 'lib/hooks/usePalette' +import {EditableTag} from 'view/com/Tag' function uniq(tags: string[]) { return Array.from(new Set(tags)) @@ -34,29 +33,6 @@ function sanitize(tagString: string) { return tagString.trim().replace(/^#/, '') } -function Tag({ - tag, - removeTag, -}: { - tag: string - removeTag: (tag: string) => void -}) { - const pal = usePalette('default') - return ( - removeTag(tag)} - style={state => ({ - opacity: state.hovered || state.pressed || state.focused ? 0.8 : 1, - outline: 0, - })}> - - #{tag} - - - ) -} - export function TagInput({ max = 8, onChangeTags, @@ -130,7 +106,7 @@ export function TagInput({ /> )} {tags.map(tag => ( - + ))} {tags.length >= max ? null : (