@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/dist/_chunks-cjs/getTheme_v2.js +319 -0
- package/dist/_chunks-cjs/getTheme_v2.js.map +1 -0
- package/dist/_chunks-es/getTheme_v2.mjs +320 -0
- package/dist/_chunks-es/getTheme_v2.mjs.map +1 -0
- package/dist/_legacy/getTheme_v2.esm.js +320 -0
- package/dist/_legacy/getTheme_v2.esm.js.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +51 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +51 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -12
- package/dist/index.mjs.map +1 -1
- package/dist/theme.esm.js +4 -315
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +36 -349
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +4 -315
- package/dist/theme.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/components/toast/styles.ts +61 -0
- package/src/core/components/toast/toast.tsx +11 -16
- package/src/core/components/toast/toastProvider.tsx +1 -0
package/package.json
CHANGED
|
@@ -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 {
|
|
2
|
+
import {ThemeColorStateToneKey} from '@sanity/ui/theme'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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]:
|
|
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
|
-
|
|
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}>
|