@sanity/ui 2.3.6 → 2.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.3.6",
3
+ "version": "2.4.0",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -0,0 +1,61 @@
1
+ import {styled, keyframes, css} from 'styled-components'
2
+ import {ThemeColorStateToneKey, getTheme_v2} from '../../../theme'
3
+ import {POPOVER_MOTION_CONTENT_OPACITY_PROPERTY} from '../../constants'
4
+ import {Flex} from '../../primitives'
5
+ import {ThemeProps} from '../../styles'
6
+
7
+ export const TextBox = styled(Flex)`
8
+ overflow-x: auto;
9
+ `
10
+
11
+ const loadingAnimation = keyframes`
12
+ 0% {
13
+ width: 0;
14
+ }
15
+ 100% {
16
+ width: 100%;
17
+ }
18
+ `
19
+
20
+ const LOADING_BAR_HEIGHT = 2
21
+
22
+ export function rootStyles(
23
+ props: {$duration?: number; tone: ThemeColorStateToneKey} & ThemeProps,
24
+ ): ReturnType<typeof css> {
25
+ const {color} = getTheme_v2(props.theme)
26
+
27
+ const loadingBarColor = color.button.default[props.tone].enabled.bg
28
+
29
+ if (!props.$duration)
30
+ return css`
31
+ pointer-events: all;
32
+ & > * {
33
+ opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
34
+ will-change: opacity;
35
+ }
36
+ `
37
+
38
+ return css`
39
+ pointer-events: all;
40
+ width: 100%;
41
+ position: relative;
42
+ overflow: hidden;
43
+ overflow: clip;
44
+ padding-bottom: ${LOADING_BAR_HEIGHT}px;
45
+ &::before {
46
+ content: '';
47
+ position: absolute;
48
+ bottom: 0px;
49
+ height: ${LOADING_BAR_HEIGHT}px;
50
+ background: ${loadingBarColor};
51
+ animation-name: ${loadingAnimation};
52
+ animation-duration: ${props.$duration}ms;
53
+ animation-fill-mode: both;
54
+ }
55
+
56
+ & > * {
57
+ opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
58
+ will-change: opacity;
59
+ }
60
+ `
61
+ }
@@ -1,9 +1,10 @@
1
1
  import {CloseIcon} from '@sanity/icons'
2
- import {ThemeColorToneKey} from '@sanity/ui/theme'
2
+ import {ThemeColorStateToneKey} from '@sanity/ui/theme'
3
3
  import {styled} from 'styled-components'
4
- import {POPOVER_MOTION_CONTENT_OPACITY_PROPERTY} from '../../constants'
5
- import {Box, Button, Card, Flex, Stack, Text} from '../../primitives'
4
+ import {Box, Button, Flex, Stack, Text, Card} from '../../primitives'
5
+ import {ThemeProps} from '../../styles'
6
6
  import type {ButtonTone} from '../../types'
7
+ import {rootStyles, TextBox} from './styles'
7
8
 
8
9
  /**
9
10
  * @public
@@ -15,9 +16,10 @@ export interface ToastProps {
15
16
  radius?: number | number[]
16
17
  title?: React.ReactNode
17
18
  status?: 'error' | 'warning' | 'success' | 'info'
19
+ duration?: number
18
20
  }
19
21
 
20
- const STATUS_CARD_TONE: {[key: string]: ThemeColorToneKey} = {
22
+ const STATUS_CARD_TONE: {[key: string]: ThemeColorStateToneKey} = {
21
23
  error: 'critical',
22
24
  warning: 'caution',
23
25
  success: 'positive',
@@ -38,17 +40,9 @@ const ROLES = {
38
40
  info: 'alert',
39
41
  } as const
40
42
 
41
- const Root = styled(Card)`
42
- pointer-events: all;
43
- & > * {
44
- opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
45
- will-change: opacity;
46
- }
47
- `
48
-
49
- const TextBox = styled(Flex)`
50
- overflow-x: auto;
51
- `
43
+ const Root = styled(Card)<{$duration?: number; tone: ThemeColorStateToneKey} & ThemeProps>(
44
+ rootStyles,
45
+ )
52
46
 
53
47
  /**
54
48
  * The `Toast` component gives feedback to users when an action has taken place.
@@ -60,7 +54,7 @@ const TextBox = styled(Flex)`
60
54
  export function Toast(
61
55
  props: ToastProps & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'height' | 'ref' | 'title'>,
62
56
  ): React.ReactElement {
63
- const {closable, description, onClose, radius = 3, title, status, ...restProps} = props
57
+ const {closable, description, duration, onClose, radius = 3, title, status, ...restProps} = props
64
58
  const cardTone = status ? STATUS_CARD_TONE[status] : 'default'
65
59
  const buttonTone = status ? BUTTON_TONE[status] : 'default'
66
60
  const role = status ? ROLES[status] : 'status'
@@ -74,6 +68,7 @@ export function Toast(
74
68
  radius={radius}
75
69
  shadow={2}
76
70
  tone={cardTone}
71
+ $duration={duration}
77
72
  >
78
73
  <Flex align="flex-start">
79
74
  <TextBox flex={1} padding={3}>
@@ -177,6 +177,7 @@ export function ToastProvider(props: ToastProviderProps): React.ReactElement {
177
177
  onClose={dismiss}
178
178
  status={params.status}
179
179
  title={params.title}
180
+ duration={params.duration}
180
181
  />
181
182
  </motion.div>
182
183
  ))}