mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-07-20 13:49:37 +02:00
feat(ui): tool header
This commit is contained in:
parent
161b9e6bca
commit
00fd51a8e3
6 changed files with 156 additions and 53 deletions
|
@ -1,10 +1,12 @@
|
|||
import type { Accessor, ParentComponent } from 'solid-js';
|
||||
import type { ToolDefinition } from './tools.types';
|
||||
import { flatten, translator } from '@solid-primitives/i18n';
|
||||
import { merge } from 'lodash-es';
|
||||
import { createContext, useContext } from 'solid-js';
|
||||
|
||||
type ToolProviderContext = {
|
||||
toolLocaleDict: Accessor<Record<string, string>>;
|
||||
tool: Accessor<Pick<ToolDefinition, 'icon' | 'dirName' | 'createdAt'> & { name: string; description: string }>;
|
||||
};
|
||||
|
||||
const CurrentToolContext = createContext<ToolProviderContext>();
|
||||
|
@ -16,8 +18,11 @@ export function useCurrentTool<T>({ defaultDictionary }: { defaultDictionary: T
|
|||
throw new Error('useCurrentTool must be used within a CurrentToolProvider');
|
||||
}
|
||||
|
||||
const { toolLocaleDict, tool } = context;
|
||||
|
||||
return {
|
||||
t: translator(() => flatten(merge({}, defaultDictionary, context.toolLocaleDict()))),
|
||||
t: translator(() => flatten(merge({}, defaultDictionary, toolLocaleDict()))),
|
||||
getTool: tool,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue