@sanity/ui 5.0.0-alpha.1 → 5.0.0-alpha.10

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.
Files changed (76) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/install.js +2 -1
  3. package/dist/index.d.ts +362 -76
  4. package/dist/index.js +420 -158
  5. package/dist/index.js.map +1 -1
  6. package/dist/polyfills.d.ts +1 -0
  7. package/dist/polyfills.js +5 -0
  8. package/dist/polyfills.js.map +1 -0
  9. package/dist/styles.css +1 -1
  10. package/package.json +9 -3
  11. package/src/cli/install.ts +2 -1
  12. package/src/components/badge/Badge.tsx +53 -0
  13. package/src/components/badge/badge.css +6 -0
  14. package/src/components/badge/badge.props.ts +31 -0
  15. package/src/components/box/Box.tsx +6 -1
  16. package/src/components/box/box.props.ts +7 -2
  17. package/src/components/button/button.props.ts +27 -9
  18. package/src/components/card/card.props.ts +6 -2
  19. package/src/components/checkbox/Checkbox.tsx +3 -2
  20. package/src/components/checkbox/checkbox.props.ts +11 -3
  21. package/src/components/code/code.props.ts +10 -3
  22. package/src/components/container/container.props.ts +6 -2
  23. package/src/components/dialog/Dialog.tsx +139 -0
  24. package/src/components/dialog/dialog.css +49 -0
  25. package/src/components/dialog/dialog.props.ts +45 -0
  26. package/src/components/eyebrow/Eyebrow.tsx +1 -1
  27. package/src/components/eyebrow/eyebrow.props.ts +6 -2
  28. package/src/components/flex/Flex.tsx +6 -1
  29. package/src/components/flex/flex.props.ts +6 -2
  30. package/src/components/grid/Grid.tsx +6 -1
  31. package/src/components/grid/grid.props.ts +6 -2
  32. package/src/components/h-stack/hStack.props.ts +3 -1
  33. package/src/components/heading/Heading.tsx +1 -1
  34. package/src/components/heading/heading.props.ts +8 -2
  35. package/src/components/icon/icon.props.ts +6 -2
  36. package/src/components/icon-button/iconButton.props.ts +7 -2
  37. package/src/components/index.css +3 -0
  38. package/src/components/indicator/indicator.props.ts +6 -2
  39. package/src/components/indicator-stack/indicatorStack.props.ts +3 -1
  40. package/src/components/inline/inline.props.ts +6 -2
  41. package/src/components/label/label.props.ts +7 -1
  42. package/src/components/link/link.props.ts +4 -4
  43. package/src/components/list/list.props.ts +27 -9
  44. package/src/components/popover/Popover.tsx +85 -0
  45. package/src/components/popover/popover.css +21 -0
  46. package/src/components/popover/popover.props.ts +38 -0
  47. package/src/components/press-area/pressArea.props.ts +3 -1
  48. package/src/components/radio/Radio.tsx +1 -1
  49. package/src/components/radio/radio.props.ts +7 -2
  50. package/src/components/skip-to-content/skipToContent.props.ts +9 -3
  51. package/src/components/spinner/Spinner.tsx +1 -1
  52. package/src/components/spinner/spinner.props.ts +3 -0
  53. package/src/components/switch/Switch.tsx +1 -1
  54. package/src/components/switch/switch.props.ts +7 -2
  55. package/src/components/text/Text.tsx +1 -1
  56. package/src/components/text/text.props.ts +6 -2
  57. package/src/components/tooltip/Tooltip.tsx +59 -55
  58. package/src/components/tooltip/tooltip.css +19 -40
  59. package/src/components/tooltip/tooltip.props.ts +24 -8
  60. package/src/components/tooltip-group/TooltipGroup.tsx +2 -5
  61. package/src/components/tooltip-group/tooltipGroup.props.ts +3 -1
  62. package/src/components/v-stack/vStack.props.ts +3 -1
  63. package/src/components/visually-hidden/visuallyHidden.props.ts +6 -2
  64. package/src/css/classes/generic/display.css +8 -8
  65. package/src/css/classes/generic/placement.css +31 -0
  66. package/src/css/classes/local/animation.css +4 -0
  67. package/src/css/classes/local/index.css +2 -0
  68. package/src/css/classes/local/top-anchor.css +4 -0
  69. package/src/css/global/reset.css +20 -18
  70. package/src/css/tokens/semantic.css +4 -0
  71. package/src/hooks/useIsClient.ts +10 -0
  72. package/src/index.ts +5 -0
  73. package/src/polyfills.ts +15 -0
  74. package/src/utils/mergeTriggerProps.ts +66 -0
  75. package/src/utils/renderPortal.tsx +14 -0
  76. package/src/version.ts +2 -2
