@graphprotocol/gds-react 0.2.0 → 0.2.2

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 (129) hide show
  1. package/dist/GDSContext.d.ts +13 -0
  2. package/dist/GDSContext.d.ts.map +1 -0
  3. package/dist/GDSContext.js +4 -0
  4. package/dist/GDSContext.js.map +1 -0
  5. package/dist/GDSProvider.d.ts +1 -9
  6. package/dist/GDSProvider.d.ts.map +1 -1
  7. package/dist/GDSProvider.js +4 -3
  8. package/dist/GDSProvider.js.map +1 -1
  9. package/dist/components/Avatar.d.ts.map +1 -1
  10. package/dist/components/Avatar.js +2 -2
  11. package/dist/components/Avatar.js.map +1 -1
  12. package/dist/components/Breadcrumbs.parts.js +1 -1
  13. package/dist/components/Breadcrumbs.parts.js.map +1 -1
  14. package/dist/components/Button.d.ts.map +1 -1
  15. package/dist/components/Button.js +69 -69
  16. package/dist/components/Button.js.map +1 -1
  17. package/dist/components/Card.js +2 -2
  18. package/dist/components/Card.js.map +1 -1
  19. package/dist/components/CodeBlock.d.ts +1 -1
  20. package/dist/components/CodeBlock.parts.d.ts +1 -1
  21. package/dist/components/CopyButton.d.ts +1 -1
  22. package/dist/components/CopyButton.d.ts.map +1 -1
  23. package/dist/components/CopyButton.js +46 -19
  24. package/dist/components/CopyButton.js.map +1 -1
  25. package/dist/components/Input.js +2 -2
  26. package/dist/components/Input.js.map +1 -1
  27. package/dist/components/Link.js +2 -2
  28. package/dist/components/Link.js.map +1 -1
  29. package/dist/components/Menu.parts.d.ts +4 -5
  30. package/dist/components/Menu.parts.d.ts.map +1 -1
  31. package/dist/components/Menu.parts.js +52 -45
  32. package/dist/components/Menu.parts.js.map +1 -1
  33. package/dist/components/Modal.parts.d.ts.map +1 -1
  34. package/dist/components/Modal.parts.js +17 -21
  35. package/dist/components/Modal.parts.js.map +1 -1
  36. package/dist/components/Pane.d.ts +9 -0
  37. package/dist/components/Pane.d.ts.map +1 -0
  38. package/dist/components/Pane.js +8 -0
  39. package/dist/components/Pane.js.map +1 -0
  40. package/dist/components/Pane.meta.d.ts +20 -0
  41. package/dist/components/Pane.meta.d.ts.map +1 -0
  42. package/dist/components/Pane.meta.js +30 -0
  43. package/dist/components/Pane.meta.js.map +1 -0
  44. package/dist/components/Pane.parts.d.ts +77 -0
  45. package/dist/components/Pane.parts.d.ts.map +1 -0
  46. package/dist/components/Pane.parts.js +412 -0
  47. package/dist/components/Pane.parts.js.map +1 -0
  48. package/dist/components/Search.js +1 -1
  49. package/dist/components/Tooltip.parts.d.ts +13 -4
  50. package/dist/components/Tooltip.parts.d.ts.map +1 -1
  51. package/dist/components/Tooltip.parts.js +51 -63
  52. package/dist/components/Tooltip.parts.js.map +1 -1
  53. package/dist/components/base/ButtonOrLink.d.ts +1 -1
  54. package/dist/components/base/ButtonOrLink.d.ts.map +1 -1
  55. package/dist/components/base/ButtonOrLink.parts.d.ts +10 -3
  56. package/dist/components/base/ButtonOrLink.parts.d.ts.map +1 -1
  57. package/dist/components/base/ButtonOrLink.parts.js +27 -35
  58. package/dist/components/base/ButtonOrLink.parts.js.map +1 -1
  59. package/dist/components/base/MaybeButtonOrLink.d.ts +19 -2
  60. package/dist/components/base/MaybeButtonOrLink.d.ts.map +1 -1
  61. package/dist/components/base/MaybeButtonOrLink.js +5 -3
  62. package/dist/components/base/MaybeButtonOrLink.js.map +1 -1
  63. package/dist/components/base/Presence.d.ts +157 -0
  64. package/dist/components/base/Presence.d.ts.map +1 -0
  65. package/dist/components/base/Presence.js +808 -0
  66. package/dist/components/base/Presence.js.map +1 -0
  67. package/dist/components/base/index.d.ts +1 -0
  68. package/dist/components/base/index.d.ts.map +1 -1
  69. package/dist/components/base/index.js +1 -0
  70. package/dist/components/base/index.js.map +1 -1
  71. package/dist/components/index.d.ts +2 -0
  72. package/dist/components/index.d.ts.map +1 -1
  73. package/dist/components/index.js +2 -0
  74. package/dist/components/index.js.map +1 -1
  75. package/dist/hooks/useCSSProp.js +1 -1
  76. package/dist/hooks/useCSSProp.js.map +1 -1
  77. package/dist/hooks/useControlled.d.ts.map +1 -1
  78. package/dist/hooks/useControlled.js +6 -4
  79. package/dist/hooks/useControlled.js.map +1 -1
  80. package/dist/hooks/useGDS.js +1 -1
  81. package/dist/hooks/useGDS.js.map +1 -1
  82. package/dist/hooks/useStyleObserver.js +1 -1
  83. package/dist/hooks/useStyleObserver.js.map +1 -1
  84. package/dist/tailwind-plugin.d.ts.map +1 -1
  85. package/dist/tailwind-plugin.js +3 -0
  86. package/dist/tailwind-plugin.js.map +1 -1
  87. package/dist/utils/InlineCounter.d.ts +3 -0
  88. package/dist/utils/InlineCounter.d.ts.map +1 -0
  89. package/dist/utils/InlineCounter.js +7 -0
  90. package/dist/utils/InlineCounter.js.map +1 -0
  91. package/dist/utils/RenderCount.d.ts +3 -0
  92. package/dist/utils/RenderCount.d.ts.map +1 -0
  93. package/dist/utils/RenderCount.js +7 -0
  94. package/dist/utils/RenderCount.js.map +1 -0
  95. package/dist/utils/index.d.ts +2 -0
  96. package/dist/utils/index.d.ts.map +1 -1
  97. package/dist/utils/index.js +2 -0
  98. package/dist/utils/index.js.map +1 -1
  99. package/package.json +14 -14
  100. package/src/GDSContext.ts +16 -0
  101. package/src/GDSProvider.tsx +20 -31
  102. package/src/components/Avatar.tsx +3 -2
  103. package/src/components/Breadcrumbs.parts.tsx +1 -1
  104. package/src/components/Button.tsx +113 -107
  105. package/src/components/Card.tsx +2 -2
  106. package/src/components/CopyButton.tsx +49 -25
  107. package/src/components/Input.tsx +1 -1
  108. package/src/components/Link.tsx +2 -2
  109. package/src/components/Menu.parts.tsx +78 -73
  110. package/src/components/Modal.parts.tsx +26 -31
  111. package/src/components/Pane.meta.ts +31 -0
  112. package/src/components/Pane.parts.tsx +713 -0
  113. package/src/components/Pane.tsx +17 -0
  114. package/src/components/Search.tsx +1 -1
  115. package/src/components/Tooltip.parts.tsx +95 -80
  116. package/src/components/base/ButtonOrLink.parts.tsx +71 -51
  117. package/src/components/base/ButtonOrLink.tsx +1 -0
  118. package/src/components/base/MaybeButtonOrLink.tsx +26 -5
  119. package/src/components/base/Presence.tsx +1375 -0
  120. package/src/components/base/index.ts +1 -0
  121. package/src/components/index.ts +10 -0
  122. package/src/hooks/useCSSProp.ts +1 -1
  123. package/src/hooks/useControlled.ts +16 -8
  124. package/src/hooks/useGDS.ts +1 -1
  125. package/src/hooks/useStyleObserver.ts +1 -1
  126. package/src/tailwind-plugin.ts +3 -0
  127. package/src/utils/InlineCounter.tsx +17 -0
  128. package/src/utils/RenderCount.tsx +7 -0
  129. package/src/utils/index.ts +2 -0
