Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal taste: as a side-by-side comparison, the background colors in dark mode seems to be a bit less "colorful" / dull / less distinguishable (also see the MultiselectColumn tags above). 20% transparency might be a bit too much, and something between 10-20% would be a bit better. cc @jrieke

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats fair, will make a note to revisit (in any way, yellow bg was noted above as a concern)

8 changes: 4 additions & 4 deletions e2e_playwright/st_markdown_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def test_displays_individual_markdowns(app: Page):
rainbow_background = markdown_elements.nth(9).locator("span").first
green_background = markdown_elements.nth(10).locator("span").first

expect(blue_background).to_have_css("background-color", "rgba(28, 131, 225, 0.1)")
expect(blue_background).to_have_css("background-color", "rgba(28, 131, 255, 0.1)")
expect(red_background).to_have_css("background-color", "rgba(255, 43, 43, 0.1)")
expect(rainbow_background).to_have_css(
"background-image",
"linear-gradient(to right, rgba(255, 43, 43, 0.1), rgba(255, 227, 18, 0.1), "
"rgba(250, 202, 43, 0.1), rgba(33, 195, 84, 0.1), rgba(28, 131, 225, 0.1), "
"rgba(128, 61, 245, 0.1), rgba(88, 63, 132, 0.1))",
"linear-gradient(to right, rgba(255, 43, 43, 0.1), rgba(255, 164, 33, 0.1), "
"rgba(255, 255, 18, 0.1), rgba(33, 195, 84, 0.1), rgba(28, 131, 255, 0.1), "
"rgba(154, 93, 255, 0.1), rgba(88, 63, 132, 0.1))",
)
expect(green_background).to_have_css("background-color", "rgba(33, 195, 84, 0.1)")

Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/src/components/elements/Metric/Metric.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("Metric element", () => {
"color: rgb(163, 168, 184);"
)
expect(screen.getByTestId("stMetricDelta")).toHaveStyle(
"background-color: rgba(128, 132, 149, 0.1);"
"background-color: rgba(49, 51, 63, 0.1);"
)
})

