@sanity/ui 5.0.0-alpha.20 → 5.0.0-alpha.21

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": "5.0.0-alpha.20",
3
+ "version": "5.0.0-alpha.21",
4
4
  "description": "Sanity UI Library",
5
5
  "keywords": [
6
6
  "components",
@@ -1,7 +1,6 @@
1
1
  import clsx from 'clsx'
2
- import {type ComponentPropsWithRef, lazy, Suspense} from 'react'
2
+ import {lazy, Suspense} from 'react'
3
3
 
4
- import {type CodeTag} from '../../types/Code'
5
4
  import {getProps} from '../../utils/getProps'
6
5
  import {suffixClassName} from '../../utils/suffixClassName'
7
6
  import {type CodeProps, codeProps} from './code.props'
@@ -11,26 +10,26 @@ const LazyRefractor = lazy(() => import('./LazyRefractor'))
11
10
  const codeClassName = suffixClassName('sui-Code')
12
11
 
13
12
  /** @public */
14
- export function Code<T extends CodeTag = 'pre'>({
15
- size = 2,
16
- ...props
17
- }: CodeProps<T> & Omit<ComponentPropsWithRef<T>, keyof CodeProps<T>>) {
18
- const {as, children, className, language, style, ...rest} = getProps({size, ...props}, codeProps)
19
- const Component = as || 'pre'
20
-
21
- if (!language) {
22
- return (
23
- <Component className={clsx(codeClassName, className)} style={style} data-ui="Code" {...rest}>
24
- <code>{children}</code>
25
- </Component>
26
- )
27
- }
13
+ export function Code({size = 2, ...props}: CodeProps) {
14
+ const {children, className, inline, language, style, ...rest} = getProps(
15
+ {size, ...props},
16
+ codeProps,
17
+ )
18
+ /*
19
+ * The span wrapper for inline code is necessary because react-refractor does not
20
+ * support any attributes other than className
21
+ */
22
+ const Component = inline ? 'span' : 'pre'
28
23
 
29
24
  return (
30
25
  <Component className={clsx(codeClassName, className)} style={style} data-ui="Code" {...rest}>
31
- <Suspense fallback={<code>{children}</code>}>
32
- <LazyRefractor language={language} value={children} />
33
- </Suspense>
26
+ {language ? (
27
+ <Suspense fallback={<code>{children}</code>}>
28
+ <LazyRefractor language={language} value={children} />
29
+ </Suspense>
30
+ ) : (
31
+ <code>{children}</code>
32
+ )}
34
33
  </Component>
35
34
  )
36
35
  }
@@ -1,19 +1,10 @@
1
1
  import {marginProps} from '../../props/margin'
2
2
  import {type TypographyProps, typographyProps} from '../../props/typography'
3
- import {CODE_SIZE, CODE_TAG, type CodeSize, type CodeTag} from '../../types/Code'
3
+ import {CODE_SIZE, type CodeSize} from '../../types/Code'
4
4
  import {type PropDef} from '../../types/PropDef'
5
5
  import type {Responsive} from '../../types/Responsive'
6
6
 
7
- /** @public */
8
- export interface CodeProps<T extends CodeTag = 'pre'> extends Omit<
9
- TypographyProps,
10
- 'align' | 'truncate' | 'tone'
11
- > {
12
- /**
13
- * HTML element or component to render.
14
- * @remarks The defined element wraps an inner `<code>` tag.
15
- */
16
- as?: T
7
+ interface CodeBaseProps extends Omit<TypographyProps, 'align' | 'truncate' | 'tone' | 'weight'> {
17
8
  /**
18
9
  * Refractor language for syntax highlighting.
19
10
  */
@@ -24,10 +15,22 @@ export interface CodeProps<T extends CodeTag = 'pre'> extends Omit<
24
15
  size?: Responsive<CodeSize>
25
16
  }
26
17
 
18
+ /** @public */
19
+ export type CodeProps =
20
+ | (CodeBaseProps & {
21
+ /**
22
+ * Render code inline or as a block.
23
+ * @remarks Block code is wrapped in a `<pre>` tag.
24
+ */
25
+ inline?: false
26
+ } & Omit<React.ComponentPropsWithRef<'pre'>, keyof CodeBaseProps>)
27
+ | (CodeBaseProps & {
28
+ inline: true
29
+ } & Omit<React.ComponentPropsWithRef<'span'>, keyof CodeBaseProps>)
30
+
27
31
  export const codeProps: Record<string, PropDef> = {
28
- as: {
29
- type: 'union',
30
- values: CODE_TAG,
32
+ inline: {
33
+ type: 'boolean',
31
34
  },
32
35
  language: {
33
36
  type: 'string',
@@ -39,6 +42,5 @@ export const codeProps: Record<string, PropDef> = {
39
42
  },
40
43
  muted: typographyProps['muted'] as PropDef,
41
44
  trim: typographyProps['trim'] as PropDef,
42
- weight: typographyProps['weight'] as PropDef,
43
45
  ...marginProps,
44
46
  }
@@ -66,7 +66,7 @@ function DialogRoot({open = false, size = 0, ...props}: DialogProps) {
66
66
  >
67
67
  <Flex flexShrink={0} justifyContent="space-between" alignItems="center">
68
68
  {header ? (
69
- <Heading trim size={1} id={headerId}>
69
+ <Heading as="h2" trim size={1} id={headerId}>
70
70
  {header}
71
71
  </Heading>
72
72
  ) : (
@@ -10,10 +10,9 @@ const headingClassName = suffixClassName('sui-Heading')
10
10
  /** @public */
11
11
  export function Heading<T extends ElementType = 'h2'>({
12
12
  size = 2,
13
- weight = 'bold',
14
13
  ...props
15
14
  }: HeadingProps & Omit<ComponentPropsWithRef<T>, keyof HeadingProps>) {
16
- const {as, children, className, style, ...rest} = getProps({size, weight, ...props}, headingProps)
15
+ const {as, children, className, style, ...rest} = getProps({size, ...props}, headingProps)
17
16
  const Component = as || 'h2'
18
17
 
19
18
  if (props.truncate && props.trim) {
@@ -30,6 +29,7 @@ export function Heading<T extends ElementType = 'h2'>({
30
29
  <span
31
30
  className={clsx(
32
31
  'sui-overflow-hidden',
32
+ 'sui-weight-bold',
33
33
  props.truncate === 1 ? 'sui-text-overflow' : 'sui-line-clamp',
34
34
  )}
35
35
  >
@@ -41,7 +41,12 @@ export function Heading<T extends ElementType = 'h2'>({
41
41
 
42
42
  return (
43
43
  <Component
44
- className={clsx(headingClassName, props.truncate && 'sui-overflow-hidden', className)}
44
+ className={clsx(
45
+ headingClassName,
46
+ props.truncate && 'sui-overflow-hidden',
47
+ 'sui-weight-bold',
48
+ className,
49
+ )}
45
50
  style={style}
46
51
  data-ui="Heading"
47
52
  {...rest}
@@ -2,8 +2,3 @@
2
2
  --heading-color: var(--foreground-high);
3
3
  color: var(--heading-color);
4
4
  }
5
-
6
- .sui-Heading:where(.sui-text-muted) {
7
- --heading-color-muted: var(--foreground-low);
8
- color: var(--heading-color-muted);
9
- }
@@ -1,15 +1,16 @@
1
+ import {marginProps} from '../../props/margin'
2
+ import {toneProps} from '../../props/tone'
1
3
  import {type TypographyProps, typographyProps} from '../../props/typography'
2
4
  import {HEADING_SIZE, HEADING_TAG, type HeadingSize, type HeadingTag} from '../../types/Heading'
3
5
  import {type PropDef} from '../../types/PropDef'
4
6
  import type {Responsive} from '../../types/Responsive'
5
7
 
6
8
  /** @public */
7
- export interface HeadingProps extends TypographyProps {
9
+ export interface HeadingProps extends Omit<TypographyProps, 'muted' | 'weight'> {
8
10
  /**
9
11
  * Semantic heading element to render.
10
- * @remarks Always set this explicitly.
11
12
  */
12
- as?: HeadingTag
13
+ as: HeadingTag
13
14
  /**
14
15
  * Sets font size.
15
16
  * @remarks Independent of `as`.
@@ -27,5 +28,9 @@ export const headingProps: Record<string, PropDef> = {
27
28
  className: 'text-heading',
28
29
  values: HEADING_SIZE,
29
30
  },
30
- ...typographyProps,
31
+ align: typographyProps['align'] as PropDef,
32
+ trim: typographyProps['trim'] as PropDef,
33
+ truncate: typographyProps['truncate'] as PropDef,
34
+ ...marginProps,
35
+ ...toneProps,
31
36
  }
@@ -74,6 +74,10 @@
74
74
  border-spacing: 0;
75
75
  }
76
76
 
77
+ :where(code) {
78
+ font-family: var(--mono);
79
+ }
80
+
77
81
  /* Enforce no animations for users that prefer reduced motion*/
78
82
  @media (prefers-reduced-motion: reduce) {
79
83
  *,
package/src/types/Code.ts CHANGED
@@ -1,6 +1,3 @@
1
- export const CODE_TAG = ['pre', 'span'] as const
2
- export type CodeTag = (typeof CODE_TAG)[number]
3
-
4
1
  export const CODE_SIZE = [0, 1, 2, 3, 4] as const
5
2
  /** @public */
6
3
  export type CodeSize = (typeof CODE_SIZE)[number]
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 = '500alpha20'
3
- export const HASH = '77fbb7'
2
+ export const VERSION = '500alpha21'
3
+ export const HASH = 'd891eb'