Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customization: CSS, String template, Row template #15

Merged
merged 7 commits into from
Jul 6, 2021

Conversation

mxlje
Copy link
Contributor

@mxlje mxlje commented Jul 1, 2021

This PR adds three different (but combinable) ways of customizing the visual style of the element:

  1. custom css (variables)
  2. string template
  3. row template

As to not repeat everything in this PR description it’s best to read the documentation I wrote: https://github.com/geocodeearth/autocomplete-element/tree/feat/customization-templates#customization

mxlje added 2 commits July 1, 2021 13:16
this small but powerful addition allows a user of the element to define
a custom <style> element inside of the custom element, which is then
moved in to the Shadow DOM. The <style> tag can define arbitrary CSS of
course, but the main (and supported) way of using it is to override CSS
variables to customize the styling of the element.

Example:

<ge-autocomplete …>
	<style>
	  :host {
	    --input-bg: salmon;
	    --loading-color: red;
	  }
	</style>
</ge-autocomplete>
this is the second (after CSS), very powerful customization feature: it
allows a user of the element to define a <template row> tag inside the
custom element, and inside of that they can create HTML markup as well
as access the data of the row (the Feature) through the lodash template
language.

Example:

<ge-autocomplete …>
	<template row>
	  <div>${feature.properties.gid}: ${feature.properties.name}</div>
	</template>
</ge-autocomplete>
this template allows customization of the way a Feature is converted
into a string and can be used for "smaller" customization where a fully
new template with custom styles would be overkill.

Also this applies to the resulting string that is placed in the input
field after an item is selected.

this commit also refactors the way templates are passed to parse them
both in a single function instead of duplicating the logic. This also
allows easily adding more templates in the future.
@mxlje mxlje changed the title customization: CSS, Row customization: CSS, String template, Row template Jul 1, 2021
@mxlje mxlje force-pushed the feat/customization-templates branch from 2c94d84 to c3e5419 Compare July 1, 2021 15:22
README.md Outdated Show resolved Hide resolved
README.md Outdated
</ge-autocomplete>
```

**Pro Tip™:** Use the `active` property to check if the current row is being hovered over or activated via arrow keys.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pro Tip™:

LOL 👍

README.md Show resolved Hide resolved
Co-authored-by: Julian Simioni <orangejulius@users.noreply.github.com>
@mxlje mxlje force-pushed the feat/customization-templates branch from e45182d to 90193d0 Compare July 2, 2021 11:23
by moving the actual feature data one level down we can add metadata to
the top level of the object, such as `active`, `index`, and
`searchTerm`, so the template can use

${item.feature.properties} ${item.active}

that way the meta properties don’t conflict with the geo data itself
@missinglink
Copy link
Contributor

:shipit:

@mxlje mxlje marked this pull request as ready for review July 6, 2021 10:16
@mxlje mxlje merged commit fcb8647 into main Jul 6, 2021
@mxlje mxlje deleted the feat/customization-templates branch July 6, 2021 10:17
@missinglink missinglink mentioned this pull request Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants