@snack-uikit/toolbar 0.5.4 → 0.6.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.6.0 (2024-01-18)
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+
12
+ * **FF-4102:** rename prop 'actions' to 'after', add 'before' prop, composed some props to 'search' ([8178570](https://github.com/cloud-ru-tech/snack-uikit/commit/81785709769bde31e7d11db1af9db6b87568b148))
13
+
14
+
15
+
16
+
6
17
  ## 0.5.4 (2023-12-28)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -13,11 +13,7 @@ Toolbar
13
13
  ### Props
14
14
  | name | type | default value | description |
15
15
  |------|------|---------------|-------------|
16
- | onChange* | `(value: string) => void` | - | Колбек смены значения |
17
- | value* | `string` | - | Значение строки поиска |
18
- | onSubmit | `(value: string) => void` | - | Колбек на подтверждение поиска по строке |
19
- | placeholder | `string` | - | Плейсхолдер |
20
- | loading | `boolean` | - | Состояние загрузки |
16
+ | search | `{ value: string; onChange(value: string): void; onSubmit?(value: string): void; placeholder?: string; loading?: boolean; }` | - | Параметры отвечают за строку поиска <br> <strong>value</strong>: Значение строки поиска <br> <strong>onChange</strong>: Колбэк смены значения <br> <strong>onSubmit</strong>: Колбэк на подтверждение поиска по строке <strong>placeholder</strong>: Плейсхолдер <br> <strong>loading</strong>: Состояние загрузки <br> |
21
17
  | className | `string` | - | Класснейм |
22
18
  | outline | `boolean` | - | Внешний бордер |
23
19
  | onCheck | `() => void` | - | Колбек смены значения чекбокса |
@@ -26,7 +22,8 @@ Toolbar
26
22
  | indeterminate | `boolean` | - | Состояние частичного выбора |
27
23
  | selectionMode | enum SelectionMode: `"single"`, `"multiple"` | 'multiple' | Режим выбора |
28
24
  | onRefresh | `() => void` | - | Колбек обновления |
29
- | actions | `ReactNode` | - | Дополнительный слот |
25
+ | before | `ReactNode` | - | Дополнительный слот в начале Тулбара |
26
+ | after | `ReactNode` | - | Дополнительный слот в конце тулбара |
30
27
  | moreActions | `Pick<DroplistItemSingleProps, "option" \| "caption" \| "description" \| "tagLabel" \| "disabled" \| "icon" \| "onClick">[]` | - | Элементы выпадающего списка кнопки с действиями |
31
28
 
32
29
 
@@ -1,4 +1,4 @@
1
1
  import { WithSupportProps } from '@snack-uikit/utils';
2
2
  import { CheckedToolbarProps, DefaultToolbarProps } from './types';
3
3
  export type ToolbarProps = WithSupportProps<DefaultToolbarProps | CheckedToolbarProps>;
4
- export declare function Toolbar({ className, actions, outline, moreActions, onRefresh, ...rest }: ToolbarProps): import("react/jsx-runtime").JSX.Element;
4
+ export declare function Toolbar({ className, before, after, outline, moreActions, onRefresh, search, ...rest }: ToolbarProps): import("react/jsx-runtime").JSX.Element;
@@ -17,9 +17,11 @@ import { SearchPrivate } from '@snack-uikit/search';
17
17
  import { extractSupportProps } from '@snack-uikit/utils';
18
18
  import { TEST_IDS } from '../../constants';
19
19
  import { DeleteAction, MoreActions, Separator } from '../../helperComponents';
20
- import { extractDeleteActionProps, extractSearchPrivateProps, isDeleteActionProps } from './helpers';
20
+ import { extractDeleteActionProps, isDeleteActionProps } from './helpers';
21
21
  import styles from './styles.module.css';
22
22
  export function Toolbar(_a) {
23
- var { className, actions, outline, moreActions, onRefresh } = _a, rest = __rest(_a, ["className", "actions", "outline", "moreActions", "onRefresh"]);
24
- return (_jsxs("div", Object.assign({ className: cn(styles.container, className) }, extractSupportProps(rest), { "data-outline": outline || undefined, children: [isDeleteActionProps(rest) && (_jsxs(_Fragment, { children: [_jsx(DeleteAction, Object.assign({}, extractDeleteActionProps(rest))), _jsx(Separator, {})] })), onRefresh && (_jsxs(_Fragment, { children: [_jsx(ButtonFunction, { icon: _jsx(UpdateSVG, {}), size: 'm', className: styles.updateButton, onClick: onRefresh, "data-test-id": TEST_IDS.refreshButton }), _jsx(Separator, {})] })), _jsx(SearchPrivate, Object.assign({}, extractSearchPrivateProps(rest), { className: styles.search, size: 'm', "data-test-id": TEST_IDS.search })), actions && (_jsxs(_Fragment, { children: [_jsx(Separator, {}), _jsx("div", { "data-test-id": TEST_IDS.actions, className: styles.actions, children: actions })] })), moreActions && (_jsxs(_Fragment, { children: [_jsx(Separator, {}), _jsx(MoreActions, { moreActions: moreActions })] }))] })));
23
+ var { className, before, after, outline, moreActions, onRefresh, search } = _a, rest = __rest(_a, ["className", "before", "after", "outline", "moreActions", "onRefresh", "search"]);
24
+ const needsDeleteAction = isDeleteActionProps(rest);
25
+ const hasLeftSideElements = Boolean(needsDeleteAction || before || onRefresh);
26
+ return (_jsxs("div", Object.assign({ className: cn(styles.container, className) }, extractSupportProps(rest), { "data-outline": outline || undefined, children: [hasLeftSideElements && (_jsxs("div", { className: styles.flexRow, children: [needsDeleteAction && _jsx(DeleteAction, Object.assign({}, extractDeleteActionProps(rest))), before && (_jsx("div", { "data-test-id": TEST_IDS.before, className: styles.actions, children: before })), (needsDeleteAction || before) && _jsx(Separator, {}), onRefresh && (_jsxs(_Fragment, { children: [_jsx(ButtonFunction, { icon: _jsx(UpdateSVG, {}), size: 'm', className: styles.updateButton, onClick: onRefresh, "data-test-id": TEST_IDS.refreshButton }), _jsx(Separator, {})] }))] })), search && _jsx(SearchPrivate, Object.assign({}, search, { className: styles.search, size: 'm', "data-test-id": TEST_IDS.search })), (moreActions || after) && (_jsxs("div", { className: styles.flexRow, "data-align-right": (!search && !hasLeftSideElements) || undefined, children: [after && (_jsxs(_Fragment, { children: [(search || hasLeftSideElements) && _jsx(Separator, {}), _jsx("div", { "data-test-id": TEST_IDS.after, className: styles.actions, children: after })] })), moreActions && (_jsxs(_Fragment, { children: [_jsx(Separator, {}), _jsx(MoreActions, { moreActions: moreActions })] }))] }))] })));
25
27
  }
@@ -1,12 +1,5 @@
1
1
  import { ToolbarProps } from './Toolbar';
2
2
  import { CheckedToolbarProps } from './types';
3
- export declare function extractSearchPrivateProps({ value, onChange, onSubmit, placeholder, loading }: Partial<ToolbarProps>): {
4
- value: string | undefined;
5
- onChange: ((value: string) => void) | undefined;
6
- onSubmit: ((value: string) => void) | undefined;
7
- placeholder: string | undefined;
8
- loading: boolean | undefined;
9
- };
10
3
  export declare function extractDeleteActionProps({ onCheck, checked, indeterminate, onDelete, selectionMode, }: Omit<CheckedToolbarProps, 'onRefresh'>): {
11
4
  onCheck: (() => void) | undefined;
12
5
  checked: boolean | undefined;
@@ -1,6 +1,3 @@
1
- export function extractSearchPrivateProps({ value, onChange, onSubmit, placeholder, loading }) {
2
- return { value, onChange, onSubmit, placeholder, loading };
3
- }
4
1
  export function extractDeleteActionProps({ onCheck, checked, indeterminate, onDelete, selectionMode, }) {
5
2
  return { onCheck, checked, indeterminate, onDelete, selectionMode };
6
3
  }
@@ -6,6 +6,7 @@
6
6
  border-radius:var(--radius-toolbar-container, 14px);
7
7
  position:relative;
8
8
  display:flex;
9
+ justify-content:space-between;
9
10
  box-sizing:border-box;
10
11
  background-color:var(--sys-neutral-background1-level, #f9f9f9);
11
12
  }
@@ -47,7 +48,16 @@
47
48
  transition-duration:0s;
48
49
  }
49
50
 
50
- .actions{
51
+ .flexRow{
51
52
  display:flex;
52
53
  flex-shrink:0;
54
+ box-sizing:border-box;
55
+ }
56
+ .flexRow[data-align-right]{
57
+ margin-left:auto;
58
+ }
59
+
60
+ .actions{
61
+ flex-shrink:0;
62
+ box-sizing:border-box;
53
63
  }
@@ -5,22 +5,28 @@ import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
5
5
  type OptionalProps = {
6
6
  /** Колбек обновления */
7
7
  onRefresh?(): void;
8
- /** Дополнительный слот */
9
- actions?: ReactNode;
8
+ /** Дополнительный слот в начале Тулбара */
9
+ before?: ReactNode;
10
+ /** Дополнительный слот в конце тулбара */
11
+ after?: ReactNode;
10
12
  /** Элементы выпадающего списка кнопки с действиями */
11
13
  moreActions?: Pick<ItemSingleProps, 'tagLabel' | 'onClick' | 'option' | 'icon' | 'disabled' | 'description' | 'caption'>[];
12
14
  };
13
15
  export type CommonToolbarProps = {
14
- /** Значение строки поиска */
15
- value: string;
16
- /** Колбек смены значения */
17
- onChange(value: string): void;
18
- /** Колбек на подтверждение поиска по строке */
19
- onSubmit?(value: string): void;
20
- /** Плейсхолдер */
21
- placeholder?: string;
22
- /** Состояние загрузки */
23
- loading?: boolean;
16
+ /** Параметры отвечают за строку поиска <br>
17
+ * <strong>value</strong>: Значение строки поиска <br>
18
+ * <strong>onChange</strong>: Колбэк смены значения <br>
19
+ * <strong>onSubmit</strong>: Колбэк на подтверждение поиска по строке
20
+ * <strong>placeholder</strong>: Плейсхолдер <br>
21
+ * <strong>loading</strong>: Состояние загрузки <br>
22
+ * */
23
+ search?: {
24
+ value: string;
25
+ onChange(value: string): void;
26
+ onSubmit?(value: string): void;
27
+ placeholder?: string;
28
+ loading?: boolean;
29
+ };
24
30
  /** Класснейм */
25
31
  className?: string;
26
32
  /** Внешний бордер */
@@ -7,5 +7,6 @@ export declare const TEST_IDS: {
7
7
  moreActionsButton: string;
8
8
  droplist: string;
9
9
  option: string;
10
- actions: string;
10
+ before: string;
11
+ after: string;
11
12
  };
package/dist/constants.js CHANGED
@@ -7,5 +7,6 @@ export const TEST_IDS = {
7
7
  moreActionsButton: 'toolbar__more-actions-button',
8
8
  droplist: 'toolbar__droplist',
9
9
  option: 'toolbar__droplist-option',
10
- actions: 'toolbar__actions',
10
+ before: 'toolbar__before',
11
+ after: 'toolbar__after',
11
12
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Toolbar",
7
- "version": "0.5.4",
7
+ "version": "0.6.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -40,5 +40,5 @@
40
40
  "@snack-uikit/utils": "3.2.0",
41
41
  "classnames": "2.3.2"
42
42
  },
43
- "gitHead": "57c597a3eebaf6528c0c61b6b27dd244753de1cf"
43
+ "gitHead": "75f118e9d2fa2f38727460ebdd9ac5a1c31cc176"
44
44
  }
@@ -7,56 +7,66 @@ import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
7
7
 
8
8
  import { TEST_IDS } from '../../constants';
9
9
  import { DeleteAction, MoreActions, Separator } from '../../helperComponents';
10
- import { extractDeleteActionProps, extractSearchPrivateProps, isDeleteActionProps } from './helpers';
10
+ import { extractDeleteActionProps, isDeleteActionProps } from './helpers';
11
11
  import styles from './styles.module.scss';
12
12
  import { CheckedToolbarProps, DefaultToolbarProps } from './types';
13
13
 
14
14
  export type ToolbarProps = WithSupportProps<DefaultToolbarProps | CheckedToolbarProps>;
15
15
 
16
- export function Toolbar({ className, actions, outline, moreActions, onRefresh, ...rest }: ToolbarProps) {
16
+ export function Toolbar({ className, before, after, outline, moreActions, onRefresh, search, ...rest }: ToolbarProps) {
17
+ const needsDeleteAction = isDeleteActionProps(rest);
18
+ const hasLeftSideElements = Boolean(needsDeleteAction || before || onRefresh);
19
+
17
20
  return (
18
21
  <div className={cn(styles.container, className)} {...extractSupportProps(rest)} data-outline={outline || undefined}>
19
- {isDeleteActionProps(rest) && (
20
- <>
21
- <DeleteAction {...extractDeleteActionProps(rest)} />
22
- <Separator />
23
- </>
24
- )}
22
+ {hasLeftSideElements && (
23
+ <div className={styles.flexRow}>
24
+ {needsDeleteAction && <DeleteAction {...extractDeleteActionProps(rest)} />}
25
25
 
26
- {onRefresh && (
27
- <>
28
- <ButtonFunction
29
- icon={<UpdateSVG />}
30
- size='m'
31
- className={styles.updateButton}
32
- onClick={onRefresh}
33
- data-test-id={TEST_IDS.refreshButton}
34
- />
35
- <Separator />
36
- </>
37
- )}
26
+ {before && (
27
+ <div data-test-id={TEST_IDS.before} className={styles.actions}>
28
+ {before}
29
+ </div>
30
+ )}
31
+
32
+ {(needsDeleteAction || before) && <Separator />}
38
33
 
39
- <SearchPrivate
40
- {...extractSearchPrivateProps(rest)}
41
- className={styles.search}
42
- size='m'
43
- data-test-id={TEST_IDS.search}
44
- />
45
-
46
- {actions && (
47
- <>
48
- <Separator />
49
- <div data-test-id={TEST_IDS.actions} className={styles.actions}>
50
- {actions}
51
- </div>
52
- </>
34
+ {onRefresh && (
35
+ <>
36
+ <ButtonFunction
37
+ icon={<UpdateSVG />}
38
+ size='m'
39
+ className={styles.updateButton}
40
+ onClick={onRefresh}
41
+ data-test-id={TEST_IDS.refreshButton}
42
+ />
43
+ <Separator />
44
+ </>
45
+ )}
46
+ </div>
53
47
  )}
54
48
 
55
- {moreActions && (
56
- <>
57
- <Separator />
58
- <MoreActions moreActions={moreActions} />
59
- </>
49
+ {search && <SearchPrivate {...search} className={styles.search} size='m' data-test-id={TEST_IDS.search} />}
50
+
51
+ {(moreActions || after) && (
52
+ <div className={styles.flexRow} data-align-right={(!search && !hasLeftSideElements) || undefined}>
53
+ {after && (
54
+ <>
55
+ {(search || hasLeftSideElements) && <Separator />}
56
+
57
+ <div data-test-id={TEST_IDS.after} className={styles.actions}>
58
+ {after}
59
+ </div>
60
+ </>
61
+ )}
62
+
63
+ {moreActions && (
64
+ <>
65
+ <Separator />
66
+ <MoreActions moreActions={moreActions} />
67
+ </>
68
+ )}
69
+ </div>
60
70
  )}
61
71
  </div>
62
72
  );
@@ -1,10 +1,6 @@
1
1
  import { ToolbarProps } from './Toolbar';
2
2
  import { CheckedToolbarProps } from './types';
3
3
 
4
- export function extractSearchPrivateProps({ value, onChange, onSubmit, placeholder, loading }: Partial<ToolbarProps>) {
5
- return { value, onChange, onSubmit, placeholder, loading };
6
- }
7
-
8
4
  export function extractDeleteActionProps({
9
5
  onCheck,
10
6
  checked,
@@ -9,9 +9,14 @@
9
9
  @include composite-var($toolbar-container);
10
10
 
11
11
  position: relative;
12
+
12
13
  display: flex;
14
+ justify-content: space-between;
15
+
13
16
  box-sizing: border-box;
17
+
14
18
  background-color: $sys-neutral-background1-level;
19
+
15
20
  &[data-outline] {
16
21
  &::before {
17
22
  @include composite-var($toolbar-container-outline);
@@ -59,8 +64,17 @@
59
64
  }
60
65
  }
61
66
 
67
+ .flexRow {
68
+ display: flex;
69
+ flex-shrink: 0;
70
+ box-sizing: border-box;
71
+
72
+ &[data-align-right] {
73
+ margin-left: auto;
74
+ }
75
+ }
62
76
 
63
77
  .actions {
64
- display: flex;
65
78
  flex-shrink: 0;
66
- }
79
+ box-sizing: border-box;
80
+ }
@@ -8,8 +8,10 @@ import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
8
8
  type OptionalProps = {
9
9
  /** Колбек обновления */
10
10
  onRefresh?(): void;
11
- /** Дополнительный слот */
12
- actions?: ReactNode;
11
+ /** Дополнительный слот в начале Тулбара */
12
+ before?: ReactNode;
13
+ /** Дополнительный слот в конце тулбара */
14
+ after?: ReactNode;
13
15
  /** Элементы выпадающего списка кнопки с действиями */
14
16
  moreActions?: Pick<
15
17
  ItemSingleProps,
@@ -18,16 +20,20 @@ type OptionalProps = {
18
20
  };
19
21
 
20
22
  export type CommonToolbarProps = {
21
- /** Значение строки поиска */
22
- value: string;
23
- /** Колбек смены значения */
24
- onChange(value: string): void;
25
- /** Колбек на подтверждение поиска по строке */
26
- onSubmit?(value: string): void;
27
- /** Плейсхолдер */
28
- placeholder?: string;
29
- /** Состояние загрузки */
30
- loading?: boolean;
23
+ /** Параметры отвечают за строку поиска <br>
24
+ * <strong>value</strong>: Значение строки поиска <br>
25
+ * <strong>onChange</strong>: Колбэк смены значения <br>
26
+ * <strong>onSubmit</strong>: Колбэк на подтверждение поиска по строке
27
+ * <strong>placeholder</strong>: Плейсхолдер <br>
28
+ * <strong>loading</strong>: Состояние загрузки <br>
29
+ * */
30
+ search?: {
31
+ value: string;
32
+ onChange(value: string): void;
33
+ onSubmit?(value: string): void;
34
+ placeholder?: string;
35
+ loading?: boolean;
36
+ };
31
37
  /** Класснейм */
32
38
  className?: string;
33
39
  /** Внешний бордер */
package/src/constants.ts CHANGED
@@ -7,5 +7,6 @@ export const TEST_IDS = {
7
7
  moreActionsButton: 'toolbar__more-actions-button',
8
8
  droplist: 'toolbar__droplist',
9
9
  option: 'toolbar__droplist-option',
10
- actions: 'toolbar__actions',
10
+ before: 'toolbar__before',
11
+ after: 'toolbar__after',
11
12
  };