@registrucentras/rc-ses-react-components 1.7.1 → 1.8.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 (44) hide show
  1. package/dist/assets/icons/CheckCircleFillIcon.d.ts +1 -1
  2. package/dist/assets/icons/CopyIcon.d.ts +3 -0
  3. package/dist/assets/icons/InfoFillIcon.d.ts +1 -1
  4. package/dist/assets/icons/QuestionFillIcon.d.ts +1 -1
  5. package/dist/assets/icons/WarningFillIcon.d.ts +1 -1
  6. package/dist/components/LoadingSpinner/LoadingSpinner.d.ts +10 -0
  7. package/dist/components/common/Button/index.d.ts +1 -1
  8. package/dist/components/overlays/Dialog/index.d.ts +11 -0
  9. package/dist/components/overlays/Modal/index.d.ts +16 -0
  10. package/dist/library/icons.d.ts +2 -1
  11. package/dist/library/index.d.ts +4 -1
  12. package/dist/library/types.d.ts +6 -1
  13. package/dist/registrucentras-rc-ses-react-components.cjs +10 -10
  14. package/dist/registrucentras-rc-ses-react-components.js +1897 -1662
  15. package/dist/stories/components/actions/Button.stories.d.ts +26 -0
  16. package/dist/stories/components/overlays/Dialog.stories.d.ts +9 -0
  17. package/dist/stories/components/overlays/Modal.stories.d.ts +10 -0
  18. package/dist/stories/components/spinner/LoadingSpinner.stories.d.ts +62 -0
  19. package/package.json +1 -1
  20. package/src/assets/icons/CheckCircleFillIcon.tsx +8 -2
  21. package/src/assets/icons/CopyIcon.tsx +23 -0
  22. package/src/assets/icons/InfoFillIcon.tsx +8 -2
  23. package/src/assets/icons/QuestionFillIcon.tsx +8 -2
  24. package/src/assets/icons/WarningFillIcon.tsx +8 -2
  25. package/src/components/LoadingSpinner/LoadingSpinner.test.tsx +48 -0
  26. package/src/components/LoadingSpinner/LoadingSpinner.tsx +70 -0
  27. package/src/components/common/Button/index.test.tsx +175 -0
  28. package/src/components/common/Button/index.tsx +48 -4
  29. package/src/components/overlays/Dialog/index.test.tsx +85 -0
  30. package/src/components/overlays/Dialog/index.tsx +85 -0
  31. package/src/components/overlays/Modal/index.test.tsx +94 -0
  32. package/src/components/overlays/Modal/index.tsx +116 -0
  33. package/src/i18n/namespaces/common/en.json +3 -0
  34. package/src/i18n/namespaces/common/lt.json +3 -0
  35. package/src/i18n/namespaces/input/en.json +18 -0
  36. package/src/i18n/namespaces/input/lt.json +18 -0
  37. package/src/library/icons.ts +2 -0
  38. package/src/library/index.ts +6 -0
  39. package/src/library/types.ts +10 -0
  40. package/src/stories/components/actions/Button.stories.tsx +201 -0
  41. package/src/stories/components/icons/Icons.stories.tsx +5 -0
  42. package/src/stories/components/overlays/Dialog.stories.tsx +271 -0
  43. package/src/stories/components/overlays/Modal.stories.tsx +98 -0
  44. package/src/stories/components/spinner/LoadingSpinner.stories.tsx +126 -0
