MCPcopy Index your code
hub / github.com/tinyplex/tinybase / ConfirmableActions

Function ConfirmableActions

src/ui-solid-inspector/index.tsx:187–240  ·  view source on GitHub ↗
(
  props: {
    readonly actions: [
      icon: string,
      title: string,
      component: (props: OnDoneProp & Props) => JSXElement,
    ][];
  } & Props,
)

Source from the content-addressed store, hash-verified

185};
186
187const ConfirmableActions = <
188 Props extends TableProps | RowProps | CellProps | ValuesProps | ValueProps,
189>(
190 props: {
191 readonly actions: [
192 icon: string,
193 title: string,
194 component: (props: OnDoneProp & Props) => JSXElement,
195 ][];
196 } & Props,
197) => {
198 const [confirming, setConfirming] = createSignal<number>();
199 const handleDone = () => setConfirming(undefined);
200
201 createEffect(() => {
202 if (!isUndefined(confirming())) {
203 const handleKeyDown = (event: KeyboardEvent) => {
204 if (!isUndefined(confirming()) && event.key == 'Escape') {
205 event.preventDefault();
206 handleDone();
207 }
208 };
209 document.addEventListener('keydown', handleKeyDown);
210 onCleanup(() => document.removeEventListener('keydown', handleKeyDown));
211 }
212 });
213
214 const content = () => {
215 const confirmingIndex = confirming();
216 const Component = isUndefined(confirmingIndex)
217 ? undefined
218 : props.actions[confirmingIndex][2];
219 return (
220 <>
221 {Component ? (
222 <>
223 {Component({...props, onDone: handleDone})}
224 <img onClick={handleDone} title="Cancel" class="cancel" />
225 </>
226 ) : (
227 arrayMap(props.actions, ([icon, title], index) => (
228 <img
229 title={title}
230 class={icon}
231 onClick={() => setConfirming(index)}
232 />
233 ))
234 )}
235 </>
236 );
237 };
238
239 return <>{content()}</>;
240};
241
242const NewId = (
243 props: OnDoneProp & {

Callers 7

TablesActionsFunction · 0.70
TableActions1Function · 0.70
TableActions2Function · 0.70
RowActionsFunction · 0.70
CellActionsFunction · 0.70
ValuesActionsFunction · 0.70
ValueActionsFunction · 0.70

Calls 4

isUndefinedFunction · 0.90
addEventListenerMethod · 0.80
removeEventListenerMethod · 0.80
contentFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…