tycho-components 0.0.3 → 0.0.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "main": "src/index.ts",
6
6
  "dependencies": {
7
7
  "@emotion/react": "^11.13.3",
@@ -20,6 +20,7 @@
20
20
  "classnames": "^2.5.1",
21
21
  "date-fns": "^2.29.1",
22
22
  "date-fns-tz": "^1.3.6",
23
+ "i18next": "^23.3.0",
23
24
  "i18next-browser-languagedetector": "^7.1.0",
24
25
  "js-cookie": "^3.0.5",
25
26
  "react": ">=17 <19",
@@ -32,6 +33,7 @@
32
33
  "react-loading": "^2.0.3",
33
34
  "react-switch": "^7.1.0",
34
35
  "react-toastify": "^9.1.3",
36
+ "tycho-storybook": "0.0.33",
35
37
  "yup": "^1.2.0"
36
38
  },
37
39
  "devDependencies": {
@@ -2,10 +2,8 @@ import { Box, Fade, Modal } from '@mui/material';
2
2
  import cx from 'classnames';
3
3
  import React from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
+ import { Button, Icon } from 'tycho-storybook';
5
6
  import './style.scss';
6
- import { Button } from 'react-bootstrap';
7
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
- import { faTimes } from '@fortawesome/free-solid-svg-icons';
9
7
 
10
8
  type Props = {
11
9
  children: React.ReactNode;
@@ -54,25 +52,25 @@ export default function AppModal({
54
52
  {subtitle && <span className="subtitle">{subtitle}</span>}
55
53
  </div>
56
54
  {!disableClose && (
57
- <FontAwesomeIcon
58
- onClick={close}
59
- className="ms-auto pointer"
60
- icon={faTimes}
61
- />
55
+ <Icon name="close" onClick={close} className="pointer" />
62
56
  )}
63
57
  </div>
64
58
  <div className="body">{children}</div>
65
59
  {!hideFooter ? (
66
60
  <div className="footer">
67
61
  {!disableCancel && (
68
- <Button onClick={cancel || close} variant="danger">
69
- {closeLabel || t('button.cancel')}
70
- </Button>
62
+ <Button
63
+ onClick={cancel || close}
64
+ text={closeLabel || t('button.cancel')}
65
+ color="danger"
66
+ />
71
67
  )}
72
68
  {confirm && (
73
- <Button onClick={confirm} disabled={disableConfirm}>
74
- {confirmLabel || t('button.confirm')}
75
- </Button>
69
+ <Button
70
+ onClick={confirm}
71
+ disabled={disableConfirm}
72
+ text={confirmLabel || t('button.confirm')}
73
+ />
76
74
  )}
77
75
  </div>
78
76
  ) : null}
@@ -1,9 +1,7 @@
1
1
  import { Box, Modal } from '@mui/material';
2
2
  import { useTranslation } from 'react-i18next';
3
+ import { Button, Icon } from 'tycho-storybook';
3
4
  import './style.scss';
4
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
- import { faWarning } from '@fortawesome/free-solid-svg-icons';
6
- import { Button } from 'react-bootstrap';
7
5
 
8
6
  type Props = {
9
7
  title: string;
@@ -28,7 +26,7 @@ export default function AppModalConfirm({
28
26
  <Modal open>
29
27
  <Box className="modal-container modal-remove" sx={style}>
30
28
  <div className="body">
31
- <FontAwesomeIcon icon={faWarning} />
29
+ <Icon name="warning" size="large" filled />
32
30
  <div className="texts">
33
31
  <span className="title">{title}</span>
34
32
  <span className="subtitle">{subtitle}</span>
@@ -36,12 +34,15 @@ export default function AppModalConfirm({
36
34
  </div>
37
35
 
38
36
  <div className="footer">
39
- <Button onClick={onClose} variant="secondary">
40
- {closeLabel || t('modal.button.cancel')}
41
- </Button>
42
- <Button onClick={onConfirm}>
43
- {confirmLabel || t('modal.button.confirm')}
44
- </Button>
37
+ <Button
38
+ onClick={onClose}
39
+ text={closeLabel || t('modal.button.cancel')}
40
+ mode="tonal"
41
+ />
42
+ <Button
43
+ onClick={onConfirm}
44
+ text={confirmLabel || t('modal.button.confirm')}
45
+ />
45
46
  </div>
46
47
  </Box>
47
48
  </Modal>
@@ -1,9 +1,7 @@
1
1
  import { Box, Modal } from '@mui/material';
2
2
  import { useTranslation } from 'react-i18next';
3
+ import { Button, Icon } from 'tycho-storybook';
3
4
  import './style.scss';
4
- import { Button } from 'react-bootstrap';
5
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
6
- import { faWarning } from '@fortawesome/free-solid-svg-icons';
7
5
 
8
6
  type Props = {
9
7
  title: string;
@@ -24,7 +22,7 @@ export default function AppModalRemove({
24
22
  <Modal open>
25
23
  <Box className="modal-container modal-remove" sx={style}>
26
24
  <div className="body">
27
- <FontAwesomeIcon icon={faWarning} />
25
+ <Icon name="warning" size="large" filled />
28
26
  <div className="texts">
29
27
  <span className="title">{title}</span>
30
28
  <span className="subtitle">{subtitle}</span>
@@ -32,11 +30,8 @@ export default function AppModalRemove({
32
30
  </div>
33
31
 
34
32
  <div className="footer">
35
- <Button onClick={onClose} variant="secondary">
36
- {t('button.cancel')}
37
- </Button>
38
-
39
- <Button onClick={onConfirm}>{t('button.confirm')}</Button>
33
+ <Button onClick={onClose} text={t('button.cancel')} mode="tonal" />
34
+ <Button onClick={onConfirm} text={t('button.confirm')} />
40
35
  </div>
41
36
  </Box>
42
37
  </Modal>
@@ -10,7 +10,7 @@ import { toastLoading } from '../../configs/store/actions';
10
10
  import Participant, { ParticipantCreateRequest } from '../types/Participant';
11
11
  import ParticipantService from '../types/ParticipantService';
12
12
  import './style.scss';
13
- import TextField from '../../TextField';
13
+ import { TextField } from 'tycho-storybook';
14
14
 
15
15
  type Props = {
16
16
  document: string;
@@ -4,21 +4,23 @@ import { initReactI18next } from 'react-i18next';
4
4
  import { ParticipantsTexts } from './localization/ParticipantsTexts';
5
5
  import { CommonTexts } from './localization/CommonTexts';
6
6
 
7
+ export const commonResources = {
8
+ en: {
9
+ common: CommonTexts.en,
10
+ participants: ParticipantsTexts.en,
11
+ },
12
+ 'pt-BR': {
13
+ common: CommonTexts['pt-BR'],
14
+ participants: ParticipantsTexts['pt-BR'],
15
+ },
16
+ };
17
+
7
18
  export default function commonLocalization() {
8
19
  i18n
9
20
  .use(initReactI18next)
10
21
  .use(languageDetector)
11
22
  .init({
12
- resources: {
13
- en: {
14
- common: CommonTexts.en,
15
- participants: ParticipantsTexts.en,
16
- },
17
- 'pt-BR': {
18
- common: CommonTexts['pt-BR'],
19
- participants: ParticipantsTexts['pt-BR'],
20
- },
21
- },
23
+ resources: commonResources,
22
24
  fallbackLng: 'en',
23
25
  defaultNS: 'message',
24
26
  interpolation: {
package/src/index.ts CHANGED
@@ -5,4 +5,5 @@ export { default as Participants } from './Participants';
5
5
  export { default as AppModal } from './AppModal';
6
6
  export { default as AppModalConfirm } from './AppModal/AppModalConfirm';
7
7
  export { default as AppModalRemove } from './AppModal/AppModalRemove';
8
- export { default as commonLocalization } from './configs/Localization';
8
+ export { commonResources } from './configs/Localization';
9
+ export { CommonProvider } from './configs/CommonContext';
@@ -1,54 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
- import { useForm } from 'react-hook-form';
3
- import TextField from './TextField';
4
-
5
- const meta = {
6
- title: 'Components/TextField',
7
- component: TextField,
8
- parameters: {
9
- layout: 'padded',
10
- },
11
- tags: ['autodocs'],
12
- argTypes: {
13
- label: { control: 'text' },
14
- attr: { control: 'text' },
15
- createdForm: { control: false },
16
- className: { control: 'text' },
17
- title: { control: 'text' },
18
- placeholder: { control: 'text' },
19
- disabled: { control: 'boolean' },
20
- multiline: { control: 'boolean' },
21
- maxChars: { control: 'text' },
22
- showEndAdornment: { control: 'boolean' },
23
- onChange: { action: 'changed' },
24
- },
25
- } satisfies Meta<typeof TextField>;
26
-
27
- export default meta;
28
- type Story = StoryObj<typeof meta>;
29
-
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- const template = (args: any) => {
32
- const createdForm = useForm({
33
- defaultValues: {
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
35
- [args.attr]: '',
36
- },
37
- });
38
-
39
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
- const handleChange = (attr: string, value: any) => {
41
- console.log(`Attribute: ${attr}, Value: ${String(value)}`);
42
- };
43
-
44
- return (
45
- <TextField {...args} createdForm={createdForm} onChange={handleChange} />
46
- );
47
- };
48
-
49
- export const Default = template.bind({});
50
- // @ts-expect-error: Suppress error for args property assignment
51
- Default.args = {
52
- attr: 'title',
53
- label: 'Title',
54
- };
@@ -1,172 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
2
- import { InputAdornment, TextField as MuiTextField } from '@mui/material';
3
- import { ThemeProvider, useTheme } from '@mui/material/styles';
4
- import cx from 'classnames';
5
- import { useEffect, useState } from 'react';
6
- import { Controller, UseFormReturn } from 'react-hook-form';
7
- import { textFieldTheme } from './TextFieldTheme';
8
- import { setCurrentInput } from './inputRefManager';
9
- import './styles.scss';
10
-
11
- type Props = {
12
- attr: string;
13
- label: string;
14
- createdForm: UseFormReturn<any, any, any>;
15
- className?: string;
16
- disabled?: boolean;
17
- multiline?: boolean;
18
- title?: string;
19
- placeholder?: string;
20
- maxChars?: number;
21
- required?: boolean;
22
- showEndAdornment?: boolean;
23
- startAdornment?: React.ReactNode;
24
- onChange?: (attr: string, value: any) => void;
25
- onFocus?: (
26
- e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement, Element>
27
- ) => void;
28
- onRemove?: () => void;
29
- password?: boolean;
30
- rows?: number;
31
- hideInfoIcon?: boolean;
32
- };
33
-
34
- export default function TextField({
35
- className,
36
- attr,
37
- label,
38
- createdForm,
39
- disabled,
40
- title,
41
- placeholder,
42
- multiline,
43
- maxChars,
44
- required,
45
- startAdornment,
46
- showEndAdornment = true,
47
- onChange,
48
- onFocus,
49
- onRemove,
50
- password,
51
- rows = 4,
52
- hideInfoIcon,
53
- }: Props) {
54
- const outerTheme = useTheme();
55
- const [showPassword, setShowPassword] = useState(false);
56
- const [active, setActive] = useState(false);
57
- const [focus, setFocus] = useState(false);
58
- const [mouseOver, setMouseOver] = useState(false);
59
-
60
- const hasError = () => createdForm.formState.errors[attr];
61
-
62
- const getClassNames = cx('ds-input-text', className, {
63
- disabled: disabled,
64
- });
65
-
66
- useEffect(() => {
67
- if (focus || mouseOver) {
68
- setActive(true);
69
- } else {
70
- setActive(false);
71
- }
72
- }, [focus, mouseOver]);
73
-
74
- return (
75
- <div className={getClassNames}>
76
- <Controller
77
- name={attr}
78
- control={createdForm.control}
79
- render={({ field }) => (
80
- <ThemeProvider theme={textFieldTheme(outerTheme)}>
81
- <MuiTextField
82
- {...field}
83
- label={label}
84
- value={field.value || ''}
85
- type={
86
- password === undefined
87
- ? 'text'
88
- : showPassword
89
- ? 'text'
90
- : 'password'
91
- }
92
- fullWidth
93
- required={required}
94
- disabled={disabled}
95
- variant="filled"
96
- placeholder={!focus ? placeholder : ''}
97
- color="error"
98
- multiline={multiline}
99
- minRows={rows}
100
- slotProps={{
101
- inputLabel: {
102
- shrink: true,
103
- },
104
- }}
105
- onFocus={(e) => {
106
- setCurrentInput(e.target, (e: any) => {
107
- field.onChange(e);
108
- onChange && onChange(attr, e.target.value);
109
- });
110
- setFocus(true);
111
- onFocus && onFocus(e);
112
- }}
113
- onBlur={() => setFocus(false)}
114
- onMouseOver={() => setMouseOver(true)}
115
- onMouseOut={() => setMouseOver(false)}
116
- onChange={(event) => {
117
- field.onChange(event);
118
- onChange && onChange(attr, event.target.value);
119
- }}
120
- sx={{
121
- borderColor: disabled
122
- ? '#BEBFC1'
123
- : hasError()
124
- ? '#C6080A'
125
- : active
126
- ? '#1C83F4'
127
- : '#BEBFC1',
128
- '.MuiInputLabel-root': {
129
- color: disabled
130
- ? '#BEBFC1'
131
- : hasError()
132
- ? '#C6080A'
133
- : active
134
- ? '#1C83F4'
135
- : '#000000',
136
- },
137
- '.MuiInputBase-root': {
138
- paddingTop: multiline ? '12px' : '4px',
139
- height: multiline ? 'auto' : '48px',
140
- },
141
- '& .MuiInputBase-inputMultiline': {
142
- paddingTop: '24px',
143
- paddingBottom: '16px',
144
- },
145
- '& .MuiInputBase-input': {
146
- paddingTop: multiline ? 'none' : '16px',
147
- },
148
- '& .MuiInputAdornment-positionEnd': {
149
- paddingTop: multiline ? '12px' : '0px',
150
- },
151
- }}
152
- />
153
-
154
- {maxChars && (
155
- <div className="character-counter">
156
- {field.value?.length || 0}/{maxChars}
157
- </div>
158
- )}
159
-
160
- {title && !hasError() && <div className="helper">{title}</div>}
161
-
162
- {hasError() && (
163
- <div className="helper error">
164
- {String(createdForm.formState.errors[attr]?.message)}
165
- </div>
166
- )}
167
- </ThemeProvider>
168
- )}
169
- />
170
- </div>
171
- );
172
- }
@@ -1,70 +0,0 @@
1
- import { createTheme, Theme } from '@mui/material/styles';
2
-
3
- export const textFieldTheme = (outerTheme: Theme) =>
4
- createTheme({
5
- ...outerTheme,
6
- components: {
7
- MuiTextField: {
8
- styleOverrides: {
9
- root: {
10
- backgroundColor: 'white',
11
- padding: '0px',
12
- border: '1px solid #EAEAEB',
13
- borderRadius: '4px',
14
- '& .MuiInputBase-root': {
15
- padding: '0px!important',
16
- backgroundColor: 'white',
17
- borderBottomLeftRadius: '4px',
18
- borderBottomRightRadius: '4px',
19
- },
20
- '& .MuiFilledInput-root::before': {
21
- content: 'none',
22
- },
23
- '& .MuiFilledInput-root::after': {
24
- content: 'none',
25
- },
26
- '& .MuiInputLabel-root': {
27
- paddingLeft: '4px',
28
- color: '#000000',
29
- textTransform: 'uppercase',
30
- // helper-medium-1
31
- fontSize: '12px',
32
- fontWeight: '400',
33
- lineHeight: '100%',
34
- letterSpacing: '0.16px',
35
- fontFamily: 'Work Sans, sans-serif',
36
- },
37
- '& .MuiInputAdornment-root': {
38
- height: '100%',
39
- maxHeight: '100%',
40
- },
41
- '& .MuiInputAdornment-positionStart': {
42
- margin: '0px!important',
43
- padding: '0px!important',
44
- },
45
- '& .MuiInputAdornment-positionEnd': {
46
- margin: '0px 16px auto!important',
47
- },
48
- '& .MuiInputBase-input': {
49
- padding: '0px 16px',
50
- height: '48px',
51
- // label-medium-1
52
- fontSize: '16px',
53
- fontWeight: '400',
54
- lineHeight: '120%',
55
- letterSpacing: '0px',
56
- fontFamily: 'Work Sans, sans-serif',
57
- '&::placeholder': {
58
- color: '#707276',
59
- },
60
- '&:-webkit-autofill': {
61
- WebkitBoxShadow: '0 0 0px 1000px transparent inset !important',
62
- WebkitTextFillColor: '#000 !important',
63
- transition: 'background-color 5000s ease-in-out 0s', // Prevents flashing
64
- },
65
- },
66
- },
67
- },
68
- },
69
- },
70
- });
@@ -1,3 +0,0 @@
1
- import TextField from './TextField';
2
-
3
- export default TextField;
@@ -1,24 +0,0 @@
1
- let currentInput: HTMLInputElement | HTMLTextAreaElement | null = null;
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- let currentOnChange: ((e: any) => void) | null = null;
4
-
5
- export function removeCurrentInput() {
6
- currentInput = null;
7
- }
8
-
9
- export function setCurrentInput(
10
- input: HTMLInputElement | HTMLTextAreaElement | null,
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- onChange: (e: any) => void
13
- ) {
14
- currentInput = input;
15
- currentOnChange = onChange;
16
- }
17
-
18
- export function getCurrentInput() {
19
- return currentInput;
20
- }
21
-
22
- export function getCurrentOnChange() {
23
- return currentOnChange;
24
- }
@@ -1,36 +0,0 @@
1
- @use '../new-styles/main' as *;
2
-
3
- .ds-input-text {
4
- width: 100%;
5
- position: relative;
6
-
7
- > .helper {
8
- @include helper-small-1;
9
- margin-top: 4px;
10
-
11
- &.error {
12
- color: var(--text-error);
13
- }
14
- }
15
-
16
- .icon-info {
17
- color: var(--icon-tertiary);
18
- }
19
-
20
- &.disabled {
21
- color: var(--text-on-disabled);
22
- cursor: not-allowed;
23
-
24
- input {
25
- cursor: not-allowed;
26
- }
27
- }
28
-
29
- .character-counter {
30
- @include helper-small-1;
31
- color: var(--text-placeholder);
32
- position: absolute;
33
- bottom: 12px;
34
- left: 16px;
35
- }
36
- }