From 996c14afb9d81e962ef66b99bd869bce4f3688f0 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Wed, 6 Jan 2021 08:00:31 +0300 Subject: Breaks Up CSS Into Components Moves the styles from the CSS file, into emotion CSS in each component's file to make navigation easier, and keep CSS and JSX together.Drops raw-loader dependency. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- src/components/Question.tsx | 61 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) (limited to 'src/components/Question.tsx') diff --git a/src/components/Question.tsx b/src/components/Question.tsx index 1c0fb31..66c1668 100644 --- a/src/components/Question.tsx +++ b/src/components/Question.tsx @@ -1,8 +1,9 @@ /** @jsx jsx */ -import { jsx } from "@emotion/react"; +import { jsx, css } from "@emotion/react"; import React, { ChangeEvent } from "react"; import { Question, QuestionType } from "../api/question"; +import { selectable } from "../commonStyles"; import create_input from "./InputTypes"; const _skip_normal_state: Array = [ @@ -37,6 +38,7 @@ class RenderedQuestion extends React.Component { this.props.public_state.set(target, value); } + // This is here to allow dynamic selection between the general handler, and the textarea handler. handler(_: ChangeEvent): void {} // eslint-disable-line normal_handler(event: ChangeEvent): void { @@ -71,8 +73,8 @@ class RenderedQuestion extends React.Component { // Toggle checkbox class if (event.target.type == "checkbox" && event.target.parentElement !== null) { - event.target.parentElement.classList.toggle("unselected_checkbox_label"); - event.target.parentElement.classList.toggle("selected_checkbox_label"); + event.target.parentElement.classList.toggle("unselected"); + event.target.parentElement.classList.toggle("selected"); } } @@ -109,17 +111,56 @@ class RenderedQuestion extends React.Component { const question = this.props.question; if (question.type === QuestionType.Section) { - return
-

{question.name}

- { question.data["text"] ?

{question.data["text"]}

: "" } -
+ const styles = css` + h1 { + margin-bottom: 0; + } + + h3 { + margin-top: 0; + } + + h1, h3 { + text-align: center; + padding: 0 2rem; + } + + @media (max-width: 500px) { + h1, h3 { + padding: 0; + } + } + `; + + return
+

{question.name}

+ { question.data["text"] ?

{question.data["text"]}

: "" } +
; + } else { + const requiredStarStyles = css` + span { + display: none; + } + + .required { + display: inline-block; + position: relative; + + color: red; + + top: -0.2rem; + margin-left: 0.2rem; + } + `; + return
-

- {question.name}* +

+ {question.name}*

- { create_input(this.props, this.handler) }
+ { create_input(this.props, this.handler) } +
; } } -- cgit v1.2.3