Skip to content

Commit

Permalink
feat: improve essay and code tasks to render correctly with 1 row
Browse files Browse the repository at this point in the history
  • Loading branch information
procaconsul committed May 28, 2024
1 parent 9ffca8c commit 849adc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
23 changes: 11 additions & 12 deletions src/components/questionStructure/Task/variants/CodeTask.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextArea } from '@radix-ui/themes'
import { TextArea, TextField } from '@radix-ui/themes'
import React, { FC, useEffect, useState } from 'react'

import { TaskType } from '../constants'
Expand All @@ -20,15 +20,14 @@ export const CodeTask: FC<CodeTaskProps> = ({
const [inputValue, setInputValue] = useState(answer)
useEffect(() => onAnswerUpdate(inputValue), [inputValue, onAnswerUpdate])

return (
<TextArea
value={inputValue}
onChange={defaultOnChangeHandler(setInputValue)}
className="monospaced"
variant="soft"
placeholder="Your answer here…"
rows={lines}
disabled={disabled}
/>
)
const commonProps = {
value: inputValue,
onChange: defaultOnChangeHandler(setInputValue),
placeholder: 'Your answer here…',
disabled: disabled,
variant: 'soft' as 'soft',
className: 'monospaced',
}
if (lines === 1) return <TextField.Root {...commonProps} />
return <TextArea {...commonProps} rows={lines} />
}
22 changes: 10 additions & 12 deletions src/components/questionStructure/Task/variants/EssayTask.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextArea } from '@radix-ui/themes'
import { TextArea, TextField } from '@radix-ui/themes'
import React, { FC, useEffect, useState } from 'react'

import { TaskType } from '../constants'
Expand All @@ -18,15 +18,13 @@ export const EssayTask: FC<EssayTaskProps> = ({
}) => {
const [inputValue, setInputValue] = useState(answer)
useEffect(() => onAnswerUpdate(inputValue), [inputValue, onAnswerUpdate])

return (
<TextArea
value={inputValue}
onChange={defaultOnChangeHandler(setInputValue)}
variant="soft"
placeholder="Your answer here…"
rows={lines}
disabled={disabled}
/>
)
const commonProps = {
value: inputValue,
onChange: defaultOnChangeHandler(setInputValue),
placeholder: 'Your answer here…',
disabled: disabled,
variant: 'soft' as 'soft',
}
if (lines === 1) return <TextField.Root {...commonProps} />
return <TextArea {...commonProps} rows={lines} />
}

0 comments on commit 849adc0

Please sign in to comment.