mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
added selector component. all questions page fixes and improvements
This commit is contained in:
parent
5c779a657d
commit
dfc5c93022
9 changed files with 104 additions and 48 deletions
|
@ -6,8 +6,11 @@ function highlightText(text, toHighlight) {
|
|||
}
|
||||
try {
|
||||
const re = new RegExp(toHighlight, 'gi')
|
||||
const splitText = text.split(toHighlight)
|
||||
console.log(splitText)
|
||||
const splitText = text.split(re)
|
||||
if (splitText.length === 1) {
|
||||
return text
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{splitText[0]}
|
||||
|
|
48
src/components/Selector.jsx
Normal file
48
src/components/Selector.jsx
Normal file
|
@ -0,0 +1,48 @@
|
|||
import React, { useState } from 'react'
|
||||
import styles from './Selector.module.css'
|
||||
|
||||
export default function Selector(props) {
|
||||
const { activeItem, data, onSelect, getLength, getName } = props
|
||||
const [searchTerm, setSearchTerm] = useState('')
|
||||
|
||||
const dataToDisplay = data.filter((item) => {
|
||||
return getName(item).toLowerCase().includes(searchTerm.toLowerCase())
|
||||
})
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<input
|
||||
type={'text'}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
placeholder={'Kezdj el írni a kereséshez ...'}
|
||||
/>
|
||||
<div className="selector">
|
||||
{dataToDisplay.length === 0 && (
|
||||
<div className={styles.noResult}>
|
||||
<span className={styles.itemName}>{'Nincs találat'}</span>
|
||||
</div>
|
||||
)}
|
||||
{dataToDisplay.map((item, i) => {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
activeItem && getName(activeItem) === getName(item)
|
||||
? 'selectorItem activeSelectorItem'
|
||||
: 'selectorItem'
|
||||
}
|
||||
key={i}
|
||||
onClick={() => onSelect(item)}
|
||||
>
|
||||
<span className={styles.itemName}>{getName(item)}</span>
|
||||
{getLength && (
|
||||
<span className={styles.questionCount}>
|
||||
[ {getLength(item)} ]
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
23
src/components/Selector.module.css
Normal file
23
src/components/Selector.module.css
Normal file
|
@ -0,0 +1,23 @@
|
|||
.questionCount {
|
||||
justify-content: flex-end;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.itemName {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 450px
|
||||
}
|
||||
|
||||
.container input {
|
||||
border: 1px solid var(--text-color);
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.noResult {
|
||||
margin: 5px;
|
||||
text-align: center;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import React from 'react'
|
||||
import styles from './SubjectSelector.module.css'
|
||||
|
||||
export default function SubjectSelector(props) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue