@hh.ru/magritte-ui-chips 3.0.23

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.
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { CheckableChipProps } from './types';
3
+ declare const CheckableChip: import("react").ForwardRefExoticComponent<CheckableChipProps & import("react").RefAttributes<HTMLLabelElement>>;
4
+ export { CheckableChip };
@@ -0,0 +1,22 @@
1
+ import './index.css';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { forwardRef } from 'react';
4
+ import { useDisabled } from '@hh.ru/magritte-common-use-disabled';
5
+ import { s as styles, C as ChipContent } from './ChipContent-061590dc.js';
6
+ import 'classnames';
7
+ import '@hh.ru/magritte-ui-counter';
8
+ import '@hh.ru/magritte-ui-typography';
9
+
10
+ const STYLE_TO_CSS = {
11
+ neutral: styles.chipStyleNeutral,
12
+ accent: styles.chipStyleAccent,
13
+ };
14
+ const CheckableChipComponent = ({ style = 'neutral', type = 'checkbox', addon, counter, hideLabel, children, disabled, ariaLabel, dataQaWrapper = 'chip', ...inputProps }, ref) => {
15
+ const forceDisabled = useDisabled();
16
+ const isComponentDisabled = disabled || forceDisabled;
17
+ return (jsxs("label", { className: `${styles.chip} ${STYLE_TO_CSS[style]}`, ref: ref, "data-qa": dataQaWrapper, "data-interactive": true, children: [jsx("input", { ...inputProps, type: type, className: styles.input, disabled: isComponentDisabled }), jsx(ChipContent, { counter: counter, addon: addon, ariaLabel: ariaLabel, hideLabel: hideLabel, children: children })] }));
18
+ };
19
+ const CheckableChip = forwardRef(CheckableChipComponent);
20
+
21
+ export { CheckableChip };
22
+ //# sourceMappingURL=CheckableChip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckableChip.js","sources":["../src/CheckableChip.tsx"],"sourcesContent":["import { forwardRef, ForwardedRef } from 'react';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport ChipContent from '@hh.ru/magritte-ui-chips/ChipContent';\nimport { CheckableChipProps } from '@hh.ru/magritte-ui-chips/types';\n\nimport styles from './chips.less';\n\nconst STYLE_TO_CSS = {\n neutral: styles.chipStyleNeutral,\n accent: styles.chipStyleAccent,\n};\n\nconst CheckableChipComponent = (\n {\n style = 'neutral',\n type = 'checkbox',\n addon,\n counter,\n hideLabel,\n children,\n disabled,\n ariaLabel,\n dataQaWrapper = 'chip',\n ...inputProps\n }: CheckableChipProps,\n ref: ForwardedRef<HTMLLabelElement>\n) => {\n const forceDisabled = useDisabled();\n const isComponentDisabled = disabled || forceDisabled;\n\n return (\n <label\n className={`${styles.chip} ${STYLE_TO_CSS[style]}`}\n ref={ref}\n data-qa={dataQaWrapper}\n data-interactive={true}\n >\n <input {...inputProps} type={type} className={styles.input} disabled={isComponentDisabled} />\n <ChipContent counter={counter} addon={addon} ariaLabel={ariaLabel} hideLabel={hideLabel}>\n {children}\n </ChipContent>\n </label>\n );\n};\n\nconst CheckableChip = forwardRef(CheckableChipComponent);\nexport { CheckableChip };\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;AAQA,MAAM,YAAY,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC,gBAAgB;IAChC,MAAM,EAAE,MAAM,CAAC,eAAe;CACjC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAC3B,EACI,KAAK,GAAG,SAAS,EACjB,IAAI,GAAG,UAAU,EACjB,KAAK,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,aAAa,GAAG,MAAM,EACtB,GAAG,UAAU,EACI,EACrB,GAAmC,KACnC;AACA,IAAA,MAAM,aAAa,GAAG,WAAW,EAAE,CAAC;AACpC,IAAA,MAAM,mBAAmB,GAAG,QAAQ,IAAI,aAAa,CAAC;AAEtD,IAAA,QACIA,IAAA,CAAA,OAAA,EAAA,EACI,SAAS,EAAE,CAAG,EAAA,MAAM,CAAC,IAAI,CAAI,CAAA,EAAA,YAAY,CAAC,KAAK,CAAC,CAAE,CAAA,EAClD,GAAG,EAAE,GAAG,EAAA,SAAA,EACC,aAAa,EAAA,kBAAA,EACJ,IAAI,EAAA,QAAA,EAAA,CAEtBC,GAAW,CAAA,OAAA,EAAA,EAAA,GAAA,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAA,CAAI,EAC7FA,GAAA,CAAC,WAAW,EAAA,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAClF,QAAA,EAAA,QAAQ,EACC,CAAA,CAAA,EAAA,CACV,EACV;AACN,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,UAAU,CAAC,sBAAsB;;;;"}
@@ -0,0 +1,22 @@
1
+ import './index.css';
2
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
+ import { cloneElement } from 'react';
4
+ import classnames from 'classnames';
5
+ import { Counter } from '@hh.ru/magritte-ui-counter';
6
+ import { Text } from '@hh.ru/magritte-ui-typography';
7
+
8
+ var styles = {"input":"magritte-input___ctH9G_3-0-23","chip":"magritte-chip___uulZ9_3-0-23","chip-wrapper":"magritte-chip-wrapper___os8tP_3-0-23","chipWrapper":"magritte-chip-wrapper___os8tP_3-0-23","chip-wrapper__disabled":"magritte-chip-wrapper__disabled___mHM6-_3-0-23","chipWrapperDisabled":"magritte-chip-wrapper__disabled___mHM6-_3-0-23","content":"magritte-content___17f1s_3-0-23","content__deletable":"magritte-content__deletable___iqF4W_3-0-23","contentDeletable":"magritte-content__deletable___iqF4W_3-0-23","addon":"magritte-addon___mlwVD_3-0-23","label":"magritte-label___NSEUN_3-0-23","counter":"magritte-counter___X35B-_3-0-23","close":"magritte-close___5I1Fe_3-0-23","chip_style-neutral":"magritte-chip_style-neutral___gELi3_3-0-23","chipStyleNeutral":"magritte-chip_style-neutral___gELi3_3-0-23","chip__checked":"magritte-chip__checked___3GRxf_3-0-23","chipChecked":"magritte-chip__checked___3GRxf_3-0-23","chip__custom":"magritte-chip__custom___mE-pN_3-0-23","chipCustom":"magritte-chip__custom___mE-pN_3-0-23","chip_style-accent":"magritte-chip_style-accent___rD0pt_3-0-23","chipStyleAccent":"magritte-chip_style-accent___rD0pt_3-0-23"};
9
+
10
+ const ChipContent = ({ addon, ariaLabel, hideLabel, onDelete, counter, children }) => {
11
+ const showLabel = !hideLabel && !!children;
12
+ return (jsxs("span", { className: classnames(styles.content, {
13
+ [styles.contentDeletable]: !!onDelete,
14
+ }), children: [addon && (jsx("span", { className: styles.addon, children: cloneElement(addon, {
15
+ 'data-qa': 'chip-addon',
16
+ 'aria-label': ariaLabel,
17
+ 'aria-hidden': showLabel,
18
+ }) })), showLabel && (jsxs(Fragment, { children: [jsx("span", { className: styles.label, children: jsx(Text, { Element: "span", typography: "subtitle-1-semibold", children: children }) }), counter && (jsx("span", { className: styles.counter, children: jsx(Counter, { label: counter, style: "attention", mode: "secondary" }) }))] }))] }));
19
+ };
20
+
21
+ export { ChipContent as C, styles as s };
22
+ //# sourceMappingURL=ChipContent-061590dc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChipContent-061590dc.js","sources":["../src/ChipContent.tsx"],"sourcesContent":["import { cloneElement, FC } from 'react';\nimport classnames from 'classnames';\n\nimport { CustomChipProps } from '@hh.ru/magritte-ui-chips/types';\nimport { Counter } from '@hh.ru/magritte-ui-counter';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './chips.less';\n\ntype ChipContentProps = Pick<\n CustomChipProps,\n 'addon' | 'hideLabel' | 'ariaLabel' | 'counter' | 'onDelete' | 'children'\n>;\n\nconst ChipContent: FC<ChipContentProps> = ({ addon, ariaLabel, hideLabel, onDelete, counter, children }) => {\n const showLabel = !hideLabel && !!children;\n return (\n <span\n className={classnames(styles.content, {\n [styles.contentDeletable]: !!onDelete,\n })}\n >\n {addon && (\n <span className={styles.addon}>\n {cloneElement(addon, {\n 'data-qa': 'chip-addon',\n 'aria-label': ariaLabel,\n 'aria-hidden': showLabel,\n })}\n </span>\n )}\n {showLabel && (\n <>\n <span className={styles.label}>\n <Text Element=\"span\" typography=\"subtitle-1-semibold\">\n {children}\n </Text>\n </span>\n {counter && (\n <span className={styles.counter}>\n <Counter label={counter} style=\"attention\" mode=\"secondary\" />\n </span>\n )}\n </>\n )}\n </span>\n );\n};\n\nexport default ChipContent;\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;;;AAcA,MAAM,WAAW,GAAyB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAI;IACvG,MAAM,SAAS,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,QAAQ,CAAC;IAC3C,QACIA,eACI,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE;AAClC,YAAA,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,CAAC,QAAQ;AACxC,SAAA,CAAC,EAED,QAAA,EAAA,CAAA,KAAK,KACFC,cAAM,SAAS,EAAE,MAAM,CAAC,KAAK,EAAA,QAAA,EACxB,YAAY,CAAC,KAAK,EAAE;AACjB,oBAAA,SAAS,EAAE,YAAY;AACvB,oBAAA,YAAY,EAAE,SAAS;AACvB,oBAAA,aAAa,EAAE,SAAS;AAC3B,iBAAA,CAAC,EACC,CAAA,CACV,EACA,SAAS,KACND,IACI,CAAAE,QAAA,EAAA,EAAA,QAAA,EAAA,CAAAD,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,MAAM,CAAC,KAAK,EAAA,QAAA,EACzBA,GAAC,CAAA,IAAI,EAAC,EAAA,OAAO,EAAC,MAAM,EAAC,UAAU,EAAC,qBAAqB,EAChD,QAAA,EAAA,QAAQ,EACN,CAAA,EAAA,CACJ,EACN,OAAO,KACJA,GAAM,CAAA,MAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,OAAO,EAC3B,QAAA,EAAAA,GAAA,CAAC,OAAO,EAAA,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,WAAW,EAAC,IAAI,EAAC,WAAW,EAAA,CAAG,EAC3D,CAAA,CACV,CACF,EAAA,CAAA,CACN,CACE,EAAA,CAAA,EACT;AACN;;;;"}
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { CustomChipProps } from './types';
3
+ type ChipContentProps = Pick<CustomChipProps, 'addon' | 'hideLabel' | 'ariaLabel' | 'counter' | 'onDelete' | 'children'>;
4
+ declare const ChipContent: FC<ChipContentProps>;
5
+ export default ChipContent;
package/ChipContent.js ADDED
@@ -0,0 +1,8 @@
1
+ import './index.css';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
4
+ import 'classnames';
5
+ import '@hh.ru/magritte-ui-counter';
6
+ import '@hh.ru/magritte-ui-typography';
7
+ export { C as default } from './ChipContent-061590dc.js';
8
+ //# sourceMappingURL=ChipContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChipContent.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,3 @@
1
+ import { PropsWithChildren, FC } from 'react';
2
+ import { ChipsContainerProps } from './src/types';
3
+ export declare const ChipsContainer: FC<PropsWithChildren<ChipsContainerProps>>;
@@ -0,0 +1,59 @@
1
+ import './index.css';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { Children, isValidElement, useRef, useLayoutEffect, cloneElement } from 'react';
4
+ import classnames from 'classnames';
5
+ import { CheckableChip } from './CheckableChip.js';
6
+ import { CustomChip } from './CustomChip.js';
7
+ import { ScrollableContainer, useScrollContext } from '@hh.ru/magritte-ui-scrollable-container';
8
+ import '@hh.ru/magritte-common-use-disabled';
9
+ import './ChipContent-061590dc.js';
10
+ import '@hh.ru/magritte-ui-counter';
11
+ import '@hh.ru/magritte-ui-typography';
12
+ import '@hh.ru/magritte-ui-action';
13
+ import '@hh.ru/magritte-ui-icon/variants/icon';
14
+
15
+ var styles = {"container":"magritte-container___o9zaa_3-0-23","scrollable":"magritte-scrollable___GhecO_3-0-23","item":"magritte-item___LBqGp_3-0-23","nowrap":"magritte-nowrap___ioKUP_3-0-23"};
16
+
17
+ const isValidCheckableChipElement = (child) => isValidElement(child) && child.type === CheckableChip;
18
+ const isValidCustomChipElement = (child) => isValidElement(child) && child.type === CustomChip;
19
+ const ContainerItem = ({ children, }) => {
20
+ const ref = useRef(null);
21
+ const mouseDownRef = useRef(false);
22
+ const { registerItem, removeItem, scrollToItem } = useScrollContext();
23
+ useLayoutEffect(() => {
24
+ registerItem(ref);
25
+ return () => removeItem(ref);
26
+ }, [registerItem, removeItem]);
27
+ const handleClick = (e) => {
28
+ children.props.onClick?.(e);
29
+ scrollToItem(ref);
30
+ mouseDownRef.current = false;
31
+ };
32
+ const handleFocus = (e) => {
33
+ children.props.onFocus?.(e);
34
+ // Проверка нужна для случая, когда клик длинный. Если не проверять, то произойдет скролл
35
+ // и onClick не вызовется, потому что будет mousemove
36
+ if (!mouseDownRef.current) {
37
+ scrollToItem(ref);
38
+ }
39
+ };
40
+ const handleMouseDown = (e) => {
41
+ children.props.onMouseDown?.(e);
42
+ mouseDownRef.current = true;
43
+ };
44
+ return (jsx("div", { ref: ref, className: styles.item, children: cloneElement(children, {
45
+ onClick: handleClick,
46
+ onFocus: handleFocus,
47
+ onMouseDown: handleMouseDown,
48
+ }) }));
49
+ };
50
+ const ChipsContainer = ({ children, noWrap = false, scrollable = false, ...containerProps }) => {
51
+ const filteredChildren = Children.toArray(children).filter((child) => isValidCheckableChipElement(child) || isValidCustomChipElement(child));
52
+ if (!scrollable) {
53
+ return (jsx("div", { className: styles.container, "data-qa": "chips-container", ...containerProps, children: filteredChildren }));
54
+ }
55
+ return (jsx(ScrollableContainer, { disableButtons: !noWrap, "data-qa": "chips-container", ...containerProps, children: jsx("div", { className: classnames(styles.container, styles.scrollable, noWrap && styles.nowrap), children: Children.map(filteredChildren, (child) => (jsx(ContainerItem, { children: child }))) }) }));
56
+ };
57
+
58
+ export { ChipsContainer };
59
+ //# sourceMappingURL=ChipsContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChipsContainer.js","sources":["../src/ChipsContainer.tsx"],"sourcesContent":["import {\n PropsWithChildren,\n FC,\n useLayoutEffect,\n useRef,\n Children,\n cloneElement,\n ReactNode,\n ReactElement,\n isValidElement,\n MouseEventHandler,\n FocusEventHandler,\n} from 'react';\nimport classnames from 'classnames';\n\nimport { CheckableChip } from '@hh.ru/magritte-ui-chips/CheckableChip';\nimport { CustomChip } from '@hh.ru/magritte-ui-chips/CustomChip';\nimport {\n CheckableChipProps,\n ChipsContainerProps,\n CustomChipWithElementProps,\n} from '@hh.ru/magritte-ui-chips/src/types';\nimport { ScrollableContainer, useScrollContext } from '@hh.ru/magritte-ui-scrollable-container';\n\nimport styles from './chips-container.less';\n\nconst isValidCheckableChipElement = (child: ReactNode): child is ReactElement<CheckableChipProps> =>\n isValidElement(child) && child.type === CheckableChip;\n\nconst isValidCustomChipElement = (child: ReactNode): child is ReactElement<CustomChipWithElementProps> =>\n isValidElement(child) && child.type === CustomChip;\n\nconst ContainerItem = ({\n children,\n}: {\n children: ReactElement<CheckableChipProps | CustomChipWithElementProps>;\n}): ReactElement => {\n const ref = useRef<HTMLDivElement>(null);\n const mouseDownRef = useRef(false);\n const { registerItem, removeItem, scrollToItem } = useScrollContext();\n useLayoutEffect(() => {\n registerItem(ref);\n return () => removeItem(ref);\n }, [registerItem, removeItem]);\n\n const handleClick: MouseEventHandler<HTMLElement> = (e) => {\n (children.props.onClick as MouseEventHandler<HTMLElement>)?.(e);\n scrollToItem(ref);\n mouseDownRef.current = false;\n };\n\n const handleFocus: FocusEventHandler<HTMLElement> = (e) => {\n (children.props.onFocus as FocusEventHandler<HTMLElement>)?.(e);\n // Проверка нужна для случая, когда клик длинный. Если не проверять, то произойдет скролл\n // и onClick не вызовется, потому что будет mousemove\n if (!mouseDownRef.current) {\n scrollToItem(ref);\n }\n };\n\n const handleMouseDown: MouseEventHandler<HTMLElement> = (e) => {\n (children.props.onMouseDown as MouseEventHandler<HTMLElement>)?.(e);\n mouseDownRef.current = true;\n };\n\n return (\n <div ref={ref} className={styles.item}>\n {cloneElement(children, {\n onClick: handleClick,\n onFocus: handleFocus,\n onMouseDown: handleMouseDown,\n })}\n </div>\n );\n};\n\nexport const ChipsContainer: FC<PropsWithChildren<ChipsContainerProps>> = ({\n children,\n noWrap = false,\n scrollable = false,\n ...containerProps\n}) => {\n const filteredChildren = Children.toArray(children).filter(\n (child): child is ReactElement<CheckableChipProps> | ReactElement<CustomChipWithElementProps> =>\n isValidCheckableChipElement(child) || isValidCustomChipElement(child)\n );\n\n if (!scrollable) {\n return (\n <div className={styles.container} data-qa=\"chips-container\" {...containerProps}>\n {filteredChildren}\n </div>\n );\n }\n\n return (\n <ScrollableContainer disableButtons={!noWrap} data-qa=\"chips-container\" {...containerProps}>\n <div className={classnames(styles.container, styles.scrollable, noWrap && styles.nowrap)}>\n {Children.map(filteredChildren, (child) => (\n <ContainerItem>{child}</ContainerItem>\n ))}\n </div>\n </ScrollableContainer>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,2BAA2B,GAAG,CAAC,KAAgB,KACjD,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,CAAC;AAE1D,MAAM,wBAAwB,GAAG,CAAC,KAAgB,KAC9C,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAEvD,MAAM,aAAa,GAAG,CAAC,EACnB,QAAQ,GAGX,KAAkB;AACf,IAAA,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;AACzC,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAA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gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CACtD,CAAC,KAAK,KACF,2BAA2B,CAAC,KAAK,CAAC,IAAI,wBAAwB,CAAC,KAAK,CAAC,CAC5E,CAAC;IAEF,IAAI,CAAC,UAAU,EAAE;AACb,QAAA,QACIA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,SAAS,EAAU,SAAA,EAAA,iBAAiB,KAAK,cAAc,EAAA,QAAA,EACzE,gBAAgB,EAAA,CACf,EACR;AACL,KAAA;IAED,QACIA,GAAC,CAAA,mBAAmB,EAAC,EAAA,cAAc,EAAE,CAAC,MAAM,EAAU,SAAA,EAAA,iBAAiB,EAAK,GAAA,cAAc,YACtFA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,EACnF,QAAA,EAAA,QAAQ,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,KAAK,MAClCA,GAAC,CAAA,aAAa,EAAE,EAAA,QAAA,EAAA,KAAK,EAAiB,CAAA,CACzC,CAAC,EAAA,CACA,EACY,CAAA,EACxB;AACN;;;;"}
@@ -0,0 +1,3 @@
1
+ import { ComponentWithCustomElement } from '@hh.ru/magritte-types';
2
+ import { CustomChipProps } from './types';
3
+ export declare const CustomChip: ComponentWithCustomElement<CustomChipProps, "button">;
package/CustomChip.js ADDED
@@ -0,0 +1,41 @@
1
+ import './index.css';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { forwardRef } from 'react';
4
+ import classnames from 'classnames';
5
+ import { useDisabled } from '@hh.ru/magritte-common-use-disabled';
6
+ import { Action } from '@hh.ru/magritte-ui-action';
7
+ import { s as styles, C as ChipContent } from './ChipContent-061590dc.js';
8
+ import { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/variants/icon';
9
+ import '@hh.ru/magritte-ui-counter';
10
+ import '@hh.ru/magritte-ui-typography';
11
+
12
+ const STYLE_TO_CSS = {
13
+ neutral: styles.chipStyleNeutral,
14
+ accent: styles.chipStyleAccent,
15
+ };
16
+ const CustomChipComponent = ({ Element = 'button', addon, style = 'neutral', counter, onDelete, checked = false, disabled = false, ariaLabel, hideLabel, dataQaWrapper = 'chip', children, ...buttonProps }, ref) => {
17
+ const forceDisabled = useDisabled();
18
+ const isComponentDisabled = disabled || forceDisabled;
19
+ let additionalAttributes;
20
+ if (Element === 'button') {
21
+ additionalAttributes = {
22
+ type: 'button',
23
+ };
24
+ }
25
+ else {
26
+ additionalAttributes = {
27
+ tabIndex: isComponentDisabled ? -1 : 0,
28
+ 'aria-disabled': disabled,
29
+ };
30
+ }
31
+ if (ref) {
32
+ additionalAttributes.ref = ref;
33
+ }
34
+ return (jsxs("div", { className: classnames(styles.chipWrapper, isComponentDisabled && styles.chipWrapperDisabled), "data-qa": dataQaWrapper, children: [jsx(Element, { ...additionalAttributes, ...buttonProps, className: classnames(styles.chip, styles.chipCustom, STYLE_TO_CSS[style], {
35
+ [styles.chipChecked]: checked,
36
+ }), disabled: isComponentDisabled, children: jsx(ChipContent, { counter: counter, onDelete: onDelete, addon: addon, ariaLabel: ariaLabel, hideLabel: hideLabel, children: children }) }), onDelete && (jsx("span", { className: styles.close, children: jsx(Action, { "data-qa": "chip-delete-action", onClick: onDelete, disabled: isComponentDisabled, mode: "secondary", icon: CrossOutlinedSize24 }) }))] }));
37
+ };
38
+ const CustomChip = forwardRef(CustomChipComponent);
39
+
40
+ export { CustomChip };
41
+ //# sourceMappingURL=CustomChip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomChip.js","sources":["../src/CustomChip.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport { ForwardRefRenderFuncWithCustomElement, ComponentWithCustomElement } from '@hh.ru/magritte-types';\nimport { Action } from '@hh.ru/magritte-ui-action';\nimport ChipContent from '@hh.ru/magritte-ui-chips/ChipContent';\nimport { CustomChipProps } from '@hh.ru/magritte-ui-chips/types';\nimport { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/variants/icon';\n\nimport styles from './chips.less';\n\nconst STYLE_TO_CSS = {\n neutral: styles.chipStyleNeutral,\n accent: styles.chipStyleAccent,\n};\n\nconst CustomChipComponent: ForwardRefRenderFuncWithCustomElement<CustomChipProps, 'button'> = (\n {\n Element = 'button',\n addon,\n style = 'neutral',\n counter,\n onDelete,\n checked = false,\n disabled = false,\n ariaLabel,\n hideLabel,\n dataQaWrapper = 'chip',\n children,\n ...buttonProps\n },\n ref\n) => {\n const forceDisabled = useDisabled();\n const isComponentDisabled = disabled || forceDisabled;\n\n let additionalAttributes: Record<string, unknown>;\n\n if (Element === 'button') {\n additionalAttributes = {\n type: 'button',\n };\n } else {\n additionalAttributes = {\n tabIndex: isComponentDisabled ? -1 : 0,\n 'aria-disabled': disabled,\n };\n }\n\n if (ref) {\n additionalAttributes.ref = ref;\n }\n\n return (\n <div\n className={classnames(styles.chipWrapper, isComponentDisabled && styles.chipWrapperDisabled)}\n data-qa={dataQaWrapper}\n >\n <Element\n {...additionalAttributes}\n {...buttonProps}\n className={classnames(styles.chip, styles.chipCustom, STYLE_TO_CSS[style], {\n [styles.chipChecked]: checked,\n })}\n disabled={isComponentDisabled}\n >\n <ChipContent\n counter={counter}\n onDelete={onDelete}\n addon={addon}\n ariaLabel={ariaLabel}\n hideLabel={hideLabel}\n >\n {children}\n </ChipContent>\n </Element>\n {onDelete && (\n <span className={styles.close}>\n <Action\n data-qa=\"chip-delete-action\"\n onClick={onDelete}\n disabled={isComponentDisabled}\n mode=\"secondary\"\n icon={CrossOutlinedSize24}\n />\n </span>\n )}\n </div>\n );\n};\n\nexport const CustomChip = forwardRef(CustomChipComponent) as ComponentWithCustomElement<CustomChipProps, 'button'>;\n"],"names":["_jsxs","_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