Skip to content

Commit 60cb0fc

Browse files
DedelweissKordyjan
authored andcommitted
Feat: Add a custom icon
- Add setting "custom" - Possible white icon with||without dark icon - Improve tap target [Cherry-picked 9f7d1d3]
1 parent cb35759 commit 60cb0fc

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

scaladoc/resources/dotty_res/styles/theme/components/button/icon-button.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,28 @@
533533
content: url("../../../../images/icon-buttons/gitter/dark/selected.svg");
534534
}
535535

536+
/* custom button */
537+
538+
.icon-button.custom-dark{
539+
display: none;
540+
}
541+
542+
.theme-dark .icon-button.custom-dark{
543+
display: unset;
544+
}
545+
546+
.theme-dark .icon-button.custom{
547+
display: none;
548+
}
549+
550+
.icon-button.custom:hover{
551+
opacity: 0.8;
552+
}
553+
554+
.icon-button.custom-dark:hover{
555+
opacity: 0.8;
556+
}
557+
536558
/* copy button */
537559

538560
.icon-button.copy-button::after {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
display: none;
6565
}
6666

67-
#footer.mobile-footer .text-mobile {
67+
#footer.mobile-footer .text-mobile {
6868
display: flex;
6969
width: 100%;
7070
justify-content: center;
@@ -78,5 +78,5 @@
7878
#footer.mobile-footer > .text-mobile {
7979
display: flex;
8080
}
81-
81+
8282
}

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
4343

4444
val socialLinks: Setting[List[String]] =
4545
MultiStringSetting("-social-links", "social-links",
46-
"Links to social sites. '[github|twitter|gitter|discord]::link' syntax is used.")
46+
"Links to social sites. '[github|twitter|gitter|discord]::link' syntax is used." +
47+
"'custom::link::white_icon_name::black_icon_name' is also allowed, in this case icons must be present in 'images/'' directory.")
4748

4849
val deprecatedSkipPackages: Setting[List[String]] =
4950
MultiStringSetting("-skip-packages", "packages", "Deprecated, please use `-skip-by-id` or `-skip-by-regex`")

scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package dotty.tools.scaladoc
22

3-
enum SocialLinks(val url: String, val className: String):
4-
case Github(ghUrl: String) extends SocialLinks(ghUrl, "gh")
5-
case Twitter(tUrl: String) extends SocialLinks(tUrl, "twitter")
6-
case Gitter(gUrl: String) extends SocialLinks(gUrl, "gitter")
7-
case Discord(dUrl: String) extends SocialLinks(dUrl, "discord")
3+
import java.nio.file.Path
4+
import java.nio.file.Paths
5+
import dotty.tools.dotc.core.Contexts.Context
6+
7+
enum SocialLinks(val url: String, val whiteIcon: String, val darkIcon: String, val className: String):
8+
case Github(ghUrl: String) extends SocialLinks(ghUrl, "", "", "gh")
9+
case Twitter(tUrl: String) extends SocialLinks(tUrl, "", "", "twitter")
10+
case Gitter(gUrl: String) extends SocialLinks(gUrl, "", "", "gitter")
11+
case Discord(dUrl: String) extends SocialLinks(dUrl, "", "", "discord")
12+
case Custom(cUrl: String, firstIcon: String, secondIcon: String) extends SocialLinks(cUrl, firstIcon, secondIcon, "custom")
813

914
object SocialLinks:
1015
def parse(s: String): Either[String, SocialLinks] =
@@ -19,5 +24,8 @@ object SocialLinks:
1924
case "gitter" => Left(errorPrefix + "For 'gitter' arg expected one argument: url")
2025
case "discord" if splitted.size == 2 => Right(Discord(splitted(1)))
2126
case "discord" => Left(errorPrefix + "For 'discord' arg expected one argument: url")
27+
case "custom" if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3)))
28+
case "custom" if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2)))
29+
case "custom" => Left(errorPrefix + "For 'custom' arg expected three arguments: url, white icon name, black icon name")
2230
case _ => Left(errorPrefix)
2331
}

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
166166
def icon(link: SocialLinks) = link.className
167167
args.socialLinks.map { link =>
168168
a(href := link.url) (
169-
button(cls := s"icon-button ${icon(link)}")
169+
if icon(link) == "custom" then
170+
Seq(
171+
img(cls := s"icon-button ${icon(link)}", src := s"../../../../images/${link.whiteIcon}"),
172+
img(cls := s"icon-button ${icon(link)}-dark", src := s"../../../../images/${link.darkIcon}")
173+
)
174+
else
175+
button(cls := s"icon-button ${icon(link)}")
170176
)
171177
}
172178

@@ -308,18 +314,7 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
308314
"Generated with"
309315
),
310316
div(cls := "right-container")(
311-
a(href := "https://github.com/lampepfl/dotty") (
312-
button(cls := "icon-button gh")
313-
),
314-
a(href := "https://twitter.com/scala_lang") (
315-
button(cls := "icon-button twitter")
316-
),
317-
a(href := "https://discord.com/invite/scala") (
318-
button(cls := "icon-button discord"),
319-
),
320-
a(href := "https://gitter.im/scala/scala") (
321-
button(cls := "icon-button gitter"),
322-
),
317+
socialLinks,
323318
div(cls := "text")(textFooter)
324319
),
325320
div(cls := "text-mobile")(textFooter)

0 commit comments

Comments
 (0)