@carbon-labs/react-animated-header 0.36.0 → 0.37.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.
@@ -58,7 +58,9 @@ const AnimatedHeader = ({
58
58
  animRef.current.destroy();
59
59
  animRef.current = null;
60
60
  }
61
- if (!animationContainer.current || !headerAnimation) return;
61
+ if (!animationContainer.current || !headerAnimation) {
62
+ return;
63
+ }
62
64
  const animation = lottie.loadAnimation({
63
65
  container: animationContainer.current,
64
66
  animationData: headerAnimation,
@@ -183,7 +185,7 @@ const AnimatedHeader = ({
183
185
  const legacyId = tile.id; // old configs
184
186
  const resolvedTileId = tileId ?? legacyId;
185
187
  const key = resolvedTileId ?? `tile-${index}`;
186
- const hasAction = tile.href || tile.onClick === 'function';
188
+ const hasAction = tile.href || typeof tile.onClick === 'function';
187
189
  return /*#__PURE__*/React.createElement(BaseTile, _extends({
188
190
  key: key,
189
191
  tileId: resolvedTileId
@@ -7,9 +7,7 @@
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
  import type { BaseTileProps } from '../../components/Tiles/BaseTile/BaseTile';
10
- export type Tile = Omit<BaseTileProps, 'id'> & {
11
- tileId: string;
12
- };
10
+ export type Tile = BaseTileProps;
13
11
  export interface TileGroup {
14
12
  id: number;
15
13
  label: string;
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React, { useMemo } from 'react';
9
+ import React from 'react';
10
10
  import { SkeletonPlaceholder, ContentSwitcher, Switch } from '@carbon/react';
11
11
  import { usePrefix } from '../../node_modules/@carbon-labs/utilities/es/usePrefix.js';
12
12
 
@@ -17,11 +17,8 @@ const ContentSwitcherSelector = ({
17
17
  }) => {
18
18
  const prefix = usePrefix();
19
19
  const blockClass = `${prefix}--animated-header__content-switcher`;
20
- if (!contentSwitcherConfig) return null;
21
- if (isLoading || contentSwitcherConfig.isLoading) {
22
- return /*#__PURE__*/React.createElement(SkeletonPlaceholder, {
23
- className: `${blockClass}-skeleton`
24
- });
20
+ if (!contentSwitcherConfig) {
21
+ return null;
25
22
  }
26
23
  const {
27
24
  items = [],
@@ -34,16 +31,18 @@ const ContentSwitcherSelector = ({
34
31
  } = contentSwitcherConfig;
35
32
  const count = visibleCount === 3 ? 3 : 2;
36
33
  const visibleItems = items.slice(0, count);
34
+ const selectedIndexSafe = Math.min(Math.max(selectedIndex, 0), visibleItems.length - 1);
35
+ if (isLoading || contentSwitcherConfig.isLoading) {
36
+ return /*#__PURE__*/React.createElement(SkeletonPlaceholder, {
37
+ className: `${blockClass}-skeleton`
38
+ });
39
+ }
37
40
  if (visibleItems.length < 2 || visibleItems.length > 3) {
38
41
  if (process.env.NODE_ENV !== 'production') {
39
42
  console.warn('[ContentSwitcherSelector] contentSwitcherConfig.items must contain 2 or 3 items.');
40
43
  }
41
44
  return null;
42
45
  }
43
- const selectedIndexSafe = useMemo(() => {
44
- const idx = typeof selectedIndex === 'number' ? selectedIndex : 0;
45
- return Math.min(Math.max(idx, 0), visibleItems.length - 1);
46
- }, [selectedIndex, visibleItems.length]);
47
46
  return /*#__PURE__*/React.createElement("div", {
48
47
  className: `${blockClass}--container`,
49
48
  "data-expanded": headerExpanded
@@ -25,10 +25,8 @@ export type TasksControllerProps = {
25
25
  tasksControllerConfig?: TasksControllerConfig | null;
26
26
  isLoading?: boolean;
27
27
  allTileGroups?: TileGroup[];
28
- selectedTileGroup?: TileGroup | null;
29
- setSelectedTileGroup?: (group: TileGroup | {
30
- selectedItem: TileGroup;
31
- }) => void;
28
+ selectedTileGroup?: TileGroup;
29
+ setSelectedTileGroup?: (e: any) => void;
32
30
  };
33
31
  declare const TasksController: ({ tasksControllerConfig, isLoading, allTileGroups, selectedTileGroup, setSelectedTileGroup, }: TasksControllerProps) => import("react/jsx-runtime").JSX.Element | null;
34
32
  export default TasksController;
@@ -33,24 +33,11 @@ const TasksController = ({
33
33
  ...dropdownOverrideProps
34
34
  } = tasksControllerConfig?.dropdown?.propsOverrides || {};
35
35
 
36
- /** Early outs */
37
- if (!tasksControllerConfig?.type) return null;
38
- if (isLoading || tasksControllerConfig?.isLoading) {
39
- return /*#__PURE__*/React.createElement(SkeletonPlaceholder, {
40
- className: `${blockClass}__task-controller-skeleton`
41
- });
42
- }
43
-
44
- /** Button mode */
45
- if (tasksControllerConfig?.type === 'button' && tasksControllerConfig?.button?.text) {
46
- return /*#__PURE__*/React.createElement(Button, _extends({
47
- className: `${blockClass}__button${buttonCustomClass ? ` ${buttonCustomClass}` : ''}`
48
- }, buttonOverrideProps), tasksControllerConfig.button.text);
49
- }
50
-
51
36
  /** Build Dropdown props (uses top-level list/selection/setter) */
52
37
  const dropdownProps = useMemo(() => {
53
- if (!allTileGroups?.length) return null;
38
+ if (!allTileGroups?.length) {
39
+ return null;
40
+ }
54
41
  return {
55
42
  id: `${blockClass}__header-dropdown`,
56
43
  className: `${blockClass}__header-dropdown${dropdownCustomClass ? ` ${dropdownCustomClass}` : ''}`,
@@ -74,6 +61,23 @@ const TasksController = ({
74
61
  };
75
62
  }, [allTileGroups, selectedTileGroup, setSelectedTileGroup, blockClass, dropdownCustomClass, dropdownOverrideProps, dropdownCustomOnChange, tasksControllerConfig?.dropdown?.label, tasksControllerConfig?.dropdown?.ariaLabel]);
76
63
 
64
+ /** Early outs */
65
+ if (!tasksControllerConfig?.type) {
66
+ return null;
67
+ }
68
+ if (isLoading || tasksControllerConfig?.isLoading) {
69
+ return /*#__PURE__*/React.createElement(SkeletonPlaceholder, {
70
+ className: `${blockClass}__task-controller-skeleton`
71
+ });
72
+ }
73
+
74
+ /** Button mode */
75
+ if (tasksControllerConfig?.type === 'button' && tasksControllerConfig?.button?.text) {
76
+ return /*#__PURE__*/React.createElement(Button, _extends({
77
+ className: `${blockClass}__button${buttonCustomClass ? ` ${buttonCustomClass}` : ''}`
78
+ }, buttonOverrideProps), tasksControllerConfig.button.text);
79
+ }
80
+
77
81
  /** Dropdown mode */
78
82
  if (tasksControllerConfig?.type === 'dropdown' && dropdownProps) {
79
83
  return /*#__PURE__*/React.createElement("div", {
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import React, { ElementType } from 'react';
10
10
  export type AIPromptTileProps = {
11
- tileId: string | null;
11
+ variant: 'aiPrompt';
12
+ tileId: string;
12
13
  href?: string | null;
13
14
  title?: string | null;
14
15
  disabledTaskLabel?: string | null;
@@ -20,5 +21,5 @@ export type AIPromptTileProps = {
20
21
  open?: boolean;
21
22
  isLoading?: boolean;
22
23
  isDisabled?: boolean;
23
- } & Record<string, unknown>;
24
+ };
24
25
  export declare const AIPromptTile: React.FC<AIPromptTileProps>;
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import React, { ElementType } from 'react';
10
10
  export type AITileProps = {
11
- tileId: string | null;
11
+ variant: 'ai';
12
+ tileId: string;
12
13
  href?: string | null;
13
14
  title?: string | null;
14
15
  subtitle?: string | null;
@@ -21,6 +22,6 @@ export type AITileProps = {
21
22
  open?: boolean;
22
23
  isLoading?: boolean;
23
24
  isDisabled?: boolean;
24
- } & Record<string, unknown>;
25
+ };
25
26
  export declare const AITile: React.FC<AITileProps>;
26
27
  export default AITile;
@@ -12,14 +12,5 @@ import { type AIPromptTileProps } from '../AIPromptTile/AIPromptTile';
12
12
  import { type GlassTileProps } from '../GlassTile/GlassTile';
13
13
  /** Base Tile router */
14
14
  export type TileVariant = 'glass' | 'aiPrompt' | 'ai';
15
- export type BaseTileProps = ({
16
- variant?: 'glass';
17
- } & GlassTileProps) | ({
18
- variant: 'aiPrompt';
19
- } & AIPromptTileProps) | (({
20
- variant: 'ai';
21
- } & AITileProps) & {
22
- id?: string;
23
- tileId?: string | null;
24
- });
15
+ export type BaseTileProps = GlassTileProps | AIPromptTileProps | AITileProps;
25
16
  export declare const BaseTile: React.FC<BaseTileProps>;
@@ -16,7 +16,7 @@ function inferVariant(props) {
16
16
  if (props.variant) {
17
17
  return props.variant;
18
18
  }
19
- if (props.id === 'ai-tile') {
19
+ if (props.tileId === 'ai-tile') {
20
20
  return 'aiPrompt';
21
21
  }
22
22
  return 'glass';
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import React, { ElementType } from 'react';
10
10
  export type GlassTileProps = {
11
- tileId: string | null;
11
+ variant?: 'glass';
12
+ tileId: string;
12
13
  href?: string | null;
13
14
  title?: string | null;
14
15
  subtitle?: string | null;
@@ -21,5 +22,5 @@ export type GlassTileProps = {
21
22
  open?: boolean;
22
23
  isLoading?: boolean;
23
24
  isDisabled?: boolean;
24
- } & Record<string, unknown>;
25
+ };
25
26
  export declare const GlassTile: React.FC<GlassTileProps>;
@@ -62,7 +62,9 @@ const AnimatedHeader = ({
62
62
  animRef.current.destroy();
63
63
  animRef.current = null;
64
64
  }
65
- if (!animationContainer.current || !headerAnimation) return;
65
+ if (!animationContainer.current || !headerAnimation) {
66
+ return;
67
+ }
66
68
  const animation = lottie.default.loadAnimation({
67
69
  container: animationContainer.current,
68
70
  animationData: headerAnimation,
@@ -187,7 +189,7 @@ const AnimatedHeader = ({
187
189
  const legacyId = tile.id; // old configs
188
190
  const resolvedTileId = tileId ?? legacyId;
189
191
  const key = resolvedTileId ?? `tile-${index}`;
190
- const hasAction = tile.href || tile.onClick === 'function';
192
+ const hasAction = tile.href || typeof tile.onClick === 'function';
191
193
  return /*#__PURE__*/React.createElement(BaseTile.BaseTile, _rollupPluginBabelHelpers.extends({
192
194
  key: key,
193
195
  tileId: resolvedTileId
@@ -7,9 +7,7 @@
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
  import type { BaseTileProps } from '../../components/Tiles/BaseTile/BaseTile';
10
- export type Tile = Omit<BaseTileProps, 'id'> & {
11
- tileId: string;
12
- };
10
+ export type Tile = BaseTileProps;
13
11
  export interface TileGroup {
14
12
  id: number;
15
13
  label: string;
@@ -21,11 +21,8 @@ const ContentSwitcherSelector = ({
21
21
  }) => {
22
22
  const prefix = usePrefix.usePrefix();
23
23
  const blockClass = `${prefix}--animated-header__content-switcher`;
24
- if (!contentSwitcherConfig) return null;
25
- if (isLoading || contentSwitcherConfig.isLoading) {
26
- return /*#__PURE__*/React.createElement(react.SkeletonPlaceholder, {
27
- className: `${blockClass}-skeleton`
28
- });
24
+ if (!contentSwitcherConfig) {
25
+ return null;
29
26
  }
30
27
  const {
31
28
  items = [],
@@ -38,16 +35,18 @@ const ContentSwitcherSelector = ({
38
35
  } = contentSwitcherConfig;
39
36
  const count = visibleCount === 3 ? 3 : 2;
40
37
  const visibleItems = items.slice(0, count);
38
+ const selectedIndexSafe = Math.min(Math.max(selectedIndex, 0), visibleItems.length - 1);
39
+ if (isLoading || contentSwitcherConfig.isLoading) {
40
+ return /*#__PURE__*/React.createElement(react.SkeletonPlaceholder, {
41
+ className: `${blockClass}-skeleton`
42
+ });
43
+ }
41
44
  if (visibleItems.length < 2 || visibleItems.length > 3) {
42
45
  if (process.env.NODE_ENV !== 'production') {
43
46
  console.warn('[ContentSwitcherSelector] contentSwitcherConfig.items must contain 2 or 3 items.');
44
47
  }
45
48
  return null;
46
49
  }
47
- const selectedIndexSafe = React.useMemo(() => {
48
- const idx = typeof selectedIndex === 'number' ? selectedIndex : 0;
49
- return Math.min(Math.max(idx, 0), visibleItems.length - 1);
50
- }, [selectedIndex, visibleItems.length]);
51
50
  return /*#__PURE__*/React.createElement("div", {
52
51
  className: `${blockClass}--container`,
53
52
  "data-expanded": headerExpanded
@@ -25,10 +25,8 @@ export type TasksControllerProps = {
25
25
  tasksControllerConfig?: TasksControllerConfig | null;
26
26
  isLoading?: boolean;
27
27
  allTileGroups?: TileGroup[];
28
- selectedTileGroup?: TileGroup | null;
29
- setSelectedTileGroup?: (group: TileGroup | {
30
- selectedItem: TileGroup;
31
- }) => void;
28
+ selectedTileGroup?: TileGroup;
29
+ setSelectedTileGroup?: (e: any) => void;
32
30
  };
33
31
  declare const TasksController: ({ tasksControllerConfig, isLoading, allTileGroups, selectedTileGroup, setSelectedTileGroup, }: TasksControllerProps) => import("react/jsx-runtime").JSX.Element | null;
34
32
  export default TasksController;
@@ -37,24 +37,11 @@ const TasksController = ({
37
37
  ...dropdownOverrideProps
38
38
  } = tasksControllerConfig?.dropdown?.propsOverrides || {};
39
39
 
40
- /** Early outs */
41
- if (!tasksControllerConfig?.type) return null;
42
- if (isLoading || tasksControllerConfig?.isLoading) {
43
- return /*#__PURE__*/React.createElement(react.SkeletonPlaceholder, {
44
- className: `${blockClass}__task-controller-skeleton`
45
- });
46
- }
47
-
48
- /** Button mode */
49
- if (tasksControllerConfig?.type === 'button' && tasksControllerConfig?.button?.text) {
50
- return /*#__PURE__*/React.createElement(react.Button, _rollupPluginBabelHelpers.extends({
51
- className: `${blockClass}__button${buttonCustomClass ? ` ${buttonCustomClass}` : ''}`
52
- }, buttonOverrideProps), tasksControllerConfig.button.text);
53
- }
54
-
55
40
  /** Build Dropdown props (uses top-level list/selection/setter) */
56
41
  const dropdownProps = React.useMemo(() => {
57
- if (!allTileGroups?.length) return null;
42
+ if (!allTileGroups?.length) {
43
+ return null;
44
+ }
58
45
  return {
59
46
  id: `${blockClass}__header-dropdown`,
60
47
  className: `${blockClass}__header-dropdown${dropdownCustomClass ? ` ${dropdownCustomClass}` : ''}`,
@@ -78,6 +65,23 @@ const TasksController = ({
78
65
  };
79
66
  }, [allTileGroups, selectedTileGroup, setSelectedTileGroup, blockClass, dropdownCustomClass, dropdownOverrideProps, dropdownCustomOnChange, tasksControllerConfig?.dropdown?.label, tasksControllerConfig?.dropdown?.ariaLabel]);
80
67
 
68
+ /** Early outs */
69
+ if (!tasksControllerConfig?.type) {
70
+ return null;
71
+ }
72
+ if (isLoading || tasksControllerConfig?.isLoading) {
73
+ return /*#__PURE__*/React.createElement(react.SkeletonPlaceholder, {
74
+ className: `${blockClass}__task-controller-skeleton`
75
+ });
76
+ }
77
+
78
+ /** Button mode */
79
+ if (tasksControllerConfig?.type === 'button' && tasksControllerConfig?.button?.text) {
80
+ return /*#__PURE__*/React.createElement(react.Button, _rollupPluginBabelHelpers.extends({
81
+ className: `${blockClass}__button${buttonCustomClass ? ` ${buttonCustomClass}` : ''}`
82
+ }, buttonOverrideProps), tasksControllerConfig.button.text);
83
+ }
84
+
81
85
  /** Dropdown mode */
82
86
  if (tasksControllerConfig?.type === 'dropdown' && dropdownProps) {
83
87
  return /*#__PURE__*/React.createElement("div", {
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import React, { ElementType } from 'react';
10
10
  export type AIPromptTileProps = {
11
- tileId: string | null;
11
+ variant: 'aiPrompt';
12
+ tileId: string;
12
13
  href?: string | null;
13
14
  title?: string | null;
14
15
  disabledTaskLabel?: string | null;
@@ -20,5 +21,5 @@ export type AIPromptTileProps = {
20
21
  open?: boolean;
21
22
  isLoading?: boolean;
22
23
  isDisabled?: boolean;
23
- } & Record<string, unknown>;
24
+ };
24
25
  export declare const AIPromptTile: React.FC<AIPromptTileProps>;
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import React, { ElementType } from 'react';
10
10
  export type AITileProps = {
11
- tileId: string | null;
11
+ variant: 'ai';
12
+ tileId: string;
12
13
  href?: string | null;
13
14
  title?: string | null;
14
15
  subtitle?: string | null;
@@ -21,6 +22,6 @@ export type AITileProps = {
21
22
  open?: boolean;
22
23
  isLoading?: boolean;
23
24
  isDisabled?: boolean;
24
- } & Record<string, unknown>;
25
+ };
25
26
  export declare const AITile: React.FC<AITileProps>;
26
27
  export default AITile;
@@ -12,14 +12,5 @@ import { type AIPromptTileProps } from '../AIPromptTile/AIPromptTile';
12
12
  import { type GlassTileProps } from '../GlassTile/GlassTile';
13
13
  /** Base Tile router */
14
14
  export type TileVariant = 'glass' | 'aiPrompt' | 'ai';
15
- export type BaseTileProps = ({
16
- variant?: 'glass';
17
- } & GlassTileProps) | ({
18
- variant: 'aiPrompt';
19
- } & AIPromptTileProps) | (({
20
- variant: 'ai';
21
- } & AITileProps) & {
22
- id?: string;
23
- tileId?: string | null;
24
- });
15
+ export type BaseTileProps = GlassTileProps | AIPromptTileProps | AITileProps;
25
16
  export declare const BaseTile: React.FC<BaseTileProps>;
@@ -18,7 +18,7 @@ function inferVariant(props) {
18
18
  if (props.variant) {
19
19
  return props.variant;
20
20
  }
21
- if (props.id === 'ai-tile') {
21
+ if (props.tileId === 'ai-tile') {
22
22
  return 'aiPrompt';
23
23
  }
24
24
  return 'glass';
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import React, { ElementType } from 'react';
10
10
  export type GlassTileProps = {
11
- tileId: string | null;
11
+ variant?: 'glass';
12
+ tileId: string;
12
13
  href?: string | null;
13
14
  title?: string | null;
14
15
  subtitle?: string | null;
@@ -21,5 +22,5 @@ export type GlassTileProps = {
21
22
  open?: boolean;
22
23
  isLoading?: boolean;
23
24
  isDisabled?: boolean;
24
- } & Record<string, unknown>;
25
+ };
25
26
  export declare const GlassTile: React.FC<GlassTileProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbon-labs/react-animated-header",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -45,5 +45,5 @@
45
45
  "devDependencies": {
46
46
  "@carbon-labs/utilities": "canary"
47
47
  },
48
- "gitHead": "269b91d0aa83d525616e8bc8ea9a36072e097499"
48
+ "gitHead": "864d211894887413eba51fb15c147b1711c83e33"
49
49
  }