✨ Added custom color for buttons
This commit is contained in:
@@ -65,6 +65,7 @@ class UserSession(ormar.Model):
|
|||||||
class ABCDQuizAnswer(BaseModel):
|
class ABCDQuizAnswer(BaseModel):
|
||||||
right: bool
|
right: bool
|
||||||
answer: str
|
answer: str
|
||||||
|
color: str | None
|
||||||
|
|
||||||
|
|
||||||
class RangeQuizAnswer(BaseModel):
|
class RangeQuizAnswer(BaseModel):
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import { reach } from 'yup';
|
import { reach } from 'yup';
|
||||||
import { ABCDQuestionSchema } from '$lib/yupSchemas';
|
import { ABCDQuestionSchema } from '$lib/yupSchemas';
|
||||||
import { getLocalization } from '$lib/i18n';
|
import { getLocalization } from '$lib/i18n';
|
||||||
|
import { invertColor } from '$lib/helpers';
|
||||||
|
|
||||||
const { t } = getLocalization();
|
const { t } = getLocalization();
|
||||||
|
|
||||||
@@ -32,11 +33,6 @@
|
|||||||
{#if Array.isArray(data.questions[selected_question].answers)}
|
{#if Array.isArray(data.questions[selected_question].answers)}
|
||||||
{#each data.questions[selected_question].answers as answer, index}
|
{#each data.questions[selected_question].answers as answer, index}
|
||||||
<div
|
<div
|
||||||
on:contextmenu|preventDefault={() => {
|
|
||||||
data.questions[selected_question].answers.splice(index, 1);
|
|
||||||
data.questions[selected_question].answers =
|
|
||||||
data.questions[selected_question].answers;
|
|
||||||
}}
|
|
||||||
out:fade={{ duration: 150 }}
|
out:fade={{ duration: 150 }}
|
||||||
class="p-4 rounded-lg flex justify-center w-full transition"
|
class="p-4 rounded-lg flex justify-center w-full transition"
|
||||||
class:bg-red-500={!answer.right}
|
class:bg-red-500={!answer.right}
|
||||||
@@ -48,7 +44,13 @@
|
|||||||
<input
|
<input
|
||||||
bind:value={answer.answer}
|
bind:value={answer.answer}
|
||||||
type="text"
|
type="text"
|
||||||
class="bg-transparent border-b-2 border-dotted w-5/6 text-center"
|
on:contextmenu|preventDefault={() => {
|
||||||
|
data.questions[selected_question].answers.splice(index, 1);
|
||||||
|
data.questions[selected_question].answers =
|
||||||
|
data.questions[selected_question].answers;
|
||||||
|
}}
|
||||||
|
class="border-b-2 border-dotted w-5/6 text-center rounded-lg"
|
||||||
|
style="background-color: {answer.color ?? 'transparent'}"
|
||||||
placeholder="Empty..."
|
placeholder="Empty..."
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
@@ -90,6 +92,14 @@
|
|||||||
</svg>
|
</svg>
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
|
<input
|
||||||
|
class="rounded-lg p-1"
|
||||||
|
type="color"
|
||||||
|
bind:value={answer.color}
|
||||||
|
on:contextmenu|preventDefault={() => {
|
||||||
|
answer.color = null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const invertColor = (hexTripletColor: string): string => {
|
||||||
|
let color = hexTripletColor;
|
||||||
|
color = color.substring(1); // remove #
|
||||||
|
let color_int = parseInt(color, 16); // convert to integer
|
||||||
|
color_int = 0xffffff ^ color_int; // invert three bytes
|
||||||
|
color = color_int.toString(16); // convert to hex
|
||||||
|
color = ('000000' + color).slice(-6); // pad with leading zeros
|
||||||
|
color = '#' + color; // prepend #
|
||||||
|
return color;
|
||||||
|
};
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
import { socket } from '$lib/socket';
|
import { socket } from '$lib/socket';
|
||||||
import Spinner from '../Spinner.svelte';
|
import Spinner from '../Spinner.svelte';
|
||||||
import { getLocalization } from '$lib/i18n';
|
import { getLocalization } from '$lib/i18n';
|
||||||
|
import { invertColor } from '$lib/helpers';
|
||||||
|
|
||||||
const { t } = getLocalization();
|
const { t } = getLocalization();
|
||||||
|
|
||||||
@@ -86,7 +87,8 @@
|
|||||||
<div class="flex flex-wrap">
|
<div class="flex flex-wrap">
|
||||||
{#each question.answers as answer}
|
{#each question.answers as answer}
|
||||||
<button
|
<button
|
||||||
class="w-1/2 text-3xl bg-amber-700 my-2 disabled:opacity-60 border border-white"
|
class="w-1/2 text-3xl my-2 disabled:opacity-60 border border-white"
|
||||||
|
style="background-color: {answer.color ?? '#B45309'}"
|
||||||
disabled={selected_answer !== undefined}
|
disabled={selected_answer !== undefined}
|
||||||
on:click={() => selectAnswer(answer.answer)}>{answer.answer}</button
|
on:click={() => selectAnswer(answer.answer)}>{answer.answer}</button
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export interface Question {
|
|||||||
export interface Answer {
|
export interface Answer {
|
||||||
right: boolean;
|
right: boolean;
|
||||||
answer: string;
|
answer: string;
|
||||||
|
color?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EditorData {
|
export interface EditorData {
|
||||||
|
|||||||
Reference in New Issue
Block a user