@sanity/ui 2.0.0-beta.14 → 2.0.0-beta.16

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.0.0-beta.14",
3
+ "version": "2.0.0-beta.16",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./exports/index.ts",
@@ -7,7 +7,7 @@ const GlobalStyle = createGlobalStyle`
7
7
  font-style: normal;
8
8
  font-weight: 100 900;
9
9
  font-display: swap;
10
- src: url('https://rsms.me/inter/font-files/InterVariable.woff2?v=4.0') format('woff2');
10
+ src: url('https://studio-static.sanity.io/InterVariable.ttf') format('ttf');
11
11
  font-named-instance: 'Regular';
12
12
  }
13
13
  @font-face {
@@ -15,7 +15,7 @@ const GlobalStyle = createGlobalStyle`
15
15
  font-style: italic;
16
16
  font-weight: 100 900;
17
17
  font-display: swap;
18
- src: url('https://rsms.me/inter/font-files/InterVariable-Italic.woff2?v=4.0') format('woff2');
18
+ src: url('https://studio-static.sanity.io/InterVariable-Italic.ttf') format('ttf');
19
19
  font-named-instance: 'Italic';
20
20
  }
21
21
  `
@@ -1,7 +1,9 @@
1
1
  import {CloseIcon} from '@sanity/icons'
2
2
  import {ThemeColorToneKey} from '@sanity/ui/theme'
3
3
  import styled from 'styled-components'
4
+ import {POPOVER_MOTION_CONTENT_OPACITY_PROPERTY} from '../../constants'
4
5
  import {Box, Button, Card, Flex, Stack, Text} from '../../primitives'
6
+ import type {ButtonTone} from '../../types'
5
7
 
6
8
  /**
7
9
  * @public
@@ -20,17 +22,28 @@ const STATUS_CARD_TONE: {[key: string]: ThemeColorToneKey} = {
20
22
  warning: 'caution',
21
23
  success: 'positive',
22
24
  info: 'primary',
23
- }
25
+ } as const
26
+
27
+ const BUTTON_TONE = {
28
+ error: 'critical',
29
+ warning: 'caution',
30
+ success: 'positive',
31
+ info: 'primary',
32
+ } satisfies {[key: string]: ButtonTone}
24
33
 
25
34
  const ROLES = {
26
35
  error: 'alert',
27
36
  warning: 'alert',
28
37
  success: 'alert',
29
38
  info: 'alert',
30
- }
39
+ } as const
31
40
 
32
41
  const Root = styled(Card)`
33
42
  pointer-events: all;
43
+ & > * {
44
+ opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
45
+ will-change: opacity;
46
+ }
34
47
  `
35
48
 
36
49
  const TextBox = styled(Flex)`
