@snack-uikit/attachment 0.0.1-preview-1913b436.0 → 0.0.1-preview-d3c8ef06.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 (31) hide show
  1. package/README.md +5 -5
  2. package/dist/components/Attachment/Attachment.d.ts +1 -1
  3. package/dist/components/Attachment/Attachment.js +3 -3
  4. package/dist/components/Attachment/components/Emblem/Emblem.d.ts +2 -2
  5. package/dist/components/Attachment/components/Emblem/Emblem.js +2 -2
  6. package/dist/components/AttachmentSquare/AttachmentSquare.d.ts +1 -1
  7. package/dist/components/AttachmentSquare/AttachmentSquare.js +13 -3
  8. package/dist/components/AttachmentSquare/components/HoverContent/HoverContent.js +3 -3
  9. package/dist/components/AttachmentSquare/components/LoadingContent/LoadingContent.js +3 -1
  10. package/dist/components/AttachmentSquare/components/MainContent/MainContent.d.ts +2 -2
  11. package/dist/components/AttachmentSquare/components/MainContent/MainContent.js +3 -3
  12. package/dist/components/AttachmentSquare/components/styles.module.css +6 -0
  13. package/dist/components/AttachmentSquare/styles.module.css +15 -7
  14. package/dist/contexts.d.ts +6 -0
  15. package/dist/contexts.js +7 -0
  16. package/dist/helperComponents/Actions/Actions.js +18 -8
  17. package/dist/types.d.ts +4 -6
  18. package/package.json +3 -3
  19. package/src/components/Attachment/Attachment.tsx +4 -4
  20. package/src/components/Attachment/components/Emblem/Emblem.tsx +3 -3
  21. package/src/components/AttachmentSquare/AttachmentSquare.tsx +36 -12
  22. package/src/components/AttachmentSquare/components/HoverContent/HoverContent.tsx +4 -3
  23. package/src/components/AttachmentSquare/components/LoadingContent/LoadingContent.tsx +4 -1
  24. package/src/components/AttachmentSquare/components/MainContent/MainContent.tsx +6 -6
  25. package/src/components/AttachmentSquare/components/styles.module.scss +8 -0
  26. package/src/components/AttachmentSquare/styles.module.scss +15 -5
  27. package/src/contexts.ts +14 -0
  28. package/src/helperComponents/Actions/Actions.tsx +28 -9
  29. package/src/types.ts +5 -7
  30. package/dist/helperComponents/Text/styles.module.css +0 -16
  31. package/src/helperComponents/Text/styles.module.scss +0 -24
package/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # Attachment
2
2
 
3
3
  ## Installation
4
+
4
5
  `npm i @snack-uikit/attachment`
5
6
 
6
7
  [Changelog](./CHANGELOG.md)
7
8
 
8
-
9
-
10
9
  [//]: DOCUMENTATION_SECTION_START
11
10
  [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
12
11
  ## AttachmentSquare
@@ -21,7 +20,8 @@
21
20
  | error | `string` | - | Сообщение об ошибке |
22
21
  | truncateVariant | "end" \| "middle" | - | Вариант обрезания строки: <br> - `End` - с конца; <br> - `Middle` - по середине |
23
22
  | loading | `boolean` | - | Управление состоянием загрузки |
24
- | extension2Icon | `Record<string, JSXElementConstructor<{ size?: number; className?: string; }>>` | - | Объект сопоставления расширения файла и отображаемой иконки @defaultIcon FileSVG |
23
+ | extensionToIcon | `Record<string, JSXElementConstructor<{ size?: number; className?: string; }>>` | - | Объект сопоставления расширения файла и отображаемой иконки @defaultIcon FileSVG |
24
+ | size | enum Size: `"s"`, `"m"` | s | Размер |
25
25
  | checked | `boolean` | - | Управление состоянием выбран/не выбран |
26
26
  | disabled | `boolean` | - | Управление состоянием интерактивности |
27
27
  | multipleSelection | `boolean` | - | Отображение галочки для режима массового выделения карточек |
@@ -39,13 +39,13 @@
39
39
  | error | `string` | - | Сообщение об ошибке |
40
40
  | truncateVariant | "end" \| "middle" | - | Вариант обрезания строки: <br> - `End` - с конца; <br> - `Middle` - по середине |
41
41
  | loading | `boolean` | - | Управление состоянием загрузки |
42
- | extension2Icon | `Record<string, JSXElementConstructor<{ size?: number; className?: string; }>>` | - | Объект сопоставления расширения файла и отображаемой иконки @defaultIcon FileSVG |
42
+ | extensionToIcon | `Record<string, JSXElementConstructor<{ size?: number; className?: string; }>>` | - | Объект сопоставления расширения файла и отображаемой иконки @defaultIcon FileSVG |
43
+ | size | enum Size: `"s"`, `"m"` | s | Размер |
43
44
  | checked | `boolean` | - | Управление состоянием выбран/не выбран |
44
45
  | disabled | `boolean` | - | Управление состоянием интерактивности |
45
46
  | multipleSelection | `boolean` | - | Отображение галочки для режима массового выделения карточек |
46
47
  | onClick | `(e: MouseEvent<HTMLDivElement \| HTMLAnchorElement, MouseEvent>) => void` | - | Колбек на клик по карточке |
47
48
  | className | `string` | - | CSS-класс для элемента с контентом |
48
- | size | enum Size: `"s"`, `"m"` | s | Размер |
49
49
 
50
50
 
51
51
  [//]: DOCUMENTATION_SECTION_END
@@ -1,2 +1,2 @@
1
1
  import { AttachmentProps } from '../../types';
2
- export declare function Attachment({ file, loading, extension2Icon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, size, ...rest }: AttachmentProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function Attachment({ file, loading, extensionToIcon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, size, ...rest }: AttachmentProps): import("react/jsx-runtime").JSX.Element;
@@ -16,13 +16,13 @@ import { AttachmentContext } from '../../contexts';
16
16
  import { Actions, TextBlock } from '../../helperComponents';
17
17
  import { getBaseFileName, getFileExtension } from '../../helpers';
18
18
  import { useImage } from '../../hooks';
19
- import { Emblem } from './components/Emblem';
19
+ import { Emblem } from './components';
20
20
  import styles from './styles.module.css';
21
21
  export function Attachment(_a) {
22
- var { file, loading, extension2Icon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, size = 's' } = _a, rest = __rest(_a, ["file", "loading", "extension2Icon", "title", "description", "error", "disabled", "truncateVariant", "checked", "multipleSelection", "onDownload", "onDelete", "onClick", "size"]);
22
+ var { file, loading, extensionToIcon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, size = 's' } = _a, rest = __rest(_a, ["file", "loading", "extensionToIcon", "title", "description", "error", "disabled", "truncateVariant", "checked", "multipleSelection", "onDownload", "onDelete", "onClick", "size"]);
23
23
  const { loading: loadingImage, imageData } = useImage(file);
24
24
  const isLoading = loading || loadingImage;
25
25
  const title = titleProp || getBaseFileName(file === null || file === void 0 ? void 0 : file.name);
26
26
  const description = descriptionProp || getFileExtension(file === null || file === void 0 ? void 0 : file.name);
27
- return (_jsx(Card, Object.assign({}, extractSupportProps(rest), { outline: true, disabled: disabled, checked: checked, multipleSelection: multipleSelection, size: size, onClick: !isLoading && !disabled ? onClick : undefined, header: _jsx(AttachmentContext.Provider, { value: { file, truncateVariant, onDelete, onDownload, disabled, size }, children: _jsxs("div", { className: styles.composition, "data-size": size, children: [_jsx(Emblem, { title: title, loading: isLoading, extension2Icon: extension2Icon, imageData: imageData }), _jsx(TextBlock, { title: title, description: description, error: error }), _jsx(Actions, { hideDownload: isLoading })] }) }) })));
27
+ return (_jsx(Card, Object.assign({}, extractSupportProps(rest), { outline: true, disabled: disabled, checked: checked, multipleSelection: multipleSelection, size: size, onClick: !isLoading && !disabled ? onClick : undefined, header: _jsx(AttachmentContext.Provider, { value: { file, truncateVariant, onDelete, onDownload, disabled, size }, children: _jsxs("div", { className: styles.composition, "data-size": size, children: [_jsx(Emblem, { title: title, loading: isLoading, extensionToIcon: extensionToIcon, imageData: imageData }), _jsx(TextBlock, { title: title, description: description, error: error }), _jsx(Actions, { hideDownload: isLoading || Boolean(error) })] }) }) })));
28
28
  }
@@ -1,5 +1,5 @@
1
1
  import { AttachmentProps } from '../../../../types';
2
2
  export type EmblemProps = {
3
3
  imageData?: string;
4
- } & Pick<AttachmentProps, 'extension2Icon' | 'loading' | 'title'>;
5
- export declare function Emblem({ loading, extension2Icon, imageData, title }: EmblemProps): import("react/jsx-runtime").JSX.Element;
4
+ } & Pick<AttachmentProps, 'extensionToIcon' | 'loading' | 'title'>;
5
+ export declare function Emblem({ loading, extensionToIcon, imageData, title }: EmblemProps): import("react/jsx-runtime").JSX.Element;
@@ -6,7 +6,7 @@ import { Spinner } from '@snack-uikit/loaders';
6
6
  import { useAttachmentContext } from '../../../../contexts';
7
7
  import { getFileExtension } from '../../../../helpers';
8
8
  import styles from './styled.module.css';
9
- export function Emblem({ loading, extension2Icon, imageData, title }) {
9
+ export function Emblem({ loading, extensionToIcon, imageData, title }) {
10
10
  var _a;
11
11
  const { file, size } = useAttachmentContext();
12
12
  const extension = useMemo(() => { var _a; return (_a = getFileExtension(file === null || file === void 0 ? void 0 : file.name)) !== null && _a !== void 0 ? _a : ''; }, [file === null || file === void 0 ? void 0 : file.name]);
@@ -16,5 +16,5 @@ export function Emblem({ loading, extension2Icon, imageData, title }) {
16
16
  if (imageData) {
17
17
  return (_jsx(IconPredefined, { size: size, icon: () => _jsx("img", { src: imageData, alt: title, "data-size": size || undefined, className: styles.img }), decor: false, shape: 'square' }));
18
18
  }
19
- return (_jsx(IconPredefined, { size: size, icon: (_a = extension2Icon === null || extension2Icon === void 0 ? void 0 : extension2Icon[extension]) !== null && _a !== void 0 ? _a : FileSVG, decor: true, appearance: 'neutral', shape: 'square' }));
19
+ return (_jsx(IconPredefined, { size: size, icon: (_a = extensionToIcon === null || extensionToIcon === void 0 ? void 0 : extensionToIcon[extension]) !== null && _a !== void 0 ? _a : FileSVG, decor: true, appearance: 'neutral', shape: 'square' }));
20
20
  }
@@ -1,2 +1,2 @@
1
1
  import { AttachmentSquareProps } from '../../types';
2
- export declare function AttachmentSquare({ file, loading, extension2Icon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, ...rest }: AttachmentSquareProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function AttachmentSquare({ file, loading, extensionToIcon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, size, ...rest }: AttachmentSquareProps): import("react/jsx-runtime").JSX.Element;
@@ -10,18 +10,28 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import cn from 'classnames';
14
+ import { useState } from 'react';
13
15
  import { Card } from '@snack-uikit/card';
14
16
  import { extractSupportProps } from '@snack-uikit/utils';
15
- import { AttachmentContext } from '../../contexts';
17
+ import { AttachmentContext, AttachmentFocusActionsContext } from '../../contexts';
16
18
  import { getBaseFileName, getFileExtension } from '../../helpers';
17
19
  import { useImage } from '../../hooks';
18
20
  import { HoverContent, LoadingContent, MainContent } from './components';
19
21
  import styles from './styles.module.css';
20
22
  export function AttachmentSquare(_a) {
21
- var { file, loading, extension2Icon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick } = _a, rest = __rest(_a, ["file", "loading", "extension2Icon", "title", "description", "error", "disabled", "truncateVariant", "checked", "multipleSelection", "onDownload", "onDelete", "onClick"]);
23
+ var { file, loading, extensionToIcon, title: titleProp, description: descriptionProp, error, disabled, truncateVariant, checked, multipleSelection, onDownload, onDelete, onClick, size = 's' } = _a, rest = __rest(_a, ["file", "loading", "extensionToIcon", "title", "description", "error", "disabled", "truncateVariant", "checked", "multipleSelection", "onDownload", "onDelete", "onClick", "size"]);
22
24
  const { loading: loadingImage, imageData } = useImage(file);
23
25
  const isLoading = loading || loadingImage;
24
26
  const title = titleProp || getBaseFileName(file === null || file === void 0 ? void 0 : file.name);
25
27
  const description = descriptionProp || getFileExtension(file === null || file === void 0 ? void 0 : file.name);
26
- return (_jsx(Card, Object.assign({}, extractSupportProps(rest), { outline: true, disabled: disabled, size: 's', className: styles.wrapper, checked: checked, multipleSelection: multipleSelection, onClick: !isLoading && !disabled ? onClick : undefined, header: _jsxs(AttachmentContext.Provider, { value: { file, truncateVariant, onDelete, onDownload, disabled, size: 's' }, children: [!isLoading && !disabled && (_jsx(MainContent, { title: title, extension2Icon: extension2Icon, imageData: imageData, className: styles.main })), !isLoading && (_jsx(HoverContent, { title: title, description: description, error: error, className: styles.hover })), isLoading && _jsx(LoadingContent, {})] }) })));
28
+ const [hasFocusedActions, setHasFocusedActions] = useState(false);
29
+ return (_jsx(Card, Object.assign({}, extractSupportProps(rest), { outline: true, disabled: disabled, size: size, className: cn(styles.wrapper, {
30
+ [styles.sizeS]: size === 's',
31
+ [styles.sizeM]: size === 'm',
32
+ [styles.hasFocusedActions]: hasFocusedActions,
33
+ }), checked: checked, multipleSelection: multipleSelection, onClick: !isLoading && !disabled ? onClick : undefined, header: _jsx(AttachmentContext.Provider, { value: { file, truncateVariant, onDelete, onDownload, disabled, size }, children: _jsxs(AttachmentFocusActionsContext.Provider, { value: {
34
+ focused: hasFocusedActions,
35
+ setFocused: setHasFocusedActions,
36
+ }, children: [!isLoading && !disabled && !error && (_jsx(MainContent, { title: title, extensionToIcon: extensionToIcon, imageData: imageData, className: styles.main })), !isLoading && (_jsx(HoverContent, { title: title, description: description, error: error, className: styles.hover })), isLoading && _jsx(LoadingContent, {})] }) }) })));
27
37
  }
@@ -4,8 +4,8 @@ import { useAttachmentContext } from '../../../../contexts';
4
4
  import { Actions, TextBlock } from '../../../../helperComponents';
5
5
  import styles from '../styles.module.css';
6
6
  export function HoverContent({ title, description, error, className = '' }) {
7
- const { disabled } = useAttachmentContext();
7
+ const { disabled, size } = useAttachmentContext();
8
8
  return (_jsxs("div", { className: cn(styles.composition, {
9
- [className]: !disabled,
10
- }), children: [_jsx(TextBlock, { title: title, error: error, description: !error ? description : undefined, align: 'center' }), _jsx(Actions, {})] }));
9
+ [className]: !disabled && !error,
10
+ }), "data-size": size, children: [_jsx(TextBlock, { title: title, error: error, description: !error ? description : undefined, align: 'center' }), _jsx(Actions, { hideDownload: Boolean(error) })] }));
11
11
  }
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { IconPredefined } from '@snack-uikit/icon-predefined';
3
3
  import { Spinner } from '@snack-uikit/loaders';
4
+ import { useAttachmentContext } from '../../../../contexts';
4
5
  import { Actions } from '../../../../helperComponents';
5
6
  import styles from '../styles.module.css';
6
7
  export function LoadingContent() {
7
- return (_jsxs("div", { className: styles.composition, children: [_jsx(IconPredefined, { size: 's', icon: () => _jsx(Spinner, { size: 's' }), decor: false, appearance: 'neutral', shape: 'square' }), _jsx(Actions, { hideDownload: true })] }));
8
+ const { size } = useAttachmentContext();
9
+ return (_jsxs("div", { className: styles.composition, "data-size": size, children: [_jsx(IconPredefined, { size: 's', icon: () => _jsx(Spinner, { size: 's' }), decor: false, appearance: 'neutral', shape: 'square' }), _jsx(Actions, { hideDownload: true })] }));
8
10
  }
@@ -1,6 +1,6 @@
1
1
  import { AttachmentProps } from '../../../../types';
2
2
  type MainContentProps = {
3
3
  imageData?: string;
4
- } & Pick<AttachmentProps, 'title' | 'extension2Icon' | 'className'>;
5
- export declare function MainContent({ title, extension2Icon, imageData, className }: MainContentProps): import("react/jsx-runtime").JSX.Element;
4
+ } & Pick<AttachmentProps, 'title' | 'extensionToIcon' | 'className'>;
5
+ export declare function MainContent({ title, extensionToIcon, imageData, className }: MainContentProps): import("react/jsx-runtime").JSX.Element;
6
6
  export {};
