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

Display question type components on mobile #258

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -11,10 +11,7 @@ import Toggle from 'shared/components/Toggle/Toggle';
import { DraggableProvidedDragHandleProps } from 'react-beautiful-dnd';
import clsx from 'clsx';
import { QuestionType } from '@prisma/client';
import EmojiIcon from 'shared/components/QuestionTypeIcons/EmojiIcon';
import InputIcon from 'shared/components/QuestionTypeIcons/InputIcon';
import ChoiceIcon from 'shared/components/QuestionTypeIcons/ChoiceIcon';
import RateIcon from 'shared/components/QuestionTypeIcons/RateIcon';
import QuestionTypeIcons from 'shared/components/QuestionTypeIcons/QuestionTypeIcons';

interface QuestionBlockWrapperProps {
index: number;
Expand Down Expand Up @@ -90,14 +87,11 @@ export default function QuestionBlockWrapper({
/>
</button>

<div className="mx-1 hidden h-[42px] w-[30px] items-center justify-center px-[1px] text-gray-400 sm:flex">
{type === QuestionType.EMOJI && <EmojiIcon />}
{type === QuestionType.INPUT && <InputIcon />}
{type === QuestionType.CHOICE && <ChoiceIcon />}
{type === QuestionType.RATE && <RateIcon />}
<div className="hidden sm:block">
<QuestionTypeIcons type={type} />
</div>

<div className=" w-full grow">
<div className="w-full grow">
<Input
placeholder={t('questionPlaceholder')}
onInput={handleQuestionChange}
Expand All @@ -110,27 +104,33 @@ export default function QuestionBlockWrapper({
</div>
</div>

{(isDraggingPossible || isRemovingPossible) && (
<div className="mb-2 flex w-full items-start justify-end gap-2 sm:w-auto">
{isDraggingPossible && (
<div
className="cursor-pointer rounded-md border bg-white p-[13px] shadow-sm hover:scale-95"
{...dragHandleProps}
>
<SelectorIcon className="w-[15px]" />
</div>
)}
{isRemovingPossible && (
<button
onClick={removeQuestion}
data-test-id={`remove-question-${index}`}
className="cursor-pointer rounded-md border bg-white p-[13px] shadow-sm hover:scale-95"
>
<TrashIcon className="w-[15px] text-red-700" />
</button>
)}
<div className="mb-2 flex w-full items-center justify-end gap-2 sm:mb-0 sm:w-auto">
<div className="mr-1 sm:hidden">
<QuestionTypeIcons type={type} />
</div>
)}

{(isDraggingPossible || isRemovingPossible) && (
<div className="flex gap-2">
{isDraggingPossible && (
<div
className="cursor-pointer rounded-md border bg-white p-[13px] shadow-sm hover:scale-95"
{...dragHandleProps}
>
<SelectorIcon className="w-[15px]" />
</div>
)}
{isRemovingPossible && (
<button
onClick={removeQuestion}
data-test-id={`remove-question-${index}`}
className="cursor-pointer rounded-md border bg-white p-[13px] shadow-sm hover:scale-95"
>
<TrashIcon className="w-[15px] text-red-700" />
</button>
)}
</div>
)}
</div>
</div>

{expanded && (
Expand Down
10 changes: 8 additions & 2 deletions src/shared/components/QuestionTypeIcons/EmojiIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { EmojiHappyIcon } from '@heroicons/react/outline';
import React from 'react';

export default function EmojiIcon() {
return <EmojiHappyIcon />;
interface EmojiIconProps {
'data-test-id'?: string;
}

const EmojiIcon: React.FC<EmojiIconProps> = ({ 'data-test-id': testId }) => {
return <EmojiHappyIcon data-test-id={testId} />;
};

export default EmojiIcon;
10 changes: 8 additions & 2 deletions src/shared/components/QuestionTypeIcons/InputIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { PencilIcon } from '@heroicons/react/outline';
import React from 'react';

export default function InputIcon() {
return <PencilIcon />;
interface InputIconProps {
'data-test-id'?: string;
}

const InputIcon: React.FC<InputIconProps> = ({ 'data-test-id': testId }) => {
return <PencilIcon data-test-id={testId} />;
};

export default InputIcon;
21 changes: 21 additions & 0 deletions src/shared/components/QuestionTypeIcons/QuestionTypeIcons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { QuestionType } from '@prisma/client';
import ChoiceIcon from 'shared/components/QuestionTypeIcons/ChoiceIcon';
import EmojiIcon from 'shared/components/QuestionTypeIcons/EmojiIcon';
import InputIcon from 'shared/components/QuestionTypeIcons/InputIcon';
import RateIcon from 'shared/components/QuestionTypeIcons/RateIcon';

interface QuestionTypeIconsProps {
type: QuestionType;
}

export default function QuestionTypeIcons({ type }: QuestionTypeIconsProps) {
return (
<div className="mx-1 flex h-[42px] w-[26px] items-center justify-center px-[1px] text-gray-400">
{type === QuestionType.EMOJI && <EmojiIcon />}
{type === QuestionType.INPUT && <InputIcon />}
{type === QuestionType.CHOICE && <ChoiceIcon />}
{type === QuestionType.RATE && <RateIcon />}
</div>
);
}
Loading