Skip to content

Commit

Permalink
feat: add example for dependent attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulthink committed Jan 7, 2023
1 parent f7c6a14 commit 3cd4547
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/08.attribute-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// title: dynamic attributes depending on each other

import {Marker} from './lib/marker';

// dynamic attributes can be written to reliably depend on the current value
// of another attribute, for example to make colors depend on the icon shown
// or make colors depend on each other. Note that this also works when
// depending on other dynamic attributes.
//
// Returning undefined for the borderColor causes the borderColor to be set
// automatically via the color attribute.

export default (map: google.maps.Map) => {
const marker = new Marker({
position: {lat: 53.55, lng: 10.05},
color: ({marker}) => (marker.hovered ? 'red' : 'green'),
borderColor: ({attr}) => (attr.color === 'red' ? 'black' : undefined),
map
});
};

0 comments on commit 3cd4547

Please sign in to comment.