@digital-ai/dot-components 2.28.0 → 3.0.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/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import { useState, useRef, useEffect, createContext, useMemo, useContext, forwardRef, useCallback, createElement, Fragment as Fragment$1, useLayoutEffect } from 'react';
4
- import { Tooltip, Icon, Typography, Accordion, AccordionSummary, AccordionDetails, AccordionActions, InputAdornment, InputLabel, TextField, Toolbar, Alert, Fade, StyledEngineProvider, Avatar, Button, Link, List, ListSubheader, Divider, CircularProgress, Popper, MenuList, MenuItem, Paper, ClickAwayListener, Drawer, IconButton, ListItem, ListItemButton, Collapse, ListItemIcon, ListItemText, Badge, useMediaQuery, Autocomplete, Chip, AvatarGroup, Breadcrumbs, ToggleButtonGroup, ToggleButton, Card, CardContent, CardHeader, FormControlLabel, Checkbox, FormControl, FormGroup, FormLabel, FormHelperText, Dialog, DialogContent, DialogActions, useTheme as useTheme$1, RadioGroup, Radio, Switch, Skeleton, Snackbar, ButtonGroup, Stepper, Step, StepLabel, StepContent, TablePagination, TableContainer, TableBody, TableCell, TableRow, TableSortLabel, TableHead, Table, Tabs, Tab, LinearProgress, Slide } from '@mui/material';
4
+ import { Tooltip, Icon, Typography, Accordion, AccordionSummary, AccordionDetails, AccordionActions, InputAdornment, InputLabel, TextField, Toolbar, Fade, StyledEngineProvider, Alert, Avatar, Button, Link, List, ListSubheader, Divider, CircularProgress, Popper, MenuList, MenuItem, Paper, ClickAwayListener, Drawer, IconButton, ListItem, ListItemButton, Collapse, ListItemIcon, ListItemText, Badge, useMediaQuery, Autocomplete, Chip, AvatarGroup, Breadcrumbs, ToggleButtonGroup, ToggleButton, Card, CardContent, CardHeader, FormControlLabel, Checkbox, FormControl, FormGroup, FormLabel, FormHelperText, Dialog, DialogContent, DialogActions, useTheme as useTheme$1, RadioGroup, Radio, Switch, Skeleton, Snackbar, ButtonGroup, Stepper, Step, StepLabel, StepContent, TablePagination, TableContainer, TableBody, TableCell, TableRow, TableSortLabel, TableHead, Table, Tabs, Tab, LinearProgress, Slide } from '@mui/material';
5
5
  import '@digital-ai/dot-icons';
6
6
  import styled, { css, createGlobalStyle, ThemeProvider as ThemeProvider$1, keyframes } from 'styled-components';
7
7
  import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
@@ -602,73 +602,6 @@ const DotActionToolbar = ({
602
602
  });
603
603
  };
604
604
 
605
- const rootClassName$14 = 'dot-alert-banner';
606
- const StyledAlertBanner = styled(Alert)`
607
- ${({
608
- theme
609
- }) => css`
610
- &.${rootClassName$14} {
611
- align-items: center;
612
- border-radius: 8px;
613
- box-sizing: border-box;
614
- display: flex;
615
- min-height: 48px;
616
- overflow: hidden;
617
- padding: ${theme.spacing(0.75, 2)};
618
-
619
- svg,
620
- .dot-typography {
621
- color: ${theme.palette.figma.overlay.alerts.text.black};
622
- }
623
-
624
- .dot-icon,
625
- .MuiAlert-icon,
626
- .MuiAlert-message {
627
- padding: 0;
628
- .dot-typography {
629
- margin-bottom: 0;
630
- }
631
- }
632
-
633
- &.MuiAlert-standardSuccess {
634
- background: ${theme.palette.figma.overlay.alerts.success.background};
635
-
636
- .dot-icon,
637
- .MuiAlert-icon {
638
- color: ${theme.palette.figma.overlay.alerts.success.icon};
639
- }
640
- }
641
-
642
- &.MuiAlert-standardInfo {
643
- background: ${theme.palette.figma.overlay.alerts.info.background};
644
-
645
- .dot-icon,
646
- .MuiAlert-icon {
647
- color: ${theme.palette.figma.overlay.alerts.info.icon};
648
- }
649
- }
650
-
651
- &.MuiAlert-standardWarning {
652
- background: ${theme.palette.figma.overlay.alerts.warning.background};
653
-
654
- .dot-icon,
655
- .MuiAlert-icon {
656
- color: ${theme.palette.figma.overlay.alerts.warning.icon};
657
- }
658
- }
659
-
660
- &.MuiAlert-standardError {
661
- background: ${theme.palette.figma.overlay.alerts.error.background};
662
-
663
- .dot-icon,
664
- .MuiAlert-icon {
665
- color: ${theme.palette.figma.overlay.alerts.error.icon};
666
- }
667
- }
668
- }
669
- `}
670
- `;
671
-
672
605
  //Primary blue