@@ -8,12 +8,12 @@ import { useAttachmentContext } from '../../../../contexts';
8
8
  import { TextBlock } from '../../../../helperComponents';
9
9
  import { getFileExtension } from '../../../../helpers';
10
10
  import styles from '../styles.module.css';
11
- export function MainContent({ title, extension2Icon, imageData, className }) {
11
+ export function MainContent({ title, extensionToIcon, imageData, className }) {
12
12
  var _a, _b;
13
- const { file } = useAttachmentContext();
13
+ const { file, size } = useAttachmentContext();
14
14
  const extension = useMemo(() => { var _a; return (_a = getFileExtension(file === null || file === void 0 ? void 0 : file.name)) !== null && _a !== void 0 ? _a : ''; }, [file === null || file === void 0 ? void 0 : file.name]);
15
15
  if (imageData) {
16
16
  return (_jsx("div", { className: cn(styles.composition, className), children: _jsx(Card.Image, { src: imageData, alt: (_a = file === null || file === void 0 ? void 0 : file.name) !== null && _a !== void 0 ? _a : 'file', mode: 'background', hideFading: true }) }));
17
17
  }
18
- return (_jsxs("div", { className: cn(styles.composition, className), children: [_jsx(TextBlock, { title: title, align: 'center' }), _jsx(IconPredefined, { size: 's', icon: (_b = extension2Icon === null || extension2Icon === void 0 ? void 0 : extension2Icon[extension]) !== null && _b !== void 0 ? _b : FileSVG, decor: true, appearance: 'neutral', shape: 'square' })] }));
18
+ return (_jsxs("div", { className: cn(styles.composition, className), "data-size": size, children: [_jsx(TextBlock, { title: title, align: 'center' }), _jsx(IconPredefined, { size: size, icon: (_b = extensionToIcon === null || extensionToIcon === void 0 ? void 0 : extensionToIcon[extension]) !== null && _b !== void 0 ? _b : FileSVG, decor: true, appearance: 'neutral', shape: 'square' })] }));
19
19
  }
@@ -9,4 +9,10 @@
9
9
  margin:calc(0px - var(--dimension-050m, 4px));
10
10
  padding:var(--dimension-050m, 4px);
11
11
  text-align:center;
12
+ }
13
+ .composition[data-size=s]{
14
+ gap:var(--space-attachment-composition-s-gap, 8px);
15
+ }
16
+ .composition[data-size=m]{
17
+ gap:var(--space-attachment-composition-m-gap, 12px);
12
18
  }
