Skip to content

Commit 4b1bfae

Browse files
committed
fix filtering visibility, add styles for diagram
1 parent 7652341 commit 4b1bfae

File tree

9 files changed

+73
-85
lines changed

9 files changed

+73
-85
lines changed

scaladoc/resources/dotty_res/scripts/components/FilterBar.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @typedef { import("./Filter").Filter } Filter
33
*/
44

5-
class FilterBar extends Component {
5+
class FilterBar extends Component {
66
constructor(props) {
77
super(props);
88

@@ -14,6 +14,7 @@ class FilterBar extends Component {
1414
this.state = {
1515
filter: new Filter("", {}, this.refs.elements, true),
1616
isVisible: false,
17+
selectedPill: '',
1718
};
1819

1920
this.inputComp = new Input({ onInputChange: this.onInputChange });
@@ -25,6 +26,8 @@ class FilterBar extends Component {
2526
onFilterToggle: this.onFilterToggle,
2627
onGroupSelectChange: this.onGroupSelectChange,
2728
onFilterVisibilityChange: this.onFilterVisibilityChange,
29+
onPillClick: this.onPillClick,
30+
onPillCollapse: this.onPillCollapse,
2831
});
2932

3033
this.render();
@@ -58,6 +61,20 @@ class FilterBar extends Component {
5861
}));
5962
};
6063

