tycho-components 0.0.15-SNAPSHOT-13 → 0.0.15-SNAPSHOT-15

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.
@@ -9,6 +9,10 @@ type Props = {
9
9
  onDrop?: () => void;
10
10
  keepName?: boolean;
11
11
  title?: string;
12
+ alternativeButton?: {
13
+ title: string;
14
+ action: () => void;
15
+ };
12
16
  };
13
- export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, }: Props): import("react/jsx-runtime").JSX.Element;
17
+ export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, }: Props): import("react/jsx-runtime").JSX.Element;
14
18
  export {};
@@ -6,7 +6,7 @@ import './style.scss';
6
6
  import UploadService from './UploadService';
7
7
  import { useMessageUtils } from '../configs/useMessageUtils';
8
8
  import AppModal from '../AppModal';
9
- export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, }) {
9
+ export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, }) {
10
10
  const { t } = useTranslation('upload');
11
11
  const { dispatchError } = useMessageUtils();
12
12
  const [file, setFile] = useState();
@@ -37,7 +37,7 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
37
37
  onError && onError(err);
38
38
  });
39
39
  };
40
- return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: upload, children: _jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), file && preview && (_jsx("img", { className: "preview", src: preview, onLoad: () => {
40
+ return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: upload, alternativeButton: alternativeButton, children: _jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), file && preview && (_jsx("img", { className: "preview", src: preview, onLoad: () => {
41
41
  URL.revokeObjectURL(preview);
42
42
  } })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("span", { children: file.name }), _jsx("b", { children: t('label.confirm') })] }))] }) }));
