Skip to content

Commit

Permalink
feat: add mode and description to quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeUrSelf committed Dec 23, 2024
1 parent 66d391f commit 441efe7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
7 changes: 3 additions & 4 deletions resources/js/Helpers/vDynamicTextAreaHeight.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { type DirectiveBinding } from 'vue'

function initDynamicHeightCalc(input: HTMLTextAreaElement & { _calculateDynamicHeight: () => void }, binding?: DirectiveBinding<boolean>) {
input.style.resize = 'none'
input._calculateDynamicHeight = () => calculateDynamicHeight(input, binding)

document.fonts.addEventListener('loadingdone', input._calculateDynamicHeight)
input.addEventListener('transitionend', input._calculateDynamicHeight)

input._calculateDynamicHeight()
input.style.resize = 'none'
input.style.overflowY = 'hidden'
}

function calculateDynamicHeight(input: HTMLTextAreaElement, binding?: DirectiveBinding<boolean>){
Expand All @@ -18,8 +17,8 @@ function calculateDynamicHeight(input: HTMLTextAreaElement, binding?: DirectiveB

// Reset the height to a minimal value to refresh scrollHeight.
// This ensures the textarea will shrink when text is removed.
input.style.height = '5px'
input.style.height = `${input.scrollHeight}px`
input.style.height = '0'
input.style.height = `${input.scrollHeight+1}px`
}

function removeDynamicHeightCalc(input: HTMLTextAreaElement & { _calculateDynamicHeight: () => void }) {
Expand Down
7 changes: 6 additions & 1 deletion resources/js/components/Crud/CrudInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const props = defineProps<{
error?: string
password?: boolean
large?: boolean
row?: boolean
column?: boolean
format?: (value: T) => any
} & InputProps>()
Expand All @@ -28,10 +30,12 @@ function handleInput() {
<template>
<div
class="flex gap-1 duration-200 min-h-7"
:class="{ 'text-sm text-gray-600' : !selected && !editing && !large, 'text-lg h-8': large }"
:class="{ 'text-sm text-gray-600' : !selected && !editing && !large, 'text-lg min-h-8': large }"
>
<InputWrapper
:label
:row
:column
:hide-content="!value && !editing"
:error="error"
:hide-error="!editing"
Expand All @@ -41,6 +45,7 @@ function handleInput() {
<b
v-if="!editing"
class="row-start-1 col-start-1"
:class="{'text-nowrap truncate': !selected}"
>
{{ format ? format(value) : value }}
</b>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/QuizzesPanel/QuizComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function toggleEditing(isEditing: boolean){
:errors="errors"
/>

<template v-if="selected">
<template v-if="selected && !quiz.isLocal">
<InputWrapper
v-for="(question, idx) of quiz.questions"
:key="getKey(question)"
Expand Down
42 changes: 42 additions & 0 deletions resources/js/components/QuizzesPanel/QuizHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CustomDatepicker from '@/components/Common/CustomDatepicker.vue'
import { formatDate } from '@/Helpers/Format'
import CrudInput from '@/components/Crud/CrudInput.vue'
import { computed } from 'vue'
import vDynamicTextAreaHeight from '@/Helpers/vDynamicTextAreaHeight'
defineProps<{
editing: boolean
Expand All @@ -12,6 +13,7 @@ defineProps<{
}>()
const quiz = defineModel<Quiz>({ required: true })
const publicAvailabityString = computed(() => quiz.value.isPublic ? 'Dostępny dla wszystkich' : 'Dostępny tylko dla zaproszonych')
const quizModeString = computed(() => quiz.value.isLocal ? 'Offline' : 'Online')
</script>

<template>
Expand Down Expand Up @@ -65,5 +67,45 @@ const publicAvailabityString = computed(() => quiz.value.isPublic ? 'Dostępny d
{{ publicAvailabityString }}
</button>
</CrudInput>

<CrudInput
v-model="quizModeString"
label="Tryb:"
:error="errors.is_local"
:editing
:selected
>
<button
class="font-bold text-primary border-b border-primary/30 hover:border-primary transition-colors"
@click="quiz.isLocal = !quiz.isLocal"
>
{{ quizModeString }}
</button>
</CrudInput>

<Transition>
<CrudInput
v-if="quiz.description || editing"
v-model="quiz.description"
label="Opis:"
:column="selected"
:error="errors.is_public"
:editing
:selected
>
<textarea
v-model="quiz.description"
v-dynamic-text-area-height
name="name"
autocomplete="off"
class="size-full bg-transparent outline-none font-bold"
:disabled="!editing"
:class="{
'border-b border-b-primary/30 duration-200 transition-colors hover:border-b-primary/60 text-primary' : editing,
'border-b-red' : errors.name
}"
/>
</CrudInput>
</Transition>
</div>
</template>

0 comments on commit 441efe7

Please sign in to comment.