Obsidian API์ ์ฌ๋ฌ ๊ตฌ์ฑ ์์, ์๋ฅผ ๋ค์ด Settings๋ ์ปจํ ์ด๋ ์์(container elements) ๋ฅผ ๋ ธ์ถํฉ๋๋ค:
import { App, PluginSettingTab } from 'obsidian';
class ExampleSettingTab extends PluginSettingTab {
plugin: ExamplePlugin;
constructor(app: App, plugin: ExamplePlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
// highlight-next-line
let { containerEl } = this;
// ...
}
}
์ปจํ
์ด๋ ์์๋ Obsidian ๋ด์์ ์ฌ์ฉ์ ์ ์ ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค ์ ์๊ฒ ํด์ฃผ๋ HTMLElement
๊ฐ์ฒด์
๋๋ค.
createEl()
์ ์ฌ์ฉํ์ฌ HTML ์์ ์์ฑํ๊ธฐ
์ปจํ
์ด๋ ์์๋ฅผ ํฌํจํ ๋ชจ๋ HTMLElement
๋ ์๋ณธ ์์ ์๋์ HTMLElement
๋ฅผ ์์ฑํ๋ createEl()
๋ฉ์๋๋ฅผ ๋
ธ์ถํฉ๋๋ค.
์๋ฅผ ๋ค์ด, ์ปจํ
์ด๋ ์์ ๋ด๋ถ์ <h1>
์ ๋ชฉ ์์๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
containerEl.createEl('h1', { text: 'Heading 1' });
createEl()
์ ์ ์์์ ๋ํ ์ฐธ์กฐ๋ฅผ ๋ฐํํฉ๋๋ค:
const book = containerEl.createEl('div');
book.createEl('div', { text: 'How to Take Smart Notes' });
book.createEl('small', { text: 'Sรถnke Ahrens' });
์์ ์คํ์ผ๋งํ๊ธฐ
ํ๋ฌ๊ทธ์ธ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์ styles.css
ํ์ผ์ ์ถ๊ฐํ์ฌ ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉ์ ์ ์ CSS ์คํ์ผ์ ์ถ๊ฐํ ์ ์์ต๋๋ค. ์ด์ ์ฑ
์์ ์ ๋ํ ์คํ์ผ์ ์ถ๊ฐํ๋ ค๋ฉด:
.book {
border: 1px solid var(--background-modifier-border);
padding: 10px;
}
.book__title {
font-weight: 600;
}
.book__author {
color: var(--text-muted);
}
Tip
--background-modifier-border
์--text-muted
๋ Obsidian ์์ฒด์์ ์ ์ํ๊ณ ์ฌ์ฉํ๋ CSS ๋ณ์์ ๋๋ค. ์คํ์ผ์ ์ด ๋ณ์๋ค์ ์ฌ์ฉํ๋ฉด ์ฌ์ฉ์๊ฐ ๋ค๋ฅธ ํ ๋ง๋ฅผ ์ฌ์ฉํ๋๋ผ๋ ํ๋ฌ๊ทธ์ธ์ด ๋ฉ์ง๊ฒ ๋ณด์ผ ๊ฒ์ ๋๋ค! ๐
HTML ์์๊ฐ ์คํ์ผ์ ์ฌ์ฉํ๋๋ก ํ๋ ค๋ฉด HTML ์์์ cls
์์ฑ์ ์ค์ ํ์ธ์:
const book = containerEl.createEl('div', { cls: 'book' });
book.createEl('div', { text: 'How to Take Smart Notes', cls: 'book__title' });
book.createEl('small', { text: 'Sรถnke Ahrens', cls: 'book__author' });
์ด์ ํจ์ฌ ์ข์ ๋ณด์ ๋๋ค! ๐
์กฐ๊ฑด๋ถ ์คํ์ผ
์ฌ์ฉ์ ์ค์ ์ด๋ ๋ค๋ฅธ ๊ฐ์ ๋ฐ๋ผ ์์์ ์คํ์ผ์ ๋ณ๊ฒฝํ๋ ค๋ฉด toggleClass
๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ธ์:
element.toggleClass('danger', status === 'error');