Skip to content

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

Radio component redesign (#80372)

Egor Grushin05300912fb71
diff --git a/.loki/reference/chrome_laptop_Components_Inputs_Checkbox_Checkbox_Card.png b/.loki/reference/chrome_laptop_Components_Inputs_Checkbox_Checkbox_Card.png
index 9c8546e3e8c..e069e99168a 100644
Binary files a/.loki/reference/chrome_laptop_Components_Inputs_Checkbox_Checkbox_Card.png and b/.loki/reference/chrome_laptop_Components_Inputs_Checkbox_Checkbox_Card.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Inputs_Radio_Overview.png b/.loki/reference/chrome_laptop_Components_Inputs_Radio_Overview.png
new file mode 100644
index 00000000000..ae68ae4a32b
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Inputs_Radio_Overview.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Inputs_Radio_Radio_Card.png b/.loki/reference/chrome_laptop_Components_Inputs_Radio_Radio_Card.png
new file mode 100644
index 00000000000..a81b10e34b2
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Inputs_Radio_Radio_Card.png differ
diff --git a/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.module.css b/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.module.css
deleted file mode 100644
index 7031ca982b7..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.module.css
+++ /dev/null
@@ -1,12 +0,0 @@
-.radioCard {
- cursor: pointer;
- border: 1px solid var(--mb-color-border-neutral);
-}
-
-.radioCard[data-checked] {
- border-color: var(--mb-color-core-brand);
-}
-
-.radioCard[data-checked] .radioCardTitle {
- color: var(--mb-color-core-brand);
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.tsx b/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.tsx
index 641f72a7f0a..2636bf90fed 100644
--- a/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/tenants/EditUserStrategyModal/EditUserStrategyModal.tsx
@@ -8,9 +8,7 @@ import { useConfirmation } from "metabase/common/hooks/use-confirmation";
import { useDispatch } from "metabase/redux";
import { useNavigate } from "metabase/router";
import { useAdminSetting } from "metabase/settings";
-import { Button, Flex, Group, Modal, Radio, Stack, Text } from "metabase/ui";
-
-import S from "./EditUserStrategyModal.module.css";
+import { Button, Flex, Modal, Radio, Stack } from "metabase/ui";
interface EditUserStrategyModalProps {
onClose: () => void;
@@ -104,12 +102,12 @@ export const EditUserStrategyModal = ({
const strategyOptions = [
{
value: "multi-tenant",
- title: t`Multi tenant`,
+ label: t`Multi tenant`,
description: t`Each tenant operates in an isolated environment with dedicated resources and permissions. Best for SaaS platforms, scalable embedding, or strict data isolation needs.`,
},
{
value: "single-tenant",
- title: t`Single tenant`,
+ label: t`Single tenant`,
// eslint-disable-next-line metabase/no-literal-metabase-strings -- in admin settings
description: t`All users exist in the same world and are managed via Metabase groups. Ideal for internal company analytics, proof of concept, or simple embedding setups.`,
},
@@ -135,28 +133,10 @@ export const EditUserStrategyModal = ({
<Radio.Card
key={option.value}
value={option.value}
- radius="md"
- p="md"
- className={S.radioCard}
- >
- <Group wrap="nowrap">
- <div>
- <Text
- fw={700}
- fz="lg"
- lh="xl"
- mb="xs"
- className={S.radioCardTitle}
- >
- {option.title}
- </Text>
-
- <Text c="text-secondary" fz="sm" lh="lg">
- {option.description}
- </Text>
- </div>
- </Group>
- </Radio.Card>
+ label={option.label}
+ description={option.description}
+ withIndicator={false}
+ />
))}
</Stack>
</Radio.Group>
diff --git a/frontend/src/metabase/common/metrics/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx b/frontend/src/metabase/common/metrics/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
index ee6d7820afc..edfed8cebf4 100644
--- a/frontend/src/metabase/common/metrics/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
+++ b/frontend/src/metabase/common/metrics/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
@@ -72,7 +72,6 @@ export function DefaultFilterPicker({
value={option.operator}
label={option.displayName}
pb={6}
- size="xs"
/>
))}
</Stack>
diff --git a/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.module.css b/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.module.css
deleted file mode 100644
index 006c5421dc4..00000000000
--- a/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.module.css
+++ /dev/null
@@ -1,18 +0,0 @@
-.radioCard {
- cursor: pointer;
- border: 1px solid var(--mb-color-border-neutral);
-}
-
-.radioCard[data-checked] {
- border-color: var(--mb-color-core-brand);
- background: var(--mb-color-background_surface-hover);
-}
-
-.radioCard[data-checked] .radioCardTitle {
- color: var(--mb-color-core-brand);
-}
-
-.cardIcon {
- flex-shrink: 0;
- color: var(--mb-color-core-brand);
-}
diff --git a/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.tsx b/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.tsx
index a093c5f1494..49eb1620e59 100644
--- a/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.tsx
+++ b/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/DataSegregationStrategyPicker.tsx
@@ -2,11 +2,9 @@
import { t } from "ttag";
-import { Button, Flex, Group, Icon, Radio, Stack, Text } from "metabase/ui";
+import { Button, FixedSizeIcon, Flex, Radio, Stack } from "metabase/ui";
import type { DataSegregationStrategy, IconName } from "metabase-types/api";
-import S from "./DataSegregationStrategyPicker.module.css";
-
interface DataSegregationStrategyPickerProps {
value: DataSegregationStrategy | null;
onChange: (value: DataSegregationStrategy) => void;
@@ -16,7 +14,7 @@ interface DataSegregationStrategyPickerProps {
interface StrategyOption {
id: DataSegregationStrategy;
icon: IconName;
- title: string;
+ label: string;
description: string;
confirmText: string;
}
@@ -25,21 +23,21 @@ const getOptions = (): StrategyOption[] => [
{
id: "row-column-level-security",
icon: "layout_grid",
- title: t`Row and column level security`,
+ label: t`Row and column level security`,
description: t`All data is stored in the same database and Metabase will apply a filter to queries for a table column to match a specific value (ex: customerId = 2).`,
confirmText: t`Use row and column level security`,
},
{
id: "connection-impersonation",
icon: "corner_up_right",
- title: t`Connection impersonation`,
+ label: t`Connection impersonation`,
description: t`All data is stored in the same database, but Metabase will use a different database role to connect for each tenant. Roles are configured at the database level to only query relevant data.`,
confirmText: t`Use connection impersonation`,
},
{
id: "database-routing",
icon: "database_routing",
- title: t`Database routing`,
+ label: t`Database routing`,
description: t`Each tenant has their own database with identical schema. Metabase will use a connection string from a tenant attribute to run queries against a different destination database.`,
confirmText: t`Use database routing`,
},
@@ -66,30 +64,19 @@ export const DataSegregationStrategyPicker = ({
<Radio.Card
key={strategy.id}
value={strategy.id}
- radius="md"
- p="md"
- className={S.radioCard}
- data-testid={`strategy-card-${strategy.id}`}
- >
- <Group wrap="nowrap" align="flex-start">
- <Icon
+ label={strategy.label}
+ description={strategy.description}
+ leftSection={
+ <FixedSizeIcon
name={strategy.icon}
- className={S.cardIcon}
+ color="core-brand"
w={24}
h={24}
/>
-
- <div>
- <Text fw="bold" size="md" className={S.radioCardTitle}>
- {strategy.title}
- </Text>
-
- <Text size="sm" c="text-secondary" lh="lg">
- {strategy.description}
- </Text>
- </div>
- </Group>
- </Radio.Card>
+ }
+ data-testid={`strategy-card-${strategy.id}`}
+ withIndicator={false}
+ />
))}
</Stack>
</Radio.Group>
diff --git a/frontend/src/metabase/querying/common/components/BooleanPicker/BooleanPicker.tsx b/frontend/src/metabase/querying/common/components/BooleanPicker/BooleanPicker.tsx
index 4ee2824fdf3..b5dc2625827 100644
--- a/frontend/src/metabase/querying/common/components/BooleanPicker/BooleanPicker.tsx
+++ b/frontend/src/metabase/querying/common/components/BooleanPicker/BooleanPicker.tsx
@@ -44,7 +44,6 @@ export function BooleanPicker({
key={option.value}
value={option.value}
label={option.label}
- size="xs"
/>
))}
</Stack>
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
index 61b3642d8fb..fca9e9fd8c6 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
@@ -83,7 +83,6 @@ export function DefaultFilterPicker({
value={option.operator}
label={option.displayName}
pb={6}
- size="xs"
/>
))}
</Stack>
diff --git a/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.module.css b/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.module.css
index af37ebe9a58..d38ee66a2ce 100644
--- a/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.module.css
+++ b/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.module.css
@@ -93,6 +93,8 @@
}
.card {
+ --card-ring: 0 0 0 0 transparent;
+
display: flex;
align-items: flex-start;
gap: rem(12px);
@@ -100,7 +102,7 @@
border: 0.5px solid var(--mb-color-border-neutral-strong);
border-radius: rem(12px);
background-color: var(--mb-color-background_surface-primary);
- box-shadow: var(--mantine-shadow-xs);
+ box-shadow: var(--mantine-shadow-xs), var(--card-ring);
text-align: left;
overflow-wrap: anywhere;
@@ -109,7 +111,9 @@
}
&[data-checked]:not(:disabled) {
- border: 1px solid var(--mb-color-border-highlight);
+ --card-ring: inset 0 0 0 0.5px var(--mb-color-border-highlight);
+
+ border-color: var(--mb-color-border-highlight);
}
&:disabled {
diff --git a/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.stories.tsx b/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.stories.tsx
index 0de2484372d..c39f3ba22ce 100644
--- a/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.stories.tsx
+++ b/frontend/src/metabase/ui/components/inputs/Checkbox/Checkbox.stories.tsx
@@ -1,5 +1,5 @@
import type { StoryFn } from "@storybook/react";
-import { Fragment } from "react";
+import { Fragment, useState } from "react";
import { Box, Checkbox, type CheckboxProps, Stack, Text } from "metabase/ui";
import {
@@ -225,7 +225,7 @@ const CardTemplate: StoryFn<CheckboxProps> = () => (
w="16rem"
label="React"
description="A library for building user interfaces"
- defaultChecked={state.checked ?? false}
+ checked={state.checked ?? false}
disabled={state.disabled ?? false}
data-state-row={state.id}
/>
@@ -247,3 +247,74 @@ export const Card = {
controls: { disable: true },
},
};
+
+const INTERACTIVE_CARDS = [
+ {
+ value: "react",
+ label: "React",
+ description: "A library for building user interfaces",
+ attrs: "",
+ props: {},
+ },
+ {
+ value: "svelte",
+ label: "Svelte",
+ description: "Cybernetically enhanced web apps",
+ attrs: "",
+ props: {},
+ },
+ {
+ value: "ng",
+ label: "Angular",
+ description: "The web development framework for modern apps",
+ attrs: " disabled",
+ props: { disabled: true },
+ },
+ {
+ value: "vue",
+ label: "Vue",
+ description: "The progressive JavaScript framework",
+ attrs: " withIndicator={false}",
+ props: { withIndicator: false },
+ },
+];
+
+const INTERACTIVE_JSX = [
+ `<Checkbox.Group>`,
+ ...INTERACTIVE_CARDS.map(({ attrs }) => ` <Checkbox.Card${attrs} />`),
+ `</Checkbox.Group>`,
+].join("\n");
+
+const InteractiveCardTemplate: StoryFn<CheckboxProps> = () => {
+ const [value, setValue] = useState(["react"]);
+
+ return (
+ <StoryBoard title="Checkbox.Card" background="background_page-primary">
+ <Stack gap="1.5rem">
+ <StoryJsx>{INTERACTIVE_JSX}</StoryJsx>
+ <Checkbox.Group value={value} onChange={setValue}>
+ <Stack gap="0.375rem" w="16rem">
+ {INTERACTIVE_CARDS.map(({ value, label, description, props }) => (
+ <Checkbox.Card
+ key={value}
+ value={value}
+ label={label}
+ description={description}
+ {...props}
+ />
+ ))}
+ </Stack>
+ </Checkbox.Group>
+ </Stack>
+ </StoryBoard>
+ );
+};
+
+export const InteractiveCard = {
+ render: InteractiveCardTemplate,
+ name: "Checkbox.Card (interactive)",
+ parameters: {
+ controls: { disable: true },
+ loki: { skip: true },
+ },
+};
diff --git a/frontend/src/metabase/ui/components/inputs/Checkbox/CheckboxCard.tsx b/frontend/src/metabase/ui/components/inputs/Checkbox/CheckboxCard.tsx
index 2d82cf0bf4f..289bcf41ec7 100644
--- a/frontend/src/metabase/ui/components/inputs/Checkbox/CheckboxCard.tsx
+++ b/frontend/src/metabase/ui/components/inputs/Checkbox/CheckboxCard.tsx
@@ -11,13 +11,17 @@ import { type ReactNode, forwardRef } from "react";
export type CheckboxCardProps = Omit<MantineCheckboxCardProps, "children"> & {
label?: ReactNode;
description?: ReactNode;
+ withIndicator?: boolean;
};
export const CheckboxCard = forwardRef<HTMLButtonElement, CheckboxCardProps>(
- function CheckboxCard({ label, description, disabled, ...props }, ref) {
+ function CheckboxCard(
+ { label, description, disabled, withIndicator = true, ...props },
+ ref,
+ ) {
return (
<MantineCheckboxCard disabled={disabled} {...props} ref={ref}>
- <MantineCheckboxIndicator disabled={disabled} />
+ {withIndicator && <MantineCheckboxIndicator disabled={disabled} />}
<Stack component="span" gap={rem(2)} miw={0}>
{label && (
<Text
diff --git a/frontend/src/metabase/ui/components/inputs/Radio/Radio.config.ts b/frontend/src/metabase/ui/components/inputs/Radio/Radio.config.ts
index 8def1787301..a52cf21bc35 100644
--- a/frontend/src/metabase/ui/components/inputs/Radio/Radio.config.ts
+++ b/frontend/src/metabase/ui/components/inputs/Radio/Radio.config.ts
@@ -1,34 +1,55 @@
-import { Radio, getSize, rem } from "@mantine/core";
+import { Radio, RadioCard, RadioIndicator, rem } from "@mantine/core";
import RadioStyles from "./Radio.module.css";
-const SIZES: Record<string, string> = {
- md: rem(20),
-};
+const RADIO_SIZE = rem(16);
+const ICON_SIZE = rem(6);
export const radioOverrides = {
Radio: Radio.extend({
defaultProps: {
- size: "md",
+ radius: "md",
},
classNames: {
root: RadioStyles.root,
+ body: RadioStyles.body,
+ inner: RadioStyles.inner,
radio: RadioStyles.radio,
+ icon: RadioStyles.icon,
label: RadioStyles.label,
labelWrapper: RadioStyles.labelWrapper,
description: RadioStyles.description,
- icon: RadioStyles.icon,
+ error: RadioStyles.error,
},
- vars: (_theme, { size = "md" }) => ({
+ vars: () => ({
root: {
- "--radio-size": getSize(SIZES[size]),
+ "--radio-size": RADIO_SIZE,
+ "--radio-icon-size": ICON_SIZE,
+ "--radio-icon-color": "var(--mb-color-text-primary-inverse)",
},
}),
}),
- RadioIndicator: Radio.Indicator.extend({
+ RadioCard: RadioCard.extend({
+ defaultProps: {
+ withBorder: false,
+ },
classNames: {
- // indicator is visually same as Radio so it needs the same styles
- indicator: RadioStyles.radio,
+ card: RadioStyles.card,
},
}),
+ RadioIndicator: RadioIndicator.extend({
+ defaultProps: {
+ radius: "md",
+ },
+ classNames: {
+ indicator: RadioStyles.cardIndicator,
+ icon: RadioStyles.icon,
+ },
+ vars: () => ({
+ indicator: {
+ "--radio-size": RADIO_SIZE,
+ "--radio-icon-size": ICON_SIZE,
+ },
+ }),
+ }),
};
diff --git a/frontend/src/metabase/ui/components/inputs/Radio/Radio.mdx b/frontend/src/metabase/ui/components/inputs/Radio/Radio.mdx
index 14b59bb2080..d451f596663 100644
--- a/frontend/src/metabase/ui/components/inputs/Radio/Radio.mdx
+++ b/frontend/src/metabase/ui/components/inputs/Radio/Radio.mdx
@@ -6,7 +6,7 @@ import * as RadioStories from "./Radio.stories";
# Radio
-Our themed wrapper around [Mantine Radio](https://v6.mantine.dev/core/radio/).
+Our themed wrapper around [Mantine Radio](https://mantine.dev/core/radio/).
## When to use Radio
@@ -14,40 +14,37 @@ Radio buttons allow users to select a single option from a list of mutually excl
## Docs
-- [Figma File](https://www.figma.com/file/7LCGPhkbJdrhdIaeiU1O9c/Input-%2F-Radio?type=design&node-id=1-96&mode=design&t=yaNljw178EFJeU7k-0)
-- [Mantine Radio Docs](https://v6.mantine.dev/core/radio/)
+- [Figma File](https://www.figma.com/design/qYbAmJHUJ2Tkb01WFegUKp/Component-Library?node-id=250-13082)
+- [Mantine Radio Docs](https://mantine.dev/core/radio/)
## Usage guidelines
-- **Use this component if there are more than 5 options**. If there are fewer options, feel free to check out Radio or Select.
+- **Use this component when the options are mutually exclusive and users pick exactly one.** For independent options that toggle on their own, use <a href="/?path=/docs/components-inputs-checkbox--docs" target="_top">Checkbox</a> instead.
+- **Keep the list short.** Past a handful of options a <a href="/?path=/docs/components-inputs-select--docs" target="_top">Select</a> is easier to scan than a long column of radios.
- For option ordering, try to use your best judgement on a sensible order. For example, Yes should come before No. Alphabetical ordering is usually a good fallback if there's no inherent order in your set of choices.
-- In almost all circumstances you'll want to use `<Radio.Group>` to provide a set of options and help with defaultValues and state management between them.
+- In almost all circumstances you'll want to use `<Radio.Group>` (<a href="/?path=/story/components-inputs-radio--groups" target="_top">an example</a>) to provide a set of options and help with defaultValues and state management between them.
## Examples
<Canvas of={RadioStories.Default} />
-### Radio.Group
+### States
-<Canvas of={RadioStories.RadioGroup} />
+<Canvas of={RadioStories.Overview} />
-### Label
+### Radio.Group and Radio.Card Group
-<Canvas of={RadioStories.Label} />
+<Canvas of={RadioStories.Groups} />
-#### Left label position
+### Radio.Card
-<Canvas of={RadioStories.LabelLeftPosition} />
-
-### Description
-
-<Canvas of={RadioStories.Description} />
-
-#### Left label position
-
-<Canvas of={RadioStories.DescriptionLeftPosition} />
+<Canvas of={RadioStories.Card} />
## Related components
-- Checkbox
-- Select
+- <a href="/?path=/docs/components-inputs-checkbox--docs" target="_top">
+ Checkbox
+ </a>
+- <a href="/?path=/docs/components-inputs-select--docs" target="_top">
+ Select
+ </a>
diff --git a/frontend/src/metabase/ui/components/inputs/Radio/Radio.module.css b/frontend/src/metabase/ui/components/inputs/Radio/Radio.module.css
index 01903744ded..0d390b2db40 100644
--- a/frontend/src/metabase/ui/components/inputs/Radio/Radio.module.css
+++ b/frontend/src/metabase/ui/components/inputs/Radio/Radio.module.css
@@ -1,60 +1,123 @@
.root {
- &:has(.radio:disabled) {
- .label {
- color: var(--mb-color-text-disabled);
- }
+ .description {
+ color: var(--mb-color-text-secondary);
+ font-size: var(--mantine-font-size-sm);
+ line-height: var(--mantine-line-height-sm);
+ margin-top: 0 !important;
+ margin-bottom: 0 !important;
+ }
- .description {
- color: var(--mb-color-text-disabled);
- }
+ .error {
+ color: var(--mb-color-feedback-negative-strong);
+ margin-top: 0 !important;
+ margin-bottom: 0 !important;
+ }
+ &:has(.radio:disabled) {
+ .label,
+ .description,
.icon {
- color: var(--mb-color-text-primary-inverse);
+ color: var(--mb-color-text-disabled);
}
}
+}
+
+.body {
+ --label-offset-start: 0;
+ --label-offset-end: 0;
+
+ align-items: start;
+ column-gap: var(--mantine-spacing-sm);
- /* Need the additional specificity to override global focus outline rule */
- .radio:focus {
- outline: none;
+ &:has(.label) .inner {
+ display: flex;
+ align-items: center;
+ height: rem(20px);
}
}
.radio {
- border-color: var(--mb-color-text-disabled);
+ border: 1px solid var(--mb-color-border-neutral-strong);
+ background-color: var(--mb-color-background_surface-secondary);
&:not(:disabled) {
cursor: pointer;
}
&:checked {
- border-color: var(--mb-color-core-brand);
- background-color: var(--mb-color-core-brand);
+ border-color: var(--mb-color-border-neutral-strong);
+ background-color: var(--mb-color-background_surface-brand-strong);
}
&:disabled {
- opacity: 0.3;
- }
-
- &:disabled:not(:checked) {
- border-color: var(--mb-color-text-disabled);
- background-color: var(--mb-color-background_page-tertiary);
+ border-color: transparent;
+ background-color: var(--mb-color-background_surface-disabled);
}
}
.label {
color: var(--mb-color-text-primary);
font-size: var(--mantine-font-size-md);
- line-height: var(--mantine-line-height-md);
+ line-height: rem(20px);
}
.labelWrapper {
- justify-content: center;
- width: 100%;
+ gap: rem(2px);
+ align-self: center;
}
-.description {
- color: var(--mb-color-text-primary);
- font-size: var(--mantine-font-size-sm);
- line-height: var(--mantine-line-height-md);
- margin-top: var(--mantine-spacing-xs);
+.card {
+ --card-ring: 0 0 0 0 transparent;
+
+ display: flex;
+ align-items: flex-start;
+ gap: rem(12px);
+ padding: var(--mantine-spacing-md);
+ border: 0.5px solid var(--mb-color-border-neutral-strong);
+ border-radius: rem(12px);
+ background-color: var(--mb-color-background_surface-primary);
+ box-shadow: var(--mantine-shadow-xs), var(--card-ring);
+ text-align: left;
+ overflow-wrap: anywhere;
+
+ &:hover {
+ background-color: var(--mb-color-background_surface-primary-hover);
+ }
+
+ &[data-checked]:not(:disabled) {
+ --card-ring: inset 0 0 0 0.5px var(--mb-color-border-highlight);
+
+ border-color: var(--mb-color-border-highlight);
+ }
+
+ &:disabled {
+ cursor: not-allowed;
+ border-color: transparent;
+ background-color: var(--mb-color-background_surface-disabled);
+ }
+}
+
+.cardIndicator {
+ --radio-icon-color: var(--mb-color-text-primary-inverse);
+
+ flex-shrink: 0;
+ margin-top: rem(1px);
+ border: 1px solid var(--mb-color-border-neutral-strong);
+ background-color: var(--mb-color-background_surface-secondary);
+
+ &[data-checked] {
+ border-color: var(--mb-color-border-neutral-strong);
+ background-color: var(--mb-color-background_surface-brand-strong);
+ }
+
+ &[data-disabled] {
+ --radio-icon-color: var(--mb-color-text-disabled);
+
+ border-color: transparent;
+ background-color: var(--mb-color-background_surface-disabled);
+
+ [data-mantine-color-scheme] &[data-checked] > .icon {
+ color: var(--mb-color-text-disabled);
+ }
+ }
}
diff --git a/frontend/src/metabase/ui/components/inputs/Radio/Radio.stories.tsx b/frontend/src/metabase/ui/components/inputs/Radio/Radio.stories.tsx
index a6e4510c04e..7aff032d638 100644
--- a/frontend/src/metabase/ui/components/inputs/Radio/Radio.stories.tsx
+++ b/frontend/src/metabase/ui/components/inputs/Radio/Radio.stories.tsx
@@ -1,10 +1,18 @@
-import { Radio, type RadioProps, Stack } from "metabase/ui";
+import type { StoryFn } from "@storybook/react";
+import { Fragment, useState } from "react";
+
+import { Box, Radio, type RadioProps, Stack, Text } from "metabase/ui";
+import {
+ StoryBoard,
+ StoryJsx,
+ StorySection,
+} from "metabase/ui/stories/showcase";
const args = {
label: "Label",
- description: "",
+ description: undefined,
+ error: undefined,
disabled: false,
- labelPosition: "right",
};
const argTypes = {
@@ -14,39 +22,14 @@ const argTypes = {
description: {
control: { type: "text" },
},
+ error: {
+ control: { type: "text" },
+ },
disabled: {
control: { type: "boolean" },
},
- labelPosition: {
- options: ["left", "right"],
- control: { type: "inline-radio" },
- },
};
-const RadioGroupTemplate = () => (
- <Radio.Group
- defaultValue={"react"}
- label="An array of good frameworks"
- description="But which one to use?"
- >
- <Stack mt="md">
- <Radio value="react" label="React" />
- <Radio value="svelte" label="Svelte" />
- <Radio value="ng" label="Angular" />
- <Radio value="vue" label="Vue" />
- </Stack>
- </Radio.Group>
-);
-
-const StateTemplate = (args: RadioProps) => (
- <Stack>
- <Radio {...args} label="Default radio" />
- <Radio {...args} label="Checked radio" defaultChecked />
- <Radio {...args} label="Disabled radio" disabled />
- <Radio {...args} label="Disabled checked radio" disabled defaultChecked />
- </Stack>
-);
-
export default {
title: "Components/Inputs/Radio",
component: Radio,
@@ -56,35 +39,262 @@ export default {
export const Default = {};
-export const RadioGroup = {
- render: RadioGroupTemplate,
- name: "Radio group",
+const OVERVIEW_STATES = [
+ { id: "default", attrs: "", props: {} },
+ { id: "checked", attrs: " defaultChecked", props: { defaultChecked: true } },
+ { id: "disabled", attrs: " disabled", props: { disabled: true } },
+ {
+ id: "disabled-checked",
+ attrs: " disabled defaultChecked",
+ props: { disabled: true, defaultChecked: true },
+ },
+];
+
+const gridStyle = {
+ display: "grid",
+ gridTemplateColumns: "18rem 20rem",
+ columnGap: "1.5rem",
+ rowGap: "1rem",
+ alignItems: "center",
+} as const;
+
+const OverviewTemplate: StoryFn<RadioProps> = () => (
+ <StoryBoard title="Radio" padding="2rem">
+ <StorySection title="States">
+ <Box style={gridStyle}>
+ {OVERVIEW_STATES.map(({ id, attrs, props }) => (
+ <Fragment key={id}>
+ <StoryJsx>{`<Radio label="…" description="…"${attrs} />`}</StoryJsx>
+ <Radio
+ label="Label"
+ description="Description"
+ wrapperProps={{ "data-testid": `radio-overview-${id}` }}
+ {...props}
+ />
+ </Fragment>
+ ))}
+ </Box>
+ </StorySection>
+
+ <StorySection title="Label only">
+ <Box style={gridStyle}>
+ {OVERVIEW_STATES.map(({ id, attrs, props }) => (
+ <Fragment key={id}>
+ <StoryJsx>{`<Radio label="…"${attrs} />`}</StoryJsx>
+ <Radio label="Label" {...props} />
+ </Fragment>
+ ))}
+ </Box>
+ </StorySection>
+
+ <StorySection title="Error">
+ <Box style={gridStyle}>
+ <StoryJsx>{`<Radio error="…" />`}</StoryJsx>
+ <Radio
+ label="Label"
+ description="Description"
+ error="Something went wrong"
+ />
+ </Box>
+ </StorySection>
+ </StoryBoard>
+);
+
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ controls: { disable: true },
+ },
+};
+
+const GroupsTemplate: StoryFn<RadioProps> = () => (
+ <StoryBoard title="Radio.Group">
+ <Stack gap="1.5rem">
+ <StoryJsx>{"<Radio.Group />"}</StoryJsx>
+ <Radio.Group
+ defaultValue="react"
+ label="An array of good frameworks"
+ description="But which one to use?"
+ >
+ <Stack gap="0.75rem" mt="1rem" w="16rem">
+ <Radio value="react" label="React" />
+ <Radio value="svelte" label="Svelte" />
+ <Radio value="ng" label="Angular" />
+ <Radio value="vue" label="Vue" />
+ </Stack>
+ </Radio.Group>
+ </Stack>
+ <Stack gap="1.5rem">
+ <StoryJsx>{"<Radio.Group><Radio.Card /></Radio.Group>"}</StoryJsx>
+ <Radio.Group
+ defaultValue="react"
+ label="An array of good frameworks"
+ description="But which one to use?"
+ >
+ <Stack gap="0.375rem" mt="1rem" w="16rem">
+ <Radio.Card
+ value="react"
+ label="React"
+ description="A library for building user interfaces"
+ />
+ <Radio.Card
+ value="svelte"
+ label="Svelte"
+ description="Cybernetically enhanced web apps"
+ />
+ <Radio.Card
+ value="ng"
+ label="Angular"
+ description="The web development framework for modern apps"
+ />
+ <Radio.Card
+ value="vue"
+ label="Vue"
+ description="The progressive JavaScript framework"
+ />
+ </Stack>
+ </Radio.Group>
+ </Stack>
+ </StoryBoard>
+);
+
+export const Groups = {
+ render: GroupsTemplate,
+ parameters: {
+ controls: { disable: true },
+ },
};
-export const Label = {
- render: StateTemplate,
+type CardState = {
+ id: string;
+ label: string;
+ checked?: boolean;
+ hovered?: boolean;
+ disabled?: boolean;
};
-export const LabelLeftPosition = {
- render: StateTemplate,
- name: "Label, left position",
- args: {
- labelPosition: "left",
+const CARD_STATES: CardState[] = [
+ { id: "default", label: "Default" },
+ { id: "hover", label: "Hover", hovered: true },
+ { id: "selected", label: "Selected", checked: true },
+ {
+ id: "selected-hover",
+ label: "Selected - Hover",
+ checked: true,
+ hovered: true,
+ },
+ { id: "disabled", label: "Disabled", disabled: true },
+ {
+ id: "disabled-checked",
+ label: "Disabled - Checked",
+ checked: true,
+ disabled: true,
+ },
+];
+
+const CardTemplate: StoryFn<RadioProps> = () => (
+ <StoryBoard title="Radio.Card" background="background_page-primary">
+ <Stack gap="1.5rem">
+ <StoryJsx>{"<Radio.Card />"}</StoryJsx>
+ {CARD_STATES.map((state) => (
+ <Stack key={state.id} gap="0.75rem">
+ <Text size="sm" c="text-secondary">
+ {state.label}
+ </Text>
+ <Radio.Card
+ w="16rem"
+ label="React"
+ description="A library for building user interfaces"
+ checked={state.checked ?? false}
+ disabled={state.disabled ?? false}
+ data-state-row={state.id}
+ />
+ </Stack>
+ ))}
+ </Stack>
+ </StoryBoard>
+);
+
+export const Card = {
+ render: CardTemplate,
+ name: "Radio.Card",
+ parameters: {
+ pseudo: {
+ hover: CARD_STATES.filter((state) => state.hovered).map(
+ (state) => `[data-state-row="${state.id}"]`,
+ ),
+ },
+ controls: { disable: true },
},
};
-export const Description = {
- render: StateTemplate,
- args: {
- description: "Description",
+const INTERACTIVE_CARDS = [
+ {
+ value: "react",
+ label: "React",
+ description: "A library for building user interfaces",
+ attrs: "",
+ props: {},
+ },
+ {
+ value: "svelte",
+ label: "Svelte",
+ description: "Cybernetically enhanced web apps",
+ attrs: "",
+ props: {},
+ },
+ {
+ value: "ng",
+ label: "Angular",
+ description: "The web development framework for modern apps",
+ attrs: " disabled",
+ props: { disabled: true },
},
+ {
+ value: "vue",
+ label: "Vue",
+ description: "The progressive JavaScript framework",
+ attrs: " withIndicator={false}",
+ props: { withIndicator: false },
+ },
+];
+
+const INTERACTIVE_JSX = [
+ `<Radio.Group>`,
+ ...INTERACTIVE_CARDS.map(({ attrs }) => ` <Radio.Card${attrs} />`),
+ `</Radio.Group>`,
+].join("\n");
+
+const InteractiveCardTemplate: StoryFn<RadioProps> = () => {
+ const [value, setValue] = useState("react");
+
+ return (
+ <StoryBoard title="Radio.Card" background="background_page-primary">
+ <Stack gap="1.5rem">
+ <StoryJsx>{INTERACTIVE_JSX}</StoryJsx>
+ <Radio.Group value={value} onChange={setValue}>
+ <Stack gap="0.375rem" w="16rem">
+ {INTERACTIVE_CARDS.map(({ value, label, description, props }) => (
+ <Radio.Card
+ key={value}
+ value={value}
+ label={label}
+ description={description}
+ {...props}
+ />
+ ))}
+ </Stack>
+ </Radio.Group>
+ </Stack>
+ </StoryBoard>
+ );
};
-export const DescriptionLeftPosition = {
- render: StateTemplate,
- name: "Description, left position",
- args: {
- description: "Description",
- labelPosition: "left",
+export const InteractiveCard = {
+ render: InteractiveCardTemplate,
+ name: "Radio.Card (interactive)",
+ parameters: {
+ controls: { disable: true },
+ loki: { skip: true },
},
};
diff --git a/frontend/src/metabase/ui/components/inputs/Radio/RadioCard.tsx b/frontend/src/metabase/ui/components/inputs/Radio/RadioCard.tsx
new file mode 100644
index 00000000000..ee2b6b6636b
--- /dev/null
+++ b/frontend/src/metabase/ui/components/inputs/Radio/RadioCard.tsx
@@ -0,0 +1,59 @@
+import {
+ RadioCard as MantineRadioCard,
+ type RadioCardProps as MantineRadioCardProps,
+ RadioIndicator as MantineRadioIndicator,
+ Stack,
+ Text,
+ rem,
+} from "@mantine/core";
+import { type ReactNode, forwardRef } from "react";
+
+export type RadioCardProps = Omit<MantineRadioCardProps, "children"> & {
+ label?: ReactNode;
+ description?: ReactNode;
+ leftSection?: ReactNode;
+ disabled?: boolean;
+ withIndicator?: boolean;
+};
+
+export const RadioCard = forwardRef<HTMLButtonElement, RadioCardProps>(
+ function RadioCard(
+ {
+ label,
+ description,
+ leftSection,
+ disabled,
+ withIndicator = true,
+ ...props
+ },
+ ref,
+ ) {
+ return (
+ <MantineRadioCard disabled={disabled} {...props} ref={ref}>
+ {withIndicator && <MantineRadioIndicator disabled={disabled} />}
+ {leftSection}
+ <Stack component="span" gap={rem(4)} miw={0}>
+ {label && (
+ <Text
+ component="span"
+ c={disabled ? "text-disabled" : "text-primary"}
+ fw={700}
+ lh={rem(18)}
+ >
+ {label}
+ </Text>
+ )}
+ {description && (
+ <Text
+ component="span"
+ size="sm"
+ c={disabled ? "text-disabled" : "text-secondary"}
+ >
+ {description}
+ </Text>
+ )}
+ </Stack>
+ </MantineRadioCard>
+ );
+ },
+);
diff --git a/frontend/src/metabase/ui/components/inputs/Radio/index.tsx b/frontend/src/metabase/ui/components/inputs/Radio/index.tsx
index 1329b5d7664..ac3ca6e3898 100644
--- a/frontend/src/metabase/ui/components/inputs/Radio/index.tsx
+++ b/frontend/src/metabase/ui/components/inputs/Radio/index.tsx
@@ -1,3 +1,25 @@
-export { Radio } from "@mantine/core";
+import {
+ Radio as MantineRadio,
+ type RadioProps as MantineRadioProps,
+} from "@mantine/core";
+import { forwardRef } from "react";
+
+import { RadioCard } from "./RadioCard";
+
+export type RadioProps = Omit<MantineRadioProps, "labelPosition" | "size">;
+
+const RadioRoot = forwardRef<HTMLInputElement, RadioProps>(
+ function RadioRoot(props, ref) {
+ return <MantineRadio {...props} ref={ref} />;
+ },
+);
+
+export const Radio = Object.assign(RadioRoot, {
+ Group: MantineRadio.Group,
+ Indicator: MantineRadio.Indicator,
+ Card: RadioCard,
+});
+
export { radioOverrides } from "./Radio.config";
-export type { RadioProps, RadioGroupProps } from "@mantine/core";
+export type { RadioGroupProps } from "@mantine/core";
+export type { RadioCardProps } from "./RadioCard";
diff --git a/frontend/src/metabase/ui/stories/showcase/StoryJsx.tsx b/frontend/src/metabase/ui/stories/showcase/StoryJsx.tsx
index fac127e8755..96c20412dba 100644
--- a/frontend/src/metabase/ui/stories/showcase/StoryJsx.tsx
+++ b/frontend/src/metabase/ui/stories/showcase/StoryJsx.tsx
@@ -66,7 +66,7 @@ interface StoryJsxProps {
/** Monospace JSX with light syntax highlighting (tags, props, values). */
export function StoryJsx({ children }: StoryJsxProps) {
return (
- <Text ff="monospace" size="sm" fw={500}>
+ <Text ff="monospace" size="sm" fw={500} style={{ whiteSpace: "pre-wrap" }}>
{tokenizeJsx(children).map((token, index) => (
<span
key={`${index}-${token.value}`}
diff --git a/loki.config.js b/loki.config.js
index 8ee384ef79a..30bcac9d740 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -9,8 +9,9 @@ module.exports = {
"^app/embed",
"^design system",
"^Patterns/Overlays",
- "^Components/Inputs/Checkbox (Overview|Checkbox\\.Card)",
+ "^Components/Inputs/Checkbox (Overview|Checkbox\\.Card)$",
"^Components/Inputs/DatePicker Dates range",
+ "^Components/Inputs/Radio (Overview|Radio\\.Card)$",
"^Components/Parameters/DatePicker",
"^Components/Buttons/Button Compact size, custom color",
"^Components/overlays/Tooltip",