Skip to content

Commit 505792c

Browse files
committed
feat: Add minimal component skeleton for navigation bar
1 parent 3025360 commit 505792c

8 files changed

Lines changed: 123 additions & 30 deletions

File tree

build-tools/utils/files.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ function writeFile(filepath, content) {
99
}
1010

1111
function listPublicItems(baseDir) {
12-
return fs
13-
.readdirSync(baseDir)
14-
.filter(
15-
elem =>
16-
!elem.startsWith('__') &&
17-
!elem.startsWith('.') &&
18-
elem !== 'internal' &&
19-
elem !== 'index.tsx' &&
20-
elem !== 'index.ts' &&
21-
elem !== 'interfaces.ts' &&
22-
elem !== 'test-utils' &&
23-
elem !== 'i18n' &&
24-
elem !== 'theming' &&
25-
elem !== 'plugins' &&
26-
elem !== 'contexts'
27-
);
12+
return fs.readdirSync(baseDir).filter(
13+
elem =>
14+
!elem.startsWith('__') &&
15+
!elem.startsWith('.') &&
16+
elem !== 'internal' &&
17+
elem !== 'navigation-bar' && // in development, not yet public
18+
elem !== 'index.tsx' &&
19+
elem !== 'index.ts' &&
20+
elem !== 'interfaces.ts' &&
21+
elem !== 'test-utils' &&
22+
elem !== 'i18n' &&
23+
elem !== 'theming' &&
24+
elem !== 'plugins' &&
25+
elem !== 'contexts'
26+
);
2827
}
2928

3029
module.exports = { writeFile, listPublicItems };

build-tools/utils/pluralize.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const pluralizationMap = {
5656
Modal: 'Modals',
5757
Multiselect: 'Multiselects',
5858
NavigableGroup: 'NavigableGroups',
59+
NavigationBar: 'NavigationBars',
5960
Pagination: 'Paginations',
6061
AppLayoutToolbar: 'AppLayoutToolbars',
6162
PanelLayout: 'PanelLayouts',

src/__tests__/utils.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@ const componentsDir = path.resolve(__dirname, '../../lib/components');
1111
const designTokensDir = path.resolve(__dirname, '../../lib/design-tokens');
1212

1313
export function getAllComponents(): string[] {
14-
return fs
15-
.readdirSync(componentsDir)
16-
.filter(
17-
name =>
18-
name !== 'internal' &&
19-
name !== 'test-utils' &&
20-
name !== 'theming' &&
21-
name !== 'contexts' &&
22-
name !== 'plugins' &&
23-
name !== 'i18n' &&
24-
!name.includes('.') &&
25-
!name.includes('LICENSE') &&
26-
!name.includes('NOTICE')
27-
);
14+
return fs.readdirSync(componentsDir).filter(
15+
name =>
16+
name !== 'internal' &&
17+
name !== 'navigation-bar' && // in development, not yet public
18+
name !== 'test-utils' &&
19+
name !== 'theming' &&
20+
name !== 'contexts' &&
21+
name !== 'plugins' &&
22+
name !== 'i18n' &&
23+
!name.includes('.') &&
24+
!name.includes('LICENSE') &&
25+
!name.includes('NOTICE')
26+
);
2827
}
2928

3029
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import React from 'react';
4+
import { render } from '@testing-library/react';
5+
6+
import NavigationBar from '../../../lib/components/navigation-bar';
7+
8+
describe('NavigationBar', () => {
9+
test('renders content', () => {
10+
const { container } = render(<NavigationBar content={<span>Hello</span>} />);
11+
expect(container.querySelector('nav')).toHaveTextContent('Hello');
12+
});
13+
});

src/navigation-bar/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
'use client';
4+
import React from 'react';
5+
6+
import useBaseComponent from '../internal/hooks/use-base-component';
7+
import { applyDisplayName } from '../internal/utils/apply-display-name';
8+
import { getExternalProps } from '../internal/utils/external-props';
9+
import { NavigationBarProps } from './interfaces';
10+
import InternalNavigationBar from './internal';
11+
12+
export { NavigationBarProps };
13+
14+
export default function NavigationBar(props: NavigationBarProps) {
15+
const baseComponentProps = useBaseComponent('NavigationBar');
16+
return <InternalNavigationBar {...getExternalProps(props)} {...baseComponentProps} />;
17+
}
18+
19+
applyDisplayName(NavigationBar, 'NavigationBar');

src/navigation-bar/interfaces.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { ReactNode } from 'react';
4+
5+
import { BaseComponentProps } from '../internal/base-component';
6+
7+
export interface NavigationBarProps extends BaseComponentProps {
8+
/**
9+
* Content of the navigation bar.
10+
*/
11+
content?: ReactNode;
12+
13+
/**
14+
* Accessible label for the navigation landmark.
15+
*/
16+
ariaLabel?: string;
17+
}

src/navigation-bar/internal.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import React from 'react';
4+
import clsx from 'clsx';
5+
6+
import { getBaseProps } from '../internal/base-component';
7+
import { InternalBaseComponentProps } from '../internal/hooks/use-base-component';
8+
import { NavigationBarProps } from './interfaces';
9+
10+
import styles from './styles.css.js';
11+
12+
type InternalNavigationBarProps = NavigationBarProps & InternalBaseComponentProps;
13+
14+
export default function InternalNavigationBar({
15+
content,
16+
ariaLabel,
17+
__internalRootRef,
18+
...restProps
19+
}: InternalNavigationBarProps) {
20+
const baseProps = getBaseProps(restProps);
21+
22+
return (
23+
<nav
24+
{...baseProps}
25+
ref={__internalRootRef}
26+
aria-label={ariaLabel}
27+
className={clsx(baseProps.className, styles.root)}
28+
>
29+
{content}
30+
</nav>
31+
);
32+
}

src/navigation-bar/styles.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
@use '../internal/styles' as styles;
7+
8+
.root {
9+
@include styles.styles-reset;
10+
display: flex;
11+
align-items: center;
12+
box-sizing: border-box;
13+
}

0 commit comments

Comments
 (0)