The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Match SelectButton styling to Select (#79879)
Oleh K8129fff8364c
diff --git a/frontend/src/metabase/common/components/SelectButton/SelectButton.module.css b/frontend/src/metabase/common/components/SelectButton/SelectButton.module.cssnew file mode 100644index 00000000000..9762147822a--- /dev/null+++ b/frontend/src/metabase/common/components/SelectButton/SelectButton.module.css@@ -0,0 +1,84 @@+/*+ * Spacing is pixel-matched to the md Select input.+ */+.root {+ box-sizing: border-box;+ display: flex;+ align-items: center;+ min-width: 104px;+ min-height: 2.5rem;+ padding: 0 0.75rem 0 0.6875rem;+ border: 1px solid var(--mb-color-border-neutral);+ border-radius: var(--mantine-radius-xs);+ background-color: var(--mb-color-background_page-primary);+ color: var(--mb-color-text-primary);+ font-size: var(--mantine-font-size-md);+ font-weight: normal;+ line-height: 1.5rem;+ text-align: left;+ cursor: pointer;++ &:hover:not(:disabled) {+ border-color: var(--mb-color-core-brand);+ }++ &:focus {+ border-color: var(--mb-color-core-brand);+ outline: 2px solid var(--mb-color-input-focus);+ }++ &:not(:focus-visible) {+ outline: none;+ }++ &:disabled {+ background-color: var(--mb-color-background_surface-disabled);+ color: var(--mb-color-text-disabled);+ pointer-events: none;+ }+}++.fullWidth {+ width: 100%;+}++.noValue {+ color: var(--mb-color-text-disabled);+}++.highlighted {+ border-color: var(--mb-color-core-brand);+ background-color: var(--mb-color-core-brand);+ color: var(--mb-color-text-primary-inverse);+}++.content {+ min-width: 0;+ margin-right: 0.6875rem;+ overflow: hidden;+ white-space: nowrap;+ text-overflow: ellipsis;+}++.contentClearable {+ margin-right: 0.4375rem;+}++.icon {+ display: flex;+ flex-shrink: 0;+ margin-left: auto;+ color: var(--mb-color-text-primary);+}++.icon + .icon {+ margin-left: var(--mantine-spacing-sm);+}++.iconHighlighted {+ color: var(--mb-color-text-primary-inverse);+}++.iconDisabled {+ color: var(--mb-color-text-disabled);+}diff --git a/frontend/src/metabase/common/components/SelectButton/SelectButton.styled.tsx b/frontend/src/metabase/common/components/SelectButton/SelectButton.styled.tsxdeleted file mode 100644index df14f9c5f28..00000000000--- a/frontend/src/metabase/common/components/SelectButton/SelectButton.styled.tsx+++ /dev/null@@ -1,83 +0,0 @@-// eslint-disable-next-line no-restricted-imports-import styled from "@emotion/styled";-import type { ComponentPropsWithRef } from "react";--import { Icon } from "metabase/ui";-import { color } from "metabase/ui/utils/colors";-interface SelectButtonRootProps {- hasValue: boolean;- fullWidth: boolean;- highlighted: boolean;-}--const getColor = ({ hasValue, highlighted }: SelectButtonRootProps) => {- if (hasValue) {- return highlighted ? color("text-primary-inverse") : color("text-primary");- } else {- return color("text-disabled");- }-};--export const SelectButtonRoot = styled.button<SelectButtonRootProps>`- padding: 0.625rem 0.75rem;- cursor: pointer;- display: flex;- width: ${(props) => (props.fullWidth ? "100%" : "unset")};- align-items: center;- border: 1px solid- ${({ hasValue, highlighted }) =>- hasValue && highlighted ? color("core-brand") : color("border-neutral")};- background-color: ${({ hasValue, highlighted }) =>- hasValue && highlighted- ? color("core-brand")- : color("background_page-primary")};- border-radius: var(--mantine-spacing-sm);- font-weight: 700;- min-width: 104px;- color: ${getColor};-- &:hover {- border-color: var(--mb-color-core-brand);- }-- &:focus {- border-color: var(--mb-color-core-brand);- outline: 2px solid var(--mb-color-input-focus);- }-- &:not(:focus-visible) {- outline: none;- }-- &:disabled {- background-color: var(--mb-color-background_page-secondary);- color: var(--mb-color-text-secondary);- pointer-events: none;- }-`;--interface SelectButtonIconProps {- hasValue: boolean;- highlighted: boolean;-}--export const SelectButtonIcon = styled(- ({- hasValue,- highlighted,- ...rest- }: SelectButtonIconProps & ComponentPropsWithRef<typeof Icon>) => (- <Icon {...rest} />- ),-)`- display: flex;- margin-left: auto;- color: ${({ hasValue, highlighted }) =>- hasValue && highlighted- ? color("text-primary-inverse")- : color("text-secondary")};-`;--export const SelectButtonContent = styled.span`- margin-right: 0.5rem;-`;diff --git a/frontend/src/metabase/common/components/SelectButton/SelectButton.tsx b/frontend/src/metabase/common/components/SelectButton/SelectButton.tsxindex 0fd8217f757..56273e19c0a 100644--- a/frontend/src/metabase/common/components/SelectButton/SelectButton.tsx+++ b/frontend/src/metabase/common/components/SelectButton/SelectButton.tsx@@ -1,13 +1,11 @@import cx from "classnames";import type { ButtonHTMLAttributes, Ref } from "react";-import { forwardRef, useCallback, useMemo } from "react";+import { forwardRef, useCallback } from "react";import * as React from "react";-import {- SelectButtonContent,- SelectButtonIcon,- SelectButtonRoot,-} from "./SelectButton.styled";+import { Icon } from "metabase/ui";++import S from "./SelectButton.module.css";export interface SelectButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {left?: React.ReactNode;@@ -56,46 +54,50 @@ const SelectButtonInner = forwardRef(function SelectButton([onClear],);- const rightIcon = useMemo(() => {- if (hasValue && onClear) {- return "close";- }- return "chevrondown";- }, [hasValue, onClear]);+ const showClear = hasValue && !!onClear;++ const iconClassName = cx(+ S.icon,+ {+ [S.iconHighlighted]: hasValue && highlighted,+ [S.iconDisabled]: disabled,+ },+ classNames.icon,+ );return (- <SelectButtonRoot+ <buttontype="button"data-testid={`${dataTestId ? `${dataTestId}-` : ""}select-button`}ref={ref}- className={cx(classNames.root, className)}+ className={cx(+ S.root,+ {+ [S.fullWidth]: fullWidth,+ [S.noValue]: !hasValue,+ [S.highlighted]: hasValue && highlighted,+ },+ classNames.root,+ className,+ )}style={style}- hasValue={hasValue}disabled={disabled}- highlighted={highlighted}- fullWidth={fullWidth}onClick={onClick}{...rest}>{React.isValidElement(left) && left}- <SelectButtonContent data-testid="select-button-content">+ <span+ className={cx(S.content, { [S.contentClearable]: showClear })}+ data-testid="select-button-content"+ >{children}- </SelectButtonContent>- <SelectButtonIcon- className={classNames.icon}- name={rightIcon}- size={12}- hasValue={hasValue}- highlighted={highlighted}- onClick={rightIcon === "close" ? handleClear : undefined}- style={{ flexShrink: 0 }}- />- </SelectButtonRoot>+ </span>+ {showClear && (+ <Icon className={iconClassName} name="close" onClick={handleClear} />+ )}+ <Icon className={iconClassName} name="chevrondown" />+ </button>);});-export const SelectButton = Object.assign(SelectButtonInner, {- Root: SelectButtonRoot,- Content: SelectButtonContent,- Icon: SelectButtonIcon,-});+export const SelectButton = SelectButtonInner;diff --git a/frontend/src/metabase/ui/components/inputs/Select/Select.module.css b/frontend/src/metabase/ui/components/inputs/Select/Select.module.cssindex e32970a31b8..4b20d456bff 100644--- a/frontend/src/metabase/ui/components/inputs/Select/Select.module.css+++ b/frontend/src/metabase/ui/components/inputs/Select/Select.module.css@@ -24,10 +24,41 @@padding-right: var(--input-right-section-width);}}++ &[data-size="xs"]:has([data-combined-clear-section]) {+ .SelectInput {+ padding-right: 2.5625rem;+ }+ }++ &[data-size="sm"]:has([data-combined-clear-section]) {+ .SelectInput {+ padding-right: 3.125rem;+ }+ }++ &[data-size="md"]:has([data-combined-clear-section]) {+ .SelectInput {+ padding-right: 3.75rem;+ }+ }++ &[data-size="lg"]:has([data-combined-clear-section]) {+ .SelectInput {+ padding-right: 4.5rem;+ }+ }++ &[data-size="xl"]:has([data-combined-clear-section]) {+ .SelectInput {+ padding-right: 5.5625rem;+ }+ }}.SelectInput {color: var(--mb-color-text-primary);+ text-overflow: ellipsis;background-color: var(--mb-color-background_page-primary);&[data-disabled] {@@ -70,7 +101,6 @@[data-disabled] & {opacity: 1;color: var(--mb-color-text-disabled);- background-color: var(--mb-color-background_page-tertiary);&::placeholder {color: var(--mb-color-text-disabled);