The main purpose behind this pull request is to allow users to have multiple triggers that have different options.
This is done by allowing the trigger prop to be either a string or array of strings (I kept it as string OR array of strings so already existent code passing trigger a string doesn't break).
<TextField trigger={["@"]} options={["aa", "ab", "abc", "abcd"]} />
The options prop can now be either an array or an object that maps each trigger to a specific option array (this was kept as an array OR object for the same reason). If the option prop is an array and the trigger prop is an array of strings then all triggers will have the same options.
<TextField trigger={["@", "@@"]} options={{"@": ["aa", "ab", "abc", "abcd"], "@@": ["az", "ar"]}} /><TextField trigger=["@", "@@"] options={["aa", "ab", "abc", "abcd"]} /> Here both triggers will have the same options
I also included tests for this feature to show that it's functional and how it would operate.
Changes made to the eslintrc were made to combat errors shown below:
Change - "arrow-parens": "off"
Reasoning - So I can return an object with an arrow function
const triggersMatch = triggers.map((trigger) => ({ triggerStr: trigger, triggerMatch: trigger.match(re), triggerLength: trigger.length, }));
Change - "class-methods-use-this": 0
Reasoning - Without this method like arrayTriggerMatch and isTrigger would give an error because I didn't use this inside the method
Change - "brace-style": "off"
Reasoning - So I can have my else if on a different line instead of next to the closing bracket of my if block
Overall I hope this code is useful and can be merged if there aren't any errors :)
The main purpose behind this pull request is to allow users to have multiple triggers that have different options.
This is done by allowing the trigger prop to be either a string or array of strings (I kept it as string OR array of strings so already existent code passing trigger a string doesn't break).
<TextField trigger={["@"]} options={["aa", "ab", "abc", "abcd"]} />
The options prop can now be either an array or an object that maps each trigger to a specific option array (this was kept as an array OR object for the same reason). If the option prop is an array and the trigger prop is an array of strings then all triggers will have the same options.
<TextField trigger={["@", "@@"]} options={{"@": ["aa", "ab", "abc", "abcd"], "@@": ["az", "ar"]}} />
<TextField trigger=["@", "@@"] options={["aa", "ab", "abc", "abcd"]} />
Here both triggers will have the same optionsI also included tests for this feature to show that it's functional and how it would operate.
Changes made to the eslintrc were made to combat errors shown below: Change - "arrow-parens": "off" Reasoning - So I can return an object with an arrow function
const triggersMatch = triggers.map((trigger) => ({ triggerStr: trigger, triggerMatch: trigger.match(re), triggerLength: trigger.length, }));
Change - "class-methods-use-this": 0 Reasoning - Without this method like
arrayTriggerMatch
andisTrigger
would give an error because I didn't usethis
inside the methodChange - "brace-style": "off" Reasoning - So I can have my
else if
on a different line instead of next to the closing bracket of myif
blockOverall I hope this code is useful and can be merged if there aren't any errors :)