我在编写风格指南,使用Fabricator和the docs似乎表明我应该能够添加“控件”以让用户在各个部分上切换可见性。将“控件”添加到加工者的UI工具包中
默认情况下,Fabricator版本带有3个主切换:labels
,notes
和code
。我想添加第4个切换,我打电话给styles
。
的fabricator.js
文件看起来像这样的相关章节:
/**
* Default options
* @type {Object}
*/
fabricator.options = {
toggles: {
labels: true,
notes: true,
code: false,
styles: true,
},
menu: true,
mq: '(min-width: 60em)',
};
&
/**
* Handler for preview and code toggles
* @return {Object} fabricator
*/
fabricator.allItemsToggles =() => {
const itemCache = {
labels: document.querySelectorAll('[data-f-toggle="labels"]'),
notes: document.querySelectorAll('[data-f-toggle="notes"]'),
code: document.querySelectorAll('[data-f-toggle="code"]'),
styles: document.querySelectorAll('[data-f-toggle="styles"]'),
};
}
正如你所看到的,我已经添加了我的styles
切换到fabricator.options
对象和对itemCache对象与现有元素的格式匹配。
我还添加了新的styles
部分的控件和内容谐音:
f-item-controls.html
{{!-- this is part of the default build --}}
{{#if notes}}
<span class="f-control f-icon" data-f-toggle-control="notes" title="Toggle Notes">
<svg>
<use xlink:href="#f-icon-notes" />
</svg>
</span>
{{/if}}
{{!-- this is my matching addition --}}
{{#if styles}}
<span class="f-control f-icon" data-f-toggle-control="styles" title="Toggle Styles">
<svg>
<use xlink:href="#f-icon-styles" />
</svg>
</span>
{{/if}}
f-item-content.html
{{!-- this is part of the default build --}}
{{#if notes}}
<div class="f-item-notes" data-f-toggle="notes">
{{{notes}}}
</div>
{{/if}}
{{!-- this is my matching addition --}}
{{#if styles}}
<div class="f-item-styles" data-f-toggle="styles">
{{{styles}}}
</div>
{{/if}}
最后,只是让我有内容的工作,我添加了一些我的按钮组件可以呈现的'前端'数据:
---
notes: |
These are notes written in `markdown`
styles: |
These are styles written in `markdown`
---
notes
(默认构建的一部分)呈现并正确切换; styles
根本不渲染。如果删除styles
块的{{#if}}条件,则会生成control
图标和相应的content
<div>
,但实际的style
文本仍然丢失。
我已经与Luke Askew(制造者的创造者)联系,要求澄清,但我还没有收到他的回复。与此同时,我希望SO社区中的某个人能够帮助我理解这是如何工作的,以便我可以继续我的工作。