Skip to content

Commit

Permalink
Quickfix/action filters alignment (#193)
Browse files Browse the repository at this point in the history
* Align filter labels properly

* Do not wrap filter label tooltips alone

* Add contrast to select dropdown hover items
  • Loading branch information
terotik authored Oct 13, 2023
1 parent 37d28ca commit 155f972
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
14 changes: 10 additions & 4 deletions components/actions/ActionListFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ const MainCategory = styled.div`
}
`;

const FilterColumn = styled(Col)`
display: flex;
flex-direction: column;
justify-content: flex-end;
`;

function sortDepthFirst<Type>(
items: Type[],
compareItem: (a: Type, b: Type) => number,
Expand Down Expand Up @@ -481,7 +487,7 @@ abstract class DefaultFilter<Value extends FilterValue>
) {
const _isMulti = isMulti ?? false;
return (
<Col sm={this.sm} md={this.md} lg={this.lg} key={this.id}>
<FilterColumn sm={this.sm} md={this.md} lg={this.lg} key={this.id}>
<ActionListDropdownInput
isMulti={_isMulti}
id={this.id}
Expand All @@ -492,7 +498,7 @@ abstract class DefaultFilter<Value extends FilterValue>
onChange={onChange}
options={this.options}
/>
</Col>
</FilterColumn>
);
}
}
Expand Down Expand Up @@ -806,7 +812,7 @@ class ActionNameFilter implements ActionListFilter<string | undefined> {
t: TFunction
) {
return (
<Col m={this.sm} md={this.md} lg={this.lg} key={this.id}>
<FilterColumn m={this.sm} md={this.md} lg={this.lg} key={this.id}>
<ActionListTextInput
id={this.id}
label={this.getLabel(t)}
Expand All @@ -815,7 +821,7 @@ class ActionNameFilter implements ActionListFilter<string | undefined> {
currentValue={value}
inputRef={this.ref}
/>
</Col>
</FilterColumn>
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/common/PopoverTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'common/i18n';
import { Button, Tooltip } from 'reactstrap';

const InfoButton = styled(Button)`
padding: 0 0.5rem 0.1rem;
padding: 0 0.25rem 0.1rem;
line-height: 0.5rem;
opacity: 0.5;
svg {
Expand Down
41 changes: 29 additions & 12 deletions components/common/SelectDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import Select, {
components,
DropdownIndicatorProps,
GroupBase,
MultiValueProps,
Theme as SelectTheme,
ValueContainerProps,
Expand All @@ -11,16 +10,17 @@ import styled from 'styled-components';
import Highlighter from 'react-highlight-words';
import { FormGroup, Label as BSLabel } from 'reactstrap';
import { useTheme, Theme } from 'common/theme';
import { data } from 'autoprefixer';
import PopoverTip from 'components/common/PopoverTip';
import { TRUE } from 'sass';
import { useTranslation } from 'common/i18n';

const Label = styled(BSLabel)`
font-weight: ${(props) => props.theme.formLabelFontWeight};
line-height: ${(props) => props.theme.lineHeightSm};
`;

const TooltipWrapper = styled.span`
white-space: nowrap; // Prevents the tooltip from wrapping
`;

function getSelectStyles<Option extends SelectDropdownOption>(
theme: Theme,
multi: boolean,
Expand Down Expand Up @@ -81,11 +81,15 @@ function getSelectStyles<Option extends SelectDropdownOption>(
const { indent } = data;
const ret = {
...provided,
color: theme.themeColors.black,
color: isSelected
? theme.themeColors.white
: isFocused
? theme.themeColors.black
: theme.themeColors.black,
backgroundColor: isSelected
? theme.graphColors.grey020
? theme.graphColors.grey080
: isFocused
? theme.graphColors.grey005
? theme.graphColors.grey020
: theme.graphColors.white,
margin: 0,
//marginLeft: `${indent ?? 0}rem`,
Expand Down Expand Up @@ -231,14 +235,27 @@ function SelectDropdown<
} = props;
const theme = useTheme();
const styles = getSelectStyles(theme, props.isMulti === true, size);

/* Do not wrap the tooltip icon on a new line alone */
/* Join it with the last word of the label instead */
/* TODO: Make this a part of the label/PopoverTip component */
const labelLastWord = label?.split(' ').pop();
const labelText = helpText
? label?.slice(0, label.length - (labelLastWord?.length || 0))
: label;
const tooltipElement = helpText ? (
<TooltipWrapper>
{labelLastWord}
<PopoverTip content={helpText} identifier={id} invert={invert} />
</TooltipWrapper>
) : null;

return (
<FormGroup>
{label && (
<Label for={id}>
{label}
{helpText && (
<PopoverTip content={helpText} identifier={id} invert={invert} />
)}
{labelText}
{tooltipElement}
</Label>
)}
<Select<SelectDropdownOption, IsMulti>
Expand All @@ -261,7 +278,7 @@ function SelectDropdown<
/>
);
if (context === 'value' || !indent) return highlighted;
let spans: JSX.Element[] = [];
const spans: JSX.Element[] = [];
for (let i = 0; i < indent; i++) {
spans.push(
<span
Expand Down

0 comments on commit 155f972

Please sign in to comment.