Skip to content

Commit

Permalink
Tidy up defence box styles, including focus indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswilty committed Oct 4, 2023
1 parent a39a3b8 commit eae4fbd
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# JetBrains
.idea

# yarn v2
.yarn/cache
.yarn/unplugged
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/components/ControlPanel/ControlPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

.control-collapsible-section {
background-color: var(--control-body-background-colour);
margin-bottom: 12px;
border-radius: 8px;
overflow: hidden;
margin-bottom: 0.75rem;
border-radius: 0.5rem;
}

.control-collapsible-section-header {
background-color: var(--control-header-background-colour);
padding: 12px 14px;
padding: 0.75rem;
cursor: default;
outline-color: white;
border-radius: 8px;
}
86 changes: 42 additions & 44 deletions frontend/src/components/DefenceBox/DefenceMechanism.css
Original file line number Diff line number Diff line change
@@ -1,94 +1,92 @@
.defence-mechanism {
position: relative;
padding: 12px 14px;
cursor: default;
}

.defence-mechanism details summary {
font-size: 1rem;
font-style: normal;
font-weight: 400;
margin: 0;
.defence-mechanism > * {
padding: 0.75rem;
}

.defence-mechanism > .info-box {
font-size: 0.875rem;
margin-top: 4px;
}

.validation-text {
font-size: 0.875rem;
font-weight: 600;
.defence-mechanism > summary {
position: relative;
font-size: 1rem;
}

/*
* Modified from https://www.w3schools.com/howto/howto_css_switch.asp
*/

/* The switch - the box around the slider */
.switch {
.defence-mechanism label.switch {
position: absolute;
display: inline-block;
width: 29px;
height: 13px;
right: 16px;
top: 15px;
width: 2rem;
height: 1rem;
right: 0.75rem;
top: 0.75rem;
}

.switch:focus-within {
.defence-mechanism label.switch:focus-within {
outline: white auto 1px;
border-radius: 34px;
border-radius: 0.5rem;
}

/* Hide default HTML checkbox */
.switch input {
.defence-mechanism label.switch > input {
opacity: 0;
width: 0;
height: 0;
}

.defence-mechanism label.switch > input:checked + .slider {
background-color: var(--main-toggle-on-colour);
}

.defence-mechanism label.switch > input:focus + .slider {
box-shadow: 0 0 1px var(--main-toggle-on-colour);
}

.defence-mechanism label.switch > input:checked + .slider:before {
transform: translateX(1rem);
}

/* The slider */
.slider {
.defence-mechanism label.switch > .slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--main-toggle-off-colour);
-webkit-transition: 0.4s;
transition: 0.4s;
}

.slider:before {
position: absolute;
.defence-mechanism label.switch > .slider:before {
content: "";
height: 13px;
width: 13px;
position: absolute;
height: 1rem;
width: 1rem;
background-color: var(--main-toggle-ball-colour);
-webkit-transition: 0.4s;
transition: 0.4s;
}

input:checked + .slider {
background-color: var(--main-toggle-on-colour);
/* Rounded sliders */
.defence-mechanism label.switch > .slider.round {
border-radius: 0.5rem;
}

input:focus + .slider {
box-shadow: 0 0 1px var(--main-toggle-on-colour);
.defence-mechanism label.switch > .slider.round:before {
border-radius: 50%;
}

input:checked + .slider:before {
-webkit-transform: translateX(16px);
-ms-transform: translateX(16px);
transform: translateX(16px);
.defence-mechanism .info-box {
font-size: 0.875rem;
}

/* Rounded sliders */
.slider.round {
border-radius: 34px;
.defence-mechanism .info-box :first-child {
margin-top: 0;
}

.slider.round:before {
border-radius: 50%;
.defence-mechanism .info-box .validation-text {
font-size: inherit;
font-weight: 600;
}
84 changes: 42 additions & 42 deletions frontend/src/components/DefenceBox/DefenceMechanism.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,48 @@ function DefenceMechanism({
}

return (
<div className="defence-mechanism">
<details>
<summary>{defenceDetail.name}</summary>
<div className="info-box">
<p>{defenceDetail.info}</p>

{showConfigurations &&
defenceDetail.config.map((config) => {
return (
<DefenceConfiguration
key={config.id}
isActive={defenceDetail.isActive}
config={config}
setConfigurationValue={setConfigurationValue}
/>
);
})}

{isConfigured &&
(configValidated ? (
<p className="validation-text">
<TiTick /> defence successfully configured
</p>
) : (
<p className="validation-text">
<TiTimes /> invalid input - configuration failed
</p>
))}
</div>
</details>
<label className="switch">
<input
type="checkbox"
placeholder="defence-toggle"
onChange={toggleDefence}
// set checked if defence is active
checked={defenceDetail.isActive}
aria-label="toggle defence"
/>
<span className="slider round"></span>
</label>
</div>
<details className="defence-mechanism">
<summary>
<span>{defenceDetail.name}</span>
<label className="switch">
<input
type="checkbox"
placeholder="defence-toggle"
onChange={toggleDefence}
// set checked if defence is active
checked={defenceDetail.isActive}
aria-label="toggle defence"
/>
<span className="slider round"></span>
</label>
</summary>
<div className="info-box">
<p>{defenceDetail.info}</p>
{showConfigurations &&
defenceDetail.config.map((config) => {
return (
<DefenceConfiguration
key={config.id}
isActive={defenceDetail.isActive}
config={config}
setConfigurationValue={setConfigurationValue}
/>
);
})
}
{isConfigured &&
(configValidated ? (
<p className="validation-text">
<TiTick /> defence successfully configured
</p>
) : (
<p className="validation-text">
<TiTimes /> invalid input - configuration failed
</p>
))
}
</div>
</details>
);
}

Expand Down

0 comments on commit eae4fbd

Please sign in to comment.