Expand Down Expand Up @@ -412,7 +412,7 @@ describe("Metric element", () => {
expect.objectContaining({
mark: expect.objectContaining({
type: "area",
opacity: 0.2,
opacity: 1,
line: expect.objectContaining({
strokeWidth: 2,
strokeCap: "round",
Expand Down
5 changes: 4 additions & 1 deletion frontend/lib/src/components/elements/Metric/Metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { Placement } from "~lib/components/shared/Tooltip"
import TooltipIcon from "~lib/components/shared/TooltipIcon"
import { StyledWidgetLabelHelpInline } from "~lib/components/widgets/BaseWidget"
import { useCalculatedDimensions } from "~lib/hooks/useCalculatedDimensions"
import { getMetricBackgroundColor } from "~lib/theme/getColors"
import { labelVisibilityProtoValueToEnum } from "~lib/util/utils"

import {
Expand Down Expand Up @@ -100,9 +101,11 @@ export function getMetricChartSpec(
}),
...(chartType === MetricProto.ChartType.AREA && {
type: "area",
opacity: 0.2,
color: getMetricBackgroundColor(theme, metricColor),
opacity: 1,
line: {
color: getMetricColor(theme, metricColor),
opacity: 1,
strokeWidth: 2,
strokeCap: "round",
},
Expand Down
32 changes: 1 addition & 31 deletions frontend/lib/src/components/elements/Metric/styled-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/

import styled from "@emotion/styled"
import { transparentize } from "color2k"

import { Metric as MetricProto } from "@streamlit/protobuf"

import { StyledWidgetLabel } from "~lib/components/widgets/BaseWidget/styled-components"
import { EmotionTheme } from "~lib/theme"
import { hasLightBackgroundColor } from "~lib/theme/getColors"
import { getMetricBackgroundColor } from "~lib/theme/getColors"
import { LabelVisibilityOptions } from "~lib/util/utils"

export interface StyledMetricContainerProps {
Expand Down Expand Up @@ -115,35 +114,6 @@ export const getMetricColor = (
}
}

// Delta uses the same background colors as background colored Markdown text.
// TODO: We should refactor this and probably move it somewhere else (e.g. getColors.ts)
// when we work on text/background colors for advanced theming.
const getMetricBackgroundColor = (
theme: EmotionTheme,
color: MetricProto.MetricColor
): string => {
const lightTheme = hasLightBackgroundColor(theme)

switch (color) {
case MetricProto.MetricColor.RED:
return transparentize(
theme.colors[lightTheme ? "red80" : "red60"],
lightTheme ? 0.9 : 0.7
)
case MetricProto.MetricColor.GREEN:
return transparentize(
theme.colors[lightTheme ? "green70" : "green60"],
lightTheme ? 0.9 : 0.7
)
// this must be grey
default:
return transparentize(
theme.colors[lightTheme ? "gray70" : "gray50"],
lightTheme ? 0.9 : 0.7
)
}
}

export const StyledMetricDeltaText = styled.div<StyledMetricDeltaTextProps>(
({ theme, metricColor }) => ({
color: getMetricColor(theme, metricColor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import React, { ReactElement } from "react"

import { cleanup, screen } from "@testing-library/react"
import { transparentize } from "color2k"
import ReactMarkdown from "react-markdown"

import IsDialogContext from "~lib/components/core/IsDialogContext"
import IsSidebarContext from "~lib/components/core/IsSidebarContext"
import { LibContext } from "~lib/components/core/LibContext"
import { mockTheme } from "~lib/mocks/mockTheme"
import { render } from "~lib/test_util"
import { getMarkdownBgColors } from "~lib/theme/getColors"
import { colors } from "~lib/theme/primitives/colors"

import StreamlitMarkdown, {
Expand Down Expand Up @@ -137,6 +137,25 @@ describe("linkReference", () => {
})

describe("StreamlitMarkdown", () => {
let bgColors: ReturnType<typeof getMarkdownBgColors>
let backgroundColorMapping: Map<string, string>

beforeAll(() => {
// Use the actual implementation to get background colors
bgColors = getMarkdownBgColors(mockTheme.emotion)

backgroundColorMapping = new Map([
["red", bgColors.redbg],
["orange", bgColors.orangebg],
["yellow", bgColors.yellowbg],
["blue", bgColors.bluebg],
["green", bgColors.greenbg],
["violet", bgColors.violetbg],
["gray", bgColors.graybg],
["grey", bgColors.graybg],
])
})

it("renders header anchors when isInSidebar is false", () => {
const source = "# header"
render(
Expand Down Expand Up @@ -457,26 +476,7 @@ describe("StreamlitMarkdown", () => {
})

it("properly adds background colors", () => {
const redbg = transparentize(colors.red80, 0.9)
const orangebg = transparentize(colors.yellow70, 0.9)
const yellowbg = transparentize(colors.yellow80, 0.9)
const greenbg = transparentize(colors.green70, 0.9)
const bluebg = transparentize(colors.blue70, 0.9)
const violetbg = transparentize(colors.purple70, 0.9)
const graybg = transparentize(colors.gray70, 0.9)

const colorMapping = new Map([
["red", redbg],
["orange", orangebg],
["yellow", yellowbg],
["blue", bluebg],
["green", greenbg],
["violet", violetbg],
["gray", graybg],
["grey", graybg],
])

colorMapping.forEach(function (style, color) {
backgroundColorMapping.forEach(function (style, color) {
const source = `:${color}-background[text]`
render(<StreamlitMarkdown source={source} allowHTML={false} />)
const markdown = screen.getByText("text")
Expand All @@ -490,32 +490,16 @@ describe("StreamlitMarkdown", () => {
})

it("properly adds rainbow background color", () => {
const redbg = transparentize(colors.red80, 0.9)
const orangebg = transparentize(colors.yellow70, 0.9)
const yellowbg = transparentize(colors.yellow70, 0.9)
const greenbg = transparentize(colors.green70, 0.9)
const bluebg = transparentize(colors.blue70, 0.9)
const violetbg = transparentize(colors.purple70, 0.9)
const purplebg = transparentize(colors.purple90, 0.9)

const colorMapping = new Map([
[
"rainbow",
`linear-gradient(to right, ${redbg}, ${orangebg}, ${yellowbg}, ${greenbg}, ${bluebg}, ${violetbg}, ${purplebg})`,
],
])
const { redbg, orangebg, yellowbg, greenbg, bluebg, violetbg, purplebg } =
bgColors
const rainbowGradient = `linear-gradient(to right, ${redbg}, ${orangebg}, ${yellowbg}, ${greenbg}, ${bluebg}, ${violetbg}, ${purplebg})`

colorMapping.forEach(function (style, color) {
const source = `:${color}-background[text]`
render(<StreamlitMarkdown source={source} allowHTML={false} />)
const markdown = screen.getByText("text")
const tagName = markdown.nodeName.toLowerCase()
expect(tagName).toBe("span")
expect(markdown).toHaveStyle(`background: ${style}`)

// Removes rendered StreamlitMarkdown component before next case run
cleanup()
})
const source = `:rainbow-background[text]`
render(<StreamlitMarkdown source={source} allowHTML={false} />)
const markdown = screen.getByText("text")
const tagName = markdown.nodeName.toLowerCase()
expect(tagName).toBe("span")
expect(markdown).toHaveStyle(`background: ${rainbowGradient}`)
})

it("renders small text properly", () => {
Expand Down
17 changes: 12 additions & 5 deletions frontend/lib/src/mocks/mockTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ const requiredThemeColors = {
bgColor: colors.white,
secondaryBg: colors.gray20,
bodyText: colors.gray85,
link: colors.blue80,

// TODO (mgbarnes): Transition each of these to updated text colors
warning: colors.yellow110,
warningBg: transparentize(colors.yellow80, 0.8),
success: colors.green100,
successBg: transparentize(colors.green80, 0.8),
infoBg: transparentize(colors.blue70, 0.9),
info: colors.blue100,
danger: colors.red100,
dangerBg: transparentize(colors.red70, 0.8),
link: colors.blue80,

primary: colors.red70,
secondary: colors.blue70,
Expand All @@ -72,6 +70,15 @@ const requiredThemeColors = {
greenColor: colors.green70,
violetColor: colors.purple70,
grayColor: colors.gray60,

// Default background theme colors (light theme)
redBackgroundColor: transparentize(colors.red80, 0.9),
orangeBackgroundColor: transparentize(colors.orange70, 0.9),
yellowBackgroundColor: transparentize(colors.yellow65, 0.9),
blueBackgroundColor: transparentize(colors.blue65, 0.9),
greenBackgroundColor: transparentize(colors.green70, 0.9),
violetBackgroundColor: transparentize(colors.purple60, 0.9),
grayBackgroundColor: transparentize(colors.gray85, 0.9),
}

interface OptionalThemeColors {
Expand Down
23 changes: 15 additions & 8 deletions frontend/lib/src/theme/emotionBaseTheme/themeColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ const requiredThemeColors = {
bgColor: colors.white,
secondaryBg: colors.gray20,
bodyText: colors.gray85,
warning: colors.yellow110,
warningBg: transparentize(colors.yellow80, 0.8),
success: colors.green100,
successBg: transparentize(colors.green80, 0.8),
infoBg: transparentize(colors.blue70, 0.9),
info: colors.blue100,
danger: colors.red100,
dangerBg: transparentize(colors.red70, 0.8),
link: colors.blue80,

primary: colors.red70,
Expand All @@ -42,6 +34,12 @@ const requiredThemeColors = {
gray: colors.gray60,
darkGray: colors.gray70,

// TODO (mgbarnes): Transition each of these to updated text colors
warning: colors.yellow110,
success: colors.green100,
info: colors.blue100,
danger: colors.red100,

// TODO (mgbarnes): Reduce/remove these colors to avoid
// confusion with the default main/text/bg theme colors
red: colors.red80,
Expand All @@ -56,6 +54,15 @@ const requiredThemeColors = {
greenColor: colors.green70,
violetColor: colors.purple70,
grayColor: colors.gray60,

// Default background theme colors (light theme)
redBackgroundColor: transparentize(colors.red80, 0.9),
orangeBackgroundColor: transparentize(colors.orange70, 0.9),
yellowBackgroundColor: transparentize(colors.yellow65, 0.9),
blueBackgroundColor: transparentize(colors.blue65, 0.9),
greenBackgroundColor: transparentize(colors.green70, 0.9),
violetBackgroundColor: transparentize(colors.purple60, 0.9),
grayBackgroundColor: transparentize(colors.gray85, 0.9),
}

export type RequiredThemeColors = Record<
Expand Down
23 changes: 15 additions & 8 deletions frontend/lib/src/theme/emotionDarkTheme/themeColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ export default {
...colors,
bgColor: colors.gray100,
bodyText: colors.gray10,
warning: colors.yellow20,
warningBg: transparentize(colors.yellow70, 0.8),
success: colors.green10,
successBg: transparentize(colors.green60, 0.8),
info: colors.blue20,
infoBg: transparentize(colors.blue60, 0.8),
danger: colors.red20,
dangerBg: transparentize(colors.red60, 0.8),
// Brighten link color a bit so they're easier to read:
link: lighten(colors.blue80, 0.2),

primary: colors.red70,
secondaryBg: colors.gray90,
disabled: colors.gray70,

// TODO (mgbarnes): Transition each of these to updated text colors
warning: colors.yellow20,
success: colors.green10,
info: colors.blue20,
danger: colors.red20,

// TODO (mgbarnes): Reduce/remove these colors to avoid
// confusion with the default main/text/bg theme colors
red: colors.red70,
Expand All @@ -51,4 +49,13 @@ export default {
greenColor: colors.green80,
violetColor: colors.purple70,
grayColor: colors.gray80,

// Default background theme colors (dark theme)
redBackgroundColor: transparentize(colors.red60, 0.8),
orangeBackgroundColor: transparentize(colors.orange80, 0.8),
yellowBackgroundColor: transparentize(colors.yellow65, 0.8),
blueBackgroundColor: transparentize(colors.blue60, 0.8),
greenBackgroundColor: transparentize(colors.green60, 0.8),
violetBackgroundColor: transparentize(colors.purple60, 0.8),
grayBackgroundColor: transparentize(colors.gray70, 0.8),
}
10 changes: 0 additions & 10 deletions frontend/lib/src/theme/emotionLightTheme/themeColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@
* limitations under the License.
*/

import { transparentize } from "color2k"

import { colors } from "~lib/theme/primitives/colors"

export default {
...colors,
// For this one, we use a specific color,
// outside our standard color palette,
// to ensure contrast is good enough for accessibility
warning: "#926C05",
warningBg: transparentize(colors.yellow70, 0.9),
successBg: transparentize(colors.green70, 0.9),
danger: colors.red100,
dangerBg: transparentize(colors.red80, 0.91),
}
Loading
Loading