Skip to content

Commit

Permalink
Add square hatch legend icon
Browse files Browse the repository at this point in the history
Implement a square icon with a hatching pattern.
Make the background color, hatch color, and hatch width adjustable

closes #15
  • Loading branch information
TangoYankee committed Dec 20, 2024
1 parent 8978e9c commit 80a39ed
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/components/labs-ui/icons/square-hatch.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<svg width=".875em" height=".875em">
<defs>
<pattern id="diagonalHatch" patternUnits="userSpaceOnUse" width="4" height="4" patternTransform="rotate(-45 2 2)">
<path d="M -1,2 l 6,0" stroke={{this.hatchColor}} stroke-width={{this.hatchWidth}} />
</pattern>
</defs>
<rect fill={{this.backgroundColor}} rx="2" ry="2" width="100%" height="100%" />
<rect fill="url(#diagonalHatch)" ry="2" rx="2" height="100%" width="100%" />
</svg>
21 changes: 21 additions & 0 deletions addon/components/labs-ui/icons/square-hatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Component from '@glimmer/component';
import { htmlSafe } from '@ember/template';

export default class SquareHatchComponent extends Component {
get backgroundColor() {
const backgroundColor = this.args?.options?.backgroundColor;
return backgroundColor !== undefined
? htmlSafe(backgroundColor)
: 'rgba(255, 255, 255, 1)';
}

get hatchColor() {
const hatchColor = this.args?.options?.hatchColor;
return hatchColor !== undefined ? htmlSafe(hatchColor) : 'rgba(0, 0, 0, 1)';
}

get hatchWidth() {
const hatchWidth = this.args?.options?.hatchWidth;
return hatchWidth !== undefined ? htmlSafe(hatchWidth) : '1';
}
}
4 changes: 4 additions & 0 deletions addon/components/labs-ui/legend-icon.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<LabsUi::Icons::rectangle @options={{icon-layer}} />
{{/if}}

{{#if (eq @icon.type "square-hatch")}}
<LabsUi::Icons::square-hatch @options={{icon-layer}} />
{{/if}}

{{#if (eq @icon.type "fa-icon")}}
<LabsUi::Icons::fa-icon @options={{icon-layer}} />
{{/if}}
Expand Down
1 change: 1 addition & 0 deletions app/components/labs-ui/icons/square-hatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@nycplanning/ember/components/labs-ui/icons/square-hatch';
17 changes: 17 additions & 0 deletions tests/integration/components/labs-ui/icons/square-hatch-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | labs-ui/icons/square-hatch', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`{{labs-ui/icons/square-hatch}}`);

assert.strictEqual(this.element.textContent.trim(), '');
});
});

0 comments on commit 80a39ed

Please sign in to comment.