673
606
  //https://zeroheight.com/4a9ac476a/p/22005a-color/t/6288e9
674
607
  const b50 = '#e8edf3';
@@ -1727,6 +1660,35 @@ const renderNodeOrTypography = (content, typographyVariant = 'body1') => {
1727
1660
  const checkIfArrowUpPressed = event => event.key === 'ArrowUp';
1728
1661
  const checkIfArrowDownPressed = event => event.key === 'ArrowDown';
1729
1662
 
1663
+ const rootClassName$14 = 'dot-alert-banner';
1664
+ const StyledAlertBanner = styled(Alert)`
1665
+ ${({
1666
+ theme
1667
+ }) => css`
1668
+ &.${rootClassName$14} {
1669
+ box-sizing: border-box;
1670
+ min-height: 48px;
1671
+ overflow: hidden;
1672
+
1673
+ &.MuiAlert-standardSuccess {
1674
+ background: ${theme.palette.figma.overlay.alerts.success.background};
1675
+ }
1676
+
1677
+ &.MuiAlert-standardInfo {
1678
+ background: ${theme.palette.figma.overlay.alerts.info.background};
1679
+ }
1680
+
1681
+ &.MuiAlert-standardWarning {
1682
+ background: ${theme.palette.figma.overlay.alerts.warning.background};
1683
+ }
1684
+
1685
+ &.MuiAlert-standardError {
1686
+ background: ${theme.palette.figma.overlay.alerts.error.background};
1687
+ }
1688
+ }
1689
+ `}
1690
+ `;
1691
+
1730
1692
  const DotAlertBanner = ({
1731
1693
  action,
1732
1694
  ariaLabel,
@@ -1737,19 +1699,9 @@ const DotAlertBanner = ({
1737
1699
  onClose,
1738
1700
  roundedCorners = true,
1739
1701
  severity,
1740
- textVariant = 'body1'
1702
+ textVariant = 'body1',
1703
+ width
1741
1704
  }) => {
1742
- const AlertBannerIcon = iconId => {
1743
- return jsx(DotIcon, {
1744
- iconId: iconId
1745
- });
1746
- };
1747
- const AlertBannerIconMapping = {
1748
- error: AlertBannerIcon('error-solid'),
1749
- info: AlertBannerIcon('info-solid'),
1750
- success: AlertBannerIcon('check-solid'),
1751
- warning: AlertBannerIcon('warning-solid')
1752
- };
1753
1705
  const rootClasses = useStylesWithRootClass(rootClassName$14, severity, className);
1754
1706
  /* For simple string use default component, for everything else use 'div' */
1755
1707
  const typographyComponent = isString$1(children) ? undefined : 'div';
@@ -1761,11 +1713,11 @@ const DotAlertBanner = ({
1761
1713
  },
1762
1714
  "data-pendoid": dataPendoId,
1763
1715
  "data-testid": dataTestId,
1764
- iconMapping: AlertBannerIconMapping,
1765
1716
  onClose: onClose,
1766
1717
  severity: severity,
1767
1718
  style: {
1768
- borderRadius: roundedCorners ? '8px' : undefined
1719
+ borderRadius: roundedCorners ? '8px' : undefined,
1720
+ width
1769
1721
  },
1770
1722
  children: jsx(DotTypography, {
1771
1723
  variant: textVariant,
@@ -10222,83 +10174,71 @@ const DotSkeleton = ({
10222
10174
  });
10223
10175
  };
10224
10176
 
10177
+ function addAutoHideDuration(severity) {
10178
+ return severity === 'error' ? null : 10000;
10179
+ }
10180
+
10181
+ const getSnackbarTitleFromSeverity = severity => {
10182
+ switch (severity) {
10183
+ case 'success':
10184
+ return 'Success';
10185
+ case 'warning':
10186
+ return 'Warning';
10187
+ case 'error':
10188
+ return 'Error';
10189
+ case 'info':
10190
+ return 'Info';
10191
+ default:
10192
+ return 'Success';
10193
+ }
10194
+ };
10195
+
10225
10196
  const rootClassName$n = 'dot-snackbar';
10226
10197
  const StyledSnackbar = styled(Snackbar)`
10227
10198
  ${({
10228
- theme
10199
+ theme,
10200
+ width,
10201
+ $anchorOriginTop
10229
10202
  }) => css`
10230
- &.${rootClassName$n} {
10231
- .dot-icon-btn .dot-icon {
10232
- color: ${theme.palette.figma.icon.white};
10233
- }
10234
-
10235
- .dot-icon-btn:hover {
10236
- background: ${n900_20};
10237
- }
10203
+ &.${rootClassName$n} {
10204
+ .MuiAlert-message {
10205
+ word-break: break-word;
10206
+ }
10238
10207
 
10239
- .MuiAlert-icon {
10240
- color: ${theme.palette.figma.icon.white};
10241
- padding: 11px 0px;
10242
- }
10243
- .MuiAlert-message {
10244
- padding: 13px 0px;
10245
- word-break: break-word;
10246
- }
10247
- &.MuiSnackbar-anchorOriginTopRight{
10248
- top: 0px;
10249
- z-index: ${levelFourth};
10250
- }
10208
+ &.MuiSnackbar-anchorOriginTopLeft,
10209
+ &.MuiSnackbar-anchorOriginTopCenter,
10210
+ &.MuiSnackbar-anchorOriginTopRight {
10211
+ top: ${$anchorOriginTop}px;
10212
+ z-index: ${levelFourth};
10213
+ }
10251
10214
 
10252
- .MuiAlert-root {
10253
- color: ${theme.palette.figma.typography.white};
10254
- position: relative;
10255
- margin-top: 108px;
10256
- max-width: 500px;
10257
- min-width: 344px;
10258
- z-index: ${levelFourth};
10215
+ .dot-snackbar-actions {
10216
+ display: flex;
10217
+ align-items: center;
10218
+ margin-top: ${theme.spacing(1)};
10219
+ gap: ${theme.spacing(2)};
10259
10220
 
10260
- @media (min-width: 720px) {
10261
- .MuiAlert-root {
10262
- top: 112px;
10263
- position: relative;
10221
+ .primary-action-btn {
10222
+ background-color: transparent;
10264
10223
  }
10265
10224
  }
10266
10225
 
10267
- &.MuiAlert-standardSuccess {
10268
- background: ${theme.palette.figma.success.normal};
10269
- }
10270
- &.MuiAlert-standardInfo {
10271
- background: ${theme.palette.figma.inProgress.normal};
10272
- }
10273
- &.MuiAlert-standardWarning {
10274
- background: ${theme.palette.figma.warning.normal};
10275
- }
10276
- &.MuiAlert-standardError {
10277
- background: ${theme.palette.figma.destructive.normal};
10226
+ .MuiAlert-root {
10227
+ max-width: ${width ? 'unset' : '500px'};
10228
+ min-width: ${width ? 'unset' : '344px'};
10229
+ z-index: ${levelFourth};
10278
10230
  }
10279
10231
  }
10280
10232
  `}
10281
10233
  `;
10282
10234
 
10283
- function addAutoHideDuration(severity) {
10284
- return severity === 'error' ? null : 10000;
10285
- }
10286
-
10287
- function checkForConflictingEventHandlers({
10288
- action,
10289
- onClose
10290
- }) {
10291
- if (action && onClose) {
10292
- console.error('You have passed two event handlers for action buttons. Please pick one.');
10293
- }
10294
- }
10295
10235
  const DEFAULT_ANCHOR_ORIGIN = {
10296
10236
  vertical: 'top',
10297
10237
  horizontal: 'right'
10298
10238
  };
10299
10239
  const DotSnackbar = ({
10300
- action,
10301
10240
  anchorOrigin = DEFAULT_ANCHOR_ORIGIN,
10241
+ anchorOriginTop = 108,
10302
10242
  ariaLabel,
10303
10243
  autoHideDuration,
10304
10244
  children,
@@ -10307,22 +10247,22 @@ const DotSnackbar = ({
10307
10247
  hideOnClickAway = true,
10308
10248
  onClose,
10309
10249
  open,
10250
+ primaryAction,
10251
+ secondaryAction,
10310
10252
  severity,
10311
10253
  width
10312
10254
  }) => {
10255
+ const hasActions = !!(primaryAction || secondaryAction);
10313
10256
  const calculatedAutoHideDuration = autoHideDuration === null || autoHideDuration > 0 ? autoHideDuration : addAutoHideDuration(severity);
10314
- checkForConflictingEventHandlers({
10315
- onClose,
10316
- action
10317
- });
10318
10257
  const rootClasses = useStylesWithRootClass(rootClassName$n, className);
10319
10258
  const handleSnackbarClose = reason => {
10320
- if (hideOnClickAway || !hideOnClickAway && reason !== 'clickaway') {
10259
+ if (!reason || hideOnClickAway || !hideOnClickAway && reason !== 'clickaway') {
10321
10260
  onClose();
10322
10261
  }
10323
10262
  };
10324
10263
  return jsx(StyledSnackbar, {
10325
10264
  anchorOrigin: anchorOrigin,
10265
+ "$anchorOriginTop": anchorOriginTop,
10326
10266
  "aria-label": ariaLabel,
10327
10267
  autoHideDuration: calculatedAutoHideDuration,
10328
10268
  classes: {
@@ -10332,16 +10272,41 @@ const DotSnackbar = ({
10332
10272
  onClose: (_e, r) => handleSnackbarClose(r),
10333
10273
  open: open,
10334
10274
  severity: severity,
10335
- children: jsx(Alert, {
10336
- action: action,
10337
- onClose: onClose,
10338
- severity: severity,
10339
- style: {
10340
- width: width
10341
- },
10342
- children: jsx("span", {
10343
- "aria-label": severity,
10344
- children: children
10275
+ width: width,
10276
+ children: jsx("div", {
10277
+ children: jsx(DotAlertBanner, {
10278
+ severity: severity,
10279
+ width: width,
10280
+ onClose: _e => handleSnackbarClose(),
10281
+ children: jsxs("div", {
10282
+ children: [jsx(DotTypography, {
10283
+ variant: "subtitle2",
10284
+ noMarginBottom: false,
10285
+ children: getSnackbarTitleFromSeverity(severity)
10286
+ }), isString$1(children) ? jsx(DotTypography, {
10287
+ ariaLabel: severity,
10288
+ variant: "body1",
10289
+ children: children
10290
+ }) : jsx("span", {
10291
+ "aria-label": severity,
10292
+ children: children
10293
+ }), hasActions && jsxs("div", {
10294
+ className: "dot-snackbar-actions",
10295
+ children: [primaryAction && jsx(DotButton, {
10296
+ className: "primary-action-btn",
10297
+ "data-testid": "primary-action-btn",
10298
+ onClick: primaryAction.onClick,
10299
+ size: "small",
10300
+ type: "outlined",
10301
+ children: primaryAction.label
10302
+ }), secondaryAction && jsx(DotLink, {
10303
+ "data-testid": "secondary-action-link",
10304
+ href: secondaryAction.href,
10305
+ color: "inherit",
10306
+ children: secondaryAction.label
10307
+ })]
10308
+ })]
10309
+ })
10345
10310
  })
10346
10311
  })
10347
10312
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digital-ai/dot-components",
3
- "version": "2.28.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "license": "SEE LICENSE IN <LICENSE.md>",
6
6
  "contributors": [
@@ -15,5 +15,7 @@ export interface AlertBannerProps extends CommonProps {
15
15
  severity: AlertBannerSeverity;
16
16
  /** when specified, will control the text that is used inside the alert banner */
17
17
  textVariant?: TypographyVariant;
18
+ /** when specified, will control the width of the encapsulated Alert component */
19
+ width?: string;
18
20
  }
19
- export declare const DotAlertBanner: ({ action, ariaLabel, children, className, "data-pendoid": dataPendoId, "data-testid": dataTestId, onClose, roundedCorners, severity, textVariant, }: AlertBannerProps) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const DotAlertBanner: ({ action, ariaLabel, children, className, "data-pendoid": dataPendoId, "data-testid": dataTestId, onClose, roundedCorners, severity, textVariant, width, }: AlertBannerProps) => import("react/jsx-runtime").JSX.Element;
@@ -32,7 +32,7 @@ export type { DividerOrientation, DividerProps, DividerVariant, } from './divide
32
32
  export type { BadgeProps, BadgeOverlap, BadgeVariant } from './badge';
33
33
  export type { TruncateWithTooltipProps } from './truncate-with-tooltip';
34
34
  export type { DraggableItem, DraggableListChangeHandler, } from './draggable-list';
35
- export type { SnackbarProps, SnackbarSeverity, SnackbarOrigin, } from './snackbar';
35
+ export type { SnackbarProps, SnackbarSeverity, SnackbarOrigin, SnackbarPrimaryAction, SnackbarSecondaryAction, } from './snackbar';
36
36
  export type { CharactersLimit, InlineEditProps } from './inline-edit';
37
37
  export type { progressColorOptions, progressVariantOptions, ProgressProps, } from './progress';
38
38
  export type { FileItemProps, FileUploadError, FileUploadProps, ListItemFile, MappedFile, MappedListItemFile, } from './file-upload';
@@ -2,11 +2,19 @@ import { ReactNode } from 'react';
2
2
  import { CommonProps } from '../CommonProps';
3
3
  import { SnackbarOrigin } from './';
4
4
  export type SnackbarSeverity = 'error' | 'warning' | 'info' | 'success';
5
+ export interface SnackbarPrimaryAction {
6
+ label: string;
7
+ onClick: () => void;
8
+ }
9
+ export interface SnackbarSecondaryAction {
10
+ href: string;
11
+ label: string;
12
+ }
5
13
  export interface SnackbarProps extends CommonProps {
6
- /** Property used for creating a custom action button. */
7
- action?: ReactNode;
8
14
  /** The anchor of the Snackbar. On smaller screens, the component grows to occupy all the available width, the horizontal alignment is ignored. */
9
15
  anchorOrigin?: SnackbarOrigin;
16
+ /** When specified, will set `top` property (in pixels) only for the vertical top origins */
17
+ anchorOriginTop?: number;
10
18
  /** The number of milliseconds to wait before automatically closing the snackbar. If null is passed, then the snackbar never automatically closes. If the prop is not passed at all, then snackbars close after 10 seconds (except error snackbar which never closes automatically). */
11
19
  autoHideDuration?: number | null;
12
20
  /** The message the user sees once the alert displays. */
@@ -14,12 +22,16 @@ export interface SnackbarProps extends CommonProps {
14
22
  /** If false, then snackbar does not close when clicking away. True by default. */
15
23
  hideOnClickAway?: boolean;
16
24
  /** A callback to handle closing the alert. */
17
- onClose?: () => void;
25
+ onClose: () => void;
18
26
  /** Boolean value to switch between opening and closing the alert. */
19
27
  open: boolean;
28
+ /** When specified, will render button underneath snackbar message */
29
+ primaryAction?: SnackbarPrimaryAction;
30
+ /** When specified, will render link next to primary action button */
31
+ secondaryAction?: SnackbarSecondaryAction;
20
32
  /** An alert level, indicating the importance of the message. */
21
33
  severity: SnackbarSeverity;
22
34
  /** Width of the encapsulated Alert component. */
23
35
  width?: string;
24
36
  }
25
- export declare const DotSnackbar: ({ action, anchorOrigin, ariaLabel, autoHideDuration, children, className, "data-testid": dataTestId, hideOnClickAway, onClose, open, severity, width, }: SnackbarProps) => import("react/jsx-runtime").JSX.Element;
37
+ export declare const DotSnackbar: ({ anchorOrigin, anchorOriginTop, ariaLabel, autoHideDuration, children, className, "data-testid": dataTestId, hideOnClickAway, onClose, open, primaryAction, secondaryAction, severity, width, }: SnackbarProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,9 @@ import { Snackbar } from '@mui/material';
2
2
  import { SnackbarSeverity } from './Snackbar';
3
3
  export declare const rootClassName = "dot-snackbar";
4
4
  interface StyledProps {
5
+ $anchorOriginTop?: number;
5
6
  severity: SnackbarSeverity;
7
+ width?: string;
6
8
  }
7
9
  export declare const StyledSnackbar: import("styled-components").StyledComponent<typeof Snackbar, any, StyledProps, never>;
8
10
  export {};
@@ -1,4 +1,4 @@
1
1
  export type { SnackbarOrigin } from '@mui/material';
2
- export type { SnackbarProps, SnackbarSeverity } from './Snackbar';
2
+ export type { SnackbarProps, SnackbarSeverity, SnackbarPrimaryAction, SnackbarSecondaryAction, } from './Snackbar';
3
3
  export { DotSnackbar } from './Snackbar';
4
4
  export { DotSnackbarContainer, DotSnackbarProvider, useDotSnackbarContext, } from './SnackbarProvider';
@@ -0,0 +1,2 @@
1
+ import { SnackbarSeverity } from '../Snackbar';
2
+ export declare const getSnackbarTitleFromSeverity: (severity: SnackbarSeverity) => "Success" | "Warning" | "Error" | "Info";