Skip to content

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

GDGT-3231: 1. Combobox: add Select, MultiSelect and Combobox stories with Loki snapshots (#82756)

Anna Tomka97283f9c024c
diff --git a/.loki/reference/chrome_laptop_Components_Inputs_MultiSelect_Overview.png b/.loki/reference/chrome_laptop_Components_Inputs_MultiSelect_Overview.png
new file mode 100644
index 00000000000..1ea8c973991
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Inputs_MultiSelect_Overview.png differ
diff --git a/.loki/reference/chrome_laptop_Components_Inputs_Select_Overview.png b/.loki/reference/chrome_laptop_Components_Inputs_Select_Overview.png
new file mode 100644
index 00000000000..58c9b0d4943
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Inputs_Select_Overview.png differ
diff --git a/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.mdx b/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.mdx
index 957431c035d..07ece482e40 100644
--- a/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.mdx
+++ b/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.mdx
@@ -17,6 +17,10 @@ Our themed wrapper around [Mantine MultiSelect](https://v6.mantine.dev/core/mult
<Canvas of={MultiSelectStories.Default} />
+### States
+
+<Canvas of={MultiSelectStories.Overview} />
+
### Size - md
<Canvas of={MultiSelectStories.EmptyMd} />
diff --git a/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.stories.tsx b/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.stories.tsx
index e4baea092f2..f169af523b6 100644
--- a/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.stories.tsx
+++ b/frontend/src/metabase/ui/components/inputs/MultiSelect/MultiSelect.stories.tsx
@@ -1,4 +1,21 @@
-import { MultiSelect, type MultiSelectProps, Stack } from "metabase/ui";
+import type { StoryFn } from "@storybook/react";
+import { Fragment } from "react";
+
+import {
+ Box,
+ Icon,
+ MultiSelect,
+ type MultiSelectProps,
+ Stack,
+ Text,
+} from "metabase/ui";
+import {
+ StoryJsx,
+ StorySection,
+ StoryShowcase,
+} from "metabase/ui/stories/showcase";
+
+import S from "./MultiSelect.module.css";
const dataWithGroupsLarge = [
{
@@ -128,6 +145,144 @@ export default {
export const Default = {};
+const OVERVIEW_SIZES = ["md", "xs"] as const;
+
+const OVERVIEW_VALUE = [dataWithLabels[0].value, dataWithLabels[1].value];
+
+type OverviewRow = {
+ id: string;
+ label: string;
+ props: Partial<MultiSelectProps>;
+ focus?: boolean;
+};
+
+const OVERVIEW_STATES = [
+ { id: "default-empty", label: "Default, empty", props: {} },
+ {
+ id: "default-filled",
+ label: "Default, filled",
+ props: { defaultValue: OVERVIEW_VALUE },
+ },
+ { id: "focused-empty", label: "Focused, empty", props: {}, focus: true },
+ {
+ id: "focused-filled",
+ label: "Focused, filled",
+ props: { defaultValue: OVERVIEW_VALUE },
+ focus: true,
+ },
+ {
+ id: "error-empty",
+ label: "Error, empty",
+ props: { error: sampleArgs.error },
+ },
+ {
+ id: "error-filled",
+ label: "Error, filled",
+ props: { error: sampleArgs.error, defaultValue: OVERVIEW_VALUE },
+ },
+ {
+ id: "error-focused-empty",
+ label: "Error + Focused, empty",
+ props: { error: sampleArgs.error },
+ focus: true,
+ },
+ {
+ id: "error-focused-filled",
+ label: "Error + Focused, filled",
+ props: { error: sampleArgs.error, defaultValue: OVERVIEW_VALUE },
+ focus: true,
+ },
+ {
+ id: "disabled-empty",
+ label: "Disabled, empty",
+ props: { disabled: true },
+ },
+ {
+ id: "disabled-filled",
+ label: "Disabled, filled",
+ props: { disabled: true, defaultValue: OVERVIEW_VALUE },
+ },
+] satisfies OverviewRow[];
+
+const OVERVIEW_CONTENT = [
+ { id: "label-only", label: "Label only", props: {} },
+ {
+ id: "description",
+ label: "With description",
+ props: { description: "Input description" },
+ },
+ {
+ id: "left-icon",
+ label: "With left icon",
+ props: {
+ description: "Input description",
+ leftSection: <Icon name="label" />,
+ },
+ },
+] satisfies OverviewRow[];
+
+const OverviewGrid = ({ rows }: { rows: readonly OverviewRow[] }) => (
+ <Box
+ style={{
+ display: "grid",
+ gridTemplateColumns: `14rem repeat(${OVERVIEW_SIZES.length}, max-content)`,
+ columnGap: "2rem",
+ rowGap: "1rem",
+ alignItems: "center",
+ }}
+ >
+ <div />
+ {OVERVIEW_SIZES.map((size) => (
+ <StoryJsx key={size}>{`<MultiSelect size="${size}" />`}</StoryJsx>
+ ))}
+ {rows.map((state) => (
+ <Fragment key={state.id}>
+ <Text size="sm" c="text-secondary">
+ {state.label}
+ </Text>
+ {OVERVIEW_SIZES.map((size) => (
+ <Box key={size} w={256}>
+ <MultiSelect
+ wrapperProps={{ "data-state-row": state.id }}
+ data={dataWithLabels}
+ label="Label"
+ placeholder="Placeholder"
+ size={size}
+ {...state.props}
+ />
+ </Box>
+ ))}
+ </Fragment>
+ ))}
+ </Box>
+);
+
+const OverviewTemplate: StoryFn<MultiSelectProps> = () => (
+ <StoryShowcase title="MultiSelect">
+ <StorySection title="States">
+ <OverviewGrid rows={OVERVIEW_STATES} />
+ </StorySection>
+ <StorySection title="Content">
+ <OverviewGrid rows={OVERVIEW_CONTENT} />
+ </StorySection>
+ </StoryShowcase>
+);
+
+const focusSelector = (id: string) =>
+ `[data-state-row="${id}"] .${S.MultiSelectInput}`;
+
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ pseudo: {
+ focusWithin: OVERVIEW_STATES.filter((state) => state.focus).map((state) =>
+ focusSelector(state.id),
+ ),
+ },
+ controls: { include: ["theme"] },
+ },
+};
+
export const EmptyMd = {
render: VariantTemplate,
name: "Empty, md",
diff --git a/frontend/src/metabase/ui/components/inputs/Select/Select.mdx b/frontend/src/metabase/ui/components/inputs/Select/Select.mdx
index 0cdc5d11bfe..dd81ef8264f 100644
--- a/frontend/src/metabase/ui/components/inputs/Select/Select.mdx
+++ b/frontend/src/metabase/ui/components/inputs/Select/Select.mdx
@@ -17,6 +17,10 @@ Our themed wrapper around [Mantine Select](https://v6.mantine.dev/core/select/).
<Canvas of={SelectStories.Default} />
+### States
+
+<Canvas of={SelectStories.Overview} />
+
### Size - md
<Canvas of={SelectStories.EmptyMd} />
diff --git a/frontend/src/metabase/ui/components/inputs/Select/Select.stories.tsx b/frontend/src/metabase/ui/components/inputs/Select/Select.stories.tsx
index e90ae6abff2..263f6da6d15 100644
--- a/frontend/src/metabase/ui/components/inputs/Select/Select.stories.tsx
+++ b/frontend/src/metabase/ui/components/inputs/Select/Select.stories.tsx
@@ -1,6 +1,13 @@
import type { ComboboxItem, ComboboxItemGroup } from "@mantine/core";
+import type { StoryFn } from "@storybook/react";
+import { Fragment } from "react";
-import { Select, type SelectProps, Stack } from "metabase/ui";
+import { Box, Icon, Select, type SelectProps, Stack, Text } from "metabase/ui";
+import {
+ StoryJsx,
+ StorySection,
+ StoryShowcase,
+} from "metabase/ui/stories/showcase";
type ComboboxItemWithIcon = ComboboxItem & { icon: string };
@@ -132,6 +139,171 @@ export default {
export const Default = {};
+type OverviewRow = {
+ id: string;
+ label: string;
+ props: Partial<SelectProps<string>>;
+ focus?: boolean;
+};
+
+const OVERVIEW_SIZES = ["md", "xs"] as const;
+
+const OVERVIEW_STATES = [
+ { id: "default-empty", label: "Default, empty", props: {} },
+ {
+ id: "default-filled",
+ label: "Default, filled",
+ props: { defaultValue: sampleArgs.value },
+ },
+ { id: "focused-empty", label: "Focused, empty", props: {}, focus: true },
+ {
+ id: "focused-filled",
+ label: "Focused, filled",
+ props: { defaultValue: sampleArgs.value },
+ focus: true,
+ },
+ {
+ id: "error-empty",
+ label: "Error, empty",
+ props: { error: sampleArgs.error },
+ },
+ {
+ id: "error-filled",
+ label: "Error, filled",
+ props: { error: sampleArgs.error, defaultValue: sampleArgs.value },
+ },
+ {
+ id: "error-focused-empty",
+ label: "Error + Focused, empty",
+ props: { error: sampleArgs.error },
+ focus: true,
+ },
+ {
+ id: "error-focused-filled",
+ label: "Error + Focused, filled",
+ props: { error: sampleArgs.error, defaultValue: sampleArgs.value },
+ focus: true,
+ },
+ {
+ id: "disabled-empty",
+ label: "Disabled, empty",
+ props: { disabled: true },
+ },
+ {
+ id: "disabled-filled",
+ label: "Disabled, filled",
+ props: { disabled: true, defaultValue: sampleArgs.value },
+ },
+ {
+ id: "clearable",
+ label: "With clear button",
+ props: { clearable: true, defaultValue: sampleArgs.value },
+ },
+ {
+ id: "clearable-focused",
+ label: "With clear button, focused",
+ props: { clearable: true, defaultValue: sampleArgs.value },
+ focus: true,
+ },
+ {
+ id: "clearable-error",
+ label: "With clear button, error",
+ props: {
+ clearable: true,
+ defaultValue: sampleArgs.value,
+ error: sampleArgs.error,
+ },
+ },
+ {
+ id: "clearable-error-focused",
+ label: "With clear button, error + focused",
+ props: {
+ clearable: true,
+ defaultValue: sampleArgs.value,
+ error: sampleArgs.error,
+ },
+ focus: true,
+ },
+] satisfies OverviewRow[];
+
+const OVERVIEW_CONTENT = [
+ { id: "label-only", label: "Label only", props: {} },
+ {
+ id: "description",
+ label: "With description",
+ props: { description: "Input description" },
+ },
+ {
+ id: "left-icon",
+ label: "With left icon",
+ props: {
+ description: "Input description",
+ leftSection: <Icon name="label" />,
+ },
+ },
+] satisfies OverviewRow[];
+
+const OverviewGrid = ({ rows }: { rows: readonly OverviewRow[] }) => (
+ <Box
+ style={{
+ display: "grid",
+ gridTemplateColumns: `14rem repeat(${OVERVIEW_SIZES.length}, max-content)`,
+ columnGap: "2rem",
+ rowGap: "1rem",
+ alignItems: "center",
+ }}
+ >
+ <div />
+ {OVERVIEW_SIZES.map((size) => (
+ <StoryJsx key={size}>{`<Select size="${size}" />`}</StoryJsx>
+ ))}
+ {rows.map((state) => (
+ <Fragment key={state.id}>
+ <Text size="sm" c="text-secondary">
+ {state.label}
+ </Text>
+ {OVERVIEW_SIZES.map((size) => (
+ <Box key={size} w={256}>
+ <Select
+ data-state-row={state.id}
+ data={dataWithNoGroups}
+ label="Label"
+ placeholder="Placeholder"
+ size={size}
+ {...state.props}
+ />
+ </Box>
+ ))}
+ </Fragment>
+ ))}
+ </Box>
+);
+
+const OverviewTemplate: StoryFn<SelectProps<string>> = () => (
+ <StoryShowcase title="Select">
+ <StorySection title="States">
+ <OverviewGrid rows={OVERVIEW_STATES} />
+ </StorySection>
+ <StorySection title="Content">
+ <OverviewGrid rows={OVERVIEW_CONTENT} />
+ </StorySection>
+ </StoryShowcase>
+);
+
+const focusSelector = (id: string) => `[data-state-row="${id}"]`;
+
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ pseudo: {
+ focus: OVERVIEW_STATES.filter((state) => state.focus).map((state) =>
+ focusSelector(state.id),
+ ),
+ },
+ controls: { include: ["theme"] },
+ },
+};
+
export const EmptyMd = {
render: VariantTemplate,
name: "Empty, md",
diff --git a/loki.config.js b/loki.config.js
index 23fed4d0d05..3f41dee94c3 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -32,6 +32,8 @@ module.exports = {
"^Components/Table",
"^Components/Inputs/PasswordInput Overview",
"^Components/Data display/Accordion Overview",
+ "^Components/Inputs/Select Overview",
+ "^Components/Inputs/MultiSelect Overview",
"^App/Palette",
"^viz/GridMapPdfExport",
"ParameterValueWidget",