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
25 changes: 18 additions & 7 deletions apps/website/screens/components/dropdown/code/DropdownCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ import QuickNavContainer from "@/common/QuickNavContainer";
import Example from "@/common/example/Example";
import basicUsage from "./examples/basicUsage";
import icons from "./examples/icons";
import Code, { TableCode } from "@/common/Code";
import Code, { ExtendedTableCode, TableCode } from "@/common/Code";
import StatusBadge from "@/common/StatusBadge";

const optionsTypeString = `{
label?: string;
icon?: string
| (React.ReactNode
& React.SVGProps<SVGSVGElement>);
hasDivider?: boolean;
value: string;
}[]`;

const sections = [
{
title: "Props",
Expand Down Expand Up @@ -117,16 +126,15 @@ const sections = [
<tr>
<td>
<DxcFlex direction="column" gap="var(--spacing-gap-xs)" alignItems="baseline">
<StatusBadge status="required" />
<DxcFlex gap="var(--spacing-gap-xs)" alignItems="baseline">
<StatusBadge status="required" />
<StatusBadge status="new" />
</DxcFlex>
options
</DxcFlex>
</td>
<td>
<TableCode>
{
"{ label?: string; icon?: string | (React.ReactNode & React.SVGProps <SVGSVGElement>); value: string }[]"
}
</TableCode>
<ExtendedTableCode>{optionsTypeString}</ExtendedTableCode>
</td>
<td>
An array of objects representing the options. Each object has the following properties:
Comment thread
PelayoFelgueroso marked this conversation as resolved.
Expand All @@ -146,6 +154,9 @@ const sections = [
<li>
<strong>value</strong>: Option inner value.
</li>
<li>
<strong>hasDivider</strong>: Whether a divider should be displayed after the option.
</li>
</ul>
</td>
<td>-</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@ const code = `() => {
},
{
value: 2,
label: "Windows",
label: "IOS",
hasDivider: true,
},
{
value: 3,
label: "IOS",
label: "Windows",
},
{
value: 4,
label: "Linux",
},
{
value: 5,
label: "macOS",
hasDivider: true,
},
{
value: 6,
label: "Other",
},
];

Expand Down
25 changes: 21 additions & 4 deletions apps/website/screens/components/dropdown/code/examples/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,34 @@ const code = `() => {
{
value: 1,
label: "Android",
icon: "filled_phone_android",
icon: "phone_android",
},
{
value: 2,
label: "IOS",
icon: "phone_iphone",
hasDivider: true,
},
{
value: 3,
label: "Windows",
icon: "desktop_windows",
},
{
value: 3,
label: "IOS",
icon: "filled_phone_iphone",
value: 4,
label: "Linux",
icon: "laptop",
},
{
value: 5,
label: "macOS",
icon: "laptop_mac",
hasDivider: true,
},
{
value: 6,
label: "Other",
icon: "devices_other",
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ const sections = [
<strong>Use icons thoughtfully:</strong> icons can enhance usability but should only be added when they add
clarity. Overloading the dropdown with icons can create visual clutter.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Add dividers when necessary:</strong> add them when it helps users understand a meaningful distinction
between groups of options.
</DxcBulletedList.Item>
</DxcBulletedList>
),
},
Expand Down
3 changes: 3 additions & 0 deletions packages/lib/src/dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const defaultOptions: Option[] = [
{
value: "3",
label: "Apple",
hasDivider: true,
},
{
value: "4",
Expand All @@ -56,6 +57,7 @@ const defaultOptions: Option[] = [
{
value: "5",
label: "Aliexpress",
hasDivider: true,
},
{
value: "6",
Expand All @@ -78,6 +80,7 @@ const options: Option[] = [
{
value: "2",
label: "Ebay",
hasDivider: true,
},
{
value: "3",
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/dropdown/Dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const options = [
{
value: "2",
label: "Ebay",
hasDivider: true,
},
{
value: "3",
Expand Down
20 changes: 12 additions & 8 deletions packages/lib/src/dropdown/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DropdownMenuItem from "./DropdownMenuItem";
import { DropdownMenuProps } from "./types";
import scrollbarStyles from "../styles/scroll";
import DxcBleed from "../bleed/Bleed";
import DxcDivider from "../divider/Divider";

const DropdownMenuContainer = styled.ul`
max-height: 230px;
Expand Down Expand Up @@ -35,14 +36,17 @@ const DropdownMenu = forwardRef<HTMLUListElement, DropdownMenuProps>(
style={styles}
>
{options.map((option, index) => (
<DropdownMenuItem
id={`${id}-option-${index}`}
key={`${id}-option-${index}`}
visuallyFocused={index === visualFocusIndex}
iconPosition={iconsPosition}
onClick={menuItemOnClick}
option={option}
/>
<>
<DropdownMenuItem
id={`${id}-option-${index}`}
key={`${id}-option-${option.value}`}
visuallyFocused={index === visualFocusIndex}
iconPosition={iconsPosition}
onClick={menuItemOnClick}
option={option}
/>
{option.hasDivider && <DxcDivider />}
</>
))}
</DropdownMenuContainer>
</DxcBleed>
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/dropdown/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type Option = {
* Option inner value.
*/
value: string;
/**
* Whether the option has a divider below it.
*/
hasDivider?: boolean;
};

type Props = {
Expand Down
Loading