64+
onPillClick = (key) => {
65+
this.setState((prevState) => ({
66+
filter: prevState.filter,
67+
selectedPill: key
68+
}))
69+
}
70+
71+
onPillCollapse = () => {
72+
this.setState((prevState) => ({
73+
filter: prevState.filter,
74+
selectedPill: ""
75+
}))
76+
}
77+
6178
render() {
6279
if (this.refs.filterBar) {
6380
if (this.state.isVisible) {
@@ -68,7 +85,7 @@ class FilterBar extends Component {
6885
}
6986

7087
this.listComp.render({ filter: this.state.filter });
71-
this.filterGroupComp.render({ filter: this.state.filter });
88+
this.filterGroupComp.render({ filter: this.state.filter, selectedPill: this.state.selectedPill });
7289
}
7390
}
7491

scaladoc/resources/dotty_res/scripts/components/FilterGroup.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ class FilterGroup extends Component {
1515
this.render(this.props);
1616
}
1717

18-
onFilterClick = ({
19-
currentTarget: {
20-
dataset: { key, value },
21-
},
22-
}) => {
18+
onFilterClick = (e) => {
19+
const {currentTarget: {dataset: {key, value}}} = e;
2320
this.props.onFilterToggle(key, value);
21+
e.stopPropagation();
22+
e.preventDefault();
2423
};
2524

2625
onSelectAllClick = ({
@@ -42,6 +41,16 @@ class FilterGroup extends Component {
4241
.forEach(([key, _values]) => this.props.onGroupSelectChange(key, false))
4342
};
4443

44+
showPillDropdown = (e) => {
45+
this.props.onPillClick(e.currentTarget.dataset.key);
46+
e.stopPropagation();
47+
e.preventDefault();
48+
}
49+
50+
hidePillDropdown = () => {
51+
this.props.onPillCollapse();
52+
}
53+
4554
attachFiltersClicks() {
4655
const refs = findRefs(
4756
"li.filterButtonItem",
@@ -66,9 +75,21 @@ class FilterGroup extends Component {
6675
this.documentableFilterRef
6776
);
6877

78+
const onPillClick = findRefs(
79+
"div.pill",
80+
this.filtersContainerRef
81+
)
82+
83+
const onOutsidePillClick = findRefs(
84+
"#main",
85+
)
86+
6987
attachListeners(selectAllRefs, "click", this.onSelectAllClick);
7088
attachListeners(deselectAllRefs, "click", this.onDeselectAllClick);
7189
attachListeners(deselectAllRefsWithClearButton, "click", this.onClearFilters);
90+
attachListeners(onPillClick, "click", this.showPillDropdown);
91+
attachListeners(onOutsidePillClick, "click", this.hidePillDropdown);
92+
7293
}
7394

7495
isActive(isActive) {
@@ -112,16 +133,21 @@ class FilterGroup extends Component {
112133
}, 0)
113134
}
114135

115-
getFilterGroup(filterKey, values) {
136+
getFilterGroup(filterKey, values, selectedPill) {
116137
const firstSelected = this.getFirstSelected(filterKey, values);
117138
const numberOfSelectedFilters = this.getNumberOfSelectedFilters(filterKey, values);
118139
const numberToDisplay = numberOfSelectedFilters > 1
119140
? `+${numberOfSelectedFilters -1}`
120141
: ""
121142

143+
const isMenuVisible = selectedPill === filterKey;
144+
122145
return `
123-
<div class="pill-container body-small" tabindex="1">
124-
<div class="pill ${numberOfSelectedFilters > 0 ? "has-value" : ""}">
146+
<div
147+
class="pill-container body-small ${isMenuVisible ? "menu-visible" : ""}"
148+
tabindex="1"
149+
>
150+
<div class="pill ${numberOfSelectedFilters > 0 ? "has-value" : ""}" data-key="${filterKey}">
125151
<span class="filter-name">${filterKey.substring(1)}</span>
126152
${firstSelected} ${numberToDisplay}
127153
<span
@@ -155,12 +181,12 @@ class FilterGroup extends Component {
155181
`;
156182
}
157183

158-
render({ filter }) {
184+
render({ filter, selectedPill }) {
159185
attachDOM(
160186
this.filtersContainerRef,
161187
Object.entries(filter.filters)
162188
.filter(([_key, values]) => Object.values(values).some((v) => v.visible))
163-
.map(([key, values]) => this.getFilterGroup(key, values)),
189+
.map(([key, values]) => this.getFilterGroup(key, values, selectedPill)),
164190
);
165191

166192
this.attachFiltersClicks();

scaladoc/resources/dotty_res/styles/diagram.css

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.diagram-class {
2+
position: relative;
3+
}

scaladoc/resources/dotty_res/styles/theme/components/pill.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@
8989
content: url(../../../images/thick-dark.svg);
9090
}
9191

92-
.pill-container:focus ul {
92+
.pill-container.menu-visible ul {
9393
display: block;
9494
}
9595

96-
.pill-container:focus .pill {
96+
.pill-container.menu-visible .pill {
9797
background-color: var(--action-primary-background-selected);
9898
border: 1px solid var(--action-primary-border-default);
9999
}

scaladoc/resources/dotty_res/styles/theme/layout/content.css

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,26 +234,30 @@
234234

235235
.companion-badge {
236236
color: var(--text-primary);
237-
padding: 16px;
237+
padding: calc(2 * var(--base-spacing));
238238
background-color: var(--indigo3);
239239
border-radius: 4px;
240240
}
241241

242+
.companion-badge span {
243+
display: flex;
244+
}
245+
242246
.companion-badge .micon {
243-
margin-left: 0.5em;
244-
margin-right: 0.5em;
247+
margin-left: calc(1 * var(--base-spacing));
248+
margin-right: calc(1 * var(--base-spacing));
245249
}
246250

247251
.main-signature {
248252
background-color: var(--action-primary-background-default-solid);
249-
padding: 24px;
253+
padding: calc(3 * var(--base-spacing));
250254
border-radius: 4px;
251255
}
252256

253257
#content .main-signature a {
254258
text-decoration: none;
255259
}
256260

257-
#content>div>* {
258-
margin-bottom: 24px;
261+
#content > div > * {
262+
margin-bottom: calc(3 * var(--base-spacing));
259263
}

scaladoc/resources/dotty_res/styles/theme/layout/footer.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
color: var(--text-primary);
1111
box-sizing: border-box;
1212
flex-wrap: wrap;
13-
z-index: 2;
13+
z-index: 3;
1414
}
1515

1616
#footer .left-container {

scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
338338
val tabs = allTabs.filter(_.content.nonEmpty)
339339
if tabs.isEmpty then Nil else
340340
Seq(div(cls := (if singleSelection then "tabs single" else "tabs"))(
341-
div(cls := "names")(tabs.map(t =>
342-
button(tabAttr(t.id), cls := s"tab ${t.cls}")(t.name)
343-
)),
344341
div(cls := "contents")(tabs.map(t =>
345342
div(tabAttr(t.id), cls := s"tab ${t.cls}")(t.content)
346343
))
@@ -351,7 +348,7 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
351348
val graphHtml = m.graph match
352349
case graph if graph.edges.nonEmpty =>
353350
Seq(div( id := "inheritance-diagram", cls := "diagram-class showGraph")(
354-
input(value := "Reset zoom", `type` := "button", cls := "btn", onclick := "zoomOut()"),
351+
button(`type` := "button", cls := "label-only-button", onclick := "zoomOut()")("Reset zoom"),
355352
svg(id := "graph"),
356353
script(`type` := "text/dot", id := "dot")(
357354
raw(DotDiagramBuilder.build(graph, signatureRenderer))

scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ trait Resources(using ctx: DocContext) extends Locations, Writer:
130130
"styles/theme/components/attributes.css",
131131
"styles/theme/components/supertypes.css",
132132
"styles/theme/components/subtypes.css",
133+
"styles/theme/components/diagram.css",
133134

134135
"styles/nord-light.css",
135136
"styles/dotty-icons.css",
136-
"styles/diagram.css",
137137
"styles/filter-bar.css",
138138
"styles/code-snippets.css",
139139
"styles/searchbar.css",

0 commit comments

Comments
 (0)