diff --git a/package.json b/package.json
index c06f2f0d..e7415666 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@netdata/netdata-ui",
- "version": "5.7.0",
+ "version": "5.8.0",
"description": "netdata UI kit",
"main": "dist/index.js",
"module": "dist/es6/index.js",
diff --git a/src/components/button/README.md b/src/components/button/README.md
index 95856be4..39088eb4 100644
--- a/src/components/button/README.md
+++ b/src/components/button/README.md
@@ -67,7 +67,7 @@ const myButton: Button = (
### Surface appearance
-`` uses `controlBackground` and the softer `border` at rest. Hover uses `controlHoverBackground`, `controlBorder`, and `controlHoverText`; active, expanded, and pressed controls use `controlPressedBackground`, `controlBorder`, and `controlPressedText`. Resting label ink uses `controlText`. All three text roles default to the existing `textFocus` value in each theme. Resting icons follow the label unless `iconColor` is set; hover follows the existing label-ink behavior. `colorPalette` can remap these theme roles, including token arrays such as `colorPalette={{ controlBackground: ["transparent", "full"] }}` to preserve an originally transparent control.
+`` uses `controlBackground` and `controlBorder` at rest. Hover uses `controlHoverBackground`, `inputBorderHover`, and `controlHoverText`; active, expanded, and pressed controls use `controlPressedBackground`, `inputBorderHover`, and `controlPressedText`. Resting label ink uses `controlText`. All three text roles default to the existing `textFocus` value in each theme. Resting icons follow the label unless `iconColor` is set; hover follows the existing label-ink behavior. `colorPalette` can remap these theme roles, including token arrays such as `colorPalette={{ controlBackground: ["transparent", "full"] }}` to preserve an originally transparent control.
Use `colorPalette={{ controlText: "statusMutedText", controlHoverText: "textFocus", controlPressedText: "textFocus" }}` for a muted trigger that gains emphasis on interaction.
diff --git a/src/components/button/buttonGroup.test.js b/src/components/button/buttonGroup.test.js
index 3268178d..70045ba0 100644
--- a/src/components/button/buttonGroup.test.js
+++ b/src/components/button/buttonGroup.test.js
@@ -547,7 +547,7 @@ describe("ButtonGroup", () => {
"light",
DefaultTheme,
"#F0F3F0",
- "#E0E7E2",
+ "#FFFFFF",
"0 0 0 1px #D3DBD5,0 1px 2px rgba(23, 32, 32, 0.14)",
"#007830",
],
@@ -587,7 +587,8 @@ describe("ButtonGroup", () => {
expect(selected).toHaveStyleRule("background-color", selectedBackground)
expect(selected).toHaveStyleRule("box-shadow", shadow)
expect(selected).toHaveStyleRule("font-weight", "600")
- expect(selected).toHaveStyleRule("color", theme.colors.textFocus)
+ expect(selected).toHaveStyleRule("color", theme.colors.text)
+ expect(selected).toHaveStyleRule("color", theme.colors.text, { modifier: ":hover" })
expect(idle).toHaveStyleRule("color", theme.colors.statusMutedText)
expect(idle).toHaveStyleRule("font-weight", "500")
expect(idle).toHaveStyleRule("box-shadow", "none")
diff --git a/src/components/button/segmented.js b/src/components/button/segmented.js
index 77db5944..013f6aba 100644
--- a/src/components/button/segmented.js
+++ b/src/components/button/segmented.js
@@ -72,7 +72,7 @@ export const RaisedSegmentedItem = styled(Flex).attrs(
height: height === undefined ? (compact ? 5.5 : 6.5) : height,
padding: padding === undefined ? [0, compact ? 2 : 2.5] : padding,
round: round === undefined ? (compact ? 1 : 1.5) : round,
- color: active ? (accent ? "segmentedAccentText" : "textFocus") : "statusMutedText",
+ color: active ? (accent ? "segmentedAccentText" : "text") : "statusMutedText",
background: active
? accent
? "segmentedAccentBackground"
@@ -104,7 +104,9 @@ export const RaisedSegmentedItem = styled(Flex).attrs(
&:hover {
color: ${({ active, accent, _hover }) =>
- getColor(_hover?.color || (active && accent ? "segmentedAccentText" : "textFocus"))};
+ getColor(
+ _hover?.color || (active ? (accent ? "segmentedAccentText" : "text") : "textFocus")
+ )};
}
&:focus-visible {
diff --git a/src/components/button/styled.js b/src/components/button/styled.js
index cec7813e..71870650 100644
--- a/src/components/button/styled.js
+++ b/src/components/button/styled.js
@@ -156,9 +156,9 @@ const colorsByFlavour = ({
bg: getColor("controlBackground"),
bgHover: getColor("controlHoverBackground"),
bgActive: getColor("controlPressedBackground"),
- border: getColor("border"),
- borderHover: getColor("controlBorder"),
- borderActive: getColor("controlBorder"),
+ border: getColor("controlBorder"),
+ borderHover: getColor("inputBorderHover"),
+ borderActive: getColor("inputBorderHover"),
iconColor: specialIconColor || getColor("controlText"),
}
: {}
diff --git a/src/components/button/surface.test.js b/src/components/button/surface.test.js
index 08f457b8..ff7fe152 100644
--- a/src/components/button/surface.test.js
+++ b/src/components/button/surface.test.js
@@ -20,13 +20,13 @@ describe.each(themes)("surface Button in %s", (name, theme) => {
expect(button).toHaveStyleRule("background-color", theme.colors.controlBackground, {
modifier: "&&",
})
- expect(button).toHaveStyleRule("border-color", theme.colors.border, { modifier: "&&" })
+ expect(button).toHaveStyleRule("border-color", theme.colors.controlBorder, { modifier: "&&" })
expect(button).toHaveStyleRule("color", theme.colors.textFocus, { modifier: "&&" })
expect(button).toHaveStyleRule("border-radius", "4px", { modifier: "&&" })
expect(button).toHaveStyleRule("background-color", theme.colors.controlHoverBackground, {
modifier: "&&:hover",
})
- expect(button).toHaveStyleRule("border-color", theme.colors.controlBorder, {
+ expect(button).toHaveStyleRule("border-color", theme.colors.inputBorderHover, {
modifier: "&&:hover",
})
expect(button).toHaveStyleRule("color", theme.colors.textFocus, { modifier: "&&:hover" })
@@ -34,7 +34,7 @@ describe.each(themes)("surface Button in %s", (name, theme) => {
expect(button).toHaveStyleRule("background-color", theme.colors.controlPressedBackground, {
modifier,
})
- expect(button).toHaveStyleRule("border-color", theme.colors.controlBorder, { modifier })
+ expect(button).toHaveStyleRule("border-color", theme.colors.inputBorderHover, { modifier })
expect(button).toHaveStyleRule("color", theme.colors.textFocus, { modifier })
}
})
@@ -123,7 +123,7 @@ describe.each(themes)("surface Button in %s", (name, theme) => {
expect(button).toHaveStyleRule("background-color", theme.colors.controlBackground, {
modifier: '&&[aria-disabled="true"]:hover',
})
- expect(button).toHaveStyleRule("border-color", theme.colors.border, {
+ expect(button).toHaveStyleRule("border-color", theme.colors.controlBorder, {
modifier: '&&[aria-disabled="true"]:hover',
})
})
diff --git a/src/components/drops/dropdownStyles.d.ts b/src/components/drops/dropdownStyles.d.ts
index bb2bcff0..1b71beb1 100644
--- a/src/components/drops/dropdownStyles.d.ts
+++ b/src/components/drops/dropdownStyles.d.ts
@@ -15,7 +15,13 @@ export function getDropdownOptionColors(
theme: DropdownTheme,
selectionStyle?: DropdownSelectionStyle,
surface?: string
-): { hover: string; selected: string; selectedHover: string; selectedText: string }
+): {
+ hover: string
+ selected: string
+ selectedHover: string
+ selectedText: string
+ pressed: string
+}
export function withDropdownDefaults(
props: T
diff --git a/src/components/drops/dropdownStyles.js b/src/components/drops/dropdownStyles.js
index bd386934..f979b207 100644
--- a/src/components/drops/dropdownStyles.js
+++ b/src/components/drops/dropdownStyles.js
@@ -10,7 +10,7 @@ export const insetMenuRowRound = 1.75
export const menuSelectionMarker = ({ theme }) =>
`inset ${getSizeBy(0.375)({ theme })} 0 0 ${getColor("primary")({ theme })}`
-export const getDropdownOptionColors = (theme, selectionStyle = "marker", surface = "dropdown") => {
+export const getDropdownOptionColors = (theme, selectionStyle = "marker") => {
const { colors } = theme
if (selectionStyle !== "quiet") {
return {
@@ -18,14 +18,17 @@ export const getDropdownOptionColors = (theme, selectionStyle = "marker", surfac
selected: colors.menuItemSelected,
selectedHover: colors.menuItemSelectedHover,
selectedText: colors.menuItemSelectedText,
+ pressed: colors.menuItemSelected,
}
}
- const background = colors[surface] || colors.dropdown
- const contrast = colors.neutral[theme.name === "Dark" ? "white" : "black"]
- const mix = amount => `color-mix(in srgb, ${background}, ${contrast} ${amount}%)`
-
- return { hover: mix(9), selected: mix(14), selectedHover: mix(18), selectedText: colors.text }
+ return {
+ hover: colors.tableRowBgHover,
+ selected: "transparent",
+ selectedHover: colors.tableRowBgHover,
+ selectedText: colors.text,
+ pressed: colors.selected,
+ }
}
export const withDropdownDefaults = props =>
diff --git a/src/components/drops/menu/dropdownItem.test.js b/src/components/drops/menu/dropdownItem.test.js
index 03f64b2c..8bccac3f 100644
--- a/src/components/drops/menu/dropdownItem.test.js
+++ b/src/components/drops/menu/dropdownItem.test.js
@@ -128,9 +128,9 @@ describe("DropdownItem row styles", () => {
})
it.each([
- ["light", DefaultTheme, "black"],
- ["dark", DarkTheme, "white"],
- ])("uses neutral row states in a quiet custom option in %s", (_, theme, ink) => {
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+ ])("uses neutral row states in a quiet custom option in %s", (_, theme) => {
renderWithProviders(
row
@@ -138,11 +138,10 @@ describe("DropdownItem row styles", () => {
{ theme }
)
- const { dropdown, neutral, text } = theme.colors
- const mix = amount => `color-mix(in srgb, ${dropdown}, ${neutral[ink]} ${amount}%)`
+ const { tableRowBgHover, text } = theme.colors
expect(option()).toHaveStyleRule("color", text)
- expect(option()).toHaveStyleRule("background-color", mix(14))
- expect(option()).toHaveStyleRule("background-color", mix(18), { modifier: ":hover" })
+ expect(option()).toHaveStyleRule("background-color", "transparent")
+ expect(option()).toHaveStyleRule("background-color", tableRowBgHover, { modifier: ":hover" })
expect(option()).not.toHaveStyleRule("box-shadow", expect.stringContaining("inset 3px"))
expect(option().querySelector("svg")).toBeNull()
})
diff --git a/src/components/input/input.d.ts b/src/components/input/input.d.ts
index 60a53659..009b8b2a 100644
--- a/src/components/input/input.d.ts
+++ b/src/components/input/input.d.ts
@@ -51,6 +51,7 @@ export interface InputProps extends InputTypographyProps {
autoFocus?: boolean
// "tiny" and "compact" are 24px; "small" and "large" (the default) are 30px.
size?: "tiny" | "compact" | "small" | "large"
+ appearance?: "surface"
}
export interface MetaOptions {
@@ -80,6 +81,7 @@ export type TextInputProps = InputProps &
type InputControlStyleProps = Omit &
InputTypographyProps & {
size?: InputProps["size"]
+ appearance?: InputProps["appearance"]
error?: boolean | string
hasValue?: boolean
textAlign?: CSSProperties["textAlign"]
diff --git a/src/components/input/styled.js b/src/components/input/styled.js
index 31982516..c6271286 100644
--- a/src/components/input/styled.js
+++ b/src/components/input/styled.js
@@ -4,6 +4,7 @@ import Flex from "@/components/templates/flex"
import { TextMicro, TextSmall } from "@/components/typography"
import { getColor, getOrElse, getSizeBy, getValidatedControlColor } from "@/theme/utils"
import { fieldFocusRing } from "@/mixins/focusRing"
+import { fieldHalo, fieldSurfaceRound } from "@/mixins/fieldSurface"
import { controlHeight, controlFontSize } from "@/mixins/controlSize"
import { FONT_MONOSPACE } from "@/theme/default/constants"
@@ -39,15 +40,27 @@ const ownFocusSurface = css`
}
`
+const isSurface = ({ appearance }) => appearance === "surface"
+
+const surfaceFocusRing = css`
+ &:focus-visible {
+ border-color: ${({ error }) => getColor(error ? "error" : "segmentedFocus")};
+ ${({ error }) => fieldHalo(error ? "error" : "segmentedFocus")}
+ }
+`
+
+const restBackground = props => (isSurface(props) ? "panelBg" : "controlBackground")
+const hoverBackground = props => (isSurface(props) ? "panelBg" : "controlHoverBackground")
+
export const Input = styled(Flex).attrs(props => ({
- round: 1,
+ round: isSurface(props) ? fieldSurfaceRound * 2 : 1,
as: "input",
- background: "controlBackground",
+ background: restBackground(props),
width: "100%",
border: props.error ? "error" : "controlBorder",
_hover: {
border: props.error ? "error" : "inputBorderHover",
- background: props.disabled ? undefined : "controlHoverBackground",
+ background: props.disabled ? undefined : hoverBackground(props),
},
padding: fieldPadding(props.size),
height: controlHeight(fieldSizeOf(props.size))(props),
@@ -89,6 +102,7 @@ export const Input = styled(Flex).attrs(props => ({
${fieldFocusRing}
${props => props.background !== ghostBackground && ownFocusSurface}
${({ error }) => error && errorFocusRing}
+ ${props => isSurface(props) && surfaceFocusRing}
&::placeholder {
font-size: ${fieldFontSize};
diff --git a/src/components/input/surface.test.js b/src/components/input/surface.test.js
new file mode 100644
index 00000000..c28fd91b
--- /dev/null
+++ b/src/components/input/surface.test.js
@@ -0,0 +1,43 @@
+import { renderWithProviders, screen } from "testUtilities"
+import { DefaultTheme, DarkTheme } from "@/theme"
+import { fieldHaloShadow } from "@/mixins/fieldSurface"
+import { TextInput } from "./input"
+
+describe.each([
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+])("surface TextInput in %s", (name, theme) => {
+ const { panelBg, controlBorder, inputBorderHover, segmentedFocus, error } = theme.colors
+
+ it("keeps a filled field through hover and focus", () => {
+ renderWithProviders( {}} />, {
+ theme,
+ })
+ const field = screen.getByRole("textbox", { name: "host" })
+
+ expect(field).toHaveStyleRule("background-color", panelBg)
+ expect(field).toHaveStyleRule("border", `1px solid ${controlBorder}`)
+ expect(field).toHaveStyleRule("border-radius", "6px")
+ expect(field).toHaveStyleRule("border", `1px solid ${inputBorderHover}`, {
+ modifier: "&:hover",
+ })
+ expect(field).toHaveStyleRule("background-color", panelBg, { modifier: "&:hover" })
+ expect(field).toHaveStyleRule("border-color", segmentedFocus, { modifier: "&:focus-visible" })
+ expect(field).toHaveStyleRule("background-color", panelBg, { modifier: "&:focus-visible" })
+ expect(field).toHaveStyleRule("box-shadow", fieldHaloShadow(segmentedFocus), {
+ modifier: "&:focus-visible",
+ })
+ })
+
+ it("rings an invalid field in the error colour", () => {
+ renderWithProviders( {}} />, {
+ theme,
+ })
+ const field = screen.getByRole("textbox", { name: "port" })
+
+ expect(field).toHaveStyleRule("border-color", error, { modifier: "&:focus-visible" })
+ expect(field).toHaveStyleRule("box-shadow", fieldHaloShadow(error), {
+ modifier: "&:focus-visible",
+ })
+ })
+})
diff --git a/src/components/select/index.d.ts b/src/components/select/index.d.ts
index 3f8ffff6..0f8a800b 100644
--- a/src/components/select/index.d.ts
+++ b/src/components/select/index.d.ts
@@ -1,4 +1,4 @@
-import { FC } from "react"
+import { FC, ReactNode } from "react"
import { Props } from "react-select"
import { DropdownSelectionStyle } from "../drops/dropdownStyles"
@@ -7,8 +7,12 @@ export interface SelectProps extends Props {
"data-testid"?: string
estimatedOptionHeight?: number
selectionStyle?: DropdownSelectionStyle
+ appearance?: "surface"
+ menuFooter?: ReactNode
}
+export declare const selectSurfaceStyles: (theme: any) => NonNullable
+
declare const Select: FC
export { Select }
diff --git a/src/components/select/index.js b/src/components/select/index.js
index 78fac978..8a614d0c 100644
--- a/src/components/select/index.js
+++ b/src/components/select/index.js
@@ -14,8 +14,10 @@ import {
insetMenuRowRound,
menuSelectionMarker,
} from "@/components/drops/dropdownStyles"
-import { getSizeBy } from "@/theme"
+import Box from "@/components/templates/box"
+import { getColor, getSizeBy } from "@/theme"
import { controlHeight, controlFontSize } from "@/mixins/controlSize"
+import { chevronMark, fieldHaloShadow, fieldSurfaceRound } from "@/mixins/fieldSurface"
const useDataAttrs = (props, name) => {
const { "data-ga": dataGA, "data-testid": dataTestId } = props.selectProps
@@ -53,6 +55,43 @@ const withDOMDataAttrs = (Component, name) => props => {
}
const OriginalOption = defaultComponents.Option
+const OriginalMenu = defaultComponents.Menu
+
+// react-select keeps the hovered option in the Select's own state, so every hover rebuilds every option.
+const withoutHoverState = innerProps => ({
+ ...innerProps,
+ onMouseMove: undefined,
+ onMouseOver: undefined,
+})
+
+const pointerFreeOptions = new WeakMap()
+
+const pointerFree = Component => {
+ if (!pointerFreeOptions.has(Component))
+ pointerFreeOptions.set(Component, props => (
+
+ ))
+ return pointerFreeOptions.get(Component)
+}
+
+const MenuFooter = styled(Box)`
+ padding: ${getSizeBy(0.75)} ${getSizeBy(1.5)};
+ border-top: 1px solid ${getColor("border")};
+ font-size: ${getSizeBy(1.5)};
+ line-height: 18px;
+ color: ${getColor("statusMutedText")};
+`
+
+const Menu = props => (
+
+ {props.children}
+ {props.selectProps.menuFooter ? (
+
+ {props.selectProps.menuFooter}
+
+ ) : null}
+
+)
const OptionLabel = styled.span`
min-width: 0;
@@ -62,9 +101,10 @@ const OptionLabel = styled.span`
`
const Option = props => {
- const { children, data, innerProps, isMulti, isSelected, selectProps } = props
+ const { children, data, isMulti, isSelected, selectProps } = props
const title = typeof children === "string" ? children : undefined
const quiet = selectProps.selectionStyle === "quiet"
+ const innerProps = withoutHoverState(props.innerProps)
return (
@@ -91,7 +131,7 @@ const customComponents = {
IndicatorSeparator: null,
Input: withDOMDataAttrs(defaultComponents.Input, "Input"),
LoadingIndicator: withDataAttrs(defaultComponents.LoadingIndicator, "LoadingIndicator"),
- Menu: withDataAttrs(defaultComponents.Menu, "Menu"),
+ Menu: withDataAttrs(Menu, "Menu"),
MenuList: withDataAttrs(defaultComponents.MenuList, "MenuList"),
MenuPortal: withDataAttrs(defaultComponents.MenuPortal, "MenuPortal"),
LoadingMessage: withDataAttrs(defaultComponents.LoadingMessage, "LoadingMessage"),
@@ -165,7 +205,59 @@ const getControlBorder = (theme, state) => {
return theme.colors.controlBorder
}
-const makeCustomStyles = (theme, selectionStyle, { minWidth, ...providedStyles } = {}) => {
+export const selectSurfaceStyles = theme => {
+ const { panelBg, controlBorder, inputBorderHover, placeholder, segmentedFocus, text } =
+ theme.colors
+ const muted = theme.colors.statusMutedText
+ const fontSize = fontSizeOf(theme)
+
+ return {
+ control: (styles, state) => ({
+ ...styles,
+ outline: "none",
+ borderRadius: sizeBy(theme, fieldSurfaceRound),
+ ...(state.isDisabled ? {} : { backgroundColor: panelBg }),
+ borderColor: state.isFocused ? segmentedFocus : controlBorder,
+ boxShadow: state.isFocused ? fieldHaloShadow(segmentedFocus) : "none",
+ ":hover": {
+ borderColor: state.isFocused ? segmentedFocus : inputBorderHover,
+ },
+ }),
+ dropdownIndicator: styles => ({
+ ...styles,
+ padding: `0 ${sizeBy(theme, 1.5)} 0 ${sizeBy(theme, 0.25)}`,
+ color: muted,
+ ":hover": { color: text },
+ "& svg": { display: "none" },
+ "&::after": chevronMark,
+ }),
+ input: styles => ({ ...styles, color: text }),
+ singleValue: (styles, state) => ({
+ ...styles,
+ fontSize,
+ color: state.isDisabled ? muted : text,
+ }),
+ placeholder: styles => ({ ...styles, fontSize, color: placeholder }),
+ groupHeading: styles => ({
+ ...styles,
+ textTransform: "none",
+ fontSize: 11,
+ lineHeight,
+ fontWeight: 600,
+ color: muted,
+ }),
+ }
+}
+
+const appearanceStylesBy = { surface: selectSurfaceStyles }
+
+const makeCustomStyles = (
+ theme,
+ selectionStyle,
+ { minWidth, ...providedStyles } = {},
+ appearance
+) => {
+ const appearanceStyles = appearanceStylesBy[appearance]?.(theme)
const optionColors = getDropdownOptionColors(theme, selectionStyle)
const fontSize = fontSizeOf(theme)
const minHeight = Number.parseFloat(controlHeight("default")({ theme }))
@@ -268,8 +360,19 @@ const makeCustomStyles = (theme, selectionStyle, { minWidth, ...providedStyles }
// The placeholder colour is close to body text, so disabled options also fade like other disabled controls.
opacity: state.isDisabled ? 0.4 : 1,
cursor: state.isDisabled ? "not-allowed" : "pointer",
+ ...(state.isDisabled
+ ? {}
+ : {
+ ":hover": {
+ backgroundColor: state.isSelected ? optionColors.selectedHover : optionColors.hover,
+ },
+ // While the pointer drives the list, only the row under it is highlighted.
+ "[data-pointing] &:not(:hover)": {
+ backgroundColor: state.isSelected ? optionColors.selected : "transparent",
+ },
+ }),
":active": {
- backgroundColor: state.isDisabled ? "transparent" : optionColors.selected,
+ backgroundColor: state.isDisabled ? "transparent" : optionColors.pressed,
},
fontSize,
lineHeight,
@@ -302,6 +405,7 @@ const makeCustomStyles = (theme, selectionStyle, { minWidth, ...providedStyles }
minHeight: innerMinHeight,
padding: `0 ${sizeBy(theme, 1.5)}`,
}),
+ ...appearanceStyles,
...providedStyles,
}
}
@@ -310,12 +414,18 @@ const MenuList = props => ({
+ ...components,
+ ...provided,
+ ...(provided.Option ? { Option: pointerFree(provided.Option) } : {}),
+})
+
const getAttrs = props => ({
...props,
insetMenuContent: !props.styles?.menuList && !props.components?.MenuList,
- components: props.components ? { ...components, ...props.components } : components,
+ components: props.components ? mergeComponents(props.components) : components,
theme: makeCustomTheme(props.theme),
- styles: makeCustomStyles(props.theme, props.selectionStyle, props.styles),
+ styles: makeCustomStyles(props.theme, props.selectionStyle, props.styles, props.appearance),
})
const SelectComponent = styled(ReactSelect).attrs(getAttrs)``
diff --git a/src/components/select/index.test.js b/src/components/select/index.test.js
index 3cffdf06..668f42b8 100644
--- a/src/components/select/index.test.js
+++ b/src/components/select/index.test.js
@@ -1,7 +1,7 @@
import { renderWithProviders, screen, user, within } from "testUtilities"
import { DefaultTheme } from "@/theme/default"
import { DarkTheme } from "@/theme/dark"
-import Select from "."
+import Select, { selectSurfaceStyles } from "."
const rgb = hex => {
const n = parseInt(hex.slice(1), 16)
@@ -122,30 +122,40 @@ describe("Select", () => {
})
it.each([
- ["light", DefaultTheme, "black"],
- ["dark", DarkTheme, "white"],
- ])(
- "shows quiet choices with a check and neutral keyboard focus in %s",
- async (_, theme, ink) => {
- setup({ defaultValue: options[1], selectionStyle: "quiet" }, { theme })
- const u = await openMenu()
- const selected = screen.getAllByTestId("selOption").find(el => el.textContent === "Two")
- const { dropdown, neutral, text } = theme.colors
- const mix = amount =>
- `color-mix(in srgb, ${rgb(dropdown)} ${100 - amount}%, ${rgb(neutral[ink])})`
-
- expect(style(selected).backgroundColor).toBe(mix(18))
- expect(style(selected).color).toBe(rgb(text))
- expect(style(selected).boxShadow).toBe("none")
- expect(selected.lastElementChild?.getAttribute("aria-hidden")).toBe("true")
-
- await u.keyboard("{ArrowDown}")
- expect(style(selected).backgroundColor).toBe(mix(14))
- expect(style(document.querySelector(".rs__option--is-focused")).backgroundColor).toBe(
- mix(9)
- )
- }
- )
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+ ])("shows quiet choices with a check and neutral keyboard focus in %s", async (_, theme) => {
+ setup({ defaultValue: options[1], selectionStyle: "quiet" }, { theme })
+ const u = await openMenu()
+ const selected = screen.getAllByTestId("selOption").find(el => el.textContent === "Two")
+ const { tableRowBgHover, text } = theme.colors
+
+ expect(style(selected).backgroundColor).toBe(rgb(tableRowBgHover))
+ expect(style(selected).color).toBe(rgb(text))
+ expect(style(selected).boxShadow).toBe("none")
+ expect(selected.lastElementChild?.getAttribute("aria-hidden")).toBe("true")
+
+ await u.keyboard("{ArrowDown}")
+ expect(style(selected).backgroundColor).toBe("rgba(0, 0, 0, 0)")
+ expect(style(document.querySelector(".rs__option--is-focused")).backgroundColor).toBe(
+ rgb(tableRowBgHover)
+ )
+ })
+
+ it.each([
+ ["quiet", "selected"],
+ ["marker", "menuItemSelected"],
+ ])("presses a %s option with the %s tint", async (selectionStyle, token) => {
+ setup({ selectionStyle })
+ await openMenu()
+ const option = screen.getAllByTestId("selOption")[0]
+ const pressed = [...document.styleSheets]
+ .flatMap(sheet => [...sheet.cssRules])
+ .find(rule => rule.selectorText === `.${option.className.split(" ").pop()}:active`)
+ expect(pressed.cssText).toBe(
+ `${pressed.selectorText} {background-color: ${DefaultTheme.colors[token]};}`
+ )
+ })
it("uses passive checkboxes for quiet multi-choice options", async () => {
setup({
@@ -361,3 +371,61 @@ it("keeps the active option mounted when it belongs to a distant group", async (
const active = screen.getByRole("option", { name: "Grouped option 100" })
expect(screen.getByRole("combobox")).toHaveAttribute("aria-activedescendant", active.id)
})
+
+describe.each([
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+])("surface Select in %s", (name, theme) => {
+ const { panelBg, controlBorder, segmentedFocus, statusMutedText } = theme.colors
+
+ it("rests as a filled field", () => {
+ setup({ appearance: "surface" }, { theme })
+ const control = screen.getByTestId("selControl")
+
+ expect(style(control).backgroundColor).toBe(rgb(panelBg))
+ expect(style(control).borderColor).toBe(rgb(controlBorder))
+ expect(style(control).borderRadius).toBe("6px")
+ expect(style(control).minWidth).not.toBe("160px")
+ expect(style(control).opacity).toBe("")
+ expect(style(screen.getByTestId("selDropdownIndicator")).color).toBe(rgb(statusMutedText))
+ })
+
+ it("keeps its fill and takes the focus edge with a halo when focused", async () => {
+ setup({ appearance: "surface" }, { theme })
+ await user().click(screen.getByRole("combobox"))
+ const control = screen.getByTestId("selControl")
+
+ expect(style(control).backgroundColor).toBe(rgb(panelBg))
+ expect(style(control).borderColor).toBe(rgb(segmentedFocus))
+ expect(style(control).boxShadow).toContain("0 0 0 3px")
+ })
+
+ it("lets a site extend one part of the surface", () => {
+ const surface = selectSurfaceStyles(theme)
+ setup(
+ {
+ appearance: "surface",
+ styles: {
+ control: (base, state) => ({ ...surface.control(base, state), borderTopRightRadius: 0 }),
+ },
+ },
+ { theme }
+ )
+ const control = screen.getByTestId("selControl")
+
+ expect(style(control).borderTopRightRadius).toBe("0")
+ expect(style(control).backgroundColor).toBe(rgb(panelBg))
+ })
+
+ it("does not fade a disabled field", () => {
+ setup({ appearance: "surface", isDisabled: true }, { theme })
+
+ expect(style(screen.getByTestId("selControl")).opacity).toBe("")
+ })
+})
+
+it("keeps replacing a part's styles when no appearance is set", () => {
+ setup({ styles: { control: base => ({ ...base, borderTopRightRadius: 0 }) } })
+
+ expect(style(screen.getByTestId("selControl")).minHeight).not.toBe("30px")
+})
diff --git a/src/components/select/largeMenu.test.js b/src/components/select/largeMenu.test.js
new file mode 100644
index 00000000..86e7a4f2
--- /dev/null
+++ b/src/components/select/largeMenu.test.js
@@ -0,0 +1,112 @@
+import { renderWithProviders, screen, user, fireEvent } from "testUtilities"
+import Select from "."
+
+const flat = Array.from({ length: 300 }, (_, i) => ({ label: `system.ctx${i}`, value: `ctx${i}` }))
+const grouped = [
+ { label: "Host labels", options: flat.slice(0, 150) },
+ { label: "Chart labels", options: flat.slice(150) },
+]
+
+const open = async (props = {}) => {
+ const labels = jest.fn(option => option.label)
+ renderWithProviders(
+
+ )
+ await user().click(screen.getByRole("combobox"))
+ return labels
+}
+
+const rows = () => [...document.querySelectorAll(".rs__option")]
+const rules = () => [...document.styleSheets].flatMap(sheet => [...sheet.cssRules])
+const hoverRuleOf = row =>
+ rules().find(rule => [...row.classList].some(name => rule.selectorText === `.${name}:hover`))
+
+describe("Select with many options", () => {
+ it("does no option work when the pointer moves over a row", async () => {
+ const labels = await open()
+ const combobox = screen.getByRole("combobox")
+ const active = combobox.getAttribute("aria-activedescendant")
+ labels.mockClear()
+
+ fireEvent.mouseMove(rows()[2])
+ fireEvent.mouseOver(rows()[2])
+
+ expect(labels).not.toHaveBeenCalled()
+ expect(combobox.getAttribute("aria-activedescendant")).toBe(active)
+ })
+
+ it("highlights the row under the pointer through the stylesheet", async () => {
+ await open()
+
+ expect(hoverRuleOf(rows()[2]).style.backgroundColor).not.toBe("")
+ })
+
+ it("still selects the row that is clicked", async () => {
+ const onChange = jest.fn()
+ await open({ onChange })
+
+ await user().click(rows()[2])
+
+ expect(onChange).toHaveBeenCalledWith(flat[2], expect.anything())
+ })
+
+ it("keeps a custom option free of pointer work too", async () => {
+ const Option = ({ innerProps, children }) => (
+
+ {children}
+
+ )
+ const labels = await open({ components: { Option } })
+ labels.mockClear()
+
+ fireEvent.mouseMove(rows()[2])
+ fireEvent.mouseOver(rows()[2])
+
+ expect(labels).not.toHaveBeenCalled()
+ })
+
+ it("mounts only the rows near the viewport of a grouped list", async () => {
+ await open({ options: grouped })
+
+ expect(rows().length).toBeLessThan(40)
+ expect(rows().length).toBeGreaterThan(0)
+ expect(screen.getByText("Host labels")).toBeVisible()
+ })
+
+ it("mounts every row of a short list", async () => {
+ await open({ options: [{ label: "A", options: flat.slice(0, 60) }, { label: "B", options: flat.slice(60, 120) }] })
+
+ expect(rows()).toHaveLength(120)
+ expect(screen.getByText("B")).toBeVisible()
+ })
+
+ it("keeps a grouped list navigable by keyboard across groups", async () => {
+ const onChange = jest.fn()
+ await open({ options: [{ label: "A", options: flat.slice(0, 2) }, { label: "B", options: flat.slice(2, 4) }], onChange })
+
+ await user().keyboard("{ArrowDown}{ArrowDown}{Enter}")
+
+ expect(onChange).toHaveBeenCalledWith(flat[2], expect.anything())
+ })
+
+ it("shows a footer note below the scrolling list", async () => {
+ await open({ menuFooter: "Nodes without the label never match." })
+ const footer = screen.getByText("Nodes without the label never match.")
+
+ expect(document.querySelector(".rs__menu")).toContainElement(footer)
+ expect(document.querySelector(".rs__menu-list")).not.toContainElement(footer)
+ expect(footer).toHaveClass("rs__menu-footer")
+ })
+})
+
+it("keeps the heading of the group being read in view while scrolling", async () => {
+ await open({ options: grouped })
+ const list = document.querySelector(".rs__menu-list")
+
+ Object.defineProperty(list, "scrollTop", { configurable: true, value: 20000 })
+ fireEvent.scroll(list)
+
+ expect(await screen.findByText("Host labels")).toBeVisible()
+ expect(list.querySelector('[data-index="0"]')).not.toBeInTheDocument()
+ expect(screen.queryByText("Chart labels")).not.toBeInTheDocument()
+})
diff --git a/src/components/select/select.usage.mdx b/src/components/select/select.usage.mdx
index 80bfed53..e880fe56 100644
--- a/src/components/select/select.usage.mdx
+++ b/src/components/select/select.usage.mdx
@@ -24,6 +24,7 @@ Options are `{ label, value }`. Add `icon` to show an icon before the label, and
- `isCreatable`: typing offers a "create" option and calls `onCreateOption`.
- `selectionStyle="quiet"`: choices use a neutral hover and selected fill. Single-choice options show a trailing check, and multi-choice options show a checkbox indicator. Set `hideSelectedOptions={false}` to keep checked rows visible in a multi-choice list.
- `selectionStyle="marker"` (default): selected options use the menu tint and a 3px left marker.
+- `appearance="surface"`: a filled editor field with a 6px radius, a `segmentedFocus` edge and soft halo on focus, and a CSS chevron. A `styles` part replaces the matching surface part; extend one with `selectSurfaceStyles(theme)`.
diff --git a/src/components/select/virtualizedMenuList.js b/src/components/select/virtualizedMenuList.js
index 999648f8..82d9d1f3 100644
--- a/src/components/select/virtualizedMenuList.js
+++ b/src/components/select/virtualizedMenuList.js
@@ -1,11 +1,25 @@
-import { Children, cloneElement, isValidElement, useEffect, useLayoutEffect, useRef } from "react"
+import {
+ Children,
+ cloneElement,
+ isValidElement,
+ useEffect,
+ useLayoutEffect,
+ useMemo,
+ useRef,
+} from "react"
import { useVirtualizer } from "@tanstack/react-virtual"
-import { useTheme } from "styled-components"
+import styled, { css, useTheme } from "styled-components"
import { insetMenuPadding } from "@/components/drops/dropdownStyles"
import Box from "@/components/templates/box"
+import { getColor } from "@/theme"
import { mergeRefs } from "@/utils/mergeRefs"
import { virtualRangeWithIndex } from "@/utils/virtualRangeWithIndex"
+const POINTING = "data-pointing"
+// Short lists mount every row: with hover off the render path, windowing only pays off for long ones.
+const WINDOWED_ABOVE = 200
+const WINDOW_OVERSCAN = 5
+
const fullyVisible = (list, index) => {
const row = list?.querySelector(`[data-index="${index}"]`)
if (!row) return false
@@ -14,48 +28,120 @@ const fullyVisible = (list, index) => {
return inner.top >= outer.top && inner.bottom <= outer.bottom
}
+const isGroup = item => !!item.props?.Heading
+
+const withoutScrollRef = option =>
+ isValidElement(option) && "innerRef" in option.props
+ ? cloneElement(option, { innerRef: undefined })
+ : option
+
+// A group is one child of the list, so its options are laid out as rows of their own to be virtualized.
+const rowsOf = children =>
+ Children.toArray(children).flatMap(item => {
+ if (!isGroup(item)) return [{ element: item }]
+ const options = Children.toArray(item.props.children)
+ return [
+ { group: item, heading: true },
+ ...options.map((element, index) => ({
+ element,
+ group: item,
+ last: index === options.length - 1,
+ })),
+ ]
+ })
+
+const GroupHeading = ({ group }) => {
+ const { Heading, headingProps, label, cx, getStyles, getClassNames, theme, selectProps } =
+ group.props
+
+ return (
+
+ {label}
+
+ )
+}
+
+const groupGap = ({ theme }) => `${theme.constants.SIZE_SUB_UNIT * 2}px`
+
+const Row = styled(Box)`
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ ${({ heading }) =>
+ heading &&
+ css`
+ padding-top: ${groupGap};
+ `}
+ ${({ last }) =>
+ last &&
+ css`
+ padding-bottom: ${groupGap};
+ `}
+`
+
+const PinnedSlot = styled(Box)`
+ position: sticky;
+ top: 0;
+ z-index: 1;
+ height: 0;
+`
+
+const PinnedHeading = styled(Box)`
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ background: ${getColor("dropdown")};
+`
+
const VirtualizedMenuList = ({ MenuList, children, innerRef, innerProps, ...props }) => {
const scrollRef = useRef(null)
const opened = useRef(false)
const pointing = useRef(false)
- const items = Children.toArray(children)
- const focused = items.findIndex(
- item =>
- item.props?.isFocused ||
- (item.props?.Heading &&
- Array.isArray(item.props.children) &&
- item.props.children.some(option => option.props.isFocused))
- )
- const focusedOption = items[focused]?.props?.isFocused
+ const rows = useMemo(() => rowsOf(children), [children])
+ const focused = useMemo(() => rows.findIndex(row => row.element?.props?.isFocused), [rows])
const estimate = props.selectProps.estimatedOptionHeight ?? 35
const inset = props.selectProps.insetMenuContent ? insetMenuPadding : 0
const padding = inset * useTheme().constants.SIZE_SUB_UNIT
const virtualizer = useVirtualizer({
- count: items.length,
+ count: rows.length,
getScrollElement: () => scrollRef.current,
estimateSize: () => estimate,
paddingStart: padding,
paddingEnd: padding,
- overscan: 5,
+ overscan: rows.length > WINDOWED_ABOVE ? WINDOW_OVERSCAN : rows.length,
rangeExtractor: range => virtualRangeWithIndex(range, focused),
})
useEffect(() => {
const onKey = () => {
pointing.current = false
+ scrollRef.current?.removeAttribute(POINTING)
}
document.addEventListener("keydown", onKey, true)
return () => document.removeEventListener("keydown", onKey, true)
}, [])
useLayoutEffect(() => {
- if (!focusedOption) return
+ if (focused < 0) return
if (opened.current && (pointing.current || fullyVisible(scrollRef.current, focused))) return
const [offset] =
virtualizer.getOffsetForIndex(focused, opened.current ? "auto" : "center") || []
if (offset !== undefined) virtualizer.scrollToOffset(offset)
opened.current = true
- }, [focused, focusedOption, virtualizer])
+ }, [focused, virtualizer])
+
+ const top = virtualizer.getVirtualItemForOffset(virtualizer.scrollOffset ?? 0)
+ const topRow = rows[top?.index]
+ const pinned = topRow?.group && !topRow.heading ? topRow.group : null
return (
{
+ if (!pointing.current) scrollRef.current?.setAttribute(POINTING, "")
pointing.current = true
innerProps?.onMouseMove?.(event)
},
}}
>
+ {pinned ? (
+
+
+
+
+
+ ) : null}
- {virtualizer.getVirtualItems().map(row => (
-
- {isValidElement(items[row.index]) && "innerRef" in items[row.index].props
- ? cloneElement(items[row.index], { innerRef: undefined })
- : items[row.index]}
-
- ))}
+ {virtualizer.getVirtualItems().map(item => {
+ const row = rows[item.index]
+ return (
+
+ {row.heading ? : withoutScrollRef(row.element)}
+
+ )
+ })}
diff --git a/src/components/table/body/rowStyles.test.js b/src/components/table/body/rowStyles.test.js
index c6c5b6c0..92acd79c 100644
--- a/src/components/table/body/rowStyles.test.js
+++ b/src/components/table/body/rowStyles.test.js
@@ -1,7 +1,6 @@
import "jest-styled-components"
import { renderWithProviders, screen, waitFor } from "testUtilities"
import { DefaultTheme, getRgbColor } from "@/theme"
-import rawColors from "@/theme/rawColors"
import Table from "../table"
const data = [
@@ -121,7 +120,7 @@ describe("Table row hover", () => {
renderRows()
const row = await rowByText("db")
- expect(row).toHaveStyleRule("background-color", rawColors.neutral.grey190, {
+ expect(row).toHaveStyleRule("background-color", DefaultTheme.colors.tableRowBgHover, {
modifier: ":hover",
})
expect(row).toHaveStyleRule("border-bottom", `1px solid ${DefaultTheme.colors.tableBorder}`)
diff --git a/src/components/tabs/styled.js b/src/components/tabs/styled.js
index 47c9060d..4a678eb5 100644
--- a/src/components/tabs/styled.js
+++ b/src/components/tabs/styled.js
@@ -221,13 +221,14 @@ export const VerticalTab = styled(StyledTab).attrs({
})`
justify-content: flex-start;
height: auto;
- color: ${({ active }) => getColor(active ? "menuItemSelectedText" : "text")};
- background: ${({ active }) => getColor(active ? "menuItemSelected" : transparent)};
+ color: ${getColor("text")};
+ background: ${({ active }) => getColor(active ? "segmentedSelectedBackground" : transparent)};
box-shadow: ${({ active, theme }) =>
active ? `inset 3px 0 0 ${getColor("primary")({ theme })}` : "none"};
&:hover {
- background: ${({ active }) => getColor(active ? "menuItemSelectedHover" : "menuItemHover")};
+ background: ${({ active }) =>
+ getColor(active ? "segmentedSelectedBackground" : "menuItemHover")};
}
> span {
diff --git a/src/components/tabs/tabs.test.js b/src/components/tabs/tabs.test.js
index 34e7e7ae..9a417f32 100644
--- a/src/components/tabs/tabs.test.js
+++ b/src/components/tabs/tabs.test.js
@@ -461,12 +461,25 @@ describe("Tabs raised contained appearance", () => {
modifier: ":hover",
})
expect(inactive).toHaveStyleRule("color", theme.colors.statusMutedText)
+ expect(inactive).toHaveStyleRule("color", theme.colors.textFocus, { modifier: ":hover" })
expect(inactive).toHaveStyleRule("box-shadow", "none")
expect(active).toHaveStyleRule("outline-color", theme.colors.segmentedFocus, {
modifier: ":focus-visible",
})
})
+ it.each([
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+ ])("inks the selected non-accent raised tab with text in %s theme", (_, theme) => {
+ const { getAllByRole } = renderRaised({}, { theme })
+ const [active, , inactive] = getAllByRole("tab")
+
+ expect(active).toHaveStyleRule("color", theme.colors.text)
+ expect(active).toHaveStyleRule("color", theme.colors.text, { modifier: ":hover" })
+ expect(inactive).toHaveStyleRule("color", theme.colors.textFocus, { modifier: ":hover" })
+ })
+
it("keeps controlled selection, native activation, and external tab attributes", async () => {
const onChange = jest.fn()
const { getAllByRole, queryByText } = renderWithProviders(
diff --git a/src/components/tabs/vertical.test.js b/src/components/tabs/vertical.test.js
index 76996d61..edf06940 100644
--- a/src/components/tabs/vertical.test.js
+++ b/src/components/tabs/vertical.test.js
@@ -1,5 +1,6 @@
import { renderWithProviders, screen, user } from "testUtilities"
import { Tab, Tabs } from "."
+import { DefaultTheme, DarkTheme } from "@/theme"
it("selects and labels a vertical panel with keyboard navigation", async () => {
renderWithProviders(
@@ -32,3 +33,26 @@ it("selects and labels a vertical panel with keyboard navigation", async () => {
await keyboard.keyboard("{Home}")
expect(info).toHaveFocus()
})
+
+describe.each([
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+])("selected vertical tab in %s", (name, theme) => {
+ it("rests and hovers on the neutral selected surface with body text", () => {
+ renderWithProviders(
+
+ Info panel
+ Nodes panel
+ ,
+ { theme }
+ )
+ const selected = screen.getByRole("tab", { name: "Info" })
+ const { segmentedSelectedBackground, text } = theme.colors
+
+ expect(selected).toHaveStyleRule("color", text)
+ expect(selected).toHaveStyleRule("background", segmentedSelectedBackground)
+ expect(selected).toHaveStyleRule("background", segmentedSelectedBackground, {
+ modifier: "&:hover",
+ })
+ })
+})
diff --git a/src/components/toggle/README.md b/src/components/toggle/README.md
index fde8e340..1cafe734 100644
--- a/src/components/toggle/README.md
+++ b/src/components/toggle/README.md
@@ -41,8 +41,8 @@ export const ContolledToggle = () => {
`"compact"` is 26×16 with a 9px knob. All dimensions use the theme size unit.
`variant="outline"` draws a transparent off track with a 1.5px border. It uses
-`controlBorder` for the off border and knob, `segmentedAccentText` for the checked track,
-`buttonNeutralText` for its checked knob, `textFocus` for off hover, and `segmentedFocus`
+`controlBorder` for the off border and knob, `text` for the checked track,
+`buttonNeutralText` for its checked knob, `inputBorderHover` for off hover, and `segmentedFocus`
for keyboard focus. Disabled outline switches dim the track while their labels stay legible.
The default variant retains its existing palette.
diff --git a/src/components/toggle/outline.test.js b/src/components/toggle/outline.test.js
index a124d61e..dfa427e5 100644
--- a/src/components/toggle/outline.test.js
+++ b/src/components/toggle/outline.test.js
@@ -1,7 +1,9 @@
+import { css } from "styled-components"
import { renderWithProviders, screen, user } from "testUtilities"
import { DefaultTheme } from "@/theme/default"
import { DarkTheme } from "@/theme/dark"
import { Toggle } from "."
+import { StyledLabel } from "./styled"
const OutlineToggle = props => (
{}} {...props} />
@@ -44,13 +46,34 @@ it.each([
})
rerender()
const onTrack = screen.getByRole("switch").nextElementSibling
- expect(onTrack).toHaveStyleRule("background", theme.colors.segmentedAccentText)
- expect(onTrack).toHaveStyleRule("border-color", theme.colors.segmentedAccentText)
+ expect(onTrack).toHaveStyleRule("background", theme.colors.text)
+ expect(onTrack).toHaveStyleRule("border-color", theme.colors.text)
expect(onTrack).toHaveStyleRule("background-color", theme.colors.buttonNeutralText, {
modifier: ":after",
})
})
+it.each([
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+])("darkens the outline edge on hover in the %s theme", (_, theme) => {
+ const hover = {
+ modifier: css`
+ ${StyledLabel}:hover &
+ `,
+ }
+ const { rerender } = renderWithProviders(, { theme })
+ expect(screen.getByRole("switch").nextElementSibling).toHaveStyleRule(
+ "border-color",
+ theme.colors.inputBorderHover,
+ hover
+ )
+ rerender()
+ const onTrack = screen.getByRole("switch").nextElementSibling
+ expect(onTrack).toHaveStyleRule("border-color", theme.colors.text, hover)
+ expect(onTrack).toHaveStyleRule("background", theme.colors.text, hover)
+})
+
it("opts into Enter activation once without submitting its form", async () => {
const onChange = jest.fn()
const onSubmit = jest.fn(e => e.preventDefault())
diff --git a/src/components/toggle/styled.js b/src/components/toggle/styled.js
index 4c02a335..5701aae6 100644
--- a/src/components/toggle/styled.js
+++ b/src/components/toggle/styled.js
@@ -117,12 +117,12 @@ export const StyledToggle = styled.div`
${({ variant, checked, disabled }) =>
variant === "outline" &&
css`
- background: ${checked ? getColor("segmentedAccentText") : getColor(["transparent", "full"])};
+ background: ${checked ? getColor("text") : getColor(["transparent", "full"])};
opacity: ${disabled ? 0.4 : 1};
cursor: ${disabled ? "not-allowed" : "pointer"};
pointer-events: auto;
border-width: ${getSizeBy(0.1875)};
- border-color: ${getColor(checked ? "segmentedAccentText" : "controlBorder")};
+ border-color: ${getColor(checked ? "text" : "controlBorder")};
border-radius: ${getSizeBy(12.5)};
${HiddenToggleInput}:focus-visible + & {
@@ -133,16 +133,20 @@ export const StyledToggle = styled.div`
background-color: ${getColor(checked ? "buttonNeutralText" : "controlBorder")};
}
- ${!disabled &&
- css`
- ${StyledLabel}:hover & {
- border-color: ${getColor(checked ? "segmentedAccentText" : "textFocus")};
- ${checked &&
- css`
- background: ${getColor("segmentedAccentText")};
- `}
- }
- `}
+ ${
+ !disabled &&
+ css`
+ ${StyledLabel}:hover & {
+ border-color: ${getColor(checked ? "text" : "inputBorderHover")};
+ ${
+ checked &&
+ css`
+ background: ${getColor("text")};
+ `
+ }
+ }
+ `
+ }
`}
@media (prefers-reduced-motion: reduce) {
diff --git a/src/index.js b/src/index.js
index a5c9ef30..9afcdfab 100644
--- a/src/index.js
+++ b/src/index.js
@@ -139,7 +139,7 @@ export {
OverflowTooltip,
} from "./components/table"
-export { default as Select } from "./components/select"
+export { default as Select, selectSurfaceStyles } from "./components/select"
export { default as SearchInput } from "./components/search"
export { default as CopyToClipboard } from "./components/copyToClipboard"
diff --git a/src/mixins/fieldSurface.d.ts b/src/mixins/fieldSurface.d.ts
new file mode 100644
index 00000000..4dec93a4
--- /dev/null
+++ b/src/mixins/fieldSurface.d.ts
@@ -0,0 +1,8 @@
+import { CSSObject, RuleSet } from "styled-components"
+import { ColorType } from "./types"
+
+export declare const fieldSurfaceRound: number
+export declare const chevronMark: CSSObject
+export declare const fieldHaloShadow: (color: string) => string
+export declare const fieldHalo: (color?: ColorType) => RuleSet
+export declare const fieldSurface: RuleSet
diff --git a/src/mixins/fieldSurface.js b/src/mixins/fieldSurface.js
new file mode 100644
index 00000000..5f0391ee
--- /dev/null
+++ b/src/mixins/fieldSurface.js
@@ -0,0 +1,36 @@
+import { css } from "styled-components"
+import { getColor, getSizeBy } from "@/theme"
+
+export const fieldSurfaceRound = 0.75
+
+export const chevronMark = {
+ content: '""',
+ boxSizing: "border-box",
+ width: "6px",
+ height: "6px",
+ borderRight: "1.5px solid currentColor",
+ borderBottom: "1.5px solid currentColor",
+ transform: "translateY(-2px) rotate(45deg)",
+}
+
+export const fieldHaloShadow = color => `0 0 0 3px color-mix(in srgb, ${color} 22%, transparent)`
+
+export const fieldHalo = (color = "segmentedFocus") => css`
+ box-shadow: ${props => fieldHaloShadow(getColor(color)(props))};
+`
+
+export const fieldSurface = css`
+ background: ${getColor("panelBg")};
+ border: 1px solid ${getColor("controlBorder")};
+ border-radius: ${getSizeBy(fieldSurfaceRound)};
+
+ &:hover {
+ border-color: ${getColor("inputBorderHover")};
+ }
+
+ &:focus {
+ outline: none;
+ border-color: ${getColor("segmentedFocus")};
+ ${fieldHalo()}
+ }
+`
diff --git a/src/mixins/fieldSurface.test.js b/src/mixins/fieldSurface.test.js
new file mode 100644
index 00000000..1a0e2965
--- /dev/null
+++ b/src/mixins/fieldSurface.test.js
@@ -0,0 +1,57 @@
+import styled from "styled-components"
+import { renderWithProviders, screen } from "testUtilities"
+import { DefaultTheme, DarkTheme } from "@/theme"
+import { chevronMark, fieldSurface, fieldHalo, fieldHaloShadow } from "@/index"
+
+const Field = styled.input`
+ ${fieldSurface}
+`
+
+const Invalid = styled.input`
+ &:focus {
+ ${fieldHalo("statusErrorText")}
+ }
+`
+
+describe.each([
+ ["light", DefaultTheme],
+ ["dark", DarkTheme],
+])("field surface in %s", (name, theme) => {
+ const { panelBg, controlBorder, inputBorderHover, segmentedFocus, statusErrorText } = theme.colors
+
+ it("fills the field, edges it, and marks hover and focus", () => {
+ renderWithProviders(, { theme })
+ const field = screen.getByRole("textbox", { name: "Name" })
+
+ expect(field).toHaveStyleRule("background", panelBg)
+ expect(field).toHaveStyleRule("border", `1px solid ${controlBorder}`)
+ expect(field).toHaveStyleRule("border-radius", "6px")
+ expect(field).toHaveStyleRule("border-color", inputBorderHover, { modifier: "&:hover" })
+ expect(field).toHaveStyleRule("border-color", segmentedFocus, { modifier: "&:focus" })
+ expect(field).toHaveStyleRule("box-shadow", fieldHaloShadow(segmentedFocus), {
+ modifier: "&:focus",
+ })
+ expect(field).toHaveStyleRule("outline", "none", { modifier: "&:focus" })
+ })
+
+ it("draws the halo in any token colour", () => {
+ renderWithProviders(, { theme })
+
+ expect(screen.getByRole("textbox", { name: "Port" })).toHaveStyleRule(
+ "box-shadow",
+ fieldHaloShadow(statusErrorText),
+ { modifier: "&:focus" }
+ )
+ })
+})
+
+it("builds a soft 3px halo from a colour", () => {
+ expect(fieldHaloShadow("#123456")).toBe("0 0 0 3px color-mix(in srgb, #123456 22%, transparent)")
+})
+
+it("draws the chevron from the text colour of its host", () => {
+ expect(chevronMark).toMatchObject({
+ borderRight: "1.5px solid currentColor",
+ borderBottom: "1.5px solid currentColor",
+ })
+})
diff --git a/src/mixins/index.js b/src/mixins/index.js
index f6c70e24..d1ba878c 100644
--- a/src/mixins/index.js
+++ b/src/mixins/index.js
@@ -19,3 +19,4 @@ export {
} from "./focusRing"
export { default as visuallyHidden } from "./visuallyHidden"
+export { chevronMark, fieldSurface, fieldHalo, fieldHaloShadow } from "./fieldSurface"
diff --git a/src/theme/dark/colors.js b/src/theme/dark/colors.js
index 24b5eaf5..5683437d 100644
--- a/src/theme/dark/colors.js
+++ b/src/theme/dark/colors.js
@@ -8,11 +8,13 @@ const appColors = {
main: "#D5DDD7",
border: "#48584D",
borderSecondary: "#344239",
+ chipBorder: "#48584D",
appSidebarBackground: "#1B231E",
appBackground: "#171D19",
workspaceSidebarBackground: "#202723",
workspaceBackground: "#171D19",
tableBorder: "#344239",
+ tableRowBorder: "#29312C",
tableHeaderBackground: "#171D19",
disabled: rawColors.neutral.grey100,
disabledBackground: "#29312C",
@@ -50,7 +52,7 @@ const appColors = {
segmentedBackground: "#29312C",
segmentedSelectedBackground: "rgba(255,255,255,0.11)",
segmentedFocus: rawColors.green.green110,
- segmentedAccentText: "#B0C5B5",
+ segmentedAccentText: "#93c9cb",
segmentedAccentBackground: "#2C342F",
segmentedBorder: "#1E2420",
controlBackground: "#222B25",
@@ -63,7 +65,7 @@ const appColors = {
buttonNeutralFillHover: "#C2CAC4",
buttonNeutralFillPressed: "#CBD1CD",
buttonNeutralText: "#171D19",
- buttonNeutralBorder: "#728077",
+ buttonNeutralBorder: rawColors.neutral.grey120,
buttonNeutralBorderHover: "#98A69D",
buttonNeutralHollowHover: "#2A332D",
buttonNeutralHollowPressed: "#344038",
@@ -173,11 +175,11 @@ const appColors = {
dateTimePickerChipAccent: rawColors.violet.violet120,
// Input colors
// Resting edge for fields: 3:1 against the page so the field is findable without hover.
- controlBorder: "#98A69D",
+ controlBorder: rawColors.neutral.grey120,
textInfo: rawColors.blue.blue150,
inputBg: "#222B25",
inputBorder: "#98A69D",
- inputBorderHover: "#B0C5B5",
+ inputBorderHover: "#98A69D",
inputBorderFocus: "#B0C5B5",
// Badges
nodeBadgeBackground: "#2C342F",
@@ -202,6 +204,12 @@ const appColors = {
negatedTokenMark: "#b6a0f8",
syntaxKey: "#93c9cb",
+ editorAccent: "#93c9cb",
+ modalBackdrop: "rgba(0, 0, 0, 0.5)",
+ dialogShadow: "rgba(0, 0, 0, 0.5)",
+ stripShadow: "rgba(0, 0, 0, 0.7)",
+ logoTileBackground: rawColors.neutral.grey165,
+ searchMatchBackground: "rgba(152, 166, 157, 0.2)",
syntaxNumber: "#d79bf2",
syntaxParen1: "#f38bc0",
syntaxParen2: "#c8c86b",
@@ -210,6 +218,10 @@ const appColors = {
errorContentBackground: "#3a1d22",
thresholdWarningText: "#1f1300",
thresholdCriticalText: "#ffdfe3",
+ thresholdWarningBand: "rgba(191, 113, 0, 0.32)",
+ thresholdWarningZone: "rgba(191, 113, 0, 0.15)",
+ thresholdCriticalBand: "rgba(110, 11, 24, 0.55)",
+ thresholdCriticalZone: "rgba(110, 11, 24, 0.28)",
chartSeries1: "#93c9cb",
chartSeries2: "#a58be0",
chartSeries3: "#b4c0cc",
@@ -224,7 +236,7 @@ const appColors = {
idleClear: rawColors.green.green20,
// Table
- tableRowBgHover: tableRowHover,
+ tableRowBgHover: "#29312C",
tableRowBg: rawColors.neutral.grey25,
tableRowBg2: rawColors.neutral.grey25,
tableRowBg2Hover: tableRowHover,
diff --git a/src/theme/default/colors.js b/src/theme/default/colors.js
index 4be9d2cb..8e2777ec 100644
--- a/src/theme/default/colors.js
+++ b/src/theme/default/colors.js
@@ -6,11 +6,13 @@ const appColors = {
main: "#2D3E33",
border: "#C5D0C8",
borderSecondary: "#DEE6E0",
+ chipBorder: "#D3DBD5",
appSidebarBackground: "#F4F6F4",
appBackground: "#FFFFFF",
workspaceSidebarBackground: "#F2F5F2",
workspaceBackground: "#FFFFFF",
tableBorder: "#DEE6E0",
+ tableRowBorder: "#EEF0EE",
tableHeaderBackground: "#F6F8F6",
disabled: rawColors.neutral.grey160,
disabledBackground: "#EEF3EF",
@@ -45,9 +47,9 @@ const appColors = {
secondaryHighlight: rawColors.green.green190,
neutralHighlight: "#E0E7E2",
segmentedBackground: "#F0F3F0",
- segmentedSelectedBackground: "#E0E7E2",
+ segmentedSelectedBackground: "#FFFFFF",
segmentedFocus: rawColors.green.green70,
- segmentedAccentText: "#476453",
+ segmentedAccentText: "#1d6470",
segmentedAccentBackground: "#E0E7E2",
segmentedBorder: "#D3DBD5",
controlBackground: "#EEF3EF",
@@ -60,7 +62,7 @@ const appColors = {
buttonNeutralFillHover: "#3C5746",
buttonNeutralFillPressed: "#334C3D",
buttonNeutralText: "#FFFFFF",
- buttonNeutralBorder: "#718073",
+ buttonNeutralBorder: rawColors.neutral.grey125,
buttonNeutralBorderHover: "#5C6A61",
buttonNeutralHollowHover: "#E6EEE8",
buttonNeutralHollowPressed: "#D9E4DC",
@@ -172,11 +174,11 @@ const appColors = {
// Input colors
// Resting edge for fields: 3:1 against the page so the field is findable without hover.
- controlBorder: "#5C6A61",
+ controlBorder: rawColors.neutral.grey125,
textInfo: rawColors.blue.blue100,
inputBg: "#EEF3EF",
inputBorder: "#5C6A61",
- inputBorderHover: "#4D5C52",
+ inputBorderHover: "#5C6A61",
inputBorderFocus: "#4D5C52",
// Badges
@@ -202,6 +204,12 @@ const appColors = {
negatedTokenMark: "#6544b0",
syntaxKey: "#1d6470",
+ editorAccent: "#1d6470",
+ modalBackdrop: "rgba(0, 0, 0, 0.28)",
+ dialogShadow: "rgba(0, 0, 0, 0.2)",
+ stripShadow: "rgba(0, 0, 0, 0.18)",
+ logoTileBackground: rawColors.neutral.grey195,
+ searchMatchBackground: "rgba(113, 128, 115, 0.12)",
syntaxNumber: "#8a2aa8",
syntaxParen1: "#b0306a",
syntaxParen2: "#6b6b00",
@@ -210,6 +218,10 @@ const appColors = {
errorContentBackground: "#fceef0",
thresholdWarningText: "#5a3500",
thresholdCriticalText: "#4d0610",
+ thresholdWarningBand: "rgba(255, 224, 179, 0.8)",
+ thresholdWarningZone: "rgba(255, 224, 179, 0.4)",
+ thresholdCriticalBand: "rgba(243, 133, 147, 0.35)",
+ thresholdCriticalZone: "rgba(243, 133, 147, 0.18)",
chartSeries1: "#1d6470",
chartSeries2: "#6b4fbf",
chartSeries3: "#5b6b7a",
@@ -226,7 +238,7 @@ const appColors = {
// Table
dropdownTable: rawColors.neutral.white,
tableRowBg: rawColors.neutral.grey195,
- tableRowBgHover: rawColors.neutral.grey190,
+ tableRowBgHover: "#F0F3F0",
tableRowBg2: rawColors.neutral.grey195,
tableRowBg2Hover: rawColors.neutral.grey180,
columnHighlight: rawColors.neutral.grey190,
diff --git a/src/theme/editorTokens.test.js b/src/theme/editorTokens.test.js
index 59e76503..7ad67807 100644
--- a/src/theme/editorTokens.test.js
+++ b/src/theme/editorTokens.test.js
@@ -1,4 +1,4 @@
-import { DarkTheme, DefaultTheme, getColor } from "./index"
+import { DarkTheme, DefaultTheme, getColor, getRgbColor } from "./index"
describe("editor chip tokens", () => {
it.each([
@@ -18,3 +18,33 @@ describe("editor chip tokens", () => {
expect(getColor(token)({ theme: DarkTheme })).toBe(dark)
})
})
+
+describe("editor surface tokens", () => {
+ it.each([
+ ["editorAccent", "#1d6470", "#93c9cb"],
+ ["modalBackdrop", "rgba(0, 0, 0, 0.28)", "rgba(0, 0, 0, 0.5)"],
+ ["dialogShadow", "rgba(0, 0, 0, 0.2)", "rgba(0, 0, 0, 0.5)"],
+ ["stripShadow", "rgba(0, 0, 0, 0.18)", "rgba(0, 0, 0, 0.7)"],
+ ["logoTileBackground", "#F6F7F7", "#C2CAC4"],
+ ["searchMatchBackground", "rgba(113, 128, 115, 0.12)", "rgba(152, 166, 157, 0.2)"],
+ ])("resolves %s in each theme", (token, light, dark) => {
+ expect(getColor(token)({ theme: DefaultTheme })).toBe(light)
+ expect(getColor(token)({ theme: DarkTheme })).toBe(dark)
+ })
+})
+
+describe("threshold tint tokens", () => {
+ it.each([
+ ["thresholdWarningBand", "warningBackground", 0.8, 0.32],
+ ["thresholdWarningZone", "warningBackground", 0.4, 0.15],
+ ["thresholdCriticalBand", "errorBackground", 0.35, 0.55],
+ ["thresholdCriticalZone", "errorBackground", 0.18, 0.28],
+ ])("resolves %s from %s in each theme", (token, base, lightAlpha, darkAlpha) => {
+ expect(getColor(token)({ theme: DefaultTheme })).toBe(
+ getRgbColor(base, lightAlpha)({ theme: DefaultTheme })
+ )
+ expect(getColor(token)({ theme: DarkTheme })).toBe(
+ getRgbColor(base, darkAlpha)({ theme: DarkTheme })
+ )
+ })
+})
diff --git a/src/theme/index.d.ts b/src/theme/index.d.ts
index cdff1e84..123f56a1 100644
--- a/src/theme/index.d.ts
+++ b/src/theme/index.d.ts
@@ -8,6 +8,7 @@ export type AppColorsT = {
main: string
border: string
borderSecondary: string
+ chipBorder: string
appSidebarBackground: string
appBackground: string
workspaceSidebarBackground: string
@@ -17,6 +18,7 @@ export type AppColorsT = {
menuItemSelectedHover: string
menuItemSelectedText: string
tableBorder: string
+ tableRowBorder: string
tableHeaderBackground: string
segmentedBackground: string
segmentedSelectedBackground: string
@@ -68,6 +70,12 @@ export type AppColorsT = {
negatedTokenText: string
negatedTokenMark: string
syntaxKey: string
+ editorAccent: string
+ modalBackdrop: string
+ dialogShadow: string
+ stripShadow: string
+ logoTileBackground: string
+ searchMatchBackground: string
syntaxNumber: string
syntaxParen1: string
syntaxParen2: string
@@ -76,6 +84,10 @@ export type AppColorsT = {
errorContentBackground: string
thresholdWarningText: string
thresholdCriticalText: string
+ thresholdWarningBand: string
+ thresholdWarningZone: string
+ thresholdCriticalBand: string
+ thresholdCriticalZone: string
chartSeries1: string
chartSeries2: string
chartSeries3: string
diff --git a/src/theme/index.test.js b/src/theme/index.test.js
index 37da1b4a..e894c867 100644
--- a/src/theme/index.test.js
+++ b/src/theme/index.test.js
@@ -44,7 +44,9 @@ describe("theme colors", () => {
expect(luminance("appSidebarBackground")).toBeLessThan(luminance("workspaceBackground"))
expect(luminance("workspaceSidebarBackground")).toBeLessThan(luminance("appSidebarBackground"))
expect(luminance("inputBg")).toBeLessThan(luminance("workspaceSidebarBackground"))
- expect(luminance("segmentedSelectedBackground")).toBeLessThan(luminance("segmentedBackground"))
+ expect(luminance("segmentedSelectedBackground")).toBeGreaterThan(
+ luminance("segmentedBackground")
+ )
expect(luminance("popoverBackground")).toBeLessThan(luminance("workspaceBackground"))
})
@@ -89,7 +91,7 @@ describe("visual refresh token values", () => {
it("gives dark input borders a visible edge", () => {
expect(DarkTheme.colors.inputBorder).toBe("#98A69D")
- expect(DarkTheme.colors.inputBorderHover).toBe("#B0C5B5")
+ expect(DarkTheme.colors.inputBorderHover).toBe("#98A69D")
})
it("keeps dark focused input borders distinct from resting borders", () => {
@@ -103,14 +105,12 @@ describe("visual refresh token values", () => {
expect(DarkTheme.colors.tooltipText).toBe("#F0F4F1")
})
- it("keeps table row dividers visible under hover", () => {
- expect(DefaultTheme.colors.tableRowBgHover).toBe(rawColors.neutral.grey190)
- const { workspaceBackground, cardBackground, tableBorder, tableRowBgHover, text } =
- DarkTheme.colors
+ it("keeps dark table row hover distinct from its surfaces", () => {
+ expect(DefaultTheme.colors.tableRowBgHover).toBe("#F0F3F0")
+ const { workspaceBackground, cardBackground, tableRowBgHover, text } = DarkTheme.colors
expect(getLuminance(tableRowBgHover)).toBeGreaterThan(getLuminance(cardBackground))
expect(getContrast(tableRowBgHover, workspaceBackground)).toBeGreaterThanOrEqual(1.25)
- expect(getContrast(tableRowBgHover, cardBackground)).toBeGreaterThanOrEqual(1.15)
- expect(getContrast(tableRowBgHover, tableBorder)).toBeGreaterThanOrEqual(1.15)
+ expect(getContrast(tableRowBgHover, cardBackground)).toBeGreaterThanOrEqual(1.1)
expect(getContrast(text, tableRowBgHover)).toBeGreaterThanOrEqual(4.5)
})
@@ -163,8 +163,8 @@ describe("soft pill text keys", () => {
describe("approved colour proposal", () => {
it("adds controlBorder and textInfo to both themes", () => {
- expect(DefaultTheme.colors.controlBorder).toBe("#5C6A61")
- expect(DarkTheme.colors.controlBorder).toBe("#98A69D")
+ expect(DefaultTheme.colors.controlBorder).toBe(rawColors.neutral.grey125)
+ expect(DarkTheme.colors.controlBorder).toBe(rawColors.neutral.grey120)
expect(DefaultTheme.colors.textInfo).toBe(rawColors.blue.blue100)
expect(DarkTheme.colors.textInfo).toBe(rawColors.blue.blue150)
})
@@ -218,9 +218,9 @@ describe("light surface ladder and field edges (audit L1–L4)", () => {
expect(c.datePickerPausedBg).toBe(n.grey185)
})
it("gives fields one softer edge that still reaches 3:1, and darkens it on hover", () => {
- expect(c.controlBorder).toBe("#5C6A61")
+ expect(c.controlBorder).toBe(n.grey125)
expect(c.inputBorder).toBe("#5C6A61")
- expect(c.inputBorderHover).toBe("#4D5C52")
+ expect(c.inputBorderHover).toBe("#5C6A61")
expect(c.inputBorderFocus).toBe("#4D5C52")
})
it("renders stale as a neutral grey", () => {
@@ -229,7 +229,6 @@ describe("light surface ladder and field edges (audit L1–L4)", () => {
})
})
-
describe("Sage compact label contrast", () => {
it.each([
["light", DefaultTheme],
@@ -244,3 +243,34 @@ describe("Sage compact label contrast", () => {
expect(getContrast(textLite, controlPressedBackground)).toBeGreaterThanOrEqual(4.5)
})
})
+
+describe("editor hierarchy tokens", () => {
+ it("softens control and neutral-button edges", () => {
+ expect(DefaultTheme.colors.buttonNeutralBorder).toBe(rawColors.neutral.grey125)
+ expect(DarkTheme.colors.buttonNeutralBorder).toBe(rawColors.neutral.grey120)
+ })
+
+ it("shifts the selected segmented accent ink and its selected shadow", () => {
+ expect(DefaultTheme.colors.segmentedAccentText).toBe("#1d6470")
+ expect(DarkTheme.colors.segmentedAccentText).toBe("#93c9cb")
+ expect(DefaultTheme.shadows.segmentedAccentSelected).toContain("#1d6470")
+ expect(DarkTheme.shadows.segmentedAccentSelected).toContain("#93c9cb")
+ })
+
+ it("lifts the light selected segment to white and leaves dark unchanged", () => {
+ expect(DefaultTheme.colors.segmentedSelectedBackground).toBe("#FFFFFF")
+ expect(DarkTheme.colors.segmentedSelectedBackground).toBe("rgba(255,255,255,0.11)")
+ })
+
+ it("darkens the dark table row hover without changing grouped-row hover", () => {
+ expect(DarkTheme.colors.tableRowBgHover).toBe("#29312C")
+ expect(DarkTheme.colors.tableRowBg2Hover).toBe("#29352D")
+ })
+
+ it("adds chipBorder and tableRowBorder to both themes", () => {
+ expect(DefaultTheme.colors.chipBorder).toBe("#D3DBD5")
+ expect(DarkTheme.colors.chipBorder).toBe("#48584D")
+ expect(DefaultTheme.colors.tableRowBorder).toBe("#EEF0EE")
+ expect(DarkTheme.colors.tableRowBorder).toBe("#29312C")
+ })
+})