@carbon-labs/react-animated-header 0.3.0 → 0.4.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 +497 -587
  2. package/es/__stories__/data/index.d.ts +18 -8
  3. package/es/components/AnimatedHeader/AnimatedHeader.d.ts +26 -15
  4. package/es/components/AnimatedHeader/AnimatedHeader.js +63 -65
  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 +497 -587
  11. package/lib/__stories__/data/index.d.ts +18 -8
  12. package/lib/components/AnimatedHeader/AnimatedHeader.d.ts +26 -15
  13. package/lib/components/AnimatedHeader/AnimatedHeader.js +62 -64
  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,11 +1,3 @@
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
3
  text: 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,17 +1,29 @@
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
18
  text: 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;
@@ -19,21 +31,20 @@ export interface TileGroup {
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
+ headerAnimation?: object;
38
+ headerStatic?: React.JSX.Element;
28
39
  productName?: string;
29
- selectedWorkspace?: SelectedWorkspace[] | any;
30
- setSelectedWorkspace: (e: any) => void;
31
- allWorkspaces?: SelectedWorkspace[];
32
40
  selectedTileGroup: TileGroup[] | any;
41
+ selectedWorkspace?: SelectedWorkspace | any;
33
42
  setSelectedTileGroup: (e: any) => void;
34
- allTiles: TileGroup[];
35
- headerAnimation?: object;
36
- headerStatic?: React.JSX.Element;
43
+ setSelectedWorkspace: (e: any) => void;
44
+ tasksConfig?: TasksConfig;
45
+ userName?: string;
46
+ welcomeText?: string;
47
+ workspaceLabel?: string;
37
48
  }
38
49
  declare const AnimatedHeader: React.FC<AnimatedHeaderProps>;
39
50
  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,24 @@ 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
+ headerAnimation,
28
+ headerStatic,
30
29
  productName = '[Product name]',
31
- selectedWorkspace,
32
- setSelectedWorkspace,
33
- allWorkspaces,
34
30
  selectedTileGroup,
31
+ selectedWorkspace,
35
32
  setSelectedTileGroup,
36
- allTiles,
37
- headerAnimation,
38
- headerStatic
33
+ setSelectedWorkspace,
34
+ tasksConfig,
35
+ userName,
36
+ welcomeText,
37
+ workspaceLabel = `Open in: ${userName}'s workspace` || `Select a workspace`
39
38
  } = _ref;
40
39
  const prefix = usePrefix();
41
40
  const blockClass = `${prefix}--animated-header`;
42
- let animationContainer = /*#__PURE__*/createRef();
41
+ const animationContainer = /*#__PURE__*/createRef();
43
42
  const [open, setOpen] = useState(true);
44
43
  const [playing, setPlaying] = useState(true);
45
44
  const [headingTextAnimation, setHeadingTextAnimation] = useState('');
@@ -63,7 +62,7 @@ const AnimatedHeader = _ref => {
63
62
  setPlaying(!playing);
64
63
  };