@@ -18,6 +18,7 @@ export { Field, type FieldProps, type FieldState } from './Field.tsx'
18
18
  export { FieldMeta } from './Field.meta.ts'
19
19
  export { MaybeButtonOrLink, type MaybeButtonOrLinkProps } from './MaybeButtonOrLink.tsx'
20
20
  export { Portal } from './Portal.tsx'
21
+ export { Presence, usePresence, type PresenceProps } from './Presence.tsx'
21
22
  export {
22
23
  Render,
23
24
  type RenderFnProps,
@@ -63,6 +63,16 @@ export {
63
63
  export { ModalMeta } from './Modal.meta.ts'
64
64
  export { OTCInput, type OTCInputProps } from './OTCInput.tsx'
65
65
  export { OTCInputMeta } from './OTCInput.meta.ts'
66
+ export {
67
+ Pane,
68
+ usePane,
69
+ type PaneContainerProps,
70
+ type PaneProps,
71
+ type PaneProviderProps,
72
+ type PaneToggleButtonProps,
73
+ type UsePaneOptions,
74
+ } from './Pane.tsx'
75
+ export { PaneContainerMeta, PaneMeta } from './Pane.meta.ts'
66
76
  export { Radio, type RadioAreaProps, type RadioGroupProps, type RadioProps } from './Radio.tsx'
67
77
  export { RadioMeta } from './Radio.meta.ts'
68
78
  export { Search, type SearchProps } from './Search.tsx'
@@ -8,7 +8,7 @@ import {
8
8
  type GDSComponent,
9
9
  } from '@graphprotocol/gds-css'
10
10
 
11
- import { styleScheduler } from '../utils/styleScheduler.ts'
11
+ import { styleScheduler } from '../utils/index.ts'
12
12
 
13
13
  /**
14
14
  * Returns a `ref` to set on an element, and an async function to get the current value of a CSS
@@ -1,20 +1,28 @@
1
- import { useState } from 'react'
1
+ import { useCallback, useRef, useState } from 'react'
2
2
 
3
3
  export function useControlled<T, OnChangeValue extends T = T, OnChangeArgs extends unknown[] = []>(
4
4
  controlledValue: T | undefined,
5
5
  defaultValue: T,
6
6
  onChange?: (value: OnChangeValue, ...args: OnChangeArgs) => void,
7
7
  ) {
8
+ const onChangeRef = useRef(onChange)
9
+ onChangeRef.current = onChange
10
+
8
11
  const [uncontrolledValue, setUncontrolledValue] = useState(
9
12
  controlledValue !== undefined ? controlledValue : defaultValue,
10
13
  )
14
+
11
15
  const value = controlledValue !== undefined ? controlledValue : uncontrolledValue
12
- const setValue = (newValue: OnChangeValue, ...args: OnChangeArgs) => {
13
- if (newValue === value) return
14
- onChange?.(newValue, ...args)
15
- if (controlledValue === undefined) {
16
- setUncontrolledValue(newValue)
17
- }
18
- }
16
+ const setValue = useCallback(
17
+ (newValue: OnChangeValue, ...args: OnChangeArgs) => {
18
+ if (newValue === value) return
19
+ onChangeRef.current?.(newValue, ...args)
20
+ if (controlledValue === undefined) {
21
+ setUncontrolledValue(newValue)
22
+ }
23
+ },
24
+ [controlledValue, value],
25
+ )
26
+
19
27
  return [value, setValue] as const
20
28
  }
@@ -1,6 +1,6 @@
1
1
  import { useContext } from 'react'
2
2
 
3
- import { GDSContext } from '../GDSProvider.tsx'
3
+ import { GDSContext } from '../GDSContext.ts'
4
4
 
5
5
  /** Throws an error if used outside of a `GDSProvider`. */
6
6
  export function useGDS() {
@@ -2,7 +2,7 @@ import { useCallback, useLayoutEffect, useRef, type Ref } from 'react'
2
2
  import { useMergedRefs } from '@base-ui/utils/useMergedRefs'
3
3
  import StyleObserver from 'style-observer'
4
4
 
5
- import { styleScheduler } from '../utils/styleScheduler.ts'
5
+ import { styleScheduler } from '../utils/index.ts'
6
6
  import { useEffectWithRefDeps } from './useEffectWithRefDeps.ts'
7
7
 
8
8
  type Record<T extends string> = Parameters<ConstructorParameters<typeof StyleObserver>[0]>[0][0] & {
@@ -31,6 +31,7 @@ import { LinkMeta } from './components/Link.meta.ts'
31
31
  import { MenuItemMeta, MenuMeta } from './components/Menu.meta.ts'
32
32
  import { ModalMeta } from './components/Modal.meta.ts'
33
33
  import { OTCInputMeta } from './components/OTCInput.meta.ts'
34
+ import { PaneContainerMeta, PaneMeta } from './components/Pane.meta.ts'
34
35
  import { RadioMeta } from './components/Radio.meta.ts'
35
36
  import { SearchMeta } from './components/Search.meta.ts'
36
37
  import {
@@ -104,6 +105,8 @@ const gdsTailwindPluginWithComponents: ReturnType<typeof createPlugin> = createP
104
105
  MenuMeta,
105
106
  ModalMeta,
106
107
  OTCInputMeta,
108
+ PaneContainerMeta,
109
+ PaneMeta,
107
110
  RadioMeta,
108
111
  SearchMeta,
109
112
  SegmentedControlMeta,
@@ -0,0 +1,17 @@
1
+ import { useState, type ComponentProps } from 'react'
2
+
3
+ export function InlineCounter(props: ComponentProps<'span'>) {
4
+ const [count, setCount] = useState(0)
5
+ return (
6
+ <span {...props}>
7
+ {count}{' '}
8
+ <button
9
+ type="button"
10
+ onClick={() => setCount((prev) => prev + 1)}
11
+ className="inline hover:underline"
12
+ >
13
+ (increment)
14
+ </button>
15
+ </span>
16
+ )
17
+ }
@@ -0,0 +1,7 @@
1
+ import type { ComponentProps } from 'react'
2
+ import { useRenderCount } from '@react-hookz/web'
3
+
4
+ export function RenderCount(props: ComponentProps<'span'>) {
5
+ const renderCount = useRenderCount()
6
+ return <span {...props}>{renderCount}</span>
7
+ }
@@ -2,8 +2,10 @@ export { cn } from './cn.ts'
2
2
  export { getAssetUrl } from './getAssetUrl.ts'
3
3
  export { getCSSPropsAttributes } from './getCSSPropsAttributes.ts'
4
4
  export { getReactNodeKey } from './getReactNodeKey.ts'
5
+ export { InlineCounter } from './InlineCounter.tsx'
5
6
  export { isReactNode } from './isReactNode.ts'
6
7
  export { reactNodeToString } from './reactNodeToString.ts'
8
+ export { RenderCount } from './RenderCount.tsx'
7
9
  export { splitProps } from './splitProps.ts'
8
10
  export { styleScheduler } from './styleScheduler.ts'
9
11
  export { trimReactNode } from './trimReactNode.tsx'