43
43
  }
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import './style.scss';
3
2
  type Props = {
4
3
  children: React.ReactNode;
@@ -15,6 +14,10 @@ type Props = {
15
14
  confirmLabel?: string;
16
15
  closeLabel?: string;
17
16
  onEntered?: () => void;
17
+ alternativeButton?: {
18
+ title: string;
19
+ action: () => void;
20
+ };
18
21
  };
19
- export default function AppModal({ children, title, subtitle, className, close, confirm, disableConfirm, hideFooter, disableClose, disableCancel, confirmLabel, closeLabel, cancel, onEntered, }: Props): import("react/jsx-runtime").JSX.Element;
22
+ export default function AppModal({ children, title, subtitle, className, close, confirm, disableConfirm, hideFooter, disableClose, disableCancel, confirmLabel, closeLabel, cancel, onEntered, alternativeButton, }: Props): import("react/jsx-runtime").JSX.Element;
20
23
  export {};
@@ -4,10 +4,10 @@ import cx from 'classnames';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { Button, Icon } from 'tycho-storybook';
6
6
  import './style.scss';
7
- export default function AppModal({ children, title, subtitle, className, close, confirm, disableConfirm, hideFooter, disableClose, disableCancel, confirmLabel, closeLabel, cancel, onEntered, }) {
7
+ export default function AppModal({ children, title, subtitle, className, close, confirm, disableConfirm, hideFooter, disableClose, disableCancel, confirmLabel, closeLabel, cancel, onEntered, alternativeButton, }) {
8
8
  const { t } = useTranslation('common');
9
9
  const getClassNames = cx('modal-container', className);
10
- return (_jsx(Modal, { open: true, disableEnforceFocus: true, disableAutoFocus: true, disableRestoreFocus: true, children: _jsx(Fade, { in: true, onEntered: () => onEntered && onEntered(), children: _jsxs(Box, { className: getClassNames, sx: style, children: [_jsxs("div", { className: "header", children: [_jsxs("div", { className: "titles", children: [_jsx("span", { className: "title", children: title }), subtitle && _jsx("span", { className: "subtitle", children: subtitle })] }), !disableClose && (_jsx(Icon, { name: "close", onClick: close, className: "pointer" }))] }), _jsx("div", { className: "body", children: children }), !hideFooter ? (_jsxs("div", { className: "footer", children: [!disableCancel && (_jsx(Button, { onClick: cancel || close, text: closeLabel || t('button.cancel'), color: "danger" })), confirm && (_jsx(Button, { onClick: confirm, disabled: disableConfirm, text: confirmLabel || t('button.confirm') }))] })) : null] }) }) }));
10
+ return (_jsx(Modal, { open: true, disableEnforceFocus: true, disableAutoFocus: true, disableRestoreFocus: true, children: _jsx(Fade, { in: true, onEntered: () => onEntered && onEntered(), children: _jsxs(Box, { className: getClassNames, sx: style, children: [_jsxs("div", { className: "header", children: [_jsxs("div", { className: "titles", children: [_jsx("span", { className: "title", children: title }), subtitle && _jsx("span", { className: "subtitle", children: subtitle })] }), !disableClose && (_jsx(Icon, { name: "close", onClick: close, className: "pointer" }))] }), _jsx("div", { className: "body", children: children }), !hideFooter ? (_jsxs("div", { className: "footer", children: [alternativeButton && (_jsx(Button, { className: "alternative", color: "white", onClick: alternativeButton.action, text: alternativeButton.title })), !disableCancel && (_jsx(Button, { onClick: cancel || close, text: closeLabel || t('button.cancel'), color: "danger" })), confirm && (_jsx(Button, { onClick: confirm, disabled: disableConfirm, text: confirmLabel || t('button.confirm') }))] })) : null] }) }) }));
11
11
  }
12
12
  const style = {
13
13
  position: 'absolute',
@@ -0,0 +1,17 @@
1
+ import './style.scss';
2
+ type Props = {
3
+ gotoPage: (p: number) => void;
4
+ canPreviousPage: boolean;
5
+ canNextPage: boolean;
6
+ previousPage: () => void;
7
+ nextPage: () => void;
8
+ pageIndex: number;
9
+ pageOptions: number[];
10
+ setPageSize: (p: number) => void;
11
+ pageSize: number;
12
+ multiple?: number;
13
+ total: number;
14
+ hideTotal?: boolean;
15
+ };
16
+ export default function AppPagination({ gotoPage, canPreviousPage, canNextPage, previousPage, nextPage, pageIndex, pageOptions, setPageSize, pageSize, multiple, total, hideTotal, }: Props): import("react/jsx-runtime").JSX.Element;
17
+ export {};
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { faChevronLeft, faChevronRight, } from '@fortawesome/free-solid-svg-icons';
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
+ import { useEffect, useState } from 'react';
5
+ import { useTranslation } from 'react-i18next';
6
+ import AppSelect from '../AppSelect';
7
+ import './style.scss';
8
+ const minPages = 5;
9
+ export default function AppPagination({ gotoPage, canPreviousPage, canNextPage, previousPage, nextPage, pageIndex, pageOptions, setPageSize, pageSize, multiple, total, hideTotal, }) {
10
+ const { t } = useTranslation('common');
11
+ const getPageSizeOptions = () => {
12
+ const arrayPagination = [];
13
+ if (multiple) {
14
+ for (let i = 0; i < 5; i += 1)
15
+ arrayPagination.push({
16
+ label: `${t('pagination.label.showing')} ${(i + 1) * multiple} ${t('pagination.label.results')}`,
17
+ value: (i + 1) * multiple,
18
+ });
19
+ }
20
+ return arrayPagination;
21
+ };
22
+ const alterColorPageSelected = (pageOption) => pageOption === pageIndex ? 'page-item selected' : 'page-item';
23
+ const [buttons, setButtons] = useState([]);
24
+ const renderButton = (pageOption) => {
25
+ if (pageOption === undefined)
26
+ return null;
27
+ if (pageOption === -1 || pageOption === -2) {
28
+ return (_jsx("button", { type: "button", className: "page-ellipsis", children: "..." }, pageOption.valueOf()));
29
+ }
30
+ return (_jsx("button", { type: "button", onClick: () => {
31
+ gotoPage(pageOption);
32
+ }, className: alterColorPageSelected(pageOption), children: pageOption + 1 }, pageOption.valueOf()));
33
+ };
34
+ useEffect(() => {
35
+ if (pageOptions && pageOptions.length > minPages) {
36
+ const arr = [];
37
+ // add first and check for need of ...
38
+ arr.push(0);
39
+ if (pageIndex > 1)
40
+ arr.push(-1);
41
+ if (pageIndex >= pageOptions.length - 3) {
42
+ for (let i = pageOptions.length - 3; i < pageOptions.length; i += 1) {
43
+ if (i !== pageOptions.length - 1) {
44
+ arr.push(i);
45
+ }
46
+ }
47
+ }
48
+ else {
49
+ for (let i = 0; i < 3; i += 1) {
50
+ if (pageIndex + i !== 0) {
51
+ arr.push(pageIndex + i);
52
+ }
53
+ }
54
+ }
55
+ // check for need of ... and add last
56
+ if (pageIndex < pageOptions.length - 3)
57
+ arr.push(-2);
58
+ arr.push(pageOptions[pageOptions.length - 1]);
59
+ setButtons(arr);
60
+ }
61
+ else {
62
+ setButtons(pageOptions.slice());
63
+ }
64
+ }, [pageIndex]);
65
+ return (_jsxs("div", { className: "pagination-container", children: [_jsxs("div", { className: "select", children: [multiple && (_jsx(AppSelect, { options: getPageSizeOptions(), value: getPageSizeOptions().find((p) => p.value === pageSize), emptyValue: false, onChange: (e) => {
66
+ setPageSize(e);
67
+ } })), !hideTotal && (_jsxs("span", { className: "total", children: [t('pagination.label.total'), ": ", total] }))] }), _jsxs("div", { className: "pages", children: [_jsx("button", { type: "button", onClick: () => previousPage(), disabled: !canPreviousPage, className: "page-item-chevron", children: _jsx(FontAwesomeIcon, { icon: faChevronLeft }) }), buttons?.map((pageOption, idx) => renderButton(pageOption)), _jsx("button", { type: "button", onClick: () => nextPage(), disabled: !canNextPage, className: "page-item-chevron", children: _jsx(FontAwesomeIcon, { icon: faChevronRight }) })] })] }));
68
+ }
@@ -0,0 +1,2 @@
1
+ import AppPagination from './AppPagination';
2
+ export default AppPagination;
@@ -0,0 +1,2 @@
1
+ import AppPagination from './AppPagination';
2
+ export default AppPagination;
@@ -0,0 +1,59 @@
1
+ .pagination-container {
2
+ display: flex;
3
+ align-items: center;
4
+
5
+ > .pages {
6
+ display: flex;
7
+ margin-left: auto;
8
+
9
+ .page-item,
10
+ .page-item-chevron,
11
+ .page-ellipsis {
12
+ height: 30px;
13
+ width: 35px;
14
+ margin-left: 4px;
15
+ border-radius: var(--radius-100);
16
+ background-color: var(--background-default);
17
+ }
18
+
19
+ .page-item-chevron {
20
+ border: none;
21
+ }
22
+
23
+ .page-ellipsis {
24
+ cursor: default;
25
+ }
26
+
27
+ .page-item,
28
+ .page-ellipsis {
29
+ @include button-small;
30
+ border: 1px solid var(--border-subtle-3);
31
+ background-color: var(--button-secondary-default);
32
+ color: var(--text-secondary);
33
+ align-items: center;
34
+
35
+ &.selected {
36
+ background: var(--button-primary-default);
37
+ color: var(--text-on-color-light);
38
+ }
39
+
40
+ &:hover {
41
+ background: var(--button-secondary-hover);
42
+ }
43
+ }
44
+ }
45
+
46
+ .select {
47
+ display: flex;
48
+ align-items: center;
49
+ gap: 16px;
50
+
51
+ .form-select {
52
+ width: auto;
53
+ }
54
+
55
+ .total {
56
+ @include label-medium-2;
57
+ }
58
+ }
59
+ }
@@ -10,7 +10,7 @@
10
10
  @include subtitle-large-2;
11
11
  width: 100%;
12
12
  text-align: center;
13
- background-color: var(--layer-layer-2);
13
+ background-color: var(--layer-layer-3);
14
14
  color: var(--text-placeholder);
15
15
  padding: 32px;
16
16
  }
@@ -0,0 +1,9 @@
1
+ import './style.scss';
2
+ type Props = {
3
+ options: any[];
4
+ value: any;
5
+ onChange: (value: any) => void;
6
+ emptyValue?: boolean;
7
+ };
8
+ export default function AppSelect({ options, onChange, emptyValue, }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Form } from 'react-bootstrap';
3
+ import './style.scss';
4
+ import { useTranslation } from 'react-i18next';
5
+ export default function AppSelect({ options, onChange, emptyValue = true, }) {
6
+ const { t } = useTranslation('common');
7
+ const getValues = () => {
8
+ if (Array.isArray(options))
9
+ return options;
10
+ const arr = [];
11
+ Object.keys(options).forEach((key) => {
12
+ arr.push({
13
+ label: options[key],
14
+ value: key,
15
+ });
16
+ });
17
+ return arr;
18
+ };
19
+ return (_jsxs(Form.Select, { onChange: (e) => onChange(e.target.value), children: [emptyValue && _jsx("option", { value: "", children: t('select.empty') }), getValues().map((option, idx) => (_jsx("option", { value: option.value, children: option.label }, idx.valueOf())))] }));
20
+ }
@@ -0,0 +1,2 @@
1
+ import AppSelect from './AppSelect';
2
+ export default AppSelect;
@@ -0,0 +1,2 @@
1
+ import AppSelect from './AppSelect';
2
+ export default AppSelect;
File without changes
@@ -4,6 +4,7 @@ export declare const commonResources: {
4
4
  'button.confirm': string;
5
5
  'button.cancel': string;
6
6
  'button.remove': string;
7
+ 'select.empty': string;
7
8
  'pagination.label.showing': string;
8
9
  'pagination.label.results': string;
9
10
  'pagination.label.total': string;
@@ -133,6 +134,8 @@ export declare const commonResources: {
133
134
  common: {
134
135
  'button.confirm': string;
135
136
  'button.cancel': string;
137
+ 'button.remove': string;
138
+ 'select.empty': string;
136
139
  'pagination.label.showing': string;
137
140
  'pagination.label.results': string;
138
141
  'pagination.label.total': string;
@@ -3,6 +3,7 @@ export declare const CommonTexts: {
3
3
  'button.confirm': string;
4
4
  'button.cancel': string;
5
5
  'button.remove': string;
6
+ 'select.empty': string;
6
7
  'pagination.label.showing': string;
7
8
  'pagination.label.results': string;
8
9
  'pagination.label.total': string;
@@ -21,6 +22,8 @@ export declare const CommonTexts: {
21
22
  'pt-BR': {
22
23
  'button.confirm': string;
23
24
  'button.cancel': string;
25
+ 'button.remove': string;
26
+ 'select.empty': string;
24
27
  'pagination.label.showing': string;
25
28
  'pagination.label.results': string;
26
29
  'pagination.label.total': string;
@@ -40,6 +43,7 @@ export declare const CommonTexts: {
40
43
  'button.confirm': string;
41
44
  'button.cancel': string;
42
45
  'button.remove': string;
46
+ 'select.empty': string;
43
47
  'pagination.label.showing': string;
44
48
  'pagination.label.results': string;
45
49
  'pagination.label.total': string;
@@ -3,6 +3,7 @@ export const CommonTexts = {
3
3
  'button.confirm': 'Confirm',
4
4
  'button.cancel': 'Cancel',
5
5
  'button.remove': 'Remove',
6
+ 'select.empty': 'Select',
6
7
  'pagination.label.showing': 'Showing',
7
8
  'pagination.label.results': 'results per page',
8
9
  'pagination.label.total': 'Total',
@@ -21,6 +22,8 @@ export const CommonTexts = {
21
22
  'pt-BR': {
22
23
  'button.confirm': 'Confirmar',
23
24
  'button.cancel': 'Cancelar',
25
+ 'button.remove': 'Remover',
26
+ 'select.empty': 'Selecionar',
24
27
  'pagination.label.showing': 'Exibindo',
25
28
  'pagination.label.results': 'resultados por página',
26
29
  'pagination.label.total': 'Total',
@@ -40,6 +43,7 @@ export const CommonTexts = {
40
43
  'button.confirm': 'Conferma',
41
44
  'button.cancel': 'Annulla',
42
45
  'button.remove': 'Rimuovi',
46
+ 'select.empty': 'Seleziona',
43
47
  'pagination.label.showing': 'Mostrando',
44
48
  'pagination.label.results': 'risultati per pagina',
45
49
  'pagination.label.total': 'Totale',
package/dist/index.d.ts CHANGED
@@ -6,8 +6,10 @@ export { default as AppLoading } from './AppLoading';
6
6
  export { default as AppModal } from './AppModal';
7
7
  export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
8
8
  export { default as AppModalRemove } from './AppModal/AppModalRemove';
9
+ export { default as AppPagination } from './AppPagination';
9
10
  export { default as AppPicture } from './AppPicture';
10
11
  export { default as AppPlaceholder } from './AppPlaceholder';
12
+ export { default as AppSelect } from './AppSelect';
11
13
  export { default as AppToast } from './AppToast';
12
14
  export { default as CommentComponent } from './Comments';
13
15
  export { default as Header } from './Header';
package/dist/index.js CHANGED
@@ -6,8 +6,10 @@ export { default as AppLoading } from './AppLoading';
6
6
  export { default as AppModal } from './AppModal';
7
7
  export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
8
8
  export { default as AppModalRemove } from './AppModal/AppModalRemove';
9
+ export { default as AppPagination } from './AppPagination';
9
10
  export { default as AppPicture } from './AppPicture';
10
11
  export { default as AppPlaceholder } from './AppPlaceholder';
12
+ export { default as AppSelect } from './AppSelect';
11
13
  export { default as AppToast } from './AppToast';
12
14
  export { default as CommentComponent } from './Comments';
13
15
  export { default as Header } from './Header';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.0.15-SNAPSHOT-13",
4
+ "version": "0.0.15-SNAPSHOT-15",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {