From a936732b941247f913d30e2d49ed9de8e3c1c746 Mon Sep 17 00:00:00 2001 From: Anastasiia Mishchenko <76526539+AnastasiiaMP@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:19:46 +0100 Subject: [PATCH] feat(SelectBadge): Components improvements (#1238) * feat: improve selected badge * test: update tests * refactor: remove unused console.log and simplify docs * chore: take care of undefined priority item * refactor: correct punctuation in docs * refactor: remove unnecessary "?" * refactor: change rendering conditions * refactor: remove redundant logic * refactor: remove redundant logic * test: update tes descriptions * refactor: address review comments * chore: change optionItem value in storybook to something real * refactor: Select Badge story simplification * refactor: simplify names * refactor: address final comments * refactor: remove unnecessary string literal --------- Co-authored-by: Anastasiia Mishchenko --- src/components/SelectBadge/SelectBadge.scss | 39 +-- src/components/SelectBadge/SelectBadge.tsx | 188 ++++++------- .../__tests__/SelectBadge.spec.tsx | 168 ++++++------ .../__snapshots__/SelectBadge.spec.tsx.snap | 106 ++++---- src/components/SelectBadge/index.ts | 7 +- stories/organisms/SelectBadge.stories.tsx | 252 +++++++++++------- 6 files changed, 430 insertions(+), 330 deletions(-) diff --git a/src/components/SelectBadge/SelectBadge.scss b/src/components/SelectBadge/SelectBadge.scss index 5273f42b2..1b3cbc9c9 100644 --- a/src/components/SelectBadge/SelectBadge.scss +++ b/src/components/SelectBadge/SelectBadge.scss @@ -5,14 +5,14 @@ $activeColor: var(--color-background-neutral-subtlest-pressed) ) { & { + width: var(--space-400); + height: var(--space-400); align-items: center; background-color: var(--transparent); cursor: pointer; display: flex; flex-shrink: 0; - height: var(--space-400); justify-content: center; - width: var(--space-400); } &:hover:not([disabled]) { @@ -66,6 +66,7 @@ $icon-status-colors: ( ); .SelectBadge { + width: 100%; height: var(--space-400); border: 1px solid var(--color-border-subtle); border-radius: var(--space-100); @@ -97,18 +98,19 @@ $icon-status-colors: ( } &__optionText { - min-width: var(--space-600); + max-width: var(--space-600); + min-width: var(--space-200); color: var(--color-text-information-default); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + flex-shrink: 0; } &__optionButton { width: 100%; padding: 0 var(--space-100); border: 0; - justify-content: space-around; flex-grow: 1; gap: var(--space-50); @@ -127,10 +129,13 @@ $icon-status-colors: ( } &__valueContainer { + width: 100%; + padding: 0 var(--space-100); + float: left; display: flex; - align-items: center; justify-content: center; - flex-grow: 1; + gap: var(--space-50); + overflow: auto; cursor: default; } @@ -152,19 +157,17 @@ $icon-status-colors: ( } } - .Dropdown { - &__list { - width: 100%; - border-radius: var(--space-100); - overflow: hidden; + .badgeDropdownList { + width: 100%; + border-radius: var(--space-100); + overflow: hidden; + } - .ListItem { - display: flex; - align-items: center; - justify-content: flex-start; - gap: var(--space-100); - } - } + .badgeListItem { + display: flex; + align-items: center; + justify-content: flex-start; + gap: var(--space-100); } &__deleteButton { diff --git a/src/components/SelectBadge/SelectBadge.tsx b/src/components/SelectBadge/SelectBadge.tsx index c46cd16e1..94acf9d2b 100644 --- a/src/components/SelectBadge/SelectBadge.tsx +++ b/src/components/SelectBadge/SelectBadge.tsx @@ -18,88 +18,69 @@ const iconMap = { export type Priority = 'mandatory' | 'important' | 'optional' | 'exclude'; -export interface Option { - value: string; +export type PriorityItem = { + priority: Priority; label: string; -} + value?: PriorityItemValue; +}; + +// Priority related props +type PriorityProps = { + /** Currently selected priority item that indicates the importance of the component. */ + selectedItem?: PriorityItem; + /** Array of availible priority items. */ + list: Array>; + /** Callback function triggered when a new priority is selected. */ + onChange: (newPriorityItem: PriorityItem) => void; + /** Priority button label name for ARIA labelling */ + buttonAriaLabel: string; +}; -export interface Props extends Omit, 'onChange'> { +// Option related props +type OptionProps = { + /** Currently selected option item. */ + selectedItem?: OptionItem; + /** Header title for the options list. */ + listHeader?: string; + /** Array of options available for selection. */ + list?: Array; + /** Converts an option to a string label for display. */ + toLabel: (option: OptionItem) => string; + /** Generates a unique key for an option. */ + toKey: (option: OptionItem) => string; + /** Callback function triggered when a new option is selected. */ + onChange?: (newOptionItem: OptionItem) => void; + /** Option button label name for ARIA labelling */ + buttonAriaLabel: string; +}; + +export interface Props + extends Omit, 'onChange'> { /** * Children nodes to be rendered within the component, * specifically used to display the selected value from parent component. */ children: React.ReactNode; - /** - * Optional object containing labels for different priorities, used primarily for localization. - */ - priorityLabels?: { - mandatory?: string; - important?: string; - optional?: string; - exclude?: string; - }; - /** - * Current priority value that indicates the importance of the component. - * Uses the Priority type which can be 'mandatory', 'important', 'optional', or 'exclude'. - */ - priority: Priority; - /** - * Optional object specifying the currently selected option with value and label properties. - */ - option?: Option; - /** - * Array of options available for selection. - * Each option is an object with a value and a label. - */ - optionList?: Array