Skip to content

Commit

Permalink
feat: itemsControl property of Side Navigation (#2673)
Browse files Browse the repository at this point in the history
Co-authored-by: ManzuraZakirova <[email protected]>
  • Loading branch information
Manzurka and ManzuraZakirova authored Sep 13, 2024
1 parent 2e32ba3 commit 3b871f2
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pages/side-navigation/app-layout.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';

import AppLayout from '~components/app-layout';
import Badge from '~components/badge';
import Select from '~components/select';
import SideNavigation, { SideNavigationProps } from '~components/side-navigation';

import labels from '../app-layout/utils/labels';
Expand Down Expand Up @@ -102,6 +103,17 @@ const items: SideNavigationProps.Item[] = [
{ type: 'link', text: 'Documentation', href: '#', external: true, externalIconAriaLabel: 'Opens in a new tab' },
];

const itemsControl = (
<Select
options={[
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2' },
]}
selectedOption={{ value: 'option1', label: 'Option 1' }}
onChange={() => null}
/>
);

export default function SideNavigationPage() {
const [open, setOpen] = React.useState(true);

Expand All @@ -125,6 +137,7 @@ export default function SideNavigationPage() {
},
}}
items={items}
itemsControl={itemsControl}
/>
}
content={
Expand Down
8 changes: 7 additions & 1 deletion src/__tests__/__snapshots__/documenter.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14070,7 +14070,13 @@ Object that represents an expandable group of links.
"type": "ReadonlyArray<SideNavigationProps.Item>",
},
],
"regions": Array [],
"regions": Array [
Object {
"description": "A slot located below the header and above the items.",
"isDefault": false,
"name": "itemsControl",
},
],
"releaseStatus": "stable",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ Object {
"awsui_expandable-link-group_l0dv0",
"awsui_header-link_l0dv0",
"awsui_header_l0dv0",
"awsui_items-control_l0dv0",
"awsui_link-active_l0dv0",
"awsui_link_l0dv0",
"awsui_list-variant-root_l0dv0",
Expand Down
15 changes: 15 additions & 0 deletions src/side-navigation/__tests__/side-navigation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as React from 'react';
import { render } from '@testing-library/react';

import Select from '../../../lib/components/select';
import SideNavigation, { SideNavigationProps } from '../../../lib/components/side-navigation';
import createWrapper from '../../../lib/components/test-utils/dom';

Expand Down Expand Up @@ -1219,6 +1220,20 @@ describe('SideNavigation', () => {
expect(logo).toHaveAttribute('alt', 'logo');
});
});

describe('Items Control', () => {
it('renders Select component when provided', () => {
const wrapper = renderSideNavigation({
itemsControl: <Select options={[]} selectedOption={{}} onChange={() => null} />,
});
expect(wrapper.findItemsControl()!.getElement()).toBeInTheDocument();
expect(wrapper.findItemsControl()!.findSelect()?.getElement()).toBeInTheDocument();
});
it('returns null when items control is not provided', () => {
const wrapper = renderSideNavigation({});
expect(wrapper.findItemsControl()).toBeNull();
});
});
});

describe('URL sanitization', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/side-navigation/implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type SideNavigationInternalProps = SideNavigationProps & InternalBaseComp

export function SideNavigationImplementation({
header,
itemsControl,
activeHref,
items = [],
onFollow,
Expand Down Expand Up @@ -68,6 +69,7 @@ export function SideNavigationImplementation({
{header && (
<Header definition={header} activeHref={activeHref} fireChange={onChangeHandler} fireFollow={onFollowHandler} />
)}
{itemsControl && <div className={styles['items-control']}>{itemsControl}</div>}
{items && (
<div className={styles['list-container']}>
<NavigationItemsList
Expand Down
5 changes: 5 additions & 0 deletions src/side-navigation/interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export interface SideNavigationProps extends BaseComponentProps {
*/
header?: SideNavigationProps.Header;

/**
* A slot located below the header and above the items.
**/
itemsControl?: React.ReactNode;

/**
* Specifies the `href` of the currently active link.
* All items within the navigation with a matching `href` are highlighted.
Expand Down
5 changes: 5 additions & 0 deletions src/side-navigation/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
}
}

.items-control {
margin-block-start: awsui.$space-panel-content-top;
padding-inline: awsui.$space-l;
}

.list-container {
margin-block-start: awsui.$space-panel-content-top;
.with-toolbar > & {
Expand Down
4 changes: 4 additions & 0 deletions src/test-utils/dom/side-navigation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class SideNavigationWrapper extends ComponentWrapper {
return this.findByClassName(styles['header-link']);
}

findItemsControl(): ElementWrapper | null {
return this.findByClassName(styles['items-control']);
}

findLinkByHref(href: string): ElementWrapper<HTMLAnchorElement> | null {
return this.find(`.${styles.link}[href="${href}"]`);
}
Expand Down

0 comments on commit 3b871f2

Please sign in to comment.