@@ -49,6 +62,7 @@ export function Toast(
49
62
  ): React.ReactElement {
50
63
  const {closable, description, onClose, radius = 3, title, status, ...restProps} = props
51
64
  const cardTone = status ? STATUS_CARD_TONE[status] : 'default'
65
+ const buttonTone = status ? BUTTON_TONE[status] : 'default'
52
66
  const role = status ? ROLES[status] : 'status'
53
67
 
54
68
  return (
@@ -84,6 +98,7 @@ export function Toast(
84
98
  icon={CloseIcon}
85
99
  mode="bleed"
86
100
  padding={2}
101
+ tone={buttonTone}
87
102
  onClick={onClose}
88
103
  style={{verticalAlign: 'top'}}
89
104
  />
@@ -1,6 +1,7 @@
1
1
  import {AnimatePresence, motion} from 'framer-motion'
2
2
  import {useCallback, useEffect, useMemo, useRef, useState, startTransition} from 'react'
3
3
  import styled from 'styled-components'
4
+ import {POPOVER_MOTION_CONTENT_OPACITY_PROPERTY} from '../../constants'
4
5
  import {useMounted} from '../../hooks/useMounted'
5
6
  import {Box} from '../../primitives'
6
7
  import {Layer} from '../../utils'
@@ -132,9 +133,25 @@ export function ToastProvider(props: ToastProviderProps): React.ReactElement {
132
133
  <AnimatePresence initial={false}>
133
134
  {state.map(({dismiss, id, params}) => (
134
135
  <motion.div
135
- animate={{opacity: 1, y: 0, scale: 1}}
136
- exit={{opacity: 0, scale: 0.5, transition: {duration: 0.2}}}
137
- initial={{opacity: 0, y: 32, scale: 0.25, willChange: 'transform'}}
136
+ animate={{
137
+ opacity: [0, 1, 1],
138
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: [0, 0, 1],
139
+ y: 0,
140
+ scale: 1,
141
+ }}
142
+ exit={{
143
+ opacity: [1, 1, 0],
144
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: [1, 0, 0],
145
+ scale: 0.5,
146
+ transition: {duration: 0.2},
147
+ }}
148
+ initial={{
149
+ opacity: 0,
150
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: 0,
151
+ y: 32,
152
+ scale: 0.25,
153
+ willChange: 'transform',
154
+ }}
138
155
  key={id}
139
156
  layout="position"
140
157
  transition={{type: 'spring', damping: 30, stiffness: 400}}
@@ -10,6 +10,11 @@ export const EMPTY_ARRAY: never[] = []
10
10
  */
11
11
  export const EMPTY_RECORD: Record<string, never> = {}
12
12
 
13
+ /**
14
+ * @internal
15
+ */
16
+ export const POPOVER_MOTION_CONTENT_OPACITY_PROPERTY = '--motion-content-opacity'
17
+
13
18
  /**
14
19
  * Shared `framer-motion` variants used by `Popover` and `Tooltip` components.
15
20
  * @internal
@@ -20,9 +25,23 @@ export const POPOVER_MOTION_PROPS: {
20
25
  exit: Variant
21
26
  transition: Transition
22
27
  } = {
23
- initial: {opacity: 0.5, scale: 0.97},
24
- animate: {opacity: 1, scale: 1},
25
- exit: {opacity: 0, scale: 0.97},
28
+ initial: {
29
+ opacity: 0.5,
30
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: 0,
31
+ scale: 0.97,
32
+ willChange: 'transform',
33
+ },
34
+ animate: {
35
+ opacity: [null, 1, 1],
36
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: [null, null, 1],
37
+ scale: 1,
38
+ },
39
+ exit: {
40
+ // @ts-expect-error -- passing null a second time is valid: https://github.com/framer/motion/blob/b9ce4c42914c3916ea523609c5b032dfc72718bb/packages/framer-motion/src/animation/utils/keyframes.ts#L34C22-L34C22
41
+ opacity: [null, null, 0],
42
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: [null, 0, 0],
43
+ scale: 0.97,
44
+ },
26
45
  transition: {duration: 0.4, type: 'spring'},
27
46
  }
28
47
 
@@ -3,7 +3,7 @@ import {ThemeColorSchemeKey} from '@sanity/ui/theme'
3
3
  import {MotionProps, motion} from 'framer-motion'
4
4
  import React, {CSSProperties, forwardRef, memo, useMemo} from 'react'
5
5
  import styled from 'styled-components'
6
- import {POPOVER_MOTION_PROPS} from '../../constants'
6
+ import {POPOVER_MOTION_CONTENT_OPACITY_PROPERTY, POPOVER_MOTION_PROPS} from '../../constants'
7
7
  import {BoxOverflow, CardTone, Placement, PopoverMargins, Radius} from '../../types'
8
8
  import {Arrow, useLayer} from '../../utils'
9
9
  import {Card, CardProps} from '../card'
@@ -22,6 +22,10 @@ const MotionCard = styled(motion(Card))`
22
22
  flex-direction: column;
23
23
  width: max-content;
24
24
  min-width: min-content;
25
+ & > * {
26
+ opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
27
+ will-change: opacity;
28
+ }
25
29
  `
26
30
 
27
31
  /**
@@ -2,7 +2,7 @@ import {ThemeColorSchemeKey} from '@sanity/ui/theme'
2
2
  import {MotionProps, motion} from 'framer-motion'
3
3
  import React, {CSSProperties, forwardRef, memo, useMemo} from 'react'
4
4
  import styled from 'styled-components'
5
- import {POPOVER_MOTION_PROPS} from '../../constants'
5
+ import {POPOVER_MOTION_CONTENT_OPACITY_PROPERTY, POPOVER_MOTION_PROPS} from '../../constants'
6
6
  import {Placement, Radius} from '../../types'
7
7
  import {Arrow} from '../../utils'
8
8
  import {Card, CardProps} from '../card'
@@ -12,7 +12,12 @@ import {
12
12
  DEFAULT_TOOLTIP_ARROW_WIDTH,
13
13
  } from './constants'
14
14
 
15
- const MotionCard = styled(motion(Card))``
15
+ const MotionCard = styled(motion(Card))`
16
+ & > * {
17
+ opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
18
+ will-change: opacity;
19
+ }
20
+ `
16
21
 
17
22
  /**
18
23
  * @internal
@@ -36,6 +36,7 @@ export function getScopedTheme(
36
36
  layer: layer_v0,
37
37
  v2: {
38
38
  ...v2,
39
+ _resolved: true,
39
40
  color: color_v2,
40
41
  layer: layer_v2,
41
42
  },
@@ -114,7 +114,15 @@ export type RootTheme = BaseTheme
114
114
  /**
115
115
  * @public
116
116
  */
117
- export type Theme_v2 = Omit<RootTheme_v2, 'color'> & {color: ThemeColorCard_v2}
117
+ export type Theme_v2 = Omit<RootTheme_v2, 'color'> & {
118
+ color: ThemeColorCard_v2
119
+ /**
120
+ * Indicates whether the theme is resolved or raw, it's necessary to avoid issues
121
+ * with sanity V2 components accessing a v1 <ThemeProvider>.
122
+ * See https://github.com/sanity-io/ui/pull/1203 for more info.
123
+ */
124
+ _resolved: boolean
125
+ }
118
126
 
119
127
  /**
120
128
  * @public
@@ -6,7 +6,7 @@ const cache = new WeakMap<Theme, Theme_v2>()
6
6
 
7
7
  /** @public */
8
8
  export function getTheme_v2(theme: Theme): Theme_v2 {
9
- if (theme.sanity.v2) return theme.sanity.v2
9
+ if (theme.sanity.v2?._resolved) return theme.sanity.v2
10
10
 
11
11
  const cached_v2 = cache.get(theme)
12
12
 
@@ -14,6 +14,7 @@ export function getTheme_v2(theme: Theme): Theme_v2 {
14
14
 
15
15
  const v2: Theme_v2 = {
16
16
  _version: 2,
17
+ _resolved: true,
17
18
  avatar: {
18
19
  ...defaultThemeConfig.avatar,
19
20
  ...theme.sanity.avatar,