Skip to content

Commit 68583ef

Browse files
Update version selector (#1394)
* Use page-level version selector * Style fixes * Color, radius, spacing consistency * Design review * Small padding tweak * Engineering review * Refactor the Z-index to have just one place to modify all the components and layers (#1401) * Update z-indices to semantic use * Match existing focus highlight --------- Co-authored-by: Andres Ramirez Fuentes <a.ramirezfuentes@snowflake.com>
1 parent 0afec90 commit 68583ef

26 files changed

+424
-210
lines changed

components/blocks/autofunction.js

Lines changed: 20 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import React, { useEffect, useState, useRef } from "react";
2-
import classNames from "classnames";
32
import Table from "./table";
43
import { H2, H3 } from "./headers";
54
import Warning from "./warning";
65
import Deprecation from "./deprecation";
7-
import { withRouter, useRouter } from "next/router";
86
import Prism from "prismjs";
97
import "prismjs/components/prism-python";
108
import "prismjs/plugins/line-numbers/prism-line-numbers";
@@ -17,12 +15,10 @@ import getConfig from "next/config";
1715
const { publicRuntimeConfig } = getConfig();
1816

1917
import styles from "./autofunction.module.css";
20-
import { looksLikeVersionAndPlatformString } from "../../lib/next/utils";
2118
import { getThemedUrl, getThemeFromDOM } from "../../lib/next/ThemeContext";
2219

2320
const LATEST_VERSION = publicRuntimeConfig.LATEST_VERSION;
2421
const DEFAULT_VERSION = publicRuntimeConfig.DEFAULT_VERSION;
25-
const VERSIONS_LIST = publicRuntimeConfig.VERSIONS_LIST;
2622

2723
const cleanHref = (name) => {
2824
return String(name).replace(/\./g, "").replace(/\s+/g, "-");
@@ -37,10 +33,8 @@ const Autofunction = ({
3733
deprecated,
3834
deprecatedText,
3935
oldStreamlitFunction,
40-
goToLatest,
4136
}) => {
4237
const blockRef = useRef();
43-
const router = useRouter();
4438
const [isHighlighted, setIsHighlighted] = useState(false);
4539
const currentNumericVersion =
4640
version == DEFAULT_VERSION ? LATEST_VERSION : version;
@@ -121,56 +115,6 @@ const Autofunction = ({
121115
setIsHighlighted(true);
122116
};
123117

124-
const VersionSelector = ({ currentNumericVersion, handleSelectVersion }) => {
125-
const selectClass =
126-
currentNumericVersion != LATEST_VERSION
127-
? "version-select old-version"
128-
: "version-select";
129-
130-
return (
131-
<form className={classNames(selectClass, styles.Form)}>
132-
<label>
133-
<span className="sr-only">Streamlit Version</span>
134-
<select
135-
value={currentNumericVersion}
136-
onChange={handleSelectVersion}
137-
className={styles.Select}
138-
>
139-
{VERSIONS_LIST.map((version, index) => (
140-
<option value={version} key={version}>
141-
{"Version " + version}
142-
</option>
143-
))}
144-
</select>
145-
</label>
146-
</form>
147-
);
148-
};
149-
150-
const handleSelectVersion = (event) => {
151-
const functionObject =
152-
docstrings[streamlitFunction] ?? docstrings[oldStreamlitFunction];
153-
const slicedSlug = slug.slice();
154-
155-
if (event.target.value !== currentNumericVersion) {
156-
if (looksLikeVersionAndPlatformString(slicedSlug[0])) {
157-
slicedSlug.shift();
158-
}
159-
if (event.target.value !== LATEST_VERSION) {
160-
slicedSlug.unshift(event.target.value);
161-
} else {
162-
goToLatest();
163-
}
164-
}
165-
166-
if (!functionObject) {
167-
router.push(`/${slicedSlug.join("/")}`);
168-
} else {
169-
const name = cleanHref(`st.${functionObject.name}`);
170-
router.push(`/${slicedSlug.join("/")}#${name} `);
171-
}
172-
};
173-
174118
const footers = [];
175119
const args = [];
176120
const returns = [];
@@ -201,31 +145,25 @@ const Autofunction = ({
201145
}
202146
} else {
203147
return (
204-
<div className={styles.HeaderContainer}>
205-
<div className={styles.TitleContainer} ref={blockRef} key={slug}>
206-
<H2
207-
className={`
208-
${styles.Title}
209-
relative
210-
`}
148+
<div className={styles.HeaderContainer} ref={blockRef} key={slug}>
149+
<H2
150+
className={`
151+
${styles.Title}
152+
relative
153+
`}
154+
>
155+
<a
156+
aria-hidden="true"
157+
tabIndex="-1"
158+
href={`#${cleanHref(
159+
streamlitFunction.replace("streamlit", "st"),
160+
)}`.toLowerCase()}
161+
className="absolute"
211162
>
212-
<a
213-
aria-hidden="true"
214-
tabIndex="-1"
215-
href={`#${cleanHref(
216-
streamlitFunction.replace("streamlit", "st"),
217-
)}`.toLowerCase()}
218-
className="absolute"
219-
>
220-
<span className="icon icon-link"></span>
221-
</a>
222-
{streamlitFunction.replace("streamlit", "st")}
223-
</H2>
224-
<VersionSelector
225-
currentNumericVersion={currentNumericVersion}
226-
handleSelectVersion={handleSelectVersion}
227-
/>
228-
</div>
163+
<span className="icon icon-link"></span>
164+
</a>
165+
{streamlitFunction.replace("streamlit", "st")}
166+
</H2>
229167
<Warning>
230168
<p>
231169
This method does not exist in version{" "}
@@ -280,18 +218,7 @@ const Autofunction = ({
280218
);
281219
header = (
282220
<div className={styles.HeaderContainer}>
283-
<div
284-
className={`
285-
${styles.TitleContainer}
286-
relative
287-
`}
288-
>
289-
{headerTitle}
290-
<VersionSelector
291-
currentNumericVersion={currentNumericVersion}
292-
handleSelectVersion={handleSelectVersion}
293-
/>
294-
</div>
221+
{headerTitle}
295222
{deprecated === true ? (
296223
<Deprecation>
297224
<p dangerouslySetInnerHTML={{ __html: deprecatedText }} />
@@ -565,4 +492,4 @@ const Autofunction = ({
565492
);
566493
};
567494

568-
export default withRouter(Autofunction);
495+
export default Autofunction;

components/blocks/autofunction.module.css

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,10 @@
1010
@apply mb-6;
1111
}
1212

13-
.TitleContainer {
14-
@apply flex flex-col items-start md:flex-row md:items-baseline mt-4 mb-2;
15-
}
16-
1713
.Title {
1814
@apply mt-6 mb-2;
1915
}
2016

21-
.Form {
22-
@apply relative my-4 md:my-0 ml-0 md:ml-auto min-w-fit;
23-
}
24-
25-
.Form::after {
26-
@apply hidden md:block md:absolute md:bottom-1/4 md:right-0 md:opacity-70 md:pointer-events-none md:w-3 md:h-2;
27-
content: "";
28-
background-image: url("data:image/svg+xml,%0A%3Csvg width='11px' height='8px' viewBox='0 0 11 8' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg id='select_arrow_down_disabled' fill='%23000000' fill-rule='nonzero'%3E%3Cpath d='M10.8703474,1.8762017 L5.80707196,6.93171246 C5.72063689,7.01813145 5.61827957,7.06134094 5.5,7.06134094 C5.38172043,7.06134094 5.27936311,7.01813145 5.19292804,6.93171246 L0.129652605,1.8762017 C0.0432175352,1.78978271 0,1.68630735 0,1.5657756 C0,1.44524385 0.0432175352,1.34176849 0.129652605,1.2553495 L1.26240695,0.129628481 C1.34884202,0.0432094937 1.45119934,0 1.56947891,0 C1.68775848,0 1.7901158,0.0432094937 1.87655087,0.129628481 L5.5,3.7524034 L9.12344913,0.129628481 C9.2098842,0.0432094937 9.31224152,0 9.43052109,0 C9.54880066,0 9.65115798,0.0432094937 9.73759305,0.129628481 L10.8703474,1.2553495 C10.9567825,1.34176849 11,1.44524385 11,1.5657756 C11,1.68630735 10.9567825,1.78978271 10.8703474,1.8762017 Z' id='Path'%3E%3C/path%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
29-
}
30-
31-
.Form::before {
32-
@apply md:hidden block absolute bottom-1/4 left-0 opacity-70 pointer-events-none w-3 h-2;
33-
content: "";
34-
background-image: url("data:image/svg+xml,%0A%3Csvg width='11px' height='8px' viewBox='0 0 11 8' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg id='select_arrow_down_disabled' fill='%23000000' fill-rule='nonzero'%3E%3Cpath d='M10.8703474,1.8762017 L5.80707196,6.93171246 C5.72063689,7.01813145 5.61827957,7.06134094 5.5,7.06134094 C5.38172043,7.06134094 5.27936311,7.01813145 5.19292804,6.93171246 L0.129652605,1.8762017 C0.0432175352,1.78978271 0,1.68630735 0,1.5657756 C0,1.44524385 0.0432175352,1.34176849 0.129652605,1.2553495 L1.26240695,0.129628481 C1.34884202,0.0432094937 1.45119934,0 1.56947891,0 C1.68775848,0 1.7901158,0.0432094937 1.87655087,0.129628481 L5.5,3.7524034 L9.12344913,0.129628481 C9.2098842,0.0432094937 9.31224152,0 9.43052109,0 C9.54880066,0 9.65115798,0.0432094937 9.73759305,0.129628481 L10.8703474,1.2553495 C10.9567825,1.34176849 11,1.44524385 11,1.5657756 C11,1.68630735 10.9567825,1.78978271 10.8703474,1.8762017 Z' id='Path'%3E%3C/path%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
35-
}
36-
37-
.Select {
38-
@apply appearance-none bg-white border-none p-0 m-0 w-full font-mono text-lg font-bold leading-none md:text-right text-left md:pr-5 md:pl-0 pr-0 pl-5;
39-
}
40-
41-
:global(.dark) .Select {
42-
@apply bg-gray-100 text-gray-40;
43-
}
44-
45-
:global(.old-version) .Select {
46-
@apply text-red-70;
47-
}
48-
49-
:global(.sis-version) .Select {
50-
@apply text-lightBlue-70;
51-
}
52-
53-
:global(.dark) .Form::after {
54-
background-image: url("data:image/svg+xml,%0A%3Csvg width='11px' height='8px' viewBox='0 0 11 8' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg id='select_arrow_down_disabled' fill='%23FFFFFF' fill-rule='nonzero'%3E%3Cpath d='M10.8703474,1.87655087 L5.80707196,6.93300248 C5.72063689,7.01943755 5.61827957,7.06265509 5.5,7.06265509 C5.38172043,7.06265509 5.27936311,7.01943755 5.19292804,6.93300248 L0.129652605,1.87655087 C0.0432175352,1.7901158 0,1.68662117 0,1.566067 C0,1.44551282 0.0432175352,1.3420182 0.129652605,1.25558313 L1.26240695,0.129652605 C1.34884202,0.0432175352 1.45119934,0 1.56947891,0 C1.68775848,0 1.7901158,0.0432175352 1.87655087,0.129652605 L5.5,3.75310174 L9.12344913,0.129652605 C9.2098842,0.0432175352 9.31224152,0 9.43052109,0 C9.54880066,0 9.65115798,0.0432175352 9.73759305,0.129652605 L10.8703474,1.25558313 C10.9567825,1.3420182 11,1.44551282 11,1.566067 C11,1.68662117 10.9567825,1.7901158 10.8703474,1.87655087 Z' id='Path'%3E%3C/path%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
55-
}
56-
57-
:global(.dark) .Form::before {
58-
background-image: url("data:image/svg+xml,%0A%3Csvg width='11px' height='8px' viewBox='0 0 11 8' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg id='select_arrow_down_disabled' fill='%23FFFFFF' fill-rule='nonzero'%3E%3Cpath d='M10.8703474,1.87655087 L5.80707196,6.93300248 C5.72063689,7.01943755 5.61827957,7.06265509 5.5,7.06265509 C5.38172043,7.06265509 5.27936311,7.01943755 5.19292804,6.93300248 L0.129652605,1.87655087 C0.0432175352,1.7901158 0,1.68662117 0,1.566067 C0,1.44551282 0.0432175352,1.3420182 0.129652605,1.25558313 L1.26240695,0.129652605 C1.34884202,0.0432175352 1.45119934,0 1.56947891,0 C1.68775848,0 1.7901158,0.0432175352 1.87655087,0.129652605 L5.5,3.75310174 L9.12344913,0.129652605 C9.2098842,0.0432175352 9.31224152,0 9.43052109,0 C9.54880066,0 9.65115798,0.0432175352 9.73759305,0.129652605 L10.8703474,1.25558313 C10.9567825,1.3420182 11,1.44551282 11,1.566067 C11,1.68662117 10.9567825,1.7901158 10.8703474,1.87655087 Z' id='Path'%3E%3C/path%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
59-
}
60-
6117
.CodeBlockContainer {
6218
@apply mb-7 relative bg-gray-90 rounded-xl;
6319
}
@@ -88,12 +44,12 @@
8844

8945
/* Keep in sync with components/blocks/autofunction.module.css */
9046
.CodeBlockContainer pre code {
91-
@apply z-10 relative;
47+
@apply z-elevated relative;
9248
}
9349

9450
/* Keep in sync with components/blocks/code.module.css */
9551
.LineHighlight {
96-
@apply bg-gray-80 opacity-30 z-0;
52+
@apply bg-gray-80 opacity-30 z-base;
9753
}
9854

9955
/* Keep in sync with components/blocks/code.module.css */
@@ -155,7 +111,7 @@
155111

156112
/* Styles for deprecation notice in param */
157113
.DeprecatedContent {
158-
@apply bg-orange-20 text-gray-90 px-2 py-1 rounded-md text-sm mb-2 flex items-center relative;
114+
@apply bg-orange-10 text-gray-90 px-2 py-1 rounded-xl text-sm mb-2 flex items-center relative;
159115
}
160116

161117
.DeprecatedContent i {

components/blocks/callout.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.Container {
2-
@apply p-4 md:p-8 rounded-md mt-8 mb-12;
2+
@apply p-4 md:p-8 rounded-xl mt-8 mb-12;
33
}
44

55
.Container p {

components/blocks/code.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434

3535
/* Keep in sync with components/blocks/autofunction.module.css */
3636
.Pre code {
37-
@apply z-10 relative;
37+
@apply z-elevated relative;
3838
}
3939

4040
/* Keep in sync with components/blocks/autofunction.module.css */
4141
.LineHighlight {
42-
@apply bg-gray-80 opacity-30 z-0;
42+
@apply bg-gray-80 opacity-30 z-base;
4343
}
4444

4545
/* Keep in sync with components/blocks/autofunction.module.css */

components/blocks/componentSlider.module.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/* Hover styles for cards. Need to be done here to prevent the card overflow */
1515
.Container :global(.slick-slide) > div {
16-
@apply transition-all duration-75 z-10;
16+
@apply transition-all duration-75 z-elevated;
1717
}
1818

1919
.Container :global(.slick-slide) > div:hover {
@@ -45,12 +45,12 @@
4545
}
4646

4747
.Tooltip {
48-
@apply p-3 bg-gray-90 absolute rounded-md transition delay-100 ease-in-out opacity-0 w-full w-64 z-10;
48+
@apply p-3 bg-gray-90 absolute rounded-md transition delay-100 ease-in-out opacity-0 w-full w-64 z-elevated;
4949
bottom: 100%;
5050
}
5151

5252
.TooltipArrow {
53-
@apply h-3 w-3 p-0 absolute opacity-0 -bottom-[2px] right-9 transition ease-in-out delay-100 bg-gray-90 z-10;
53+
@apply h-3 w-3 p-0 absolute opacity-0 -bottom-[2px] right-9 transition ease-in-out delay-100 bg-gray-90 z-elevated;
5454
}
5555

5656
.Open {

components/blocks/image.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232

3333
.LightBox {
34-
@apply fixed z-30 top-0 left-0 w-full h-full flex justify-center items-center overscroll-contain bg-gray-20;
34+
@apply fixed z-header top-0 left-0 w-full h-full flex justify-center items-center overscroll-contain bg-gray-20;
3535
}
3636

3737
:global(.dark) .LightBox {
@@ -48,7 +48,7 @@
4848

4949
.CloseButton {
5050
font-family: "Material Icons";
51-
@apply font-normal text-5xl absolute right-0 md:right-8 top-12 cursor-pointer bg-gray-20 z-20 text-gray-90 hover:shadow-none hover:opacity-60 mb-0 px-2 lg:p-4;
51+
@apply font-normal text-5xl absolute right-0 md:right-8 top-12 cursor-pointer bg-gray-20 z-sidebar text-gray-90 hover:shadow-none hover:opacity-60 mb-0 px-2 lg:p-4;
5252
}
5353

5454
:global(.dark) .CloseButton {

components/blocks/important.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
}
44

55
:global(.dark) .Important {
6-
background-color: #481d00;
6+
@apply bg-orange-100/30;
77
}

components/blocks/note.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
}
44

55
:global(.dark) .Note {
6-
background-color: #062633;
6+
@apply bg-lightBlue-100/30;
77
}

components/blocks/refCard.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.Container {
2-
@apply relative rounded-md overflow-hidden border border-gray-30 text-base cursor-pointer transition-all duration-75 flex flex-col z-20;
2+
@apply relative rounded-md overflow-hidden border border-gray-30 text-base cursor-pointer transition-all duration-75 flex flex-col z-sidebar;
33
}
44

55
.Container:hover {

components/layouts/container.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
@apply col-span-full lg:col-start-2 lg:col-end-5;
77
}
88

9+
.StickyContext {
10+
/* Container for sticky version selector - must have height */
11+
@apply relative;
12+
}
13+
914
.ArticleContainer {
1015
@apply relative;
1116
}

0 commit comments

Comments
 (0)