@@ -0,0 +1,85 @@
1
+ import { Button } from '@mui/material'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { describe, expect, it } from 'vitest'
4
+
5
+ import RcSesDialog from './index'
6
+
7
+ describe('RcSesDialog', () => {
8
+ it('should render dialog title', () => {
9
+ render(<RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>} />)
10
+
11
+ expect(screen.getByText('Test Title')).toBeInTheDocument()
12
+ })
13
+
14
+ it('should render children when provided', () => {
15
+ render(
16
+ <RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>}>
17
+ Test Content
18
+ </RcSesDialog>,
19
+ )
20
+
21
+ expect(screen.getByText('Test Content')).toBeInTheDocument()
22
+ })
23
+
24
+ it('should not render DialogContent when children are not provided', () => {
25
+ render(<RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>} />)
26
+
27
+ const dialogContent = document.querySelector('.MuiDialogContent-root')
28
+ expect(dialogContent).not.toBeInTheDocument()
29
+ })
30
+
31
+ it('should render actions', () => {
32
+ render(
33
+ <RcSesDialog open dialogTitle='Test Title' actions={<Button>Submit</Button>} />,
34
+ )
35
+
36
+ expect(screen.getByText('Submit')).toBeInTheDocument()
37
+ })
38
+
39
+ it('should apply medium size by default', () => {
40
+ render(<RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>} />)
41
+
42
+ const paper = document.querySelector('.MuiDialog-paper')
43
+ expect(paper).toHaveStyle({ width: '600px' })
44
+ })
45
+
46
+ it('should apply small size (480px)', () => {
47
+ render(
48
+ <RcSesDialog
49
+ open
50
+ size='sm'
51
+ dialogTitle='Test Title'
52
+ actions={<Button>Close</Button>}
53
+ />,
54
+ )
55
+
56
+ const paper = document.querySelector('.MuiDialog-paper')
57
+ expect(paper).toHaveStyle({ width: '480px' })
58
+ })
59
+
60
+ it('should apply large size (800px)', () => {
61
+ render(
62
+ <RcSesDialog
63
+ open
64
+ size='lg'
65
+ dialogTitle='Test Title'
66
+ actions={<Button>Close</Button>}
67
+ />,
68
+ )
69
+
70
+ const paper = document.querySelector('.MuiDialog-paper')
71
+ expect(paper).toHaveStyle({ width: '800px' })
72
+ })
73
+
74
+ it('should render ReactNode as title', () => {
75
+ render(
76
+ <RcSesDialog
77
+ open
78
+ dialogTitle={<h2>Custom Title Element</h2>}
79
+ actions={<Button>Close</Button>}
80
+ />,
81
+ )
82
+
83
+ expect(screen.getByText('Custom Title Element')).toBeInTheDocument()
84
+ })
85
+ })
@@ -0,0 +1,85 @@
1
+ import {
2
+ DialogActions,
3
+ DialogContent,
4
+ DialogTitle,
5
+ Dialog as MuiDialog,
6
+ DialogProps as MuiDialogProps,
7
+ } from '@mui/material'
8
+ import { ReactNode, useId } from 'react'
9
+
10
+ export type DialogSize = 'sm' | 'md' | 'lg'
11
+
12
+ const SIZE_MAP: Record<DialogSize, string> = {
13
+ sm: '480px',
14
+ md: '600px',
15
+ lg: '800px',
16
+ }
17
+
18
+ export interface RcSesDialogProps
19
+ extends Omit<MuiDialogProps, 'children' | 'title' | 'PaperProps' | 'maxWidth'> {
20
+ dialogTitle: string | ReactNode
21
+ children?: ReactNode
22
+ actions: ReactNode
23
+ size?: DialogSize
24
+ }
25
+
26
+ function RcSesDialog({
27
+ dialogTitle,
28
+ children,
29
+ actions,
30
+ onClose,
31
+ size = 'md',
32
+ ...props
33
+ }: RcSesDialogProps) {
34
+ const dialogWidth = SIZE_MAP[size]
35
+ const titleId = useId()
36
+ const contentId = useId()
37
+
38
+ return (
39
+ <MuiDialog
40
+ onClose={onClose}
41
+ {...props}
42
+ maxWidth={false}
43
+ PaperProps={{ sx: { width: dialogWidth, borderRadius: '16px' } }}
44
+ aria-labelledby={titleId}
45
+ aria-describedby={children ? contentId : undefined}
46
+ >
47
+ <DialogTitle
48
+ id={titleId}
49
+ sx={{
50
+ display: 'flex',
51
+ justifyContent: 'space-between',
52
+ alignItems: 'flex-start',
53
+ fontSize: '24px',
54
+ lineHeight: '32px',
55
+ padding: '2rem 2rem 1rem !important',
56
+ }}
57
+ >
58
+ {dialogTitle}
59
+ </DialogTitle>
60
+
61
+ {children && (
62
+ <DialogContent
63
+ id={contentId}
64
+ sx={{
65
+ padding: '0 2rem !important',
66
+ }}
67
+ >
68
+ {children}
69
+ </DialogContent>
70
+ )}
71
+
72
+ {actions && (
73
+ <DialogActions
74
+ sx={{
75
+ padding: '1.25rem 2rem 2rem !important',
76
+ }}
77
+ >
78
+ {actions}
79
+ </DialogActions>
80
+ )}
81
+ </MuiDialog>
82
+ )
83
+ }
84
+
85
+ export default RcSesDialog
@@ -0,0 +1,94 @@
1
+ import { render, screen } from '@testing-library/react'
2
+ import i18n from 'i18next'
3
+ import { I18nextProvider } from 'react-i18next'
4
+ import { beforeAll, describe, expect, it, vi } from 'vitest'
5
+
6
+ import inputEn from '@/i18n/namespaces/input/en.json'
7
+ import inputLt from '@/i18n/namespaces/input/lt.json'
8
+
9
+ import RcSesModal from './index'
10
+
11
+ beforeAll(() => {
12
+ if (!i18n.isInitialized) {
13
+ i18n.init({
14
+ lng: 'lt',
15
+ resources: {
16
+ lt: { input: inputLt },
17
+ en: { input: inputEn },
18
+ },
19
+ })
20
+ }
21
+ })
22
+
23
+ describe('RcSesModal', () => {
24
+ it('renders title and message', () => {
25
+ render(
26
+ <I18nextProvider i18n={i18n}>
27
+ <RcSesModal
28
+ open
29
+ onClose={vi.fn()}
30
+ title='Test Title'
31
+ message='Test Message'
32
+ onPrimaryAction={vi.fn()}
33
+ />
34
+ </I18nextProvider>,
35
+ )
36
+
37
+ expect(screen.getByText('Test Title')).toBeInTheDocument()
38
+ expect(screen.getByText('Test Message')).toBeInTheDocument()
39
+ })
40
+
41
+ it('renders success variant with only primary button', () => {
42
+ const onPrimary = vi.fn()
43
+
44
+ render(
45
+ <I18nextProvider i18n={i18n}>
46
+ <RcSesModal
47
+ open
48
+ onClose={vi.fn()}
49
+ title='Success!'
50
+ message='Operation complete'
51
+ variant='success'
52
+ onPrimaryAction={onPrimary}
53
+ />
54
+ </I18nextProvider>,
55
+ )
56
+
57
+ const buttons = screen.getAllByRole('button')
58
+ expect(buttons.length).toBe(1)
59
+ })
60
+
61
+ it('uses custom primary label when provided', () => {
62
+ render(
63
+ <I18nextProvider i18n={i18n}>
64
+ <RcSesModal
65
+ open
66
+ onClose={vi.fn()}
67
+ title='Test'
68
+ message='Test Message'
69
+ primaryActionLabel='Custom Label'
70
+ onPrimaryAction={vi.fn()}
71
+ />
72
+ </I18nextProvider>,
73
+ )
74
+
75
+ expect(screen.getByText('Custom Label')).toBeInTheDocument()
76
+ })
77
+
78
+ it('renders custom actions when provided', () => {
79
+ render(
80
+ <I18nextProvider i18n={i18n}>
81
+ <RcSesModal
82
+ open
83
+ onClose={vi.fn()}
84
+ title='Test'
85
+ message='Test Message'
86
+ actions={<button type='button'>Custom Action</button>}
87
+ onPrimaryAction={vi.fn()}
88
+ />
89
+ </I18nextProvider>,
90
+ )
91
+
92
+ expect(screen.getByText('Custom Action')).toBeInTheDocument()
93
+ })
94
+ })
@@ -0,0 +1,116 @@
1
+ import { Button, Typography } from '@mui/material'
2
+ import { ReactNode } from 'react'
3
+ import { useTranslation } from 'react-i18next'
4
+
5
+ import CheckCircleFillIcon from '@/assets/icons/CheckCircleFillIcon'
6
+ import InfoFillIcon from '@/assets/icons/InfoFillIcon'
7
+ import QuestionFillIcon from '@/assets/icons/QuestionFillIcon'
8
+ import WarningFillIcon from '@/assets/icons/WarningFillIcon'
9
+ import palette from '@/theme/palette'
10
+
11
+ import RcSesDialog, { RcSesDialogProps } from '../Dialog'
12
+
13
+ export type ModalVariant = 'destructive' | 'confirm' | 'success' | 'info'
14
+
15
+ const VARIANT_CONFIG: Record<ModalVariant, { icon: ReactNode }> = {
16
+ destructive: {
17
+ icon: <WarningFillIcon size={36} weight='regular' fillColor={palette.error['600']} />,
18
+ },
19
+ confirm: {
20
+ icon: <QuestionFillIcon size={36} weight='regular' fillColor={palette.grey['700']} />,
21
+ },
22
+ success: {
23
+ icon: (
24
+ <CheckCircleFillIcon
25
+ size={36}
26
+ weight='regular'
27
+ fillColor={palette.secondary['600']}
28
+ />
29
+ ),
30
+ },
31
+ info: {
32
+ icon: <InfoFillIcon size={36} weight='regular' fillColor={palette.primary['500']} />,
33
+ },
34
+ }
35
+
36
+ export interface RcSesModalProps
37
+ extends Omit<RcSesDialogProps, 'children' | 'dialogTitle' | 'actions'> {
38
+ title: string
39
+ message: ReactNode
40
+ variant?: ModalVariant
41
+ showIcon?: boolean
42
+ onPrimaryAction?: () => void
43
+ onSecondaryAction?: () => void
44
+ primaryActionLabel?: string
45
+ secondaryActionLabel?: string
46
+ actions?: ReactNode
47
+ }
48
+
49
+ function RcSesModal({
50
+ title,
51
+ message,
52
+ variant = 'info',
53
+ showIcon = false,
54
+ onPrimaryAction,
55
+ onSecondaryAction,
56
+ primaryActionLabel,
57
+ secondaryActionLabel,
58
+ actions: customActions,
59
+ ...props
60
+ }: RcSesModalProps) {
61
+ const { t } = useTranslation('input', { keyPrefix: 'components.Modal' })
62
+ const config = VARIANT_CONFIG[variant]
63
+
64
+ const getPrimaryLabel = () => {
65
+ if (primaryActionLabel) return primaryActionLabel
66
+ return t(`actions.${variant}.primary`)
67
+ }
68
+
69
+ const getSecondaryLabel = () => {
70
+ if (secondaryActionLabel) return secondaryActionLabel
71
+ return t('actions.cancel')
72
+ }
73
+
74
+ const titleContent = showIcon ? (
75
+ <div
76
+ style={{
77
+ display: 'flex',
78
+ flexDirection: 'column',
79
+ alignItems: 'flex-start',
80
+ gap: 8,
81
+ }}
82
+ >
83
+ <div aria-hidden='true'>{config.icon}</div>
84
+ {title}
85
+ </div>
86
+ ) : (
87
+ title
88
+ )
89
+
90
+ const defaultActions = (
91
+ <>
92
+ {(variant === 'destructive' || variant === 'confirm') && (
93
+ <Button onClick={onSecondaryAction} variant='outlined' color='grey'>
94
+ {getSecondaryLabel()}
95
+ </Button>
96
+ )}
97
+ <Button
98
+ onClick={onPrimaryAction}
99
+ variant='contained'
100
+ color={variant === 'destructive' ? 'error' : 'primary'}
101
+ >
102
+ {getPrimaryLabel()}
103
+ </Button>
104
+ </>
105
+ )
106
+
107
+ const actions = customActions || defaultActions
108
+
109
+ return (
110
+ <RcSesDialog dialogTitle={titleContent} actions={actions} {...props}>
111
+ <Typography variant='body1'>{message}</Typography>
112
+ </RcSesDialog>
113
+ )
114
+ }
115
+
116
+ export default RcSesModal
@@ -4,6 +4,9 @@
4
4
  "draft": "Save for later",
5
5
  "discard": "Discard and delete form data",
6
6
  "submit": "Save and add to cart"
7
+ },
8
+ "Button": {
9
+ "loading": "Loading"
7
10
  }
8
11
  }
9
12
  }
@@ -4,6 +4,9 @@
4
4
  "draft": "Baigti pildyti vėliau",
5
5
  "discard": "Atšaukti pildymą ir ištrinti formos duomenis",
6
6
  "submit": "Baigti pildyti ir pridėti į krepšelį"
7
+ },
8
+ "Button": {
9
+ "loading": "Kraunasi"
7
10
  }
8
11
  }
9
12
  }
@@ -59,6 +59,24 @@
59
59
  "aria": {
60
60
  "close": "Close notification"
61
61
  }
62
+ },
63
+
64
+ "Modal": {
65
+ "actions": {
66
+ "destructive": {
67
+ "primary": "Remove"
68
+ },
69
+ "confirm": {
70
+ "primary": "Continue"
71
+ },
72
+ "success": {
73
+ "primary": "Close"
74
+ },
75
+ "info": {
76
+ "primary": "I understand"
77
+ },
78
+ "cancel": "Cancel"
79
+ }
62
80
  }
63
81
  }
64
82
  }
@@ -59,6 +59,24 @@
59
59
  "aria": {
60
60
  "close": "Uždaryti pranešimą"
61
61
  }
