-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathinterfaces.tsx
More file actions
195 lines (179 loc) · 7.96 KB
/
interfaces.tsx
File metadata and controls
195 lines (179 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import { BaseComponentProps } from '../internal/base-component';
import { BaseNavigationDetail, CancelableEventHandler, NonCancelableEventHandler } from '../internal/events';
export interface SideNavigationProps extends BaseComponentProps {
/**
* Controls the header that appears at the top of the navigation component.
*
* It contains the following:
* - `text` (string) - Specifies the header text.
* - `href` (string) - Specifies the `href` that the header links to.
* - `logo` (object) - Specifies a logo image.
*/
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.
*
* `Sections` and `Expandable Page Groups` that contain a highlighted item
* are automatically expanded, unless their definitions have the `defaultExpanded`
* property explicitly set to `false`.
*/
activeHref?: string;
/**
* Specifies the items to be displayed in the navigation.
* Allowed objects are: `Link`, `Divider`, `Section`, `LinkGroup` and `ExpandableLinkGroup`.
*
* You can inject extra properties (for example, an ID)
* in order to identify the item when it's used in an event `detail`
* (for more information, see the events section below).
*
* #### Link
* Object that represents an anchor in the navigation.
* Links are rendered as `<a>` tags.
* - `type` - `'link'`.
* - `text` (string) - Specifies the link text.
* - `href` (string) - Specifies the `href` of the link.
* - `external` (boolean) - Determines whether to display an external link icon next to the link.
* If set to `true`, an external link icon appears next to the link.
* The anchor also has the attributes `target="_blank"` and `rel="noopener"`.
* Additionally, the `activeHref` property won't be modified when a user chooses the link.
* - `externalIconAriaLabel` (string) - Adds an aria-label to the external icon.
* - `info` (ReactNode) - Enables you to display content next to the link. Although it is technically possible to insert any content,
* our UX guidelines allow only to add a Badge and/or a "New" label.
*
* #### Divider
* Object that represents a horizontal divider between navigation content.
* It contains `type`: `'divider'` only.
*
* #### Section
* Object that represents a section within the navigation.
* - `type`: `'section'`.
* - `text` (string) - Specifies the text to display as a title of the section.
* - `defaultExpanded` (boolean) - Determines whether the section should be expanded by default. Default value is `true`.
* - `items` (array) - Specifies the content of the section. You can use any valid item from this list.
* Although there is no technical limitation to the nesting level,
* our UX recommendation is to use only one level.
*
* #### Section Group
* Aggregates a set of items that are conceptually related to each other, and can be displayed under a single heading to provide further organization.
* You can nest sections, links, link groups and expandable link groups within a section group depending on your information architecture needs.
* - `type`: `'section-group'`.
* - `title` (string) - Specifies the text to display as a title of the section group.
* - `items` (array) - Specifies the content of the section header group. You can use `Section`, `Link`, `LinkGroup`, `ExpandableLinkGroup`.
*
* #### LinkGroup
* Object that represents a group of links.
* - `type`: `'link-group'`.
* - `text` (string) - Specifies the text of the group link.
* - `href` (string) - Specifies the `href` of the group link.
* - `info` (ReactNode) - Enables you to display content next to the link. Although it is technically possible to insert any content,
* our UX guidelines allow only to add a Badge and/or a "New" label.
* - `items` (array) - Specifies the content of the section. You can use any valid item from this list.
* Although there is no technical limitation to the nesting level,
* our UX recommendation is to use only one level.
*
* #### ExpandableLinkGroup
*
* Object that represents an expandable group of links.
* - `type`: `'expandable-link-group'`.
* - `text` (string) - Specifies the text of the group link.
* - `href` (string) - Specifies the `href` of the group link.
* - `defaultExpanded` (boolean) - Specifies whether the group should be expanded by default.
* If not explicitly set, the group is collapsed by default, unless one of the nested links is active.
* - `items` (array) - Specifies the content of the section. You can use any valid item from this list.
* Although there is no technical limitation to the nesting level,
* our UX recommendation is to use only one level.
*/
items?: ReadonlyArray<SideNavigationProps.Item>;
/**
* Fired when an anchor is clicked without any modifier (that is, CTRL, ALT, SHIFT).
* The event `detail` contains a definition of the clicked item.
* Use this event to prevent default browser navigation (by calling `preventDefault` method)
* and branch your own routing.
*
* If the event is prevented the `activeHref` property won't be automatically set
* to the href of the clicked item so you'll have to do it yourself.
*/
onFollow?: CancelableEventHandler<SideNavigationProps.FollowDetail>;
/**
* Fired when the expansion state of `Section` or `ExpandablePageGroup` items changes
* as a result of a user interaction. The event `detail` contains an object with information about the changed item.
*
* - `item` (object) - Specifies the item that was changed.
* - `expanded` (boolean) - Specifies whether the item is expanded or not.
* - `expandableParents` (array) - A list of parent items that have a type of `Section`
* or `ExpandablePageGroup`. Use this `expandableParents` array to set their expanded
* state to `true` if you want your data model to keep track of the current state
* of the navigation items.
*
* Note: If the expansion is a result of the activation of a nested link
* upon changing the `activeHref` property, this event isn't raised.
*/
onChange?: NonCancelableEventHandler<SideNavigationProps.ChangeDetail>;
}
export namespace SideNavigationProps {
export interface Logo {
src: string;
alt?: string;
}
export interface Header {
text?: string;
href: string;
logo?: Logo;
}
export interface Divider {
type: 'divider';
}
export interface Link {
type: 'link';
text: string;
href: string;
external?: boolean;
externalIconAriaLabel?: string;
info?: React.ReactNode;
}
export interface Section {
type: 'section';
text: string;
items: ReadonlyArray<Item>;
defaultExpanded?: boolean;
}
export interface SectionGroup {
type: 'section-group';
title: string;
items: ReadonlyArray<Section | Link | LinkGroup | ExpandableLinkGroup>;
}
export interface LinkGroup {
type: 'link-group';
text: string;
href: string;
info?: React.ReactNode;
items: ReadonlyArray<Item>;
}
export interface ExpandableLinkGroup {
type: 'expandable-link-group';
text: string;
href: string;
items: ReadonlyArray<Item>;
defaultExpanded?: boolean;
}
export type Item = Divider | Link | Section | LinkGroup | ExpandableLinkGroup | SectionGroup;
export interface ChangeDetail {
item: Section | ExpandableLinkGroup;
expanded: boolean;
expandableParents: ReadonlyArray<Section | ExpandableLinkGroup>;
}
export interface FollowDetail extends BaseNavigationDetail {
text?: string;
href: string;
type?: 'link' | 'link-group' | 'expandable-link-group' | 'section-header';
info?: React.ReactNode;
}
}