Skip to content

Commit

Permalink
refactor: United API, Examples, and Docs under Documentation page
Browse files Browse the repository at this point in the history
  • Loading branch information
iisakkirotko committed Dec 11, 2023
1 parent b27c3d5 commit f021065
Show file tree
Hide file tree
Showing 189 changed files with 610 additions and 176 deletions.
4 changes: 1 addition & 3 deletions solara/website/assets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ blockquote p:last-child {
.component-card{
display: flex;
flex-direction: column;
justify-content: space-between;
width: 20%;
min-width: 300px;
width: 19rem;
}

/* vuetify component overrides */
Expand Down
139 changes: 139 additions & 0 deletions solara/website/components/algolia_api.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<template>
<v-menu
v-model="show_results"
offset-y>
<template v-slot:activator="{ on }">
<v-text-field
v-model="query"
append-icon="mdi-magnify"
hide-details
placeholder="Search"
outlined
rounded
style="min-width: 19rem; width: 33%; background-color: #ffeec5;"
@click="show($event, on); item = 'Hi';"
></v-text-field>
</template>
<v-list v-if="results != null && results.length == 0">
<v-list-item>
<v-list-item-content>
{{this.query == "" ? "Start Typing to Search" : "No search results found."}}
</v-list-item-content>
</v-list-item>
</v-list>
<v-list v-else>
<v-list-item-group v-model="item">
<v-list-item v-for="(element, index) in this.results.hits" :key="element['url']">
<v-list-item-content>
<v-list-item-title>{{ element.hierarchy[element.type] }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
<v-list-item>
<v-list-item-content>
<v-list-item-title>And {{ this.results.nbHits - 10}} More...</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</template>
<script>
module.exports = {
async mounted() {
window.search = this;
await this.loadRequire();
this.algoliasearch = (await this.import([`https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js`]))[0];
this.initSearch();
window.search = this;
},
watch: {
query ( value ) {
this.show_results = true;
this.search();
},
item ( value ) {
if ( this.results.hits != null && this.results.hits.length > 0 ) {
let url = this.results.hits[value].url;
if (url.startsWith("https://solara.dev")) {
url = url.slice(18);
}
solara.router.push( url );
}
},
},
methods: {
show( e, on ) {
this.show_results = false;
this.$nextTick( () => {
on.click( e )
} );
},
initSearch() {
this.client = this.algoliasearch( '9KW9L7O5EQ', '647ca12ba642437cc40c2adee4a78d08' );
this.index = this.client.initIndex( 'solara' );
},
async search() {
results = await this.index.search( this.query, { hitsPerPage: 10 } );
if (results) {
this.results = results;
}else{
this.$set(this.results, []);
}
},
import(dependencies) {
return this.loadRequire().then(
() => {
if (window.jupyterVue) {
// in jupyterlab, we take Vue from ipyvue/jupyterVue
define("vue", [], () => window.jupyterVue.Vue);
} else {
define("vue", ['jupyter-vue'], jupyterVue => jupyterVue.Vue);
}
return new Promise((resolve, reject) => {
requirejs(dependencies, (...modules) => resolve(modules));
})
}
);
},
loadRequire() {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = `${this.getCdn()}/[email protected]/require.js`;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
},
getBaseUrl() {
if (window.solara && window.solara.rootPath !== undefined) {
return solara.rootPath + "/";
}
// if base url is set, we use ./ for relative paths compared to the base url
if (document.getElementsByTagName("base").length) {
return document.baseURI;
}
const labConfigData = document.getElementById('jupyter-config-data');
if (labConfigData) {
/* lab and Voila */
return JSON.parse(labConfigData.textContent).baseUrl;
}
let base = document.body.dataset.baseUrl || document.baseURI;
if (!base.endsWith('/')) {
base += '/';
}
return base
},
getCdn() {
return (typeof solara_cdn !== "undefined" && solara_cdn) || `${this.getBaseUrl()}_solara/cdn`;
},
},
data(){
return {
query: '',
results: [],
item: null,
show_results: false,
}
},
}
</script>
13 changes: 7 additions & 6 deletions solara/website/components/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from solara.server import settings


@solara._component_vue("algolia.vue")
def Algolia(app_id: str, index_name: str, api_key: str, debug=False):
@solara.component_vue("algolia.vue")
def Algolia(app_id: str, api_key: str, index_name: str, debug=False):
pass


Expand Down Expand Up @@ -40,7 +40,7 @@ def Header(
"div",
unsafe_innerHTML="<a href='https://github.com/widgetti/solara' target='_blank' >Star us on github 🤩</a>",
)
with rv.AppBar(tag="header", flat=True, class_="bg-primary-fade padding-40", height="auto"):
with solara.v.AppBar(tag="header", flat=True, class_="bg-primary-fade padding-40", height="auto", clipped_left=True):
with rv.ToolbarTitle(class_="d-flex", style_="align-items:center"):
if route_current and len(route_current.children) > 0:
with solara.Button(icon=True, class_="hidden-md-and-up", on_click=lambda: on_toggle_left_menu and on_toggle_left_menu()):
Expand All @@ -53,19 +53,20 @@ def Header(
from solara_enterprise.search.search import Search

Search()
Algolia(app_id="9KW9L7O5EQ", api_key="ef7495102afff1e16d1b7cf6ec2ab2d0", index_name="solara", debug=True)
else:
Algolia(app_id="9KW9L7O5EQ", api_key="ef7495102afff1e16d1b7cf6ec2ab2d0", index_name="solara")
# menu
with rv.Html(tag="ul", class_="main-menu menu d-none d-md-flex"):
for route in all_routes:
if route.path == "apps":
if route.path in ["apps", "contact", "changelog"]:
continue
current = route_current == route
with rv.Html(tag="li", class_="active" if current else None):
solara.Link("/" + route.path if route.path != "/" else "/", children=[route.label])
with rv.Btn(icon=True, tag="a", class_="d-none d-md-flex", attributes={"href": solara.github_url, "target": "_blank"}):
rv.Icon(children=["mdi-github-circle"])

with rv.Btn(icon=True, tag="a", class_="d-none d-md-flex", attributes={"href": "https://discord.gg/dm4GKNDjXN", "target": "_blank"}):
with rv.Btn(icon=True, tag="a", class_="d-none d-md-flex", attributes={"href": "https://discord.solara.dev", "target": "_blank"}):
rv.Icon(children=["mdi-discord"])

with solara.Button(icon=True, class_="hidden-md-and-up", on_click=lambda: on_toggle_right_menu and on_toggle_right_menu()):
Expand Down
23 changes: 9 additions & 14 deletions solara/website/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

title = "Home"

route_order = ["/", "showcase", "docs", "api", "examples", "apps"]
route_order = ["/", "showcase", "documentation", "apps", "contact", "changelog"]


@solara.component
Expand Down Expand Up @@ -96,7 +96,7 @@ def Layout(children=[]):
button_text="Quickstart",
)

with rv.Container(tag="section", fluid=True, ma_0=True, pa_0=True, class_="fill-height mb-8 solara-content-main"):
with rv.Container(tag="section", fluid=True, ma_0=True, pa_0=True, class_="fill-height solara-content-main"):
if route_current is not None and route_current.path == "/":
description = "Use ipywidgets with Solara to build powerful and scalable web apps for Jupyter and production in Python."
# both tags in one
Expand Down Expand Up @@ -209,7 +209,8 @@ def Layout(children=[]):
rv.ExpansionPanelHeader(children=["FastAPI"])
with rv.ExpansionPanelContent():
solara.Markdown(
"Using [solara-server](/docs/understanding/solara-server), we can run our app in production using FastAPI."
"""Using [solara-server](documentation/docs/understanding/solara-server),
we can run our app in production using FastAPI."""
)

with solara.Column(style={"width": "100%"}):
Expand Down Expand Up @@ -265,29 +266,24 @@ def Layout(children=[]):

else:
with rv.Row(
style_="gap:6rem; flex-wrap: nowrap;",
justify="center" if route_current is not None and route_current.path in ["showcase", "api"] else "start",
style_="gap:40px; flex-wrap: nowrap; margin: 0; min-height: calc(100vh - 215.5px);",
justify="center" if route_current is not None and route_current.path in ["documentation", "showcase"] else "start",
):
if route_current is not None and hasattr(route_current.module, "Sidebar"):
route_current.module.Sidebar() # type: ignore
else:
if route_current is not None and route_current.path not in ["showcase", "api"]:
if route_current is not None and route_current.path not in ["documentation", "showcase", "contact", "changelog"]:
Sidebar()
with rv.Col(
tag="main",
md=True,
class_="pt-12 pl-12 pr-10",
style_=f"max-width: {'1024px' if route_current.path != 'api' else '75%'}; overflow: auto;",
style_=f"max-width: {'1024px' if route_current.path not in ['documentation', 'contact', 'changelog'] else 'unset'}; overflow: auto;",
):
if route_current is not None and route_current.path == "/":
with rv.Row(align="center"):
pass
# with rv.Col(md=6, class_="pa-0"):
# rv.Html(tag="h1", children=["Live Demo"])
# with rv.Col(md=6, class_="d-flex", style_="justify-content: end"):
# rv.Btn(elevation=0, large=True, children=["Running App"], color="primary", class_="btn-size--xlarge")
# solara.Padding(6)
with rv.Row(children=children, class_="solara-page-content-search"):
with rv.Row(children=children, justify="center", class_="solara-page-content-search"):
pass

# absolute = True prevents the drawer from being below the overlay it generates
Expand Down Expand Up @@ -351,7 +347,6 @@ def Testimonial(text, name, position, img):
max_width=max_width,
style_="display: flex; flex-direction: column; justify-content: space-between;",
):
# rv.CardTitle(children=["Former Plotly CEO"])
with rv.CardActions():
with rv.ListItem(class_="grow"):
with rv.ListItemAvatar(color="grey darken-3"):
Expand Down
2 changes: 1 addition & 1 deletion solara/website/pages/apps/jupyter-dashboard-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limit = solara.reactive(100)


ROOT = Path(solara.__file__).parent / "website" / "pages" / "docs" / "content" / "04-tutorial"
ROOT = Path(solara.__file__).parent / "website" / "pages" / "documentation" / "getting_started" / "content" / "04-tutorial"
path = ROOT / Path("SF_crime_sample.csv.gz")
url = "https://raw.githubusercontent.com/widgetti/solara/master/solara/website/pages/docs/content/04-tutorial/SF_crime_sample.csv"

Expand Down
8 changes: 8 additions & 0 deletions solara/website/pages/changelog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path

import solara

title = "Changelog"
HERE = Path(__file__)

Page = solara.Markdown(Path(HERE.parent / "changelog.md").read_text())
File renamed without changes.
8 changes: 8 additions & 0 deletions solara/website/pages/contact/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path

import solara

title = "Contact"
HERE = Path(__file__)

Page = solara.Markdown(Path(HERE.parent / "contact.md").read_text())
File renamed without changes.
Loading

0 comments on commit f021065

Please sign in to comment.