Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 55 additions & 45 deletions bun.lock

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions src/atoms/utils/environmentToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ const VARIANT_COLORS: Record<StatusVariant, ColorConfig> = {
},
};

const DEFAULT_COLORS: ColorConfig = {
border: colors.interactive.warning__resting.rgba,
background: colors.interactive.warning__text.rgba,
chipBackground: colors.interactive.warning__resting.rgba,
outline: colors.interactive.warning__resting.rgba,
};

export function getVariantColors(
variant: StatusVariant | undefined
): ColorConfig {
return variant ? VARIANT_COLORS[variant] : DEFAULT_COLORS;
export function getVariantColors(variant: StatusVariant): ColorConfig {
return VARIANT_COLORS[variant];
}
2 changes: 1 addition & 1 deletion src/molecules/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ export const Compact: Story = {
},
play: async ({ canvas, args }) => {
const container = canvas.getByText(args.children as string);
await expect(container.parentElement).toHaveStyle('padding: 8px');
await expect(container.parentElement).toHaveStyle('padding: 4px 8px');
},
};
20 changes: 9 additions & 11 deletions src/molecules/Select/ComboBox/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const BasicComboBox: StoryFn = (args) => {
);
};

export const ComboBoxWithReallyLongName: StoryFn = (args) => {
export const ReallyLongName: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand All @@ -140,7 +140,7 @@ export const ComboBoxWithReallyLongName: StoryFn = (args) => {
);
};

export const ComboBoxWithGroups: StoryFn = (args) => {
export const Groups: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand All @@ -161,7 +161,7 @@ export const ComboBoxWithGroups: StoryFn = (args) => {
);
};

export const ComboBoxParented: StoryFn = (args) => {
export const Parented: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand All @@ -182,7 +182,7 @@ export const ComboBoxParented: StoryFn = (args) => {
);
};

export const ComboBoxInDialog: StoryFn = (args) => {
export const InDialog: StoryFn = (args) => {
const [openDialog, setOpenDialog] = useState(false);
const [values, setValues] = useState<SelectOption<Item>[]>([]);
const [openComboBox, setOpenComboBox] = useState(false);
Expand Down Expand Up @@ -225,7 +225,7 @@ export const ComboBoxInDialog: StoryFn = (args) => {
);
};

export const ComboBoxWithAdd: StoryFn = (args) => {
export const AddFunctionality: StoryFn = (args) => {
const [items, setItems] = useState([...FAKE_ITEMS]);
const [values, setValues] = useState<SelectOption<Item>[]>([]);
const handleOnSelect = (newValues: SelectOptionRequired[]) => {
Expand Down Expand Up @@ -277,7 +277,7 @@ const CustomValueElement: FC<{
</ComboBoxChip>
);

export const ComboBoxWithCustomValueElements: StoryFn = (args) => {
export const CustomizableValueElement: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand All @@ -299,7 +299,7 @@ export const ComboBoxWithCustomValueElements: StoryFn = (args) => {
);
};

export const ComboBoxWithSelectedValuesAsText: StoryFn = (args) => {
export const SelectedValuesAsText: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand All @@ -321,9 +321,7 @@ export const ComboBoxWithSelectedValuesAsText: StoryFn = (args) => {
);
};

export const ComboBoxWithCustomSelectedValuesAsTextFunction: StoryFn = (
args
) => {
export const CustomSelectedValuesAsTextFunction: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand Down Expand Up @@ -358,7 +356,7 @@ const CustomMenuItem: FC<{
</>
);

export const ComboboxWithCustomizableSelectMenuItem: StoryFn = (args) => {
export const CustomizableMenuItem: StoryFn = (args) => {
const [values, setValues] = useState<SelectOption<Item>[]>([]);

const handleOnSelect = (
Expand Down
108 changes: 94 additions & 14 deletions src/molecules/Select/ComboBox/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,22 +664,102 @@ const CustomValueElement: FC<{
</ComboBoxChip>
);

test('Custom value component', () => {
const label = faker.animal.bear();
const items = fakeSelectItems();
const handler = vi.fn();
describe('Custom value component', () => {
test('Renders', () => {
const label = faker.animal.bear();
const items = fakeSelectItems();
const handler = vi.fn();

render(
<ComboBox
label={label}
onSelect={handler}
items={items}
values={[items[0]]}
customValueComponent={CustomValueElement}
/>
);
render(
<ComboBox
label={label}
onSelect={handler}
items={items}
values={[items[0]]}
customValueComponent={CustomValueElement}
/>
);

const customChip = screen
.getByText('custom')
.closest('.amplify-combo-box-chip');

expect(customChip).toBeInTheDocument();
});

test('Removal by clicking', async () => {
const label = faker.animal.bear();
const items = fakeSelectItems();
const handler = vi.fn();

const { rerender } = render(
<ComboBox
label={label}
onSelect={handler}
items={items}
values={[items[0]]}
customValueComponent={CustomValueElement}
/>
);

expect(screen.getByText('custom')).toBeInTheDocument();
const user = userEvent.setup();
const customChip = screen
.getByText('custom')
.closest('.amplify-combo-box-chip');

await user.click(customChip!);

expect(handler).toHaveBeenCalledWith([], items[0]);

rerender(
<ComboBox
label={label}
onSelect={handler}
items={items}
values={[]}
customValueComponent={CustomValueElement}
/>
);

expect(screen.queryByText('custom')).not.toBeInTheDocument();
});

test('Removal by backspace', async () => {
const label = faker.animal.bear();
const items = fakeSelectItems();
const handler = vi.fn();

const { rerender } = render(
<ComboBox
label={label}
onSelect={handler}
items={items}
values={[items[0]]}
customValueComponent={CustomValueElement}
/>
);

const user = userEvent.setup();
const searchField = screen.getByRole('combobox');

await user.click(searchField);
await user.keyboard('{Backspace}');
await user.keyboard('{Backspace}');

expect(handler).toHaveBeenCalledWith([], items[0]);

rerender(
<ComboBox
label={label}
onSelect={handler}
items={items}
values={[]}
customValueComponent={CustomValueElement}
/>
);

expect(screen.queryByText('custom')).not.toBeInTheDocument();
});
});

test('showSelectedValuesAsText', async () => {
Expand Down
7 changes: 1 addition & 6 deletions src/molecules/Select/DynamicMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyboardEvent, MouseEvent, ReactNode, useMemo } from 'react';
import { KeyboardEvent, MouseEvent, useMemo } from 'react';

import { checkbox, checkbox_outline } from '@equinor/eds-icons';

Expand All @@ -22,14 +22,12 @@ interface DynamicMenuItemProps<T extends SelectOptionRequired> {
menuItemProps: SingleSelectMenuItemProps<T> | MultiSelectMenuItemProps<T>;
isSelected: boolean;
handleOnParentKeyDown?: (event: KeyboardEvent<HTMLButtonElement>) => void;
children?: ReactNode;
}

export const DynamicMenuItem = <T extends SelectOptionRequired>({
menuItemProps,
isSelected,
handleOnParentKeyDown,
children,
}: DynamicMenuItemProps<T>) => {
const {
index,
Expand Down Expand Up @@ -64,8 +62,6 @@ export const DynamicMenuItem = <T extends SelectOptionRequired>({
};

const itemContent = useMemo(() => {
if (children) return children;

if (CustomMenuItemComponent) {
return (
<CustomMenuItemComponent item={item} selectedState={selectedState} />
Expand All @@ -90,7 +86,6 @@ export const DynamicMenuItem = <T extends SelectOptionRequired>({
}, [
CustomMenuItemComponent,
checkboxIcon,
children,
item,
menuItemProps,
selectedState,
Expand Down
24 changes: 19 additions & 5 deletions src/molecules/Select/GroupedSelectPersistent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ import {
NoItemsFoundText,
PersistentGroupsWrapper,
} from 'src/molecules/Select/Select.styles';
import { GroupedSelectPropsCombined } from 'src/molecules/Select/Select.types';
import {
CustomMenuItemComponentProps,
GroupedSelectProps,
MenuModeSelectProps,
MultiSelectCommon,
PersistentModeSelectProps,
SelectMenuProps,
SingleSelectCommon,
} from 'src/molecules/Select/Select.types';
import { SelectMenuItem } from 'src/molecules/Select/SelectMenuItem';

// Ignored because <T extends SelectOptionRequired> is marked at not covered, and is removed at runtime so it cannot be covered.
/* c8 ignore next */
export const GroupedSelectPersistent = <T extends SelectOptionRequired>(
props: GroupedSelectPropsCombined<T>
props: GroupedSelectProps<T> &
SelectMenuProps<T> &
CustomMenuItemComponentProps<T> &
(MultiSelectCommon<T> | SingleSelectCommon<T>) &
(PersistentModeSelectProps | MenuModeSelectProps)
) => {
const {
onItemSelect,
Expand All @@ -27,9 +41,9 @@ export const GroupedSelectPersistent = <T extends SelectOptionRequired>(
return <NoItemsFoundText>No items found</NoItemsFoundText>;
}

if ('value' in props) {
throw new Error('You cannot use SingleSelect with persistent mode');
}
// This case never happens, since there is a check in select.tsx. This check gives the correct typescript inference.
/* c8 ignore next */
if ('value' in props) return null;
Comment thread
aslakihle marked this conversation as resolved.

return (
<PersistentGroupsWrapper>
Expand Down
2 changes: 2 additions & 0 deletions src/molecules/Select/ListSelectPersistent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
import { getChildOffset } from 'src/molecules/Select/Select.utils';
import { SelectMenuItem } from 'src/molecules/Select/SelectMenuItem';

// Ignored because <T extends SelectOptionRequired> is marked at not covered, and is removed at runtime so it cannot be covered.
/* c8 ignore next */
export const ListSelectPersistent = <T extends SelectOptionRequired>(
props: Omit<ListSelectProps<T>, 'onAddItem'> &
ListSelectMenuProps &
Expand Down
Loading
Loading