Skip to content

Commit

Permalink
Better third-party theme compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
phibr0 committed Jun 8, 2022
1 parent d60fbda commit 0373039
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "cmdr",
"name": "Commander",
"version": "0.0.2",
"version": "0.0.3",
"minAppVersion": "0.12.0",
"description": "Customize your workspace by adding commands /everywhere/.",
"author": "jsmorabito & phibr0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cmdr",
"version": "0.0.2",
"version": "0.0.3",
"description": "Customize your workspace by adding commands /everywhere/.",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
display: flex;
place-items: center;
flex-flow: column;
height: 80%;
margin: 3rem 0px;
place-content: center;

svg {
Expand Down Expand Up @@ -143,7 +143,7 @@
flex-direction: column;
align-items: flex-start;
border: none;
background-color: var(--background-secondary-alt);
background-color: var(--background-modifier-border);
padding: 6px 12px;
border-radius: 12px;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/commandViewerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export default function CommandViewer({ manager, plugin }: CommandViewerProps):
await manager.addCommand(pair);
this.forceUpdate();
}}
aria-label="Add new"
>
<div ref={addIcon} />
Add new
</button>
</div>
</ManagerContext.Provider>
Expand Down
12 changes: 1 addition & 11 deletions src/ui/components/macroBuilderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useRef, useState, } from "preact/hooks";
import ReactFlow, { useEdgesState, useNodesState, Background, Edge, ReactFlowProvider, addEdge } from 'react-flow-renderer/nocss';
import chroma from "chroma-js";
import { ReactFlowInstance } from "react-flow-renderer";
import { ObsidianIcon } from "src/util";

interface BaseComponentProps {
color: string;
Expand Down Expand Up @@ -112,14 +113,3 @@ export default function MacroBuilder(): h.JSX.Element {
</Fragment>
);
}

function ObsidianIcon({ icon, size }: { icon: string, size?: number }): h.JSX.Element {
const iconEl = useRef<HTMLDivElement>(null);

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
setIcon(iconEl.current!, icon, size);
}, [icon, size]);

return <div style={{ display: "grid" }} ref={iconEl} />;
}
15 changes: 14 additions & 1 deletion src/util.ts → src/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { CommandIconPair } from './types';
import CommanderPlugin from "./main";
import AddCommandModal from "./ui/addCommandModal";
import ChooseIconModal from './ui/chooseIconModal';
import { Command } from 'obsidian';
import { Command, setIcon } from 'obsidian';
import ChooseCustomNameModal from './ui/chooseCustomNameModal';
import { h } from 'preact';
import { useRef, useEffect } from 'preact/hooks';

/**
* It creates a modal, waits for the user to select a command, and then creates another modal to wait
Expand Down Expand Up @@ -34,3 +36,14 @@ export async function chooseNewCommand(plugin: CommanderPlugin): Promise<Command
export function getCommandFromId(id: string): Command | null {
return app.commands.commands[id] ?? null;
}

export function ObsidianIcon({ icon, size }: { icon: string, size?: number }): h.JSX.Element {
const iconEl = useRef<HTMLDivElement>(null);

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
setIcon(iconEl.current!, icon, size);
}, [icon, size]);

return <div style={{ display: "grid" }} ref={iconEl} />;
}

0 comments on commit 0373039

Please sign in to comment.