@snack-uikit/accordion 0.10.15 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.11.0 (2025-03-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PDS-1983:** add accordion CollapseBlock onClick ([fff6b98](https://github.com/cloud-ru-tech/snack-uikit/commit/fff6b9859b07ad4deb8dcb07fd99b7ab7c1bd37e))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.10.15 (2025-03-19)
7
18
 
8
19
  ### Only dependencies have been changed
@@ -1,2 +1,2 @@
1
1
  import { CollapseBlockPrimaryProps } from '../../types';
2
- export declare function CollapseBlockPrimary({ id, header, children, actions, className, outline, shape, removeContentFromDOM, ...rest }: CollapseBlockPrimaryProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function CollapseBlockPrimary({ id, header, children, actions, className, outline, shape, removeContentFromDOM, onClick, ...rest }: CollapseBlockPrimaryProps): import("react/jsx-runtime").JSX.Element;
@@ -32,9 +32,10 @@ function CollapseBlockPrimary(_a) {
32
32
  className,
33
33
  outline,
34
34
  shape = 'round',
35
- removeContentFromDOM
35
+ removeContentFromDOM,
36
+ onClick
36
37
  } = _a,
37
- rest = __rest(_a, ["id", "header", "children", "actions", "className", "outline", "shape", "removeContentFromDOM"]);
38
+ rest = __rest(_a, ["id", "header", "children", "actions", "className", "outline", "shape", "removeContentFromDOM", "onClick"]);
38
39
  const {
39
40
  isExpanded,
40
41
  isExpandedDebounced,
@@ -47,6 +48,8 @@ function CollapseBlockPrimary(_a) {
47
48
  }, className),
48
49
  shape: shape,
49
50
  header: (0, jsx_runtime_1.jsx)(helperComponents_1.CollapseBlockHeaderContainer, {
51
+ id: id,
52
+ onClick: onClick,
50
53
  expanded: isExpanded,
51
54
  toggleExpanded: handleToggleExpanded,
52
55
  actions: actions,
@@ -1,2 +1,2 @@
1
1
  import { CollapseBlockSecondaryProps } from '../../types';
2
- export declare function CollapseBlockSecondary({ header, children, id, actions, className, removeContentFromDOM, ...rest }: CollapseBlockSecondaryProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function CollapseBlockSecondary({ header, children, id, actions, className, removeContentFromDOM, onClick, ...rest }: CollapseBlockSecondaryProps): import("react/jsx-runtime").JSX.Element;
@@ -30,9 +30,10 @@ function CollapseBlockSecondary(_a) {
30
30
  id,
31
31
  actions,
32
32
  className,
33
- removeContentFromDOM
33
+ removeContentFromDOM,
34
+ onClick
34
35
  } = _a,
35
- rest = __rest(_a, ["header", "children", "id", "actions", "className", "removeContentFromDOM"]);
36
+ rest = __rest(_a, ["header", "children", "id", "actions", "className", "removeContentFromDOM", "onClick"]);
36
37
  const {
37
38
  isExpanded,
38
39
  isExpandedDebounced,
@@ -41,6 +42,8 @@ function CollapseBlockSecondary(_a) {
41
42
  return (0, jsx_runtime_1.jsx)(helperComponents_1.CollapseBlockPrivate, Object.assign({
42
43
  className: (0, classnames_1.default)(styles_module_scss_1.default.container, className),
43
44
  header: (0, jsx_runtime_1.jsx)(helperComponents_1.CollapseBlockHeaderContainer, {
45
+ id: id,
46
+ onClick: onClick,
44
47
  expanded: isExpanded,
45
48
  toggleExpanded: handleToggleExpanded,
46
49
  actions: actions,
@@ -4,5 +4,7 @@ export type CollapseBlockHeaderContainerProps = {
4
4
  toggleExpanded(expanded: boolean): void;
5
5
  expanded: boolean;
6
6
  actions?: ReactNode;
7
+ id: string;
8
+ onClick?(id: string, expanded: boolean): void;
7
9
  };
8
- export declare function CollapseBlockHeaderContainer({ children, toggleExpanded, expanded, actions, }: CollapseBlockHeaderContainerProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function CollapseBlockHeaderContainer({ id, children, toggleExpanded, expanded, actions, onClick, }: CollapseBlockHeaderContainerProps): import("react/jsx-runtime").JSX.Element;
@@ -18,10 +18,12 @@ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
18
18
  const utils_1 = require("./utils");
19
19
  function CollapseBlockHeaderContainer(_ref) {
20
20
  let {
21
+ id,
21
22
  children,
22
23
  toggleExpanded,
23
24
  expanded,
24
- actions
25
+ actions,
26
+ onClick
25
27
  } = _ref;
26
28
  const functionLayoutRef = (0, react_1.useRef)(null);
27
29
  const [width, setWidth] = (0, react_1.useState)('0px');
@@ -33,7 +35,11 @@ function CollapseBlockHeaderContainer(_ref) {
33
35
  return '0px';
34
36
  });
35
37
  }, [functionLayoutRef]);
36
- const handleToggleExpanded = () => toggleExpanded(!expanded);
38
+ const handleToggleExpanded = () => {
39
+ const newState = !expanded;
40
+ toggleExpanded(newState);
41
+ onClick === null || onClick === void 0 ? void 0 : onClick(id, newState);
42
+ };
37
43
  return (
38
44
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
39
45
  (0, jsx_runtime_1.jsxs)("div", {
@@ -14,6 +14,8 @@ export type CollapseBlockSecondaryProps = WithSupportProps<{
14
14
  className?: string;
15
15
  /** Проп отвечающий будет ли контент удаляться из DOM дерева */
16
16
  removeContentFromDOM?: boolean;
17
+ /** Обработчик клика по хедеру CollapseBlock */
18
+ onClick?(id: string, expanded: boolean): void;
17
19
  }>;
18
20
  export type CollapseBlockPrimaryProps = CollapseBlockSecondaryProps & {
19
21
  /** Внешний бордер */
@@ -1,2 +1,2 @@
1
1
  import { CollapseBlockPrimaryProps } from '../../types';
2
- export declare function CollapseBlockPrimary({ id, header, children, actions, className, outline, shape, removeContentFromDOM, ...rest }: CollapseBlockPrimaryProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function CollapseBlockPrimary({ id, header, children, actions, className, outline, shape, removeContentFromDOM, onClick, ...rest }: CollapseBlockPrimaryProps): import("react/jsx-runtime").JSX.Element;
@@ -16,7 +16,7 @@ import { CollapseBlockHeaderContainer, CollapseBlockPrivate } from '../../helper
16
16
  import { useExpanded } from '../../hooks';
17
17
  import styles from './styles.module.css';
18
18
  export function CollapseBlockPrimary(_a) {
19
- var { id, header, children, actions, className, outline, shape = 'round', removeContentFromDOM } = _a, rest = __rest(_a, ["id", "header", "children", "actions", "className", "outline", "shape", "removeContentFromDOM"]);
19
+ var { id, header, children, actions, className, outline, shape = 'round', removeContentFromDOM, onClick } = _a, rest = __rest(_a, ["id", "header", "children", "actions", "className", "outline", "shape", "removeContentFromDOM", "onClick"]);
20
20
  const { isExpanded, isExpandedDebounced, handleToggleExpanded } = useExpanded(id);
21
- return (_jsx(CollapseBlockPrivate, Object.assign({ className: cn(styles.containerBase, { [styles.container]: !outline, [styles.containerOutline]: outline }, className), shape: shape, header: _jsx(CollapseBlockHeaderContainer, { expanded: isExpanded, toggleExpanded: handleToggleExpanded, actions: actions, children: header }), expanded: isExpanded, expandedDebounced: isExpandedDebounced, removeContentFromDOM: removeContentFromDOM }, extractSupportProps(rest), { children: children })));
21
+ return (_jsx(CollapseBlockPrivate, Object.assign({ className: cn(styles.containerBase, { [styles.container]: !outline, [styles.containerOutline]: outline }, className), shape: shape, header: _jsx(CollapseBlockHeaderContainer, { id: id, onClick: onClick, expanded: isExpanded, toggleExpanded: handleToggleExpanded, actions: actions, children: header }), expanded: isExpanded, expandedDebounced: isExpandedDebounced, removeContentFromDOM: removeContentFromDOM }, extractSupportProps(rest), { children: children })));
22
22
  }
@@ -1,2 +1,2 @@
1
1
  import { CollapseBlockSecondaryProps } from '../../types';
2
- export declare function CollapseBlockSecondary({ header, children, id, actions, className, removeContentFromDOM, ...rest }: CollapseBlockSecondaryProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function CollapseBlockSecondary({ header, children, id, actions, className, removeContentFromDOM, onClick, ...rest }: CollapseBlockSecondaryProps): import("react/jsx-runtime").JSX.Element;
@@ -16,7 +16,7 @@ import { CollapseBlockHeaderContainer, CollapseBlockPrivate } from '../../helper
16
16
  import { useExpanded } from '../../hooks';
17
17
  import styles from './styles.module.css';
18
18
  export function CollapseBlockSecondary(_a) {
19
- var { header, children, id, actions, className, removeContentFromDOM } = _a, rest = __rest(_a, ["header", "children", "id", "actions", "className", "removeContentFromDOM"]);
19
+ var { header, children, id, actions, className, removeContentFromDOM, onClick } = _a, rest = __rest(_a, ["header", "children", "id", "actions", "className", "removeContentFromDOM", "onClick"]);
20
20
  const { isExpanded, isExpandedDebounced, handleToggleExpanded } = useExpanded(id);
21
- return (_jsx(CollapseBlockPrivate, Object.assign({ className: cn(styles.container, className), header: _jsx(CollapseBlockHeaderContainer, { expanded: isExpanded, toggleExpanded: handleToggleExpanded, actions: actions, children: header }), expanded: isExpanded, expandedDebounced: isExpandedDebounced, removeContentFromDOM: removeContentFromDOM }, extractSupportProps(rest), { children: children })));
21
+ return (_jsx(CollapseBlockPrivate, Object.assign({ className: cn(styles.container, className), header: _jsx(CollapseBlockHeaderContainer, { id: id, onClick: onClick, expanded: isExpanded, toggleExpanded: handleToggleExpanded, actions: actions, children: header }), expanded: isExpanded, expandedDebounced: isExpandedDebounced, removeContentFromDOM: removeContentFromDOM }, extractSupportProps(rest), { children: children })));
22
22
  }
@@ -4,5 +4,7 @@ export type CollapseBlockHeaderContainerProps = {
4
4
  toggleExpanded(expanded: boolean): void;
5
5
  expanded: boolean;
6
6
  actions?: ReactNode;
7
+ id: string;
8
+ onClick?(id: string, expanded: boolean): void;
7
9
  };
8
- export declare function CollapseBlockHeaderContainer({ children, toggleExpanded, expanded, actions, }: CollapseBlockHeaderContainerProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function CollapseBlockHeaderContainer({ id, children, toggleExpanded, expanded, actions, onClick, }: CollapseBlockHeaderContainerProps): import("react/jsx-runtime").JSX.Element;
@@ -5,7 +5,7 @@ import { ChevronDownSVG } from '@snack-uikit/icons';
5
5
  import { TEST_IDS } from '../../testIds';
6
6
  import styles from './styles.module.css';
7
7
  import { stopPropagationClick } from './utils';
8
- export function CollapseBlockHeaderContainer({ children, toggleExpanded, expanded, actions, }) {
8
+ export function CollapseBlockHeaderContainer({ id, children, toggleExpanded, expanded, actions, onClick, }) {
9
9
  const functionLayoutRef = useRef(null);
10
10
  const [width, setWidth] = useState('0px');
11
11
  useEffect(() => {
@@ -16,7 +16,11 @@ export function CollapseBlockHeaderContainer({ children, toggleExpanded, expande
16
16
  return '0px';
17
17
  });
18
18
  }, [functionLayoutRef]);
19
- const handleToggleExpanded = () => toggleExpanded(!expanded);
19
+ const handleToggleExpanded = () => {
20
+ const newState = !expanded;
21
+ toggleExpanded(newState);
22
+ onClick === null || onClick === void 0 ? void 0 : onClick(id, newState);
23
+ };
20
24
  return (
21
25
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
22
26
  _jsxs("div", { className: styles.header, "data-test-id": TEST_IDS.header, onClick: handleToggleExpanded, children: [_jsx("div", { className: styles.text, style: { '--width': width }, children: children }), _jsxs("div", { className: styles.functionLayout, ref: functionLayoutRef, onClick: stopPropagationClick, children: [actions, _jsx(ButtonFunction, { className: styles.button, "data-expanded": expanded || undefined, icon: _jsx(ChevronDownSVG, {}), onClick: handleToggleExpanded, size: 'xs', "data-test-id": TEST_IDS.chevron })] })] }));
@@ -14,6 +14,8 @@ export type CollapseBlockSecondaryProps = WithSupportProps<{
14
14
  className?: string;
15
15
  /** Проп отвечающий будет ли контент удаляться из DOM дерева */
16
16
  removeContentFromDOM?: boolean;
17
+ /** Обработчик клика по хедеру CollapseBlock */
18
+ onClick?(id: string, expanded: boolean): void;
17
19
  }>;
18
20
  export type CollapseBlockPrimaryProps = CollapseBlockSecondaryProps & {
19
21
  /** Внешний бордер */
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Accordion",
7
- "version": "0.10.15",
7
+ "version": "0.11.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -49,5 +49,5 @@
49
49
  "devDependencies": {
50
50
  "@types/lodash.debounce": "4.0.8"
51
51
  },
52
- "gitHead": "e14c6ec6fbc59b086b7ed348403eb1bac740b9c3"
52
+ "gitHead": "fd5d0d2178960964555fed3d643c99eaa6686e04"
53
53
  }
@@ -16,6 +16,7 @@ export function CollapseBlockPrimary({
16
16
  outline,
17
17
  shape = 'round',
18
18
  removeContentFromDOM,
19
+ onClick,
19
20
  ...rest
20
21
  }: CollapseBlockPrimaryProps) {
21
22
  const { isExpanded, isExpandedDebounced, handleToggleExpanded } = useExpanded(id);
@@ -29,7 +30,13 @@ export function CollapseBlockPrimary({
29
30
  )}
30
31
  shape={shape}
31
32
  header={
32
- <CollapseBlockHeaderContainer expanded={isExpanded} toggleExpanded={handleToggleExpanded} actions={actions}>
33
+ <CollapseBlockHeaderContainer
34
+ id={id}
35
+ onClick={onClick}
36
+ expanded={isExpanded}
37
+ toggleExpanded={handleToggleExpanded}
38
+ actions={actions}
39
+ >
33
40
  {header}
34
41
  </CollapseBlockHeaderContainer>
35
42
  }
@@ -14,6 +14,7 @@ export function CollapseBlockSecondary({
14
14
  actions,
15
15
  className,
16
16
  removeContentFromDOM,
17
+ onClick,
17
18
  ...rest
18
19
  }: CollapseBlockSecondaryProps) {
19
20
  const { isExpanded, isExpandedDebounced, handleToggleExpanded } = useExpanded(id);
@@ -22,7 +23,13 @@ export function CollapseBlockSecondary({
22
23
  <CollapseBlockPrivate
23
24
  className={cn(styles.container, className)}
24
25
  header={
25
- <CollapseBlockHeaderContainer expanded={isExpanded} toggleExpanded={handleToggleExpanded} actions={actions}>
26
+ <CollapseBlockHeaderContainer
27
+ id={id}
28
+ onClick={onClick}
29
+ expanded={isExpanded}
30
+ toggleExpanded={handleToggleExpanded}
31
+ actions={actions}
32
+ >
26
33
  {header}
27
34
  </CollapseBlockHeaderContainer>
28
35
  }
@@ -12,13 +12,17 @@ export type CollapseBlockHeaderContainerProps = {
12
12
  toggleExpanded(expanded: boolean): void;
13
13
  expanded: boolean;
14
14
  actions?: ReactNode;
15
+ id: string;
16
+ onClick?(id: string, expanded: boolean): void;
15
17
  };
16
18
 
17
19
  export function CollapseBlockHeaderContainer({
20
+ id,
18
21
  children,
19
22
  toggleExpanded,
20
23
  expanded,
21
24
  actions,
25
+ onClick,
22
26
  }: CollapseBlockHeaderContainerProps) {
23
27
  const functionLayoutRef = useRef<HTMLDivElement>(null);
24
28
 
@@ -34,7 +38,11 @@ export function CollapseBlockHeaderContainer({
34
38
  });
35
39
  }, [functionLayoutRef]);
36
40
 
37
- const handleToggleExpanded = () => toggleExpanded(!expanded);
41
+ const handleToggleExpanded = () => {
42
+ const newState = !expanded;
43
+ toggleExpanded(newState);
44
+ onClick?.(id, newState);
45
+ };
38
46
 
39
47
  return (
40
48
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
package/src/types.ts CHANGED
@@ -17,6 +17,8 @@ export type CollapseBlockSecondaryProps = WithSupportProps<{
17
17
  className?: string;
18
18
  /** Проп отвечающий будет ли контент удаляться из DOM дерева */
19
19
  removeContentFromDOM?: boolean;
20
+ /** Обработчик клика по хедеру CollapseBlock */
21
+ onClick?(id: string, expanded: boolean): void;
20
22
  }>;
21
23
 
22
24
  export type CollapseBlockPrimaryProps = CollapseBlockSecondaryProps & {