@carbon-labs/react-animated-header 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/es/__stories__/AnimatedHeader.stories.d.ts +466 -544
  2. package/es/__stories__/data/index.d.ts +21 -11
  3. package/es/components/AnimatedHeader/AnimatedHeader.d.ts +30 -17
  4. package/es/components/AnimatedHeader/AnimatedHeader.js +79 -64
  5. package/es/components/Tiles/AIPromptTile/AIPromptTile.d.ts +3 -3
  6. package/es/components/Tiles/AIPromptTile/AIPromptTile.js +7 -5
  7. package/es/components/Tiles/GlassTile/GlassTile.d.ts +3 -3
  8. package/es/components/Tiles/GlassTile/GlassTile.js +4 -4
  9. package/es/node_modules/@carbon/icons-react/es/Icon.js +1 -1
  10. package/lib/__stories__/AnimatedHeader.stories.d.ts +466 -544
  11. package/lib/__stories__/data/index.d.ts +21 -11
  12. package/lib/components/AnimatedHeader/AnimatedHeader.d.ts +30 -17
  13. package/lib/components/AnimatedHeader/AnimatedHeader.js +78 -63
  14. package/lib/components/Tiles/AIPromptTile/AIPromptTile.d.ts +3 -3
  15. package/lib/components/Tiles/AIPromptTile/AIPromptTile.js +7 -5
  16. package/lib/components/Tiles/GlassTile/GlassTile.d.ts +3 -3
  17. package/lib/components/Tiles/GlassTile/GlassTile.js +4 -4
  18. package/lib/node_modules/@carbon/icons-react/es/Icon.js +1 -1
  19. package/package.json +2 -2
  20. package/scss/AnimatedHeader/animated-header.scss +17 -11
  21. package/scss/Tiles/AIPromptTile/ai-prompt-tile.scss +11 -4
  22. package/scss/Tiles/GlassTile/glass-tile.scss +4 -2
  23. /package/es/node_modules/@carbon/{icon-helpers → icons-react/node_modules/@carbon/icon-helpers}/es/index.js +0 -0
  24. /package/lib/node_modules/@carbon/{icon-helpers → icons-react/node_modules/@carbon/icon-helpers}/es/index.js +0 -0
@@ -1,18 +1,10 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright IBM Corp. 2025
5
- *
6
- * This source code is licensed under the Apache-2.0 license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
9
1
  export const workspaceData: {
10
2
  id: string;
11
- text: string;
3
+ label: string;
12
4
  }[];
