From de13e207e5d788ed0e57096464841f918f3f5cc6 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Thu, 27 Jan 2022 11:27:38 +0000 Subject: [PATCH] ui: css-prop modifier (#12205) Get the value for a single specific CSS Property from the modified element. returns can be specified either as a second parameter or an option. --- .../consul-ui/app/modifiers/css-prop.js | 12 +++++++++ .../consul-ui/app/modifiers/css-prop.mdx | 25 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 ui/packages/consul-ui/app/modifiers/css-prop.js create mode 100644 ui/packages/consul-ui/app/modifiers/css-prop.mdx diff --git a/ui/packages/consul-ui/app/modifiers/css-prop.js b/ui/packages/consul-ui/app/modifiers/css-prop.js new file mode 100644 index 0000000000..2b836acd11 --- /dev/null +++ b/ui/packages/consul-ui/app/modifiers/css-prop.js @@ -0,0 +1,12 @@ +import Modifier from 'ember-modifier'; +import { inject as service } from '@ember/service'; + +export default class CSSPropModifier extends Modifier { + @service('-document') doc; + didReceiveArguments() { + const params = this.args.positional; + const options = this.args.named; + const returns = params[1] || options.returns; + returns(this.doc.defaultView.getComputedStyle(this.element).getPropertyValue(params[0])); + } +} diff --git a/ui/packages/consul-ui/app/modifiers/css-prop.mdx b/ui/packages/consul-ui/app/modifiers/css-prop.mdx new file mode 100644 index 0000000000..2ddf1bead5 --- /dev/null +++ b/ui/packages/consul-ui/app/modifiers/css-prop.mdx @@ -0,0 +1,25 @@ +# css-prop + +Get the value for a single specific CSS Property from the modified element. +`returns` can be specified either as a second parameter or an option. + +```hbs preview-template +
+ --red-500: {{this.red}} +
+``` + +## Positional Arguments + +| Argument | Type | Default | Description | +| --- | --- | --- | --- | +| `property` | `string` | | The name of the CSS property to fetch from the element | +| `returns` | `function` | | Usually `set` or `mut` or similar | + +## Named Arguments + +| Argument | Type | Default | Description | +| --- | --- | --- | --- | +| `returns` | `function` | | See the `returns` positional argument |