mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-20 22:50:11 -04:00
* WIP * Some minor fixes for light theme - Fix `useIsDark` not reading the initial theme value (only reacting to theme changes) - Fix `Inspector` always showing a dark image when no item was selected - Fix `Thumb` video extension using black text on light theme * Improve form error messages - Fix `addLocationDialog` not registering the path input - Remove `@hookform/error-message` * Fix Dialog not respecting max-width - Fix ErrorMessage animation jumping * A lot of misc fixes - Implement an `useExplorerItemData` (cleaner fix for thumbnail flicker) - Fix broken image showing for `Thumb` due a rece condition when props are updated - Implement an `ExternalObject` component that hacks an alternative for `onLoad` and `onError` events for <object> - Fix `Overview` broken layout when `Inspector` is open and window is small - Improve `IndexerRuleEditor` UX in `AddLocationDialog` - Improve the way `IndexerRuleEditor` handles rules deletion - Fix `IndexerRuleEditor` closing the the new rule form even when the rule creation fails - Add an editable prop to `IndexerRuleEditor` to disable all editable functions - Fix `getIcon` fallbacking to Document instead of the dark version of an icon if it exists - Add some missing colors to white theme * Format * Fix Backup restore key dialog not resetting after error * Feedback * Format * Normalize imports * Fix ColorPicker export * Fix Thumb video ext not showing in MediaView with show square thumbnails - Fix AddLocationDialog Error resetting when changing IndexRules
38 lines
992 B
TypeScript
38 lines
992 B
TypeScript
import * as icons from '.';
|
|
|
|
// Record is defined as follows inside TypeScript
|
|
export type IconTypes<K = keyof typeof icons> = K extends `${string}_${string}` ? never : K;
|
|
|
|
export const iconNames = Object.fromEntries(
|
|
Object.keys(icons)
|
|
.filter((key) => !key.includes('_'))
|
|
.map((key) => [key, key])
|
|
) as Record<IconTypes, string>;
|
|
|
|
export const getIcon = (
|
|
kind: string,
|
|
isDark?: boolean,
|
|
extension?: string | null,
|
|
isDir?: boolean
|
|
) => {
|
|
if (isDir) return icons[isDark ? 'Folder' : 'Folder_Light'];
|
|
|
|
let document: Extract<keyof typeof icons, 'Document' | 'Document_Light'> = 'Document';
|
|
if (extension) extension = `${kind}_${extension.toLowerCase()}`;
|
|
if (!isDark) {
|
|
document = 'Document_Light';
|
|
if (extension) extension = extension + '_Light';
|
|
}
|
|
|
|
const lightKind = kind + '_Light';
|
|
return icons[
|
|
(extension && extension in icons
|
|
? extension
|
|
: !isDark && lightKind in icons
|
|
? lightKind
|
|
: kind in icons
|
|
? kind
|
|
: document) as keyof typeof icons
|
|
];
|
|
};
|