62
+ },
63
+
64
+ "Modal": {
65
+ "actions": {
66
+ "destructive": {
67
+ "primary": "Pašalinti"
68
+ },
69
+ "confirm": {
70
+ "primary": "Tęsti"
71
+ },
72
+ "success": {
73
+ "primary": "Uždaryti"
74
+ },
75
+ "info": {
76
+ "primary": "Suprantu"
77
+ },
78
+ "cancel": "Atšaukti"
79
+ }
62
80
  }
63
81
  }
64
82
  }
@@ -19,6 +19,7 @@ import CheckUncheckedBoldIcon from '@/assets/icons/CheckUncheckedBoldIcon'
19
19
  import CircleFilledIcon from '@/assets/icons/CircleFilledIcon'
20
20
  import CloseIcon from '@/assets/icons/CloseIcon'
21
21
  import CollapseChevronsIcon from '@/assets/icons/CollapseChevronsIcon'
22
+ import CopyIcon from '@/assets/icons/CopyIcon'
22
23
  import DotCircleFilledIcon from '@/assets/icons/DotCircleFilledIcon'
23
24
  import ExpandChevronsIcon from '@/assets/icons/ExpandChevronsIcon'
24
25
  import InfoFillIcon from '@/assets/icons/InfoFillIcon'
