Skip to content

Commit 50b1c3d

Browse files
committed
Improve bundlephobia presentation
1 parent 1d0d8d3 commit 50b1c3d

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

apps/components_guide/lib/components_guide/research/spec.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ defmodule ComponentsGuide.Research.Spec do
5959
def search_for(:bundlephobia, query) when is_binary(query) do
6060
{:ok, data} = Source.json_at("https://bundlephobia.com/api/size?package=#{query}")
6161

62-
inspect(data)
62+
data
6363
end
6464
end

apps/components_guide_web/lib/components_guide_web/controllers/research_controller.ex

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule ComponentsGuideWeb.ResearchController do
2222
end
2323

2424
defp h2(text) do
25-
content_tag(:h2, text, class: "font-bold")
25+
content_tag(:h2, text, class: "text-2xl font-bold")
2626
end
2727

2828
defp present_results(results) when is_binary(results) do
@@ -36,12 +36,34 @@ defmodule ComponentsGuideWeb.ResearchController do
3636
content_tag(:ul, items)
3737
end
3838

39+
defp bundlephobia(query) do
40+
case Spec.search_for(:bundlephobia, query) do
41+
# %{"assets" => [%{"gzip" => 3920, "name" => "main", "size" => 10047, "type" => "js"}], "dependencyCount" => 0, "dependencySizes" => [%{"approximateSize" => 9537, "name" => "preact"}], "description" => "Fast 3kb React-compatible Virtual DOM library.", "gzip" => 3920, "hasJSModule" => "dist/preact.module.js", "hasJSNext" => false, "hasSideEffects" => true, "name" => "preact", "repository" => "https://github.com/preactjs/preact.git", "scoped" => false, "size" => 10047, "version" => "10.4.1"}
42+
%{"name" => name, "size" => size, "gzip" => size_gzip, "version" => version} ->
43+
emerging_3g_ms = floor(size_gzip / 50)
44+
content_tag(:article, [
45+
content_tag(:h3, "#{name}@#{version}", class: "text-2xl"),
46+
content_tag(:dl, [
47+
content_tag(:dt, "Minified", class: "font-bold"),
48+
content_tag(:dd, "#{size}"),
49+
content_tag(:dt, "Minified + Gzipped", class: "font-bold"),
50+
content_tag(:dd, "#{size_gzip}"),
51+
content_tag(:dt, "Emerging 3G (50kB/s)", class: "font-bold"),
52+
content_tag(:dd, "#{emerging_3g_ms}ms"),
53+
], class: "grid grid-flow-col grid-rows-2")
54+
], class: "text-xl")
55+
56+
other ->
57+
inspect(other)
58+
end
59+
end
60+
3961
defp load_results(query) when is_binary(query) do
4062
# ComponentsGuide.Research.Source.clear_cache()
4163
[
4264
content_tag(:article, [
4365
h2("Bundlephobia"),
44-
Spec.search_for(:bundlephobia, query) |> present_results()
66+
bundlephobia(query)
4567
]),
4668
content_tag(:article, [
4769
h2("Can I Use"),

apps/components_guide_web/lib/components_guide_web/templates/research/index.html.eex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
<%= "Research 🔍 specs and implementations" %>
55
</h2>
66
<form role=search action="/research" class="flex h-full pt-8 px-2 items-center">
7-
<input type=text name=q placeholder="Search" class="w-full py-1 px-2 bg-white text-black text-xl" value="<%= @query %>">
7+
<input type=text name=q placeholder="Search" class="w-full py-1 px-3 text-3xl bg-white text-black rounded" value="<%= @query %>">
88
</form>
9-
<ul class="list-none flex pt-4" style="--links-padding: 1em">
9+
<ul class="list-none flex pt-4 text-xl italic" style="--links-padding: 0.75em">
1010
<li><%= link("form", to: "?q=form") %>
1111
<li><%= link("button", to: "?q=button") %>
1212
<li><%= link("transition", to: "?q=transition") %>
13+
<li><%= link("react-dom", to: "?q=react-dom") %>
14+
<li><%= link("preact", to: "?q=preact") %>
15+
<li><%= link("error", to: "?q=error") %>
1316
</ul>
1417
</section>
1518
</header>

0 commit comments

Comments
 (0)