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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const myButton: Button = (

### Surface appearance

`<Button neutral flavour="hollow" appearance="surface" />` 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.
`<Button neutral flavour="hollow" appearance="surface" />` 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.

Expand Down
5 changes: 3 additions & 2 deletions src/components/button/buttonGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions src/components/button/segmented.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/components/button/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
: {}
Expand Down
8 changes: 4 additions & 4 deletions src/components/button/surface.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ 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" })
for (const modifier of ["&&:active", '&&[aria-pressed="true"]', '&&[aria-expanded="true"]']) {
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 })
}
})
Expand Down Expand Up @@ -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',
})
})
Expand Down
8 changes: 7 additions & 1 deletion src/components/drops/dropdownStyles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends { background?: unknown }>(
props: T
Expand Down
15 changes: 9 additions & 6 deletions src/components/drops/dropdownStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ 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 {
hover: colors.menuItemHover,
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 =>
Expand Down
13 changes: 6 additions & 7 deletions src/components/drops/menu/dropdownItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,20 @@ 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(
<ItemContainer selectionStyle="quiet" selected>
row
</ItemContainer>,
{ 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()
})
Expand Down
2 changes: 2 additions & 0 deletions src/components/input/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -80,6 +81,7 @@ export type TextInputProps = InputProps &
type InputControlStyleProps = Omit<FlexProps, "as"> &
InputTypographyProps & {
size?: InputProps["size"]
appearance?: InputProps["appearance"]
error?: boolean | string
hasValue?: boolean
textAlign?: CSSProperties["textAlign"]
Expand Down
20 changes: 17 additions & 3 deletions src/components/input/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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};
Expand Down
43 changes: 43 additions & 0 deletions src/components/input/surface.test.js
Original file line number Diff line number Diff line change
@@ -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(<TextInput appearance="surface" name="host" onChange={() => {}} />, {
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(<TextInput appearance="surface" name="port" error onChange={() => {}} />, {
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",
})
})
})
6 changes: 5 additions & 1 deletion src/components/select/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "react"
import { FC, ReactNode } from "react"
import { Props } from "react-select"
import { DropdownSelectionStyle } from "../drops/dropdownStyles"

Expand All @@ -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<Props["styles"]>

declare const Select: FC<SelectProps>

export { Select }
Expand Down
Loading
Loading