13
5
  export const headerTiles: ({
14
6
  id: number;
15
- name: string;
7
+ label: string;
16
8
  tiles: ({
17
9
  id: string;
18
10
  href: string;
@@ -28,7 +20,7 @@ export const headerTiles: ({
28
20
  })[];
29
21
  } | {
30
22
  id: number;
31
- name: string;
23
+ label: string;
32
24
  tiles: ({
33
25
  id: string;
34
26
  href: string;
@@ -45,3 +37,21 @@ export const headerTiles: ({
45
37
  subtitle?: undefined;
46
38
  })[];
47
39
  })[];
40
+ export namespace tasksConfigButton {
41
+ let type: string;
42
+ namespace button {
43
+ export let href: string;
44
+ export { Add as icon };
45
+ export let text: string;
46
+ let type_1: "tertiary";
47
+ export { type_1 as type };
48
+ }
49
+ }
50
+ export namespace tasksConfigDropdown {
51
+ let type_2: string;
52
+ export { type_2 as type };
53
+ export namespace dropdown {
54
+ let label: string;
55
+ }
56
+ }
57
+ import { Add } from '@carbon/react/icons';
@@ -1,39 +1,52 @@
1
1
  import React from 'react';
2
2
  import { ButtonKind } from '@carbon/react';
3
3
  /** Animated Header */
4
+ export interface TasksConfig {
5
+ type: 'button' | 'dropdown' | string;
6
+ button?: {
7
+ href?: string;
8
+ icon?: any;
9
+ text?: string;
10
+ type?: ButtonKind;
11
+ };
12
+ dropdown?: {
13
+ label?: string;
14
+ };
15
+ }
4
16
  export interface SelectedWorkspace {
5
17
  id: string;
6
- text: string;
18
+ label: string;
7
19
  }
8
20
  export interface Tile {
9
- id: string;
10
21
  href: string | null;
11
- title: string | null;
12
- subtitle: string | null;
22
+ id: string;
13
23
  mainIcon: string | null;
14
- secondaryIcon: string | null;
24
+ secondaryIcon?: string | null;
25
+ subtitle?: string | null;
26
+ title: string | null;
15
27
  }
16
28
  export interface TileGroup {
17
29
  id: number;
18
- name: string;
30
+ label: string;
19
31
  tiles: Tile[];
20
32
  }
21
33
  export interface AnimatedHeaderProps {
22
- name?: string;
34
+ allTiles: TileGroup[];
35
+ allWorkspaces?: SelectedWorkspace[];
23
36
  description?: string;
24
- buttonText?: string;
25
- buttonType?: ButtonKind;
26
- buttonIcon?: any;
27
- headerDropdown?: boolean;
37
+ handleHeaderItemsToString: (item: TileGroup | null) => string;
38
+ handleWorkspaceItemsToString: (item: SelectedWorkspace | null) => string;
39
+ headerAnimation?: object;
40
+ headerStatic?: React.JSX.Element;
28
41
  productName?: string;
29
- selectedWorkspace?: SelectedWorkspace[] | any;
30
- setSelectedWorkspace: (e: any) => void;
31
- allWorkspaces?: SelectedWorkspace[];
32
42
  selectedTileGroup: TileGroup[] | any;
43
+ selectedWorkspace?: SelectedWorkspace | any;
33
44
  setSelectedTileGroup: (e: any) => void;
34
- allTiles: TileGroup[];
35
- headerAnimation?: object;
36
- headerStatic?: React.JSX.Element;
45
+ setSelectedWorkspace: (e: any) => void;
46
+ tasksConfig?: TasksConfig;
47
+ userName?: string;
48
+ welcomeText?: string;
49
+ workspaceLabel?: string;
37
50
  }
38
51
  declare const AnimatedHeader: React.FC<AnimatedHeaderProps>;
39
52
  export default AnimatedHeader;
@@ -7,7 +7,7 @@
7
7
 
8
8
  import PropTypes from 'prop-types';
9
9
  import React, { useState, useEffect, createRef } from 'react';
10
- import { ButtonKinds, Grid, Column, Tooltip, Button, Dropdown, IconButton } from '@carbon/react';
10
+ import { Grid, Column, Tooltip, Button, Dropdown, IconButton } from '@carbon/react';
11
11
  import lottie from '../../_virtual/lottie.js';
12
12
  import { usePrefix } from '../../node_modules/@carbon-labs/utilities/es/usePrefix.js';
13
13
  import { BaseTile } from '../Tiles/BaseTile/BaseTile.js';
@@ -21,25 +21,26 @@ var _PauseFilled, _PlayFilledAlt;
21
21
 
22
22
  const AnimatedHeader = _ref => {
23
23
  let {
24
- name,
24
+ allTiles,
25
+ allWorkspaces,
25
26
  description,
26
- buttonText,
27
- buttonType = 'tertiary',
28
- buttonIcon = null,
29
- headerDropdown = false,
27
+ handleHeaderItemsToString,
28
+ handleWorkspaceItemsToString,
29
+ headerAnimation,
30
+ headerStatic,
30
31
  productName = '[Product name]',
31
- selectedWorkspace,
32
- setSelectedWorkspace,
33
- allWorkspaces,
34
32
  selectedTileGroup,
33
+ selectedWorkspace,
35
34
  setSelectedTileGroup,
36
- allTiles,
37
- headerAnimation,
38
- headerStatic
35
+ setSelectedWorkspace,
36
+ tasksConfig,
37
+ userName,
38
+ welcomeText,
39
+ workspaceLabel = `Open in: ${userName}'s workspace` || `Select a workspace`
39
40
  } = _ref;
40
41
  const prefix = usePrefix();
41
42
  const blockClass = `${prefix}--animated-header`;
42
- let animationContainer = /*#__PURE__*/createRef();
43
+ const animationContainer = /*#__PURE__*/createRef();
43
44
  const [open, setOpen] = useState(true);
44
45
  const [playing, setPlaying] = useState(true);
45
46
  const [headingTextAnimation, setHeadingTextAnimation] = useState('');
@@ -63,7 +64,7 @@ const AnimatedHeader = _ref => {
63
64
  setPlaying(!playing);
64
65
  };
65
66
  useEffect(() => {
66
- let animation = lottie.loadAnimation({
67
+ const animation = lottie.loadAnimation({
67
68
  container: animationContainer.current,
68
69
  animationData: headerAnimation,
69
70
  renderer: 'svg',
@@ -84,7 +85,7 @@ const AnimatedHeader = _ref => {
84
85
  animation.setSpeed(lottieLoopSpeed);
85
86
  animation.playSegments([animationData.markers.at(1).tm, animationData.op], true);
86
87
  }
87
- if (!!isReduced) {
88
+ if (isReduced) {
88
89
  // reduced motion on
89
90
  animation.addEventListener('DOMLoaded', reducedMotion);
90
91
  } else {
@@ -96,9 +97,15 @@ const AnimatedHeader = _ref => {
96
97
  // Run Looped Animation
97
98
  animation.addEventListener('complete', loop);
98
99
  }
99
- }, []);
100
+ return () => {
101
+ animation?.removeEventListener('DOMLoaded', reducedMotion);
102
+ animation?.removeEventListener('DOMLoaded', load);
103
+ animation?.removeEventListener('complete', loop);
104
+ };
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, [headerAnimation, isReduced]);
100
107
  return /*#__PURE__*/React.createElement("section", {
101
- className: `${blockClass} ${!open && collapsed}`
108
+ className: `${blockClass}${!open ? ` ${collapsed}` : ''}`
102
109
  }, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement("div", {
103
110
  className: `${blockClass}__gradient--overlay`
104
111
  }), /*#__PURE__*/React.createElement("div", {
@@ -121,14 +128,14 @@ const AnimatedHeader = _ref => {
121
128
  lg: 16
122
129
  }, /*#__PURE__*/React.createElement(Tooltip, {
123
130
  align: "bottom",
124
- label: `Welcome, ${name}`
131
+ label: `${welcomeText}, ${userName}`
125
132
  }, /*#__PURE__*/React.createElement("h1", {
126
133
  className: `${blockClass}__heading ${headingTextAnimation}`
127
134
  }, /*#__PURE__*/React.createElement("span", {
128
135
  className: `${blockClass}__heading-welcome`
129
- }, "Welcome,", ' '), /*#__PURE__*/React.createElement("span", {
136
+ }, welcomeText, ",", ' '), /*#__PURE__*/React.createElement("span", {
130
137
  className: `${blockClass}__heading-name`
131
- }, name)))), (description || buttonText || headerDropdown) && /*#__PURE__*/React.createElement(Column, {
138
+ }, userName)))), (description || tasksConfig && tasksConfig.type === 'button' && tasksConfig.button?.text || tasksConfig && tasksConfig.type === 'dropdown' && tasksConfig.dropdown?.label) && /*#__PURE__*/React.createElement(Column, {
132
139
  sm: 4,
133
140
  md: 8,
134
141
  lg: 4,
@@ -138,24 +145,23 @@ const AnimatedHeader = _ref => {
138
145
  label: description
139
146
  }, /*#__PURE__*/React.createElement("h2", {
140
147
  className: `${blockClass}__description`
141
- }, description)), buttonText && /*#__PURE__*/React.createElement(Button, {
148
+ }, description)), tasksConfig?.button?.text && /*#__PURE__*/React.createElement(Button, {
142
149
  className: `${blockClass}__button`,
143
- kind: buttonType,
144
- renderIcon: buttonIcon
145
- }, buttonText), !buttonText && headerDropdown && allTiles && /*#__PURE__*/React.createElement("div", {
150
+ kind: tasksConfig.button.type,
151
+ renderIcon: tasksConfig.button.icon,
152
+ href: tasksConfig.button.href
153
+ }, tasksConfig.button.text), !tasksConfig?.button?.text && tasksConfig && tasksConfig.type === 'dropdown' && allTiles && /*#__PURE__*/React.createElement("div", {
146
154
  className: `${blockClass}__header-dropdown--container`
147
155
  }, /*#__PURE__*/React.createElement(Dropdown, {
148
156
  id: `${blockClass}__header-dropdown`,
149
157
  className: `${blockClass}__header-dropdown`,
150
158
  size: "md",
151
- autoAlign: true,
152
159
  titleText: "Label",
153
- initialSelectedItem: allTiles[0],
154
- label: allTiles[0].name || 'Select an option below',
160
+ label: tasksConfig.dropdown?.label || allTiles[0].label,
155
161
  hideLabel: true,
156
162
  type: "inline",
157
163
  items: allTiles,
158
- itemToString: item => item ? item.name : '',
164
+ itemToString: item => handleHeaderItemsToString(item),
159
165
  onChange: e => setSelectedTileGroup(e)
160
166
  }))), selectedTileGroup && /*#__PURE__*/React.createElement(Column, {
161
167
  sm: 4,
@@ -169,11 +175,11 @@ const AnimatedHeader = _ref => {
169
175
  className: `${blockClass}__workspace`,
170
176
  size: "sm",
171
177
  titleText: "Label",
172
- label: `Open in: ${name}'s workspace` || 'Select a workspace',
178
+ label: workspaceLabel,
173
179
  hideLabel: true,
174
180
  type: "inline",
175
181
  items: allWorkspaces,
176
- itemToString: item => item ? item['text'] : '',
182
+ itemToString: item => handleWorkspaceItemsToString(item),
177
183
  onChange: e => setSelectedWorkspace(e)
178
184
  })), /*#__PURE__*/React.createElement("div", {
179
185
  className: `${blockClass}__tiles-container`
@@ -215,76 +221,85 @@ const AnimatedHeader = _ref => {
215
221
  AnimatedHeader.displayName = 'Animated Header';
216
222
  AnimatedHeader.propTypes = {
217
223
  /**
218
- * Specify an optional className to be added to your Animated Header
224
+ * Array of each tile group setup
219
225
  */
220
- className: PropTypes.string,
226
+ allTiles: PropTypes.arrayOf(PropTypes.object),
221
227
  /**
222
- * Specify the current username of active user
228
+ * Array of all workspace options
223
229
  */
224
- name: PropTypes.string,
230
+ allWorkspaces: PropTypes.arrayOf(PropTypes.object),
231
+ /**
232
+ * Specify an optional className to be added to your Animated Header
233
+ */
234
+ className: PropTypes.string,
225
235
  /**
226
236
  * Provide short sentence in max. 3 lines related to product context
227
237
  */
228
238
  description: PropTypes.string,
229
239
  /**
230
- * (optional), Provide content that needs highest attention from
231
- * the user or content that triggers an action and allow users to
232
- * directly start working and gain value (within one click)
240
+ * Helper function passed to downshift that allows the library to render a
241
+ * given item to a string label. By default, it extracts the `label` field
242
+ * from a given item to serve as the item label in the list. (Dropdown
243
+ * under description in header).
233
244
  */
234
- buttonText: PropTypes.string,
245
+ handleHeaderItemsToString: PropTypes.func,
235
246
  /**
236
- * Specify the carbon button type
247
+ * Helper function passed to downshift that allows the library to render a
248
+ * given item to a string label. By default, it extracts the `label` field
249
+ * from a given item to serve as the item label in the list. (Dropdown
250
+ * related to workspace selection).
237
251
  */
238
- buttonType: ButtonKinds,
252
+ handleWorkspaceItemsToString: PropTypes.func,
239
253
  /**
240
- * (optional), Provide the renderIcon used in the button
241
- * ex. Launch, Add, ect.
254
+ * In-product imagery / lottie animation (.json) dim. 1312 x 738
255
+ * (to update headerAnimation content storybook requires remount in toolbar)
242
256
  */
243
- buttonIcon: PropTypes.any,
257
+ headerAnimation: PropTypes.object,
244
258
  /**
245
- * Header dropdown menu when button/buttonText is not in use
259
+ * In-product imagery / static imagery dim. 1312 x 738
260
+ * Only active when headerAnimation is not in use
246
261
  */
247
- headerDropdown: PropTypes.bool,
262
+ headerStatic: PropTypes.object,
248
263
  /**
249
264
  * Provide current product name
250
265
  */
251
266
  productName: PropTypes.string,
267
+ /**
268
+ * The tile group that is active in the header
269
+ * ex. "AI Chat Tile w/ two glass tiles", "Four glass tiles", ect.
270
+ */
271
+ selectedTileGroup: PropTypes.object,
252
272
  /**
253
273
  * Object containing workspace selection
254
274
  * `Open in: "_"`
255
275
  */
256
276
  selectedWorkspace: PropTypes.object,
257
277
  /**
258
- * Provide function to be called when switching workspace selection
259
- */
260
- setSelectedWorkspace: PropTypes.func,
261
- /**
262
- * Array of all workspace options
278
+ * Provide function to be called when switching selected tile group
263
279
  */
264
- allWorkspaces: PropTypes.arrayOf(PropTypes.object),
280
+ setSelectedTileGroup: PropTypes.func,
265
281
  /**
266
- * The tile group that is active in the header
267
- * ex. "AI Chat Tile w/ two glass tiles", "Four glass tiles", ect.
282
+ * Provide function to be called when switching workspace selection
268
283
  */
269
- selectedTileGroup: PropTypes.object,
284
+ setSelectedWorkspace: PropTypes.func,
270
285
  /**
271
- * Provide function to be called when switching selected tile group
286
+ * Configuration for Carbon button or dropdown menu in header. Customized
287
+ * tasks are used to allow users that have multiple roles and permissions
288
+ * to experience better tailored content based on their need.
272
289
  */
273
- setSelectedTileGroup: PropTypes.func,
290
+ tasksConfig: PropTypes.object,
274
291
  /**
275
- * Array of each tile group setup
292
+ * Specify the current username of active user
276
293
  */
277
- allTiles: PropTypes.arrayOf(PropTypes.object),
294
+ userName: PropTypes.string,
278
295
  /**
279
- * In-product imagery / lottie animation (.json) dim. 1312 x 738
280
- * (to update headerAnimation content storybook requires remount in toolbar)
296
+ * Specify the current welcome text on the header
281
297
  */
282
- headerAnimation: PropTypes.object,
298
+ welcomeText: PropTypes.string,
283
299
  /**
284
- * In-product imagery / static imagery dim. 1312 x 738
285
- * Only active when headerAnimation is not in use
300
+ * Specify the default workspace label above the tiles
286
301
  */
287
- headerStatic: PropTypes.object
302
+ workspaceLabel: PropTypes.string
288
303
  };
289
304
 
290
305
  export { AnimatedHeader as default };
@@ -9,12 +9,12 @@
9
9
  import React from 'react';
10
10
  /** Primary UI component for user interaction */
11
11
  interface AIPromptTileProps {
12
- id?: string;
13
12
  href?: string;
14
- open?: boolean;
13
+ id?: string;
15
14
  mainIcon?: string;
16
- title?: string;
15
+ open?: boolean;
17
16
  productName?: string;
17
+ title?: string;
18
18
  }
19
19
  export declare const AIPromptTile: React.FC<AIPromptTileProps>;
20
20
  export {};
@@ -17,12 +17,12 @@ var _AILabel;
17
17
 
18
18
  const AIPromptTile = _ref => {
19
19
  let {
20
- id,
21
20
  href,
22
- open,
21
+ id,
23
22
  mainIcon,
24
- title,
25
- productName
23
+ open,
24
+ productName,
25
+ title
26
26
  } = _ref;
27
27
  const prefix = usePrefix();
28
28
  const blockClass = `${prefix}--animated-header__ai-prompt-tile`;
@@ -35,7 +35,9 @@ const AIPromptTile = _ref => {
35
35
  };
36
36
  const openInNewTab = url => {
37
37
  const newWindow = window.open(url, '_blank', 'noopener,noreferrer');
38
- if (newWindow) newWindow.opener = null;
38
+ if (newWindow) {
39
+ newWindow.opener = null;
40
+ }
39
41
  };
40
42
  const handleTextInputKeyDown = event => {
41
43
  if (event.key === 'Enter') {
@@ -9,13 +9,13 @@
9
9
  import React from 'react';
10
10
  /** Primary UI component for user interaction */
11
11
  interface GlassTileProps {
12
- id?: string;
13
12
  href?: string;
14
- open?: boolean;
13
+ id?: string;
15
14
  mainIcon?: string;
15
+ open?: boolean;
16
16
  secondaryIcon?: string;
17
- title?: string;
18
17
  subtitle?: string;
18
+ title?: string;
19
19
  }
20
20
  export declare const GlassTile: React.FC<GlassTileProps>;
21
21
  export {};
@@ -14,13 +14,13 @@ import { usePrefix } from '../../../node_modules/@carbon-labs/utilities/es/usePr
14
14
 
15
15
  const GlassTile = _ref => {
16
16
  let {
17
- id,
18
17
  href,
19
- open,
18
+ id,
20
19
  mainIcon,
20
+ open,
21
21
  secondaryIcon,
22
- title,
23
- subtitle
22
+ subtitle,
23
+ title
24
24
  } = _ref;
25
25
  const prefix = usePrefix();
26
26
  const blockClass = `${prefix}--animated-header__glass-tile`;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { getAttributes } from '../../icon-helpers/es/index.js';
8
+ import { getAttributes } from '../node_modules/@carbon/icon-helpers/es/index.js';
9
9
  import PropTypes from 'prop-types';
10
10
  import React from 'react';
11
11