@@ -1,16 +1,24 @@
1
- .wrapper{
2
- width:var(--size-attachment-container-square, 80px);
3
- height:var(--size-attachment-container-square, 80px);
1
+ .wrapper.sizeS{
2
+ width:var(--size-attachment-container-square-s, 80px);
3
+ height:var(--size-attachment-container-square-s, 80px);
4
+ }
5
+ .wrapper.sizeM{
6
+ width:var(--size-attachment-container-square-m, 108px);
7
+ height:var(--size-attachment-container-square-m, 108px);
4
8
  }
5
9
  .wrapper .main{
6
10
  display:flex;
7
11
  }
8
12
  .wrapper .hover{
9
- display:none;
13
+ pointer-events:none;
14
+ height:0;
15
+ opacity:0;
10
16
  }
11
- .wrapper:hover .hover, .wrapper:focus-within .hover, .wrapper:focus-visible .hover{
12
- display:flex;
17
+ .wrapper:hover .hover, .wrapper:focus-visible .hover, .wrapper.hasFocusedActions .hover{
18
+ pointer-events:unset;
19
+ height:unset;
20
+ opacity:1;
13
21
  }
14
- .wrapper:hover .main, .wrapper:focus-within .main, .wrapper:focus-visible .main{
22
+ .wrapper:hover .main, .wrapper:focus-visible .main, .wrapper.hasFocusedActions .main{
15
23
  display:none;
16
24
  }
@@ -3,3 +3,9 @@ import { AttachmentProps } from './types';
3
3
  export type AttachmentContextType = Pick<AttachmentProps, 'size' | 'file' | 'truncateVariant' | 'onDownload' | 'onDelete' | 'disabled'>;
4
4
  export declare const AttachmentContext: import("react").Context<AttachmentContextType>;
5
5
  export declare function useAttachmentContext(): AttachmentContextType;
6
+ export type AttachmentFocusActionsContextType = {
7
+ focused: boolean;
8
+ setFocused(focused: boolean): void;
9
+ };
10
+ export declare const AttachmentFocusActionsContext: import("react").Context<AttachmentFocusActionsContextType>;
11
+ export declare function useAttachmentFocusActionsContext(): AttachmentFocusActionsContextType;
package/dist/contexts.js CHANGED
@@ -3,3 +3,10 @@ export const AttachmentContext = createContext({});
3
3
  export function useAttachmentContext() {
4
4
  return useContext(AttachmentContext);
5
5
  }
6
+ export const AttachmentFocusActionsContext = createContext({
7
+ focused: false,
8
+ setFocused: () => { },
9
+ });
10
+ export function useAttachmentFocusActionsContext() {
11
+ return useContext(AttachmentFocusActionsContext);
12
+ }
@@ -1,20 +1,30 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ButtonFunction } from '@snack-uikit/button';
3
3
  import { DownloadSVG, TrashSVG } from '@snack-uikit/icons';
4
- import { useAttachmentContext } from '../../contexts';
4
+ import { useAttachmentContext, useAttachmentFocusActionsContext } from '../../contexts';
5
5
  import styles from './styles.module.css';
6
+ const noop = () => { };
6
7
  export function Actions({ hideDelete, hideDownload }) {
7
8
  const { onDelete, onDownload, file, disabled } = useAttachmentContext();
9
+ const { setFocused = noop } = useAttachmentFocusActionsContext();
8
10
  const showDownload = onDownload && !hideDownload;
9
11
  const showDelete = onDelete && !hideDelete;
12
+ const handleFocus = () => {
13
+ setFocused(true);
14
+ };
15
+ const handleBlur = () => {
16
+ setFocused(false);
17
+ };
18
+ const handleDownload = (e) => {
19
+ onDownload === null || onDownload === void 0 ? void 0 : onDownload(file);
20
+ e.stopPropagation();
21
+ };
22
+ const handleDelete = (e) => {
23
+ onDelete === null || onDelete === void 0 ? void 0 : onDelete(file);
24
+ e.stopPropagation();
25
+ };
10
26
  if (!showDownload && !showDelete) {
11
27
  return null;
12
28
  }
13
- return (_jsxs("div", { className: styles.actions, children: [showDownload && (_jsx(ButtonFunction, { disabled: disabled, size: 'xs', icon: _jsx(DownloadSVG, {}), onClick: e => {
14
- onDownload(file);
15
- e.stopPropagation();
16
- } })), showDelete && (_jsx(ButtonFunction, { disabled: disabled, size: 'xs', icon: _jsx(TrashSVG, {}), onClick: e => {
17
- onDelete(file);
18
- e.stopPropagation();
19
- } }))] }));
29
+ return (_jsxs("div", { className: styles.actions, children: [showDownload && (_jsx(ButtonFunction, { disabled: disabled, size: 'xs', icon: _jsx(DownloadSVG, {}), onClick: handleDownload, onFocus: handleFocus, onBlur: handleBlur })), showDelete && (_jsx(ButtonFunction, { disabled: disabled, size: 'xs', icon: _jsx(TrashSVG, {}), onClick: handleDelete, onFocus: handleFocus, onBlur: handleBlur }))] }));
20
30
  }
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ import { IconPredefinedProps } from '@snack-uikit/icon-predefined';
3
3
  import { TruncateStringProps } from '@snack-uikit/truncate-string';
4
4
  import { WithSupportProps } from '@snack-uikit/utils';
5
5
  export type Size = 's' | 'm';
6
- export type AttachmentCommonProps = WithSupportProps<{
6
+ export type AttachmentProps = WithSupportProps<{
7
7
  /** Файл */
8
8
  file?: File;
9
9
  /** Колбек на клик по кнопке скачивания */
@@ -34,10 +34,8 @@ export type AttachmentCommonProps = WithSupportProps<{
34
34
  * Объект сопоставления расширения файла и отображаемой иконки
35
35
  * @defaultIcon FileSVG
36
36
  */
37
- extension2Icon?: Record<string, IconPredefinedProps['icon']>;
38
- }> & Pick<CardProps, 'checked' | 'disabled' | 'multipleSelection' | 'onClick' | 'className'>;
39
- export type AttachmentSquareProps = AttachmentCommonProps;
40
- export type AttachmentProps = AttachmentCommonProps & {
37
+ extensionToIcon?: Record<string, IconPredefinedProps['icon']>;
41
38
  /** Размер */
42
39
  size?: Size;
43
- };
40
+ }> & Pick<CardProps, 'checked' | 'disabled' | 'multipleSelection' | 'onClick' | 'className'>;
41
+ export type AttachmentSquareProps = AttachmentProps;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Attachment",
7
- "version": "0.0.1-preview-1913b436.0",
7
+ "version": "0.0.1-preview-d3c8ef06.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,7 +33,7 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@snack-uikit/button": "0.17.1",
36
- "@snack-uikit/card": "0.12.13",
36
+ "@snack-uikit/card": "0.12.14-preview-d3c8ef06.0",
37
37
  "@snack-uikit/icon-predefined": "0.5.1",
38
38
  "@snack-uikit/icons": "0.21.0",
39
39
  "@snack-uikit/loaders": "0.5.2",
@@ -41,5 +41,5 @@
41
41
  "@snack-uikit/utils": "3.3.0",
42
42
  "classnames": "2.3.2"
43
43
  },
44
- "gitHead": "4052d521d291e1987c85162369886d8e49b3ef49"
44
+ "gitHead": "93ec1b7cbdd9a002297609c6e4ef3c96ca7178d7"
45
45
  }
@@ -6,13 +6,13 @@ import { Actions, TextBlock } from '../../helperComponents';
6
6
  import { getBaseFileName, getFileExtension } from '../../helpers';
7
7
  import { useImage } from '../../hooks';
8
8
  import { AttachmentProps } from '../../types';
9
- import { Emblem } from './components/Emblem';
9
+ import { Emblem } from './components';
10
10
  import styles from './styles.module.scss';
11
11
 
12
12
  export function Attachment({
13
13
  file,
14
14
  loading,
15
- extension2Icon,
15
+ extensionToIcon,
16
16
  title: titleProp,
17
17
  description: descriptionProp,
18
18
  error,
@@ -44,9 +44,9 @@ export function Attachment({
44
44
  header={
45
45
  <AttachmentContext.Provider value={{ file, truncateVariant, onDelete, onDownload, disabled, size }}>
46
46
  <div className={styles.composition} data-size={size}>
47
- <Emblem title={title} loading={isLoading} extension2Icon={extension2Icon} imageData={imageData} />
47
+ <Emblem title={title} loading={isLoading} extensionToIcon={extensionToIcon} imageData={imageData} />
48
48
  <TextBlock title={title} description={description} error={error} />
49
- <Actions hideDownload={isLoading} />
49
+ <Actions hideDownload={isLoading || Boolean(error)} />
50
50
  </div>
51
51
  </AttachmentContext.Provider>
52
52
  }
@@ -11,9 +11,9 @@ import styles from './styled.module.scss';
11
11
 
12
12
  export type EmblemProps = {
13
13
  imageData?: string;
14
- } & Pick<AttachmentProps, 'extension2Icon' | 'loading' | 'title'>;
14
+ } & Pick<AttachmentProps, 'extensionToIcon' | 'loading' | 'title'>;
15
15
 
16
- export function Emblem({ loading, extension2Icon, imageData, title }: EmblemProps) {
16
+ export function Emblem({ loading, extensionToIcon, imageData, title }: EmblemProps) {
17
17
  const { file, size } = useAttachmentContext();
18
18
 
19
19
  const extension = useMemo(() => getFileExtension(file?.name) ?? '', [file?.name]);
@@ -38,7 +38,7 @@ export function Emblem({ loading, extension2Icon, imageData, title }: EmblemProp
38
38
  return (
39
39
  <IconPredefined
40
40
  size={size}
41
- icon={extension2Icon?.[extension] ?? FileSVG}
41
+ icon={extensionToIcon?.[extension] ?? FileSVG}
42
42
  decor
43
43
  appearance='neutral'
44
44
  shape='square'
@@ -1,7 +1,10 @@
1
+ import cn from 'classnames';
2
+ import { useState } from 'react';
3
+
1
4
  import { Card } from '@snack-uikit/card';
2
5
  import { extractSupportProps } from '@snack-uikit/utils';
3
6
 
4
- import { AttachmentContext } from '../../contexts';
7
+ import { AttachmentContext, AttachmentFocusActionsContext } from '../../contexts';
5
8
  import { getBaseFileName, getFileExtension } from '../../helpers';
6
9
  import { useImage } from '../../hooks';
7
10
  import { AttachmentSquareProps } from '../../types';
@@ -11,7 +14,7 @@ import styles from './styles.module.scss';
11
14
  export function AttachmentSquare({
12
15
  file,
13
16
  loading,
14
- extension2Icon,
17
+ extensionToIcon,
15
18
  title: titleProp,
16
19
  description: descriptionProp,
17
20
  error,
@@ -22,6 +25,7 @@ export function AttachmentSquare({
22
25
  onDownload,
23
26
  onDelete,
24
27
  onClick,
28
+ size = 's',
25
29
  ...rest
26
30
  }: AttachmentSquareProps) {
27
31
  const { loading: loadingImage, imageData } = useImage(file);
@@ -30,25 +34,45 @@ export function AttachmentSquare({
30
34
  const title = titleProp || getBaseFileName(file?.name);
31
35
  const description = descriptionProp || getFileExtension(file?.name);
32
36
 
37
+ const [hasFocusedActions, setHasFocusedActions] = useState<boolean>(false);
38
+
33
39
  return (
34
40
  <Card
35
41
  {...extractSupportProps(rest)}
36
42
  outline
37
43
  disabled={disabled}
38
- size='s'
39
- className={styles.wrapper}
44
+ size={size}
45
+ className={cn(styles.wrapper, {
46
+ [styles.sizeS]: size === 's',
47
+ [styles.sizeM]: size === 'm',
48
+ [styles.hasFocusedActions]: hasFocusedActions,
49
+ })}
40
50
  checked={checked}
41
51
  multipleSelection={multipleSelection}
42
52
  onClick={!isLoading && !disabled ? onClick : undefined}
43
53
  header={
44
- <AttachmentContext.Provider value={{ file, truncateVariant, onDelete, onDownload, disabled, size: 's' }}>
45
- {!isLoading && !disabled && (
46
- <MainContent title={title} extension2Icon={extension2Icon} imageData={imageData} className={styles.main} />
47
- )}
48
- {!isLoading && (
49
- <HoverContent title={title} description={description} error={error} className={styles.hover} />
50
- )}
51
- {isLoading && <LoadingContent />}
54
+ <AttachmentContext.Provider value={{ file, truncateVariant, onDelete, onDownload, disabled, size }}>
55
+ <AttachmentFocusActionsContext.Provider
56
+ value={{
57
+ focused: hasFocusedActions,
58
+ setFocused: setHasFocusedActions,
59
+ }}
60
+ >
61
+ {!isLoading && !disabled && !error && (
62
+ <MainContent
63
+ title={title}
64
+ extensionToIcon={extensionToIcon}
65
+ imageData={imageData}
66
+ className={styles.main}
67
+ />
68
+ )}
69
+
70
+ {!isLoading && (
71
+ <HoverContent title={title} description={description} error={error} className={styles.hover} />
72
+ )}
73
+
74
+ {isLoading && <LoadingContent />}
75
+ </AttachmentFocusActionsContext.Provider>
52
76
  </AttachmentContext.Provider>
53
77
  }
54
78
  />
@@ -8,17 +8,18 @@ import styles from '../styles.module.scss';
8
8
  type HoverContentProps = Pick<AttachmentProps, 'title' | 'description' | 'error' | 'className'>;
9
9
 
10
10
  export function HoverContent({ title, description, error, className = '' }: HoverContentProps) {
11
- const { disabled } = useAttachmentContext();
11
+ const { disabled, size } = useAttachmentContext();
12
12
 
13
13
  return (
14
14
  <div
15
15
  className={cn(styles.composition, {
16
- [className]: !disabled,
16
+ [className]: !disabled && !error,
17
17
  })}
18
+ data-size={size}
18
19
  >
19
20
  <TextBlock title={title} error={error} description={!error ? description : undefined} align='center' />
20
21
 
21
- <Actions />
22
+ <Actions hideDownload={Boolean(error)} />
22
23
  </div>
23
24
  );
24
25
  }
@@ -1,12 +1,15 @@
1
1
  import { IconPredefined } from '@snack-uikit/icon-predefined';
2
2
  import { Spinner } from '@snack-uikit/loaders';
3
3
 
4
+ import { useAttachmentContext } from '../../../../contexts';
4
5
  import { Actions } from '../../../../helperComponents';
5
6
  import styles from '../styles.module.scss';
6
7
 
7
8
  export function LoadingContent() {
9
+ const { size } = useAttachmentContext();
10
+
8
11
  return (
9
- <div className={styles.composition}>
12
+ <div className={styles.composition} data-size={size}>
10
13
  <IconPredefined size='s' icon={() => <Spinner size='s' />} decor={false} appearance='neutral' shape='square' />
11
14
  <Actions hideDownload />
12
15
  </div>
@@ -13,10 +13,10 @@ import styles from '../styles.module.scss';
13
13
 
14
14
  type MainContentProps = {
15
15
  imageData?: string;
16
- } & Pick<AttachmentProps, 'title' | 'extension2Icon' | 'className'>;
16
+ } & Pick<AttachmentProps, 'title' | 'extensionToIcon' | 'className'>;
17
17
 
18
- export function MainContent({ title, extension2Icon, imageData, className }: MainContentProps) {
19
- const { file } = useAttachmentContext();
18
+ export function MainContent({ title, extensionToIcon, imageData, className }: MainContentProps) {
19
+ const { file, size } = useAttachmentContext();
20
20
 
21
21
  const extension = useMemo(() => getFileExtension(file?.name) ?? '', [file?.name]);
22
22
 
@@ -29,12 +29,12 @@ export function MainContent({ title, extension2Icon, imageData, className }: Mai
29
29
  }
30
30
 
31
31
  return (
32
- <div className={cn(styles.composition, className)}>
32
+ <div className={cn(styles.composition, className)} data-size={size}>
33
33
  <TextBlock title={title} align='center' />
34
34
 
35
35
  <IconPredefined
36
- size='s'
37
- icon={extension2Icon?.[extension] ?? FileSVG}
36
+ size={size}
37
+ icon={extensionToIcon?.[extension] ?? FileSVG}
38
38
  decor
39
39
  appearance='neutral'
40
40
  shape='square'
@@ -1,5 +1,7 @@
1
1
  @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-attachment';
2
2
 
3
+ $sizes: 's', 'm';
4
+
3
5
  .composition {
4
6
  @include composite-var($attachment-composition-s);
5
7
 
@@ -14,4 +16,10 @@
14
16
  padding: $dimension-050m;
15
17
 
16
18
  text-align: center;
19
+
20
+ @each $size in $sizes {
21
+ &[data-size='#{$size}'] {
22
+ @include composite-var($attachment, 'composition', $size);
23
+ }
24
+ }
17
25
  }
@@ -1,21 +1,31 @@
1
1
  @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-attachment';
2
2
 
3
3
  .wrapper {
4
- @include composite-var($attachment-container-square);
4
+ &.sizeS {
5
+ @include composite-var($attachment-container-square-s);
6
+ }
7
+
8
+ &.sizeM {
9
+ @include composite-var($attachment-container-square-m);
10
+ }
5
11
 
6
12
  .main {
7
13
  display: flex;
8
14
  }
9
15
 
10
16
  .hover {
11
- display: none;
17
+ pointer-events: none;
18
+ height: 0;
19
+ opacity: 0;
12
20
  }
13
21
 
14
22
  &:hover,
15
- &:focus-within,
16
- &:focus-visible {
23
+ &:focus-visible,
24
+ &.hasFocusedActions {
17
25
  .hover {
18
- display: flex;
26
+ pointer-events: unset;
27
+ height: unset;
28
+ opacity: 1;
19
29
  }
20
30
 
21
31
  .main {
package/src/contexts.ts CHANGED
@@ -12,3 +12,17 @@ export const AttachmentContext = createContext<AttachmentContextType>({});
12
12
  export function useAttachmentContext() {
13
13
  return useContext(AttachmentContext);
14
14
  }
15
+
16
+ export type AttachmentFocusActionsContextType = {
17
+ focused: boolean;
18
+ setFocused(focused: boolean): void;
19
+ };
20
+
21
+ export const AttachmentFocusActionsContext = createContext<AttachmentFocusActionsContextType>({
22
+ focused: false,
23
+ setFocused: () => {},
24
+ });
25
+
26
+ export function useAttachmentFocusActionsContext() {
27
+ return useContext(AttachmentFocusActionsContext);
28
+ }
@@ -1,7 +1,9 @@
1
+ import { MouseEvent } from 'react';
2
+
1
3
  import { ButtonFunction } from '@snack-uikit/button';
2
4
  import { DownloadSVG, TrashSVG } from '@snack-uikit/icons';
3
5
 
4
- import { useAttachmentContext } from '../../contexts';
6
+ import { useAttachmentContext, useAttachmentFocusActionsContext } from '../../contexts';
5
7
  import styles from './styles.module.scss';
6
8
 
7
9
  type ActionsProps = {
@@ -9,12 +11,31 @@ type ActionsProps = {
9
11
  hideDelete?: boolean;
10
12
  };
11
13
 
14
+ const noop = () => {};
15
+
12
16
  export function Actions({ hideDelete, hideDownload }: ActionsProps) {
13
17
  const { onDelete, onDownload, file, disabled } = useAttachmentContext();
18
+ const { setFocused = noop } = useAttachmentFocusActionsContext();
14
19
 
15
20
  const showDownload = onDownload && !hideDownload;
16
21
  const showDelete = onDelete && !hideDelete;
17
22
 
23
+ const handleFocus = () => {
24
+ setFocused(true);
25
+ };
26
+ const handleBlur = () => {
27
+ setFocused(false);
28
+ };
29
+ const handleDownload = (e: MouseEvent<HTMLButtonElement>) => {
30
+ onDownload?.(file);
31
+ e.stopPropagation();
32
+ };
33
+
34
+ const handleDelete = (e: MouseEvent<HTMLButtonElement>) => {
35
+ onDelete?.(file);
36
+ e.stopPropagation();
37
+ };
38
+
18
39
  if (!showDownload && !showDelete) {
19
40
  return null;
20
41
  }
@@ -26,10 +47,9 @@ export function Actions({ hideDelete, hideDownload }: ActionsProps) {
26
47
  disabled={disabled}
27
48
  size='xs'
28
49
  icon={<DownloadSVG />}
29
- onClick={e => {
30
- onDownload(file);
31
- e.stopPropagation();
32
- }}
50
+ onClick={handleDownload}
51
+ onFocus={handleFocus}
52
+ onBlur={handleBlur}
33
53
  />
34
54
  )}
35
55
  {showDelete && (
@@ -37,10 +57,9 @@ export function Actions({ hideDelete, hideDownload }: ActionsProps) {
37
57
  disabled={disabled}
38
58
  size='xs'
39
59
  icon={<TrashSVG />}
40
- onClick={e => {
41
- onDelete(file);
42
- e.stopPropagation();
43
- }}
60
+ onClick={handleDelete}
61
+ onFocus={handleFocus}
62
+ onBlur={handleBlur}
44
63
  />
45
64
  )}
46
65
  </div>
package/src/types.ts CHANGED
@@ -5,7 +5,7 @@ import { WithSupportProps } from '@snack-uikit/utils';
5
5
 
6
6
  export type Size = 's' | 'm';
7
7
 
8
- export type AttachmentCommonProps = WithSupportProps<{
8
+ export type AttachmentProps = WithSupportProps<{
9
9
  /** Файл */
10
10
  file?: File;
11
11
  /** Колбек на клик по кнопке скачивания */
@@ -36,12 +36,10 @@ export type AttachmentCommonProps = WithSupportProps<{
36
36
  * Объект сопоставления расширения файла и отображаемой иконки
37
37
  * @defaultIcon FileSVG
38
38
  */
39
- extension2Icon?: Record<string, IconPredefinedProps['icon']>;
39
+ extensionToIcon?: Record<string, IconPredefinedProps['icon']>;
40
+ /** Размер */
41
+ size?: Size;
40
42
  }> &
41
43
  Pick<CardProps, 'checked' | 'disabled' | 'multipleSelection' | 'onClick' | 'className'>;
42
44
 
43
- export type AttachmentSquareProps = AttachmentCommonProps;
44
- export type AttachmentProps = AttachmentCommonProps & {
45
- /** Размер */
46
- size?: Size;
47
- };
45
+ export type AttachmentSquareProps = AttachmentProps;
@@ -1,16 +0,0 @@
1
- .wrapper{
2
- width:var(--size-attachment-container-square, 80px);
3
- height:var(--size-attachment-container-square, 80px);
4
- }
5
- .wrapper .main{
6
- display:flex;
7
- }
8
- .wrapper .hover{
9
- display:none;
10
- }
11
- .wrapper:hover .hover, .wrapper:focus-visible .hover{
12
- display:flex;
13
- }
14
- .wrapper:hover .main, .wrapper:focus-visible .main{
15
- display:none;
16
- }
@@ -1,24 +0,0 @@
1
- @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-attachment';
2
-
3
- .wrapper {
4
- @include composite-var($attachment-container-square);
5
-
6
- .main {
7
- display: flex;
8
- }
9
-
10
- .hover {
11
- display: none;
12
- }
13
-
14
- &:hover,
15
- &:focus-visible {
16
- .hover {
17
- display: flex;
18
- }
19
-
20
- .main {
21
- display: none;
22
- }
23
- }
24
- }