Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search input clear and colors #876

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ interface InputProps {
id: string;
placeholder: string;
icon?: 'search';
iconPosition?: 'left' | 'right';
iconPosition?: 'left' | 'right' | 'both';
disabled?: boolean;
currentValue?: string;
handleChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
handleClear?: () => void;
}

const SearchInput: React.FC<InputProps> = ({
Expand All @@ -22,6 +23,7 @@ const SearchInput: React.FC<InputProps> = ({
disabled,
currentValue,
handleChange,
handleClear,
}) => {
SearchInput.defaultProps = {
iconPosition: undefined,
Expand All @@ -37,13 +39,14 @@ const SearchInput: React.FC<InputProps> = ({
direction="column"
>
{!!icon && (
<IconWrapper data-iconposition={iconPosition}>
<IconWrapper data-iconposition={iconPosition === 'both' ? 'left' : iconPosition}>
{icon === 'search' && (
<Icon
name="search"
css={{
width: '$24',
height: '$24',
color: '$primary400',
}}
/>
)}
Expand All @@ -64,6 +67,29 @@ const SearchInput: React.FC<InputProps> = ({
{placeholder}
</PlaceholderText>
</Flex>
<IconWrapper
data-iconposition={iconPosition === 'both' ? 'right' : iconPosition}
css={{
width: '$24',
height: '$24',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
borderRadius: '100%',
}}
onClick={handleClear}
>
<Icon
name="close"
size={16}
css={{
color: '$white',
backgroundColor: '$primary100',
borderRadius: '100%',
padding: '2px',
}}
/>
</IconWrapper>
</Flex>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const ListMembersDialog = React.memo<ListMembersDialogProps>(
setSearchMember(event.target.value);
};

const handleClearSearch = () => {
setSearchMember('');
};

const handleChecked = (id: string) => {
const updateCheckedUsers = usersChecked.map((user) =>
user._id === id ? { ...user, isChecked: !user.isChecked } : user,
Expand Down Expand Up @@ -137,8 +141,9 @@ const ListMembersDialog = React.memo<ListMembersDialogProps>(
<SearchInput
currentValue={searchMember}
handleChange={handleSearchChange}
handleClear={handleClearSearch}
icon="search"
iconPosition="left"
iconPosition="both"
id="search"
placeholder="Search member"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const PlaceholderText = styled(Text, {
'&[data-iconposition="right"]': {
pl: '$17',
},
'&[data-iconposition="both"]': {
pl: '$57',
},
});

const IconWrapper = styled(Flex, {
Expand All @@ -50,6 +53,9 @@ const IconWrapper = styled(Flex, {
'&[data-iconposition="right"]': {
right: '$16',
},
'&[data-iconposition="both"]': {
left: '$16',
},
'&[data-type="password"]': {
'&:hover': {
cursor: 'pointer',
Expand Down Expand Up @@ -174,6 +180,10 @@ const StyledInput = styled('input', {
'&[data-iconposition="right"]': {
pr: '$56',
},

'&[data-iconposition="both"]': {
px: '$56',
},
});

export { ButtonAddMember, IconWrapper, PlaceholderText, ScrollableContent, StyledInput };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TeamChecked, Team } from '@/types/team/team';
import isEmpty from '@/utils/isEmpty';
import Dialog from '@/components/Primitives/Dialog';
import { useQueryClient } from '@tanstack/react-query';
import SearchInput from './SearchInput';
import SearchInput from '@/components/Teams/CreateTeam/ListMembersDialog/SearchInput';
import { ScrollableContent } from './styles';

type Props = {
Expand Down Expand Up @@ -49,6 +49,10 @@ const ListTeams = ({ isOpen, setIsOpen, providerAccountCreatedAt, joinedAt }: Pr
setSearchTeam(event.target.value);
};

const handleClearSearch = () => {
setSearchTeam('');
};

const handleChecked = (id: string) => {
teamsUserIsNotMember = teamsUserIsNotMember.map((team) =>
team._id === id ? { ...team, isChecked: !team.isChecked } : team,
Expand Down Expand Up @@ -91,8 +95,9 @@ const ListTeams = ({ isOpen, setIsOpen, providerAccountCreatedAt, joinedAt }: Pr
<SearchInput
currentValue={searchTeam}
handleChange={handleSearchChange}
handleClear={handleClearSearch}
icon="search"
iconPosition="left"
iconPosition="both"
id="search"
placeholder="Search team"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const ListOfCards = React.memo(() => {
setSearch(event.target.value);
};

const handleClearSearch = () => {
setSearch('');
};

useEffect(() => {
const timer = setTimeout(() => {
fetchUsers.refetch();
Expand All @@ -87,11 +91,12 @@ const ListOfCards = React.memo(() => {
<Flex css={{ width: '460px' }} direction="column" gap={16}>
<SearchInput
icon="search"
iconPosition="left"
iconPosition="both"
id="search"
placeholder="Search user"
currentValue={search}
handleChange={handleSearchUser}
handleClear={handleClearSearch}
/>
</Flex>
</Flex>
Expand Down