Skip to content

Commit f58d179

Browse files
Syntax Lookup: Put deprecated constructs to the end of a section and color it differently
1 parent a4d6bfd commit f58d179

File tree

3 files changed

+59
-18
lines changed

3 files changed

+59
-18
lines changed

misc_docs/syntax/decorator_obj.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ keywords: ["obj", "decorator"]
44
name: "@obj"
55
summary: "This is the `@obj` decorator."
66
category: "decorators"
7+
status: "deprecated"
78
---
89

910

misc_docs/syntax/operators_triangle_pipe.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ keywords: [pipe", "triangle", "operator", "function", "argument"]
44
name: "|>"
55
summary: "This is the `triangle pipe` operator."
66
category: "operators"
7+
status: "deprecated"
78
---
89

910
The `|>` operator passes a value to a function as its last argument.

src/SyntaxLookup.res

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,43 @@ module Category = {
4242
}
4343
}
4444

45-
// The data representing a syntax construct
46-
// handled in the widget
47-
type item = {
48-
id: string,
49-
keywords: array<string>,
50-
name: string,
51-
summary: string,
52-
category: Category.t,
53-
children: React.element,
45+
module Status = {
46+
type t =
47+
| Active
48+
| Deprecated
49+
50+
let fromString = (s: string): t =>
51+
switch s {
52+
| "deprecated" => Deprecated
53+
| "active" | _ => Active
54+
}
55+
56+
let compare = (a, b) =>
57+
switch (a, b) {
58+
| (Deprecated, Deprecated) | (Active, Active) => 0
59+
| (Active, Deprecated) => -1
60+
| (Deprecated, Active) => 1
61+
}
62+
}
63+
64+
module Item = {
65+
// The data representing a syntax construct
66+
// handled in the widget
67+
type t = {
68+
id: string,
69+
keywords: array<string>,
70+
name: string,
71+
summary: string,
72+
category: Category.t,
73+
children: React.element,
74+
status: Status.t,
75+
}
76+
77+
let compare = (a, b) =>
78+
switch Status.compare(a.status, b.status) {
79+
| 0 => String.compare(a.name, b.name)
80+
| x => x
81+
}
5482
}
5583

5684
type itemInfo = {
@@ -59,6 +87,7 @@ type itemInfo = {
5987
name: string,
6088
summary: string,
6189
category: Category.t,
90+
status: Status.t,
6291
}
6392

6493
let getAnchor = path => {
@@ -70,8 +99,13 @@ let getAnchor = path => {
7099

71100
module Tag = {
72101
@react.component
73-
let make = (~text: string) => {
74-
<span className="hover:bg-fire hover:text-white bg-fire-5 py-1 px-3 rounded text-fire text-16">
102+
let make = (~deprecated: bool, ~text: string) => {
103+
<span
104+
className={`
105+
py-1 px-3 rounded text-16
106+
${deprecated
107+
? "hover:bg-gray-30 bg-gray-50 text-gray-80 line-through"
108+
: "hover:bg-fire hover:text-white bg-fire-5 text-fire"}`}>
75109
{React.string(text)}
76110
</span>
77111
}
@@ -104,8 +138,8 @@ module DetailBox = {
104138

105139
type state =
106140
| ShowAll
107-
| ShowFiltered(string, array<item>) // (search, filteredItems)
108-
| ShowDetails(item)
141+
| ShowFiltered(string, array<Item.t>) // (search, filteredItems)
142+
| ShowDetails(Item.t)
109143

110144
@val @scope("window")
111145
external scrollTo: (int, int) => unit = "scrollTo"
@@ -122,21 +156,26 @@ let decode = (json: Js.Json.t) => {
122156
let name = json->(field("name", string, _))
123157
let summary = json->(field("summary", string, _))
124158
let category = json->field("category", string, _)->Category.fromString
159+
let status =
160+
json
161+
->optional(field("status", string, _), _)
162+
->Belt.Option.mapWithDefault(Status.Active, Status.fromString)
125163

126164
{
127165
id,
128166
keywords,
129167
name,
130168
summary,
131169
category,
170+
status,
132171
}
133172
}
134173

135174
let default = (props: props) => {
136175
let {mdxSources} = props
137176

138177
let allItems = mdxSources->Js.Array2.map(mdxSource => {
139-
let {id, keywords, category, summary, name} = decode(mdxSource.frontmatter)
178+
let {id, keywords, category, summary, name, status} = decode(mdxSource.frontmatter)
140179

141180
let children =
142181
<MdxRemote
@@ -146,7 +185,7 @@ let default = (props: props) => {
146185
components={MarkdownComponents.default}
147186
/>
148187

149-
{id, keywords, category, summary, name, children}
188+
{Item.id, keywords, category, summary, name, status, children}
150189
})
151190

152191
let fuseOpts = Fuse.Options.t(
@@ -160,7 +199,7 @@ let default = (props: props) => {
160199
(),
161200
)
162201

163-
let fuse: Fuse.t<item> = Fuse.make(allItems, fuseOpts)
202+
let fuse: Fuse.t<Item.t> = Fuse.make(allItems, fuseOpts)
164203

165204
let router = Next.Router.useRouter()
166205
let (state, setState) = React.useState(_ => ShowAll)
@@ -267,14 +306,14 @@ let default = (props: props) => {
267306
} else {
268307
let children =
269308
items
270-
->Belt.SortArray.stableSortBy((v1, v2) => String.compare(v1.name, v2.name))
309+
->Belt.SortArray.stableSortBy(Item.compare)
271310
->Belt.Array.map(item => {
272311
let onMouseDown = evt => {
273312
ReactEvent.Mouse.preventDefault(evt)
274313
onSearchValueChange(item.name)
275314
}
276315
<span className="mr-2 mb-2 cursor-pointer" onMouseDown key=item.name>
277-
<Tag text={item.name} />
316+
<Tag text={item.name} deprecated={item.status == Deprecated} />
278317
</span>
279318
})
280319
let el =

0 commit comments

Comments
 (0)