Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Restyle Chip component according to Figma spec (#74769)

Oleh K348c513d475a
diff --git a/.loki/reference/chrome_laptop_Components_Ask_Before_Using_Chip_Overview.png b/.loki/reference/chrome_laptop_Components_Ask_Before_Using_Chip_Overview.png
new file mode 100644
index 00000000000..e3bf352f27f
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Ask_Before_Using_Chip_Overview.png differ
diff --git a/frontend/src/metabase/admin/settings/components/Email/BaseSMTPConnectionForm.tsx b/frontend/src/metabase/admin/settings/components/Email/BaseSMTPConnectionForm.tsx
index b5299c04bbb..7725024f3d0 100644
--- a/frontend/src/metabase/admin/settings/components/Email/BaseSMTPConnectionForm.tsx
+++ b/frontend/src/metabase/admin/settings/components/Email/BaseSMTPConnectionForm.tsx
@@ -235,13 +235,13 @@ export const BaseSMTPConnectionForm = ({
label={t`SMTP Port`}
groupProps={{ mt: "0.5rem" }}
>
- <Chip value={"465"} variant="brand">
+ <Chip value={"465"} variant="filled">
465
</Chip>
- <Chip value={"587"} variant="brand">
+ <Chip value={"587"} variant="filled">
587
</Chip>
- <Chip value={"2525"} variant="brand">
+ <Chip value={"2525"} variant="filled">
2525
</Chip>
</FormChipGroup>
@@ -264,7 +264,7 @@ export const BaseSMTPConnectionForm = ({
groupProps={{ mt: "0.5rem" }}
>
{securityOptions.map(({ value, label }) => (
- <Chip key={value} value={value} variant="brand">
+ <Chip key={value} value={value} variant="filled">
{label}
</Chip>
))}
@@ -305,7 +305,7 @@ export const BaseSMTPConnectionForm = ({
label={t`Save changes`}
disabled={!dirty || !isValid || isSubmitting}
loading={isSubmitting}
- variant="filled"
+ variant="brand"
/>
</Flex>
</Stack>
diff --git a/frontend/src/metabase/admin/settings/components/widgets/Notifications/WebhookForm.tsx b/frontend/src/metabase/admin/settings/components/widgets/Notifications/WebhookForm.tsx
index c45be1dc4b7..f6d09cc7b0e 100644
--- a/frontend/src/metabase/admin/settings/components/widgets/Notifications/WebhookForm.tsx
+++ b/frontend/src/metabase/admin/settings/components/widgets/Notifications/WebhookForm.tsx
@@ -133,10 +133,10 @@ const renderAuthSection = (type: string) => {
label={t`Add to`}
groupProps={{ mb: "1.5rem", mt: "0.5rem" }}
>
- <Chip value="header" variant="brand">
+ <Chip value="header" variant="filled">
{t`Header`}
</Chip>
- <Chip value="query-param" variant="brand">
+ <Chip value="query-param" variant="filled">
{t`Query param`}
</Chip>
</FormChipGroup>
@@ -311,16 +311,16 @@ export const WebhookForm = ({
}
}}
>
- <Chip value="none" variant="brand">
+ <Chip value="none" variant="filled">
{t`None`}
</Chip>
- <Chip value="basic" variant="brand">
+ <Chip value="basic" variant="filled">
{t`Basic`}
</Chip>
- <Chip value="bearer" variant="brand">
+ <Chip value="bearer" variant="filled">
{t`Bearer`}
</Chip>
- <Chip value="api-key" variant="brand">
+ <Chip value="api-key" variant="filled">
{t`API Key`}
</Chip>
</FormChipGroup>
@@ -347,7 +347,7 @@ export const WebhookForm = ({
<FormSubmitButton
disabled={!dirty}
label={submitLabel}
- variant="filled"
+ variant="brand"
/>
</Group>
</Flex>
diff --git a/frontend/src/metabase/ui/components/inputs/Chip/Chip.config.ts b/frontend/src/metabase/ui/components/inputs/Chip/Chip.config.ts
index bcc8adacd37..a8a2ea3432c 100644
--- a/frontend/src/metabase/ui/components/inputs/Chip/Chip.config.ts
+++ b/frontend/src/metabase/ui/components/inputs/Chip/Chip.config.ts
@@ -2,15 +2,31 @@ import { Chip, type MantineThemeOverride } from "@mantine/core";
import S from "./Chip.module.css";
+const SIZE_VARS: Record<string, { height: string; paddingInline: string }> = {
+ sm: { height: "1.5rem", paddingInline: "0.5rem" },
+ md: { height: "2rem", paddingInline: "0.75rem" },
+};
+
export const chipOverrides: MantineThemeOverride["components"] = {
Chip: Chip.extend({
defaultProps: {
size: "md",
+ variant: "light",
},
classNames: {
+ root: S.ChipRoot,
label: S.ChipLabel,
iconWrapper: S.ChipIconWrapper,
- input: S.ChipInput,
+ checkIcon: S.ChipCheckIcon,
+ },
+ vars: (_theme, { size = "md" }) => {
+ const { height, paddingInline } = SIZE_VARS[size];
+ return {
+ root: {
+ "--chip-size": height,
+ "--chip-padding": paddingInline,
+ },
+ };
},
}),
};
diff --git a/frontend/src/metabase/ui/components/inputs/Chip/Chip.module.css b/frontend/src/metabase/ui/components/inputs/Chip/Chip.module.css
index 2f1fc70c44c..2c94b45f64f 100644
--- a/frontend/src/metabase/ui/components/inputs/Chip/Chip.module.css
+++ b/frontend/src/metabase/ui/components/inputs/Chip/Chip.module.css
@@ -1,22 +1,77 @@
.ChipLabel {
- background-color: var(--mb-color-background-brand);
- color: var(--mb-color-core-brand);
- padding: 0.5rem 1rem;
- display: block;
- height: auto;
- line-height: 100%;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.25rem;
+ height: var(--chip-size);
+ padding-inline: var(--chip-padding);
+ border-radius: 9999px;
+ font-weight: 600;
+ line-height: 1rem;
+ white-space: nowrap;
+ cursor: pointer;
+ transition:
+ background-color 0.15s ease,
+ color 0.15s ease;
+}
- &[data-checked="true"] {
- padding-inline: 1rem;
- background-color: var(--mb-color-core-brand);
- color: var(--mb-color-text-primary-inverse);
- }
+.ChipRoot .ChipLabel:not([data-disabled]) {
+ border: none;
+ background-color: var(--mb-color-background_surface-secondary);
+ color: var(--mb-color-text-primary);
+}
+
+.ChipRoot .ChipLabel:not([data-disabled]):hover {
+ background-color: var(--mb-color-background_surface-secondary-hover);
+}
+
+.ChipRoot .ChipLabel:not([data-disabled]):active {
+ background-color: var(--mb-color-background_surface-secondary-pressed);
+}
+
+.ChipRoot[data-variant="light"] .ChipLabel[data-checked]:not([data-disabled]) {
+ background-color: var(--mb-color-background_surface-brand-subtle);
+ color: var(--mb-color-text-brand-strong);
+}
+
+.ChipRoot[data-variant="light"]
+ .ChipLabel[data-checked]:not([data-disabled]):hover,
+.ChipRoot[data-variant="light"]
+ .ChipLabel[data-checked]:not([data-disabled]):active {
+ background-color: var(--mb-color-background_surface-brand-subtle-hover);
+ color: var(--mb-color-text-brand-strong-hover);
+}
+
+.ChipRoot[data-variant="filled"] .ChipLabel[data-checked]:not([data-disabled]) {
+ background-color: var(--mb-color-background_surface-brand-strong);
+ color: var(--mb-color-text-primary-inverse);
+}
+
+.ChipRoot[data-variant="filled"]
+ .ChipLabel[data-checked]:not([data-disabled]):hover,
+.ChipRoot[data-variant="filled"]
+ .ChipLabel[data-checked]:not([data-disabled]):active {
+ background-color: var(--mb-color-background_surface-brand-strong-hover);
+}
+
+.ChipRoot .ChipLabel[data-disabled] {
+ border: none;
+ background-color: var(--mb-color-background_surface-disabled);
+ color: var(--mb-color-text-disabled);
+ cursor: default;
}
.ChipIconWrapper {
- display: none;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 0.75rem;
+ height: 0.75rem;
+ margin: 0;
}
-.ChipInput {
- display: block;
+.ChipCheckIcon {
+ width: 0.55rem;
+ height: auto;
+ color: currentColor;
}
diff --git a/frontend/src/metabase/ui/components/inputs/Chip/Chip.stories.tsx b/frontend/src/metabase/ui/components/inputs/Chip/Chip.stories.tsx
index e517ccefc32..ac1ea4db8bf 100644
--- a/frontend/src/metabase/ui/components/inputs/Chip/Chip.stories.tsx
+++ b/frontend/src/metabase/ui/components/inputs/Chip/Chip.stories.tsx
@@ -1,28 +1,149 @@
import type { StoryFn } from "@storybook/react";
+import { Fragment } from "react";
-import { Chip, type ChipProps } from "metabase/ui";
+import { Box, Chip, type ChipProps, Group, Text } from "metabase/ui";
+import { StoryJsx, StoryShowcase } from "metabase/ui/stories/showcase";
+
+import S from "./Chip.module.css";
+
+const LABEL = "Label";
+
+const args = {
+ size: "md",
+ children: LABEL,
+ disabled: false,
+};
const argTypes = {
size: {
- options: ["xs", "sm", "md", "lg", "xl"],
+ options: ["sm", "md"],
control: { type: "inline-radio" },
},
+ children: {
+ control: { type: "text" },
+ },
+ disabled: {
+ control: { type: "boolean" },
+ },
+};
+
+const VARIANTS = ["light", "filled"] as const;
+
+const SIZES = ["sm", "md"] as const;
+
+const COLUMNS: {
+ variant: (typeof VARIANTS)[number];
+ size: (typeof SIZES)[number];
+}[] = VARIANTS.flatMap((variant) => SIZES.map((size) => ({ variant, size })));
+
+// The interactive states from the Figma spec. `Hover` and `Pressed` rows have
+// their state forced by `storybook-addon-pseudo-states` (see
+// `parameters.pseudo` on the `Overview` story below) so the matrix renders them
+// without real pointer interaction.
+type ChipState = {
+ id: string;
+ label: string;
+ checked?: boolean;
+ disabled?: boolean;
+};
+
+const STATES: ChipState[] = [
+ { id: "default", label: "Default" },
+ { id: "hover", label: "Hover" },
+ { id: "pressed", label: "Pressed" },
+ { id: "selected", label: "Selected", checked: true },
+ { id: "hover-selected", label: "Hover selected", checked: true },
+ { id: "disabled", label: "Disabled", disabled: true },
+ {
+ id: "disabled-selected",
+ label: "Disabled selected",
+ checked: true,
+ disabled: true,
+ },
+];
+
+// Per-row selectors for the pseudo-states addon. The addon rewrites every
+// `:hover` rule to also match `<rule>.pseudo-hover`, so the selector must
+// target the exact element the rule attaches to — the `.ChipLabel` slot, not
+// the root. We tag each chip with `data-state-row` so we can target a single
+// row's labels (one per column).
+const chipLabelSelectorFor = (id: string) =>
+ `[data-state-row="${id}"] .${S.ChipLabel}`;
+
+const PSEUDO_STATE_PARAMETERS = {
+ pseudo: {
+ hover: ["hover", "hover-selected"].map(chipLabelSelectorFor),
+ active: ["pressed"].map(chipLabelSelectorFor),
+ },
};
+const OverviewTemplate: StoryFn<ChipProps> = ({ children }) => (
+ <StoryShowcase title="Chip">
+ <Box
+ style={{
+ display: "grid",
+ gridTemplateColumns: `9rem repeat(${COLUMNS.length}, max-content)`,
+ columnGap: "2rem",
+ rowGap: "1rem",
+ alignItems: "center",
+ justifyItems: "start",
+ }}
+ >
+ <div />
+ {COLUMNS.map(({ variant, size }) => (
+ <StoryJsx
+ key={`${variant}-${size}`}
+ >{`<Chip variant="${variant}" size="${size}" />`}</StoryJsx>
+ ))}
+
+ {STATES.map((state) => (
+ <Fragment key={state.id}>
+ <Text size="sm" c="text-secondary">
+ {state.label}
+ </Text>
+ {COLUMNS.map(({ variant, size }) => (
+ <Chip
+ key={`${variant}-${size}`}
+ // Mantine forwards top-level `data-*` to the hidden `<input>`,
+ // so we use `wrapperProps` to land it on the chip root where
+ // the pseudo-states selector can reach `.ChipLabel`.
+ wrapperProps={{ "data-state-row": state.id }}
+ variant={variant}
+ size={size}
+ checked={state.checked ?? false}
+ disabled={state.disabled ?? false}
+ onChange={() => {}}
+ >
+ {children}
+ </Chip>
+ ))}
+ </Fragment>
+ ))}
+ </Box>
+ </StoryShowcase>
+);
+
+const DefaultTemplate: StoryFn<ChipProps> = (args) => (
+ <Group>
+ <Chip {...args} defaultChecked />
+ </Group>
+);
+
export default {
title: "Components/Ask Before Using/Chip",
component: Chip,
- args: {
- size: "md",
- children: "Text",
- },
+ args,
argTypes,
};
-const Template: StoryFn<ChipProps> = (args) => {
- return <Chip {...args} />;
+export const Default = {
+ render: DefaultTemplate,
};
-export const Default = {
- render: Template,
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ ...PSEUDO_STATE_PARAMETERS,
+ controls: { include: ["children", "theme"] },
+ },
};
diff --git a/loki.config.js b/loki.config.js
index 78c8fb5ecd7..000ccc57d51 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -15,6 +15,7 @@ module.exports = {
"^Components/overlays/Tooltip",
"^Components/Documents",
"^Components/Feedback/Alert",
+ "^Components/Ask Before Using/Chip Overview",
"^Components/Table",
"^App/Palette",
"^EmbeddingSDK/SdkQuestion/ChartTypeDropdownInner",