How to create a field macro similar to the tag macro

\define filter-pill(pill_filter pill_label:"FilterPill Label" pillcolour:lightgrey textcolour:#333333)
<$let popupID=<<qualify """$:/temp/state/$pill_label$""">>>
<$button dragFilter="$pill_filter$" class="tc-tag-label tc-btn-invisible" style="background-color:$pillcolour$; color:$textcolour$;" popup=<<qualify """$:/temp/state/$pill_label$$id$""">> >$pill_label$
</$button>
<$reveal type="popup" state=<<popupID>> >
<div class="tc-drop-down">
<$button> export
<$action-sendmessage $message="tm-download-file"
   $param="$:/core/templates/exporters/JsonFile"
   exportFilter="$pill_filter$"
   filename="tiddlers.json" /> 
</$button>
<hr>
{{{$pill_filter$}}}
</div>
</$reveal>
\end

<<filter-pill "[!is[system]search:title[Drop]]" """Non-system Tiddlers With "Drop" in the title""" "grey" "white" >>

<<filter-pill "[ae-cycle[shadow]]" """Non-system Tiddlers With "Drop" in the title""" "grey" "white" >>

<<filter-pill "[leftbar[shadow]]" """Non-system Tiddlers With "Drop" in the title""" "grey" "white" >>

@EricShulman I tried this code, but its not working. You had helped me in the past for a similar problem. I had tried this method of using qualify macro and stateID before, then also it didnt work. Must be due to some problem with my code.