Documentation ¶
Overview ¶
Package merge defines the main Merger interface and its implementation. Import and use this package to instantiate a Merger. This package is used primarily to manage the merging of HTML attribute sets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClassMergeFunc ¶
The ClassMergeFunc is designed to be used with CSS classes. All of the classes in the incoming string that are not duplicates of those in the existing string will be merged together.
Types ¶
type MergeFunc ¶
A MergeFunc is a function that defines how two conflicting attributes should be merged. MergeFuncs should prioritise the incoming values and override existing values. If a MergeFunc does not know how to merge part of an attribute, it may return 'remaining'. Merged attributes should be returned in 'committed' in a type that is able to be converted to a string by fmt.Sprint(). 'remaining' attributes may be handled by downstream MergeFuncs.
type Merger ¶
The Merger type merges two attribute sets. These may be any kind of attributes but this package was made for merging HTML attributes
func New ¶
New instantiates a Merger for you. You must pass an 'attrsFuncMap' that defines the MergeFuncs, though this may be empty. A string key is used for the name of the attribute. A slice of MergeFuncs is used to define the merge behaviour for this attribute. When Merger.Merge is called, the MergeFuncs are iterated through, with the 'remaining' and 'committed' values of each being passed into the following MergeFunc. The MergeFunc with index 0 is called first. If a MergeFunc leaves some part of an attribute un-merged in the 'remaining' variable, it will be handled by MergeFuncs defined with a higher index in the array. The DefaultMergeFunc is added to the end of all slices of MergeFuncs that simply discards all remaining attributes.
type TailwindMerge ¶
type TailwindMerge interface {
TailwindMergeFunc(existing any, incoming any) (remaining any, committed any)
}
func NewTailwindMerge ¶
func NewTailwindMerge() (TailwindMerge, error)
NewTailwindMerge creates an instance of twMergeGoja, the provider of the tailwind-merge library in JavaScript. It runs in github.com/dop251/goja, making it far slower than the other included Merge functions. It is recommended that you run the NewTailwindMerge function in a seperate goroutine as it can have a runtime of up to 14ms. Subsequent calls of TailwindMergeFunc are much faster, and do not need to run in a goroutine.
Directories ¶
Path | Synopsis |
---|---|
Package twMergeGoja manages the Goja runtime and the running of the tailwind-merge JavaScript bundle.
|
Package twMergeGoja manages the Goja runtime and the running of the tailwind-merge JavaScript bundle. |