@@ -62,6 +63,7 @@ export {
62
63
  CircleFilledIcon,
63
64
  CloseIcon,
64
65
  CollapseChevronsIcon,
66
+ CopyIcon,
65
67
  DotCircleFilledIcon,
66
68
  ExpandChevronsIcon,
67
69
  InfoFillIcon,
@@ -3,6 +3,7 @@ import type {} from '@mui/system'
3
3
  import type {} from '@mui/x-date-pickers/themeAugmentation'
4
4
 
5
5
  import RcSesIconProps from '@/assets/IconProps'
6
+ import RcSesLoadingSpinner from '@/components/LoadingSpinner/LoadingSpinner'
6
7
  import RcSesAccordion from '@/components/common/Accordion'
7
8
  import useAccordionController from '@/components/common/Accordion/hooks/useAccordionController'
8
9
  import RcSesAlert from '@/components/common/Alert'
@@ -46,6 +47,8 @@ import RcSesCardFormContainer from '@/components/layout/ServiceFormContainer/Car
46
47
  import RcSesServiceHeader from '@/components/layout/ServiceHeader'
47
48
  import RcSesServicePage from '@/components/layout/ServicePage'
48
49
  import ServiceWizardStepper from '@/components/layout/ServiceWizardStepper'
50
+ import RcSesDialog from '@/components/overlays/Dialog'
51
+ import RcSesModal from '@/components/overlays/Modal'
49
52
  import RcSesTheme from '@/theme/light'
50
53
  import RcSesPalette from '@/theme/palette'
51
54
 
@@ -64,11 +67,14 @@ export {
64
67
  RcSesBreadcrumbs,
65
68
  RcSesButton,
66
69
  RcSesButtonWithPopover,
70
+ RcSesLoadingSpinner,
67
71
  RcSesCard,
72
+ RcSesDialog,
68
73
  RcSesFooter,
69
74
  RcSesImageCard,
70
75
  RcSesSnackbar,
71
76
  RcSesSnackbarProvider,
77
+ RcSesModal,
72
78
  }
73
79
  export { RcSesCheckbox, RcSesCheckboxFormControl, RcSesSimpleCheckbox }
74
80
  export { useSnackbar }
@@ -1,3 +1,7 @@
1
+ import {
2
+ RcSesLoadingSpinnerProps,
3
+ RcSesSpinnerColor,
4
+ } from '@/components/LoadingSpinner/LoadingSpinner'
1
5
  import { RcSesCardProps } from '@/components/common/Card'
2
6
  import { ListWithIconsProps } from '@/components/common/ListWithIcons'
3
7
  import { ListWithIconsItemData } from '@/components/common/ListWithIcons/ListWithIcons.types'
@@ -5,6 +9,8 @@ import { RcSesFormControlLabelProps } from '@/components/form/inputs/FormControl
5
9
  import { SimpleCheckboxProps } from '@/components/form/inputs/SimpleCheckbox'
6
10
  import { RcSesCardFormContainerProps } from '@/components/layout/ServiceFormContainer/CardFormContainer'
7
11
  import { ServiceWizardStepperProps } from '@/components/layout/ServiceWizardStepper'
12
+ import { DialogSize, RcSesDialogProps } from '@/components/overlays/Dialog'
13
+ import { ModalVariant, RcSesModalProps } from '@/components/overlays/Modal'
8
14
  import { ButtonProps } from '@/types/buttons/ButtonProps'
9
15
 
10
16
  export type { ListWithIconsProps, ListWithIconsItemData }
@@ -16,4 +22,8 @@ export type {
16
22
  ServiceWizardStepperProps,
17
23
  SimpleCheckboxProps,
18
24
  RcSesFormControlLabelProps,
25
+ RcSesLoadingSpinnerProps,
26
+ RcSesSpinnerColor,
19
27
  }
28
+ export type { RcSesDialogProps, DialogSize }
29
+ export type { RcSesModalProps, ModalVariant }