Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: toggle for wiki opening info display #15662

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/analyse/src/main/ui/AnalyseUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ final class AnalyseUi(helpers: Helpers)(externalEngineEndpoint: String):
)(v.name)
}
),
pov.game.variant.standard.option(div(cls := "analyse__wiki"))
pov.game.variant.standard.option(
fieldset(cls := "analyse__wiki empty toggle-box toggle-box--toggle", id := "wikibook-field")(
legend(tabindex := 0)("WikiBook"),
div(cls := "analyse__wiki-text")
)
)
)
),
div(cls := "analyse__board main-board")(chessgroundBoard),
Expand Down
6 changes: 3 additions & 3 deletions modules/ui/src/main/helper/Form3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ final class Form3(formHelper: FormHelper & I18nHelper, flairApi: FlairApi):
def fieldset(legend: Frag, toggle: Option[Boolean] = none): Tag =
st.fieldset(
cls := List(
"form-fieldset" -> true,
"form-fieldset--toggle" -> toggle.isDefined,
"form-fieldset--toggle-off" -> toggle.has(false)
"toggle-box" -> true,
"toggle-box--toggle" -> toggle.isDefined,
"toggle-box--toggle-off" -> toggle.has(false)
)
)(st.legend(toggle.map(_ => tabindex := 0))(legend))

Expand Down
10 changes: 8 additions & 2 deletions ui/analyse/css/_side.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
}
}
.analyse__wiki {
margin-top: 2vh;
margin: 2vh 0;
flex: 1 1 auto;
@include mq-at-least-col3 {
flex: 1 1 0;
padding: 0.5em 1em 0 0;
}

&.empty {
visibility: hidden;
}
}
}
Expand All @@ -30,6 +33,9 @@
}
&__wiki {
overflow-y: auto;
padding: 1rem 1rem 0 1rem;
scrollbar-gutter: stable both-edges;

p {
text-align: justify;
line-height: 1.5;
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/css/build/analyse.free.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../analyse.abstract';
@import '../../../common/css/component/mselect';
@import '../../../common/css/component/toggle-box';

@import '../analyse.free';
6 changes: 5 additions & 1 deletion ui/analyse/src/view/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
renderTools,
renderUnderboard,
} from './components';
import { wikiToggleBox } from '../wiki';

export default function (deps?: typeof studyDeps) {
return function (ctrl: AnalyseCtrl): VNode {
Expand Down Expand Up @@ -51,7 +52,10 @@ function analyseView(ctrl: AnalyseCtrl, deps?: typeof studyDeps): VNode {
'aside.analyse__side',
{
hook: onInsert(elm => {
ctrl.opts.$side && ctrl.opts.$side.length && $(elm).replaceWith(ctrl.opts.$side);
if (ctrl.opts.$side && ctrl.opts.$side.length) {
$(elm).replaceWith(ctrl.opts.$side);
wikiToggleBox();
}
}),
},
ctrl.studyPractice
Expand Down
25 changes: 23 additions & 2 deletions ui/analyse/src/wiki.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import debounce from 'common/debounce';
import { storedBooleanPropWithEffect } from 'common/storage';

export type WikiTheory = (nodes: Tree.Node[]) => void;

export function wikiToggleBox() {
$('#wikibook-field').each(function (this: HTMLElement) {
const box = this;

const state = storedBooleanPropWithEffect('analyse.wikibooks.display', true, value =>
box.classList.toggle('toggle-box--toggle-off', value),
);

const toggle = () => state(!state());

if (!state()) box.classList.add('toggle-box--toggle-off');

$(box)
.children('legend')
.on('click', toggle)
.on('keypress', e => e.key == 'Enter' && toggle());
});
}

export default function wikiTheory(): WikiTheory {
const cache = new Map<string, string>();
const show = (html: string) => {
$('.analyse__wiki').html(html).toggleClass('empty', !html);
$('.analyse__wiki').toggleClass('empty', !html);
$('.analyse__wiki-text').html(html);
site.pubsub.emit('chat.resize');
};

Expand Down Expand Up @@ -73,5 +94,5 @@ export default function wikiTheory(): WikiTheory {
}

export function wikiClear() {
$('.analyse__wiki').html('').toggleClass('empty', true);
$('.analyse__wiki').toggleClass('empty', true);
}
2 changes: 1 addition & 1 deletion ui/bits/css/ublog/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
padding-left: var(---box-padding);
padding-right: var(---box-padding);
}
.form-fieldset {
.toggle-box {
@extend %box-margin-horiz;
}
&__delete {
Expand Down
45 changes: 45 additions & 0 deletions ui/common/css/component/_toggle-box.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.toggle-box {
@extend %box-radius;
border: $border;
background: $c-bg-zebra;
margin: 1rem 0 3rem 0;
padding: 2rem 2rem 0 2rem;

legend {
@extend %box-radius;
background: $c-bg-zebra;
padding: 0.5em 1.5em;
text-align: right;
font-size: 1.2em;
user-select: none;
}
}
.toggle-box--toggle {
legend {
border-top: $border;
cursor: pointer;
&::after {
content: '';
margin-left: 1ch;
}
}
}
.toggle-box--toggle-off {
background: none;
border-width: 1px 0 0 0;
padding-top: 0;
legend {
border: $border;
background: none;
&:hover {
@extend %box-neat;
background: $c-bg-zebra;
}
&::after {
content: '';
}
}
> *:not(legend) {
display: none;
}
}
47 changes: 1 addition & 46 deletions ui/common/css/form/_form3.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import 'cmn-toggle';
@import '../component/flash';
@import '../component/toggle-box';

.form-group {
margin-bottom: 3rem;
Expand Down Expand Up @@ -113,49 +114,3 @@ textarea.form-control {
border: 0;
border-top: $border;
}

.form-fieldset {
@extend %box-radius;
border: $border;
background: $c-bg-zebra;
margin: 1rem 0 3rem 0;
padding: 2rem 2rem 0 2rem;

legend {
@extend %box-radius;
background: $c-bg-zebra;
padding: 0.5em 1.5em;
text-align: right;
font-size: 1.2em;
user-select: none;
}
}
.form-fieldset--toggle {
legend {
border-top: $border;
cursor: pointer;
&::after {
content: '▲';
margin-left: 1ch;
}
}
}
.form-fieldset--toggle-off {
background: none;
border-width: 1px 0 0 0;
padding-top: 0;
legend {
border: $border;
background: none;
&:hover {
@extend %box-neat;
background: $c-bg-zebra;
}
&::after {
content: '▼';
}
}
> *:not(legend) {
display: none;
}
}
4 changes: 2 additions & 2 deletions ui/site/src/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export function boot() {
el.setAttribute('content', el.getAttribute('content') + ',maximum-scale=1.0');
}

$('.form-fieldset--toggle').each(function (this: HTMLFieldSetElement) {
const toggle = () => this.classList.toggle('form-fieldset--toggle-off');
$('.toggle-box--toggle').each(function (this: HTMLFieldSetElement) {
const toggle = () => this.classList.toggle('toggle-box--toggle-off');
$(this)
.children('legend')
.on('click', toggle)
Expand Down
Loading