Skip to content

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

Update Anchor component styles (#83333)

Stas Gavrylovc0148822de59
diff --git a/.loki/reference/chrome_laptop_Components_Feedback_Alert_Feedback.png b/.loki/reference/chrome_laptop_Components_Feedback_Alert_Feedback.png
index cd3990a414b..67aed0b6adf 100644
Binary files a/.loki/reference/chrome_laptop_Components_Feedback_Alert_Feedback.png and b/.loki/reference/chrome_laptop_Components_Feedback_Alert_Feedback.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Text_Anchor_Overview.png b/.loki/reference/chrome_laptop_Components_Text_Anchor_Overview.png
new file mode 100644
index 00000000000..1ba815b18fa
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Text_Anchor_Overview.png differ
diff --git a/frontend/src/metabase/ui/colors/constants/themes/dark.ts b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
index ec572e4c557..09133bbab6b 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/dark.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
@@ -256,8 +256,8 @@ const getActualColors = (brand: BrandRamp) => ({
"switch_thumb-disabled": baseColors.orionAlphaInverse[40],
"text-brand": brand[40],
"text-brand-hover": brand[30],
- "text-brand-strong": brand[20],
- "text-brand-strong-hover": brand[10],
+ "text-brand-strong": brand[30],
+ "text-brand-strong-hover": brand[20],
"text-disabled": baseColors.orionAlphaInverse[40],
"text-disabled-inverse": baseColors.orionAlpha[40],
"text-filter": baseColors.filter[30],
diff --git a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.config.tsx b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.config.tsx
index 155b3ba690c..9bdf502fccb 100644
--- a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.config.tsx
+++ b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.config.tsx
@@ -4,6 +4,10 @@ import AnchorStyles from "./Anchor.module.css";
export const anchorOverrides: MantineThemeOverride["components"] = {
Anchor: Anchor.extend({
+ defaultProps: {
+ size: "md",
+ fw: 400,
+ },
classNames: {
root: AnchorStyles.root,
},
diff --git a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.mdx b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.mdx
index 0c494ec3f07..07227e5daf6 100644
--- a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.mdx
+++ b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.mdx
@@ -1,32 +1,29 @@
-import { Fragment } from "react";
-import { Canvas, Story, Meta } from "@storybook/blocks";
-import { Anchor, Grid, Text } from "metabase/ui";
+import { Canvas, Meta } from "@storybook/blocks";
import * as AnchorStories from "./Anchor.stories";
<Meta of={AnchorStories} />
# Anchor
-Our themed wrapper around [Mantine Anchor](https://v6.mantine.dev/core/anchor/).
+Our themed wrapper around [Mantine Anchor](https://mantine.dev/core/anchor/).
## When to use Anchor
-The Anchor component allows users to display links with themed styles, and replaces the usage of `<a href="<url>">text</a>`. This component uses the same props as the `Text` component, so it can handle sizing, line clamps, text decoration, and font weight. For regular text, use the `Text` component, and for code, use the `Code` component.
+Use Anchor for links in body text. It supports the same typography and layout props as Text, defaults to the `md` body size, and supports the `xs` through `xl` text scale.
+
+Anchors use the strong brand text color. By default, hovering changes the color and underlines the text. Use the `underline` prop to change when the underline appears.
+
+For regular text, use Text. For code, use Code.
## Docs
-- [Figma File](https://www.figma.com/file/8nuIBDQGSGKLfAPsebbASA/Navigation-%2F-Anchor?type=design&node-id=1-96&mode=design&t=2eUYOsqZZeMc4OGT-0)
-- [Mantine Anchor Docs](https://v6.mantine.dev/core/anchor/)
+- [Figma](https://www.figma.com/design/qYbAmJHUJ2Tkb01WFegUKp/Component-Library?node-id=2173-4408)
+- [Mantine Anchor](https://mantine.dev/core/anchor/)
## Examples
<Canvas of={AnchorStories.Default} />
-### Sizes
-
-<Canvas of={AnchorStories.Sizes} />
-
-## Related components
+### Sizes, weights, and states
-- Anchor
-- Code
+<Canvas of={AnchorStories.Overview} />
diff --git a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.module.css b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.module.css
index 39a3b7fdaab..a8ccd712d41 100644
--- a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.module.css
+++ b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.module.css
@@ -1,8 +1,7 @@
.root {
- color: var(--mb-color-core-brand);
+ color: var(--mb-color-text-brand-strong);
- &:active {
- color: var(--mb-color-text-primary);
- text-decoration: underline;
+ &:hover {
+ color: var(--mb-color-text-brand-strong-hover);
}
}
diff --git a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.stories.tsx b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.stories.tsx
index b94734bdc14..93bd3baeb1c 100644
--- a/frontend/src/metabase/ui/components/typography/Anchor/Anchor.stories.tsx
+++ b/frontend/src/metabase/ui/components/typography/Anchor/Anchor.stories.tsx
@@ -1,6 +1,17 @@
+import type { StoryFn } from "@storybook/react";
import { Fragment } from "react";
-import { Anchor, type AnchorProps, Grid, Text } from "metabase/ui";
+import { Anchor, type AnchorProps, Box, Text } from "metabase/ui";
+import { StoryBoard, StoryJsx } from "metabase/ui/stories/showcase";
+
+import S from "./Anchor.module.css";
+
+const SIZES = ["xs", "sm", "md", "lg", "xl"] as const;
+const WEIGHTS = [{ value: 400 }, { value: 700 }] as const;
+const STATES = [
+ { id: "default", label: "Default", underline: undefined },
+ { id: "hover", label: "Hover", underline: "always" },
+] as const;
const args = {
size: "md",
@@ -9,13 +20,13 @@ const args = {
};
const sampleArgs = {
- text: "Weniger",
+ text: "This is a link",
href: "https://example.test",
};
const argTypes = {
size: {
- options: ["xs", "sm", "md", "lg"],
+ options: SIZES,
control: { type: "inline-radio" },
},
align: {
@@ -27,27 +38,59 @@ const argTypes = {
},
};
+const anchorSelectorFor = (id: string) => `[data-state-row="${id}"].${S.root}`;
+
const DefaultTemplate = (args: AnchorProps) => (
<Anchor {...args} href={sampleArgs.href}>
{sampleArgs.text}
</Anchor>
);
-const SizeTemplate = (args: AnchorProps) => (
- <Grid align="center" maw="18rem">
- {argTypes.size.options.map((size) => (
- <Fragment key={size}>
- <Grid.Col span={2}>
- <Text fw="bold">{size}</Text>
- </Grid.Col>
- <Grid.Col span={10}>
- <Anchor {...args} size={size} href={sampleArgs.href}>
- {sampleArgs.text}
- </Anchor>
- </Grid.Col>
- </Fragment>
- ))}
- </Grid>
+const OverviewTemplate: StoryFn<AnchorProps> = () => (
+ <StoryBoard title="Anchor" padding="2rem">
+ <Box
+ style={{
+ display: "grid",
+ gridTemplateColumns: "6rem repeat(2, max-content)",
+ columnGap: "2rem",
+ rowGap: "1rem",
+ alignItems: "center",
+ }}
+ >
+ {SIZES.map((size) => (
+ <Fragment key={size}>
+ <div />
+ {WEIGHTS.map((weight) => (
+ <StoryJsx key={weight.value}>
+ {weight.value === 400
+ ? `<Anchor size="${size}" />`
+ : `<Anchor size="${size}" fw={700} />`}
+ </StoryJsx>
+ ))}
+
+ {STATES.map((state) => (
+ <Fragment key={state.id}>
+ <Text size="sm" c="text-secondary">
+ {state.label}
+ </Text>
+ {WEIGHTS.map((weight) => (
+ <Anchor
+ key={weight.value}
+ data-state-row={state.id}
+ href={sampleArgs.href}
+ size={size}
+ underline={state.underline}
+ fw={weight.value}
+ >
+ {sampleArgs.text}
+ </Anchor>
+ ))}
+ </Fragment>
+ ))}
+ </Fragment>
+ ))}
+ </Box>
+ </StoryBoard>
);
export default {
@@ -61,6 +104,12 @@ export const Default = {
render: DefaultTemplate,
};
-export const Sizes = {
- render: SizeTemplate,
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ pseudo: {
+ hover: anchorSelectorFor("hover"),
+ },
+ controls: { disable: true },
+ },
};
diff --git a/loki.config.js b/loki.config.js
index b70a4226f7d..a79cb990b11 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -26,6 +26,7 @@ module.exports = {
"^Components/Documents",
"^Components/Feedback/Alert",
"^Components/Feedback/Loader Overview",
+ "^Components/Text/Anchor Overview$",
"^Components/Ask Before Using/Chip Overview",
"^Components/CodeEditor Markdown",
"^Components/Data display/Badge Sizes and variants",