MCPcopy Create free account
hub / github.com/TanStack/query / CopyButton

Function CopyButton

packages/query-devtools/src/Explorer.tsx:87–138  ·  view source on GitHub ↗
(props: { value: unknown })

Source from the content-addressed store, hash-verified

85
86type CopyState = 'NoCopy' | 'SuccessCopy' | 'ErrorCopy'
87const CopyButton = (props: { value: unknown }) => {
88 const theme = useTheme()
89 const themed = createThemed(theme)
90 const [copyState, setCopyState] = createSignal<CopyState>('NoCopy')
91
92 return (
93 <button
94 class={themed('tsqd-style-explorer-action-button')}
95 title="Copy object to clipboard"
96 aria-label={`${
97 copyState() === 'NoCopy'
98 ? 'Copy object to clipboard'
99 : copyState() === 'SuccessCopy'
100 ? 'Object copied to clipboard'
101 : 'Error copying object to clipboard'
102 }`}
103 onClick={
104 copyState() === 'NoCopy'
105 ? () => {
106 navigator.clipboard.writeText(stringify(props.value)).then(
107 () => {
108 setCopyState('SuccessCopy')
109 setTimeout(() => {
110 setCopyState('NoCopy')
111 }, 1500)
112 },
113 (err) => {
114 console.error('Failed to copy: ', err)
115 setCopyState('ErrorCopy')
116 setTimeout(() => {
117 setCopyState('NoCopy')
118 }, 1500)
119 },
120 )
121 }
122 : undefined
123 }
124 >
125 <Switch>
126 <Match when={copyState() === 'NoCopy'}>
127 <Copier />
128 </Match>
129 <Match when={copyState() === 'SuccessCopy'}>
130 <CopiedCopier theme={theme()} />
131 </Match>
132 <Match when={copyState() === 'ErrorCopy'}>
133 <ErrorCopier />
134 </Match>
135 </Switch>
136 </button>
137 )
138}
139
140const ClearArrayButton = (props: {
141 dataPath: Array<string>

Callers

nothing calls this directly

Calls 2

useThemeFunction · 0.90
createThemedFunction · 0.90

Tested by

no test coverage detected