65
64
  useEffect(() => {
66
- let animation = lottie.loadAnimation({
65
+ const animation = lottie.loadAnimation({
67
66
  container: animationContainer.current,
68
67
  animationData: headerAnimation,
69
68
  renderer: 'svg',
@@ -84,7 +83,7 @@ const AnimatedHeader = _ref => {
84
83
  animation.setSpeed(lottieLoopSpeed);
85
84
  animation.playSegments([animationData.markers.at(1).tm, animationData.op], true);
86
85
  }
87
- if (!!isReduced) {
86
+ if (isReduced) {
88
87
  // reduced motion on
89
88
  animation.addEventListener('DOMLoaded', reducedMotion);
90
89
  } else {
@@ -96,7 +95,12 @@ const AnimatedHeader = _ref => {
96
95
  // Run Looped Animation
97
96
  animation.addEventListener('complete', loop);
98
97
  }
99
- }, []);
98
+ return () => {
99
+ animation?.removeEventListener('DOMLoaded', reducedMotion);
100
+ animation?.removeEventListener('DOMLoaded', load);
101
+ animation?.removeEventListener('complete', loop);
102
+ };
103
+ }, [animationContainer, headerAnimation, isReduced]);
100
104
  return /*#__PURE__*/React.createElement("section", {
101
105
  className: `${blockClass} ${!open && collapsed}`
102
106
  }, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement("div", {
@@ -121,14 +125,14 @@ const AnimatedHeader = _ref => {
121
125
  lg: 16
122
126
  }, /*#__PURE__*/React.createElement(Tooltip, {
123
127
  align: "bottom",
124
- label: `Welcome, ${name}`
128
+ label: `${welcomeText}, ${userName}`
125
129
  }, /*#__PURE__*/React.createElement("h1", {
126
130
  className: `${blockClass}__heading ${headingTextAnimation}`
127
131
  }, /*#__PURE__*/React.createElement("span", {
128
132
  className: `${blockClass}__heading-welcome`
129
- }, "Welcome,", ' '), /*#__PURE__*/React.createElement("span", {
133
+ }, welcomeText, ",", ' '), /*#__PURE__*/React.createElement("span", {
130
134
  className: `${blockClass}__heading-name`
131
- }, name)))), (description || buttonText || headerDropdown) && /*#__PURE__*/React.createElement(Column, {
135
+ }, userName)))), (description || tasksConfig && tasksConfig.type === 'button' && tasksConfig.button?.text || tasksConfig && tasksConfig.type === 'dropdown' && tasksConfig.dropdown?.label) && /*#__PURE__*/React.createElement(Column, {
132
136
  sm: 4,
133
137
  md: 8,
134
138
  lg: 4,
@@ -138,20 +142,19 @@ const AnimatedHeader = _ref => {
138
142
  label: description
139
143
  }, /*#__PURE__*/React.createElement("h2", {
140
144
  className: `${blockClass}__description`
141
- }, description)), buttonText && /*#__PURE__*/React.createElement(Button, {
145
+ }, description)), tasksConfig?.button?.text && /*#__PURE__*/React.createElement(Button, {
142
146
  className: `${blockClass}__button`,
143
- kind: buttonType,
144
- renderIcon: buttonIcon
145
- }, buttonText), !buttonText && headerDropdown && allTiles && /*#__PURE__*/React.createElement("div", {
147
+ kind: tasksConfig.button.type,
148
+ renderIcon: tasksConfig.button.icon,
149
+ href: tasksConfig.button.href
150
+ }, tasksConfig.button.text), !tasksConfig?.button?.text && tasksConfig && tasksConfig.type === 'dropdown' && allTiles && /*#__PURE__*/React.createElement("div", {
146
151
  className: `${blockClass}__header-dropdown--container`
147
152
  }, /*#__PURE__*/React.createElement(Dropdown, {
148
153
  id: `${blockClass}__header-dropdown`,
149
154
  className: `${blockClass}__header-dropdown`,
150
155
  size: "md",
151
- autoAlign: true,
152
156
  titleText: "Label",
153
- initialSelectedItem: allTiles[0],
154
- label: allTiles[0].name || 'Select an option below',
157
+ label: tasksConfig.dropdown?.label || allTiles[0].name,
155
158
  hideLabel: true,
156
159
  type: "inline",
157
160
  items: allTiles,
@@ -169,7 +172,7 @@ const AnimatedHeader = _ref => {
169
172
  className: `${blockClass}__workspace`,
170
173
  size: "sm",
171
174
  titleText: "Label",
172
- label: `Open in: ${name}'s workspace` || 'Select a workspace',
175
+ label: workspaceLabel,
173
176
  hideLabel: true,
174
177
  type: "inline",
175
178
  items: allWorkspaces,
@@ -215,76 +218,71 @@ const AnimatedHeader = _ref => {
215
218
  AnimatedHeader.displayName = 'Animated Header';
216
219
  AnimatedHeader.propTypes = {
217
220
  /**
218
- * Specify an optional className to be added to your Animated Header
219
- */
220
- className: PropTypes.string,
221
- /**
222
- * Specify the current username of active user
221
+ * Array of each tile group setup
223
222
  */
224
- name: PropTypes.string,
223
+ allTiles: PropTypes.arrayOf(PropTypes.object),
225
224
  /**
226
- * Provide short sentence in max. 3 lines related to product context
225
+ * Array of all workspace options
227
226
  */
228
- description: PropTypes.string,
227
+ allWorkspaces: PropTypes.arrayOf(PropTypes.object),
229
228
  /**
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)
229
+ * Specify an optional className to be added to your Animated Header
233
230
  */
234
- buttonText: PropTypes.string,
231
+ className: PropTypes.string,
235
232
  /**
236
- * Specify the carbon button type
233
+ * Provide short sentence in max. 3 lines related to product context
237
234
  */
238
- buttonType: ButtonKinds,
235
+ description: PropTypes.string,
239
236
  /**
240
- * (optional), Provide the renderIcon used in the button
241
- * ex. Launch, Add, ect.
237
+ * In-product imagery / lottie animation (.json) dim. 1312 x 738
238
+ * (to update headerAnimation content storybook requires remount in toolbar)
242
239
  */
243
- buttonIcon: PropTypes.any,
240
+ headerAnimation: PropTypes.object,
244
241
  /**
245
- * Header dropdown menu when button/buttonText is not in use
242
+ * In-product imagery / static imagery dim. 1312 x 738
243
+ * Only active when headerAnimation is not in use
246
244
  */
247
- headerDropdown: PropTypes.bool,
245
+ headerStatic: PropTypes.object,
248
246
  /**
249
247
  * Provide current product name
250
248
  */
251
249
  productName: PropTypes.string,
250
+ /**
251
+ * The tile group that is active in the header
252
+ * ex. "AI Chat Tile w/ two glass tiles", "Four glass tiles", ect.
253
+ */
254
+ selectedTileGroup: PropTypes.object,
252
255
  /**
253
256
  * Object containing workspace selection
254
257
  * `Open in: "_"`
255
258
  */
256
259
  selectedWorkspace: PropTypes.object,
257
260
  /**
258
- * Provide function to be called when switching workspace selection
259
- */
260
- setSelectedWorkspace: PropTypes.func,
261
- /**
262
- * Array of all workspace options
261
+ * Provide function to be called when switching selected tile group
263
262
  */
264
- allWorkspaces: PropTypes.arrayOf(PropTypes.object),
263
+ setSelectedTileGroup: PropTypes.func,
265
264
  /**
266
- * The tile group that is active in the header
267
- * ex. "AI Chat Tile w/ two glass tiles", "Four glass tiles", ect.
265
+ * Provide function to be called when switching workspace selection
268
266
  */
269
- selectedTileGroup: PropTypes.object,
267
+ setSelectedWorkspace: PropTypes.func,
270
268
  /**
271
- * Provide function to be called when switching selected tile group
269
+ * Configuration for Carbon button or dropdown menu in header. Customized
270
+ * tasks are used to allow users that have multiple roles and permissions
271
+ * to experience better tailored content based on their need.
272
272
  */
273
- setSelectedTileGroup: PropTypes.func,
273
+ tasksConfig: PropTypes.object,
274
274
  /**
275
- * Array of each tile group setup
275
+ * Specify the current username of active user
276
276
  */
277
- allTiles: PropTypes.arrayOf(PropTypes.object),
277
+ userName: PropTypes.string,
278
278
  /**
279
- * In-product imagery / lottie animation (.json) dim. 1312 x 738
280
- * (to update headerAnimation content storybook requires remount in toolbar)
279
+ * Specify the current welcome text on the header
281
280
  */
282
- headerAnimation: PropTypes.object,
281
+ welcomeText: PropTypes.string,
283
282
  /**
284
- * In-product imagery / static imagery dim. 1312 x 738
285
- * Only active when headerAnimation is not in use
283
+ * Specify the default workspace label above the tiles
286
284
  */
287
- headerStatic: PropTypes.object
285
+ workspaceLabel: PropTypes.string
288
286
  };
289
287
 
290
288
  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