@@ -1,52 +1,31 @@
1
+ [interestfor] {
2
+ --tooltip-delay: var(--tooltip-delay-group, 500ms);
3
+ /* The interestfor polyfill looks for intereset delay variables */
4
+ --interest-delay-start: var(--tooltip-delay);
5
+ --interest-delay-end: 0ms;
6
+ interest-delay-start: var(--tooltip-delay);
7
+ interest-delay-end: 0ms;
8
+ }
9
+
1
10
  .sui-Tooltip {
2
- --tooltip-delay-open: var(--tooltip-delay-group, 500ms);
3
- --tooltip-delay-close: var(--tooltip-delay-group, 100ms);
4
11
  background: var(--backdrop);
12
+ visibility: hidden;
5
13
  opacity: 0;
6
14
  scale: 0.9;
7
- visibility: hidden;
8
- transition:
9
- opacity 200ms cubic-bezier(0.34, 1.2, 0.64, 1) var(--tooltip-delay-close),
10
- scale 200ms cubic-bezier(0.34, 1.2, 0.64, 1) var(--tooltip-delay-close),
11
- visibility 0s linear calc(var(--tooltip-delay-close) + 200ms);
15
+ transition: none;
12
16
  }
13
17
 
14
- [aria-describedby]:is(:hover, :focus-visible) + [role="tooltip"]:not(.sui-Tooltip-Dismissed) {
18
+ .sui-Tooltip:popover-open {
15
19
  visibility: visible;
16
20
  opacity: 1;
17
21
  scale: 1;
18
- transition:
19
- opacity 200ms cubic-bezier(0.34, 1.2, 0.64, 1) var(--tooltip-delay-open),
20
- scale 200ms cubic-bezier(0.34, 1.2, 0.64, 1) var(--tooltip-delay-open),
21
- visibility 0s linear var(--tooltip-delay-open);
22
- }
23
-
24
- [aria-describedby]:is(:hover, :focus-visible) + .sui-Tooltip-Dismissed[role="tooltip"] {
25
- transition: none;
26
- }
27
-
28
- .sui-Tooltip[class*='placement-bottom'],
29
- .sui-Tooltip[class*='placement-top'] {
30
- margin-block: var(--space-1);
31
- }
32
-
33
- .sui-Tooltip[class*='placement-left'],
34
- .sui-Tooltip[class*='placement-right'] {
35
- margin-inline: var(--space-1);
36
- }
37
-
38
- .sui-Tooltip[class*='bottom'] {
39
- transform-origin: center top;
40
- }
41
-
42
- .sui-Tooltip[class*='top'] {
43
- transform-origin: center bottom;
44
- }
45
-
46
- .sui-Tooltip[class*='left'] {
47
- transform-origin: right center;
22
+ transition: var(--fade-in-transition);
48
23
  }
49
24
 
50
- .sui-Tooltip[class*='right'] {
51
- transform-origin: left center;
25
+ @starting-style {
26
+ .sui-Tooltip:popover-open {
27
+ visibility: hidden;
28
+ opacity: 0;
29
+ scale: 0.9;
30
+ }
52
31
  }
@@ -1,19 +1,35 @@
1
1
  import {type PlacementProps, placementProps} from '../../props/placement'
2
2
  import {type PropDef} from '../../types/PropDef'
3
3
 
4
- /** @public */
5
- export interface TooltipProps extends React.ComponentProps<'div'>, PlacementProps {
6
- /** Tooltip text */
7
- text?: React.ReactNode
8
- /** Disabled state */
9
- disabled?: boolean
4
+ /** @beta */
5
+ export interface TooltipProps
6
+ extends Omit<React.ComponentProps<'div'>, 'children' | 'content'>, PlacementProps {
7
+ /**
8
+ * Shared anchor identifier.
9
+ */
10
+ anchorName?: React.ReactNode
11
+ /**
12
+ * The trigger element.
13
+ */
14
+ children: React.ReactElement<Record<string, unknown>>
15
+ /**
16
+ * The tooltip label.
17
+ */
18
+ content?: React.ReactNode
19
+ /**
20
+ * Renders the label into `document.body` through a React portal instead of inline.
21
+ */
22
+ portal?: boolean
10
23
  }
11
24
 
12
25
  export const tooltipProps: Record<string, PropDef> = {
13
- text: {
26
+ anchorName: {
14
27
  type: 'string',
15
28
  },
16
- disabled: {
29
+ content: {
30
+ type: 'string',
31
+ },
32
+ portal: {
17
33
  type: 'boolean',
18
34
  },
19
35
  ...placementProps,
@@ -23,10 +23,7 @@ export function TooltipGroup<T extends ElementType = 'div'>(
23
23
  return
24
24
  }
25
25
 
26
- if (
27
- e.propertyName === 'visibility' &&
28
- window.getComputedStyle(tooltip).visibility !== 'hidden'
29
- ) {
26
+ if (e.propertyName === 'opacity' && window.getComputedStyle(tooltip).opacity !== '0') {
30
27
  setIsActive(true)
31
28
  }
32
29
  }
@@ -49,7 +46,7 @@ export function TooltipGroup<T extends ElementType = 'div'>(
49
46
  style={{
50
47
  ...style,
51
48
  ...(isActive && {
52
- '--tooltip-delay-group': 0,
49
+ '--tooltip-delay-group': '0ms',
53
50
  }),
54
51
  }}
55
52
  data-ui="TooltipGroup"
@@ -2,7 +2,9 @@ import {type PropDef} from '../../types/PropDef'
2
2
 
3
3
  /** @public */
4
4
  export interface TooltipGroupProps<T extends React.ElementType = 'div'> {
5
- /** Element to render */
5
+ /**
6
+ * HTML element to render.
7
+ */
6
8
  as?: T
7
9
  }
8
10
 
@@ -3,7 +3,9 @@ import {type PropDef} from '../../types/PropDef'
3
3
 
4
4
  /** @public */
5
5
  export interface VStackProps<T extends React.ElementType = 'div'> extends Pick<GapProps, 'gap'> {
6
- /** Element to render */
6
+ /**
7
+ * HTML element or component to render.
8
+ */
7
9
  as?: T
8
10
  }
9
11
 
@@ -2,9 +2,13 @@ import {type PropDef} from '../../types/PropDef'
2
2
 
3
3
  /** @public */
4
4
  export interface VisuallyHiddenProps<T extends React.ElementType = 'span'> {
5
- /** Element to render */
5
+ /**
6
+ * HTML element to render.
7
+ */
6
8
  as?: T
7
- /** If true, element is visible on :focus-visible */
9
+ /**
10
+ * If true, the element becomes visible on `:focus-visible`.
11
+ */
8
12
  visibleOnFocus?: boolean
9
13
  }
10
14
 
@@ -1,10 +1,10 @@
1
1
  @breakpoints {
2
- .sui-display-block { display: block; }
3
- .sui-display-inline-block { display: inline-block; }
4
- .sui-display-inline { display: inline; }
5
- .sui-display-flex { display: flex; }
6
- .sui-display-inline-flex { display: inline-flex; }
7
- .sui-display-grid { display: grid; }
8
- .sui-display-inline-grid { display: inline-grid; }
9
- .sui-display-none { display: none; }
2
+ .sui-display-block:not([hidden]) { display: block; }
3
+ .sui-display-inline-block:not([hidden]) { display: inline-block; }
4
+ .sui-display-inline:not([hidden]) { display: inline; }
5
+ .sui-display-flex:not([hidden]) { display: flex; }
6
+ .sui-display-inline-flex:not([hidden]) { display: inline-flex; }
7
+ .sui-display-grid:not([hidden]) { display: grid; }
8
+ .sui-display-inline-grid:not([hidden]) { display: inline-grid; }
9
+ .sui-display-none:not([hidden]) { display: none; }
10
10
  }
@@ -1,3 +1,8 @@
1
+ [class*='placement-'] {
2
+ inset: auto;
3
+ margin: 0;
4
+ }
5
+
1
6
  @position-try --top-center {
2
7
  top: auto;
3
8
  right: auto;
@@ -169,3 +174,29 @@
169
174
  bottom: anchor(bottom);
170
175
  position-try-fallbacks: --left-end;
171
176
  }
177
+
178
+ [class*="placement-bottom"],
179
+ [class*="placement-top"] {
180
+ margin-block: var(--space-1);
181
+ }
182
+
183
+ [class*="placement-left"],
184
+ [class*="placement-right"] {
185
+ margin-inline: var(--space-1);
186
+ }
187
+
188
+ [class*="placement-bottom"] {
189
+ transform-origin: center top;
190
+ }
191
+
192
+ [class*="placement-top"] {
193
+ transform-origin: center bottom;
194
+ }
195
+
196
+ [class*="placement-left"] {
197
+ transform-origin: right center;
198
+ }
199
+
200
+ [class*="placement-right"] {
201
+ transform-origin: left center;
202
+ }
@@ -0,0 +1,4 @@
1
+ :root {
2
+ --timing-linear: linear;
3
+ --timing-curve: cubic-bezier(0.34, 1.2, 0.64, 1);
4
+ }
@@ -1,4 +1,6 @@
1
+ @import './animation.css';
1
2
  @import './border.css';
2
3
  @import './text-overflow.css';
3
4
  @import './text-trim.css';
4
5
  @import './tone.css';
6
+ @import './top-anchor.css';
@@ -0,0 +1,4 @@
1
+ .sui-top-anchor {
2
+ inset-block-start: var(--top-anchor);
3
+ max-block-size: calc(100dvh - var(--top-anchor) * 2);
4
+ }
@@ -17,46 +17,48 @@
17
17
  }
18
18
 
19
19
  /* Prevent adjustments of font size after orientation changes in iOS. */
20
- html {
20
+ :where(html) {
21
21
  -webkit-text-size-adjust: 100%;
22
22
  }
23
23
 
24
- body {
24
+ :where(body) {
25
25
  background: light-dark(var(--white), var(--black));
26
26
  font-family: var(--sans);
27
27
  -webkit-font-smoothing: antialiased;
28
28
  }
29
29
 
30
30
  /* Display multimedia as block by default */
31
- audio,
32
- canvas,
33
- embed,
34
- iframe,
35
- img,
36
- object,
37
- picture,
38
- video {
31
+ :where(
32
+ audio,
33
+ canvas,
34
+ embed,
35
+ iframe,
36
+ img,
37
+ object,
38
+ picture,
39
+ video
40
+ ){
39
41
  display: block;
40
42
  max-width: 100%;
41
43
  }
42
- img,
43
- picture,
44
- video {
44
+ :where(img, picture, video) {
45
45
  block-size: auto;
46
46
  }
47
47
 
48
48
  /* Inherit typography in form controls */
49
- button,
50
- input,
51
- select,
52
- textarea {
49
+ :where(
50
+ button,
51
+ input,
52
+ select,
53
+ textarea
54
+ ) {
53
55
  font: inherit;
54
56
  line-height: inherit;
55
57
  color: inherit;
56
58
  }
57
59
 
58
60
  /* Remove excess space for table borders */
59
- table {
61
+ :where(table) {
60
62
  border-collapse: collapse;
61
63
  border-spacing: 0;
62
64
  }
@@ -18,4 +18,8 @@
18
18
  --hover-transition: border-color 100ms linear, background-color 100ms linear;
19
19
  --inert-background: light-dark(var(--gray-50), var(--gray-950));
20
20
  --inert-foreground: light-dark(var(--gray-400), var(--gray-600));
21
+ --fade-in-transition:
22
+ opacity 200ms cubic-bezier(0.34, 1.2, 0.64, 1),
23
+ scale 200ms cubic-bezier(0.34, 1.2, 0.64, 1), visibility 0s linear,
24
+ display 200ms linear allow-discrete;
21
25
  }
@@ -0,0 +1,10 @@
1
+ import {useSyncExternalStore} from 'react'
2
+
3
+ /** @public */
4
+ export function useIsClient() {
5
+ return useSyncExternalStore(
6
+ () => () => {},
7
+ () => true,
8
+ () => false,
9
+ )
10
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from './components/card/Card'
4
4
  export * from './components/checkbox/Checkbox'
5
5
  export * from './components/code/Code'
6
6
  export * from './components/container/Container'
7
+ export * from './components/dialog/Dialog'
7
8
  export * from './components/divider/Divider'
8
9
  export * from './components/eyebrow/Eyebrow'
9
10
  export * from './components/flex/Flex'
@@ -18,6 +19,7 @@ export * from './components/inline/Inline'
18
19
  export * from './components/label/Label'
19
20
  export * from './components/link/Link'
20
21
  export * from './components/list/List'
22
+ export * from './components/popover/Popover'
21
23
  export * from './components/press-area/PressArea'
22
24
  export * from './components/radio/Radio'
23
25
  export * from './components/skip-to-content/SkipToContent'
@@ -29,6 +31,8 @@ export * from './components/tooltip-group/TooltipGroup'
29
31
  export * from './components/v-stack/VStack'
30
32
  export * from './components/visually-hidden/VisuallyHidden'
31
33
 
34
+ export * from './hooks/useIsClient'
35
+
32
36
  export type {FlexParentProps} from './props/flexParent'
33
37
  export type {GapProps} from './props/gap'
34
38
  export type {GridParentProps} from './props/gridParent'
@@ -58,3 +62,4 @@ export type {TextSize} from './types/Text'
58
62
  export type {TextAlign} from './types/TextAlign'
59
63
  export type {FontWeight} from './types/FontWeight'
60
64
  export type {Tone} from './types/Tone'
65
+ export * from './components/badge/Badge'
@@ -0,0 +1,15 @@
1
+ import {
2
+ apply as applyClosedByPolyfill,
3
+ isSupported as isClosedBySupported,
4
+ } from 'dialog-closedby-polyfill'
5
+
6
+ if (
7
+ typeof HTMLButtonElement !== 'undefined' &&
8
+ !('interestForElement' in HTMLButtonElement.prototype)
9
+ ) {
10
+ void import('interestfor')
11
+ }
12
+
13
+ if (typeof HTMLDialogElement !== 'undefined' && !isClosedBySupported()) {
14
+ applyClosedByPolyfill()
15
+ }
@@ -0,0 +1,66 @@
1
+ function isReactEventHandler(key: string, value: unknown): value is (e: never) => void {
2
+ return /^on[A-Z]/.test(key) && typeof value === 'function'
3
+ }
4
+
5
+ function chainEventHandlers<E>(
6
+ ...handlers: (((e: E) => void) | undefined)[]
7
+ ): ((e: E) => void) | undefined {
8
+ const defined = handlers.filter(Boolean) as ((e: E) => void)[]
9
+
10
+ if (defined.length === 0) {
11
+ return undefined
12
+ }
13
+
14
+ if (defined.length === 1) {
15
+ return defined[0]
16
+ }
17
+
18
+ return (e: E) => {
19
+ for (const handler of defined) {
20
+ handler(e)
21
+ }
22
+ }
23
+ }
24
+
25
+ export function mergeTriggerProps(
26
+ childProps: Record<string, unknown>,
27
+ forwardedProps?: Record<string, unknown>,
28
+ ownProps?: Record<string, unknown>,
29
+ ) {
30
+ const result: Record<string, unknown> = {}
31
+
32
+ for (const source of [forwardedProps, ownProps]) {
33
+ if (!source) {
34
+ continue
35
+ }
36
+
37
+ for (const [key, value] of Object.entries(source)) {
38
+ if (key === 'style') {
39
+ continue
40
+ }
41
+
42
+ if (isReactEventHandler(key, value)) {
43
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
44
+ continue
45
+ }
46
+
47
+ if (value !== undefined) {
48
+ result[key] = value
49
+ }
50
+ }
51
+ }
52
+
53
+ result['style'] = {
54
+ ...(childProps['style'] as object),
55
+ ...(forwardedProps?.['style'] as object),
56
+ ...(ownProps?.['style'] as object),
57
+ }
58
+
59
+ for (const [key, value] of Object.entries(childProps)) {
60
+ if (isReactEventHandler(key, value)) {
61
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
62
+ }
63
+ }
64
+
65
+ return result
66
+ }
@@ -0,0 +1,14 @@
1
+ import {type ReactNode} from 'react'
2
+ import {createPortal} from 'react-dom'
3
+
4
+ export function renderPortal(node: ReactNode, mounted: boolean, portal?: boolean) {
5
+ if (!portal) {
6
+ return node
7
+ }
8
+
9
+ if (!mounted) {
10
+ return null
11
+ }
12
+
13
+ return createPortal(node, document.body)
14
+ }
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is generated by scripts/write-version.js. Do not edit.
2
- export const VERSION = '500alpha1'
3
- export const HASH = '162541'
2
+ export const VERSION = '500alpha10'
3
+ export const HASH = 'ad9fa1'