@registrucentras/rc-ses-react-components 1.7.0 → 1.7.1

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.
@@ -4,4 +4,4 @@ declare const meta: Meta<typeof RcSesServiceHeader>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof meta>;
6
6
  export declare const Default: Story;
7
- export declare const WhiteBackground: Story;
7
+ export declare const CustomBackground: Story;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@registrucentras/rc-ses-react-components",
3
3
  "author": "VĮ REGISTRŲ CENTRAS",
4
- "version": "1.7.0",
4
+ "version": "1.7.1",
5
5
  "description": "RC SES React komponentų biblioteka",
6
6
  "type": "module",
7
7
  "private": false,
@@ -15,6 +15,11 @@ export const SNACKBAR_DURATION = 10000 // 10s
15
15
 
16
16
  export const SNACKBAR_ICON_SIZE = { width: 18, height: 20 }
17
17
 
18
+ export const SNACKBAR_CHAR_LIMITS: Record<SnackbarSize, number> = {
19
+ standard: 120,
20
+ compact: 60,
21
+ }
22
+
18
23
  export const stateConfig: Record<
19
24
  SnackbarState,
20
25
  {
@@ -6,14 +6,20 @@ import {
6
6
  useMediaQuery,
7
7
  useTheme,
8
8
  } from '@mui/material'
9
- import { useEffect, useState } from 'react'
9
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react'
10
10
  import { useTranslation } from 'react-i18next'
11
11
 
12
12
  import CloseIcon from '@/assets/icons/CloseIcon'
13
13
  import { grey } from '@/theme/palette'
14
14
 
15
15
  import RcSesButton from '../Button'
16
- import { SNACKBAR_DURATION, SNACKBAR_ICON_SIZE, sizeConfig, stateConfig } from './config'
16
+ import {
17
+ SNACKBAR_CHAR_LIMITS,
18
+ SNACKBAR_DURATION,
19
+ SNACKBAR_ICON_SIZE,
20
+ sizeConfig,
21
+ stateConfig,
22
+ } from './config'
17
23
  import { type SnackbarSize, type SnackbarState } from './types'
18
24
 
19
25
  export interface RcSesSnackbarProps {
@@ -58,6 +64,18 @@ function RcSesSnackbar({
58
64
  const config = stateConfig[state]
59
65
  const StateIcon = config.icon
60
66
  const isStandard = size === 'standard'
67
+ const charLimit = SNACKBAR_CHAR_LIMITS[size]
68
+ const truncatedMessage =
69
+ message.length > charLimit ? `${message.slice(0, charLimit)}...` : message
70
+
71
+ const textRef = useRef<HTMLSpanElement>(null)
72
+ const [isMultiline, setIsMultiline] = useState(false)
73
+ useLayoutEffect(() => {
74
+ const el = textRef.current
75
+ if (!el) return
76
+ const singleLineHeight = parseFloat(getComputedStyle(el).lineHeight)
77
+ setIsMultiline(el.clientHeight > singleLineHeight + 4)
78
+ }, [truncatedMessage])
61
79
 
62
80
  const handleClose = () => {
63
81
  setInternalOpen(false)
@@ -92,7 +110,7 @@ function RcSesSnackbar({
92
110
  aria-atomic='true'
93
111
  sx={{
94
112
  display: 'flex',
95
- alignItems: 'center',
113
+ alignItems: isMultiline ? 'flex-start' : 'center',
96
114
  gap: theme.spacing(1),
97
115
  width: `${sizeConfig[size].width}px`,
98
116
  maxHeight: `${sizeConfig[size].maxHeight}px`,
@@ -108,8 +126,9 @@ function RcSesSnackbar({
108
126
  sx={{
109
127
  flexShrink: 0,
110
128
  display: 'flex',
111
- alignItems: 'center',
129
+ alignItems: isMultiline ? 'flex-start' : 'center',
112
130
  justifyContent: 'center',
131
+ pt: isMultiline ? '2px' : 0,
113
132
  '& svg': {
114
133
  width: `${SNACKBAR_ICON_SIZE.width}px !important`,
115
134
  height: `${SNACKBAR_ICON_SIZE.height}px !important`,
@@ -119,18 +138,14 @@ function RcSesSnackbar({
119
138
  <StateIcon fillColor={config.color} aria-hidden />
120
139
  </Box>
121
140
  <Typography
141
+ ref={textRef}
122
142
  variant='body2'
123
143
  sx={{
124
144
  flex: 1,
125
145
  minWidth: 0,
126
- overflow: 'hidden',
127
- display: '-webkit-box',
128
- WebkitBoxOrient: 'vertical',
129
- WebkitLineClamp: 3,
130
- textOverflow: 'ellipsis',
131
146
  }}
132
147
  >
133
- {message}
148
+ {truncatedMessage}
134
149
  </Typography>
135
150
  <Box sx={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
136
151
  {onAction && isStandard && (
@@ -1,26 +1,24 @@
1
1
  import { Box, Container, Typography } from '@mui/material'
2
- import React from 'react'
2
+ import React, { type CSSProperties } from 'react'
3
3
 
4
4
  import RcSesBreadcrumbs from '@/components/common/Breadcrumbs'
5
5
  import theme from '@/theme/light'
6
- import Colors, { common } from '@/theme/palette'
6
+ import { common } from '@/theme/palette'
7
7
 
8
8
  type Props = {
9
9
  breadcrumbsProps: React.ComponentProps<typeof RcSesBreadcrumbs>
10
10
  children?: React.ReactNode
11
11
  title: string
12
- backgroundColor?: 'primary' | 'white'
12
+ backgroundColor?: CSSProperties['backgroundColor']
13
13
  }
14
14
  function ServiceHeader({
15
15
  breadcrumbsProps,
16
16
  children,
17
17
  title,
18
- backgroundColor = 'primary',
18
+ backgroundColor = common.white,
19
19
  }: Props) {
20
- const bgColor = backgroundColor === 'white' ? common.white : Colors.primary['50']
21
-
22
20
  return (
23
- <Box sx={{ backgroundColor: bgColor }}>
21
+ <Box sx={{ backgroundColor }}>
24
22
  <Container
25
23
  sx={{
26
24
  pb: { xs: '2rem', md: '2.25rem' },
@@ -463,7 +463,7 @@ function SnackbarDemoLongText() {
463
463
  showSnackbar({
464
464
  state: 'info',
465
465
  message:
466
- 'Tai yra labai ilgas pranešimas kuris turėtų būti trumpintas su elipsu jei nepakanka vietos komponente. Šis tekstas skirtas testuoti teksto trumpinimą',
466
+ 'Tai yra labai ilgas pranešimas kuris turėtų būti trumpintas su elipsu jei nepakanka vietos komponente. Šis tekstas skirtas testuoti teksto trumpinimą, tai yra labai labai labai ilgas tekstas testavimui.',
467
467
  showClose: true,
468
468
  })
469
469
  }
@@ -3,8 +3,7 @@ import { Meta, StoryObj } from '@storybook/react'
3
3
  import React from 'react'
4
4
 
5
5
  import RcSesServiceHeader from '@/components/layout/ServiceHeader'
6
-
7
- type ServiceHeaderProps = React.ComponentProps<typeof RcSesServiceHeader>
6
+ import { common, grey } from '@/theme/palette'
8
7
 
9
8
  const meta: Meta<typeof RcSesServiceHeader> = {
10
9
  title: 'components/layout/ServiceHeader',
@@ -13,13 +12,7 @@ const meta: Meta<typeof RcSesServiceHeader> = {
13
12
  argTypes: {
14
13
  title: { control: 'text' },
15
14
  children: { control: 'text' },
16
- backgroundColor: {
17
- control: 'inline-radio',
18
- options: ['primary', 'white'],
19
- table: {
20
- defaultValue: { summary: 'primary' },
21
- },
22
- },
15
+ backgroundColor: { control: 'text' },
23
16
  },
24
17
  }
25
18
 
@@ -39,31 +32,31 @@ export const Default: Story = {
39
32
  title: 'Service Title',
40
33
  children: 'This is a description of the service.',
41
34
  breadcrumbsProps: breadcrumbs,
42
- backgroundColor: 'primary',
35
+ backgroundColor: common.white,
43
36
  },
44
37
  render: (args) => (
45
38
  <RcSesServiceHeader
46
39
  title={args.title}
47
40
  breadcrumbsProps={args.breadcrumbsProps}
48
- backgroundColor={args.backgroundColor as ServiceHeaderProps['backgroundColor']}
41
+ backgroundColor={args.backgroundColor}
49
42
  >
50
43
  {args.children && <Typography variant='body1'>{args.children}</Typography>}
51
44
  </RcSesServiceHeader>
52
45
  ),
53
46
  }
54
47
 
55
- export const WhiteBackground: Story = {
48
+ export const CustomBackground: Story = {
56
49
  args: {
57
50
  title: 'Service Title',
58
- children: 'This is a description of the service.',
51
+ children: 'This is a description of the service with custom background.',
59
52
  breadcrumbsProps: breadcrumbs,
60
- backgroundColor: 'white',
53
+ backgroundColor: grey['100'],
61
54
  },
62
55
  render: (args) => (
63
56
  <RcSesServiceHeader
64
57
  title={args.title}
65
58
  breadcrumbsProps={args.breadcrumbsProps}
66
- backgroundColor={args.backgroundColor as ServiceHeaderProps['backgroundColor']}
59
+ backgroundColor={args.backgroundColor}
67
60
  >
68
61
  {args.children && <Typography variant='body1'>{args.children}</Typography>}
69
62
  </RcSesServiceHeader>